-
Notifications
You must be signed in to change notification settings - Fork 9.8k
[webview_flutter_wkwebview] Implement WKNavigationDelegate.didFinishNavigation
as a proof of concept for callback methods
#5199
[webview_flutter_wkwebview] Implement WKNavigationDelegate.didFinishNavigation
as a proof of concept for callback methods
#5199
Conversation
packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation_api_impls.dart
Show resolved
Hide resolved
packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation_api_impls.dart
Show resolved
Hide resolved
WKNavigationDelegate.didFinishNavigation
as a proof of concept
WKNavigationDelegate.didFinishNavigation
as a proof of conceptWKNavigationDelegate.didFinishNavigation
as a proof of concept for callback methods
packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart
Show resolved
Hide resolved
|
||
/// Mutable instance containing all Flutter Apis for the Foundation library. | ||
/// | ||
/// This should only be changed for testing purposes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better to enforce this with a private variable, a public getter, and a @visibleForTesting
setter?
packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation_api_impls.dart
Show resolved
Hide resolved
@visibleForTesting | ||
late final FunctionFlutterApiImpl functionFlutterApi; | ||
|
||
/// Ensures all the Flutter APIs have been setup to receive calls from native code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: set up
class WebKitFlutterApis { | ||
/// Constructs a [WebKitFlutterApis]. | ||
/// | ||
/// This should only be changed for testing purposes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment doesn't make sense here, since the constructor doesn't change anything.
|
||
/// Mutable instance containing all Flutter Apis for WebKit. | ||
/// | ||
/// This should only be changed for testing purposes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same note here as in the other file; this can be a getter+annotated setter
static WebKitFlutterApis instance = WebKitFlutterApis(); | ||
|
||
/// Sends binary data across the Flutter platform barrier. | ||
final BinaryMessenger? binaryMessenger; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want this to be public?
@visibleForTesting | ||
late final WKNavigationDelegateFlutterApiImpl navigationDelegateFlutterApi; | ||
|
||
/// Ensures all the Flutter APIs have been setup to receive calls from native code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set up
int? functionInstanceId; | ||
if (didFinishNavigation != null) { | ||
functionInstanceId = instanceManager.getInstanceId(didFinishNavigation); | ||
functionInstanceId ??= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why =
then ??=
rather than just functionInstanceId = ... ?? ...;
?
) function = | ||
instanceManager.getInstance(functionInstanceId)! as void Function( | ||
WKWebView webView, | ||
String? url, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems worth typedefing this instead of repeating the signature twice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually realized that InstanceManager.getInstance
uses generics to make this casting easier. So, I didn't actually need the as ...
.
@stuartmorgan This is ready for a second review |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart
Outdated
Show resolved
Hide resolved
….didFinishNavigation` as a proof of concept for callback methods (flutter/plugins#5199)
* master: (153 commits) Roll Flutter from fd360c4 to ef5a6da (1 revision) (flutter#5298) [video_player_avfoundation] Applies the standardized transform for videos with different orientations (flutter#5069) Roll Flutter from 3752fb7 to fd360c4 (2 revisions) (flutter#5295) Roll Flutter from 3c4d7a1 to 3752fb7 (11 revisions) (flutter#5294) Add owners for Android implementations (flutter#5293) Roll Flutter from f4875ae to 3c4d7a1 (2 revisions) (flutter#5292) [video_player_web] Stop buffering when browser canPlayThrough. (flutter#5068) Roll Flutter from aa5d7b6 to f4875ae (1 revision) (flutter#5289) Roll Flutter from 44be0b8 to aa5d7b6 (12 revisions) (flutter#5286) Roll Flutter from ec8289c to 44be0b8 (2 revisions) (flutter#5284) Roll Flutter from 329ceae to ec8289c (26 revisions) (flutter#5283) [flutter_plugin_tools] Preserve Dart SDK version in all-plugins-app (flutter#5281) [webview_flutter_wkwebview] Implements the `HostApis` and methods for the `CookieManager`. (flutter#5244) [webview_flutter_wkwebview] Implement `WKNavigationDelegate.didFinishNavigation` as a proof of concept for callback methods (flutter#5199) Roll Flutter from 08e467d to 2b83332 (5 revisions) (flutter#5270) Roll Flutter from e2d1206 to 08e467d (1 revision) (flutter#5268) Roll Flutter from ff9d6e5 to e2d1206 (2 revisions) (flutter#5266) Roll Flutter from 0575932 to ff9d6e5 (1 revision) (flutter#5265) [local_auth] Refactor package to make use of new platform interface and native implementations (flutter#4701) Roll Flutter from cb968c5 to 0575932 (1 revision) (flutter#5263) ...
…Navigation` as a proof of concept for callback methods (flutter#5199)
This PR implements one of the callback methods for
WKNavigationDelegate
as a proof of concept for the rest of the callback methods in the library. An anonymous functions is used rather than making a callback on an overriden method. This provides the benefit of separating theWKNavigationDelegate
instance from the callback function instances.By separating them, the Dart
WKNavigationDelegate
can be disposed and still receive callback methods. Which prevents a race condition where the DartWKNavigationDelegate
is disposed at the same time a callback is made from Objective-C. To prevent this race condition on Android, theWebView
tracks all the callback classes and handles disposing them. This implementation allows each callback class to manage its own callback methods.No version change:
Part of flutter/flutter#93732 and doesn't make any changes to the current implementation.
No CHANGELOG change: Incremental unused code doesn't need to be noted in the CHANGELOG.
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.