-
Notifications
You must be signed in to change notification settings - Fork 6k
[web] Support flutterViewId in platform view messages
#46891
Changes from 2 commits
eb01df8
116a716
54306b7
d637eee
40c7cb8
c98fde8
582f2c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,13 +63,12 @@ class PlatformViewMessageHandler { | |
| /// If all goes well, this function will `callback` with an empty success envelope. | ||
| /// In case of error, this will `callback` with an error envelope describing the error. | ||
| void _createPlatformView( | ||
| MethodCall methodCall, | ||
| Map<dynamic, dynamic> arguments, | ||
| _PlatformMessageResponseCallback callback, | ||
| ) { | ||
| final Map<dynamic, dynamic> args = methodCall.arguments as Map<dynamic, dynamic>; | ||
| final int viewId = args.readInt('id'); | ||
| final String viewType = args.readString('viewType'); | ||
| final Object? params = args['params']; | ||
| final int viewId = arguments.readInt('id'); | ||
| final String viewType = arguments.readString('viewType'); | ||
| final Object? params = arguments['params']; | ||
|
|
||
| if (!_contentManager.knowsViewType(viewType)) { | ||
| callback(_codec.encodeErrorEnvelope( | ||
|
|
@@ -114,34 +113,53 @@ class PlatformViewMessageHandler { | |
| /// | ||
| /// This function should always `callback` with an empty success envelope. | ||
| void _disposePlatformView( | ||
| MethodCall methodCall, | ||
| int viewId, | ||
| _PlatformMessageResponseCallback callback, | ||
| ) { | ||
| final int viewId = methodCall.arguments as int; | ||
|
|
||
| // The contentManager removes the slot and the contents from its internal | ||
| // cache, and the DOM. | ||
| _contentManager.clearPlatformView(viewId); | ||
|
|
||
| callback(_codec.encodeSuccessEnvelope(null)); | ||
| } | ||
|
|
||
| /// Handles legacy PlatformViewCalls that don't contain a `flutterViewId`. | ||
| /// | ||
| /// This is transitional code to support the old platform view channel. As | ||
| /// soon as the framework code is updated to send the `flutterViewId`, this | ||
| /// method can be removed. | ||
| void handleLegacyPlatformViewCall( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I totally forgot about this method. Good repurposing though!
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You must've been looking at an individual commit from the PR 🙂 This method is new. |
||
| String method, | ||
| dynamic arguments, | ||
| _PlatformMessageResponseCallback callback, | ||
| ) { | ||
| switch (method) { | ||
| case 'create': | ||
| _createPlatformView(arguments as Map<dynamic, dynamic>, callback); | ||
| return; | ||
| case 'dispose': | ||
| _disposePlatformView(arguments as int, callback); | ||
| return; | ||
| } | ||
| callback(null); | ||
| } | ||
|
|
||
| /// Handles a PlatformViewCall to the `flutter/platform_views` channel. | ||
| /// | ||
| /// This method handles two possible messages: | ||
| /// * `create`: See [_createPlatformView] | ||
| /// * `dispose`: See [_disposePlatformView] | ||
| void handlePlatformViewCall( | ||
| ByteData? data, | ||
| String method, | ||
| Map<dynamic, dynamic> arguments, | ||
| _PlatformMessageResponseCallback callback, | ||
| ) { | ||
| final MethodCall decoded = _codec.decodeMethodCall(data); | ||
| switch (decoded.method) { | ||
| switch (method) { | ||
| case 'create': | ||
| _createPlatformView(decoded, callback); | ||
| _createPlatformView(arguments, callback); | ||
| return; | ||
| case 'dispose': | ||
| _disposePlatformView(decoded, callback); | ||
| _disposePlatformView(arguments.readInt('id'), callback); | ||
| return; | ||
| } | ||
| callback(null); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ import 'package:ui/ui.dart' as ui; | |
| import 'browser_detection.dart'; | ||
| import 'dom.dart'; | ||
| import 'safe_browser_api.dart'; | ||
| import 'services.dart'; | ||
| import 'vector_math.dart'; | ||
|
|
||
| /// Generic callback signature, used by [_futurize]. | ||
|
|
@@ -627,6 +628,23 @@ extension JsonExtensions on Map<dynamic, dynamic> { | |
| } | ||
| } | ||
|
|
||
| /// Extracts view ID from the [MethodCall.arguments] map. | ||
| /// | ||
| /// Throws if the view ID is not present or if [arguments] is not a map. | ||
|
mdebbar marked this conversation as resolved.
|
||
| int readFlutterViewId(Object? arguments) { | ||
| return tryFlutterViewId(arguments)!; | ||
| } | ||
|
|
||
| /// Extracts view ID from the [MethodCall.arguments] map. | ||
| /// | ||
| /// Returns null if the view ID is not present or if [arguments] is not a map. | ||
| int? tryFlutterViewId(Object? arguments) { | ||
| if (arguments is Map) { | ||
| return arguments.tryInt('flutterViewId'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm trying to figure out if this is going to be named
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can always change this when a global naming decision has been made :)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the change is going to be a little bit of a pain, since the string needs to be kept in sync between the engine <-> framework. I think @goderbauer mentioned he'd use |
||
| } | ||
| return null; | ||
| } | ||
|
|
||
| /// Prints a list of bytes in hex format. | ||
| /// | ||
| /// Bytes are separated by one space and are padded on the left to always show | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.