allocateNewPage function

Future<void> allocateNewPage(
  1. bool sync,
  2. double newContextId,
  3. int syncBufferSize, {
  4. bool useLegacyUICommand = false,
  5. bool enableBlink = false,
})

Implementation

Future<void> allocateNewPage(bool sync, double newContextId, int syncBufferSize,
    {bool useLegacyUICommand = false, bool enableBlink = false}) async {
  await waitingSyncTaskComplete(newContextId);

  Map<String, ElementCreator> widgetElementCreators = getAllWidgetElements();
  // Built-in HTML elements that are implemented as WidgetElement on the Dart
  // side (e.g. INPUT/TEXTAREA/RouterLink). They are registered as normal HTML
  // elements, but native WidgetElement code paths still need their shapes and
  // default attribute snapshots to avoid blocking synchronous calls back to
  // Dart when running with Blink enabled.
  widgetElementCreators.putIfAbsent(INPUT, () => (context) => createElement(INPUT, context));
  widgetElementCreators.putIfAbsent(TEXTAREA, () => (context) => createElement(TEXTAREA, context));
  widgetElementCreators.putIfAbsent(ROUTER_LINK, () => (context) => createElement(ROUTER_LINK, context));
  Pointer<WidgetElementShape> shapes = createWidgetElementShape(widgetElementCreators);

  if (!sync) {
    Completer<void> completer = Completer();
    _AllocateNewPageContext context = _AllocateNewPageContext(completer, newContextId);
    Pointer<NativeFunction<HandleAllocateNewPageResult>> f = Pointer.fromFunction(_handleAllocateNewPageResult);
    _allocateNewPage(newContextId, syncBufferSize, useLegacyUICommand ? 1 : 0, enableBlink ? 1 : 0,
        dartContext!.pointer, shapes, widgetElementCreators.length, context, f);
    return completer.future;
  } else {
    Pointer<Void> page = _allocateNewPageSync(
        newContextId, dartContext!.pointer, shapes, widgetElementCreators.length, enableBlink ? 1 : 0);
    assert(!_allocatedPages.containsKey(newContextId));
    _allocatedPages[newContextId] = page;
  }
}