@@ -95,3 +95,61 @@ set debugEmulateFlutterTesterEnvironment(bool value) {
9595bool _debugEmulateFlutterTesterEnvironment = false ;
9696engine.AssetManager get webOnlyAssetManager => _assetManager! ;
9797engine.FontCollection get webOnlyFontCollection => _fontCollection! ;
98+
99+ /// Provides a compile time constant to customize flutter framework and other
100+ /// users of ui engine for web runtime.
101+ const bool isWeb = true ;
102+
103+ /// Web specific SMI. Used by bitfield. The 0x3FFFFFFFFFFFFFFF used on VM
104+ /// is not supported on Web platform.
105+ const int kMaxUnsignedSMI = - 1 ;
106+
107+ void webOnlyInitializeEngine () {
108+ engine.initializeEngine ();
109+ }
110+
111+ void webOnlySetPluginHandler (Future <void > Function (String , ByteData ? , PlatformMessageResponseCallback ? ) handler) {
112+ engine.pluginMessageCallHandler = handler;
113+ }
114+
115+ // TODO(yjbanov): The code below was temporarily moved from lib/web_ui/lib/src/engine/platform_views.dart
116+ // during the NNBD migration so that `dart:ui` does not have to export `dart:_engine`. NNBD
117+ // does not allow exported non-migrated libraries from migrated libraries. When `dart:_engine`
118+ // is migrated, we can move it back.
119+
120+ /// A function which takes a unique `id` and creates an HTML element.
121+ typedef PlatformViewFactory = html.Element Function (int viewId);
122+
123+ /// A registry for factories that create platform views.
124+ class PlatformViewRegistry {
125+ /// Register [viewTypeId] as being creating by the given [factory] .
126+ bool registerViewFactory (String viewTypeId, PlatformViewFactory viewFactory,
127+ {bool isVisible = true }) {
128+ // TODO(web): Deprecate this once there's another way of calling `registerFactory` (js interop?)
129+ return engine.platformViewManager
130+ .registerFactory (viewTypeId, viewFactory, isVisible: isVisible);
131+ }
132+ }
133+
134+ /// The platform view registry for this app.
135+ final PlatformViewRegistry platformViewRegistry = PlatformViewRegistry ();
136+
137+ // TODO(yjbanov): remove _Callback, _Callbacker, and _futurize. They are here only
138+ // because the analyzer wasn't able to infer the correct types during
139+ // NNBD migration.
140+ typedef _Callback <T > = void Function (T result);
141+ typedef _Callbacker <T > = String ? Function (_Callback <T > callback);
142+ Future <T > _futurize <T >(_Callbacker <T > callbacker) {
143+ final Completer <T > completer = Completer <T >.sync ();
144+ final String ? error = callbacker ((T t) {
145+ if (t == null ) {
146+ completer.completeError (Exception ('operation failed' ));
147+ } else {
148+ completer.complete (t);
149+ }
150+ });
151+ if (error != null ) {
152+ throw Exception (error);
153+ }
154+ return completer.future;
155+ }
0 commit comments