From 5559fddb57434d74cbeb1eb58192ad465e49bd64 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 26 Nov 2025 16:44:34 -0500 Subject: [PATCH 1/7] remove proxy --- .../webview_flutter_android/CHANGELOG.md | 4 + .../webview_flutter_test.dart | 38 +- .../lib/src/android_proxy.dart | 148 --- .../lib/src/android_webview_controller.dart | 911 ++++++++--------- .../webview_flutter_android/pubspec.yaml | 2 +- .../android_navigation_delegate_test.dart | 17 +- ...ndroid_navigation_delegate_test.mocks.dart | 1 + .../test/android_webview_controller_test.dart | 444 +++++---- ...android_webview_controller_test.mocks.dart | 939 +++--------------- ...oid_webview_cookie_manager_test.mocks.dart | 1 + ...iew_android_cookie_manager_test.mocks.dart | 1 + .../webview_android_widget_test.mocks.dart | 6 + 12 files changed, 800 insertions(+), 1712 deletions(-) delete mode 100644 packages/webview_flutter/webview_flutter_android/lib/src/android_proxy.dart diff --git a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md index 67582efec5c..35f3b5e01b0 100644 --- a/packages/webview_flutter/webview_flutter_android/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter_android/CHANGELOG.md @@ -1,3 +1,7 @@ +## 4.10.10 + +* Removes internal native library Dart proxy. + ## 4.10.9 * Fixes a compatibility issue with Kotlin 1.8. diff --git a/packages/webview_flutter/webview_flutter_android/example/integration_test/webview_flutter_test.dart b/packages/webview_flutter/webview_flutter_android/example/integration_test/webview_flutter_test.dart index 76242d290be..e05d9f04d95 100644 --- a/packages/webview_flutter/webview_flutter_android/example/integration_test/webview_flutter_test.dart +++ b/packages/webview_flutter/webview_flutter_android/example/integration_test/webview_flutter_test.dart @@ -14,7 +14,6 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; -import 'package:webview_flutter_android/src/android_proxy.dart'; import 'package:webview_flutter_android/src/android_webkit.g.dart' as android_webkit; import 'package:webview_flutter_android/src/weak_reference_utils.dart'; @@ -63,6 +62,10 @@ Future main() async { final headersUrl = '$prefixUrl/headers'; final basicAuthUrl = '$prefixUrl/http-basic-authentication'; + setUp(() { + android_webkit.PigeonOverrides.pigeon_reset(); + }); + testWidgets('loadRequest', (WidgetTester tester) async { final pageFinished = Completer(); @@ -130,33 +133,24 @@ Future main() async { } }); + android_webkit.PigeonOverrides.webView_new = + ({ + void Function(android_webkit.WebView, int, int, int, int)? + onScrollChanged, + }) { + final webView = android_webkit.WebView( + onScrollChanged: onScrollChanged, + ); + finalizer.attach(webView, webViewToken); + return webView; + }; await tester.pumpWidget( Builder( builder: (BuildContext context) { return PlatformWebViewWidget( AndroidWebViewWidgetCreationParams( controller: PlatformWebViewController( - AndroidWebViewControllerCreationParams( - androidWebViewProxy: AndroidWebViewProxy( - newWebView: - ({ - void Function( - android_webkit.WebView, - int, - int, - int, - int, - )? - onScrollChanged, - }) { - final webView = android_webkit.WebView( - onScrollChanged: onScrollChanged, - ); - finalizer.attach(webView, webViewToken); - return webView; - }, - ), - ), + AndroidWebViewControllerCreationParams(), ), ), ).build(context); diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/android_proxy.dart b/packages/webview_flutter/webview_flutter_android/lib/src/android_proxy.dart deleted file mode 100644 index dc23092ef6b..00000000000 --- a/packages/webview_flutter/webview_flutter_android/lib/src/android_proxy.dart +++ /dev/null @@ -1,148 +0,0 @@ -// Copyright 2013 The Flutter Authors -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'android_webkit.g.dart'; - -/// Handles constructing objects and calling static methods for the Android -/// WebView native library. -/// -/// This class provides dependency injection for the implementations of the -/// platform interface classes. Improving the ease of unit testing and/or -/// overriding the underlying Android WebView classes. -/// -/// By default each function calls the default constructor of the WebView class -/// it intends to return. -class AndroidWebViewProxy { - /// Constructs an [AndroidWebViewProxy]. - const AndroidWebViewProxy({ - this.newWebView = WebView.new, - this.newJavaScriptChannel = JavaScriptChannel.new, - this.newWebViewClient = WebViewClient.new, - this.newDownloadListener = DownloadListener.new, - this.newWebChromeClient = WebChromeClient.new, - this.setWebContentsDebuggingEnabledWebView = - WebView.setWebContentsDebuggingEnabled, - this.instanceCookieManager = _instanceCookieManager, - this.instanceFlutterAssetManager = _instanceFlutterAssetManager, - this.instanceWebStorage = _instanceWebStorage, - this.isWebViewFeatureSupported = WebViewFeature.isFeatureSupported, - this.setPaymentRequestEnabled = WebSettingsCompat.setPaymentRequestEnabled, - }); - - /// Constructs [WebView]. - final WebView Function({ - void Function(WebView, int left, int top, int oldLeft, int oldTop)? - onScrollChanged, - }) - newWebView; - - /// Constructs [JavaScriptChannel]. - final JavaScriptChannel Function({ - required String channelName, - required void Function(JavaScriptChannel, String) postMessage, - }) - newJavaScriptChannel; - - /// Constructs [WebViewClient]. - final WebViewClient Function({ - void Function(WebViewClient, WebView, String)? onPageStarted, - void Function(WebViewClient, WebView, String)? onPageFinished, - void Function( - WebViewClient, - WebView, - WebResourceRequest, - WebResourceResponse, - )? - onReceivedHttpError, - void Function(WebViewClient, WebView, WebResourceRequest, WebResourceError)? - onReceivedRequestError, - void Function( - WebViewClient, - WebView, - WebResourceRequest, - WebResourceErrorCompat, - )? - onReceivedRequestErrorCompat, - void Function(WebViewClient, WebView, WebResourceRequest)? requestLoading, - void Function(WebViewClient, WebView, String)? urlLoading, - void Function(WebViewClient, WebView, String, bool)? doUpdateVisitedHistory, - void Function(WebViewClient, WebView, HttpAuthHandler, String, String)? - onReceivedHttpAuthRequest, - void Function(WebViewClient, WebView, AndroidMessage, AndroidMessage)? - onFormResubmission, - void Function(WebViewClient, WebView, String)? onLoadResource, - void Function(WebViewClient, WebView, String)? onPageCommitVisible, - void Function(WebViewClient, WebView, ClientCertRequest)? - onReceivedClientCertRequest, - void Function(WebViewClient, WebView, String, String?, String)? - onReceivedLoginRequest, - void Function(WebViewClient, WebView, SslErrorHandler, SslError)? - onReceivedSslError, - void Function(WebViewClient, WebView, double, double)? onScaleChanged, - }) - newWebViewClient; - - /// Constructs [DownloadListener]. - final DownloadListener Function({ - required void Function( - DownloadListener, - String, - String, - String, - String, - int, - ) - onDownloadStart, - }) - newDownloadListener; - - /// Constructs [WebChromeClient]. - final WebChromeClient Function({ - void Function(WebChromeClient, WebView, int)? onProgressChanged, - required Future> Function( - WebChromeClient, - WebView, - FileChooserParams, - ) - onShowFileChooser, - void Function(WebChromeClient, PermissionRequest)? onPermissionRequest, - void Function(WebChromeClient, View, CustomViewCallback)? onShowCustomView, - void Function(WebChromeClient)? onHideCustomView, - void Function(WebChromeClient, String, GeolocationPermissionsCallback)? - onGeolocationPermissionsShowPrompt, - void Function(WebChromeClient)? onGeolocationPermissionsHidePrompt, - void Function(WebChromeClient, ConsoleMessage)? onConsoleMessage, - Future Function(WebChromeClient, WebView, String, String)? onJsAlert, - required Future Function(WebChromeClient, WebView, String, String) - onJsConfirm, - Future Function(WebChromeClient, WebView, String, String, String)? - onJsPrompt, - }) - newWebChromeClient; - - /// Calls to [WebView.setWebContentsDebuggingEnabled]. - final Future Function(bool) setWebContentsDebuggingEnabledWebView; - - /// Calls to [CookieManager.instance]. - final CookieManager Function() instanceCookieManager; - - /// Calls to [FlutterAssetManager.instance]. - final FlutterAssetManager Function() instanceFlutterAssetManager; - - /// Calls to [WebStorage.instance]. - final WebStorage Function() instanceWebStorage; - - /// Calls to [WebViewFeature.isFeatureSupported]. - final Future Function(String) isWebViewFeatureSupported; - - /// Calls to [WebSettingsCompat.setPaymentRequestEnabled]. - final Future Function(WebSettings, bool) setPaymentRequestEnabled; - - static CookieManager _instanceCookieManager() => CookieManager.instance; - - static FlutterAssetManager _instanceFlutterAssetManager() => - FlutterAssetManager.instance; - - static WebStorage _instanceWebStorage() => WebStorage.instance; -} diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart index 64c59287109..3b63549d394 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart @@ -11,7 +11,6 @@ import 'package:flutter/rendering.dart'; import 'package:flutter/services.dart'; import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; -import 'android_proxy.dart'; import 'android_ssl_auth_error.dart'; import 'android_webkit.g.dart' as android_webview; import 'android_webkit_constants.dart'; @@ -63,7 +62,6 @@ class AndroidWebViewControllerCreationParams extends PlatformWebViewControllerCreationParams { /// Creates a new [AndroidWebViewControllerCreationParams] instance. AndroidWebViewControllerCreationParams({ - @visibleForTesting this.androidWebViewProxy = const AndroidWebViewProxy(), @visibleForTesting android_webview.WebStorage? androidWebStorage, }) : androidWebStorage = androidWebStorage ?? android_webview.WebStorage.instance, @@ -74,22 +72,14 @@ class AndroidWebViewControllerCreationParams // Recommended placeholder to prevent being broken by platform interface. // ignore: avoid_unused_constructor_parameters PlatformWebViewControllerCreationParams params, { - @visibleForTesting - AndroidWebViewProxy androidWebViewProxy = const AndroidWebViewProxy(), @visibleForTesting android_webview.WebStorage? androidWebStorage, }) { return AndroidWebViewControllerCreationParams( - androidWebViewProxy: androidWebViewProxy, androidWebStorage: androidWebStorage ?? android_webview.WebStorage.instance, ); } - /// Handles constructing objects and calling static methods for the Android WebView - /// native library. - @visibleForTesting - final AndroidWebViewProxy androidWebViewProxy; - /// Manages the JavaScript storage APIs provided by the [android_webview.WebView]. @visibleForTesting final android_webview.WebStorage androidWebStorage; @@ -136,271 +126,257 @@ class AndroidWebViewController extends PlatformWebViewController { params as AndroidWebViewControllerCreationParams; /// The native [android_webview.WebView] being controlled. - late final android_webview.WebView _webView = _androidWebViewParams - .androidWebViewProxy - .newWebView( - onScrollChanged: withWeakReferenceTo(this, ( - WeakReference weakReference, - ) { - return (_, int left, int top, int oldLeft, int oldTop) async { - final void Function(ScrollPositionChange)? callback = - weakReference.target?._onScrollPositionChangedCallback; - callback?.call( - ScrollPositionChange(left.toDouble(), top.toDouble()), - ); - }; - }), - ); + late final android_webview.WebView _webView = android_webview.WebView( + onScrollChanged: withWeakReferenceTo(this, ( + WeakReference weakReference, + ) { + return (_, int left, int top, int oldLeft, int oldTop) async { + final void Function(ScrollPositionChange)? callback = + weakReference.target?._onScrollPositionChangedCallback; + callback?.call(ScrollPositionChange(left.toDouble(), top.toDouble())); + }; + }), + ); - late final android_webview.WebChromeClient _webChromeClient = - _androidWebViewParams.androidWebViewProxy.newWebChromeClient( - onProgressChanged: withWeakReferenceTo(this, ( - WeakReference weakReference, - ) { - return (_, android_webview.WebView webView, int progress) { - if (weakReference.target?._currentNavigationDelegate?._onProgress != - null) { - weakReference.target!._currentNavigationDelegate!._onProgress!( - progress, - ); - } - }; - }), - onGeolocationPermissionsShowPrompt: withWeakReferenceTo(this, ( - WeakReference weakReference, - ) { - return ( - _, - String origin, - android_webview.GeolocationPermissionsCallback callback, - ) async { - final OnGeolocationPermissionsShowPrompt? onShowPrompt = - weakReference.target?._onGeolocationPermissionsShowPrompt; - if (onShowPrompt != null) { - final GeolocationPermissionsResponse response = - await onShowPrompt( - GeolocationPermissionsRequestParams(origin: origin), - ); - return callback.invoke(origin, response.allow, response.retain); - } else { - // default don't allow - return callback.invoke(origin, false, false); - } - }; - }), - onGeolocationPermissionsHidePrompt: withWeakReferenceTo(this, ( - WeakReference weakReference, - ) { - return (android_webview.WebChromeClient instance) { - final OnGeolocationPermissionsHidePrompt? onHidePrompt = - weakReference.target?._onGeolocationPermissionsHidePrompt; - if (onHidePrompt != null) { - onHidePrompt(); - } - }; - }), - onShowCustomView: withWeakReferenceTo(this, ( - WeakReference weakReference, - ) { - return ( - _, - android_webview.View view, - android_webview.CustomViewCallback callback, - ) { - final AndroidWebViewController? webViewController = - weakReference.target; - if (webViewController == null) { - callback.onCustomViewHidden(); - return; - } - final OnShowCustomWidgetCallback? onShowCallback = - webViewController._onShowCustomWidgetCallback; - if (onShowCallback == null) { - callback.onCustomViewHidden(); - return; - } - onShowCallback( - AndroidCustomViewWidget.private( - controller: webViewController, - customView: view, - // ignore: invalid_use_of_protected_member - instanceManager: view.pigeon_instanceManager, - ), - () => callback.onCustomViewHidden(), - ); - }; - }), - onHideCustomView: withWeakReferenceTo(this, ( - WeakReference weakReference, - ) { - return (android_webview.WebChromeClient instance) { - final OnHideCustomWidgetCallback? onHideCustomViewCallback = - weakReference.target?._onHideCustomWidgetCallback; - if (onHideCustomViewCallback != null) { - onHideCustomViewCallback(); - } - }; - }), - onShowFileChooser: withWeakReferenceTo(this, ( - WeakReference weakReference, - ) { - return ( - _, - android_webview.WebView webView, - android_webview.FileChooserParams params, - ) async { - if (weakReference.target?._onShowFileSelectorCallback != null) { - return weakReference.target!._onShowFileSelectorCallback!( - FileSelectorParams._fromFileChooserParams(params), - ); - } - return []; - }; - }), - onConsoleMessage: withWeakReferenceTo(this, ( - WeakReference weakReference, - ) { - return ( - android_webview.WebChromeClient webChromeClient, - android_webview.ConsoleMessage consoleMessage, - ) async { - final void Function(JavaScriptConsoleMessage)? callback = - weakReference.target?._onConsoleLogCallback; - if (callback != null) { - JavaScriptLogLevel logLevel; - switch (consoleMessage.level) { - // Android maps `console.debug` to `MessageLevel.TIP`, it seems - // `MessageLevel.DEBUG` if not being used. - case android_webview.ConsoleMessageLevel.debug: - case android_webview.ConsoleMessageLevel.tip: - logLevel = JavaScriptLogLevel.debug; - case android_webview.ConsoleMessageLevel.error: - logLevel = JavaScriptLogLevel.error; - case android_webview.ConsoleMessageLevel.warning: - logLevel = JavaScriptLogLevel.warning; - case android_webview.ConsoleMessageLevel.unknown: - case android_webview.ConsoleMessageLevel.log: - logLevel = JavaScriptLogLevel.log; - } + late final android_webview.WebChromeClient + _webChromeClient = android_webview.WebChromeClient( + onProgressChanged: withWeakReferenceTo(this, ( + WeakReference weakReference, + ) { + return (_, android_webview.WebView webView, int progress) { + if (weakReference.target?._currentNavigationDelegate?._onProgress != + null) { + weakReference.target!._currentNavigationDelegate!._onProgress!( + progress, + ); + } + }; + }), + onGeolocationPermissionsShowPrompt: withWeakReferenceTo(this, ( + WeakReference weakReference, + ) { + return ( + _, + String origin, + android_webview.GeolocationPermissionsCallback callback, + ) async { + final OnGeolocationPermissionsShowPrompt? onShowPrompt = + weakReference.target?._onGeolocationPermissionsShowPrompt; + if (onShowPrompt != null) { + final GeolocationPermissionsResponse response = await onShowPrompt( + GeolocationPermissionsRequestParams(origin: origin), + ); + return callback.invoke(origin, response.allow, response.retain); + } else { + // default don't allow + return callback.invoke(origin, false, false); + } + }; + }), + onGeolocationPermissionsHidePrompt: withWeakReferenceTo(this, ( + WeakReference weakReference, + ) { + return (android_webview.WebChromeClient instance) { + final OnGeolocationPermissionsHidePrompt? onHidePrompt = + weakReference.target?._onGeolocationPermissionsHidePrompt; + if (onHidePrompt != null) { + onHidePrompt(); + } + }; + }), + onShowCustomView: withWeakReferenceTo(this, ( + WeakReference weakReference, + ) { + return ( + _, + android_webview.View view, + android_webview.CustomViewCallback callback, + ) { + final AndroidWebViewController? webViewController = + weakReference.target; + if (webViewController == null) { + callback.onCustomViewHidden(); + return; + } + final OnShowCustomWidgetCallback? onShowCallback = + webViewController._onShowCustomWidgetCallback; + if (onShowCallback == null) { + callback.onCustomViewHidden(); + return; + } + onShowCallback( + AndroidCustomViewWidget.private( + controller: webViewController, + customView: view, + // ignore: invalid_use_of_protected_member + instanceManager: view.pigeon_instanceManager, + ), + () => callback.onCustomViewHidden(), + ); + }; + }), + onHideCustomView: withWeakReferenceTo(this, ( + WeakReference weakReference, + ) { + return (android_webview.WebChromeClient instance) { + final OnHideCustomWidgetCallback? onHideCustomViewCallback = + weakReference.target?._onHideCustomWidgetCallback; + if (onHideCustomViewCallback != null) { + onHideCustomViewCallback(); + } + }; + }), + onShowFileChooser: withWeakReferenceTo(this, ( + WeakReference weakReference, + ) { + return ( + _, + android_webview.WebView webView, + android_webview.FileChooserParams params, + ) async { + if (weakReference.target?._onShowFileSelectorCallback != null) { + return weakReference.target!._onShowFileSelectorCallback!( + FileSelectorParams._fromFileChooserParams(params), + ); + } + return []; + }; + }), + onConsoleMessage: withWeakReferenceTo(this, ( + WeakReference weakReference, + ) { + return ( + android_webview.WebChromeClient webChromeClient, + android_webview.ConsoleMessage consoleMessage, + ) async { + final void Function(JavaScriptConsoleMessage)? callback = + weakReference.target?._onConsoleLogCallback; + if (callback != null) { + JavaScriptLogLevel logLevel; + switch (consoleMessage.level) { + // Android maps `console.debug` to `MessageLevel.TIP`, it seems + // `MessageLevel.DEBUG` if not being used. + case android_webview.ConsoleMessageLevel.debug: + case android_webview.ConsoleMessageLevel.tip: + logLevel = JavaScriptLogLevel.debug; + case android_webview.ConsoleMessageLevel.error: + logLevel = JavaScriptLogLevel.error; + case android_webview.ConsoleMessageLevel.warning: + logLevel = JavaScriptLogLevel.warning; + case android_webview.ConsoleMessageLevel.unknown: + case android_webview.ConsoleMessageLevel.log: + logLevel = JavaScriptLogLevel.log; + } + + callback( + JavaScriptConsoleMessage( + level: logLevel, + message: consoleMessage.message, + ), + ); + } + }; + }), + onPermissionRequest: withWeakReferenceTo(this, ( + WeakReference weakReference, + ) { + return (_, android_webview.PermissionRequest request) async { + final void Function(PlatformWebViewPermissionRequest)? callback = + weakReference.target?._onPermissionRequestCallback; + if (callback == null) { + return request.deny(); + } else { + final Set types = request + .resources + .nonNulls + .map((String type) { + switch (type) { + case PermissionRequestConstants.videoCapture: + return WebViewPermissionResourceType.camera; + case PermissionRequestConstants.audioCapture: + return WebViewPermissionResourceType.microphone; + case PermissionRequestConstants.midiSysex: + return AndroidWebViewPermissionResourceType.midiSysex; + case PermissionRequestConstants.protectedMediaId: + return AndroidWebViewPermissionResourceType + .protectedMediaId; + } - callback( - JavaScriptConsoleMessage( - level: logLevel, - message: consoleMessage.message, - ), - ); - } - }; - }), - onPermissionRequest: withWeakReferenceTo(this, ( - WeakReference weakReference, - ) { - return (_, android_webview.PermissionRequest request) async { - final void Function(PlatformWebViewPermissionRequest)? callback = - weakReference.target?._onPermissionRequestCallback; - if (callback == null) { - return request.deny(); - } else { - final Set types = request - .resources - .nonNulls - .map((String type) { - switch (type) { - case PermissionRequestConstants.videoCapture: - return WebViewPermissionResourceType.camera; - case PermissionRequestConstants.audioCapture: - return WebViewPermissionResourceType.microphone; - case PermissionRequestConstants.midiSysex: - return AndroidWebViewPermissionResourceType.midiSysex; - case PermissionRequestConstants.protectedMediaId: - return AndroidWebViewPermissionResourceType - .protectedMediaId; - } - - // Type not supported. - return null; - }) - .whereType() - .toSet(); - - // If the request didn't contain any permissions recognized by the - // implementation, deny by default. - if (types.isEmpty) { - return request.deny(); - } + // Type not supported. + return null; + }) + .whereType() + .toSet(); - callback( - AndroidWebViewPermissionRequest._( - types: types, - request: request, - ), - ); - } - }; - }), - onJsAlert: withWeakReferenceTo(this, ( - WeakReference weakReference, - ) { - return (_, __, String url, String message) async { - final Future Function(JavaScriptAlertDialogRequest)? - callback = weakReference.target?._onJavaScriptAlert; - if (callback != null) { - final request = JavaScriptAlertDialogRequest( - message: message, - url: url, - ); + // If the request didn't contain any permissions recognized by the + // implementation, deny by default. + if (types.isEmpty) { + return request.deny(); + } - await callback.call(request); - } - return; - }; - }), - onJsConfirm: withWeakReferenceTo(this, ( - WeakReference weakReference, - ) { - return (_, __, String url, String message) async { - final Future Function(JavaScriptConfirmDialogRequest)? - callback = weakReference.target?._onJavaScriptConfirm; - if (callback != null) { - final request = JavaScriptConfirmDialogRequest( - message: message, - url: url, - ); - final bool result = await callback.call(request); - return result; - } - return false; - }; - }), - onJsPrompt: withWeakReferenceTo(this, ( - WeakReference weakReference, - ) { - return ( - _, - __, - String url, - String message, - String defaultValue, - ) async { - final Future Function(JavaScriptTextInputDialogRequest)? - callback = weakReference.target?._onJavaScriptPrompt; - if (callback != null) { - final request = JavaScriptTextInputDialogRequest( - message: message, - url: url, - defaultText: defaultValue, - ); - final String result = await callback.call(request); - return result; - } - return ''; - }; - }), - ); + callback( + AndroidWebViewPermissionRequest._(types: types, request: request), + ); + } + }; + }), + onJsAlert: withWeakReferenceTo(this, ( + WeakReference weakReference, + ) { + return (_, __, String url, String message) async { + final Future Function(JavaScriptAlertDialogRequest)? callback = + weakReference.target?._onJavaScriptAlert; + if (callback != null) { + final request = JavaScriptAlertDialogRequest( + message: message, + url: url, + ); + + await callback.call(request); + } + return; + }; + }), + onJsConfirm: withWeakReferenceTo(this, ( + WeakReference weakReference, + ) { + return (_, __, String url, String message) async { + final Future Function(JavaScriptConfirmDialogRequest)? callback = + weakReference.target?._onJavaScriptConfirm; + if (callback != null) { + final request = JavaScriptConfirmDialogRequest( + message: message, + url: url, + ); + final bool result = await callback.call(request); + return result; + } + return false; + }; + }), + onJsPrompt: withWeakReferenceTo(this, ( + WeakReference weakReference, + ) { + return (_, __, String url, String message, String defaultValue) async { + final Future Function(JavaScriptTextInputDialogRequest)? + callback = weakReference.target?._onJavaScriptPrompt; + if (callback != null) { + final request = JavaScriptTextInputDialogRequest( + message: message, + url: url, + defaultText: defaultValue, + ); + final String result = await callback.call(request); + return result; + } + return ''; + }; + }), + ); /// The native [android_webview.FlutterAssetManager] allows managing assets. late final android_webview.FlutterAssetManager _flutterAssetManager = - _androidWebViewParams.androidWebViewProxy.instanceFlutterAssetManager(); + android_webview.FlutterAssetManager.instance; final Map _javaScriptChannelParams = {}; @@ -442,12 +418,8 @@ class AndroidWebViewController extends PlatformWebViewController { /// Whether to enable the platform's webview content debugging tools. /// /// Defaults to false. - static Future enableDebugging( - bool enabled, { - @visibleForTesting - AndroidWebViewProxy webViewProxy = const AndroidWebViewProxy(), - }) { - return webViewProxy.setWebContentsDebuggingEnabledWebView(enabled); + static Future enableDebugging(bool enabled) { + return android_webview.WebView.setWebContentsDebuggingEnabled(enabled); } /// Identifier used to retrieve the underlying native `WebView`. @@ -873,9 +845,7 @@ class AndroidWebViewController extends PlatformWebViewController { WebViewFeatureType.paymentRequest => WebViewFeatureConstants.paymentRequest, }; - return _androidWebViewParams.androidWebViewProxy.isWebViewFeatureSupported( - feature, - ); + return android_webview.WebViewFeature.isFeatureSupported(feature); } /// Sets whether the WebView should enable the Payment Request API. @@ -889,7 +859,7 @@ class AndroidWebViewController extends PlatformWebViewController { /// This feature requires adding queries to the AndroidManifest.xml to allow WebView to query the device for the user's payment applications: /// See https://developer.android.com/reference/androidx/webkit/WebSettingsCompat#setPaymentRequestEnabled(android.webkit.WebSettings,boolean). Future setPaymentRequestEnabled(bool enabled) { - return _androidWebViewParams.androidWebViewProxy.setPaymentRequestEnabled( + return android_webview.WebSettingsCompat.setPaymentRequestEnabled( _webView.settings, enabled, ); @@ -1090,10 +1060,8 @@ class AndroidJavaScriptChannelParams extends JavaScriptChannelParams { AndroidJavaScriptChannelParams({ required super.name, required super.onMessageReceived, - @visibleForTesting - AndroidWebViewProxy webViewProxy = const AndroidWebViewProxy(), }) : assert(name.isNotEmpty), - _javaScriptChannel = webViewProxy.newJavaScriptChannel( + _javaScriptChannel = android_webview.JavaScriptChannel( channelName: name, postMessage: withWeakReferenceTo(onMessageReceived, ( WeakReference weakReference, @@ -1109,14 +1077,8 @@ class AndroidJavaScriptChannelParams extends JavaScriptChannelParams { /// Constructs a [AndroidJavaScriptChannelParams] using a /// [JavaScriptChannelParams]. AndroidJavaScriptChannelParams.fromJavaScriptChannelParams( - JavaScriptChannelParams params, { - @visibleForTesting - AndroidWebViewProxy webViewProxy = const AndroidWebViewProxy(), - }) : this( - name: params.name, - onMessageReceived: params.onMessageReceived, - webViewProxy: webViewProxy, - ); + JavaScriptChannelParams params, + ) : this(name: params.name, onMessageReceived: params.onMessageReceived); final android_webview.JavaScriptChannel _javaScriptChannel; } @@ -1463,27 +1425,16 @@ class AndroidWebResourceError extends WebResourceError { class AndroidNavigationDelegateCreationParams extends PlatformNavigationDelegateCreationParams { /// Creates a new [AndroidNavigationDelegateCreationParams] instance. - const AndroidNavigationDelegateCreationParams._({ - @visibleForTesting this.androidWebViewProxy = const AndroidWebViewProxy(), - }) : super(); + const AndroidNavigationDelegateCreationParams._() : super(); /// Creates a [AndroidNavigationDelegateCreationParams] instance based on [PlatformNavigationDelegateCreationParams]. factory AndroidNavigationDelegateCreationParams.fromPlatformNavigationDelegateCreationParams( // Recommended placeholder to prevent being broken by platform interface. // ignore: avoid_unused_constructor_parameters - PlatformNavigationDelegateCreationParams params, { - @visibleForTesting - AndroidWebViewProxy androidWebViewProxy = const AndroidWebViewProxy(), - }) { - return AndroidNavigationDelegateCreationParams._( - androidWebViewProxy: androidWebViewProxy, - ); + PlatformNavigationDelegateCreationParams params, + ) { + return const AndroidNavigationDelegateCreationParams._(); } - - /// Handles constructing objects and calling static methods for the Android WebView - /// native library. - @visibleForTesting - final AndroidWebViewProxy androidWebViewProxy; } /// Android details of the change to a web view's url. @@ -1509,198 +1460,188 @@ class AndroidNavigationDelegate extends PlatformNavigationDelegate { ) { final weakThis = WeakReference(this); - _webViewClient = (this.params as AndroidNavigationDelegateCreationParams) - .androidWebViewProxy - .newWebViewClient( - onPageFinished: (_, android_webview.WebView webView, String url) { - final PageEventCallback? callback = - weakThis.target?._onPageFinished; - if (callback != null) { - callback(url); + _webViewClient = android_webview.WebViewClient( + onPageFinished: (_, android_webview.WebView webView, String url) { + final PageEventCallback? callback = weakThis.target?._onPageFinished; + if (callback != null) { + callback(url); + } + }, + onPageStarted: (_, android_webview.WebView webView, String url) { + final PageEventCallback? callback = weakThis.target?._onPageStarted; + if (callback != null) { + callback(url); + } + }, + onReceivedHttpError: + ( + _, + android_webview.WebView webView, + android_webview.WebResourceRequest request, + android_webview.WebResourceResponse response, + ) { + if (weakThis.target?._onHttpError != null) { + weakThis.target!._onHttpError!( + HttpResponseError( + request: WebResourceRequest(uri: Uri.parse(request.url)), + response: WebResourceResponse( + uri: null, + statusCode: response.statusCode, + ), + ), + ); } }, - onPageStarted: (_, android_webview.WebView webView, String url) { - final PageEventCallback? callback = weakThis.target?._onPageStarted; + onReceivedRequestError: + ( + _, + android_webview.WebView webView, + android_webview.WebResourceRequest request, + android_webview.WebResourceError error, + ) { + final WebResourceErrorCallback? callback = + weakThis.target?._onWebResourceError; if (callback != null) { - callback(url); + callback( + AndroidWebResourceError._( + errorCode: error.errorCode, + description: error.description, + url: request.url, + isForMainFrame: request.isForMainFrame, + ), + ); } }, - onReceivedHttpError: - ( - _, - android_webview.WebView webView, - android_webview.WebResourceRequest request, - android_webview.WebResourceResponse response, - ) { - if (weakThis.target?._onHttpError != null) { - weakThis.target!._onHttpError!( - HttpResponseError( - request: WebResourceRequest(uri: Uri.parse(request.url)), - response: WebResourceResponse( - uri: null, - statusCode: response.statusCode, - ), - ), - ); - } - }, - onReceivedRequestError: - ( - _, - android_webview.WebView webView, - android_webview.WebResourceRequest request, - android_webview.WebResourceError error, - ) { - final WebResourceErrorCallback? callback = - weakThis.target?._onWebResourceError; - if (callback != null) { - callback( - AndroidWebResourceError._( - errorCode: error.errorCode, - description: error.description, - url: request.url, - isForMainFrame: request.isForMainFrame, - ), - ); - } - }, - onReceivedRequestErrorCompat: - ( - _, - android_webview.WebView webView, - android_webview.WebResourceRequest request, - android_webview.WebResourceErrorCompat error, - ) { - final WebResourceErrorCallback? callback = - weakThis.target?._onWebResourceError; - if (callback != null) { - callback( - AndroidWebResourceError._( - errorCode: error.errorCode, - description: error.description, - url: request.url, - isForMainFrame: request.isForMainFrame, - ), - ); - } - }, - requestLoading: - ( - _, - android_webview.WebView webView, - android_webview.WebResourceRequest request, - ) { - weakThis.target?._handleNavigation( - request.url, - headers: - request.requestHeaders?.map(( - String? key, - String? value, - ) { - return MapEntry(key!, value!); - }) ?? - {}, + onReceivedRequestErrorCompat: + ( + _, + android_webview.WebView webView, + android_webview.WebResourceRequest request, + android_webview.WebResourceErrorCompat error, + ) { + final WebResourceErrorCallback? callback = + weakThis.target?._onWebResourceError; + if (callback != null) { + callback( + AndroidWebResourceError._( + errorCode: error.errorCode, + description: error.description, + url: request.url, isForMainFrame: request.isForMainFrame, - ); - }, - urlLoading: (_, android_webview.WebView webView, String url) { - weakThis.target?._handleNavigation(url, isForMainFrame: true); + ), + ); + } }, - doUpdateVisitedHistory: - (_, android_webview.WebView webView, String url, bool isReload) { - final UrlChangeCallback? callback = - weakThis.target?._onUrlChange; - if (callback != null) { - callback(AndroidUrlChange(url: url, isReload: isReload)); - } - }, - onReceivedHttpAuthRequest: - ( - _, - android_webview.WebView webView, - android_webview.HttpAuthHandler httpAuthHandler, - String host, - String realm, - ) { - final void Function(HttpAuthRequest)? callback = - weakThis.target?._onHttpAuthRequest; - if (callback != null) { - callback( - HttpAuthRequest( - onProceed: (WebViewCredential credential) { - httpAuthHandler.proceed( - credential.user, - credential.password, - ); - }, - onCancel: () { - httpAuthHandler.cancel(); - }, - host: host, - realm: realm, - ), + requestLoading: + ( + _, + android_webview.WebView webView, + android_webview.WebResourceRequest request, + ) { + weakThis.target?._handleNavigation( + request.url, + headers: + request.requestHeaders?.map(( + String? key, + String? value, + ) { + return MapEntry(key!, value!); + }) ?? + {}, + isForMainFrame: request.isForMainFrame, + ); + }, + urlLoading: (_, android_webview.WebView webView, String url) { + weakThis.target?._handleNavigation(url, isForMainFrame: true); + }, + doUpdateVisitedHistory: + (_, android_webview.WebView webView, String url, bool isReload) { + final UrlChangeCallback? callback = weakThis.target?._onUrlChange; + if (callback != null) { + callback(AndroidUrlChange(url: url, isReload: isReload)); + } + }, + onReceivedHttpAuthRequest: + ( + _, + android_webview.WebView webView, + android_webview.HttpAuthHandler httpAuthHandler, + String host, + String realm, + ) { + final void Function(HttpAuthRequest)? callback = + weakThis.target?._onHttpAuthRequest; + if (callback != null) { + callback( + HttpAuthRequest( + onProceed: (WebViewCredential credential) { + httpAuthHandler.proceed( + credential.user, + credential.password, + ); + }, + onCancel: () { + httpAuthHandler.cancel(); + }, + host: host, + realm: realm, + ), + ); + } else { + httpAuthHandler.cancel(); + } + }, + onFormResubmission: + (_, __, android_webview.AndroidMessage dontResend, ___) { + dontResend.sendToTarget(); + }, + onReceivedClientCertRequest: + (_, __, android_webview.ClientCertRequest request) { + request.cancel(); + }, + onReceivedSslError: + ( + _, + __, + android_webview.SslErrorHandler handler, + android_webview.SslError error, + ) async { + final void Function(PlatformSslAuthError)? callback = + weakThis.target?._onSslAuthError; + + if (callback != null) { + final AndroidSslAuthError authError = + await AndroidSslAuthError.fromNativeCallback( + error: error, + handler: handler, ); - } else { - httpAuthHandler.cancel(); - } - }, - onFormResubmission: - (_, __, android_webview.AndroidMessage dontResend, ___) { - dontResend.sendToTarget(); - }, - onReceivedClientCertRequest: - (_, __, android_webview.ClientCertRequest request) { - request.cancel(); - }, - onReceivedSslError: - ( - _, - __, - android_webview.SslErrorHandler handler, - android_webview.SslError error, - ) async { - final void Function(PlatformSslAuthError)? callback = - weakThis.target?._onSslAuthError; - - if (callback != null) { - final AndroidSslAuthError authError = - await AndroidSslAuthError.fromNativeCallback( - error: error, - handler: handler, - ); - - callback(authError); - } else { - await handler.cancel(); - } - }, - ); - _downloadListener = (this.params as AndroidNavigationDelegateCreationParams) - .androidWebViewProxy - .newDownloadListener( - onDownloadStart: - ( - _, - String url, - String userAgent, - String contentDisposition, - String mimetype, - int contentLength, - ) { - if (weakThis.target != null) { - weakThis.target?._handleNavigation(url, isForMainFrame: true); - } - }, - ); - } + callback(authError); + } else { + await handler.cancel(); + } + }, + ); - AndroidNavigationDelegateCreationParams get _androidParams => - params as AndroidNavigationDelegateCreationParams; + _downloadListener = android_webview.DownloadListener( + onDownloadStart: + ( + _, + String url, + String userAgent, + String contentDisposition, + String mimetype, + int contentLength, + ) { + if (weakThis.target != null) { + weakThis.target?._handleNavigation(url, isForMainFrame: true); + } + }, + ); + } - late final android_webview.WebChromeClient _webChromeClient = _androidParams - .androidWebViewProxy - .newWebChromeClient( + late final android_webview.WebChromeClient _webChromeClient = + android_webview.WebChromeClient( onJsConfirm: (_, __, ___, ____) async => false, onShowFileChooser: (_, __, ___) async => [], ); diff --git a/packages/webview_flutter/webview_flutter_android/pubspec.yaml b/packages/webview_flutter/webview_flutter_android/pubspec.yaml index ce83b556366..0d4e660cc17 100644 --- a/packages/webview_flutter/webview_flutter_android/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_android/pubspec.yaml @@ -2,7 +2,7 @@ name: webview_flutter_android description: A Flutter plugin that provides a WebView widget on Android. repository: https://github.com/flutter/packages/tree/main/packages/webview_flutter/webview_flutter_android issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview%22 -version: 4.10.9 +version: 4.10.10 environment: sdk: ^3.9.0 diff --git a/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.dart b/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.dart index 1b977b76166..29d8ac6d236 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.dart @@ -8,7 +8,6 @@ import 'dart:typed_data'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; -import 'package:webview_flutter_android/src/android_proxy.dart'; import 'package:webview_flutter_android/src/android_webkit.g.dart' as android_webview; import 'package:webview_flutter_android/src/android_webkit_constants.dart'; @@ -729,13 +728,19 @@ void main() { } AndroidNavigationDelegateCreationParams _buildCreationParams() { + android_webview.PigeonOverrides.webViewClient_new = + CapturingWebViewClient.new; + android_webview.PigeonOverrides.webChromeClient_new = + CapturingWebChromeClient.new; + android_webview.PigeonOverrides.downloadListener_new = + CapturingDownloadListener.new; return AndroidNavigationDelegateCreationParams.fromPlatformNavigationDelegateCreationParams( const PlatformNavigationDelegateCreationParams(), - androidWebViewProxy: const AndroidWebViewProxy( - newWebChromeClient: CapturingWebChromeClient.new, - newWebViewClient: CapturingWebViewClient.new, - newDownloadListener: CapturingDownloadListener.new, - ), + // androidWebViewProxy: const AndroidWebViewProxy( + // newWebChromeClient: CapturingWebChromeClient.new, + // newWebViewClient: CapturingWebViewClient.new, + // newDownloadListener: CapturingDownloadListener.new, + // ), ); } diff --git a/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.mocks.dart b/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.mocks.dart index ee1f6258fbf..81e30cf98c9 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.mocks.dart @@ -23,6 +23,7 @@ import 'package:webview_flutter_android/src/android_webkit.g.dart' as _i2; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakePigeonInstanceManager_0 extends _i1.SmartFake implements _i2.PigeonInstanceManager { diff --git a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart index a8bedbffcf4..ee9baec7625 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart @@ -7,7 +7,6 @@ import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; -import 'package:webview_flutter_android/src/android_proxy.dart'; import 'package:webview_flutter_android/src/android_webkit.g.dart' as android_webview; import 'package:webview_flutter_android/src/android_webkit_constants.dart'; @@ -21,7 +20,6 @@ import 'android_webview_controller_test.mocks.dart'; @GenerateNiceMocks(>[ MockSpec(), MockSpec(), - MockSpec(), MockSpec(), MockSpec(), MockSpec(), @@ -115,213 +113,213 @@ void main() { final android_webview.WebView nonNullMockWebView = mockWebView ?? MockWebView(); + android_webview.PigeonOverrides.webChromeClient_new = + createWebChromeClient ?? + ({ + void Function( + android_webview.WebChromeClient, + android_webview.WebView, + int, + )? + onProgressChanged, + Future> Function( + android_webview.WebChromeClient, + android_webview.WebView, + android_webview.FileChooserParams, + )? + onShowFileChooser, + void Function( + android_webview.WebChromeClient, + android_webview.PermissionRequest, + )? + onPermissionRequest, + void Function( + android_webview.WebChromeClient, + android_webview.View, + android_webview.CustomViewCallback, + )? + onShowCustomView, + void Function(android_webview.WebChromeClient)? onHideCustomView, + void Function( + android_webview.WebChromeClient, + String, + android_webview.GeolocationPermissionsCallback, + )? + onGeolocationPermissionsShowPrompt, + void Function(android_webview.WebChromeClient)? + onGeolocationPermissionsHidePrompt, + void Function( + android_webview.WebChromeClient, + android_webview.ConsoleMessage, + )? + onConsoleMessage, + Future Function( + android_webview.WebChromeClient, + android_webview.WebView, + String, + String, + )? + onJsAlert, + Future Function( + android_webview.WebChromeClient, + android_webview.WebView, + String, + String, + )? + onJsConfirm, + Future Function( + android_webview.WebChromeClient, + android_webview.WebView, + String, + String, + String, + )? + onJsPrompt, + }) => MockWebChromeClient(); + android_webview.PigeonOverrides.webView_new = + ({ + dynamic Function( + android_webview.WebView, + int left, + int top, + int oldLeft, + int oldTop, + )? + onScrollChanged, + }) => nonNullMockWebView; + android_webview.PigeonOverrides.webViewClient_new = + ({ + void Function( + android_webview.WebViewClient, + android_webview.WebView, + String, + )? + onPageStarted, + void Function( + android_webview.WebViewClient, + android_webview.WebView, + String, + )? + onPageFinished, + void Function( + android_webview.WebViewClient, + android_webview.WebView, + android_webview.WebResourceRequest, + android_webview.WebResourceResponse, + )? + onReceivedHttpError, + void Function( + android_webview.WebViewClient, + android_webview.WebView, + android_webview.WebResourceRequest, + android_webview.WebResourceError, + )? + onReceivedRequestError, + void Function( + android_webview.WebViewClient, + android_webview.WebView, + android_webview.WebResourceRequest, + android_webview.WebResourceErrorCompat, + )? + onReceivedRequestErrorCompat, + void Function( + android_webview.WebViewClient, + android_webview.WebView, + int, + String, + String, + )? + onReceivedError, + void Function( + android_webview.WebViewClient, + android_webview.WebView, + android_webview.WebResourceRequest, + )? + requestLoading, + void Function( + android_webview.WebViewClient, + android_webview.WebView, + String, + )? + urlLoading, + void Function( + android_webview.WebViewClient, + android_webview.WebView, + String, + bool, + )? + doUpdateVisitedHistory, + void Function( + android_webview.WebViewClient, + android_webview.WebView, + android_webview.HttpAuthHandler, + String, + String, + )? + onReceivedHttpAuthRequest, + void Function( + android_webview.WebViewClient, + android_webview.WebView, + android_webview.AndroidMessage, + android_webview.AndroidMessage, + )? + onFormResubmission, + void Function( + android_webview.WebViewClient, + android_webview.WebView, + String, + )? + onLoadResource, + void Function( + android_webview.WebViewClient, + android_webview.WebView, + String, + )? + onPageCommitVisible, + void Function( + android_webview.WebViewClient, + android_webview.WebView, + android_webview.ClientCertRequest, + )? + onReceivedClientCertRequest, + void Function( + android_webview.WebViewClient, + android_webview.WebView, + String, + String, + String, + )? + onReceivedLoginRequest, + void Function( + android_webview.WebViewClient, + android_webview.WebView, + android_webview.SslErrorHandler, + android_webview.SslError, + )? + onReceivedSslError, + void Function( + android_webview.WebViewClient, + android_webview.WebView, + double, + double, + )? + onScaleChanged, + }) => mockWebViewClient ?? MockWebViewClient(); + android_webview.PigeonOverrides.flutterAssetManager_instance = + mockFlutterAssetManager ?? MockFlutterAssetManager(); + android_webview.PigeonOverrides.javaScriptChannel_new = + ({ + required String channelName, + required void Function(android_webview.JavaScriptChannel, String) + postMessage, + }) => mockJavaScriptChannel ?? MockJavaScriptChannel(); + android_webview.PigeonOverrides.webViewFeature_isFeatureSupported = + isWebViewFeatureSupported ?? (_) async => false; + android_webview.PigeonOverrides.webSettingsCompat_setPaymentRequestEnabled = + setPaymentRequestEnabled ?? (_, __) async {}; + final creationParams = AndroidWebViewControllerCreationParams( androidWebStorage: mockWebStorage ?? MockWebStorage(), - androidWebViewProxy: AndroidWebViewProxy( - newWebChromeClient: - createWebChromeClient ?? - ({ - void Function( - android_webview.WebChromeClient, - android_webview.WebView, - int, - )? - onProgressChanged, - Future> Function( - android_webview.WebChromeClient, - android_webview.WebView, - android_webview.FileChooserParams, - )? - onShowFileChooser, - void Function( - android_webview.WebChromeClient, - android_webview.PermissionRequest, - )? - onPermissionRequest, - void Function( - android_webview.WebChromeClient, - android_webview.View, - android_webview.CustomViewCallback, - )? - onShowCustomView, - void Function(android_webview.WebChromeClient)? onHideCustomView, - void Function( - android_webview.WebChromeClient, - String, - android_webview.GeolocationPermissionsCallback, - )? - onGeolocationPermissionsShowPrompt, - void Function(android_webview.WebChromeClient)? - onGeolocationPermissionsHidePrompt, - void Function( - android_webview.WebChromeClient, - android_webview.ConsoleMessage, - )? - onConsoleMessage, - Future Function( - android_webview.WebChromeClient, - android_webview.WebView, - String, - String, - )? - onJsAlert, - Future Function( - android_webview.WebChromeClient, - android_webview.WebView, - String, - String, - )? - onJsConfirm, - Future Function( - android_webview.WebChromeClient, - android_webview.WebView, - String, - String, - String, - )? - onJsPrompt, - }) => MockWebChromeClient(), - newWebView: - ({ - dynamic Function( - android_webview.WebView, - int left, - int top, - int oldLeft, - int oldTop, - )? - onScrollChanged, - }) => nonNullMockWebView, - newWebViewClient: - ({ - void Function( - android_webview.WebViewClient, - android_webview.WebView, - String, - )? - onPageStarted, - void Function( - android_webview.WebViewClient, - android_webview.WebView, - String, - )? - onPageFinished, - void Function( - android_webview.WebViewClient, - android_webview.WebView, - android_webview.WebResourceRequest, - android_webview.WebResourceResponse, - )? - onReceivedHttpError, - void Function( - android_webview.WebViewClient, - android_webview.WebView, - android_webview.WebResourceRequest, - android_webview.WebResourceError, - )? - onReceivedRequestError, - void Function( - android_webview.WebViewClient, - android_webview.WebView, - android_webview.WebResourceRequest, - android_webview.WebResourceErrorCompat, - )? - onReceivedRequestErrorCompat, - void Function( - android_webview.WebViewClient, - android_webview.WebView, - int, - String, - String, - )? - onReceivedError, - void Function( - android_webview.WebViewClient, - android_webview.WebView, - android_webview.WebResourceRequest, - )? - requestLoading, - void Function( - android_webview.WebViewClient, - android_webview.WebView, - String, - )? - urlLoading, - void Function( - android_webview.WebViewClient, - android_webview.WebView, - String, - bool, - )? - doUpdateVisitedHistory, - void Function( - android_webview.WebViewClient, - android_webview.WebView, - android_webview.HttpAuthHandler, - String, - String, - )? - onReceivedHttpAuthRequest, - void Function( - android_webview.WebViewClient, - android_webview.WebView, - android_webview.AndroidMessage, - android_webview.AndroidMessage, - )? - onFormResubmission, - void Function( - android_webview.WebViewClient, - android_webview.WebView, - String, - )? - onLoadResource, - void Function( - android_webview.WebViewClient, - android_webview.WebView, - String, - )? - onPageCommitVisible, - void Function( - android_webview.WebViewClient, - android_webview.WebView, - android_webview.ClientCertRequest, - )? - onReceivedClientCertRequest, - void Function( - android_webview.WebViewClient, - android_webview.WebView, - String, - String, - String, - )? - onReceivedLoginRequest, - void Function( - android_webview.WebViewClient, - android_webview.WebView, - android_webview.SslErrorHandler, - android_webview.SslError, - )? - onReceivedSslError, - void Function( - android_webview.WebViewClient, - android_webview.WebView, - double, - double, - )? - onScaleChanged, - }) => mockWebViewClient ?? MockWebViewClient(), - instanceFlutterAssetManager: () => - mockFlutterAssetManager ?? MockFlutterAssetManager(), - newJavaScriptChannel: - ({ - required String channelName, - required void Function(android_webview.JavaScriptChannel, String) - postMessage, - }) => mockJavaScriptChannel ?? MockJavaScriptChannel(), - isWebViewFeatureSupported: - isWebViewFeatureSupported ?? (_) async => false, - setPaymentRequestEnabled: setPaymentRequestEnabled ?? (_, __) async {}, - ), ); when( @@ -331,26 +329,25 @@ void main() { return AndroidWebViewController(creationParams); } + setUp(() { + android_webview.PigeonOverrides.pigeon_reset(); + }); + group('AndroidWebViewController', () { AndroidJavaScriptChannelParams createAndroidJavaScriptChannelParamsWithMocks({ String? name, MockJavaScriptChannel? mockJavaScriptChannel, }) { + android_webview.PigeonOverrides.javaScriptChannel_new = + ({ + required String channelName, + required void Function(android_webview.JavaScriptChannel, String) + postMessage, + }) => mockJavaScriptChannel ?? MockJavaScriptChannel(); return AndroidJavaScriptChannelParams( name: name ?? 'test', onMessageReceived: (JavaScriptMessage message) {}, - webViewProxy: AndroidWebViewProxy( - newJavaScriptChannel: - ({ - required String channelName, - required void Function( - android_webview.JavaScriptChannel, - String, - ) - postMessage, - }) => mockJavaScriptChannel ?? MockJavaScriptChannel(), - ), ); } @@ -910,14 +907,15 @@ void main() { }); test('onProgress', () { + android_webview.PigeonOverrides.webViewClient_new = TestWebViewClient.new; + android_webview.PigeonOverrides.webChromeClient_new = + TestWebChromeClient.new; + android_webview.PigeonOverrides.downloadListener_new = + TestDownloadListener.new; + final androidNavigationDelegate = AndroidNavigationDelegate( AndroidNavigationDelegateCreationParams.fromPlatformNavigationDelegateCreationParams( const PlatformNavigationDelegateCreationParams(), - androidWebViewProxy: const AndroidWebViewProxy( - newWebViewClient: TestWebViewClient.new, - newWebChromeClient: TestWebChromeClient.new, - newDownloadListener: TestDownloadListener.new, - ), ), ); diff --git a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.mocks.dart b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.mocks.dart index cde0f4c97a0..e5776a14a1a 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.mocks.dart @@ -4,15 +4,14 @@ // ignore_for_file: no_leading_underscores_for_library_prefixes import 'dart:async' as _i8; -import 'dart:typed_data' as _i13; +import 'dart:typed_data' as _i12; import 'dart:ui' as _i4; -import 'package:flutter/foundation.dart' as _i10; -import 'package:flutter/gestures.dart' as _i11; +import 'package:flutter/foundation.dart' as _i9; +import 'package:flutter/gestures.dart' as _i10; import 'package:flutter/services.dart' as _i6; import 'package:mockito/mockito.dart' as _i1; -import 'package:mockito/src/dummies.dart' as _i12; -import 'package:webview_flutter_android/src/android_proxy.dart' as _i9; +import 'package:mockito/src/dummies.dart' as _i11; import 'package:webview_flutter_android/src/android_webkit.g.dart' as _i2; import 'package:webview_flutter_android/src/android_webview_controller.dart' as _i7; @@ -34,6 +33,7 @@ import 'package:webview_flutter_platform_interface/webview_flutter_platform_inte // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakeWebChromeClient_0 extends _i1.SmartFake implements _i2.WebChromeClient { @@ -78,93 +78,88 @@ class _FakeOffset_6 extends _i1.SmartFake implements _i4.Offset { : super(parent, parentInvocation); } -class _FakeWebView_7 extends _i1.SmartFake implements _i2.WebView { - _FakeWebView_7(Object parent, Invocation parentInvocation) - : super(parent, parentInvocation); -} - -class _FakeJavaScriptChannel_8 extends _i1.SmartFake - implements _i2.JavaScriptChannel { - _FakeJavaScriptChannel_8(Object parent, Invocation parentInvocation) - : super(parent, parentInvocation); -} - -class _FakeCookieManager_9 extends _i1.SmartFake implements _i2.CookieManager { - _FakeCookieManager_9(Object parent, Invocation parentInvocation) - : super(parent, parentInvocation); -} - -class _FakeFlutterAssetManager_10 extends _i1.SmartFake - implements _i2.FlutterAssetManager { - _FakeFlutterAssetManager_10(Object parent, Invocation parentInvocation) - : super(parent, parentInvocation); -} - -class _FakeWebStorage_11 extends _i1.SmartFake implements _i2.WebStorage { - _FakeWebStorage_11(Object parent, Invocation parentInvocation) - : super(parent, parentInvocation); -} - -class _FakePigeonInstanceManager_12 extends _i1.SmartFake +class _FakePigeonInstanceManager_7 extends _i1.SmartFake implements _i2.PigeonInstanceManager { - _FakePigeonInstanceManager_12(Object parent, Invocation parentInvocation) + _FakePigeonInstanceManager_7(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakePlatformViewsServiceProxy_13 extends _i1.SmartFake +class _FakePlatformViewsServiceProxy_8 extends _i1.SmartFake implements _i5.PlatformViewsServiceProxy { - _FakePlatformViewsServiceProxy_13(Object parent, Invocation parentInvocation) + _FakePlatformViewsServiceProxy_8(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakePlatformWebViewController_14 extends _i1.SmartFake +class _FakePlatformWebViewController_9 extends _i1.SmartFake implements _i3.PlatformWebViewController { - _FakePlatformWebViewController_14(Object parent, Invocation parentInvocation) + _FakePlatformWebViewController_9(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} + +class _FakeSize_10 extends _i1.SmartFake implements _i4.Size { + _FakeSize_10(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakeSize_15 extends _i1.SmartFake implements _i4.Size { - _FakeSize_15(Object parent, Invocation parentInvocation) +class _FakeFlutterAssetManager_11 extends _i1.SmartFake + implements _i2.FlutterAssetManager { + _FakeFlutterAssetManager_11(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakeGeolocationPermissionsCallback_16 extends _i1.SmartFake +class _FakeGeolocationPermissionsCallback_12 extends _i1.SmartFake implements _i2.GeolocationPermissionsCallback { - _FakeGeolocationPermissionsCallback_16( + _FakeGeolocationPermissionsCallback_12( Object parent, Invocation parentInvocation, ) : super(parent, parentInvocation); } -class _FakePermissionRequest_17 extends _i1.SmartFake +class _FakeJavaScriptChannel_13 extends _i1.SmartFake + implements _i2.JavaScriptChannel { + _FakeJavaScriptChannel_13(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} + +class _FakePermissionRequest_14 extends _i1.SmartFake implements _i2.PermissionRequest { - _FakePermissionRequest_17(Object parent, Invocation parentInvocation) + _FakePermissionRequest_14(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakeExpensiveAndroidViewController_18 extends _i1.SmartFake +class _FakeExpensiveAndroidViewController_15 extends _i1.SmartFake implements _i6.ExpensiveAndroidViewController { - _FakeExpensiveAndroidViewController_18( + _FakeExpensiveAndroidViewController_15( Object parent, Invocation parentInvocation, ) : super(parent, parentInvocation); } -class _FakeSurfaceAndroidViewController_19 extends _i1.SmartFake +class _FakeSurfaceAndroidViewController_16 extends _i1.SmartFake implements _i6.SurfaceAndroidViewController { - _FakeSurfaceAndroidViewController_19( + _FakeSurfaceAndroidViewController_16( Object parent, Invocation parentInvocation, ) : super(parent, parentInvocation); } -class _FakeWebSettings_20 extends _i1.SmartFake implements _i2.WebSettings { - _FakeWebSettings_20(Object parent, Invocation parentInvocation) +class _FakeWebSettings_17 extends _i1.SmartFake implements _i2.WebSettings { + _FakeWebSettings_17(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } -class _FakeWebViewPoint_21 extends _i1.SmartFake implements _i2.WebViewPoint { - _FakeWebViewPoint_21(Object parent, Invocation parentInvocation) +class _FakeWebView_18 extends _i1.SmartFake implements _i2.WebView { + _FakeWebView_18(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} + +class _FakeWebViewPoint_19 extends _i1.SmartFake implements _i2.WebViewPoint { + _FakeWebViewPoint_19(Object parent, Invocation parentInvocation) + : super(parent, parentInvocation); +} + +class _FakeWebStorage_20 extends _i1.SmartFake implements _i2.WebStorage { + _FakeWebStorage_20(Object parent, Invocation parentInvocation) : super(parent, parentInvocation); } @@ -867,716 +862,6 @@ class MockAndroidWebViewController extends _i1.Mock as _i8.Future); } -/// A class which mocks [AndroidWebViewProxy]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockAndroidWebViewProxy extends _i1.Mock - implements _i9.AndroidWebViewProxy { - @override - _i2.WebView Function({ - void Function(_i2.WebView, int, int, int, int)? onScrollChanged, - }) - get newWebView => - (super.noSuchMethod( - Invocation.getter(#newWebView), - returnValue: - ({ - void Function(_i2.WebView, int, int, int, int)? - onScrollChanged, - }) => _FakeWebView_7(this, Invocation.getter(#newWebView)), - returnValueForMissingStub: - ({ - void Function(_i2.WebView, int, int, int, int)? - onScrollChanged, - }) => _FakeWebView_7(this, Invocation.getter(#newWebView)), - ) - as _i2.WebView Function({ - void Function(_i2.WebView, int, int, int, int)? onScrollChanged, - })); - - @override - _i2.JavaScriptChannel Function({ - required String channelName, - required void Function(_i2.JavaScriptChannel, String) postMessage, - }) - get newJavaScriptChannel => - (super.noSuchMethod( - Invocation.getter(#newJavaScriptChannel), - returnValue: - ({ - required String channelName, - required void Function(_i2.JavaScriptChannel, String) - postMessage, - }) => _FakeJavaScriptChannel_8( - this, - Invocation.getter(#newJavaScriptChannel), - ), - returnValueForMissingStub: - ({ - required String channelName, - required void Function(_i2.JavaScriptChannel, String) - postMessage, - }) => _FakeJavaScriptChannel_8( - this, - Invocation.getter(#newJavaScriptChannel), - ), - ) - as _i2.JavaScriptChannel Function({ - required String channelName, - required void Function(_i2.JavaScriptChannel, String) postMessage, - })); - - @override - _i2.WebViewClient Function({ - void Function(_i2.WebViewClient, _i2.WebView, String, bool)? - doUpdateVisitedHistory, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.AndroidMessage, - _i2.AndroidMessage, - )? - onFormResubmission, - void Function(_i2.WebViewClient, _i2.WebView, String)? onLoadResource, - void Function(_i2.WebViewClient, _i2.WebView, String)? onPageCommitVisible, - void Function(_i2.WebViewClient, _i2.WebView, String)? onPageFinished, - void Function(_i2.WebViewClient, _i2.WebView, String)? onPageStarted, - void Function(_i2.WebViewClient, _i2.WebView, _i2.ClientCertRequest)? - onReceivedClientCertRequest, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.HttpAuthHandler, - String, - String, - )? - onReceivedHttpAuthRequest, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.WebResourceRequest, - _i2.WebResourceResponse, - )? - onReceivedHttpError, - void Function(_i2.WebViewClient, _i2.WebView, String, String?, String)? - onReceivedLoginRequest, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.WebResourceRequest, - _i2.WebResourceError, - )? - onReceivedRequestError, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.WebResourceRequest, - _i2.WebResourceErrorCompat, - )? - onReceivedRequestErrorCompat, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.SslErrorHandler, - _i2.SslError, - )? - onReceivedSslError, - void Function(_i2.WebViewClient, _i2.WebView, double, double)? - onScaleChanged, - void Function(_i2.WebViewClient, _i2.WebView, _i2.WebResourceRequest)? - requestLoading, - void Function(_i2.WebViewClient, _i2.WebView, String)? urlLoading, - }) - get newWebViewClient => - (super.noSuchMethod( - Invocation.getter(#newWebViewClient), - returnValue: - ({ - void Function(_i2.WebViewClient, _i2.WebView, String, bool)? - doUpdateVisitedHistory, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.AndroidMessage, - _i2.AndroidMessage, - )? - onFormResubmission, - void Function(_i2.WebViewClient, _i2.WebView, String)? - onLoadResource, - void Function(_i2.WebViewClient, _i2.WebView, String)? - onPageCommitVisible, - void Function(_i2.WebViewClient, _i2.WebView, String)? - onPageFinished, - void Function(_i2.WebViewClient, _i2.WebView, String)? - onPageStarted, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.ClientCertRequest, - )? - onReceivedClientCertRequest, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.HttpAuthHandler, - String, - String, - )? - onReceivedHttpAuthRequest, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.WebResourceRequest, - _i2.WebResourceResponse, - )? - onReceivedHttpError, - void Function( - _i2.WebViewClient, - _i2.WebView, - String, - String?, - String, - )? - onReceivedLoginRequest, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.WebResourceRequest, - _i2.WebResourceError, - )? - onReceivedRequestError, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.WebResourceRequest, - _i2.WebResourceErrorCompat, - )? - onReceivedRequestErrorCompat, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.SslErrorHandler, - _i2.SslError, - )? - onReceivedSslError, - void Function(_i2.WebViewClient, _i2.WebView, double, double)? - onScaleChanged, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.WebResourceRequest, - )? - requestLoading, - void Function(_i2.WebViewClient, _i2.WebView, String)? - urlLoading, - }) => _FakeWebViewClient_1( - this, - Invocation.getter(#newWebViewClient), - ), - returnValueForMissingStub: - ({ - void Function(_i2.WebViewClient, _i2.WebView, String, bool)? - doUpdateVisitedHistory, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.AndroidMessage, - _i2.AndroidMessage, - )? - onFormResubmission, - void Function(_i2.WebViewClient, _i2.WebView, String)? - onLoadResource, - void Function(_i2.WebViewClient, _i2.WebView, String)? - onPageCommitVisible, - void Function(_i2.WebViewClient, _i2.WebView, String)? - onPageFinished, - void Function(_i2.WebViewClient, _i2.WebView, String)? - onPageStarted, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.ClientCertRequest, - )? - onReceivedClientCertRequest, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.HttpAuthHandler, - String, - String, - )? - onReceivedHttpAuthRequest, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.WebResourceRequest, - _i2.WebResourceResponse, - )? - onReceivedHttpError, - void Function( - _i2.WebViewClient, - _i2.WebView, - String, - String?, - String, - )? - onReceivedLoginRequest, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.WebResourceRequest, - _i2.WebResourceError, - )? - onReceivedRequestError, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.WebResourceRequest, - _i2.WebResourceErrorCompat, - )? - onReceivedRequestErrorCompat, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.SslErrorHandler, - _i2.SslError, - )? - onReceivedSslError, - void Function(_i2.WebViewClient, _i2.WebView, double, double)? - onScaleChanged, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.WebResourceRequest, - )? - requestLoading, - void Function(_i2.WebViewClient, _i2.WebView, String)? - urlLoading, - }) => _FakeWebViewClient_1( - this, - Invocation.getter(#newWebViewClient), - ), - ) - as _i2.WebViewClient Function({ - void Function(_i2.WebViewClient, _i2.WebView, String, bool)? - doUpdateVisitedHistory, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.AndroidMessage, - _i2.AndroidMessage, - )? - onFormResubmission, - void Function(_i2.WebViewClient, _i2.WebView, String)? - onLoadResource, - void Function(_i2.WebViewClient, _i2.WebView, String)? - onPageCommitVisible, - void Function(_i2.WebViewClient, _i2.WebView, String)? - onPageFinished, - void Function(_i2.WebViewClient, _i2.WebView, String)? - onPageStarted, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.ClientCertRequest, - )? - onReceivedClientCertRequest, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.HttpAuthHandler, - String, - String, - )? - onReceivedHttpAuthRequest, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.WebResourceRequest, - _i2.WebResourceResponse, - )? - onReceivedHttpError, - void Function( - _i2.WebViewClient, - _i2.WebView, - String, - String?, - String, - )? - onReceivedLoginRequest, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.WebResourceRequest, - _i2.WebResourceError, - )? - onReceivedRequestError, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.WebResourceRequest, - _i2.WebResourceErrorCompat, - )? - onReceivedRequestErrorCompat, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.SslErrorHandler, - _i2.SslError, - )? - onReceivedSslError, - void Function(_i2.WebViewClient, _i2.WebView, double, double)? - onScaleChanged, - void Function( - _i2.WebViewClient, - _i2.WebView, - _i2.WebResourceRequest, - )? - requestLoading, - void Function(_i2.WebViewClient, _i2.WebView, String)? urlLoading, - })); - - @override - _i2.DownloadListener Function({ - required void Function( - _i2.DownloadListener, - String, - String, - String, - String, - int, - ) - onDownloadStart, - }) - get newDownloadListener => - (super.noSuchMethod( - Invocation.getter(#newDownloadListener), - returnValue: - ({ - required void Function( - _i2.DownloadListener, - String, - String, - String, - String, - int, - ) - onDownloadStart, - }) => _FakeDownloadListener_2( - this, - Invocation.getter(#newDownloadListener), - ), - returnValueForMissingStub: - ({ - required void Function( - _i2.DownloadListener, - String, - String, - String, - String, - int, - ) - onDownloadStart, - }) => _FakeDownloadListener_2( - this, - Invocation.getter(#newDownloadListener), - ), - ) - as _i2.DownloadListener Function({ - required void Function( - _i2.DownloadListener, - String, - String, - String, - String, - int, - ) - onDownloadStart, - })); - - @override - _i2.WebChromeClient Function({ - required _i8.Future Function( - _i2.WebChromeClient, - _i2.WebView, - String, - String, - ) - onJsConfirm, - required _i8.Future> Function( - _i2.WebChromeClient, - _i2.WebView, - _i2.FileChooserParams, - ) - onShowFileChooser, - void Function(_i2.WebChromeClient, _i2.ConsoleMessage)? onConsoleMessage, - void Function(_i2.WebChromeClient)? onGeolocationPermissionsHidePrompt, - void Function( - _i2.WebChromeClient, - String, - _i2.GeolocationPermissionsCallback, - )? - onGeolocationPermissionsShowPrompt, - void Function(_i2.WebChromeClient)? onHideCustomView, - _i8.Future Function(_i2.WebChromeClient, _i2.WebView, String, String)? - onJsAlert, - _i8.Future Function( - _i2.WebChromeClient, - _i2.WebView, - String, - String, - String, - )? - onJsPrompt, - void Function(_i2.WebChromeClient, _i2.PermissionRequest)? - onPermissionRequest, - void Function(_i2.WebChromeClient, _i2.WebView, int)? onProgressChanged, - void Function(_i2.WebChromeClient, _i2.View, _i2.CustomViewCallback)? - onShowCustomView, - }) - get newWebChromeClient => - (super.noSuchMethod( - Invocation.getter(#newWebChromeClient), - returnValue: - ({ - void Function(_i2.WebChromeClient, _i2.ConsoleMessage)? - onConsoleMessage, - void Function(_i2.WebChromeClient)? - onGeolocationPermissionsHidePrompt, - void Function( - _i2.WebChromeClient, - String, - _i2.GeolocationPermissionsCallback, - )? - onGeolocationPermissionsShowPrompt, - void Function(_i2.WebChromeClient)? onHideCustomView, - _i8.Future Function( - _i2.WebChromeClient, - _i2.WebView, - String, - String, - )? - onJsAlert, - required _i8.Future Function( - _i2.WebChromeClient, - _i2.WebView, - String, - String, - ) - onJsConfirm, - _i8.Future Function( - _i2.WebChromeClient, - _i2.WebView, - String, - String, - String, - )? - onJsPrompt, - void Function(_i2.WebChromeClient, _i2.PermissionRequest)? - onPermissionRequest, - void Function(_i2.WebChromeClient, _i2.WebView, int)? - onProgressChanged, - void Function( - _i2.WebChromeClient, - _i2.View, - _i2.CustomViewCallback, - )? - onShowCustomView, - required _i8.Future> Function( - _i2.WebChromeClient, - _i2.WebView, - _i2.FileChooserParams, - ) - onShowFileChooser, - }) => _FakeWebChromeClient_0( - this, - Invocation.getter(#newWebChromeClient), - ), - returnValueForMissingStub: - ({ - void Function(_i2.WebChromeClient, _i2.ConsoleMessage)? - onConsoleMessage, - void Function(_i2.WebChromeClient)? - onGeolocationPermissionsHidePrompt, - void Function( - _i2.WebChromeClient, - String, - _i2.GeolocationPermissionsCallback, - )? - onGeolocationPermissionsShowPrompt, - void Function(_i2.WebChromeClient)? onHideCustomView, - _i8.Future Function( - _i2.WebChromeClient, - _i2.WebView, - String, - String, - )? - onJsAlert, - required _i8.Future Function( - _i2.WebChromeClient, - _i2.WebView, - String, - String, - ) - onJsConfirm, - _i8.Future Function( - _i2.WebChromeClient, - _i2.WebView, - String, - String, - String, - )? - onJsPrompt, - void Function(_i2.WebChromeClient, _i2.PermissionRequest)? - onPermissionRequest, - void Function(_i2.WebChromeClient, _i2.WebView, int)? - onProgressChanged, - void Function( - _i2.WebChromeClient, - _i2.View, - _i2.CustomViewCallback, - )? - onShowCustomView, - required _i8.Future> Function( - _i2.WebChromeClient, - _i2.WebView, - _i2.FileChooserParams, - ) - onShowFileChooser, - }) => _FakeWebChromeClient_0( - this, - Invocation.getter(#newWebChromeClient), - ), - ) - as _i2.WebChromeClient Function({ - required _i8.Future Function( - _i2.WebChromeClient, - _i2.WebView, - String, - String, - ) - onJsConfirm, - required _i8.Future> Function( - _i2.WebChromeClient, - _i2.WebView, - _i2.FileChooserParams, - ) - onShowFileChooser, - void Function(_i2.WebChromeClient, _i2.ConsoleMessage)? - onConsoleMessage, - void Function(_i2.WebChromeClient)? - onGeolocationPermissionsHidePrompt, - void Function( - _i2.WebChromeClient, - String, - _i2.GeolocationPermissionsCallback, - )? - onGeolocationPermissionsShowPrompt, - void Function(_i2.WebChromeClient)? onHideCustomView, - _i8.Future Function( - _i2.WebChromeClient, - _i2.WebView, - String, - String, - )? - onJsAlert, - _i8.Future Function( - _i2.WebChromeClient, - _i2.WebView, - String, - String, - String, - )? - onJsPrompt, - void Function(_i2.WebChromeClient, _i2.PermissionRequest)? - onPermissionRequest, - void Function(_i2.WebChromeClient, _i2.WebView, int)? - onProgressChanged, - void Function( - _i2.WebChromeClient, - _i2.View, - _i2.CustomViewCallback, - )? - onShowCustomView, - })); - - @override - _i8.Future Function(bool) get setWebContentsDebuggingEnabledWebView => - (super.noSuchMethod( - Invocation.getter(#setWebContentsDebuggingEnabledWebView), - returnValue: (bool __p0) => _i8.Future.value(), - returnValueForMissingStub: (bool __p0) => _i8.Future.value(), - ) - as _i8.Future Function(bool)); - - @override - _i2.CookieManager Function() get instanceCookieManager => - (super.noSuchMethod( - Invocation.getter(#instanceCookieManager), - returnValue: () => _FakeCookieManager_9( - this, - Invocation.getter(#instanceCookieManager), - ), - returnValueForMissingStub: () => _FakeCookieManager_9( - this, - Invocation.getter(#instanceCookieManager), - ), - ) - as _i2.CookieManager Function()); - - @override - _i2.FlutterAssetManager Function() get instanceFlutterAssetManager => - (super.noSuchMethod( - Invocation.getter(#instanceFlutterAssetManager), - returnValue: () => _FakeFlutterAssetManager_10( - this, - Invocation.getter(#instanceFlutterAssetManager), - ), - returnValueForMissingStub: () => _FakeFlutterAssetManager_10( - this, - Invocation.getter(#instanceFlutterAssetManager), - ), - ) - as _i2.FlutterAssetManager Function()); - - @override - _i2.WebStorage Function() get instanceWebStorage => - (super.noSuchMethod( - Invocation.getter(#instanceWebStorage), - returnValue: () => _FakeWebStorage_11( - this, - Invocation.getter(#instanceWebStorage), - ), - returnValueForMissingStub: () => _FakeWebStorage_11( - this, - Invocation.getter(#instanceWebStorage), - ), - ) - as _i2.WebStorage Function()); - - @override - _i8.Future Function(String) get isWebViewFeatureSupported => - (super.noSuchMethod( - Invocation.getter(#isWebViewFeatureSupported), - returnValue: (String __p0) => _i8.Future.value(false), - returnValueForMissingStub: (String __p0) => - _i8.Future.value(false), - ) - as _i8.Future Function(String)); - - @override - _i8.Future Function(_i2.WebSettings, bool) - get setPaymentRequestEnabled => - (super.noSuchMethod( - Invocation.getter(#setPaymentRequestEnabled), - returnValue: (_i2.WebSettings __p0, bool __p1) => - _i8.Future.value(), - returnValueForMissingStub: (_i2.WebSettings __p0, bool __p1) => - _i8.Future.value(), - ) - as _i8.Future Function(_i2.WebSettings, bool)); -} - /// A class which mocks [AndroidWebViewWidgetCreationParams]. /// /// See the documentation for Mockito's code generation for more information. @@ -1587,11 +872,11 @@ class MockAndroidWebViewWidgetCreationParams extends _i1.Mock _i2.PigeonInstanceManager get instanceManager => (super.noSuchMethod( Invocation.getter(#instanceManager), - returnValue: _FakePigeonInstanceManager_12( + returnValue: _FakePigeonInstanceManager_7( this, Invocation.getter(#instanceManager), ), - returnValueForMissingStub: _FakePigeonInstanceManager_12( + returnValueForMissingStub: _FakePigeonInstanceManager_7( this, Invocation.getter(#instanceManager), ), @@ -1602,11 +887,11 @@ class MockAndroidWebViewWidgetCreationParams extends _i1.Mock _i5.PlatformViewsServiceProxy get platformViewsServiceProxy => (super.noSuchMethod( Invocation.getter(#platformViewsServiceProxy), - returnValue: _FakePlatformViewsServiceProxy_13( + returnValue: _FakePlatformViewsServiceProxy_8( this, Invocation.getter(#platformViewsServiceProxy), ), - returnValueForMissingStub: _FakePlatformViewsServiceProxy_13( + returnValueForMissingStub: _FakePlatformViewsServiceProxy_8( this, Invocation.getter(#platformViewsServiceProxy), ), @@ -1626,11 +911,11 @@ class MockAndroidWebViewWidgetCreationParams extends _i1.Mock _i3.PlatformWebViewController get controller => (super.noSuchMethod( Invocation.getter(#controller), - returnValue: _FakePlatformWebViewController_14( + returnValue: _FakePlatformWebViewController_9( this, Invocation.getter(#controller), ), - returnValueForMissingStub: _FakePlatformWebViewController_14( + returnValueForMissingStub: _FakePlatformWebViewController_9( this, Invocation.getter(#controller), ), @@ -1647,14 +932,14 @@ class MockAndroidWebViewWidgetCreationParams extends _i1.Mock as _i4.TextDirection); @override - Set<_i10.Factory<_i11.OneSequenceGestureRecognizer>> get gestureRecognizers => + Set<_i9.Factory<_i10.OneSequenceGestureRecognizer>> get gestureRecognizers => (super.noSuchMethod( Invocation.getter(#gestureRecognizers), - returnValue: <_i10.Factory<_i11.OneSequenceGestureRecognizer>>{}, + returnValue: <_i9.Factory<_i10.OneSequenceGestureRecognizer>>{}, returnValueForMissingStub: - <_i10.Factory<_i11.OneSequenceGestureRecognizer>>{}, + <_i9.Factory<_i10.OneSequenceGestureRecognizer>>{}, ) - as Set<_i10.Factory<_i11.OneSequenceGestureRecognizer>>); + as Set<_i9.Factory<_i10.OneSequenceGestureRecognizer>>); } /// A class which mocks [ExpensiveAndroidViewController]. @@ -1747,10 +1032,10 @@ class MockExpensiveAndroidViewController extends _i1.Mock (super.noSuchMethod( Invocation.method(#setSize, [size]), returnValue: _i8.Future<_i4.Size>.value( - _FakeSize_15(this, Invocation.method(#setSize, [size])), + _FakeSize_10(this, Invocation.method(#setSize, [size])), ), returnValueForMissingStub: _i8.Future<_i4.Size>.value( - _FakeSize_15(this, Invocation.method(#setSize, [size])), + _FakeSize_10(this, Invocation.method(#setSize, [size])), ), ) as _i8.Future<_i4.Size>); @@ -1790,7 +1075,7 @@ class MockExpensiveAndroidViewController extends _i1.Mock as _i8.Future); @override - _i8.Future dispatchPointerEvent(_i11.PointerEvent? event) => + _i8.Future dispatchPointerEvent(_i10.PointerEvent? event) => (super.noSuchMethod( Invocation.method(#dispatchPointerEvent, [event]), returnValue: _i8.Future.value(), @@ -1826,11 +1111,11 @@ class MockFlutterAssetManager extends _i1.Mock _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( Invocation.getter(#pigeon_instanceManager), - returnValue: _FakePigeonInstanceManager_12( + returnValue: _FakePigeonInstanceManager_7( this, Invocation.getter(#pigeon_instanceManager), ), - returnValueForMissingStub: _FakePigeonInstanceManager_12( + returnValueForMissingStub: _FakePigeonInstanceManager_7( this, Invocation.getter(#pigeon_instanceManager), ), @@ -1853,13 +1138,13 @@ class MockFlutterAssetManager extends _i1.Mock (super.noSuchMethod( Invocation.method(#getAssetFilePathByName, [name]), returnValue: _i8.Future.value( - _i12.dummyValue( + _i11.dummyValue( this, Invocation.method(#getAssetFilePathByName, [name]), ), ), returnValueForMissingStub: _i8.Future.value( - _i12.dummyValue( + _i11.dummyValue( this, Invocation.method(#getAssetFilePathByName, [name]), ), @@ -1871,11 +1156,11 @@ class MockFlutterAssetManager extends _i1.Mock _i2.FlutterAssetManager pigeon_copy() => (super.noSuchMethod( Invocation.method(#pigeon_copy, []), - returnValue: _FakeFlutterAssetManager_10( + returnValue: _FakeFlutterAssetManager_11( this, Invocation.method(#pigeon_copy, []), ), - returnValueForMissingStub: _FakeFlutterAssetManager_10( + returnValueForMissingStub: _FakeFlutterAssetManager_11( this, Invocation.method(#pigeon_copy, []), ), @@ -1892,11 +1177,11 @@ class MockGeolocationPermissionsCallback extends _i1.Mock _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( Invocation.getter(#pigeon_instanceManager), - returnValue: _FakePigeonInstanceManager_12( + returnValue: _FakePigeonInstanceManager_7( this, Invocation.getter(#pigeon_instanceManager), ), - returnValueForMissingStub: _FakePigeonInstanceManager_12( + returnValueForMissingStub: _FakePigeonInstanceManager_7( this, Invocation.getter(#pigeon_instanceManager), ), @@ -1916,11 +1201,11 @@ class MockGeolocationPermissionsCallback extends _i1.Mock _i2.GeolocationPermissionsCallback pigeon_copy() => (super.noSuchMethod( Invocation.method(#pigeon_copy, []), - returnValue: _FakeGeolocationPermissionsCallback_16( + returnValue: _FakeGeolocationPermissionsCallback_12( this, Invocation.method(#pigeon_copy, []), ), - returnValueForMissingStub: _FakeGeolocationPermissionsCallback_16( + returnValueForMissingStub: _FakeGeolocationPermissionsCallback_12( this, Invocation.method(#pigeon_copy, []), ), @@ -1936,11 +1221,11 @@ class MockJavaScriptChannel extends _i1.Mock implements _i2.JavaScriptChannel { String get channelName => (super.noSuchMethod( Invocation.getter(#channelName), - returnValue: _i12.dummyValue( + returnValue: _i11.dummyValue( this, Invocation.getter(#channelName), ), - returnValueForMissingStub: _i12.dummyValue( + returnValueForMissingStub: _i11.dummyValue( this, Invocation.getter(#channelName), ), @@ -1962,11 +1247,11 @@ class MockJavaScriptChannel extends _i1.Mock implements _i2.JavaScriptChannel { _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( Invocation.getter(#pigeon_instanceManager), - returnValue: _FakePigeonInstanceManager_12( + returnValue: _FakePigeonInstanceManager_7( this, Invocation.getter(#pigeon_instanceManager), ), - returnValueForMissingStub: _FakePigeonInstanceManager_12( + returnValueForMissingStub: _FakePigeonInstanceManager_7( this, Invocation.getter(#pigeon_instanceManager), ), @@ -1977,11 +1262,11 @@ class MockJavaScriptChannel extends _i1.Mock implements _i2.JavaScriptChannel { _i2.JavaScriptChannel pigeon_copy() => (super.noSuchMethod( Invocation.method(#pigeon_copy, []), - returnValue: _FakeJavaScriptChannel_8( + returnValue: _FakeJavaScriptChannel_13( this, Invocation.method(#pigeon_copy, []), ), - returnValueForMissingStub: _FakeJavaScriptChannel_8( + returnValueForMissingStub: _FakeJavaScriptChannel_13( this, Invocation.method(#pigeon_copy, []), ), @@ -2006,11 +1291,11 @@ class MockPermissionRequest extends _i1.Mock implements _i2.PermissionRequest { _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( Invocation.getter(#pigeon_instanceManager), - returnValue: _FakePigeonInstanceManager_12( + returnValue: _FakePigeonInstanceManager_7( this, Invocation.getter(#pigeon_instanceManager), ), - returnValueForMissingStub: _FakePigeonInstanceManager_12( + returnValueForMissingStub: _FakePigeonInstanceManager_7( this, Invocation.getter(#pigeon_instanceManager), ), @@ -2039,11 +1324,11 @@ class MockPermissionRequest extends _i1.Mock implements _i2.PermissionRequest { _i2.PermissionRequest pigeon_copy() => (super.noSuchMethod( Invocation.method(#pigeon_copy, []), - returnValue: _FakePermissionRequest_17( + returnValue: _FakePermissionRequest_14( this, Invocation.method(#pigeon_copy, []), ), - returnValueForMissingStub: _FakePermissionRequest_17( + returnValueForMissingStub: _FakePermissionRequest_14( this, Invocation.method(#pigeon_copy, []), ), @@ -2075,7 +1360,7 @@ class MockPlatformViewsServiceProxy extends _i1.Mock #creationParamsCodec: creationParamsCodec, #onFocus: onFocus, }), - returnValue: _FakeExpensiveAndroidViewController_18( + returnValue: _FakeExpensiveAndroidViewController_15( this, Invocation.method(#initExpensiveAndroidView, [], { #id: id, @@ -2086,7 +1371,7 @@ class MockPlatformViewsServiceProxy extends _i1.Mock #onFocus: onFocus, }), ), - returnValueForMissingStub: _FakeExpensiveAndroidViewController_18( + returnValueForMissingStub: _FakeExpensiveAndroidViewController_15( this, Invocation.method(#initExpensiveAndroidView, [], { #id: id, @@ -2118,7 +1403,7 @@ class MockPlatformViewsServiceProxy extends _i1.Mock #creationParamsCodec: creationParamsCodec, #onFocus: onFocus, }), - returnValue: _FakeSurfaceAndroidViewController_19( + returnValue: _FakeSurfaceAndroidViewController_16( this, Invocation.method(#initSurfaceAndroidView, [], { #id: id, @@ -2129,7 +1414,7 @@ class MockPlatformViewsServiceProxy extends _i1.Mock #onFocus: onFocus, }), ), - returnValueForMissingStub: _FakeSurfaceAndroidViewController_19( + returnValueForMissingStub: _FakeSurfaceAndroidViewController_16( this, Invocation.method(#initSurfaceAndroidView, [], { #id: id, @@ -2234,10 +1519,10 @@ class MockSurfaceAndroidViewController extends _i1.Mock (super.noSuchMethod( Invocation.method(#setSize, [size]), returnValue: _i8.Future<_i4.Size>.value( - _FakeSize_15(this, Invocation.method(#setSize, [size])), + _FakeSize_10(this, Invocation.method(#setSize, [size])), ), returnValueForMissingStub: _i8.Future<_i4.Size>.value( - _FakeSize_15(this, Invocation.method(#setSize, [size])), + _FakeSize_10(this, Invocation.method(#setSize, [size])), ), ) as _i8.Future<_i4.Size>); @@ -2277,7 +1562,7 @@ class MockSurfaceAndroidViewController extends _i1.Mock as _i8.Future); @override - _i8.Future dispatchPointerEvent(_i11.PointerEvent? event) => + _i8.Future dispatchPointerEvent(_i10.PointerEvent? event) => (super.noSuchMethod( Invocation.method(#dispatchPointerEvent, [event]), returnValue: _i8.Future.value(), @@ -2367,11 +1652,11 @@ class MockWebChromeClient extends _i1.Mock implements _i2.WebChromeClient { _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( Invocation.getter(#pigeon_instanceManager), - returnValue: _FakePigeonInstanceManager_12( + returnValue: _FakePigeonInstanceManager_7( this, Invocation.getter(#pigeon_instanceManager), ), - returnValueForMissingStub: _FakePigeonInstanceManager_12( + returnValueForMissingStub: _FakePigeonInstanceManager_7( this, Invocation.getter(#pigeon_instanceManager), ), @@ -2453,11 +1738,11 @@ class MockWebSettings extends _i1.Mock implements _i2.WebSettings { _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( Invocation.getter(#pigeon_instanceManager), - returnValue: _FakePigeonInstanceManager_12( + returnValue: _FakePigeonInstanceManager_7( this, Invocation.getter(#pigeon_instanceManager), ), - returnValueForMissingStub: _FakePigeonInstanceManager_12( + returnValueForMissingStub: _FakePigeonInstanceManager_7( this, Invocation.getter(#pigeon_instanceManager), ), @@ -2606,13 +1891,13 @@ class MockWebSettings extends _i1.Mock implements _i2.WebSettings { (super.noSuchMethod( Invocation.method(#getUserAgentString, []), returnValue: _i8.Future.value( - _i12.dummyValue( + _i11.dummyValue( this, Invocation.method(#getUserAgentString, []), ), ), returnValueForMissingStub: _i8.Future.value( - _i12.dummyValue( + _i11.dummyValue( this, Invocation.method(#getUserAgentString, []), ), @@ -2633,11 +1918,11 @@ class MockWebSettings extends _i1.Mock implements _i2.WebSettings { _i2.WebSettings pigeon_copy() => (super.noSuchMethod( Invocation.method(#pigeon_copy, []), - returnValue: _FakeWebSettings_20( + returnValue: _FakeWebSettings_17( this, Invocation.method(#pigeon_copy, []), ), - returnValueForMissingStub: _FakeWebSettings_20( + returnValueForMissingStub: _FakeWebSettings_17( this, Invocation.method(#pigeon_copy, []), ), @@ -2653,11 +1938,11 @@ class MockWebView extends _i1.Mock implements _i2.WebView { _i2.WebSettings get settings => (super.noSuchMethod( Invocation.getter(#settings), - returnValue: _FakeWebSettings_20( + returnValue: _FakeWebSettings_17( this, Invocation.getter(#settings), ), - returnValueForMissingStub: _FakeWebSettings_20( + returnValueForMissingStub: _FakeWebSettings_17( this, Invocation.getter(#settings), ), @@ -2668,11 +1953,11 @@ class MockWebView extends _i1.Mock implements _i2.WebView { _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( Invocation.getter(#pigeon_instanceManager), - returnValue: _FakePigeonInstanceManager_12( + returnValue: _FakePigeonInstanceManager_7( this, Invocation.getter(#pigeon_instanceManager), ), - returnValueForMissingStub: _FakePigeonInstanceManager_12( + returnValueForMissingStub: _FakePigeonInstanceManager_7( this, Invocation.getter(#pigeon_instanceManager), ), @@ -2683,11 +1968,11 @@ class MockWebView extends _i1.Mock implements _i2.WebView { _i2.WebSettings pigeonVar_settings() => (super.noSuchMethod( Invocation.method(#pigeonVar_settings, []), - returnValue: _FakeWebSettings_20( + returnValue: _FakeWebSettings_17( this, Invocation.method(#pigeonVar_settings, []), ), - returnValueForMissingStub: _FakeWebSettings_20( + returnValueForMissingStub: _FakeWebSettings_17( this, Invocation.method(#pigeonVar_settings, []), ), @@ -2734,7 +2019,7 @@ class MockWebView extends _i1.Mock implements _i2.WebView { as _i8.Future); @override - _i8.Future postUrl(String? url, _i13.Uint8List? data) => + _i8.Future postUrl(String? url, _i12.Uint8List? data) => (super.noSuchMethod( Invocation.method(#postUrl, [url, data]), returnValue: _i8.Future.value(), @@ -2890,11 +2175,11 @@ class MockWebView extends _i1.Mock implements _i2.WebView { _i2.WebView pigeon_copy() => (super.noSuchMethod( Invocation.method(#pigeon_copy, []), - returnValue: _FakeWebView_7( + returnValue: _FakeWebView_18( this, Invocation.method(#pigeon_copy, []), ), - returnValueForMissingStub: _FakeWebView_7( + returnValueForMissingStub: _FakeWebView_18( this, Invocation.method(#pigeon_copy, []), ), @@ -2924,13 +2209,13 @@ class MockWebView extends _i1.Mock implements _i2.WebView { (super.noSuchMethod( Invocation.method(#getScrollPosition, []), returnValue: _i8.Future<_i2.WebViewPoint>.value( - _FakeWebViewPoint_21( + _FakeWebViewPoint_19( this, Invocation.method(#getScrollPosition, []), ), ), returnValueForMissingStub: _i8.Future<_i2.WebViewPoint>.value( - _FakeWebViewPoint_21( + _FakeWebViewPoint_19( this, Invocation.method(#getScrollPosition, []), ), @@ -2974,11 +2259,11 @@ class MockWebViewClient extends _i1.Mock implements _i2.WebViewClient { _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( Invocation.getter(#pigeon_instanceManager), - returnValue: _FakePigeonInstanceManager_12( + returnValue: _FakePigeonInstanceManager_7( this, Invocation.getter(#pigeon_instanceManager), ), - returnValueForMissingStub: _FakePigeonInstanceManager_12( + returnValueForMissingStub: _FakePigeonInstanceManager_7( this, Invocation.getter(#pigeon_instanceManager), ), @@ -3023,11 +2308,11 @@ class MockWebStorage extends _i1.Mock implements _i2.WebStorage { _i2.PigeonInstanceManager get pigeon_instanceManager => (super.noSuchMethod( Invocation.getter(#pigeon_instanceManager), - returnValue: _FakePigeonInstanceManager_12( + returnValue: _FakePigeonInstanceManager_7( this, Invocation.getter(#pigeon_instanceManager), ), - returnValueForMissingStub: _FakePigeonInstanceManager_12( + returnValueForMissingStub: _FakePigeonInstanceManager_7( this, Invocation.getter(#pigeon_instanceManager), ), @@ -3047,11 +2332,11 @@ class MockWebStorage extends _i1.Mock implements _i2.WebStorage { _i2.WebStorage pigeon_copy() => (super.noSuchMethod( Invocation.method(#pigeon_copy, []), - returnValue: _FakeWebStorage_11( + returnValue: _FakeWebStorage_20( this, Invocation.method(#pigeon_copy, []), ), - returnValueForMissingStub: _FakeWebStorage_11( + returnValueForMissingStub: _FakeWebStorage_20( this, Invocation.method(#pigeon_copy, []), ), diff --git a/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.mocks.dart b/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.mocks.dart index da53a4dd0d4..b0d4e68f341 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.mocks.dart @@ -26,6 +26,7 @@ import 'package:webview_flutter_platform_interface/webview_flutter_platform_inte // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakePigeonInstanceManager_0 extends _i1.SmartFake implements _i2.PigeonInstanceManager { diff --git a/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_cookie_manager_test.mocks.dart b/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_cookie_manager_test.mocks.dart index 7b26a909591..772767b5600 100644 --- a/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_cookie_manager_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_cookie_manager_test.mocks.dart @@ -21,6 +21,7 @@ import 'package:webview_flutter_android/src/android_webkit.g.dart' as _i2; // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakePigeonInstanceManager_0 extends _i1.SmartFake implements _i2.PigeonInstanceManager { diff --git a/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_widget_test.mocks.dart b/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_widget_test.mocks.dart index 9c81ee5875f..eb020a5d61b 100644 --- a/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_widget_test.mocks.dart +++ b/packages/webview_flutter/webview_flutter_android/test/legacy/webview_android_widget_test.mocks.dart @@ -27,6 +27,7 @@ import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_ // ignore_for_file: unnecessary_parenthesis // ignore_for_file: camel_case_types // ignore_for_file: subtype_of_sealed_class +// ignore_for_file: invalid_use_of_internal_member class _FakePigeonInstanceManager_0 extends _i1.SmartFake implements _i2.PigeonInstanceManager { @@ -698,6 +699,11 @@ class MockWebResourceRequest extends _i1.Mock ) as bool); + @override + bool get isRedirect => + (super.noSuchMethod(Invocation.getter(#isRedirect), returnValue: false) + as bool); + @override bool get hasGesture => (super.noSuchMethod(Invocation.getter(#hasGesture), returnValue: false) From cb043c0aa3153c19a7a8c341a3a5d9690b09cdb7 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 26 Nov 2025 18:26:53 -0500 Subject: [PATCH 2/7] remove fake instancemanagers --- .../lib/src/android_webview_controller.dart | 41 +------ .../src/android_webview_cookie_manager.dart | 3 +- .../lib/src/legacy/webview_android.dart | 12 +- .../src/legacy/webview_surface_android.dart | 4 +- .../android_navigation_delegate_test.dart | 47 +------- .../test/android_webview_controller_test.dart | 111 +++--------------- .../android_webview_cookie_manager_test.dart | 14 +-- 7 files changed, 39 insertions(+), 193 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart index 3b63549d394..d8d600c26cf 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart @@ -208,8 +208,6 @@ class AndroidWebViewController extends PlatformWebViewController { AndroidCustomViewWidget.private( controller: webViewController, customView: view, - // ignore: invalid_use_of_protected_member - instanceManager: view.pigeon_instanceManager, ), () => callback.onCustomViewHidden(), ); @@ -429,8 +427,7 @@ class AndroidWebViewController extends PlatformWebViewController { /// /// See Java method `WebViewFlutterPlugin.getWebView`. int get webViewIdentifier => - // ignore: invalid_use_of_protected_member - _webView.pigeon_instanceManager.getIdentifier(_webView)!; + android_webview.PigeonInstanceManager.instance.getIdentifier(_webView)!; @override Future loadFile(String absoluteFilePath) { @@ -1098,18 +1095,15 @@ class AndroidWebViewWidgetCreationParams super.layoutDirection, super.gestureRecognizers, this.displayWithHybridComposition = false, - @visibleForTesting android_webview.PigeonInstanceManager? instanceManager, @visibleForTesting this.platformViewsServiceProxy = const PlatformViewsServiceProxy(), - }) : instanceManager = - instanceManager ?? android_webview.PigeonInstanceManager.instance; + }); /// Constructs a [WebKitWebViewWidgetCreationParams] using a /// [PlatformWebViewWidgetCreationParams]. AndroidWebViewWidgetCreationParams.fromPlatformWebViewWidgetCreationParams( PlatformWebViewWidgetCreationParams params, { bool displayWithHybridComposition = false, - @visibleForTesting android_webview.PigeonInstanceManager? instanceManager, @visibleForTesting PlatformViewsServiceProxy platformViewsServiceProxy = const PlatformViewsServiceProxy(), @@ -1119,18 +1113,9 @@ class AndroidWebViewWidgetCreationParams layoutDirection: params.layoutDirection, gestureRecognizers: params.gestureRecognizers, displayWithHybridComposition: displayWithHybridComposition, - instanceManager: instanceManager, platformViewsServiceProxy: platformViewsServiceProxy, ); - /// Maintains instances used to communicate with the native objects they - /// represent. - /// - /// This field is exposed for testing purposes only and should not be used - /// outside of tests. - @visibleForTesting - final android_webview.PigeonInstanceManager instanceManager; - /// Proxy that provides access to the platform views service. /// /// This service allows creating and controlling platform-specific views. @@ -1156,7 +1141,6 @@ class AndroidWebViewWidgetCreationParams layoutDirection, displayWithHybridComposition, platformViewsServiceProxy, - instanceManager, ); @override @@ -1165,8 +1149,7 @@ class AndroidWebViewWidgetCreationParams controller == other.controller && layoutDirection == other.layoutDirection && displayWithHybridComposition == other.displayWithHybridComposition && - platformViewsServiceProxy == other.platformViewsServiceProxy && - instanceManager == other.instanceManager; + platformViewsServiceProxy == other.platformViewsServiceProxy; } } @@ -1213,7 +1196,6 @@ class AndroidWebViewWidget extends PlatformWebViewWidget { platformViewsServiceProxy: _androidParams.platformViewsServiceProxy, view: (_androidParams.controller as AndroidWebViewController) ._webView, - instanceManager: _androidParams.instanceManager, layoutDirection: _androidParams.layoutDirection, ) ..addOnPlatformViewCreatedListener(params.onPlatformViewCreated) @@ -1269,11 +1251,9 @@ class AndroidCustomViewWidget extends StatelessWidget { super.key, required this.controller, required this.customView, - @visibleForTesting android_webview.PigeonInstanceManager? instanceManager, @visibleForTesting this.platformViewsServiceProxy = const PlatformViewsServiceProxy(), - }) : instanceManager = - instanceManager ?? android_webview.PigeonInstanceManager.instance; + }); /// The reference to the Android native view that should be shown. final android_webview.View customView; @@ -1282,14 +1262,6 @@ class AndroidCustomViewWidget extends StatelessWidget { /// view. final PlatformWebViewController controller; - /// Maintains instances used to communicate with the native objects they - /// represent. - /// - /// This field is exposed for testing purposes only and should not be used - /// outside of tests. - @visibleForTesting - final android_webview.PigeonInstanceManager instanceManager; - /// Proxy that provides access to the platform views service. /// /// This service allows creating and controlling platform-specific views. @@ -1316,7 +1288,6 @@ class AndroidCustomViewWidget extends StatelessWidget { displayWithHybridComposition: false, platformViewsServiceProxy: platformViewsServiceProxy, view: customView, - instanceManager: instanceManager, ) ..addOnPlatformViewCreatedListener(params.onPlatformViewCreated) ..create(); @@ -1330,10 +1301,10 @@ AndroidViewController _initAndroidView( required bool displayWithHybridComposition, required PlatformViewsServiceProxy platformViewsServiceProxy, required android_webview.View view, - required android_webview.PigeonInstanceManager instanceManager, TextDirection layoutDirection = TextDirection.ltr, }) { - final int identifier = instanceManager.getIdentifier(view)!; + final int identifier = android_webview.PigeonInstanceManager.instance + .getIdentifier(view)!; if (displayWithHybridComposition) { return platformViewsServiceProxy.initExpensiveAndroidView( diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_cookie_manager.dart b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_cookie_manager.dart index 88f5ad0f05a..621e9baae04 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_cookie_manager.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_cookie_manager.dart @@ -83,8 +83,7 @@ class AndroidWebViewCookieManager extends PlatformWebViewCookieManager { AndroidWebViewController controller, bool accept, ) { - // ignore: invalid_use_of_protected_member - final WebView webView = _cookieManager.pigeon_instanceManager + final WebView webView = PigeonInstanceManager.instance .getInstanceWithWeakReference(controller.webViewIdentifier)!; return _cookieManager.setAcceptThirdPartyCookies(webView, accept); } diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_android.dart b/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_android.dart index 5313cf73345..0b5580d0bb3 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_android.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_android.dart @@ -21,13 +21,7 @@ import 'webview_android_widget.dart'; /// communicate with the platform code. class AndroidWebView implements WebViewPlatform { /// Constructs an [AndroidWebView]. - AndroidWebView({@visibleForTesting PigeonInstanceManager? instanceManager}) - : instanceManager = instanceManager ?? PigeonInstanceManager.instance; - - /// Maintains instances used to communicate with the native objects they - /// represent. - @protected - final PigeonInstanceManager instanceManager; + AndroidWebView(); @override Widget build({ @@ -63,7 +57,9 @@ class AndroidWebView implements WebViewPlatform { gestureRecognizers: gestureRecognizers, layoutDirection: Directionality.maybeOf(context) ?? TextDirection.rtl, - creationParams: instanceManager.getIdentifier(controller.webView), + creationParams: PigeonInstanceManager.instance.getIdentifier( + controller.webView, + ), creationParamsCodec: const StandardMessageCodec(), ), ); diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_surface_android.dart b/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_surface_android.dart index 048a1d0b5ad..374ab2dc846 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_surface_android.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_surface_android.dart @@ -31,7 +31,7 @@ import 'webview_android_widget.dart'; /// information. class SurfaceAndroidWebView extends AndroidWebView { /// Constructs a [SurfaceAndroidWebView]. - SurfaceAndroidWebView({@visibleForTesting super.instanceManager}); + SurfaceAndroidWebView(); @override Widget build({ @@ -75,7 +75,7 @@ class SurfaceAndroidWebView extends AndroidWebView { // directionality. layoutDirection: Directionality.maybeOf(context) ?? TextDirection.ltr, - webViewIdentifier: instanceManager.getIdentifier( + webViewIdentifier: PigeonInstanceManager.instance.getIdentifier( controller.webView, )!, ) diff --git a/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.dart b/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.dart index 29d8ac6d236..a859537d5e1 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.dart @@ -86,12 +86,8 @@ void main() { hasGesture: true, method: 'GET', requestHeaders: const {'X-Mock': 'mocking'}, - pigeon_instanceManager: TestInstanceManager(), - ), - android_webview.WebResourceResponse.pigeon_detached( - statusCode: 401, - pigeon_instanceManager: TestInstanceManager(), ), + android_webview.WebResourceResponse.pigeon_detached(statusCode: 401), ); expect(callbackError.response?.statusCode, 401); @@ -117,12 +113,10 @@ void main() { hasGesture: true, method: 'GET', requestHeaders: const {'X-Mock': 'mocking'}, - pigeon_instanceManager: TestInstanceManager(), ), android_webview.WebResourceError.pigeon_detached( errorCode: WebViewClientConstants.errorFileNotFound, description: 'Page not found.', - pigeon_instanceManager: TestInstanceManager(), ), ); @@ -157,7 +151,6 @@ void main() { hasGesture: true, method: 'GET', requestHeaders: const {'X-Mock': 'mocking'}, - pigeon_instanceManager: TestInstanceManager(), ), ); @@ -192,7 +185,6 @@ void main() { hasGesture: true, method: 'GET', requestHeaders: const {'X-Mock': 'mocking'}, - pigeon_instanceManager: TestInstanceManager(), ), ); @@ -227,7 +219,6 @@ void main() { hasGesture: true, method: 'GET', requestHeaders: const {'X-Mock': 'mocking'}, - pigeon_instanceManager: TestInstanceManager(), ), ); @@ -258,7 +249,6 @@ void main() { hasGesture: true, method: 'GET', requestHeaders: const {'X-Mock': 'mocking'}, - pigeon_instanceManager: TestInstanceManager(), ), ); @@ -297,7 +287,6 @@ void main() { hasGesture: true, method: 'GET', requestHeaders: const {'X-Mock': 'mocking'}, - pigeon_instanceManager: TestInstanceManager(), ), ); @@ -340,7 +329,6 @@ void main() { hasGesture: true, method: 'GET', requestHeaders: const {'X-Mock': 'mocking'}, - pigeon_instanceManager: TestInstanceManager(), ), ); @@ -630,9 +618,7 @@ void main() { CapturingWebViewClient.lastCreatedDelegate.onReceivedHttpAuthRequest!( CapturingWebViewClient(), TestWebView(), - android_webview.HttpAuthHandler.pigeon_detached( - pigeon_instanceManager: TestInstanceManager(), - ), + android_webview.HttpAuthHandler.pigeon_detached(), expectedHost, expectedRealm, ); @@ -764,11 +750,7 @@ class CapturingWebViewClient extends android_webview.WebViewClient { super.onReceivedLoginRequest, super.onReceivedSslError, super.onScaleChanged, - }) : super.pigeon_detached( - pigeon_instanceManager: android_webview.PigeonInstanceManager( - onWeakReferenceRemoved: (_) {}, - ), - ) { + }) : super.pigeon_detached() { lastCreatedDelegate = this; } @@ -798,11 +780,7 @@ class CapturingWebChromeClient extends android_webview.WebChromeClient { super.onJsAlert, required super.onJsConfirm, super.onJsPrompt, - }) : super.pigeon_detached( - pigeon_instanceManager: android_webview.PigeonInstanceManager( - onWeakReferenceRemoved: (_) {}, - ), - ) { + }) : super.pigeon_detached() { lastCreatedDelegate = this; } @@ -816,11 +794,7 @@ class CapturingWebChromeClient extends android_webview.WebChromeClient { // Records the last created instance of itself. class CapturingDownloadListener extends android_webview.DownloadListener { CapturingDownloadListener({required super.onDownloadStart}) - : super.pigeon_detached( - pigeon_instanceManager: android_webview.PigeonInstanceManager( - onWeakReferenceRemoved: (_) {}, - ), - ) { + : super.pigeon_detached() { lastCreatedListener = this; } @@ -831,14 +805,5 @@ class CapturingDownloadListener extends android_webview.DownloadListener { } class TestWebView extends android_webview.WebView { - TestWebView() - : super.pigeon_detached( - pigeon_instanceManager: android_webview.PigeonInstanceManager( - onWeakReferenceRemoved: (_) {}, - ), - ); -} - -class TestInstanceManager extends android_webview.PigeonInstanceManager { - TestInstanceManager() : super(onWeakReferenceRemoved: (_) {}); + TestWebView() : super.pigeon_detached(); } diff --git a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart index ee9baec7625..6fc32fe8de2 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart @@ -1009,7 +1009,6 @@ void main() { acceptTypes: const ['png'], filenameHint: 'filenameHint', mode: android_webview.FileChooserMode.open, - pigeon_instanceManager: testInstanceManager, ), ); @@ -1136,9 +1135,7 @@ void main() { }, ); - final testView = android_webview.View.pigeon_detached( - pigeon_instanceManager: testInstanceManager, - ); + final testView = android_webview.View.pigeon_detached(); var showCustomViewCalled = false; var hideCustomViewCalled = false; @@ -1155,9 +1152,7 @@ void main() { onShowCustomViewHandle( mockWebChromeClient, testView, - android_webview.CustomViewCallback.pigeon_detached( - pigeon_instanceManager: testInstanceManager, - ), + android_webview.CustomViewCallback.pigeon_detached(), ); expect(showCustomViewCalled, true); @@ -1215,7 +1210,6 @@ void main() { android_webview.WebChromeClient.pigeon_detached( onJsConfirm: (_, __, ___, ____) async => false, onShowFileChooser: (_, __, ___) async => [], - pigeon_instanceManager: testInstanceManager, ), mockPermissionRequest, ); @@ -1276,7 +1270,6 @@ void main() { android_webview.WebChromeClient.pigeon_detached( onJsConfirm: (_, __, ___, ____) async => false, onShowFileChooser: (_, __, ___) async => [], - pigeon_instanceManager: testInstanceManager, ), mockPermissionRequest, ); @@ -1511,7 +1504,6 @@ void main() { message: 'Debug message', level: android_webview.ConsoleMessageLevel.debug, sourceId: 'source', - pigeon_instanceManager: testInstanceManager, ), ); onConsoleMessageCallback( @@ -1521,7 +1513,6 @@ void main() { message: 'Error message', level: android_webview.ConsoleMessageLevel.error, sourceId: 'source', - pigeon_instanceManager: testInstanceManager, ), ); onConsoleMessageCallback( @@ -1531,7 +1522,6 @@ void main() { message: 'Log message', level: android_webview.ConsoleMessageLevel.log, sourceId: 'source', - pigeon_instanceManager: testInstanceManager, ), ); onConsoleMessageCallback( @@ -1541,7 +1531,6 @@ void main() { message: 'Tip message', level: android_webview.ConsoleMessageLevel.tip, sourceId: 'source', - pigeon_instanceManager: testInstanceManager, ), ); onConsoleMessageCallback( @@ -1551,7 +1540,6 @@ void main() { message: 'Warning message', level: android_webview.ConsoleMessageLevel.warning, sourceId: 'source', - pigeon_instanceManager: testInstanceManager, ), ); onConsoleMessageCallback( @@ -1561,7 +1549,6 @@ void main() { message: 'Unknown message', level: android_webview.ConsoleMessageLevel.unknown, sourceId: 'source', - pigeon_instanceManager: testInstanceManager, ), ); @@ -1815,11 +1802,7 @@ void main() { ); when(mockWebView.getScrollPosition()).thenAnswer( (_) => Future.value( - android_webview.WebViewPoint.pigeon_detached( - x: 4, - y: 2, - pigeon_instanceManager: testInstanceManager, - ), + android_webview.WebViewPoint.pigeon_detached(x: 4, y: 2), ), ); @@ -2031,18 +2014,14 @@ void main() { test('webViewIdentifier', () { final mockWebView = MockWebView(); - final instanceManager = android_webview.PigeonInstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - instanceManager.addHostCreatedInstance(mockWebView, 0); - - when(mockWebView.pigeon_instanceManager).thenReturn(instanceManager); + final int identifier = android_webview.PigeonInstanceManager.instance + .addDartCreatedInstance(mockWebView); final AndroidWebViewController controller = createControllerWithMocks( mockWebView: mockWebView, ); - expect(controller.webViewIdentifier, 0); + expect(controller.webViewIdentifier, identifier); }); test('isWebViewFeatureSupported', () async { @@ -2096,16 +2075,12 @@ void main() { mockWebView: mockWebView, ); - final instanceManager = android_webview.PigeonInstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - instanceManager.addDartCreatedInstance(mockWebView); + android_webview.PigeonInstanceManager.instance.addDartCreatedInstance(mockWebView); final webViewWidget = AndroidWebViewWidget( AndroidWebViewWidgetCreationParams( key: const Key('test_web_view'), controller: controller, - instanceManager: instanceManager, ), ); @@ -2127,10 +2102,7 @@ void main() { mockWebView: mockWebView, ); - final instanceManager = android_webview.PigeonInstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - instanceManager.addDartCreatedInstance(mockWebView); + android_webview.PigeonInstanceManager.instance.addDartCreatedInstance(mockWebView); final mockPlatformViewsService = MockPlatformViewsServiceProxy(); @@ -2150,7 +2122,6 @@ void main() { key: const Key('test_web_view'), controller: controller, platformViewsServiceProxy: mockPlatformViewsService, - instanceManager: instanceManager, ), ); @@ -2181,10 +2152,7 @@ void main() { mockWebView: mockWebView, ); - final instanceManager = android_webview.PigeonInstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - instanceManager.addDartCreatedInstance(mockWebView); + android_webview.PigeonInstanceManager.instance.addDartCreatedInstance(mockWebView); final mockPlatformViewsService = MockPlatformViewsServiceProxy(); @@ -2205,7 +2173,6 @@ void main() { controller: controller, platformViewsServiceProxy: mockPlatformViewsService, displayWithHybridComposition: true, - instanceManager: instanceManager, ), ); @@ -2241,10 +2208,7 @@ void main() { onShowCustomViewCallback; final android_webview.WebView mockWebView = MockWebView(); - final instanceManager = android_webview.PigeonInstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - instanceManager.addDartCreatedInstance(mockWebView); + android_webview.PigeonInstanceManager.instance.addDartCreatedInstance(mockWebView); final AndroidWebViewController controller = createControllerWithMocks( createWebChromeClient: @@ -2290,7 +2254,6 @@ void main() { key: const Key('test_web_view'), controller: controller, platformViewsServiceProxy: mockPlatformViewsService, - instanceManager: instanceManager, ), ); @@ -2303,14 +2266,10 @@ void main() { ); await tester.pumpAndSettle(); - // ignore: invalid_use_of_protected_member - when(mockWebView.pigeon_instanceManager).thenReturn(instanceManager); - onShowCustomViewCallback!( MockWebChromeClient(), mockWebView, android_webview.CustomViewCallback.pigeon_detached( - pigeon_instanceManager: instanceManager, ), ); await tester.pumpAndSettle(); @@ -2322,10 +2281,7 @@ void main() { WidgetTester tester, ) async { final android_webview.WebView mockWebView = MockWebView(); - final instanceManager = android_webview.PigeonInstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - instanceManager.addDartCreatedInstance(mockWebView); + android_webview.PigeonInstanceManager.instance.addDartCreatedInstance(mockWebView); final mockPlatformViewsService = MockPlatformViewsServiceProxy(); @@ -2347,7 +2303,6 @@ void main() { AndroidWebViewWidgetCreationParams( controller: createControllerWithMocks(mockWebView: mockWebView), platformViewsServiceProxy: mockPlatformViewsService, - instanceManager: instanceManager, ), ).build(context); }, @@ -2373,7 +2328,6 @@ void main() { AndroidWebViewWidgetCreationParams( controller: createControllerWithMocks(mockWebView: mockWebView), platformViewsServiceProxy: mockPlatformViewsService, - instanceManager: instanceManager, ), ).build(context); }, @@ -2397,10 +2351,7 @@ void main() { 'PlatformView does not rebuild when creation params stay the same', (WidgetTester tester) async { final android_webview.WebView mockWebView = MockWebView(); - final instanceManager = android_webview.PigeonInstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - instanceManager.addDartCreatedInstance(mockWebView); + android_webview.PigeonInstanceManager.instance.addDartCreatedInstance(mockWebView); final mockPlatformViewsService = MockPlatformViewsServiceProxy(); @@ -2426,7 +2377,6 @@ void main() { AndroidWebViewWidgetCreationParams( controller: controller, platformViewsServiceProxy: mockPlatformViewsService, - instanceManager: instanceManager, ), ).build(context); }, @@ -2452,7 +2402,6 @@ void main() { AndroidWebViewWidgetCreationParams( controller: controller, platformViewsServiceProxy: mockPlatformViewsService, - instanceManager: instanceManager, ), ).build(context); }, @@ -2479,10 +2428,7 @@ void main() { WidgetTester tester, ) async { final android_webview.WebView mockWebView = MockWebView(); - final instanceManager = android_webview.PigeonInstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - instanceManager.addDartCreatedInstance(mockWebView); + android_webview.PigeonInstanceManager.instance.addDartCreatedInstance(mockWebView); final AndroidWebViewController controller = createControllerWithMocks( mockWebView: mockWebView, @@ -2492,7 +2438,6 @@ void main() { key: const Key('test_custom_view'), customView: mockWebView, controller: controller, - instanceManager: instanceManager, ); await tester.pumpWidget( @@ -2509,10 +2454,7 @@ void main() { WidgetTester tester, ) async { final android_webview.WebView mockWebView = MockWebView(); - final instanceManager = android_webview.PigeonInstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - instanceManager.addDartCreatedInstance(mockWebView); + android_webview.PigeonInstanceManager.instance.addDartCreatedInstance(mockWebView); final AndroidWebViewController controller = createControllerWithMocks( mockWebView: mockWebView, @@ -2535,7 +2477,6 @@ void main() { controller: controller, customView: mockWebView, platformViewsServiceProxy: mockPlatformViewsService, - instanceManager: instanceManager, ); await tester.pumpWidget( @@ -2559,12 +2500,6 @@ void main() { }); } -/// Creates a PigeonInstanceManager that doesn't make a call to Java when an -/// object is garbage collected. Also, `PigeonInstanceManager.instance` makes -/// a call to Java, so this InstanceManager is used to prevent that. -final android_webview.PigeonInstanceManager testInstanceManager = - android_webview.PigeonInstanceManager(onWeakReferenceRemoved: (_) {}); - class TestWebViewClient extends android_webview.WebViewClient { TestWebViewClient({ super.onPageStarted, @@ -2583,11 +2518,7 @@ class TestWebViewClient extends android_webview.WebViewClient { super.onReceivedLoginRequest, super.onReceivedSslError, super.onScaleChanged, - }) : super.pigeon_detached( - pigeon_instanceManager: android_webview.PigeonInstanceManager( - onWeakReferenceRemoved: (_) {}, - ), - ); + }) : super.pigeon_detached(); } class TestWebChromeClient extends android_webview.WebChromeClient { @@ -2603,18 +2534,10 @@ class TestWebChromeClient extends android_webview.WebChromeClient { super.onJsAlert, required super.onJsConfirm, super.onJsPrompt, - }) : super.pigeon_detached( - pigeon_instanceManager: android_webview.PigeonInstanceManager( - onWeakReferenceRemoved: (_) {}, - ), - ); + }) : super.pigeon_detached(); } class TestDownloadListener extends android_webview.DownloadListener { TestDownloadListener({required super.onDownloadStart}) - : super.pigeon_detached( - pigeon_instanceManager: android_webview.PigeonInstanceManager( - onWeakReferenceRemoved: (_) {}, - ), - ); + : super.pigeon_detached(); } diff --git a/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.dart b/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.dart index 84233479200..44695d2eeec 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_cookie_manager_test.dart @@ -87,16 +87,10 @@ void main() { test('setAcceptThirdPartyCookies', () async { final mockController = MockAndroidWebViewController(); - final instanceManager = android_webview.PigeonInstanceManager( - onWeakReferenceRemoved: (_) {}, - ); - final webView = android_webview.WebView.pigeon_detached( - pigeon_instanceManager: instanceManager, - ); + final webView = android_webview.WebView.pigeon_detached(); - final int webViewIdentifier = instanceManager.addDartCreatedInstance( - webView, - ); + final int webViewIdentifier = android_webview.PigeonInstanceManager.instance + .addDartCreatedInstance(webView); when(mockController.webViewIdentifier).thenReturn(webViewIdentifier); @@ -106,8 +100,6 @@ void main() { ); final mockCookieManager = MockCookieManager(); - // ignore: invalid_use_of_protected_member - when(mockCookieManager.pigeon_instanceManager).thenReturn(instanceManager); await AndroidWebViewCookieManager( params, From 82fa5f990de8c74d8e02a2c2698c31d16dec4fe7 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 26 Nov 2025 19:30:54 -0500 Subject: [PATCH 3/7] fix lints --- .../example/integration_test/webview_flutter_test_legacy.dart | 2 +- .../lib/src/android_webview_controller.dart | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_android/example/integration_test/webview_flutter_test_legacy.dart b/packages/webview_flutter/webview_flutter_android/example/integration_test/webview_flutter_test_legacy.dart index 82147e168c0..3fb1fd48c04 100644 --- a/packages/webview_flutter/webview_flutter_android/example/integration_test/webview_flutter_test_legacy.dart +++ b/packages/webview_flutter/webview_flutter_android/example/integration_test/webview_flutter_test_legacy.dart @@ -150,7 +150,7 @@ Future main() async { await tester.pumpWidget( Builder( builder: (BuildContext context) { - return AndroidWebView(instanceManager: instanceManager).build( + return AndroidWebView().build( context: context, creationParams: CreationParams( webSettings: WebSettings( diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart index d8d600c26cf..00563080c4e 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/android_webview_controller.dart @@ -1089,7 +1089,7 @@ class AndroidJavaScriptChannelParams extends JavaScriptChannelParams { class AndroidWebViewWidgetCreationParams extends PlatformWebViewWidgetCreationParams { /// Creates [AndroidWebWidgetCreationParams]. - AndroidWebViewWidgetCreationParams({ + const AndroidWebViewWidgetCreationParams({ super.key, required super.controller, super.layoutDirection, @@ -1247,7 +1247,7 @@ class AndroidCustomViewWidget extends StatelessWidget { /// This constructor is visible for testing purposes only and should /// never be called externally. @visibleForTesting - AndroidCustomViewWidget.private({ + const AndroidCustomViewWidget.private({ super.key, required this.controller, required this.customView, From 8e6b0a18bdd9e0fc8376b46e8707c6838723aa48 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 26 Nov 2025 19:40:47 -0500 Subject: [PATCH 4/7] formatting --- .../test/android_webview_controller_test.dart | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart index 6fc32fe8de2..fa878c5d0da 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_webview_controller_test.dart @@ -2075,7 +2075,9 @@ void main() { mockWebView: mockWebView, ); - android_webview.PigeonInstanceManager.instance.addDartCreatedInstance(mockWebView); + android_webview.PigeonInstanceManager.instance.addDartCreatedInstance( + mockWebView, + ); final webViewWidget = AndroidWebViewWidget( AndroidWebViewWidgetCreationParams( @@ -2102,7 +2104,9 @@ void main() { mockWebView: mockWebView, ); - android_webview.PigeonInstanceManager.instance.addDartCreatedInstance(mockWebView); + android_webview.PigeonInstanceManager.instance.addDartCreatedInstance( + mockWebView, + ); final mockPlatformViewsService = MockPlatformViewsServiceProxy(); @@ -2152,7 +2156,9 @@ void main() { mockWebView: mockWebView, ); - android_webview.PigeonInstanceManager.instance.addDartCreatedInstance(mockWebView); + android_webview.PigeonInstanceManager.instance.addDartCreatedInstance( + mockWebView, + ); final mockPlatformViewsService = MockPlatformViewsServiceProxy(); @@ -2208,7 +2214,9 @@ void main() { onShowCustomViewCallback; final android_webview.WebView mockWebView = MockWebView(); - android_webview.PigeonInstanceManager.instance.addDartCreatedInstance(mockWebView); + android_webview.PigeonInstanceManager.instance.addDartCreatedInstance( + mockWebView, + ); final AndroidWebViewController controller = createControllerWithMocks( createWebChromeClient: @@ -2269,8 +2277,7 @@ void main() { onShowCustomViewCallback!( MockWebChromeClient(), mockWebView, - android_webview.CustomViewCallback.pigeon_detached( - ), + android_webview.CustomViewCallback.pigeon_detached(), ); await tester.pumpAndSettle(); @@ -2281,7 +2288,9 @@ void main() { WidgetTester tester, ) async { final android_webview.WebView mockWebView = MockWebView(); - android_webview.PigeonInstanceManager.instance.addDartCreatedInstance(mockWebView); + android_webview.PigeonInstanceManager.instance.addDartCreatedInstance( + mockWebView, + ); final mockPlatformViewsService = MockPlatformViewsServiceProxy(); @@ -2351,7 +2360,9 @@ void main() { 'PlatformView does not rebuild when creation params stay the same', (WidgetTester tester) async { final android_webview.WebView mockWebView = MockWebView(); - android_webview.PigeonInstanceManager.instance.addDartCreatedInstance(mockWebView); + android_webview.PigeonInstanceManager.instance.addDartCreatedInstance( + mockWebView, + ); final mockPlatformViewsService = MockPlatformViewsServiceProxy(); @@ -2428,7 +2439,9 @@ void main() { WidgetTester tester, ) async { final android_webview.WebView mockWebView = MockWebView(); - android_webview.PigeonInstanceManager.instance.addDartCreatedInstance(mockWebView); + android_webview.PigeonInstanceManager.instance.addDartCreatedInstance( + mockWebView, + ); final AndroidWebViewController controller = createControllerWithMocks( mockWebView: mockWebView, @@ -2454,7 +2467,9 @@ void main() { WidgetTester tester, ) async { final android_webview.WebView mockWebView = MockWebView(); - android_webview.PigeonInstanceManager.instance.addDartCreatedInstance(mockWebView); + android_webview.PigeonInstanceManager.instance.addDartCreatedInstance( + mockWebView, + ); final AndroidWebViewController controller = createControllerWithMocks( mockWebView: mockWebView, From 37d802fb94ca9c2da24e13f16c048044ad8b932d Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 27 Nov 2025 02:12:09 -0500 Subject: [PATCH 5/7] remove commented code --- .../test/android_navigation_delegate_test.dart | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.dart b/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.dart index a859537d5e1..4a7d4ef06fa 100644 --- a/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.dart +++ b/packages/webview_flutter/webview_flutter_android/test/android_navigation_delegate_test.dart @@ -722,11 +722,6 @@ AndroidNavigationDelegateCreationParams _buildCreationParams() { CapturingDownloadListener.new; return AndroidNavigationDelegateCreationParams.fromPlatformNavigationDelegateCreationParams( const PlatformNavigationDelegateCreationParams(), - // androidWebViewProxy: const AndroidWebViewProxy( - // newWebChromeClient: CapturingWebChromeClient.new, - // newWebViewClient: CapturingWebViewClient.new, - // newDownloadListener: CapturingDownloadListener.new, - // ), ); } From f7ef4e9a030f20eb40be205873eadf9b100af9f8 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 3 Dec 2025 23:36:18 -0500 Subject: [PATCH 6/7] add destroy back in --- .../flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt index a88d9a23c4c..71d26653c2e 100644 --- a/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt +++ b/packages/webview_flutter/webview_flutter_android/android/src/main/java/io/flutter/plugins/webviewflutter/AndroidWebkitLibrary.g.kt @@ -155,6 +155,10 @@ class AndroidWebkitLibraryPigeonInstanceManager( */ fun remove(identifier: Long): T? { logWarningIfFinalizationListenerHasStopped() + val instance: Any? = getInstance(identifier) + if (instance is WebViewProxyApi.WebViewPlatformView) { + instance.destroy() + } return strongInstances.remove(identifier) as T? } From 4ddd2551fc9070f7829f3016c1dfee663e8efb58 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 3 Dec 2025 23:37:52 -0500 Subject: [PATCH 7/7] unnecessary constructors --- .../lib/src/legacy/webview_android.dart | 3 --- .../lib/src/legacy/webview_surface_android.dart | 3 --- 2 files changed, 6 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_android.dart b/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_android.dart index 0b5580d0bb3..69b3684f14d 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_android.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_android.dart @@ -20,9 +20,6 @@ import 'webview_android_widget.dart'; /// an [AndroidView] to embed the webview in the widget hierarchy, and uses a method channel to /// communicate with the platform code. class AndroidWebView implements WebViewPlatform { - /// Constructs an [AndroidWebView]. - AndroidWebView(); - @override Widget build({ required BuildContext context, diff --git a/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_surface_android.dart b/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_surface_android.dart index 374ab2dc846..e2ac80667f0 100644 --- a/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_surface_android.dart +++ b/packages/webview_flutter/webview_flutter_android/lib/src/legacy/webview_surface_android.dart @@ -30,9 +30,6 @@ import 'webview_android_widget.dart'; /// https://github.com/flutter/flutter/wiki/Hybrid-Composition for more /// information. class SurfaceAndroidWebView extends AndroidWebView { - /// Constructs a [SurfaceAndroidWebView]. - SurfaceAndroidWebView(); - @override Widget build({ required BuildContext context,