From ee32e41ac3fb8198c108b83a1a9fdaf9927d243a Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Mon, 6 Jun 2022 18:26:32 -0700 Subject: [PATCH 1/7] update navigation delegate --- .../lib/src/foundation/foundation.dart | 3 +- .../lib/src/web_kit/web_kit.dart | 54 +++--- .../lib/src/web_kit_webview_widget.dart | 100 +++++++----- .../src/foundation/foundation_test.mocks.dart | 14 +- .../test/src/ui_kit/ui_kit_test.mocks.dart | 114 ++++++------- .../test/src/web_kit/web_kit_test.mocks.dart | 154 +++++++++--------- .../web_kit_cookie_manager_test.mocks.dart | 2 +- .../test/src/web_kit_webview_widget_test.dart | 120 +++++++++----- .../web_kit_webview_widget_test.mocks.dart | 119 ++++++-------- 9 files changed, 357 insertions(+), 323 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart index 5dfb78c267de..889ed653f88c 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart @@ -9,6 +9,7 @@ import 'dart:typed_data'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; + import '../common/instance_manager.dart'; import 'foundation_api_impls.dart'; @@ -236,7 +237,7 @@ class NSHttpCookie { /// The root class of most Objective-C class hierarchies. @immutable -class NSObject with Copyable { +class NSObject implements Copyable { // TODO(bparrishMines): Change constructor name to `detached`. /// Constructs a [NSObject] without creating the associated /// Objective-C object. diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart index 2b887e97adcf..829f6e76cdfb 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart @@ -606,6 +606,11 @@ class WKNavigationDelegate extends NSObject { /// Constructs a [WKNavigationDelegate]. WKNavigationDelegate({ this.didFinishNavigation, + this.didStartProvisionalNavigation, + this.decidePolicyForNavigationAction, + this.didFailNavigation, + this.didFailProvisionalNavigation, + this.webViewWebContentProcessDidTerminate, super.binaryMessenger, super.instanceManager, }) : _navigationDelegateApi = WKNavigationDelegateHostApiImpl( @@ -623,6 +628,11 @@ class WKNavigationDelegate extends NSObject { /// library or to create a copy for an InstanceManager. WKNavigationDelegate.detached({ this.didFinishNavigation, + this.didStartProvisionalNavigation, + this.decidePolicyForNavigationAction, + this.didFailNavigation, + this.didFailProvisionalNavigation, + this.webViewWebContentProcessDidTerminate, super.binaryMessenger, super.instanceManager, }) : _navigationDelegateApi = WKNavigationDelegateHostApiImpl( @@ -636,49 +646,35 @@ class WKNavigationDelegate extends NSObject { final void Function(WKWebView webView, String? url)? didFinishNavigation; /// Called when navigation from the main frame has started. - Future setDidStartProvisionalNavigation( - void Function(WKWebView webView, String? url)? - didStartProvisionalNavigation, - ) { - throw UnimplementedError(); - } + final void Function(WKWebView webView, String? url)? + didStartProvisionalNavigation; /// Called when permission is needed to navigate to new content. - Future setDecidePolicyForNavigationAction( - Future Function( + final Future Function( WKWebView webView, WKNavigationAction navigationAction, - )? - decidePolicyForNavigationAction) { - throw UnimplementedError(); - } + )? decidePolicyForNavigationAction; /// Called when an error occurred during navigation. - Future setDidFailNavigation( - void Function(WKWebView webView, NSError error)? didFailNavigation, - ) { - throw UnimplementedError(); - } + final void Function(WKWebView webView, NSError error)? didFailNavigation; /// Called when an error occurred during the early navigation process. - Future setDidFailProvisionalNavigation( - void Function(WKWebView webView, NSError error)? - didFailProvisionalNavigation, - ) { - throw UnimplementedError(); - } + final void Function(WKWebView webView, NSError error)? + didFailProvisionalNavigation; /// Called when the web view’s content process was terminated. - Future setWebViewWebContentProcessDidTerminate( - void Function(WKWebView webView)? webViewWebContentProcessDidTerminate, - ) { - throw UnimplementedError(); - } + final void Function(WKWebView webView)? webViewWebContentProcessDidTerminate; @override - Copyable copy() { + WKNavigationDelegate copy() { return WKNavigationDelegate.detached( didFinishNavigation: didFinishNavigation, + didStartProvisionalNavigation: didStartProvisionalNavigation, + decidePolicyForNavigationAction: decidePolicyForNavigationAction, + didFailNavigation: didFailNavigation, + didFailProvisionalNavigation: didFailProvisionalNavigation, + webViewWebContentProcessDidTerminate: + webViewWebContentProcessDidTerminate, binaryMessenger: _navigationDelegateApi.binaryMessenger, instanceManager: _navigationDelegateApi.instanceManager, ); diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart index 90f1554bf99b..12224164dc06 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart @@ -92,6 +92,7 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { } bool _zoomEnabled = true; + bool _hasNavigationDelegate = false; final Map _scriptMessageHandlers = {}; @@ -121,25 +122,42 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { didFinishNavigation: (WKWebView webView, String? url) { callbacksHandler.onPageFinished(url ?? ''); }, - ) - ..setDidStartProvisionalNavigation((WKWebView webView, String? url) { - callbacksHandler.onPageStarted(url ?? ''); - }) - ..setDidFailNavigation((WKWebView webView, NSError error) { - callbacksHandler.onWebResourceError(_toWebResourceError(error)); - }) - ..setDidFailProvisionalNavigation((WKWebView webView, NSError error) { - callbacksHandler.onWebResourceError(_toWebResourceError(error)); - }) - ..setWebViewWebContentProcessDidTerminate((WKWebView webView) { - callbacksHandler.onWebResourceError(WebResourceError( - errorCode: WKErrorCode.webContentProcessTerminated, - // Value from https://developer.apple.com/documentation/webkit/wkerrordomain?language=objc. - domain: 'WKErrorDomain', - description: '', - errorType: WebResourceErrorType.webContentProcessTerminated, - )); - }); + didStartProvisionalNavigation: (WKWebView webView, String? url) { + callbacksHandler.onPageStarted(url ?? ''); + }, + decidePolicyForNavigationAction: ( + WKWebView webView, + WKNavigationAction action, + ) async { + if (!_hasNavigationDelegate) { + return WKNavigationActionPolicy.allow; + } + + final bool allow = await callbacksHandler.onNavigationRequest( + url: action.request.url, + isForMainFrame: action.targetFrame.isMainFrame, + ); + + return allow + ? WKNavigationActionPolicy.allow + : WKNavigationActionPolicy.cancel; + }, + didFailNavigation: (WKWebView webView, NSError error) { + callbacksHandler.onWebResourceError(_toWebResourceError(error)); + }, + didFailProvisionalNavigation: (WKWebView webView, NSError error) { + callbacksHandler.onWebResourceError(_toWebResourceError(error)); + }, + webViewWebContentProcessDidTerminate: (WKWebView webView) { + callbacksHandler.onWebResourceError(WebResourceError( + errorCode: WKErrorCode.webContentProcessTerminated, + // Value from https://developer.apple.com/documentation/webkit/wkerrordomain?language=objc. + domain: 'WKErrorDomain', + description: '', + errorType: WebResourceErrorType.webContentProcessTerminated, + )); + }, + ); Future _setCreationParams( CreationParams params, { @@ -358,10 +376,11 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { @override Future updateSettings(WebSettings setting) async { + if (setting.hasNavigationDelegate != null) { + _hasNavigationDelegate = setting.hasNavigationDelegate!; + } await Future.wait(>[ _setUserAgent(setting.userAgent), - if (setting.hasNavigationDelegate != null) - _setHasNavigationDelegate(setting.hasNavigationDelegate!), if (setting.hasProgressTracking != null) _setHasProgressTracking(setting.hasProgressTracking!), if (setting.javascriptMode != null) @@ -426,24 +445,6 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { await _resetUserScripts(removedJavaScriptChannels: javascriptChannelNames); } - Future _setHasNavigationDelegate(bool hasNavigationDelegate) { - if (hasNavigationDelegate) { - return navigationDelegate.setDecidePolicyForNavigationAction( - (WKWebView webView, WKNavigationAction action) async { - final bool allow = await callbacksHandler.onNavigationRequest( - url: action.request.url, - isForMainFrame: action.targetFrame.isMainFrame, - ); - - return allow - ? WKNavigationActionPolicy.allow - : WKNavigationActionPolicy.cancel; - }); - } else { - return navigationDelegate.setDecidePolicyForNavigationAction(null); - } - } - Future _setHasProgressTracking(bool hasProgressTracking) { if (hasProgressTracking) { webView.setObserveValue(( @@ -626,7 +627,26 @@ class WebViewWidgetProxy { String? url, )? didFinishNavigation, + void Function(WKWebView webView, String? url)? + didStartProvisionalNavigation, + Future Function( + WKWebView webView, + WKNavigationAction navigationAction, + )? + decidePolicyForNavigationAction, + void Function(WKWebView webView, NSError error)? didFailNavigation, + void Function(WKWebView webView, NSError error)? + didFailProvisionalNavigation, + void Function(WKWebView webView)? webViewWebContentProcessDidTerminate, }) { - return WKNavigationDelegate(didFinishNavigation: didFinishNavigation); + return WKNavigationDelegate( + didFinishNavigation: didFinishNavigation, + didStartProvisionalNavigation: didStartProvisionalNavigation, + decidePolicyForNavigationAction: decidePolicyForNavigationAction, + didFailNavigation: didFailNavigation, + didFailProvisionalNavigation: didFailProvisionalNavigation, + webViewWebContentProcessDidTerminate: + webViewWebContentProcessDidTerminate, + ); } } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.mocks.dart index 7bd208eeac05..62a51e17bc75 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.mocks.dart @@ -1,4 +1,4 @@ -// Mocks generated by Mockito 5.1.0 from annotations +// Mocks generated by Mockito 5.2.0 from annotations // in webview_flutter_wkwebview/example/ios/.symlinks/plugins/webview_flutter_wkwebview/test/src/foundation/foundation_test.dart. // Do not manually edit this file. @@ -28,21 +28,21 @@ class MockTestNSObjectHostApi extends _i1.Mock } @override - void dispose(int? instanceId) => - super.noSuchMethod(Invocation.method(#dispose, [instanceId]), + void dispose(int? identifier) => + super.noSuchMethod(Invocation.method(#dispose, [identifier]), returnValueForMissingStub: null); @override - void addObserver(int? instanceId, int? observerInstanceId, String? keyPath, + void addObserver(int? identifier, int? observerIdentifier, String? keyPath, List<_i3.NSKeyValueObservingOptionsEnumData?>? options) => super.noSuchMethod( Invocation.method( - #addObserver, [instanceId, observerInstanceId, keyPath, options]), + #addObserver, [identifier, observerIdentifier, keyPath, options]), returnValueForMissingStub: null); @override void removeObserver( - int? instanceId, int? observerInstanceId, String? keyPath) => + int? identifier, int? observerIdentifier, String? keyPath) => super.noSuchMethod( Invocation.method( - #removeObserver, [instanceId, observerInstanceId, keyPath]), + #removeObserver, [identifier, observerIdentifier, keyPath]), returnValueForMissingStub: null); } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/ui_kit/ui_kit_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/ui_kit/ui_kit_test.mocks.dart index a9f9b2c322c7..a382ecff677c 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/ui_kit/ui_kit_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/ui_kit/ui_kit_test.mocks.dart @@ -1,4 +1,4 @@ -// Mocks generated by Mockito 5.1.0 from annotations +// Mocks generated by Mockito 5.2.0 from annotations // in webview_flutter_wkwebview/example/ios/.symlinks/plugins/webview_flutter_wkwebview/test/src/ui_kit/ui_kit_test.dart. // Do not manually edit this file. @@ -30,26 +30,26 @@ class MockTestWKWebViewConfigurationHostApi extends _i1.Mock } @override - void create(int? instanceId) => - super.noSuchMethod(Invocation.method(#create, [instanceId]), + void create(int? identifier) => + super.noSuchMethod(Invocation.method(#create, [identifier]), returnValueForMissingStub: null); @override - void createFromWebView(int? instanceId, int? webViewInstanceId) => + void createFromWebView(int? identifier, int? webViewIdentifier) => super.noSuchMethod( Invocation.method( - #createFromWebView, [instanceId, webViewInstanceId]), + #createFromWebView, [identifier, webViewIdentifier]), returnValueForMissingStub: null); @override - void setAllowsInlineMediaPlayback(int? instanceId, bool? allow) => + void setAllowsInlineMediaPlayback(int? identifier, bool? allow) => super.noSuchMethod( - Invocation.method(#setAllowsInlineMediaPlayback, [instanceId, allow]), + Invocation.method(#setAllowsInlineMediaPlayback, [identifier, allow]), returnValueForMissingStub: null); @override void setMediaTypesRequiringUserActionForPlayback( - int? instanceId, List<_i3.WKAudiovisualMediaTypeEnumData?>? types) => + int? identifier, List<_i3.WKAudiovisualMediaTypeEnumData?>? types) => super.noSuchMethod( Invocation.method(#setMediaTypesRequiringUserActionForPlayback, - [instanceId, types]), + [identifier, types]), returnValueForMissingStub: null); } @@ -63,88 +63,88 @@ class MockTestWKWebViewHostApi extends _i1.Mock } @override - void create(int? instanceId, int? configurationInstanceId) => + void create(int? identifier, int? configurationIdentifier) => super.noSuchMethod( - Invocation.method(#create, [instanceId, configurationInstanceId]), + Invocation.method(#create, [identifier, configurationIdentifier]), returnValueForMissingStub: null); @override - void setUIDelegate(int? instanceId, int? uiDelegateInstanceId) => + void setUIDelegate(int? identifier, int? uiDelegateIdentifier) => super.noSuchMethod( - Invocation.method(#setUIDelegate, [instanceId, uiDelegateInstanceId]), + Invocation.method(#setUIDelegate, [identifier, uiDelegateIdentifier]), returnValueForMissingStub: null); @override void setNavigationDelegate( - int? instanceId, int? navigationDelegateInstanceId) => + int? identifier, int? navigationDelegateIdentifier) => super.noSuchMethod( Invocation.method(#setNavigationDelegate, - [instanceId, navigationDelegateInstanceId]), + [identifier, navigationDelegateIdentifier]), returnValueForMissingStub: null); @override - String? getUrl(int? instanceId) => - (super.noSuchMethod(Invocation.method(#getUrl, [instanceId])) as String?); + String? getUrl(int? identifier) => + (super.noSuchMethod(Invocation.method(#getUrl, [identifier])) as String?); @override - double getEstimatedProgress(int? instanceId) => (super.noSuchMethod( - Invocation.method(#getEstimatedProgress, [instanceId]), + double getEstimatedProgress(int? identifier) => (super.noSuchMethod( + Invocation.method(#getEstimatedProgress, [identifier]), returnValue: 0.0) as double); @override - void loadRequest(int? instanceId, _i3.NSUrlRequestData? request) => - super.noSuchMethod(Invocation.method(#loadRequest, [instanceId, request]), + void loadRequest(int? identifier, _i3.NSUrlRequestData? request) => + super.noSuchMethod(Invocation.method(#loadRequest, [identifier, request]), returnValueForMissingStub: null); @override - void loadHtmlString(int? instanceId, String? string, String? baseUrl) => + void loadHtmlString(int? identifier, String? string, String? baseUrl) => super.noSuchMethod( - Invocation.method(#loadHtmlString, [instanceId, string, baseUrl]), + Invocation.method(#loadHtmlString, [identifier, string, baseUrl]), returnValueForMissingStub: null); @override - void loadFileUrl(int? instanceId, String? url, String? readAccessUrl) => + void loadFileUrl(int? identifier, String? url, String? readAccessUrl) => super.noSuchMethod( - Invocation.method(#loadFileUrl, [instanceId, url, readAccessUrl]), + Invocation.method(#loadFileUrl, [identifier, url, readAccessUrl]), returnValueForMissingStub: null); @override - void loadFlutterAsset(int? instanceId, String? key) => super.noSuchMethod( - Invocation.method(#loadFlutterAsset, [instanceId, key]), + void loadFlutterAsset(int? identifier, String? key) => super.noSuchMethod( + Invocation.method(#loadFlutterAsset, [identifier, key]), returnValueForMissingStub: null); @override - bool canGoBack(int? instanceId) => - (super.noSuchMethod(Invocation.method(#canGoBack, [instanceId]), + bool canGoBack(int? identifier) => + (super.noSuchMethod(Invocation.method(#canGoBack, [identifier]), returnValue: false) as bool); @override - bool canGoForward(int? instanceId) => - (super.noSuchMethod(Invocation.method(#canGoForward, [instanceId]), + bool canGoForward(int? identifier) => + (super.noSuchMethod(Invocation.method(#canGoForward, [identifier]), returnValue: false) as bool); @override - void goBack(int? instanceId) => - super.noSuchMethod(Invocation.method(#goBack, [instanceId]), + void goBack(int? identifier) => + super.noSuchMethod(Invocation.method(#goBack, [identifier]), returnValueForMissingStub: null); @override - void goForward(int? instanceId) => - super.noSuchMethod(Invocation.method(#goForward, [instanceId]), + void goForward(int? identifier) => + super.noSuchMethod(Invocation.method(#goForward, [identifier]), returnValueForMissingStub: null); @override - void reload(int? instanceId) => - super.noSuchMethod(Invocation.method(#reload, [instanceId]), + void reload(int? identifier) => + super.noSuchMethod(Invocation.method(#reload, [identifier]), returnValueForMissingStub: null); @override - String? getTitle(int? instanceId) => - (super.noSuchMethod(Invocation.method(#getTitle, [instanceId])) + String? getTitle(int? identifier) => + (super.noSuchMethod(Invocation.method(#getTitle, [identifier])) as String?); @override - void setAllowsBackForwardNavigationGestures(int? instanceId, bool? allow) => + void setAllowsBackForwardNavigationGestures(int? identifier, bool? allow) => super.noSuchMethod( Invocation.method( - #setAllowsBackForwardNavigationGestures, [instanceId, allow]), + #setAllowsBackForwardNavigationGestures, [identifier, allow]), returnValueForMissingStub: null); @override - void setCustomUserAgent(int? instanceId, String? userAgent) => + void setCustomUserAgent(int? identifier, String? userAgent) => super.noSuchMethod( - Invocation.method(#setCustomUserAgent, [instanceId, userAgent]), + Invocation.method(#setCustomUserAgent, [identifier, userAgent]), returnValueForMissingStub: null); @override _i4.Future evaluateJavaScript( - int? instanceId, String? javaScriptString) => + int? identifier, String? javaScriptString) => (super.noSuchMethod( Invocation.method( - #evaluateJavaScript, [instanceId, javaScriptString]), + #evaluateJavaScript, [identifier, javaScriptString]), returnValue: Future.value()) as _i4.Future); } @@ -158,22 +158,22 @@ class MockTestUIScrollViewHostApi extends _i1.Mock } @override - void createFromWebView(int? instanceId, int? webViewInstanceId) => + void createFromWebView(int? identifier, int? webViewIdentifier) => super.noSuchMethod( Invocation.method( - #createFromWebView, [instanceId, webViewInstanceId]), + #createFromWebView, [identifier, webViewIdentifier]), returnValueForMissingStub: null); @override - List getContentOffset(int? instanceId) => - (super.noSuchMethod(Invocation.method(#getContentOffset, [instanceId]), + List getContentOffset(int? identifier) => + (super.noSuchMethod(Invocation.method(#getContentOffset, [identifier]), returnValue: []) as List); @override - void scrollBy(int? instanceId, double? x, double? y) => - super.noSuchMethod(Invocation.method(#scrollBy, [instanceId, x, y]), + void scrollBy(int? identifier, double? x, double? y) => + super.noSuchMethod(Invocation.method(#scrollBy, [identifier, x, y]), returnValueForMissingStub: null); @override - void setContentOffset(int? instanceId, double? x, double? y) => super - .noSuchMethod(Invocation.method(#setContentOffset, [instanceId, x, y]), + void setContentOffset(int? identifier, double? x, double? y) => super + .noSuchMethod(Invocation.method(#setContentOffset, [identifier, x, y]), returnValueForMissingStub: null); } @@ -186,11 +186,11 @@ class MockTestUIViewHostApi extends _i1.Mock implements _i2.TestUIViewHostApi { } @override - void setBackgroundColor(int? instanceId, int? value) => super.noSuchMethod( - Invocation.method(#setBackgroundColor, [instanceId, value]), + void setBackgroundColor(int? identifier, int? value) => super.noSuchMethod( + Invocation.method(#setBackgroundColor, [identifier, value]), returnValueForMissingStub: null); @override - void setOpaque(int? instanceId, bool? opaque) => - super.noSuchMethod(Invocation.method(#setOpaque, [instanceId, opaque]), + void setOpaque(int? identifier, bool? opaque) => + super.noSuchMethod(Invocation.method(#setOpaque, [identifier, opaque]), returnValueForMissingStub: null); } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.mocks.dart index 16d80b22c22b..18f30d434952 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.mocks.dart @@ -1,4 +1,4 @@ -// Mocks generated by Mockito 5.1.0 from annotations +// Mocks generated by Mockito 5.2.0 from annotations // in webview_flutter_wkwebview/example/ios/.symlinks/plugins/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.dart. // Do not manually edit this file. @@ -31,14 +31,14 @@ class MockTestWKHttpCookieStoreHostApi extends _i1.Mock @override void createFromWebsiteDataStore( - int? instanceId, int? websiteDataStoreInstanceId) => + int? identifier, int? websiteDataStoreIdentifier) => super.noSuchMethod( Invocation.method(#createFromWebsiteDataStore, - [instanceId, websiteDataStoreInstanceId]), + [identifier, websiteDataStoreIdentifier]), returnValueForMissingStub: null); @override - _i3.Future setCookie(int? instanceId, _i4.NSHttpCookieData? cookie) => - (super.noSuchMethod(Invocation.method(#setCookie, [instanceId, cookie]), + _i3.Future setCookie(int? identifier, _i4.NSHttpCookieData? cookie) => + (super.noSuchMethod(Invocation.method(#setCookie, [identifier, cookie]), returnValue: Future.value(), returnValueForMissingStub: Future.value()) as _i3.Future); } @@ -53,8 +53,8 @@ class MockTestWKNavigationDelegateHostApi extends _i1.Mock } @override - void create(int? instanceId) => - super.noSuchMethod(Invocation.method(#create, [instanceId]), + void create(int? identifier) => + super.noSuchMethod(Invocation.method(#create, [identifier]), returnValueForMissingStub: null); } @@ -69,15 +69,15 @@ class MockTestWKPreferencesHostApi extends _i1.Mock @override void createFromWebViewConfiguration( - int? instanceId, int? configurationInstanceId) => + int? identifier, int? configurationIdentifier) => super.noSuchMethod( Invocation.method(#createFromWebViewConfiguration, - [instanceId, configurationInstanceId]), + [identifier, configurationIdentifier]), returnValueForMissingStub: null); @override - void setJavaScriptEnabled(int? instanceId, bool? enabled) => + void setJavaScriptEnabled(int? identifier, bool? enabled) => super.noSuchMethod( - Invocation.method(#setJavaScriptEnabled, [instanceId, enabled]), + Invocation.method(#setJavaScriptEnabled, [identifier, enabled]), returnValueForMissingStub: null); } @@ -91,8 +91,8 @@ class MockTestWKScriptMessageHandlerHostApi extends _i1.Mock } @override - void create(int? instanceId) => - super.noSuchMethod(Invocation.method(#create, [instanceId]), + void create(int? identifier) => + super.noSuchMethod(Invocation.method(#create, [identifier]), returnValueForMissingStub: null); } @@ -106,8 +106,8 @@ class MockTestWKUIDelegateHostApi extends _i1.Mock } @override - void create(int? instanceId) => - super.noSuchMethod(Invocation.method(#create, [instanceId]), + void create(int? identifier) => + super.noSuchMethod(Invocation.method(#create, [identifier]), returnValueForMissingStub: null); } @@ -122,34 +122,34 @@ class MockTestWKUserContentControllerHostApi extends _i1.Mock @override void createFromWebViewConfiguration( - int? instanceId, int? configurationInstanceId) => + int? identifier, int? configurationIdentifier) => super.noSuchMethod( Invocation.method(#createFromWebViewConfiguration, - [instanceId, configurationInstanceId]), + [identifier, configurationIdentifier]), returnValueForMissingStub: null); @override void addScriptMessageHandler( - int? instanceId, int? handlerInstanceid, String? name) => + int? identifier, int? handlerIdentifier, String? name) => super.noSuchMethod( Invocation.method( - #addScriptMessageHandler, [instanceId, handlerInstanceid, name]), + #addScriptMessageHandler, [identifier, handlerIdentifier, name]), returnValueForMissingStub: null); @override - void removeScriptMessageHandler(int? instanceId, String? name) => + void removeScriptMessageHandler(int? identifier, String? name) => super.noSuchMethod( - Invocation.method(#removeScriptMessageHandler, [instanceId, name]), + Invocation.method(#removeScriptMessageHandler, [identifier, name]), returnValueForMissingStub: null); @override - void removeAllScriptMessageHandlers(int? instanceId) => super.noSuchMethod( - Invocation.method(#removeAllScriptMessageHandlers, [instanceId]), + void removeAllScriptMessageHandlers(int? identifier) => super.noSuchMethod( + Invocation.method(#removeAllScriptMessageHandlers, [identifier]), returnValueForMissingStub: null); @override - void addUserScript(int? instanceId, _i4.WKUserScriptData? userScript) => super - .noSuchMethod(Invocation.method(#addUserScript, [instanceId, userScript]), + void addUserScript(int? identifier, _i4.WKUserScriptData? userScript) => super + .noSuchMethod(Invocation.method(#addUserScript, [identifier, userScript]), returnValueForMissingStub: null); @override - void removeAllUserScripts(int? instanceId) => - super.noSuchMethod(Invocation.method(#removeAllUserScripts, [instanceId]), + void removeAllUserScripts(int? identifier) => + super.noSuchMethod(Invocation.method(#removeAllUserScripts, [identifier]), returnValueForMissingStub: null); } @@ -163,26 +163,26 @@ class MockTestWKWebViewConfigurationHostApi extends _i1.Mock } @override - void create(int? instanceId) => - super.noSuchMethod(Invocation.method(#create, [instanceId]), + void create(int? identifier) => + super.noSuchMethod(Invocation.method(#create, [identifier]), returnValueForMissingStub: null); @override - void createFromWebView(int? instanceId, int? webViewInstanceId) => + void createFromWebView(int? identifier, int? webViewIdentifier) => super.noSuchMethod( Invocation.method( - #createFromWebView, [instanceId, webViewInstanceId]), + #createFromWebView, [identifier, webViewIdentifier]), returnValueForMissingStub: null); @override - void setAllowsInlineMediaPlayback(int? instanceId, bool? allow) => + void setAllowsInlineMediaPlayback(int? identifier, bool? allow) => super.noSuchMethod( - Invocation.method(#setAllowsInlineMediaPlayback, [instanceId, allow]), + Invocation.method(#setAllowsInlineMediaPlayback, [identifier, allow]), returnValueForMissingStub: null); @override void setMediaTypesRequiringUserActionForPlayback( - int? instanceId, List<_i4.WKAudiovisualMediaTypeEnumData?>? types) => + int? identifier, List<_i4.WKAudiovisualMediaTypeEnumData?>? types) => super.noSuchMethod( Invocation.method(#setMediaTypesRequiringUserActionForPlayback, - [instanceId, types]), + [identifier, types]), returnValueForMissingStub: null); } @@ -196,88 +196,88 @@ class MockTestWKWebViewHostApi extends _i1.Mock } @override - void create(int? instanceId, int? configurationInstanceId) => + void create(int? identifier, int? configurationIdentifier) => super.noSuchMethod( - Invocation.method(#create, [instanceId, configurationInstanceId]), + Invocation.method(#create, [identifier, configurationIdentifier]), returnValueForMissingStub: null); @override - void setUIDelegate(int? instanceId, int? uiDelegateInstanceId) => + void setUIDelegate(int? identifier, int? uiDelegateIdentifier) => super.noSuchMethod( - Invocation.method(#setUIDelegate, [instanceId, uiDelegateInstanceId]), + Invocation.method(#setUIDelegate, [identifier, uiDelegateIdentifier]), returnValueForMissingStub: null); @override void setNavigationDelegate( - int? instanceId, int? navigationDelegateInstanceId) => + int? identifier, int? navigationDelegateIdentifier) => super.noSuchMethod( Invocation.method(#setNavigationDelegate, - [instanceId, navigationDelegateInstanceId]), + [identifier, navigationDelegateIdentifier]), returnValueForMissingStub: null); @override - String? getUrl(int? instanceId) => - (super.noSuchMethod(Invocation.method(#getUrl, [instanceId])) as String?); + String? getUrl(int? identifier) => + (super.noSuchMethod(Invocation.method(#getUrl, [identifier])) as String?); @override - double getEstimatedProgress(int? instanceId) => (super.noSuchMethod( - Invocation.method(#getEstimatedProgress, [instanceId]), + double getEstimatedProgress(int? identifier) => (super.noSuchMethod( + Invocation.method(#getEstimatedProgress, [identifier]), returnValue: 0.0) as double); @override - void loadRequest(int? instanceId, _i4.NSUrlRequestData? request) => - super.noSuchMethod(Invocation.method(#loadRequest, [instanceId, request]), + void loadRequest(int? identifier, _i4.NSUrlRequestData? request) => + super.noSuchMethod(Invocation.method(#loadRequest, [identifier, request]), returnValueForMissingStub: null); @override - void loadHtmlString(int? instanceId, String? string, String? baseUrl) => + void loadHtmlString(int? identifier, String? string, String? baseUrl) => super.noSuchMethod( - Invocation.method(#loadHtmlString, [instanceId, string, baseUrl]), + Invocation.method(#loadHtmlString, [identifier, string, baseUrl]), returnValueForMissingStub: null); @override - void loadFileUrl(int? instanceId, String? url, String? readAccessUrl) => + void loadFileUrl(int? identifier, String? url, String? readAccessUrl) => super.noSuchMethod( - Invocation.method(#loadFileUrl, [instanceId, url, readAccessUrl]), + Invocation.method(#loadFileUrl, [identifier, url, readAccessUrl]), returnValueForMissingStub: null); @override - void loadFlutterAsset(int? instanceId, String? key) => super.noSuchMethod( - Invocation.method(#loadFlutterAsset, [instanceId, key]), + void loadFlutterAsset(int? identifier, String? key) => super.noSuchMethod( + Invocation.method(#loadFlutterAsset, [identifier, key]), returnValueForMissingStub: null); @override - bool canGoBack(int? instanceId) => - (super.noSuchMethod(Invocation.method(#canGoBack, [instanceId]), + bool canGoBack(int? identifier) => + (super.noSuchMethod(Invocation.method(#canGoBack, [identifier]), returnValue: false) as bool); @override - bool canGoForward(int? instanceId) => - (super.noSuchMethod(Invocation.method(#canGoForward, [instanceId]), + bool canGoForward(int? identifier) => + (super.noSuchMethod(Invocation.method(#canGoForward, [identifier]), returnValue: false) as bool); @override - void goBack(int? instanceId) => - super.noSuchMethod(Invocation.method(#goBack, [instanceId]), + void goBack(int? identifier) => + super.noSuchMethod(Invocation.method(#goBack, [identifier]), returnValueForMissingStub: null); @override - void goForward(int? instanceId) => - super.noSuchMethod(Invocation.method(#goForward, [instanceId]), + void goForward(int? identifier) => + super.noSuchMethod(Invocation.method(#goForward, [identifier]), returnValueForMissingStub: null); @override - void reload(int? instanceId) => - super.noSuchMethod(Invocation.method(#reload, [instanceId]), + void reload(int? identifier) => + super.noSuchMethod(Invocation.method(#reload, [identifier]), returnValueForMissingStub: null); @override - String? getTitle(int? instanceId) => - (super.noSuchMethod(Invocation.method(#getTitle, [instanceId])) + String? getTitle(int? identifier) => + (super.noSuchMethod(Invocation.method(#getTitle, [identifier])) as String?); @override - void setAllowsBackForwardNavigationGestures(int? instanceId, bool? allow) => + void setAllowsBackForwardNavigationGestures(int? identifier, bool? allow) => super.noSuchMethod( Invocation.method( - #setAllowsBackForwardNavigationGestures, [instanceId, allow]), + #setAllowsBackForwardNavigationGestures, [identifier, allow]), returnValueForMissingStub: null); @override - void setCustomUserAgent(int? instanceId, String? userAgent) => + void setCustomUserAgent(int? identifier, String? userAgent) => super.noSuchMethod( - Invocation.method(#setCustomUserAgent, [instanceId, userAgent]), + Invocation.method(#setCustomUserAgent, [identifier, userAgent]), returnValueForMissingStub: null); @override _i3.Future evaluateJavaScript( - int? instanceId, String? javaScriptString) => + int? identifier, String? javaScriptString) => (super.noSuchMethod( Invocation.method( - #evaluateJavaScript, [instanceId, javaScriptString]), + #evaluateJavaScript, [identifier, javaScriptString]), returnValue: Future.value()) as _i3.Future); } @@ -292,22 +292,22 @@ class MockTestWKWebsiteDataStoreHostApi extends _i1.Mock @override void createFromWebViewConfiguration( - int? instanceId, int? configurationInstanceId) => + int? identifier, int? configurationIdentifier) => super.noSuchMethod( Invocation.method(#createFromWebViewConfiguration, - [instanceId, configurationInstanceId]), + [identifier, configurationIdentifier]), returnValueForMissingStub: null); @override - void createDefaultDataStore(int? instanceId) => super.noSuchMethod( - Invocation.method(#createDefaultDataStore, [instanceId]), + void createDefaultDataStore(int? identifier) => super.noSuchMethod( + Invocation.method(#createDefaultDataStore, [identifier]), returnValueForMissingStub: null); @override _i3.Future removeDataOfTypes( - int? instanceId, + int? identifier, List<_i4.WKWebsiteDataTypeEnumData?>? dataTypes, double? modificationTimeInSecondsSinceEpoch) => (super.noSuchMethod( Invocation.method(#removeDataOfTypes, - [instanceId, dataTypes, modificationTimeInSecondsSinceEpoch]), + [identifier, dataTypes, modificationTimeInSecondsSinceEpoch]), returnValue: Future.value(false)) as _i3.Future); } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_cookie_manager_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_cookie_manager_test.mocks.dart index 5989c138ff25..7973a3d61043 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_cookie_manager_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_cookie_manager_test.mocks.dart @@ -1,4 +1,4 @@ -// Mocks generated by Mockito 5.1.0 from annotations +// Mocks generated by Mockito 5.2.0 from annotations // in webview_flutter_wkwebview/example/ios/.symlinks/plugins/webview_flutter_wkwebview/test/src/web_kit_cookie_manager_test.dart. // Do not manually edit this file. diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart index 6af5f7d16279..3bc2bed78bf4 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart @@ -66,6 +66,14 @@ void main() { when(mockWebViewWidgetProxy.createUIDelgate()).thenReturn(mockUIDelegate); when(mockWebViewWidgetProxy.createNavigationDelegate( didFinishNavigation: anyNamed('didFinishNavigation'), + didStartProvisionalNavigation: + anyNamed('didStartProvisionalNavigation'), + decidePolicyForNavigationAction: + anyNamed('decidePolicyForNavigationAction'), + didFailNavigation: anyNamed('didFailNavigation'), + didFailProvisionalNavigation: anyNamed('didFailProvisionalNavigation'), + webViewWebContentProcessDidTerminate: + anyNamed('webViewWebContentProcessDidTerminate'), )).thenReturn(mockNavigationDelegate); when(mockWebView.configuration).thenReturn(mockWebViewConfiguration); when(mockWebViewConfiguration.userContentController).thenReturn( @@ -273,21 +281,6 @@ void main() { verify(mockPreferences.setJavaScriptEnabled(true)); }); - testWidgets('hasNavigationDelegate', (WidgetTester tester) async { - await buildWidget( - tester, - creationParams: CreationParams( - webSettings: WebSettings( - userAgent: const WebSetting.absent(), - hasNavigationDelegate: true, - ), - ), - ); - - verify(mockNavigationDelegate - .setDecidePolicyForNavigationAction(argThat(isNotNull))); - }); - testWidgets('userAgent', (WidgetTester tester) async { await buildWidget( tester, @@ -906,11 +899,19 @@ void main() { testWidgets('onPageStarted', (WidgetTester tester) async { await buildWidget(tester); - final dynamic didStartProvisionalNavigation = verify( - mockNavigationDelegate - .setDidStartProvisionalNavigation(captureAny)) - .captured - .single as void Function(WKWebView, String); + final dynamic didStartProvisionalNavigation = + verify(mockWebViewWidgetProxy.createNavigationDelegate( + didFinishNavigation: anyNamed('didFinishNavigation'), + didStartProvisionalNavigation: + captureAnyNamed('didStartProvisionalNavigation'), + decidePolicyForNavigationAction: + anyNamed('decidePolicyForNavigationAction'), + didFailNavigation: anyNamed('didFailNavigation'), + didFailProvisionalNavigation: + anyNamed('didFailProvisionalNavigation'), + webViewWebContentProcessDidTerminate: + anyNamed('webViewWebContentProcessDidTerminate'), + )).captured.single as void Function(WKWebView, String); didStartProvisionalNavigation(mockWebView, 'https://google.com'); verify(mockCallbacksHandler.onPageStarted('https://google.com')); @@ -922,6 +923,15 @@ void main() { final dynamic didFinishNavigation = verify(mockWebViewWidgetProxy.createNavigationDelegate( didFinishNavigation: captureAnyNamed('didFinishNavigation'), + didStartProvisionalNavigation: + anyNamed('didStartProvisionalNavigation'), + decidePolicyForNavigationAction: + anyNamed('decidePolicyForNavigationAction'), + didFailNavigation: anyNamed('didFailNavigation'), + didFailProvisionalNavigation: + anyNamed('didFailProvisionalNavigation'), + webViewWebContentProcessDidTerminate: + anyNamed('webViewWebContentProcessDidTerminate'), )).captured.single as void Function(WKWebView, String); didFinishNavigation(mockWebView, 'https://google.com'); @@ -933,9 +943,18 @@ void main() { await buildWidget(tester); final dynamic didFailNavigation = - verify(mockNavigationDelegate.setDidFailNavigation(captureAny)) - .captured - .single as void Function(WKWebView, NSError); + verify(mockWebViewWidgetProxy.createNavigationDelegate( + didFinishNavigation: anyNamed('didFinishNavigation'), + didStartProvisionalNavigation: + anyNamed('didStartProvisionalNavigation'), + decidePolicyForNavigationAction: + anyNamed('decidePolicyForNavigationAction'), + didFailNavigation: captureAnyNamed('didFailNavigation'), + didFailProvisionalNavigation: + anyNamed('didFailProvisionalNavigation'), + webViewWebContentProcessDidTerminate: + anyNamed('webViewWebContentProcessDidTerminate'), + )).captured.single as void Function(WKWebView, NSError); didFailNavigation( mockWebView, @@ -960,11 +979,19 @@ void main() { (WidgetTester tester) async { await buildWidget(tester); - final dynamic didFailProvisionalNavigation = verify( - mockNavigationDelegate - .setDidFailProvisionalNavigation(captureAny)) - .captured - .single as void Function(WKWebView, NSError); + final dynamic didFailProvisionalNavigation = + verify(mockWebViewWidgetProxy.createNavigationDelegate( + didFinishNavigation: anyNamed('didFinishNavigation'), + didStartProvisionalNavigation: + anyNamed('didStartProvisionalNavigation'), + decidePolicyForNavigationAction: + anyNamed('decidePolicyForNavigationAction'), + didFailNavigation: anyNamed('didFailNavigation'), + didFailProvisionalNavigation: + captureAnyNamed('didFailProvisionalNavigation'), + webViewWebContentProcessDidTerminate: + anyNamed('webViewWebContentProcessDidTerminate'), + )).captured.single as void Function(WKWebView, NSError); didFailProvisionalNavigation( mockWebView, @@ -993,11 +1020,19 @@ void main() { (WidgetTester tester) async { await buildWidget(tester); - final dynamic webViewWebContentProcessDidTerminate = verify( - mockNavigationDelegate - .setWebViewWebContentProcessDidTerminate(captureAny)) - .captured - .single as void Function(WKWebView); + final dynamic webViewWebContentProcessDidTerminate = + verify(mockWebViewWidgetProxy.createNavigationDelegate( + didFinishNavigation: anyNamed('didFinishNavigation'), + didStartProvisionalNavigation: + anyNamed('didStartProvisionalNavigation'), + decidePolicyForNavigationAction: + anyNamed('decidePolicyForNavigationAction'), + didFailNavigation: anyNamed('didFailNavigation'), + didFailProvisionalNavigation: + anyNamed('didFailProvisionalNavigation'), + webViewWebContentProcessDidTerminate: + captureAnyNamed('webViewWebContentProcessDidTerminate'), + )).captured.single as void Function(WKWebView); webViewWebContentProcessDidTerminate(mockWebView); final WebResourceError error = @@ -1017,12 +1052,19 @@ void main() { (WidgetTester tester) async { await buildWidget(tester, hasNavigationDelegate: true); - final dynamic decidePolicyForNavigationAction = verify( - mockNavigationDelegate - .setDecidePolicyForNavigationAction(captureAny)) - .captured - .single - as Future Function( + final dynamic decidePolicyForNavigationAction = + verify(mockWebViewWidgetProxy.createNavigationDelegate( + didFinishNavigation: anyNamed('didFinishNavigation'), + didStartProvisionalNavigation: + anyNamed('didStartProvisionalNavigation'), + decidePolicyForNavigationAction: + captureAnyNamed('decidePolicyForNavigationAction'), + didFailNavigation: anyNamed('didFailNavigation'), + didFailProvisionalNavigation: + anyNamed('didFailProvisionalNavigation'), + webViewWebContentProcessDidTerminate: + anyNamed('webViewWebContentProcessDidTerminate'), + )).captured.single as Future Function( WKWebView, WKNavigationAction); when(mockCallbacksHandler.onNavigationRequest( diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart index f2a9876a71e4..cd99b56305af 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart @@ -1,4 +1,4 @@ -// Mocks generated by Mockito 5.1.0 from annotations +// Mocks generated by Mockito 5.2.0 from annotations // in webview_flutter_wkwebview/example/ios/.symlinks/plugins/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart. // Do not manually edit this file. @@ -36,31 +36,31 @@ class _FakePoint_0 extends _i1.Fake implements _i2.Point {} class _FakeCopyable_1 extends _i1.Fake implements _i3.Copyable {} -class _FakeWKWebViewConfiguration_2 extends _i1.Fake +class _FakeWKNavigationDelegate_2 extends _i1.Fake + implements _i4.WKNavigationDelegate {} + +class _FakeWKWebViewConfiguration_3 extends _i1.Fake implements _i4.WKWebViewConfiguration {} -class _FakeUIScrollView_3 extends _i1.Fake implements _i5.UIScrollView {} +class _FakeUIScrollView_4 extends _i1.Fake implements _i5.UIScrollView {} -class _FakeWKUserContentController_4 extends _i1.Fake +class _FakeWKUserContentController_5 extends _i1.Fake implements _i4.WKUserContentController {} -class _FakeWKPreferences_5 extends _i1.Fake implements _i4.WKPreferences {} +class _FakeWKPreferences_6 extends _i1.Fake implements _i4.WKPreferences {} -class _FakeWKWebsiteDataStore_6 extends _i1.Fake +class _FakeWKWebsiteDataStore_7 extends _i1.Fake implements _i4.WKWebsiteDataStore {} -class _FakeWKHttpCookieStore_7 extends _i1.Fake +class _FakeWKHttpCookieStore_8 extends _i1.Fake implements _i4.WKHttpCookieStore {} -class _FakeWKWebView_8 extends _i1.Fake implements _i4.WKWebView {} +class _FakeWKWebView_9 extends _i1.Fake implements _i4.WKWebView {} -class _FakeWKScriptMessageHandler_9 extends _i1.Fake +class _FakeWKScriptMessageHandler_10 extends _i1.Fake implements _i4.WKScriptMessageHandler {} -class _FakeWKUIDelegate_10 extends _i1.Fake implements _i4.WKUIDelegate {} - -class _FakeWKNavigationDelegate_11 extends _i1.Fake - implements _i4.WKNavigationDelegate {} +class _FakeWKUIDelegate_11 extends _i1.Fake implements _i4.WKUIDelegate {} /// A class which mocks [UIScrollView]. /// @@ -133,51 +133,9 @@ class MockWKNavigationDelegate extends _i1.Mock } @override - _i6.Future setDidStartProvisionalNavigation( - void Function(_i4.WKWebView, String?)? - didStartProvisionalNavigation) => - (super.noSuchMethod( - Invocation.method(#setDidStartProvisionalNavigation, - [didStartProvisionalNavigation]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - _i6.Future setDecidePolicyForNavigationAction( - _i6.Future<_i4.WKNavigationActionPolicy> Function( - _i4.WKWebView, _i4.WKNavigationAction)? - decidePolicyForNavigationAction) => - (super.noSuchMethod( - Invocation.method(#setDecidePolicyForNavigationAction, - [decidePolicyForNavigationAction]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - _i6.Future setDidFailNavigation( - void Function(_i4.WKWebView, _i8.NSError)? didFailNavigation) => - (super.noSuchMethod( - Invocation.method(#setDidFailNavigation, [didFailNavigation]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - _i6.Future setDidFailProvisionalNavigation( - void Function(_i4.WKWebView, _i8.NSError)? - didFailProvisionalNavigation) => - (super.noSuchMethod( - Invocation.method( - #setDidFailProvisionalNavigation, [didFailProvisionalNavigation]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - _i6.Future setWebViewWebContentProcessDidTerminate( - void Function(_i4.WKWebView)? webViewWebContentProcessDidTerminate) => - (super.noSuchMethod( - Invocation.method(#setWebViewWebContentProcessDidTerminate, - [webViewWebContentProcessDidTerminate]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override - _i3.Copyable copy() => (super.noSuchMethod(Invocation.method(#copy, []), - returnValue: _FakeCopyable_1()) as _i3.Copyable); + _i4.WKNavigationDelegate copy() => (super.noSuchMethod( + Invocation.method(#copy, []), + returnValue: _FakeWKNavigationDelegate_2()) as _i4.WKNavigationDelegate); @override _i6.Future addObserver(_i8.NSObject? observer, {String? keyPath, Set<_i8.NSKeyValueObservingOptions>? options}) => @@ -298,12 +256,12 @@ class MockWKWebView extends _i1.Mock implements _i4.WKWebView { @override _i4.WKWebViewConfiguration get configuration => (super.noSuchMethod(Invocation.getter(#configuration), - returnValue: _FakeWKWebViewConfiguration_2()) + returnValue: _FakeWKWebViewConfiguration_3()) as _i4.WKWebViewConfiguration); @override _i5.UIScrollView get scrollView => (super.noSuchMethod(Invocation.getter(#scrollView), - returnValue: _FakeUIScrollView_3()) as _i5.UIScrollView); + returnValue: _FakeUIScrollView_4()) as _i5.UIScrollView); @override _i6.Future setUIDelegate(_i4.WKUIDelegate? delegate) => (super.noSuchMethod(Invocation.method(#setUIDelegate, [delegate]), @@ -436,16 +394,16 @@ class MockWKWebViewConfiguration extends _i1.Mock @override _i4.WKUserContentController get userContentController => (super.noSuchMethod(Invocation.getter(#userContentController), - returnValue: _FakeWKUserContentController_4()) + returnValue: _FakeWKUserContentController_5()) as _i4.WKUserContentController); @override _i4.WKPreferences get preferences => (super.noSuchMethod(Invocation.getter(#preferences), - returnValue: _FakeWKPreferences_5()) as _i4.WKPreferences); + returnValue: _FakeWKPreferences_6()) as _i4.WKPreferences); @override _i4.WKWebsiteDataStore get websiteDataStore => (super.noSuchMethod(Invocation.getter(#websiteDataStore), - returnValue: _FakeWKWebsiteDataStore_6()) as _i4.WKWebsiteDataStore); + returnValue: _FakeWKWebsiteDataStore_7()) as _i4.WKWebsiteDataStore); @override _i6.Future setAllowsInlineMediaPlayback(bool? allow) => (super .noSuchMethod(Invocation.method(#setAllowsInlineMediaPlayback, [allow]), @@ -498,7 +456,7 @@ class MockWKWebsiteDataStore extends _i1.Mock @override _i4.WKHttpCookieStore get httpCookieStore => (super.noSuchMethod(Invocation.getter(#httpCookieStore), - returnValue: _FakeWKHttpCookieStore_7()) as _i4.WKHttpCookieStore); + returnValue: _FakeWKHttpCookieStore_8()) as _i4.WKHttpCookieStore); @override _i6.Future removeDataOfTypes( Set<_i4.WKWebsiteDataType>? dataTypes, DateTime? since) => @@ -709,22 +667,39 @@ class MockWebViewWidgetProxy extends _i1.Mock @override _i4.WKWebView createWebView(_i4.WKWebViewConfiguration? configuration) => (super.noSuchMethod(Invocation.method(#createWebView, [configuration]), - returnValue: _FakeWKWebView_8()) as _i4.WKWebView); + returnValue: _FakeWKWebView_9()) as _i4.WKWebView); @override _i4.WKScriptMessageHandler createScriptMessageHandler() => (super.noSuchMethod(Invocation.method(#createScriptMessageHandler, []), - returnValue: _FakeWKScriptMessageHandler_9()) + returnValue: _FakeWKScriptMessageHandler_10()) as _i4.WKScriptMessageHandler); @override _i4.WKUIDelegate createUIDelgate() => (super.noSuchMethod(Invocation.method(#createUIDelgate, []), - returnValue: _FakeWKUIDelegate_10()) as _i4.WKUIDelegate); + returnValue: _FakeWKUIDelegate_11()) as _i4.WKUIDelegate); @override _i4.WKNavigationDelegate createNavigationDelegate( - {void Function(_i4.WKWebView, String?)? didFinishNavigation}) => - (super.noSuchMethod( - Invocation.method(#createNavigationDelegate, [], - {#didFinishNavigation: didFinishNavigation}), - returnValue: _FakeWKNavigationDelegate_11()) + {void Function(_i4.WKWebView, String?)? didFinishNavigation, + void Function(_i4.WKWebView, String?)? didStartProvisionalNavigation, + _i6.Future<_i4.WKNavigationActionPolicy> Function( + _i4.WKWebView, _i4.WKNavigationAction)? + decidePolicyForNavigationAction, + void Function(_i4.WKWebView, _i8.NSError)? didFailNavigation, + void Function(_i4.WKWebView, _i8.NSError)? + didFailProvisionalNavigation, + void Function(_i4.WKWebView)? + webViewWebContentProcessDidTerminate}) => + (super.noSuchMethod( + Invocation.method(#createNavigationDelegate, [], { + #didFinishNavigation: didFinishNavigation, + #didStartProvisionalNavigation: didStartProvisionalNavigation, + #decidePolicyForNavigationAction: + decidePolicyForNavigationAction, + #didFailNavigation: didFailNavigation, + #didFailProvisionalNavigation: didFailProvisionalNavigation, + #webViewWebContentProcessDidTerminate: + webViewWebContentProcessDidTerminate + }), + returnValue: _FakeWKNavigationDelegate_2()) as _i4.WKNavigationDelegate); } From e5fffe5b06fb9b9aa634d2a90cc93c3b7a6bcde0 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Mon, 6 Jun 2022 18:45:40 -0700 Subject: [PATCH 2/7] progress tracking --- .../lib/src/foundation/foundation.dart | 21 ++--- .../lib/src/ui_kit/ui_kit.dart | 7 +- .../lib/src/web_kit/web_kit.dart | 1 + .../lib/src/web_kit_webview_widget.dart | 30 ++++--- .../src/foundation/foundation_test.mocks.dart | 2 +- .../test/src/ui_kit/ui_kit_test.mocks.dart | 2 +- .../test/src/web_kit/web_kit_test.mocks.dart | 2 +- .../web_kit_cookie_manager_test.mocks.dart | 16 ---- .../test/src/web_kit_webview_widget_test.dart | 24 ++++-- .../web_kit_webview_widget_test.mocks.dart | 81 ++----------------- 10 files changed, 58 insertions(+), 128 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart index 889ed653f88c..d43e5bbeca25 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart @@ -9,7 +9,6 @@ import 'dart:typed_data'; import 'package:flutter/foundation.dart'; import 'package:flutter/services.dart'; - import '../common/instance_manager.dart'; import 'foundation_api_impls.dart'; @@ -245,6 +244,7 @@ class NSObject implements Copyable { /// This should only be used by subclasses created by this library or to /// create copies. NSObject({ + this.observeValue, BinaryMessenger? binaryMessenger, InstanceManager? instanceManager, }) : _api = NSObjectHostApiImpl( @@ -263,6 +263,13 @@ class NSObject implements Copyable { final NSObjectHostApiImpl _api; + /// Informs the observing object when the value at the specified key path has changed. + final void Function( + String keyPath, + NSObject object, + Map change, + )? observeValue; + /// Registers the observer object to receive KVO notifications. Future addObserver( NSObject observer, { @@ -288,18 +295,6 @@ class NSObject implements Copyable { instance._api.instanceManager.removeWeakReference(instance); } - /// Informs the observing object when the value at the specified key path has changed. - Future setObserveValue( - void Function( - String keyPath, - NSObject object, - Map change, - )? - observeValue, - ) { - throw UnimplementedError(); - } - @override Copyable copy() { return NSObject( diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/ui_kit/ui_kit.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/ui_kit/ui_kit.dart index 1d89b18c9f05..2ed1602b9ac9 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/ui_kit/ui_kit.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/ui_kit/ui_kit.dart @@ -64,8 +64,11 @@ class UIScrollView extends UIView { /// Wraps [UIView](https://developer.apple.com/documentation/uikit/uiview?language=objc). class UIView extends NSObject { /// Constructs an [NSObject]. - UIView({BinaryMessenger? binaryMessenger, InstanceManager? instanceManager}) - : _viewApi = UIViewHostApiImpl( + UIView({ + super.observeValue, + BinaryMessenger? binaryMessenger, + InstanceManager? instanceManager, + }) : _viewApi = UIViewHostApiImpl( binaryMessenger: binaryMessenger, instanceManager: instanceManager, ); diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart index 829f6e76cdfb..fc7db5d17199 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart @@ -711,6 +711,7 @@ class WKWebView extends UIView { /// configuration object. WKWebView( WKWebViewConfiguration configuration, { + super.observeValue, super.binaryMessenger, super.instanceManager, }) : _binaryMessenger = binaryMessenger, diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart index 12224164dc06..207f60b3cdd7 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart @@ -169,7 +169,14 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { autoMediaPlaybackPolicy: params.autoMediaPlaybackPolicy, ); - webView = webViewProxy.createWebView(configuration); + webView = webViewProxy.createWebView(configuration, observeValue: ( + String keyPath, + NSObject object, + Map change, + ) { + final double progress = change[NSKeyValueChangeKey.newValue]! as double; + callbacksHandler.onProgress((progress * 100).round()); + }); webView.setUIDelegate(uiDelegate); uiDelegate.setOnCreateWebView(( @@ -447,14 +454,6 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { Future _setHasProgressTracking(bool hasProgressTracking) { if (hasProgressTracking) { - webView.setObserveValue(( - String keyPath, - NSObject object, - Map change, - ) { - final double progress = change[NSKeyValueChangeKey.newValue]! as double; - callbacksHandler.onProgress((progress * 100).round()); - }); return webView.addObserver( webView, keyPath: 'estimatedProgress', @@ -463,7 +462,6 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { }, ); } else { - webView.setObserveValue(null); return webView.removeObserver(webView, keyPath: 'estimatedProgress'); } } @@ -606,8 +604,16 @@ class WebViewWidgetProxy { const WebViewWidgetProxy(); /// Constructs a [WKWebView]. - WKWebView createWebView(WKWebViewConfiguration configuration) { - return WKWebView(configuration); + WKWebView createWebView( + WKWebViewConfiguration configuration, { + void Function( + String keyPath, + NSObject object, + Map change, + )? + observeValue, + }) { + return WKWebView(configuration, observeValue: observeValue); } /// Constructs a [WKScriptMessageHandler]. diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.mocks.dart index 62a51e17bc75..e328a292fcbe 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/foundation/foundation_test.mocks.dart @@ -1,5 +1,5 @@ // Mocks generated by Mockito 5.2.0 from annotations -// in webview_flutter_wkwebview/example/ios/.symlinks/plugins/webview_flutter_wkwebview/test/src/foundation/foundation_test.dart. +// in webview_flutter_wkwebview/test/src/foundation/foundation_test.dart. // Do not manually edit this file. import 'package:mockito/mockito.dart' as _i1; diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/ui_kit/ui_kit_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/ui_kit/ui_kit_test.mocks.dart index a382ecff677c..58939f5b8829 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/ui_kit/ui_kit_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/ui_kit/ui_kit_test.mocks.dart @@ -1,5 +1,5 @@ // Mocks generated by Mockito 5.2.0 from annotations -// in webview_flutter_wkwebview/example/ios/.symlinks/plugins/webview_flutter_wkwebview/test/src/ui_kit/ui_kit_test.dart. +// in webview_flutter_wkwebview/test/src/ui_kit/ui_kit_test.dart. // Do not manually edit this file. import 'dart:async' as _i4; diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.mocks.dart index 18f30d434952..39ba08f3aa93 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.mocks.dart @@ -1,5 +1,5 @@ // Mocks generated by Mockito 5.2.0 from annotations -// in webview_flutter_wkwebview/example/ios/.symlinks/plugins/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.dart. +// in webview_flutter_wkwebview/test/src/web_kit/web_kit_test.dart. // Do not manually edit this file. import 'dart:async' as _i3; diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_cookie_manager_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_cookie_manager_test.mocks.dart index 7973a3d61043..b0c63b663066 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_cookie_manager_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_cookie_manager_test.mocks.dart @@ -54,14 +54,6 @@ class MockWKHttpCookieStore extends _i1.Mock implements _i3.WKHttpCookieStore { returnValue: Future.value(), returnValueForMissingStub: Future.value()) as _i4.Future); @override - _i4.Future setObserveValue( - void Function( - String, _i5.NSObject, Map<_i5.NSKeyValueChangeKey, Object?>)? - observeValue) => - (super.noSuchMethod(Invocation.method(#setObserveValue, [observeValue]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i4.Future); - @override _i2.Copyable copy() => (super.noSuchMethod(Invocation.method(#copy, []), returnValue: _FakeCopyable_0()) as _i2.Copyable); } @@ -100,14 +92,6 @@ class MockWKWebsiteDataStore extends _i1.Mock returnValue: Future.value(), returnValueForMissingStub: Future.value()) as _i4.Future); @override - _i4.Future setObserveValue( - void Function( - String, _i5.NSObject, Map<_i5.NSKeyValueChangeKey, Object?>)? - observeValue) => - (super.noSuchMethod(Invocation.method(#setObserveValue, [observeValue]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i4.Future); - @override _i2.Copyable copy() => (super.noSuchMethod(Invocation.method(#copy, []), returnValue: _FakeCopyable_0()) as _i2.Copyable); } diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart index 3bc2bed78bf4..b7db225971fe 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart @@ -62,7 +62,12 @@ void main() { mockNavigationDelegate = MockWKNavigationDelegate(); mockWebViewWidgetProxy = MockWebViewWidgetProxy(); - when(mockWebViewWidgetProxy.createWebView(any)).thenReturn(mockWebView); + when( + mockWebViewWidgetProxy.createWebView( + any, + observeValue: anyNamed('observeValue'), + ), + ).thenReturn(mockWebView); when(mockWebViewWidgetProxy.createUIDelgate()).thenReturn(mockUIDelegate); when(mockWebViewWidgetProxy.createNavigationDelegate( didFinishNavigation: anyNamed('didFinishNavigation'), @@ -1091,13 +1096,6 @@ void main() { testWidgets('onProgress', (WidgetTester tester) async { await buildWidget(tester, hasProgressTracking: true); - final dynamic observeValue = - verify(mockWebView.setObserveValue(captureAny)).captured.single - as void Function( - String keyPath, - NSObject object, - Map change, - ); verify(mockWebView.addObserver( mockWebView, @@ -1107,6 +1105,16 @@ void main() { }, )); + final dynamic observeValue = verify( + mockWebViewWidgetProxy.createWebView(any, + observeValue: captureAnyNamed('observeValue'))) + .captured + .single as void Function( + String keyPath, + NSObject object, + Map change, + ); + observeValue( 'estimatedProgress', mockWebView, diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart index cd99b56305af..cbb08bcd0fae 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart @@ -110,14 +110,6 @@ class MockUIScrollView extends _i1.Mock implements _i5.UIScrollView { returnValue: Future.value(), returnValueForMissingStub: Future.value()) as _i6.Future); @override - _i6.Future setObserveValue( - void Function( - String, _i8.NSObject, Map<_i8.NSKeyValueChangeKey, Object?>)? - observeValue) => - (super.noSuchMethod(Invocation.method(#setObserveValue, [observeValue]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override _i3.Copyable copy() => (super.noSuchMethod(Invocation.method(#copy, []), returnValue: _FakeCopyable_1()) as _i3.Copyable); } @@ -150,14 +142,6 @@ class MockWKNavigationDelegate extends _i1.Mock Invocation.method(#removeObserver, [observer], {#keyPath: keyPath}), returnValue: Future.value(), returnValueForMissingStub: Future.value()) as _i6.Future); - @override - _i6.Future setObserveValue( - void Function( - String, _i8.NSObject, Map<_i8.NSKeyValueChangeKey, Object?>)? - observeValue) => - (super.noSuchMethod(Invocation.method(#setObserveValue, [observeValue]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); } /// A class which mocks [WKPreferences]. @@ -188,14 +172,6 @@ class MockWKPreferences extends _i1.Mock implements _i4.WKPreferences { returnValue: Future.value(), returnValueForMissingStub: Future.value()) as _i6.Future); @override - _i6.Future setObserveValue( - void Function( - String, _i8.NSObject, Map<_i8.NSKeyValueChangeKey, Object?>)? - observeValue) => - (super.noSuchMethod(Invocation.method(#setObserveValue, [observeValue]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override _i3.Copyable copy() => (super.noSuchMethod(Invocation.method(#copy, []), returnValue: _FakeCopyable_1()) as _i3.Copyable); } @@ -233,14 +209,6 @@ class MockWKScriptMessageHandler extends _i1.Mock returnValue: Future.value(), returnValueForMissingStub: Future.value()) as _i6.Future); @override - _i6.Future setObserveValue( - void Function( - String, _i8.NSObject, Map<_i8.NSKeyValueChangeKey, Object?>)? - observeValue) => - (super.noSuchMethod(Invocation.method(#setObserveValue, [observeValue]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override _i3.Copyable copy() => (super.noSuchMethod(Invocation.method(#copy, []), returnValue: _FakeCopyable_1()) as _i3.Copyable); } @@ -370,14 +338,6 @@ class MockWKWebView extends _i1.Mock implements _i4.WKWebView { returnValue: Future.value(), returnValueForMissingStub: Future.value()) as _i6.Future); @override - _i6.Future setObserveValue( - void Function( - String, _i8.NSObject, Map<_i8.NSKeyValueChangeKey, Object?>)? - observeValue) => - (super.noSuchMethod(Invocation.method(#setObserveValue, [observeValue]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override _i3.Copyable copy() => (super.noSuchMethod(Invocation.method(#copy, []), returnValue: _FakeCopyable_1()) as _i3.Copyable); } @@ -432,14 +392,6 @@ class MockWKWebViewConfiguration extends _i1.Mock returnValue: Future.value(), returnValueForMissingStub: Future.value()) as _i6.Future); @override - _i6.Future setObserveValue( - void Function( - String, _i8.NSObject, Map<_i8.NSKeyValueChangeKey, Object?>)? - observeValue) => - (super.noSuchMethod(Invocation.method(#setObserveValue, [observeValue]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override _i3.Copyable copy() => (super.noSuchMethod(Invocation.method(#copy, []), returnValue: _FakeCopyable_1()) as _i3.Copyable); } @@ -478,14 +430,6 @@ class MockWKWebsiteDataStore extends _i1.Mock returnValue: Future.value(), returnValueForMissingStub: Future.value()) as _i6.Future); @override - _i6.Future setObserveValue( - void Function( - String, _i8.NSObject, Map<_i8.NSKeyValueChangeKey, Object?>)? - observeValue) => - (super.noSuchMethod(Invocation.method(#setObserveValue, [observeValue]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override _i3.Copyable copy() => (super.noSuchMethod(Invocation.method(#copy, []), returnValue: _FakeCopyable_1()) as _i3.Copyable); } @@ -521,14 +465,6 @@ class MockWKUIDelegate extends _i1.Mock implements _i4.WKUIDelegate { returnValue: Future.value(), returnValueForMissingStub: Future.value()) as _i6.Future); @override - _i6.Future setObserveValue( - void Function( - String, _i8.NSObject, Map<_i8.NSKeyValueChangeKey, Object?>)? - observeValue) => - (super.noSuchMethod(Invocation.method(#setObserveValue, [observeValue]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override _i3.Copyable copy() => (super.noSuchMethod(Invocation.method(#copy, []), returnValue: _FakeCopyable_1()) as _i3.Copyable); } @@ -584,14 +520,6 @@ class MockWKUserContentController extends _i1.Mock returnValue: Future.value(), returnValueForMissingStub: Future.value()) as _i6.Future); @override - _i6.Future setObserveValue( - void Function( - String, _i8.NSObject, Map<_i8.NSKeyValueChangeKey, Object?>)? - observeValue) => - (super.noSuchMethod(Invocation.method(#setObserveValue, [observeValue]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); - @override _i3.Copyable copy() => (super.noSuchMethod(Invocation.method(#copy, []), returnValue: _FakeCopyable_1()) as _i3.Copyable); } @@ -665,8 +593,13 @@ class MockWebViewWidgetProxy extends _i1.Mock } @override - _i4.WKWebView createWebView(_i4.WKWebViewConfiguration? configuration) => - (super.noSuchMethod(Invocation.method(#createWebView, [configuration]), + _i4.WKWebView createWebView(_i4.WKWebViewConfiguration? configuration, + {void Function( + String, _i8.NSObject, Map<_i8.NSKeyValueChangeKey, Object?>)? + observeValue}) => + (super.noSuchMethod( + Invocation.method( + #createWebView, [configuration], {#observeValue: observeValue}), returnValue: _FakeWKWebView_9()) as _i4.WKWebView); @override _i4.WKScriptMessageHandler createScriptMessageHandler() => From 27aab597440868703e2e3c61c091f80a5a2a2545 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Mon, 6 Jun 2022 18:59:20 -0700 Subject: [PATCH 3/7] script message handler --- .../lib/src/web_kit/web_kit.dart | 14 ++--- .../lib/src/web_kit_webview_widget.dart | 31 ++++++----- .../test/src/web_kit/web_kit_test.dart | 6 +-- .../test/src/web_kit_webview_widget_test.dart | 51 +++++++++++++------ .../web_kit_webview_widget_test.mocks.dart | 22 ++++---- 5 files changed, 74 insertions(+), 50 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart index fc7db5d17199..c5b45174b18c 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart @@ -350,6 +350,7 @@ class WKHttpCookieStore extends NSObject { class WKScriptMessageHandler extends NSObject { /// Constructs a [WKScriptMessageHandler]. WKScriptMessageHandler({ + required this.didReceiveScriptMessage, BinaryMessenger? binaryMessenger, InstanceManager? instanceManager, }) : _scriptMessageHandlerApi = WKScriptMessageHandlerHostApiImpl( @@ -366,15 +367,10 @@ class WKScriptMessageHandler extends NSObject { /// Use this method to respond to a message sent from the webpage’s /// JavaScript code. Use the [message] parameter to get the message contents and /// to determine the originating web view. - Future setDidReceiveScriptMessage( - void Function( - WKUserContentController userContentController, - WKScriptMessage message, - )? - didReceiveScriptMessage, - ) { - throw UnimplementedError(); - } + final void Function( + WKUserContentController userContentController, + WKScriptMessage message, + ) didReceiveScriptMessage; } /// Manages interactions between JavaScript code and your web view. diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart index 207f60b3cdd7..5fe8141fa444 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart @@ -410,16 +410,15 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { ).map>( (String channelName) { final WKScriptMessageHandler handler = - webViewProxy.createScriptMessageHandler() - ..setDidReceiveScriptMessage(( - WKUserContentController userContentController, - WKScriptMessage message, - ) { - javascriptChannelRegistry.onJavascriptChannelMessage( - message.name, - message.body!.toString(), - ); - }); + webViewProxy.createScriptMessageHandler(didReceiveScriptMessage: ( + WKUserContentController userContentController, + WKScriptMessage message, + ) { + javascriptChannelRegistry.onJavascriptChannelMessage( + message.name, + message.body!.toString(), + ); + }); _scriptMessageHandlers[channelName] = handler; final String wrapperSource = @@ -617,8 +616,16 @@ class WebViewWidgetProxy { } /// Constructs a [WKScriptMessageHandler]. - WKScriptMessageHandler createScriptMessageHandler() { - return WKScriptMessageHandler(); + WKScriptMessageHandler createScriptMessageHandler({ + required void Function( + WKUserContentController userContentController, + WKScriptMessage message, + ) + didReceiveScriptMessage, + }) { + return WKScriptMessageHandler( + didReceiveScriptMessage: didReceiveScriptMessage, + ); } /// Constructs a [WKUIDelegate]. diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.dart index f486474b4cfb..840791601298 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.dart @@ -186,6 +186,7 @@ void main() { TestWKScriptMessageHandlerHostApi.setup(mockPlatformHostApi); scriptMessageHandler = WKScriptMessageHandler( + didReceiveScriptMessage: (_, __) {}, instanceManager: instanceManager, ); }); @@ -287,9 +288,8 @@ void main() { TestWKScriptMessageHandlerHostApi.setup( MockTestWKScriptMessageHandlerHostApi(), ); - final WKScriptMessageHandler handler = WKScriptMessageHandler( - instanceManager: instanceManager, - ); + final WKScriptMessageHandler handler = + WKScriptMessageHandler(didReceiveScriptMessage: (_, __) {}, instanceManager: instanceManager,); userContentController.addScriptMessageHandler(handler, 'handlerName'); verify(mockPlatformHostApi.addScriptMessageHandler( diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart index b7db225971fe..a543ccebd4be 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart @@ -237,7 +237,11 @@ void main() { }); testWidgets('javascriptChannelNames', (WidgetTester tester) async { - when(mockWebViewWidgetProxy.createScriptMessageHandler()).thenReturn( + when( + mockWebViewWidgetProxy.createScriptMessageHandler( + didReceiveScriptMessage: anyNamed('didReceiveScriptMessage'), + ), + ).thenReturn( MockWKScriptMessageHandler(), ); @@ -303,8 +307,11 @@ void main() { testWidgets( 'enabling zoom re-adds JavaScript channels', (WidgetTester tester) async { - when(mockWebViewWidgetProxy.createScriptMessageHandler()) - .thenReturn( + when( + mockWebViewWidgetProxy.createScriptMessageHandler( + didReceiveScriptMessage: anyNamed('didReceiveScriptMessage'), + ), + ).thenReturn( MockWKScriptMessageHandler(), ); @@ -781,7 +788,11 @@ void main() { }); testWidgets('addJavascriptChannels', (WidgetTester tester) async { - when(mockWebViewWidgetProxy.createScriptMessageHandler()).thenReturn( + when( + mockWebViewWidgetProxy.createScriptMessageHandler( + didReceiveScriptMessage: anyNamed('didReceiveScriptMessage'), + ), + ).thenReturn( MockWKScriptMessageHandler(), ); @@ -822,7 +833,11 @@ void main() { }); testWidgets('removeJavascriptChannels', (WidgetTester tester) async { - when(mockWebViewWidgetProxy.createScriptMessageHandler()).thenReturn( + when( + mockWebViewWidgetProxy.createScriptMessageHandler( + didReceiveScriptMessage: anyNamed('didReceiveScriptMessage'), + ), + ).thenReturn( MockWKScriptMessageHandler(), ); @@ -863,7 +878,11 @@ void main() { testWidgets('removeJavascriptChannels with zoom disabled', (WidgetTester tester) async { - when(mockWebViewWidgetProxy.createScriptMessageHandler()).thenReturn( + when( + mockWebViewWidgetProxy.createScriptMessageHandler( + didReceiveScriptMessage: anyNamed('didReceiveScriptMessage'), + ), + ).thenReturn( MockWKScriptMessageHandler(), ); @@ -1127,23 +1146,23 @@ void main() { group('JavascriptChannelRegistry', () { testWidgets('onJavascriptChannelMessage', (WidgetTester tester) async { - when(mockWebViewWidgetProxy.createScriptMessageHandler()).thenReturn( + when( + mockWebViewWidgetProxy.createScriptMessageHandler( + didReceiveScriptMessage: anyNamed('didReceiveScriptMessage'), + ), + ).thenReturn( MockWKScriptMessageHandler(), ); await buildWidget(tester); await testController.addJavascriptChannels({'hello'}); - final MockWKScriptMessageHandler messageHandler = verify( - mockUserContentController.addScriptMessageHandler( - captureAny, 'hello')) + final dynamic didReceiveScriptMessage = verify( + mockWebViewWidgetProxy.createScriptMessageHandler( + didReceiveScriptMessage: + captureAnyNamed('didReceiveScriptMessage'))) .captured - .single as MockWKScriptMessageHandler; - - final dynamic didReceiveScriptMessage = - verify(messageHandler.setDidReceiveScriptMessage(captureAny)) - .captured - .single as void Function( + .single as void Function( WKUserContentController userContentController, WKScriptMessage message, ); diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart index cbb08bcd0fae..d0676de6b3d8 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart @@ -186,14 +186,12 @@ class MockWKScriptMessageHandler extends _i1.Mock } @override - _i6.Future setDidReceiveScriptMessage( - void Function(_i4.WKUserContentController, _i4.WKScriptMessage)? - didReceiveScriptMessage) => - (super.noSuchMethod( - Invocation.method( - #setDidReceiveScriptMessage, [didReceiveScriptMessage]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); + void Function(_i4.WKUserContentController, _i4.WKScriptMessage) + get didReceiveScriptMessage => + (super.noSuchMethod(Invocation.getter(#didReceiveScriptMessage), + returnValue: (_i4.WKUserContentController userContentController, + _i4.WKScriptMessage message) {}) as void Function( + _i4.WKUserContentController, _i4.WKScriptMessage)); @override _i6.Future addObserver(_i8.NSObject? observer, {String? keyPath, Set<_i8.NSKeyValueObservingOptions>? options}) => @@ -602,8 +600,12 @@ class MockWebViewWidgetProxy extends _i1.Mock #createWebView, [configuration], {#observeValue: observeValue}), returnValue: _FakeWKWebView_9()) as _i4.WKWebView); @override - _i4.WKScriptMessageHandler createScriptMessageHandler() => - (super.noSuchMethod(Invocation.method(#createScriptMessageHandler, []), + _i4.WKScriptMessageHandler createScriptMessageHandler( + {void Function(_i4.WKUserContentController, _i4.WKScriptMessage)? + didReceiveScriptMessage}) => + (super.noSuchMethod( + Invocation.method(#createScriptMessageHandler, [], + {#didReceiveScriptMessage: didReceiveScriptMessage}), returnValue: _FakeWKScriptMessageHandler_10()) as _i4.WKScriptMessageHandler); @override From ba9398cc94b8e540aaa9cd54895a1043e185e24c Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Mon, 6 Jun 2022 19:03:52 -0700 Subject: [PATCH 4/7] oncreatewebview --- .../lib/src/web_kit/web_kit.dart | 14 ++++------ .../lib/src/web_kit_webview_widget.dart | 28 +++++++++++-------- .../test/src/web_kit_webview_widget_test.dart | 14 +++++++--- .../web_kit_webview_widget_test.mocks.dart | 16 ++++------- 4 files changed, 38 insertions(+), 34 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart index c5b45174b18c..372d52cd1eae 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart @@ -568,6 +568,7 @@ class WKWebViewConfiguration extends NSObject { class WKUIDelegate extends NSObject { /// Constructs a [WKUIDelegate]. WKUIDelegate({ + this.onCreateWebView, BinaryMessenger? binaryMessenger, InstanceManager? instanceManager, }) : _uiDelegateApi = WKUIDelegateHostApiImpl( @@ -580,15 +581,10 @@ class WKUIDelegate extends NSObject { final WKUIDelegateHostApiImpl _uiDelegateApi; /// Indicates a new [WKWebView] was requested to be created with [configuration]. - Future setOnCreateWebView( - void Function( - WKWebViewConfiguration configuration, - WKNavigationAction navigationAction, - )? - onCreateWebView, - ) { - throw UnimplementedError(); - } + final void Function( + WKWebViewConfiguration configuration, + WKNavigationAction navigationAction, + )? onCreateWebView; } /// Methods for handling navigation changes and tracking navigation requests. diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart index 5fe8141fa444..1cfbc6edb458 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit_webview_widget.dart @@ -113,7 +113,15 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { /// Used to integrate custom user interface elements into web view interactions. @visibleForTesting - late final WKUIDelegate uiDelegate = webViewProxy.createUIDelgate(); + late final WKUIDelegate uiDelegate = + webViewProxy.createUIDelgate(onCreateWebView: ( + WKWebViewConfiguration configuration, + WKNavigationAction navigationAction, + ) { + if (!navigationAction.targetFrame.isMainFrame) { + webView.loadRequest(navigationAction.request); + } + }); /// Methods for handling navigation changes and tracking navigation requests. @visibleForTesting @@ -179,14 +187,6 @@ class WebKitWebViewPlatformController extends WebViewPlatformController { }); webView.setUIDelegate(uiDelegate); - uiDelegate.setOnCreateWebView(( - WKWebViewConfiguration configuration, - WKNavigationAction navigationAction, - ) { - if (!navigationAction.targetFrame.isMainFrame) { - webView.loadRequest(navigationAction.request); - } - }); await addJavascriptChannels(params.javascriptChannelNames); @@ -629,8 +629,14 @@ class WebViewWidgetProxy { } /// Constructs a [WKUIDelegate]. - WKUIDelegate createUIDelgate() { - return WKUIDelegate(); + WKUIDelegate createUIDelgate({ + void Function( + WKWebViewConfiguration configuration, + WKNavigationAction navigationAction, + )? + onCreateWebView, + }) { + return WKUIDelegate(onCreateWebView: onCreateWebView); } /// Constructs a [WKNavigationDelegate]. diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart index a543ccebd4be..c1cdfc503a59 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.dart @@ -68,7 +68,11 @@ void main() { observeValue: anyNamed('observeValue'), ), ).thenReturn(mockWebView); - when(mockWebViewWidgetProxy.createUIDelgate()).thenReturn(mockUIDelegate); + when( + mockWebViewWidgetProxy.createUIDelgate( + onCreateWebView: captureAnyNamed('onCreateWebView'), + ), + ).thenReturn(mockUIDelegate); when(mockWebViewWidgetProxy.createNavigationDelegate( didFinishNavigation: anyNamed('didFinishNavigation'), didStartProvisionalNavigation: @@ -131,9 +135,11 @@ void main() { (WidgetTester tester) async { await buildWidget(tester); - final dynamic onCreateWebView = - verify(mockUIDelegate.setOnCreateWebView(captureAny)).captured.single - as void Function(WKWebViewConfiguration, WKNavigationAction); + final dynamic onCreateWebView = verify( + mockWebViewWidgetProxy.createUIDelgate( + onCreateWebView: captureAnyNamed('onCreateWebView'))) + .captured + .single as void Function(WKWebViewConfiguration, WKNavigationAction); const NSUrlRequest request = NSUrlRequest(url: 'https://google.com'); onCreateWebView( diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart index d0676de6b3d8..728c526ca929 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit_webview_widget_test.mocks.dart @@ -440,14 +440,6 @@ class MockWKUIDelegate extends _i1.Mock implements _i4.WKUIDelegate { _i1.throwOnMissingStub(this); } - @override - _i6.Future setOnCreateWebView( - void Function(_i4.WKWebViewConfiguration, _i4.WKNavigationAction)? - onCreateWebView) => - (super.noSuchMethod( - Invocation.method(#setOnCreateWebView, [onCreateWebView]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i6.Future); @override _i6.Future addObserver(_i8.NSObject? observer, {String? keyPath, Set<_i8.NSKeyValueObservingOptions>? options}) => @@ -609,8 +601,12 @@ class MockWebViewWidgetProxy extends _i1.Mock returnValue: _FakeWKScriptMessageHandler_10()) as _i4.WKScriptMessageHandler); @override - _i4.WKUIDelegate createUIDelgate() => - (super.noSuchMethod(Invocation.method(#createUIDelgate, []), + _i4.WKUIDelegate createUIDelgate( + {void Function(_i4.WKWebViewConfiguration, _i4.WKNavigationAction)? + onCreateWebView}) => + (super.noSuchMethod( + Invocation.method( + #createUIDelgate, [], {#onCreateWebView: onCreateWebView}), returnValue: _FakeWKUIDelegate_11()) as _i4.WKUIDelegate); @override _i4.WKNavigationDelegate createNavigationDelegate( From 0ea87fb0f9cae4cf47c2bf174da478b8b73e03e3 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Mon, 6 Jun 2022 19:04:20 -0700 Subject: [PATCH 5/7] formatting --- .../test/src/web_kit/web_kit_test.dart | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.dart b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.dart index 840791601298..cf417c4e0ca2 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/test/src/web_kit/web_kit_test.dart @@ -288,8 +288,10 @@ void main() { TestWKScriptMessageHandlerHostApi.setup( MockTestWKScriptMessageHandlerHostApi(), ); - final WKScriptMessageHandler handler = - WKScriptMessageHandler(didReceiveScriptMessage: (_, __) {}, instanceManager: instanceManager,); + final WKScriptMessageHandler handler = WKScriptMessageHandler( + didReceiveScriptMessage: (_, __) {}, + instanceManager: instanceManager, + ); userContentController.addScriptMessageHandler(handler, 'handlerName'); verify(mockPlatformHostApi.addScriptMessageHandler( From 33b9894a69751d8625139f5e3d1ed26073fc8775 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Mon, 6 Jun 2022 19:07:02 -0700 Subject: [PATCH 6/7] revert some changes --- .../lib/src/foundation/foundation.dart | 2 +- .../webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart index d43e5bbeca25..0c01233168ee 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart @@ -236,7 +236,7 @@ class NSHttpCookie { /// The root class of most Objective-C class hierarchies. @immutable -class NSObject implements Copyable { +class NSObject with Copyable { // TODO(bparrishMines): Change constructor name to `detached`. /// Constructs a [NSObject] without creating the associated /// Objective-C object. diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart index 372d52cd1eae..9cd7657a61be 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart @@ -658,7 +658,7 @@ class WKNavigationDelegate extends NSObject { final void Function(WKWebView webView)? webViewWebContentProcessDidTerminate; @override - WKNavigationDelegate copy() { + Copyable copy() { return WKNavigationDelegate.detached( didFinishNavigation: didFinishNavigation, didStartProvisionalNavigation: didStartProvisionalNavigation, From 4fc1d68f9d7a6697259a7788a2faa46d0686d63b Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Mon, 6 Jun 2022 20:24:05 -0700 Subject: [PATCH 7/7] observe value parameter --- .../lib/src/foundation/foundation.dart | 1 + .../webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart index 0c01233168ee..0a1dd347f8a2 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/foundation/foundation.dart @@ -298,6 +298,7 @@ class NSObject with Copyable { @override Copyable copy() { return NSObject( + observeValue: observeValue, binaryMessenger: _api.binaryMessenger, instanceManager: _api.instanceManager, ); diff --git a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart index 9cd7657a61be..f2efd665298b 100644 --- a/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart +++ b/packages/webview_flutter/webview_flutter_wkwebview/lib/src/web_kit/web_kit.dart @@ -351,6 +351,7 @@ class WKScriptMessageHandler extends NSObject { /// Constructs a [WKScriptMessageHandler]. WKScriptMessageHandler({ required this.didReceiveScriptMessage, + super.observeValue, BinaryMessenger? binaryMessenger, InstanceManager? instanceManager, }) : _scriptMessageHandlerApi = WKScriptMessageHandlerHostApiImpl( @@ -569,6 +570,7 @@ class WKUIDelegate extends NSObject { /// Constructs a [WKUIDelegate]. WKUIDelegate({ this.onCreateWebView, + super.observeValue, BinaryMessenger? binaryMessenger, InstanceManager? instanceManager, }) : _uiDelegateApi = WKUIDelegateHostApiImpl( @@ -603,6 +605,7 @@ class WKNavigationDelegate extends NSObject { this.didFailNavigation, this.didFailProvisionalNavigation, this.webViewWebContentProcessDidTerminate, + super.observeValue, super.binaryMessenger, super.instanceManager, }) : _navigationDelegateApi = WKNavigationDelegateHostApiImpl( @@ -625,6 +628,7 @@ class WKNavigationDelegate extends NSObject { this.didFailNavigation, this.didFailProvisionalNavigation, this.webViewWebContentProcessDidTerminate, + super.observeValue, super.binaryMessenger, super.instanceManager, }) : _navigationDelegateApi = WKNavigationDelegateHostApiImpl( @@ -667,6 +671,7 @@ class WKNavigationDelegate extends NSObject { didFailProvisionalNavigation: didFailProvisionalNavigation, webViewWebContentProcessDidTerminate: webViewWebContentProcessDidTerminate, + observeValue: observeValue, binaryMessenger: _navigationDelegateApi.binaryMessenger, instanceManager: _navigationDelegateApi.instanceManager, );