From da943e5ffb59fc75b13ae36bbd5323dc724fa015 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 14 Dec 2022 18:13:00 -0500 Subject: [PATCH 1/5] Set new interface in main --- .../javascript_channel_registry.dart | 0 .../platform_interface.dart | 0 .../webview_cookie_manager.dart | 0 .../platform_interface/webview_platform.dart | 0 .../webview_platform_callbacks_handler.dart | 0 .../webview_platform_controller.dart | 0 .../types/auto_media_playback_policy.dart | 0 .../{ => legacy}/types/creation_params.dart | 0 .../types/javascript_channel.dart | 0 .../src/legacy/types/javascript_message.dart | 14 + .../legacy}/types/javascript_mode.dart | 2 +- .../{v4/src => src/legacy}/types/types.dart | 11 +- .../src/legacy/types/web_resource_error.dart | 57 ++ .../types/web_resource_error_type.dart | 0 .../src/{ => legacy}/types/web_settings.dart | 0 .../legacy}/types/webview_cookie.dart | 32 +- .../{ => legacy}/types/webview_request.dart | 0 .../webview_method_channel.dart | 297 ------- .../src/platform_navigation_delegate.dart | 24 +- .../src/platform_webview_controller.dart | 27 +- .../src/platform_webview_cookie_manager.dart | 0 .../{v4 => }/src/platform_webview_widget.dart | 0 .../lib/src/types/javascript_message.dart | 47 +- .../lib/src/types/javascript_mode.dart | 2 +- .../src/types/load_request_params.dart | 6 +- .../lib/src/types/navigation_decision.dart | 12 + .../lib/src/types/navigation_request.dart | 18 + ...m_navigation_delegate_creation_params.dart | 0 ...rm_webview_controller_creation_params.dart | 0 ...ebview_cookie_manager_creation_params.dart | 0 ...atform_webview_widget_creation_params.dart | 0 .../lib/src/types/types.dart | 13 +- .../lib/src/types/web_resource_error.dart | 138 +++- .../lib/src/types/webview_cookie.dart | 32 +- ...iew_flutter_platform_interface_legacy.dart | 6 + .../lib/{v4 => }/src/webview_platform.dart | 2 +- .../lib/v4/src/types/javascript_message.dart | 51 -- .../lib/v4/src/types/web_resource_error.dart | 119 --- .../webview_flutter_platform_interface.dart | 10 - .../webview_flutter_platform_interface.dart | 7 +- .../pubspec.yaml | 1 + .../javascript_channel_registry_test.dart | 3 +- .../webview_cookie_manager_test.dart | 3 +- .../types/javascript_channel_test.dart | 2 +- .../types/webview_cookie_test.dart | 2 +- .../types/webview_request_test.dart | 2 +- .../platform_navigation_delegate_test.dart | 5 +- .../platform_webview_controller_test.dart | 32 +- ...latform_webview_controller_test.mocks.dart | 106 +++ .../v4 => }/platform_webview_widget_test.dart | 4 +- .../webview_method_channel_test.dart | 746 ------------------ ...latform_webview_controller_test.mocks.dart | 72 -- .../src/v4/webview_platform_test.mocks.dart | 78 -- .../{src/v4 => }/webview_platform_test.dart | 3 +- .../test/webview_platform_test.mocks.dart | 146 ++++ 55 files changed, 596 insertions(+), 1536 deletions(-) rename packages/webview_flutter/webview_flutter_platform_interface/lib/src/{ => legacy}/platform_interface/javascript_channel_registry.dart (100%) rename packages/webview_flutter/webview_flutter_platform_interface/lib/src/{ => legacy}/platform_interface/platform_interface.dart (100%) rename packages/webview_flutter/webview_flutter_platform_interface/lib/src/{ => legacy}/platform_interface/webview_cookie_manager.dart (100%) rename packages/webview_flutter/webview_flutter_platform_interface/lib/src/{ => legacy}/platform_interface/webview_platform.dart (100%) rename packages/webview_flutter/webview_flutter_platform_interface/lib/src/{ => legacy}/platform_interface/webview_platform_callbacks_handler.dart (100%) rename packages/webview_flutter/webview_flutter_platform_interface/lib/src/{ => legacy}/platform_interface/webview_platform_controller.dart (100%) rename packages/webview_flutter/webview_flutter_platform_interface/lib/src/{ => legacy}/types/auto_media_playback_policy.dart (100%) rename packages/webview_flutter/webview_flutter_platform_interface/lib/src/{ => legacy}/types/creation_params.dart (100%) rename packages/webview_flutter/webview_flutter_platform_interface/lib/src/{ => legacy}/types/javascript_channel.dart (100%) create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_message.dart rename packages/webview_flutter/webview_flutter_platform_interface/lib/{v4/src => src/legacy}/types/javascript_mode.dart (94%) rename packages/webview_flutter/webview_flutter_platform_interface/lib/{v4/src => src/legacy}/types/types.dart (51%) create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_resource_error.dart rename packages/webview_flutter/webview_flutter_platform_interface/lib/src/{ => legacy}/types/web_resource_error_type.dart (100%) rename packages/webview_flutter/webview_flutter_platform_interface/lib/src/{ => legacy}/types/web_settings.dart (100%) rename packages/webview_flutter/webview_flutter_platform_interface/lib/{v4/src => src/legacy}/types/webview_cookie.dart (63%) rename packages/webview_flutter/webview_flutter_platform_interface/lib/src/{ => legacy}/types/webview_request.dart (100%) delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/method_channel/webview_method_channel.dart rename packages/webview_flutter/webview_flutter_platform_interface/lib/{v4 => }/src/platform_navigation_delegate.dart (78%) rename packages/webview_flutter/webview_flutter_platform_interface/lib/{v4 => }/src/platform_webview_controller.dart (92%) rename packages/webview_flutter/webview_flutter_platform_interface/lib/{v4 => }/src/platform_webview_cookie_manager.dart (100%) rename packages/webview_flutter/webview_flutter_platform_interface/lib/{v4 => }/src/platform_webview_widget.dart (100%) rename packages/webview_flutter/webview_flutter_platform_interface/lib/{v4 => }/src/types/load_request_params.dart (94%) create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_decision.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_request.dart rename packages/webview_flutter/webview_flutter_platform_interface/lib/{v4 => }/src/types/platform_navigation_delegate_creation_params.dart (100%) rename packages/webview_flutter/webview_flutter_platform_interface/lib/{v4 => }/src/types/platform_webview_controller_creation_params.dart (100%) rename packages/webview_flutter/webview_flutter_platform_interface/lib/{v4 => }/src/types/platform_webview_cookie_manager_creation_params.dart (100%) rename packages/webview_flutter/webview_flutter_platform_interface/lib/{v4 => }/src/types/platform_webview_widget_creation_params.dart (100%) create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/webview_flutter_platform_interface_legacy.dart rename packages/webview_flutter/webview_flutter_platform_interface/lib/{v4 => }/src/webview_platform.dart (98%) delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/javascript_message.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/web_resource_error.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/v4/webview_flutter_platform_interface.dart rename packages/webview_flutter/webview_flutter_platform_interface/test/{src => legacy}/platform_interface/javascript_channel_registry_test.dart (94%) rename packages/webview_flutter/webview_flutter_platform_interface/test/{src => legacy}/platform_interface/webview_cookie_manager_test.dart (81%) rename packages/webview_flutter/webview_flutter_platform_interface/test/{src => legacy}/types/javascript_channel_test.dart (93%) rename packages/webview_flutter/webview_flutter_platform_interface/test/{src => legacy}/types/webview_cookie_test.dart (87%) rename packages/webview_flutter/webview_flutter_platform_interface/test/{src => legacy}/types/webview_request_test.dart (93%) rename packages/webview_flutter/webview_flutter_platform_interface/test/{src/v4 => }/platform_navigation_delegate_test.dart (95%) rename packages/webview_flutter/webview_flutter_platform_interface/test/{src/v4 => }/platform_webview_controller_test.dart (92%) create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.mocks.dart rename packages/webview_flutter/webview_flutter_platform_interface/test/{src/v4 => }/platform_webview_widget_test.dart (92%) delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/src/method_channel/webview_method_channel_test.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_webview_controller_test.mocks.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/webview_platform_test.mocks.dart rename packages/webview_flutter/webview_flutter_platform_interface/test/{src/v4 => }/webview_platform_test.dart (95%) create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/webview_platform_test.mocks.dart diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_interface/javascript_channel_registry.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/javascript_channel_registry.dart similarity index 100% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_interface/javascript_channel_registry.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/javascript_channel_registry.dart diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_interface/platform_interface.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/platform_interface.dart similarity index 100% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_interface/platform_interface.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/platform_interface.dart diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_interface/webview_cookie_manager.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_cookie_manager.dart similarity index 100% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_interface/webview_cookie_manager.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_cookie_manager.dart diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_interface/webview_platform.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform.dart similarity index 100% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_interface/webview_platform.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform.dart diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_interface/webview_platform_callbacks_handler.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform_callbacks_handler.dart similarity index 100% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_interface/webview_platform_callbacks_handler.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform_callbacks_handler.dart diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_interface/webview_platform_controller.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform_controller.dart similarity index 100% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_interface/webview_platform_controller.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform_controller.dart diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/auto_media_playback_policy.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/auto_media_playback_policy.dart similarity index 100% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/auto_media_playback_policy.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/auto_media_playback_policy.dart diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/creation_params.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/creation_params.dart similarity index 100% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/creation_params.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/creation_params.dart diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_channel.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_channel.dart similarity index 100% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_channel.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_channel.dart diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_message.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_message.dart new file mode 100644 index 000000000000..8d080452c54a --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_message.dart @@ -0,0 +1,14 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// A message that was sent by JavaScript code running in a [WebView]. +class JavascriptMessage { + /// Constructs a JavaScript message object. + /// + /// The `message` parameter must not be null. + const JavascriptMessage(this.message) : assert(message != null); + + /// The contents of the message that was sent by the JavaScript code. + final String message; +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/javascript_mode.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_mode.dart similarity index 94% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/javascript_mode.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_mode.dart index bcbebff8bb1a..53d049175907 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/javascript_mode.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_mode.dart @@ -3,7 +3,7 @@ // found in the LICENSE file. /// Describes the state of JavaScript support in a given web view. -enum JavaScriptMode { +enum JavascriptMode { /// JavaScript execution is disabled. disabled, diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/types.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/types.dart similarity index 51% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/types.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/types.dart index 05504fffd211..f2bcf19f42fd 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/types.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/types.dart @@ -2,12 +2,13 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +export 'auto_media_playback_policy.dart'; +export 'creation_params.dart'; +export 'javascript_channel.dart'; export 'javascript_message.dart'; export 'javascript_mode.dart'; -export 'load_request_params.dart'; -export 'platform_navigation_delegate_creation_params.dart'; -export 'platform_webview_controller_creation_params.dart'; -export 'platform_webview_cookie_manager_creation_params.dart'; -export 'platform_webview_widget_creation_params.dart'; export 'web_resource_error.dart'; +export 'web_resource_error_type.dart'; +export 'web_settings.dart'; export 'webview_cookie.dart'; +export 'webview_request.dart'; diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_resource_error.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_resource_error.dart new file mode 100644 index 000000000000..b61671f0ac45 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_resource_error.dart @@ -0,0 +1,57 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'web_resource_error_type.dart'; + +/// Error returned in `WebView.onWebResourceError` when a web resource loading error has occurred. +class WebResourceError { + /// Creates a new [WebResourceError] + /// + /// A user should not need to instantiate this class, but will receive one in + /// [WebResourceErrorCallback]. + WebResourceError({ + required this.errorCode, + required this.description, + this.domain, + this.errorType, + this.failingUrl, + }) : assert(errorCode != null), + assert(description != null); + + /// Raw code of the error from the respective platform. + /// + /// On Android, the error code will be a constant from a + /// [WebViewClient](https://developer.android.com/reference/android/webkit/WebViewClient#summary) and + /// will have a corresponding [errorType]. + /// + /// On iOS, the error code will be a constant from `NSError.code` in + /// Objective-C. See + /// https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/ErrorObjectsDomains/ErrorObjectsDomains.html + /// for more information on error handling on iOS. Some possible error codes + /// can be found at https://developer.apple.com/documentation/webkit/wkerrorcode?language=objc. + final int errorCode; + + /// The domain of where to find the error code. + /// + /// This field is only available on iOS and represents a "domain" from where + /// the [errorCode] is from. This value is taken directly from an `NSError` + /// in Objective-C. See + /// https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/ErrorObjectsDomains/ErrorObjectsDomains.html + /// for more information on error handling on iOS. + final String? domain; + + /// Description of the error that can be used to communicate the problem to the user. + final String description; + + /// The type this error can be categorized as. + /// + /// This will never be `null` on Android, but can be `null` on iOS. + final WebResourceErrorType? errorType; + + /// Gets the URL for which the resource request was made. + /// + /// This value is not provided on iOS. Alternatively, you can keep track of + /// the last values provided to [WebViewPlatformController.loadUrl]. + final String? failingUrl; +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/web_resource_error_type.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_resource_error_type.dart similarity index 100% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/web_resource_error_type.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_resource_error_type.dart diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/web_settings.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_settings.dart similarity index 100% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/web_settings.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_settings.dart diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/webview_cookie.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/webview_cookie.dart similarity index 63% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/webview_cookie.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/webview_cookie.dart index 7f56a312049f..406c510afd4b 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/webview_cookie.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/webview_cookie.dart @@ -2,18 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'package:flutter/foundation.dart'; - -/// A cookie that can be set globally for all web views using [WebViewCookieManagerPlatform]. -@immutable +/// A cookie that can be set globally for all web views +/// using [WebViewCookieManagerPlatform]. class WebViewCookie { - /// Creates a new [WebViewCookieDelegate] - const WebViewCookie({ - required this.name, - required this.value, - required this.domain, - this.path = '/', - }); + /// Constructs a new [WebViewCookie]. + const WebViewCookie( + {required this.name, + required this.value, + required this.domain, + this.path = '/'}); /// The cookie-name of the cookie. /// @@ -33,9 +30,20 @@ class WebViewCookie { /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 final String domain; - /// The path-value of the cookie, set to `/` by default. + /// The path-value of the cookie. + /// Is set to `/` in the constructor by default. /// /// Its value should match "path-value" in RFC6265bis: /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 final String path; + + /// Serializes the [WebViewCookie] to a Map. + Map toJson() { + return { + 'name': name, + 'value': value, + 'domain': domain, + 'path': path + }; + } } diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/webview_request.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/webview_request.dart similarity index 100% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/webview_request.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/webview_request.dart diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/method_channel/webview_method_channel.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/method_channel/webview_method_channel.dart deleted file mode 100644 index 0e98ea08fd16..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/method_channel/webview_method_channel.dart +++ /dev/null @@ -1,297 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:async'; - -import 'package:flutter/services.dart'; - -import '../platform_interface/platform_interface.dart'; -import '../types/types.dart'; - -/// A [WebViewPlatformController] that uses a method channel to control the webview. -class MethodChannelWebViewPlatform implements WebViewPlatformController { - /// Constructs an instance that will listen for webviews broadcasting to the - /// given [id], using the given [WebViewPlatformCallbacksHandler]. - MethodChannelWebViewPlatform( - int id, - this._platformCallbacksHandler, - this._javascriptChannelRegistry, - ) : assert(_platformCallbacksHandler != null), - _channel = MethodChannel('plugins.flutter.io/webview_$id') { - _channel.setMethodCallHandler(_onMethodCall); - } - - final JavascriptChannelRegistry _javascriptChannelRegistry; - - final WebViewPlatformCallbacksHandler _platformCallbacksHandler; - - final MethodChannel _channel; - - static const MethodChannel _cookieManagerChannel = - MethodChannel('plugins.flutter.io/cookie_manager'); - - Future _onMethodCall(MethodCall call) async { - switch (call.method) { - case 'javascriptChannelMessage': - final String channel = call.arguments['channel']! as String; - final String message = call.arguments['message']! as String; - _javascriptChannelRegistry.onJavascriptChannelMessage(channel, message); - return true; - case 'navigationRequest': - return await _platformCallbacksHandler.onNavigationRequest( - url: call.arguments['url']! as String, - isForMainFrame: call.arguments['isForMainFrame']! as bool, - ); - case 'onPageFinished': - _platformCallbacksHandler - .onPageFinished(call.arguments['url']! as String); - return null; - case 'onProgress': - _platformCallbacksHandler.onProgress(call.arguments['progress'] as int); - return null; - case 'onPageStarted': - _platformCallbacksHandler - .onPageStarted(call.arguments['url']! as String); - return null; - case 'onWebResourceError': - _platformCallbacksHandler.onWebResourceError( - WebResourceError( - errorCode: call.arguments['errorCode']! as int, - description: call.arguments['description']! as String, - // iOS doesn't support `failingUrl`. - failingUrl: call.arguments['failingUrl'] as String?, - domain: call.arguments['domain'] as String?, - errorType: call.arguments['errorType'] == null - ? null - : WebResourceErrorType.values.firstWhere( - (WebResourceErrorType type) { - return type.toString() == - '$WebResourceErrorType.${call.arguments['errorType']}'; - }, - ), - ), - ); - return null; - } - - throw MissingPluginException( - '${call.method} was invoked but has no handler', - ); - } - - @override - Future loadFile(String absoluteFilePath) async { - assert(absoluteFilePath != null); - - try { - return await _channel.invokeMethod('loadFile', absoluteFilePath); - } on PlatformException catch (ex) { - if (ex.code == 'loadFile_failed') { - throw ArgumentError(ex.message); - } - - rethrow; - } - } - - @override - Future loadFlutterAsset(String key) async { - assert(key.isNotEmpty); - - try { - return await _channel.invokeMethod('loadFlutterAsset', key); - } on PlatformException catch (ex) { - if (ex.code == 'loadFlutterAsset_invalidKey') { - throw ArgumentError(ex.message); - } - - rethrow; - } - } - - @override - Future loadHtmlString( - String html, { - String? baseUrl, - }) async { - assert(html != null); - return _channel.invokeMethod('loadHtmlString', { - 'html': html, - 'baseUrl': baseUrl, - }); - } - - @override - Future loadUrl( - String url, - Map? headers, - ) async { - assert(url != null); - return _channel.invokeMethod('loadUrl', { - 'url': url, - 'headers': headers, - }); - } - - @override - Future loadRequest(WebViewRequest request) async { - assert(request != null); - return _channel.invokeMethod('loadRequest', { - 'request': request.toJson(), - }); - } - - @override - Future currentUrl() => _channel.invokeMethod('currentUrl'); - - @override - Future canGoBack() => - _channel.invokeMethod('canGoBack').then((bool? result) => result!); - - @override - Future canGoForward() => _channel - .invokeMethod('canGoForward') - .then((bool? result) => result!); - - @override - Future goBack() => _channel.invokeMethod('goBack'); - - @override - Future goForward() => _channel.invokeMethod('goForward'); - - @override - Future reload() => _channel.invokeMethod('reload'); - - @override - Future clearCache() => _channel.invokeMethod('clearCache'); - - @override - Future updateSettings(WebSettings settings) async { - final Map updatesMap = _webSettingsToMap(settings); - if (updatesMap.isNotEmpty) { - await _channel.invokeMethod('updateSettings', updatesMap); - } - } - - @override - Future evaluateJavascript(String javascript) { - return _channel - .invokeMethod('evaluateJavascript', javascript) - .then((String? result) => result!); - } - - @override - Future runJavascript(String javascript) async { - await _channel.invokeMethod('runJavascript', javascript); - } - - @override - Future runJavascriptReturningResult(String javascript) { - return _channel - .invokeMethod('runJavascriptReturningResult', javascript) - .then((String? result) => result!); - } - - @override - Future addJavascriptChannels(Set javascriptChannelNames) { - return _channel.invokeMethod( - 'addJavascriptChannels', javascriptChannelNames.toList()); - } - - @override - Future removeJavascriptChannels(Set javascriptChannelNames) { - return _channel.invokeMethod( - 'removeJavascriptChannels', javascriptChannelNames.toList()); - } - - @override - Future getTitle() => _channel.invokeMethod('getTitle'); - - @override - Future scrollTo(int x, int y) { - return _channel.invokeMethod('scrollTo', { - 'x': x, - 'y': y, - }); - } - - @override - Future scrollBy(int x, int y) { - return _channel.invokeMethod('scrollBy', { - 'x': x, - 'y': y, - }); - } - - @override - Future getScrollX() => - _channel.invokeMethod('getScrollX').then((int? result) => result!); - - @override - Future getScrollY() => - _channel.invokeMethod('getScrollY').then((int? result) => result!); - - /// Method channel implementation for [WebViewPlatform.clearCookies]. - static Future clearCookies() { - return _cookieManagerChannel - .invokeMethod('clearCookies') - .then((dynamic result) => result! as bool); - } - - /// Method channel implementation for [WebViewPlatform.setCookie]. - static Future setCookie(WebViewCookie cookie) { - return _cookieManagerChannel.invokeMethod( - 'setCookie', cookie.toJson()); - } - - static Map _webSettingsToMap(WebSettings? settings) { - final Map map = {}; - void addIfNonNull(String key, dynamic value) { - if (value == null) { - return; - } - map[key] = value; - } - - void addSettingIfPresent(String key, WebSetting setting) { - if (!setting.isPresent) { - return; - } - map[key] = setting.value; - } - - addIfNonNull('jsMode', settings!.javascriptMode?.index); - addIfNonNull('hasNavigationDelegate', settings.hasNavigationDelegate); - addIfNonNull('hasProgressTracking', settings.hasProgressTracking); - addIfNonNull('debuggingEnabled', settings.debuggingEnabled); - addIfNonNull('gestureNavigationEnabled', settings.gestureNavigationEnabled); - addIfNonNull( - 'allowsInlineMediaPlayback', settings.allowsInlineMediaPlayback); - addSettingIfPresent('userAgent', settings.userAgent); - addIfNonNull('zoomEnabled', settings.zoomEnabled); - return map; - } - - /// Converts a [CreationParams] object to a map as expected by `platform_views` channel. - /// - /// This is used for the `creationParams` argument of the platform views created by - /// [AndroidWebViewBuilder] and [CupertinoWebViewBuilder]. - static Map creationParamsToMap( - CreationParams creationParams, { - bool usesHybridComposition = false, - }) { - return { - 'initialUrl': creationParams.initialUrl, - 'settings': _webSettingsToMap(creationParams.webSettings), - 'javascriptChannelNames': creationParams.javascriptChannelNames.toList(), - 'userAgent': creationParams.userAgent, - 'autoMediaPlaybackPolicy': creationParams.autoMediaPlaybackPolicy.index, - 'usesHybridComposition': usesHybridComposition, - 'backgroundColor': creationParams.backgroundColor?.value, - 'cookies': creationParams.cookies - .map((WebViewCookie cookie) => cookie.toJson()) - .toList() - }; - } -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/platform_navigation_delegate.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_navigation_delegate.dart similarity index 78% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/platform_navigation_delegate.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_navigation_delegate.dart index a66f1defdf60..2df6cff73ab5 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/platform_navigation_delegate.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_navigation_delegate.dart @@ -9,6 +9,19 @@ import 'package:plugin_platform_interface/plugin_platform_interface.dart'; import 'webview_platform.dart'; +/// Signature for callbacks that report a pending navigation request. +typedef NavigationRequestCallback = FutureOr Function( + NavigationRequest navigationRequest); + +/// Signature for callbacks that report page events triggered by the native web view. +typedef PageEventCallback = void Function(String url); + +/// Signature for callbacks that report loading progress of a page. +typedef ProgressCallback = void Function(int progress); + +/// Signature for callbacks that report a resource loading error. +typedef WebResourceErrorCallback = void Function(WebResourceError error); + /// An interface defining navigation events that occur on the native platform. /// /// The [PlatformWebViewController] is notifying this delegate on events that @@ -40,8 +53,7 @@ abstract class PlatformNavigationDelegate extends PlatformInterface { /// /// See [PlatformWebViewController.setPlatformNavigationDelegate]. Future setOnNavigationRequest( - FutureOr Function({required String url, required bool isForMainFrame}) - onNavigationRequest, + NavigationRequestCallback onNavigationRequest, ) { throw UnimplementedError( 'setOnNavigationRequest is not implemented on the current platform.'); @@ -51,7 +63,7 @@ abstract class PlatformNavigationDelegate extends PlatformInterface { /// /// See [PlatformWebViewController.setPlatformNavigationDelegate]. Future setOnPageStarted( - void Function(String url) onPageStarted, + PageEventCallback onPageStarted, ) { throw UnimplementedError( 'setOnPageStarted is not implemented on the current platform.'); @@ -61,7 +73,7 @@ abstract class PlatformNavigationDelegate extends PlatformInterface { /// /// See [PlatformWebViewController.setPlatformNavigationDelegate]. Future setOnPageFinished( - void Function(String url) onPageFinished, + PageEventCallback onPageFinished, ) { throw UnimplementedError( 'setOnPageFinished is not implemented on the current platform.'); @@ -71,7 +83,7 @@ abstract class PlatformNavigationDelegate extends PlatformInterface { /// /// See [PlatformWebViewController.setPlatformNavigationDelegate]. Future setOnProgress( - void Function(int progress) onProgress, + ProgressCallback onProgress, ) { throw UnimplementedError( 'setOnProgress is not implemented on the current platform.'); @@ -81,7 +93,7 @@ abstract class PlatformNavigationDelegate extends PlatformInterface { /// /// See [PlatformWebViewController.setPlatformNavigationDelegate]. Future setOnWebResourceError( - void Function(WebResourceError error) onWebResourceError, + WebResourceErrorCallback onWebResourceError, ) { throw UnimplementedError( 'setOnWebResourceError is not implemented on the current platform.'); diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/platform_webview_controller.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_controller.dart similarity index 92% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/platform_webview_controller.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_controller.dart index 3585ec8b1886..7bb259c274b1 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/platform_webview_controller.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_controller.dart @@ -2,13 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:math'; -import 'dart:ui'; - import 'package:flutter/foundation.dart'; +import 'package:flutter/painting.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; -import 'platform_navigation_delegate.dart'; +import '../../src/platform_navigation_delegate.dart'; import 'webview_platform.dart'; /// Interface for a platform implementation of a web view controller. @@ -178,7 +176,7 @@ abstract class PlatformWebViewController extends PlatformInterface { /// The Future completes with an error if a JavaScript error occurred, or if the /// type the given expression evaluates to is unsupported. Unsupported values include /// certain non-primitive types on iOS, as well as `undefined` or `null` on iOS 14+. - Future runJavaScriptReturningResult(String javaScript) { + Future runJavaScriptReturningResult(String javaScript) { throw UnimplementedError( 'runJavaScriptReturningResult is not implemented on the current platform'); } @@ -226,24 +224,12 @@ abstract class PlatformWebViewController extends PlatformInterface { /// Return the current scroll position of this view. /// /// Scroll position is measured from the top left. - Future> getScrollPosition() { + Future getScrollPosition() { throw UnimplementedError( 'getScrollPosition is not implemented on the current platform'); } - /// Whether to enable the platform's webview content debugging tools. - Future enableDebugging(bool enabled) { - throw UnimplementedError( - 'enableDebugging is not implemented on the current platform'); - } - - /// Whether to allow swipe based navigation on supported platforms. - Future enableGestureNavigation(bool enabled) { - throw UnimplementedError( - 'enableGestureNavigation is not implemented on the current platform'); - } - - /// Whhether to support zooming using its on-screen zoom controls and gestures. + /// Whether to support zooming using its on-screen zoom controls and gestures. Future enableZoom(bool enabled) { throw UnimplementedError( 'enableZoom is not implemented on the current platform'); @@ -269,9 +255,10 @@ abstract class PlatformWebViewController extends PlatformInterface { } /// Describes the parameters necessary for registering a JavaScript channel. +@immutable class JavaScriptChannelParams { /// Creates a new [JavaScriptChannelParams] object. - JavaScriptChannelParams({ + const JavaScriptChannelParams({ required this.name, required this.onMessageReceived, }); diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/platform_webview_cookie_manager.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_cookie_manager.dart similarity index 100% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/platform_webview_cookie_manager.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_cookie_manager.dart diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/platform_webview_widget.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_widget.dart similarity index 100% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/platform_webview_widget.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_widget.dart diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_message.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_message.dart index 8d080452c54a..b37661a045a9 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_message.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_message.dart @@ -2,12 +2,49 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'package:flutter/foundation.dart'; + /// A message that was sent by JavaScript code running in a [WebView]. -class JavascriptMessage { - /// Constructs a JavaScript message object. - /// - /// The `message` parameter must not be null. - const JavascriptMessage(this.message) : assert(message != null); +/// +/// Platform specific implementations can add additional fields by extending +/// this class and providing a factory method that takes the +/// [JavaScriptMessage] as a parameter. +/// +/// {@tool sample} +/// This example demonstrates how to extend the [JavaScriptMessage] to +/// provide additional platform specific parameters. +/// +/// When extending [JavaScriptMessage] additional parameters should always +/// accept `null` or have a default value to prevent breaking changes. +/// +/// ```dart +/// @immutable +/// class WKWebViewScriptMessage extends JavaScriptMessage { +/// WKWebViewScriptMessage._( +/// JavaScriptMessage javaScriptMessage, +/// this.extraData, +/// ) : super(javaScriptMessage.message); +/// +/// factory WKWebViewScriptMessage.fromJavaScripMessage( +/// JavaScriptMessage javaScripMessage, { +/// String? extraData, +/// }) { +/// return WKWebViewScriptMessage._( +/// javaScriptMessage, +/// extraData: extraData, +/// ); +/// } +/// +/// final String? extraData; +/// } +/// ``` +/// {@end-tool} +@immutable +class JavaScriptMessage { + /// Creates a new JavaScript message object. + const JavaScriptMessage({ + required this.message, + }); /// The contents of the message that was sent by the JavaScript code. final String message; diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_mode.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_mode.dart index 53d049175907..bcbebff8bb1a 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_mode.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_mode.dart @@ -3,7 +3,7 @@ // found in the LICENSE file. /// Describes the state of JavaScript support in a given web view. -enum JavascriptMode { +enum JavaScriptMode { /// JavaScript execution is disabled. disabled, diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/load_request_params.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/load_request_params.dart similarity index 94% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/load_request_params.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/load_request_params.dart index a0d1c8821798..ad934d6747b7 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/load_request_params.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/load_request_params.dart @@ -72,8 +72,8 @@ class LoadRequestParams { /// Used by the platform implementation to create a new [LoadRequestParams]. const LoadRequestParams({ required this.uri, - required this.method, - required this.headers, + this.method = LoadRequestMethod.get, + this.headers = const {}, this.body, }); @@ -81,6 +81,8 @@ class LoadRequestParams { final Uri uri; /// HTTP method used to make the request. + /// + /// Defaults to [LoadRequestMethod.get]. final LoadRequestMethod method; /// Headers for the request. diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_decision.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_decision.dart new file mode 100644 index 000000000000..d8178acd8096 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_decision.dart @@ -0,0 +1,12 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// A decision on how to handle a navigation request. +enum NavigationDecision { + /// Prevent the navigation from taking place. + prevent, + + /// Allow the navigation to take place. + navigate, +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_request.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_request.dart new file mode 100644 index 000000000000..ee3f1f910f9d --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_request.dart @@ -0,0 +1,18 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// Defines the parameters of the pending navigation callback. +class NavigationRequest { + /// Creates a [NavigationRequest]. + const NavigationRequest({ + required this.url, + required this.isMainFrame, + }); + + /// The URL of the pending navigation request. + final String url; + + /// Indicates whether the request was made in the web site's main frame or a subframe. + final bool isMainFrame; +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/platform_navigation_delegate_creation_params.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_navigation_delegate_creation_params.dart similarity index 100% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/platform_navigation_delegate_creation_params.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_navigation_delegate_creation_params.dart diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/platform_webview_controller_creation_params.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_controller_creation_params.dart similarity index 100% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/platform_webview_controller_creation_params.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_controller_creation_params.dart diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/platform_webview_cookie_manager_creation_params.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_cookie_manager_creation_params.dart similarity index 100% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/platform_webview_cookie_manager_creation_params.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_cookie_manager_creation_params.dart diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/platform_webview_widget_creation_params.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_widget_creation_params.dart similarity index 100% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/platform_webview_widget_creation_params.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_widget_creation_params.dart diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/types.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/types.dart index f2bcf19f42fd..4df8800c83e1 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/types.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/types.dart @@ -2,13 +2,14 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -export 'auto_media_playback_policy.dart'; -export 'creation_params.dart'; -export 'javascript_channel.dart'; export 'javascript_message.dart'; export 'javascript_mode.dart'; +export 'load_request_params.dart'; +export 'navigation_decision.dart'; +export 'navigation_request.dart'; +export 'platform_navigation_delegate_creation_params.dart'; +export 'platform_webview_controller_creation_params.dart'; +export 'platform_webview_cookie_manager_creation_params.dart'; +export 'platform_webview_widget_creation_params.dart'; export 'web_resource_error.dart'; -export 'web_resource_error_type.dart'; -export 'web_settings.dart'; export 'webview_cookie.dart'; -export 'webview_request.dart'; diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/web_resource_error.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/web_resource_error.dart index b61671f0ac45..e2522da859f7 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/web_resource_error.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/web_resource_error.dart @@ -2,56 +2,122 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'web_resource_error_type.dart'; +import 'package:flutter/foundation.dart'; + +/// Possible error type categorizations used by [WebResourceError]. +enum WebResourceErrorType { + /// User authentication failed on server. + authentication, + + /// Malformed URL. + badUrl, + + /// Failed to connect to the server. + connect, + + /// Failed to perform SSL handshake. + failedSslHandshake, + + /// Generic file error. + file, + + /// File not found. + fileNotFound, + + /// Server or proxy hostname lookup failed. + hostLookup, + + /// Failed to read or write to the server. + io, + + /// User authentication failed on proxy. + proxyAuthentication, + + /// Too many redirects. + redirectLoop, + + /// Connection timed out. + timeout, + + /// Too many requests during this load. + tooManyRequests, + + /// Generic error. + unknown, + + /// Resource load was canceled by Safe Browsing. + unsafeResource, + + /// Unsupported authentication scheme (not basic or digest). + unsupportedAuthScheme, + + /// Unsupported URI scheme. + unsupportedScheme, + + /// The web content process was terminated. + webContentProcessTerminated, + + /// The web view was invalidated. + webViewInvalidated, + + /// A JavaScript exception occurred. + javaScriptExceptionOccurred, + + /// The result of JavaScript execution could not be returned. + javaScriptResultTypeIsUnsupported, +} /// Error returned in `WebView.onWebResourceError` when a web resource loading error has occurred. +/// +/// Platform specific implementations can add additional fields by extending +/// this class. +/// +/// {@tool sample} +/// This example demonstrates how to extend the [WebResourceError] to +/// provide additional platform specific parameters. +/// +/// When extending [WebResourceError] additional parameters should always +/// accept `null` or have a default value to prevent breaking changes. +/// +/// ```dart +/// class IOSWebResourceError extends WebResourceError { +/// IOSWebResourceError._(WebResourceError error, {required this.domain}) +/// : super( +/// errorCode: error.errorCode, +/// description: error.description, +/// errorType: error.errorType, +/// ); +/// +/// factory IOSWebResourceError.fromWebResourceError( +/// WebResourceError error, { +/// required String? domain, +/// }) { +/// return IOSWebResourceError._(error, domain: domain); +/// } +/// +/// final String? domain; +/// } +/// ``` +/// {@end-tool} +@immutable class WebResourceError { - /// Creates a new [WebResourceError] - /// - /// A user should not need to instantiate this class, but will receive one in - /// [WebResourceErrorCallback]. - WebResourceError({ + /// Used by the platform implementation to create a new [WebResourceError]. + const WebResourceError({ required this.errorCode, required this.description, - this.domain, this.errorType, - this.failingUrl, - }) : assert(errorCode != null), - assert(description != null); + this.isForMainFrame, + }); /// Raw code of the error from the respective platform. - /// - /// On Android, the error code will be a constant from a - /// [WebViewClient](https://developer.android.com/reference/android/webkit/WebViewClient#summary) and - /// will have a corresponding [errorType]. - /// - /// On iOS, the error code will be a constant from `NSError.code` in - /// Objective-C. See - /// https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/ErrorObjectsDomains/ErrorObjectsDomains.html - /// for more information on error handling on iOS. Some possible error codes - /// can be found at https://developer.apple.com/documentation/webkit/wkerrorcode?language=objc. final int errorCode; - /// The domain of where to find the error code. - /// - /// This field is only available on iOS and represents a "domain" from where - /// the [errorCode] is from. This value is taken directly from an `NSError` - /// in Objective-C. See - /// https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/ErrorObjectsDomains/ErrorObjectsDomains.html - /// for more information on error handling on iOS. - final String? domain; - /// Description of the error that can be used to communicate the problem to the user. final String description; /// The type this error can be categorized as. - /// - /// This will never be `null` on Android, but can be `null` on iOS. final WebResourceErrorType? errorType; - /// Gets the URL for which the resource request was made. - /// - /// This value is not provided on iOS. Alternatively, you can keep track of - /// the last values provided to [WebViewPlatformController.loadUrl]. - final String? failingUrl; + /// Whether the error originated from the main frame. + final bool? isForMainFrame; } diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/webview_cookie.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/webview_cookie.dart index 406c510afd4b..7f56a312049f 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/webview_cookie.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/webview_cookie.dart @@ -2,15 +2,18 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -/// A cookie that can be set globally for all web views -/// using [WebViewCookieManagerPlatform]. +import 'package:flutter/foundation.dart'; + +/// A cookie that can be set globally for all web views using [WebViewCookieManagerPlatform]. +@immutable class WebViewCookie { - /// Constructs a new [WebViewCookie]. - const WebViewCookie( - {required this.name, - required this.value, - required this.domain, - this.path = '/'}); + /// Creates a new [WebViewCookieDelegate] + const WebViewCookie({ + required this.name, + required this.value, + required this.domain, + this.path = '/', + }); /// The cookie-name of the cookie. /// @@ -30,20 +33,9 @@ class WebViewCookie { /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 final String domain; - /// The path-value of the cookie. - /// Is set to `/` in the constructor by default. + /// The path-value of the cookie, set to `/` by default. /// /// Its value should match "path-value" in RFC6265bis: /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 final String path; - - /// Serializes the [WebViewCookie] to a Map. - Map toJson() { - return { - 'name': name, - 'value': value, - 'domain': domain, - 'path': path - }; - } } diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/webview_flutter_platform_interface_legacy.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/webview_flutter_platform_interface_legacy.dart new file mode 100644 index 000000000000..1964e7089d2d --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/webview_flutter_platform_interface_legacy.dart @@ -0,0 +1,6 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +export 'legacy/platform_interface/platform_interface.dart'; +export 'legacy/types/types.dart'; diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/webview_platform.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/webview_platform.dart similarity index 98% rename from packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/webview_platform.dart rename to packages/webview_flutter/webview_flutter_platform_interface/lib/src/webview_platform.dart index c5c5dffc6a22..e91396243ea5 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/webview_platform.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/webview_platform.dart @@ -4,7 +4,7 @@ import 'package:plugin_platform_interface/plugin_platform_interface.dart'; -import 'platform_navigation_delegate.dart'; +import '../../src/platform_navigation_delegate.dart'; import 'platform_webview_controller.dart'; import 'platform_webview_cookie_manager.dart'; import 'platform_webview_widget.dart'; diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/javascript_message.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/javascript_message.dart deleted file mode 100644 index b37661a045a9..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/javascript_message.dart +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter/foundation.dart'; - -/// A message that was sent by JavaScript code running in a [WebView]. -/// -/// Platform specific implementations can add additional fields by extending -/// this class and providing a factory method that takes the -/// [JavaScriptMessage] as a parameter. -/// -/// {@tool sample} -/// This example demonstrates how to extend the [JavaScriptMessage] to -/// provide additional platform specific parameters. -/// -/// When extending [JavaScriptMessage] additional parameters should always -/// accept `null` or have a default value to prevent breaking changes. -/// -/// ```dart -/// @immutable -/// class WKWebViewScriptMessage extends JavaScriptMessage { -/// WKWebViewScriptMessage._( -/// JavaScriptMessage javaScriptMessage, -/// this.extraData, -/// ) : super(javaScriptMessage.message); -/// -/// factory WKWebViewScriptMessage.fromJavaScripMessage( -/// JavaScriptMessage javaScripMessage, { -/// String? extraData, -/// }) { -/// return WKWebViewScriptMessage._( -/// javaScriptMessage, -/// extraData: extraData, -/// ); -/// } -/// -/// final String? extraData; -/// } -/// ``` -/// {@end-tool} -@immutable -class JavaScriptMessage { - /// Creates a new JavaScript message object. - const JavaScriptMessage({ - required this.message, - }); - - /// The contents of the message that was sent by the JavaScript code. - final String message; -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/web_resource_error.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/web_resource_error.dart deleted file mode 100644 index 465799472912..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/src/types/web_resource_error.dart +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter/foundation.dart'; - -/// Possible error type categorizations used by [WebResourceError]. -enum WebResourceErrorType { - /// User authentication failed on server. - authentication, - - /// Malformed URL. - badUrl, - - /// Failed to connect to the server. - connect, - - /// Failed to perform SSL handshake. - failedSslHandshake, - - /// Generic file error. - file, - - /// File not found. - fileNotFound, - - /// Server or proxy hostname lookup failed. - hostLookup, - - /// Failed to read or write to the server. - io, - - /// User authentication failed on proxy. - proxyAuthentication, - - /// Too many redirects. - redirectLoop, - - /// Connection timed out. - timeout, - - /// Too many requests during this load. - tooManyRequests, - - /// Generic error. - unknown, - - /// Resource load was canceled by Safe Browsing. - unsafeResource, - - /// Unsupported authentication scheme (not basic or digest). - unsupportedAuthScheme, - - /// Unsupported URI scheme. - unsupportedScheme, - - /// The web content process was terminated. - webContentProcessTerminated, - - /// The web view was invalidated. - webViewInvalidated, - - /// A JavaScript exception occurred. - javaScriptExceptionOccurred, - - /// The result of JavaScript execution could not be returned. - javaScriptResultTypeIsUnsupported, -} - -/// Error returned in `WebView.onWebResourceError` when a web resource loading error has occurred. -/// -/// Platform specific implementations can add additional fields by extending -/// this class. -/// -/// {@tool sample} -/// This example demonstrates how to extend the [WebResourceError] to -/// provide additional platform specific parameters. -/// -/// When extending [WebResourceError] additional parameters should always -/// accept `null` or have a default value to prevent breaking changes. -/// -/// ```dart -/// class IOSWebResourceError extends WebResourceError { -/// IOSWebResourceError._(WebResourceError error, {required this.domain}) -/// : super( -/// errorCode: error.errorCode, -/// description: error.description, -/// errorType: error.errorType, -/// ); -/// -/// factory IOSWebResourceError.fromWebResourceError( -/// WebResourceError error, { -/// required String? domain, -/// }) { -/// return IOSWebResourceError._(error, domain: domain); -/// } -/// -/// final String? domain; -/// } -/// ``` -/// {@end-tool} -@immutable -class WebResourceError { - /// Used by the platform implementation to create a new [WebResourceError]. - const WebResourceError({ - required this.errorCode, - required this.description, - this.errorType, - }); - - /// Raw code of the error from the respective platform. - final int errorCode; - - /// Description of the error that can be used to communicate the problem to the user. - final String description; - - /// The type this error can be categorized as. - final WebResourceErrorType? errorType; -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/webview_flutter_platform_interface.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/webview_flutter_platform_interface.dart deleted file mode 100644 index d14fec163327..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/v4/webview_flutter_platform_interface.dart +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -export 'src/platform_navigation_delegate.dart'; -export 'src/platform_webview_controller.dart'; -export 'src/platform_webview_cookie_manager.dart'; -export 'src/platform_webview_widget.dart'; -export 'src/types/types.dart'; -export 'src/webview_platform.dart'; diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/webview_flutter_platform_interface.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/webview_flutter_platform_interface.dart index aa41c8285975..d14fec163327 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/webview_flutter_platform_interface.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/webview_flutter_platform_interface.dart @@ -2,6 +2,9 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -export 'src/method_channel/webview_method_channel.dart'; -export 'src/platform_interface/platform_interface.dart'; +export 'src/platform_navigation_delegate.dart'; +export 'src/platform_webview_controller.dart'; +export 'src/platform_webview_cookie_manager.dart'; +export 'src/platform_webview_widget.dart'; export 'src/types/types.dart'; +export 'src/webview_platform.dart'; diff --git a/packages/webview_flutter/webview_flutter_platform_interface/pubspec.yaml b/packages/webview_flutter/webview_flutter_platform_interface/pubspec.yaml index 8f60592b852d..e4b5381eed3c 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_platform_interface/pubspec.yaml @@ -5,6 +5,7 @@ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+ # NOTE: We strongly prefer non-breaking changes, even at the expense of a # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes version: 1.9.5 +publish_to: none environment: sdk: ">=2.12.0 <3.0.0" diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/src/platform_interface/javascript_channel_registry_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/platform_interface/javascript_channel_registry_test.dart similarity index 94% rename from packages/webview_flutter/webview_flutter_platform_interface/test/src/platform_interface/javascript_channel_registry_test.dart rename to packages/webview_flutter/webview_flutter_platform_interface/test/legacy/platform_interface/javascript_channel_registry_test.dart index aec568e92b79..c9d27c601985 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/src/platform_interface/javascript_channel_registry_test.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/platform_interface/javascript_channel_registry_test.dart @@ -3,8 +3,7 @@ // found in the LICENSE file. import 'package:flutter_test/flutter_test.dart'; -import 'package:webview_flutter_platform_interface/src/platform_interface/javascript_channel_registry.dart'; -import 'package:webview_flutter_platform_interface/src/types/types.dart'; +import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; void main() { final Map log = {}; diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/src/platform_interface/webview_cookie_manager_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/platform_interface/webview_cookie_manager_test.dart similarity index 81% rename from packages/webview_flutter/webview_flutter_platform_interface/test/src/platform_interface/webview_cookie_manager_test.dart rename to packages/webview_flutter/webview_flutter_platform_interface/test/legacy/platform_interface/webview_cookie_manager_test.dart index e0aae2146abc..a9faea52e407 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/src/platform_interface/webview_cookie_manager_test.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/platform_interface/webview_cookie_manager_test.dart @@ -3,8 +3,7 @@ // found in the LICENSE file. import 'package:flutter_test/flutter_test.dart'; -import 'package:webview_flutter_platform_interface/src/platform_interface/platform_interface.dart'; -import 'package:webview_flutter_platform_interface/src/types/webview_cookie.dart'; +import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; void main() { WebViewCookieManagerPlatform? cookieManager; diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/src/types/javascript_channel_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/javascript_channel_test.dart similarity index 93% rename from packages/webview_flutter/webview_flutter_platform_interface/test/src/types/javascript_channel_test.dart rename to packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/javascript_channel_test.dart index 8d7177150b7c..ecb9c3fbed10 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/src/types/javascript_channel_test.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/javascript_channel_test.dart @@ -3,7 +3,7 @@ // found in the LICENSE file. import 'package:flutter_test/flutter_test.dart'; -import 'package:webview_flutter_platform_interface/src/types/javascript_channel.dart'; +import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; void main() { final List validChars = diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/src/types/webview_cookie_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/webview_cookie_test.dart similarity index 87% rename from packages/webview_flutter/webview_flutter_platform_interface/test/src/types/webview_cookie_test.dart rename to packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/webview_cookie_test.dart index f058b8649b96..f1702f4ad1c0 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/src/types/webview_cookie_test.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/webview_cookie_test.dart @@ -3,7 +3,7 @@ // found in the LICENSE file. import 'package:flutter_test/flutter_test.dart'; -import 'package:webview_flutter_platform_interface/src/types/types.dart'; +import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; void main() { test('WebViewCookie should serialize correctly', () { diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/src/types/webview_request_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/webview_request_test.dart similarity index 93% rename from packages/webview_flutter/webview_flutter_platform_interface/test/src/types/webview_request_test.dart rename to packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/webview_request_test.dart index 6e1a4d7b4d56..fff1a9b19878 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/src/types/webview_request_test.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/webview_request_test.dart @@ -4,7 +4,7 @@ import 'dart:typed_data'; import 'package:flutter_test/flutter_test.dart'; -import 'package:webview_flutter_platform_interface/src/types/types.dart'; +import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; void main() { test('WebViewRequestMethod should serialize correctly', () { diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_navigation_delegate_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/platform_navigation_delegate_test.dart similarity index 95% rename from packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_navigation_delegate_test.dart rename to packages/webview_flutter/webview_flutter_platform_interface/test/platform_navigation_delegate_test.dart index dd4a26c4faf9..5e9aa2e12437 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_navigation_delegate_test.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/platform_navigation_delegate_test.dart @@ -5,8 +5,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; -import 'package:webview_flutter_platform_interface/v4/src/platform_navigation_delegate.dart'; -import 'package:webview_flutter_platform_interface/v4/src/webview_platform.dart'; +import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; import 'webview_platform_test.mocks.dart'; @@ -61,7 +60,7 @@ void main() { expect( () => callbackDelegate.setOnNavigationRequest( - ({required bool isForMainFrame, required String url}) => true), + (NavigationRequest navigationRequest) => NavigationDecision.navigate), throwsUnimplementedError, ); }); diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_webview_controller_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.dart similarity index 92% rename from packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_webview_controller_test.dart rename to packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.dart index 32374fb04484..6710f34895b7 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_webview_controller_test.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.dart @@ -7,9 +7,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; -import 'package:webview_flutter_platform_interface/v4/src/platform_navigation_delegate.dart'; -import 'package:webview_flutter_platform_interface/v4/src/platform_webview_controller.dart'; -import 'package:webview_flutter_platform_interface/v4/src/webview_platform.dart'; +import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; import 'platform_navigation_delegate_test.dart'; import 'webview_platform_test.mocks.dart'; @@ -357,34 +355,6 @@ void main() { ); }); - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of enableDebugging should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.enableDebugging(true), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of enableGestureNavigation should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.enableGestureNavigation(true), - throwsUnimplementedError, - ); - }); - test( // ignore: lines_longer_than_80_chars 'Default implementation of enableZoom should throw unimplemented error', diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.mocks.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.mocks.dart new file mode 100644 index 000000000000..db142fe6a782 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.mocks.dart @@ -0,0 +1,106 @@ +// Mocks generated by Mockito 5.3.2 from annotations +// in webview_flutter_platform_interface/test/platform_webview_controller_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i4; + +import 'package:mockito/mockito.dart' as _i1; +import 'package:webview_flutter_platform_interface/src/platform_navigation_delegate.dart' + as _i3; +import 'package:webview_flutter_platform_interface/src/webview_platform.dart' + as _i2; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +class _FakePlatformNavigationDelegateCreationParams_0 extends _i1.SmartFake + implements _i2.PlatformNavigationDelegateCreationParams { + _FakePlatformNavigationDelegateCreationParams_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [PlatformNavigationDelegate]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockPlatformNavigationDelegate extends _i1.Mock + implements _i3.PlatformNavigationDelegate { + MockPlatformNavigationDelegate() { + _i1.throwOnMissingStub(this); + } + + @override + _i2.PlatformNavigationDelegateCreationParams get params => + (super.noSuchMethod( + Invocation.getter(#params), + returnValue: _FakePlatformNavigationDelegateCreationParams_0( + this, + Invocation.getter(#params), + ), + ) as _i2.PlatformNavigationDelegateCreationParams); + @override + _i4.Future setOnNavigationRequest( + _i3.NavigationRequestCallback? onNavigationRequest) => + (super.noSuchMethod( + Invocation.method( + #setOnNavigationRequest, + [onNavigationRequest], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + @override + _i4.Future setOnPageStarted(_i3.PageEventCallback? onPageStarted) => + (super.noSuchMethod( + Invocation.method( + #setOnPageStarted, + [onPageStarted], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + @override + _i4.Future setOnPageFinished(_i3.PageEventCallback? onPageFinished) => + (super.noSuchMethod( + Invocation.method( + #setOnPageFinished, + [onPageFinished], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + @override + _i4.Future setOnProgress(_i3.ProgressCallback? onProgress) => + (super.noSuchMethod( + Invocation.method( + #setOnProgress, + [onProgress], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + @override + _i4.Future setOnWebResourceError( + _i3.WebResourceErrorCallback? onWebResourceError) => + (super.noSuchMethod( + Invocation.method( + #setOnWebResourceError, + [onWebResourceError], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_webview_widget_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_widget_test.dart similarity index 92% rename from packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_webview_widget_test.dart rename to packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_widget_test.dart index ede16c162413..652f326cf20e 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_webview_widget_test.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_widget_test.dart @@ -6,9 +6,7 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/mockito.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; -import 'package:webview_flutter_platform_interface/v4/src/platform_webview_controller.dart'; -import 'package:webview_flutter_platform_interface/v4/src/platform_webview_widget.dart'; -import 'package:webview_flutter_platform_interface/v4/src/webview_platform.dart'; +import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; import 'webview_platform_test.mocks.dart'; diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/src/method_channel/webview_method_channel_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/src/method_channel/webview_method_channel_test.dart deleted file mode 100644 index ea9eb92452ba..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/src/method_channel/webview_method_channel_test.dart +++ /dev/null @@ -1,746 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// TODO(a14n): remove this import once Flutter 3.1 or later reaches stable (including flutter/flutter#106316) -// ignore: unnecessary_import -import 'dart:typed_data'; - -// TODO(a14n): remove this import once Flutter 3.1 or later reaches stable (including flutter/flutter#106316) -// ignore: unnecessary_import -import 'package:flutter/cupertino.dart'; -import 'package:flutter/services.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:mockito/mockito.dart'; -import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; - -void main() { - TestWidgetsFlutterBinding.ensureInitialized(); - - group('Tests on `plugin.flutter.io/webview_` channel', () { - const int channelId = 1; - const MethodChannel channel = - MethodChannel('plugins.flutter.io/webview_$channelId'); - final WebViewPlatformCallbacksHandler callbacksHandler = - MockWebViewPlatformCallbacksHandler(); - final JavascriptChannelRegistry javascriptChannelRegistry = - MockJavascriptChannelRegistry(); - - final List log = []; - channel.setMockMethodCallHandler((MethodCall methodCall) async { - log.add(methodCall); - - switch (methodCall.method) { - case 'currentUrl': - return 'https://test.url'; - case 'canGoBack': - case 'canGoForward': - return true; - case 'loadFile': - if (methodCall.arguments == 'invalid file') { - throw PlatformException( - code: 'loadFile_failed', message: 'Failed loading file.'); - } else if (methodCall.arguments == 'some error') { - throw PlatformException( - code: 'some_error', - message: 'Some error occurred.', - ); - } - return null; - case 'loadFlutterAsset': - if (methodCall.arguments == 'invalid key') { - throw PlatformException( - code: 'loadFlutterAsset_invalidKey', - message: 'Failed loading asset.', - ); - } else if (methodCall.arguments == 'some error') { - throw PlatformException( - code: 'some_error', - message: 'Some error occurred.', - ); - } - return null; - case 'runJavascriptReturningResult': - case 'evaluateJavascript': - return methodCall.arguments as String; - case 'getScrollX': - return 10; - case 'getScrollY': - return 20; - } - - // Return null explicitly instead of relying on the implicit null - // returned by the method channel if no return statement is specified. - return null; - }); - - final MethodChannelWebViewPlatform webViewPlatform = - MethodChannelWebViewPlatform( - channelId, - callbacksHandler, - javascriptChannelRegistry, - ); - - tearDown(() { - log.clear(); - }); - - test('loadFile', () async { - await webViewPlatform.loadFile( - '/folder/asset.html', - ); - - expect( - log, - [ - isMethodCall( - 'loadFile', - arguments: '/folder/asset.html', - ), - ], - ); - }); - - test('loadFile with invalid file', () async { - expect( - () => webViewPlatform.loadFile('invalid file'), - throwsA( - isA().having( - (ArgumentError error) => error.message, - 'message', - 'Failed loading file.', - ), - ), - ); - }); - - test('loadFile with some error.', () async { - expect( - () => webViewPlatform.loadFile('some error'), - throwsA( - isA().having( - (PlatformException error) => error.message, - 'message', - 'Some error occurred.', - ), - ), - ); - }); - - test('loadFlutterAsset', () async { - await webViewPlatform.loadFlutterAsset( - 'folder/asset.html', - ); - - expect( - log, - [ - isMethodCall( - 'loadFlutterAsset', - arguments: 'folder/asset.html', - ), - ], - ); - }); - - test('loadFlutterAsset with empty key', () async { - expect(() => webViewPlatform.loadFlutterAsset(''), throwsAssertionError); - }); - - test('loadFlutterAsset with invalid key', () async { - expect( - () => webViewPlatform.loadFlutterAsset('invalid key'), - throwsA( - isA().having( - (ArgumentError error) => error.message, - 'message', - 'Failed loading asset.', - ), - ), - ); - }); - - test('loadFlutterAsset with some error.', () async { - expect( - () => webViewPlatform.loadFlutterAsset('some error'), - throwsA( - isA().having( - (PlatformException error) => error.message, - 'message', - 'Some error occurred.', - ), - ), - ); - }); - - test('loadHtmlString without base URL', () async { - await webViewPlatform.loadHtmlString( - 'Test HTML string', - ); - - expect( - log, - [ - isMethodCall( - 'loadHtmlString', - arguments: { - 'html': 'Test HTML string', - 'baseUrl': null, - }, - ), - ], - ); - }); - - test('loadHtmlString without base URL', () async { - await webViewPlatform.loadHtmlString( - 'Test HTML string', - baseUrl: 'https://flutter.dev', - ); - - expect( - log, - [ - isMethodCall( - 'loadHtmlString', - arguments: { - 'html': 'Test HTML string', - 'baseUrl': 'https://flutter.dev', - }, - ), - ], - ); - }); - - test('loadUrl with headers', () async { - await webViewPlatform.loadUrl( - 'https://test.url', - const { - 'Content-Type': 'text/plain', - 'Accept': 'text/html', - }, - ); - - expect( - log, - [ - isMethodCall( - 'loadUrl', - arguments: { - 'url': 'https://test.url', - 'headers': { - 'Content-Type': 'text/plain', - 'Accept': 'text/html', - }, - }, - ), - ], - ); - }); - - test('loadUrl without headers', () async { - await webViewPlatform.loadUrl( - 'https://test.url', - null, - ); - - expect( - log, - [ - isMethodCall( - 'loadUrl', - arguments: { - 'url': 'https://test.url', - 'headers': null, - }, - ), - ], - ); - }); - - test('loadRequest', () async { - await webViewPlatform.loadRequest(WebViewRequest( - uri: Uri.parse('https://test.url'), - method: WebViewRequestMethod.get, - )); - - expect( - log, - [ - isMethodCall( - 'loadRequest', - arguments: { - 'request': { - 'uri': 'https://test.url', - 'method': 'get', - 'headers': {}, - 'body': null, - } - }, - ), - ], - ); - }); - - test('loadRequest with optional parameters', () async { - await webViewPlatform.loadRequest(WebViewRequest( - uri: Uri.parse('https://test.url'), - method: WebViewRequestMethod.get, - headers: {'foo': 'bar'}, - body: Uint8List.fromList('hello world'.codeUnits), - )); - - expect( - log, - [ - isMethodCall( - 'loadRequest', - arguments: { - 'request': { - 'uri': 'https://test.url', - 'method': 'get', - 'headers': {'foo': 'bar'}, - 'body': 'hello world'.codeUnits, - } - }, - ), - ], - ); - }); - - test('currentUrl', () async { - final String? currentUrl = await webViewPlatform.currentUrl(); - - expect(currentUrl, 'https://test.url'); - expect( - log, - [ - isMethodCall( - 'currentUrl', - arguments: null, - ), - ], - ); - }); - - test('canGoBack', () async { - final bool canGoBack = await webViewPlatform.canGoBack(); - - expect(canGoBack, true); - expect( - log, - [ - isMethodCall( - 'canGoBack', - arguments: null, - ), - ], - ); - }); - - test('canGoForward', () async { - final bool canGoForward = await webViewPlatform.canGoForward(); - - expect(canGoForward, true); - expect( - log, - [ - isMethodCall( - 'canGoForward', - arguments: null, - ), - ], - ); - }); - - test('goBack', () async { - await webViewPlatform.goBack(); - - expect( - log, - [ - isMethodCall( - 'goBack', - arguments: null, - ), - ], - ); - }); - - test('goForward', () async { - await webViewPlatform.goForward(); - - expect( - log, - [ - isMethodCall( - 'goForward', - arguments: null, - ), - ], - ); - }); - - test('reload', () async { - await webViewPlatform.reload(); - - expect( - log, - [ - isMethodCall( - 'reload', - arguments: null, - ), - ], - ); - }); - - test('clearCache', () async { - await webViewPlatform.clearCache(); - - expect( - log, - [ - isMethodCall( - 'clearCache', - arguments: null, - ), - ], - ); - }); - - test('updateSettings', () async { - final WebSettings settings = - WebSettings(userAgent: const WebSetting.of('Dart Test')); - await webViewPlatform.updateSettings(settings); - - expect( - log, - [ - isMethodCall( - 'updateSettings', - arguments: { - 'userAgent': 'Dart Test', - }, - ), - ], - ); - }); - - test('updateSettings all parameters', () async { - final WebSettings settings = WebSettings( - userAgent: const WebSetting.of('Dart Test'), - javascriptMode: JavascriptMode.disabled, - hasNavigationDelegate: true, - hasProgressTracking: true, - debuggingEnabled: true, - gestureNavigationEnabled: true, - allowsInlineMediaPlayback: true, - zoomEnabled: false, - ); - await webViewPlatform.updateSettings(settings); - - expect( - log, - [ - isMethodCall( - 'updateSettings', - arguments: { - 'userAgent': 'Dart Test', - 'jsMode': 0, - 'hasNavigationDelegate': true, - 'hasProgressTracking': true, - 'debuggingEnabled': true, - 'gestureNavigationEnabled': true, - 'allowsInlineMediaPlayback': true, - 'zoomEnabled': false, - }, - ), - ], - ); - }); - - test('updateSettings without settings', () async { - final WebSettings settings = - WebSettings(userAgent: const WebSetting.absent()); - await webViewPlatform.updateSettings(settings); - - expect( - log.isEmpty, - true, - ); - }); - - test('evaluateJavascript', () async { - final String evaluateJavascript = - await webViewPlatform.evaluateJavascript( - 'This simulates some JavaScript code.', - ); - - expect('This simulates some JavaScript code.', evaluateJavascript); - expect( - log, - [ - isMethodCall( - 'evaluateJavascript', - arguments: 'This simulates some JavaScript code.', - ), - ], - ); - }); - - test('runJavascript', () async { - await webViewPlatform.runJavascript( - 'This simulates some JavaScript code.', - ); - - expect( - log, - [ - isMethodCall( - 'runJavascript', - arguments: 'This simulates some JavaScript code.', - ), - ], - ); - }); - - test('runJavascriptReturningResult', () async { - final String evaluateJavascript = - await webViewPlatform.runJavascriptReturningResult( - 'This simulates some JavaScript code.', - ); - - expect('This simulates some JavaScript code.', evaluateJavascript); - expect( - log, - [ - isMethodCall( - 'runJavascriptReturningResult', - arguments: 'This simulates some JavaScript code.', - ), - ], - ); - }); - - test('addJavascriptChannels', () async { - final Set channels = {'channel one', 'channel two'}; - await webViewPlatform.addJavascriptChannels(channels); - - expect(log, [ - isMethodCall( - 'addJavascriptChannels', - arguments: [ - 'channel one', - 'channel two', - ], - ), - ]); - }); - - test('addJavascriptChannels without channels', () async { - final Set channels = {}; - await webViewPlatform.addJavascriptChannels(channels); - - expect(log, [ - isMethodCall( - 'addJavascriptChannels', - arguments: [], - ), - ]); - }); - - test('removeJavascriptChannels', () async { - final Set channels = {'channel one', 'channel two'}; - await webViewPlatform.removeJavascriptChannels(channels); - - expect(log, [ - isMethodCall( - 'removeJavascriptChannels', - arguments: [ - 'channel one', - 'channel two', - ], - ), - ]); - }); - - test('removeJavascriptChannels without channels', () async { - final Set channels = {}; - await webViewPlatform.removeJavascriptChannels(channels); - - expect(log, [ - isMethodCall( - 'removeJavascriptChannels', - arguments: [], - ), - ]); - }); - - test('getTitle', () async { - final String? title = await webViewPlatform.getTitle(); - - expect(title, null); - expect( - log, - [ - isMethodCall('getTitle', arguments: null), - ], - ); - }); - - test('scrollTo', () async { - await webViewPlatform.scrollTo(10, 20); - - expect( - log, - [ - isMethodCall( - 'scrollTo', - arguments: { - 'x': 10, - 'y': 20, - }, - ), - ], - ); - }); - - test('scrollBy', () async { - await webViewPlatform.scrollBy(10, 20); - - expect( - log, - [ - isMethodCall( - 'scrollBy', - arguments: { - 'x': 10, - 'y': 20, - }, - ), - ], - ); - }); - - test('getScrollX', () async { - final int x = await webViewPlatform.getScrollX(); - - expect(x, 10); - expect( - log, - [ - isMethodCall( - 'getScrollX', - arguments: null, - ), - ], - ); - }); - - test('getScrollY', () async { - final int y = await webViewPlatform.getScrollY(); - - expect(y, 20); - expect( - log, - [ - isMethodCall( - 'getScrollY', - arguments: null, - ), - ], - ); - }); - - test('backgroundColor is null by default', () { - final CreationParams creationParams = CreationParams( - webSettings: WebSettings( - userAgent: const WebSetting.of('Dart Test'), - ), - ); - final Map creationParamsMap = - MethodChannelWebViewPlatform.creationParamsToMap(creationParams); - - expect(creationParamsMap['backgroundColor'], null); - }); - - test('backgroundColor is converted to an int', () { - const Color whiteColor = Color(0xFFFFFFFF); - final CreationParams creationParams = CreationParams( - backgroundColor: whiteColor, - webSettings: WebSettings( - userAgent: const WebSetting.of('Dart Test'), - ), - ); - final Map creationParamsMap = - MethodChannelWebViewPlatform.creationParamsToMap(creationParams); - - expect(creationParamsMap['backgroundColor'], whiteColor.value); - }); - }); - - group('Tests on `plugins.flutter.io/cookie_manager` channel', () { - const MethodChannel cookieChannel = - MethodChannel('plugins.flutter.io/cookie_manager'); - - final List log = []; - cookieChannel.setMockMethodCallHandler((MethodCall methodCall) async { - log.add(methodCall); - - if (methodCall.method == 'clearCookies') { - return true; - } - - // Return null explicitly instead of relying on the implicit null - // returned by the method channel if no return statement is specified. - return null; - }); - - tearDown(() { - log.clear(); - }); - - test('clearCookies', () async { - final bool clearCookies = - await MethodChannelWebViewPlatform.clearCookies(); - - expect(clearCookies, true); - expect( - log, - [ - isMethodCall( - 'clearCookies', - arguments: null, - ), - ], - ); - }); - - test('setCookie', () async { - await MethodChannelWebViewPlatform.setCookie(const WebViewCookie( - name: 'foo', value: 'bar', domain: 'flutter.dev')); - - expect( - log, - [ - isMethodCall( - 'setCookie', - arguments: { - 'name': 'foo', - 'value': 'bar', - 'domain': 'flutter.dev', - 'path': '/', - }, - ), - ], - ); - }); - }); -} - -class MockWebViewPlatformCallbacksHandler extends Mock - implements WebViewPlatformCallbacksHandler {} - -class MockJavascriptChannelRegistry extends Mock - implements JavascriptChannelRegistry {} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_webview_controller_test.mocks.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_webview_controller_test.mocks.dart deleted file mode 100644 index 47e67379f124..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/platform_webview_controller_test.mocks.dart +++ /dev/null @@ -1,72 +0,0 @@ -// Mocks generated by Mockito 5.0.16 from annotations -// in webview_flutter_platform_interface/test/src/v4/platform_webview_controller_test.dart. -// Do not manually edit this file. - -import 'dart:async' as _i4; - -import 'package:mockito/mockito.dart' as _i1; -import 'package:webview_flutter_platform_interface/v4/src/platform_navigation_delegate.dart' - as _i3; -import 'package:webview_flutter_platform_interface/v4/src/webview_platform.dart' - as _i2; - -// ignore_for_file: avoid_redundant_argument_values -// ignore_for_file: avoid_setters_without_getters -// ignore_for_file: comment_references -// ignore_for_file: implementation_imports -// ignore_for_file: invalid_use_of_visible_for_testing_member -// ignore_for_file: prefer_const_constructors -// ignore_for_file: unnecessary_parenthesis -// ignore_for_file: camel_case_types - -class _FakePlatformNavigationDelegateCreationParams_0 extends _i1.Fake - implements _i2.PlatformNavigationDelegateCreationParams {} - -/// A class which mocks [PlatformNavigationDelegate]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockPlatformNavigationDelegate extends _i1.Mock - implements _i3.PlatformNavigationDelegate { - MockPlatformNavigationDelegate() { - _i1.throwOnMissingStub(this); - } - - @override - _i2.PlatformNavigationDelegateCreationParams get params => - (super.noSuchMethod(Invocation.getter(#params), - returnValue: _FakePlatformNavigationDelegateCreationParams_0()) - as _i2.PlatformNavigationDelegateCreationParams); - @override - _i4.Future setOnNavigationRequest( - _i4.FutureOr Function({bool isForMainFrame, String url})? - onNavigationRequest) => - (super.noSuchMethod( - Invocation.method(#setOnNavigationRequest, [onNavigationRequest]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i4.Future); - @override - _i4.Future setOnPageStarted(void Function(String)? onPageStarted) => - (super.noSuchMethod(Invocation.method(#setOnPageStarted, [onPageStarted]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i4.Future); - @override - _i4.Future setOnPageFinished(void Function(String)? onPageFinished) => - (super.noSuchMethod( - Invocation.method(#setOnPageFinished, [onPageFinished]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i4.Future); - @override - _i4.Future setOnProgress(void Function(int)? onProgress) => - (super.noSuchMethod(Invocation.method(#setOnProgress, [onProgress]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i4.Future); - @override - _i4.Future setOnWebResourceError( - void Function(_i2.WebResourceError)? onWebResourceError) => - (super.noSuchMethod( - Invocation.method(#setOnWebResourceError, [onWebResourceError]), - returnValue: Future.value(), - returnValueForMissingStub: Future.value()) as _i4.Future); - @override - String toString() => super.toString(); -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/webview_platform_test.mocks.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/webview_platform_test.mocks.dart deleted file mode 100644 index 5ce007579473..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/webview_platform_test.mocks.dart +++ /dev/null @@ -1,78 +0,0 @@ -// Mocks generated by Mockito 5.0.16 from annotations -// in webview_flutter_platform_interface/test/src/v4/webview_platform_test.dart. -// Do not manually edit this file. - -import 'package:mockito/mockito.dart' as _i1; -import 'package:webview_flutter_platform_interface/v4/src/platform_navigation_delegate.dart' - as _i3; -import 'package:webview_flutter_platform_interface/v4/src/platform_webview_controller.dart' - as _i4; -import 'package:webview_flutter_platform_interface/v4/src/platform_webview_cookie_manager.dart' - as _i2; -import 'package:webview_flutter_platform_interface/v4/src/platform_webview_widget.dart' - as _i5; -import 'package:webview_flutter_platform_interface/v4/src/types/types.dart' - as _i7; -import 'package:webview_flutter_platform_interface/v4/src/webview_platform.dart' - as _i6; - -// ignore_for_file: avoid_redundant_argument_values -// ignore_for_file: avoid_setters_without_getters -// ignore_for_file: comment_references -// ignore_for_file: implementation_imports -// ignore_for_file: invalid_use_of_visible_for_testing_member -// ignore_for_file: prefer_const_constructors -// ignore_for_file: unnecessary_parenthesis -// ignore_for_file: camel_case_types - -class _FakePlatformWebViewCookieManager_0 extends _i1.Fake - implements _i2.PlatformWebViewCookieManager {} - -class _FakePlatformNavigationDelegate_1 extends _i1.Fake - implements _i3.PlatformNavigationDelegate {} - -class _FakePlatformWebViewController_2 extends _i1.Fake - implements _i4.PlatformWebViewController {} - -class _FakePlatformWebViewWidget_3 extends _i1.Fake - implements _i5.PlatformWebViewWidget {} - -/// A class which mocks [WebViewPlatform]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockWebViewPlatform extends _i1.Mock implements _i6.WebViewPlatform { - MockWebViewPlatform() { - _i1.throwOnMissingStub(this); - } - - @override - _i2.PlatformWebViewCookieManager createPlatformCookieManager( - _i7.PlatformWebViewCookieManagerCreationParams? params) => - (super.noSuchMethod( - Invocation.method(#createPlatformCookieManager, [params]), - returnValue: _FakePlatformWebViewCookieManager_0()) - as _i2.PlatformWebViewCookieManager); - @override - _i3.PlatformNavigationDelegate createPlatformNavigationDelegate( - _i7.PlatformNavigationDelegateCreationParams? params) => - (super.noSuchMethod( - Invocation.method(#createPlatformNavigationDelegate, [params]), - returnValue: _FakePlatformNavigationDelegate_1()) - as _i3.PlatformNavigationDelegate); - @override - _i4.PlatformWebViewController createPlatformWebViewController( - _i7.PlatformWebViewControllerCreationParams? params) => - (super.noSuchMethod( - Invocation.method(#createPlatformWebViewController, [params]), - returnValue: _FakePlatformWebViewController_2()) - as _i4.PlatformWebViewController); - @override - _i5.PlatformWebViewWidget createPlatformWebViewWidget( - _i7.PlatformWebViewWidgetCreationParams? params) => - (super.noSuchMethod( - Invocation.method(#createPlatformWebViewWidget, [params]), - returnValue: _FakePlatformWebViewWidget_3()) - as _i5.PlatformWebViewWidget); - @override - String toString() => super.toString(); -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/webview_platform_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/webview_platform_test.dart similarity index 95% rename from packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/webview_platform_test.dart rename to packages/webview_flutter/webview_flutter_platform_interface/test/webview_platform_test.dart index 4ab6d587b879..34f84065e951 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/src/v4/webview_platform_test.dart +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/webview_platform_test.dart @@ -6,8 +6,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; -import 'package:webview_flutter_platform_interface/v4/src/platform_webview_controller.dart'; -import 'package:webview_flutter_platform_interface/v4/src/webview_platform.dart'; +import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; import 'webview_platform_test.mocks.dart'; diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/webview_platform_test.mocks.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/webview_platform_test.mocks.dart new file mode 100644 index 000000000000..d613cddccd54 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/webview_platform_test.mocks.dart @@ -0,0 +1,146 @@ +// Mocks generated by Mockito 5.3.2 from annotations +// in webview_flutter_platform_interface/test/webview_platform_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:mockito/mockito.dart' as _i1; +import 'package:webview_flutter_platform_interface/src/platform_navigation_delegate.dart' + as _i3; +import 'package:webview_flutter_platform_interface/src/platform_webview_controller.dart' + as _i4; +import 'package:webview_flutter_platform_interface/src/platform_webview_cookie_manager.dart' + as _i2; +import 'package:webview_flutter_platform_interface/src/platform_webview_widget.dart' + as _i5; +import 'package:webview_flutter_platform_interface/src/types/types.dart' as _i7; +import 'package:webview_flutter_platform_interface/src/webview_platform.dart' + as _i6; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +class _FakePlatformWebViewCookieManager_0 extends _i1.SmartFake + implements _i2.PlatformWebViewCookieManager { + _FakePlatformWebViewCookieManager_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakePlatformNavigationDelegate_1 extends _i1.SmartFake + implements _i3.PlatformNavigationDelegate { + _FakePlatformNavigationDelegate_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakePlatformWebViewController_2 extends _i1.SmartFake + implements _i4.PlatformWebViewController { + _FakePlatformWebViewController_2( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakePlatformWebViewWidget_3 extends _i1.SmartFake + implements _i5.PlatformWebViewWidget { + _FakePlatformWebViewWidget_3( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [WebViewPlatform]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockWebViewPlatform extends _i1.Mock implements _i6.WebViewPlatform { + MockWebViewPlatform() { + _i1.throwOnMissingStub(this); + } + + @override + _i2.PlatformWebViewCookieManager createPlatformCookieManager( + _i7.PlatformWebViewCookieManagerCreationParams? params) => + (super.noSuchMethod( + Invocation.method( + #createPlatformCookieManager, + [params], + ), + returnValue: _FakePlatformWebViewCookieManager_0( + this, + Invocation.method( + #createPlatformCookieManager, + [params], + ), + ), + ) as _i2.PlatformWebViewCookieManager); + @override + _i3.PlatformNavigationDelegate createPlatformNavigationDelegate( + _i7.PlatformNavigationDelegateCreationParams? params) => + (super.noSuchMethod( + Invocation.method( + #createPlatformNavigationDelegate, + [params], + ), + returnValue: _FakePlatformNavigationDelegate_1( + this, + Invocation.method( + #createPlatformNavigationDelegate, + [params], + ), + ), + ) as _i3.PlatformNavigationDelegate); + @override + _i4.PlatformWebViewController createPlatformWebViewController( + _i7.PlatformWebViewControllerCreationParams? params) => + (super.noSuchMethod( + Invocation.method( + #createPlatformWebViewController, + [params], + ), + returnValue: _FakePlatformWebViewController_2( + this, + Invocation.method( + #createPlatformWebViewController, + [params], + ), + ), + ) as _i4.PlatformWebViewController); + @override + _i5.PlatformWebViewWidget createPlatformWebViewWidget( + _i7.PlatformWebViewWidgetCreationParams? params) => + (super.noSuchMethod( + Invocation.method( + #createPlatformWebViewWidget, + [params], + ), + returnValue: _FakePlatformWebViewWidget_3( + this, + Invocation.method( + #createPlatformWebViewWidget, + [params], + ), + ), + ) as _i5.PlatformWebViewWidget); +} From b2f27be5f28448a33905b385af9617ed681207f3 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 14 Dec 2022 18:18:08 -0500 Subject: [PATCH 2/5] update pubspec changelog and readme --- .../webview_flutter_platform_interface/CHANGELOG.md | 7 +++++++ .../webview_flutter_platform_interface/README.md | 4 ++-- .../webview_flutter_platform_interface/pubspec.yaml | 3 +-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/webview_flutter/webview_flutter_platform_interface/CHANGELOG.md b/packages/webview_flutter/webview_flutter_platform_interface/CHANGELOG.md index b7050e4f4db3..a4be504f3035 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/CHANGELOG.md +++ b/packages/webview_flutter/webview_flutter_platform_interface/CHANGELOG.md @@ -1,3 +1,10 @@ +## 2.0.0 + +* **Breaking Change**: Releases new interface. See [documentation](https://pub.dev/documentation/webview_flutter_platform_interface/2.0.0/) and [design doc](https://flutter.dev/go/webview_flutter_4_interface) + for more details. +* **Breaking Change**: Removes MethodChannel implementation of interface. All platform + implementations will now need to create their own by implementing `WebViewPlatform`. + ## 1.9.5 * Updates code for `no_leading_underscores_for_local_identifiers` lint. diff --git a/packages/webview_flutter/webview_flutter_platform_interface/README.md b/packages/webview_flutter/webview_flutter_platform_interface/README.md index 31e57ab61597..10160b3cd132 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/README.md +++ b/packages/webview_flutter/webview_flutter_platform_interface/README.md @@ -9,10 +9,10 @@ same interface. # Usage To implement a new platform-specific implementation of `webview_flutter`, extend -[`WebviewPlatform`](lib/src/platform_interface/webview_platform.dart) with an implementation that performs the +[`WebviewPlatform`](lib/src/webview_platform.dart) with an implementation that performs the platform-specific behavior, and when you register your plugin, set the default `WebviewPlatform` by calling -`WebviewPlatform.setInstance(MyPlatformWebview())`. +`WebviewPlatform.instance = MyPlatformWebview()`. # Note on breaking changes diff --git a/packages/webview_flutter/webview_flutter_platform_interface/pubspec.yaml b/packages/webview_flutter/webview_flutter_platform_interface/pubspec.yaml index e4b5381eed3c..3ba7a567398e 100644 --- a/packages/webview_flutter/webview_flutter_platform_interface/pubspec.yaml +++ b/packages/webview_flutter/webview_flutter_platform_interface/pubspec.yaml @@ -4,8 +4,7 @@ repository: https://github.com/flutter/plugins/tree/main/packages/webview_flutte issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview_flutter%22 # NOTE: We strongly prefer non-breaking changes, even at the expense of a # less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes -version: 1.9.5 -publish_to: none +version: 2.0.0 environment: sdk: ">=2.12.0 <3.0.0" From 14ea14defb8a01e235e27e75256a7b187fb601a9 Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Wed, 14 Dec 2022 18:20:03 -0500 Subject: [PATCH 3/5] exclude from all plugins app test --- script/configs/exclude_all_plugins_app.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/script/configs/exclude_all_plugins_app.yaml b/script/configs/exclude_all_plugins_app.yaml index 8dd0fde5ef5f..62b20d9596bd 100644 --- a/script/configs/exclude_all_plugins_app.yaml +++ b/script/configs/exclude_all_plugins_app.yaml @@ -8,3 +8,4 @@ # This is a permament entry, as it should never be a direct app dependency. - plugin_platform_interface +- webview_flutter_platform_interface From 61b217c209f3639a1544db939381d2bdccf32edd Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 15 Dec 2022 07:46:47 -0500 Subject: [PATCH 4/5] delete all of platform interface --- .../AUTHORS | 67 --- .../CHANGELOG.md | 94 ---- .../LICENSE | 25 - .../README.md | 23 - .../javascript_channel_registry.dart | 42 -- .../platform_interface.dart | 9 - .../webview_cookie_manager.dart | 51 -- .../platform_interface/webview_platform.dart | 67 --- .../webview_platform_callbacks_handler.dart | 32 -- .../webview_platform_controller.dart | 254 ---------- .../types/auto_media_playback_policy.dart | 22 - .../lib/src/legacy/types/creation_params.dart | 71 --- .../src/legacy/types/javascript_channel.dart | 39 -- .../src/legacy/types/javascript_message.dart | 14 - .../lib/src/legacy/types/javascript_mode.dart | 12 - .../lib/src/legacy/types/types.dart | 14 - .../src/legacy/types/web_resource_error.dart | 57 --- .../legacy/types/web_resource_error_type.dart | 66 --- .../lib/src/legacy/types/web_settings.dart | 132 ------ .../lib/src/legacy/types/webview_cookie.dart | 49 -- .../lib/src/legacy/types/webview_request.dart | 58 --- .../lib/src/platform_navigation_delegate.dart | 101 ---- .../lib/src/platform_webview_controller.dart | 272 ----------- .../src/platform_webview_cookie_manager.dart | 55 --- .../lib/src/platform_webview_widget.dart | 37 -- .../lib/src/types/javascript_message.dart | 51 -- .../lib/src/types/javascript_mode.dart | 12 - .../lib/src/types/load_request_params.dart | 93 ---- .../lib/src/types/navigation_decision.dart | 12 - .../lib/src/types/navigation_request.dart | 18 - ...m_navigation_delegate_creation_params.dart | 44 -- ...rm_webview_controller_creation_params.dart | 45 -- ...ebview_cookie_manager_creation_params.dart | 45 -- ...atform_webview_widget_creation_params.dart | 84 ---- .../lib/src/types/types.dart | 15 - .../lib/src/types/web_resource_error.dart | 123 ----- .../lib/src/types/webview_cookie.dart | 41 -- ...iew_flutter_platform_interface_legacy.dart | 6 - .../lib/src/webview_platform.dart | 82 ---- .../webview_flutter_platform_interface.dart | 10 - .../pubspec.yaml | 23 - .../javascript_channel_registry_test.dart | 117 ----- .../webview_cookie_manager_test.dart | 26 - .../legacy/types/javascript_channel_test.dart | 48 -- .../legacy/types/webview_cookie_test.dart | 21 - .../legacy/types/webview_request_test.dart | 39 -- .../platform_navigation_delegate_test.dart | 147 ------ .../platform_webview_controller_test.dart | 444 ------------------ ...latform_webview_controller_test.mocks.dart | 106 ----- .../test/platform_webview_widget_test.dart | 94 ---- .../test/webview_platform_test.dart | 115 ----- .../test/webview_platform_test.mocks.dart | 146 ------ 52 files changed, 3670 deletions(-) delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/AUTHORS delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/CHANGELOG.md delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/LICENSE delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/README.md delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/javascript_channel_registry.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/platform_interface.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_cookie_manager.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform_callbacks_handler.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform_controller.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/auto_media_playback_policy.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/creation_params.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_channel.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_message.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_mode.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/types.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_resource_error.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_resource_error_type.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_settings.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/webview_cookie.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/webview_request.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_navigation_delegate.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_controller.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_cookie_manager.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_widget.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_message.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_mode.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/load_request_params.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_decision.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_request.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_navigation_delegate_creation_params.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_controller_creation_params.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_cookie_manager_creation_params.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_widget_creation_params.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/types.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/web_resource_error.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/webview_cookie.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/webview_flutter_platform_interface_legacy.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/webview_platform.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/webview_flutter_platform_interface.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/pubspec.yaml delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/legacy/platform_interface/javascript_channel_registry_test.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/legacy/platform_interface/webview_cookie_manager_test.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/javascript_channel_test.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/webview_cookie_test.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/webview_request_test.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/platform_navigation_delegate_test.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.mocks.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_widget_test.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/webview_platform_test.dart delete mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/webview_platform_test.mocks.dart diff --git a/packages/webview_flutter/webview_flutter_platform_interface/AUTHORS b/packages/webview_flutter/webview_flutter_platform_interface/AUTHORS deleted file mode 100644 index 78f9e5ad9f6b..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/AUTHORS +++ /dev/null @@ -1,67 +0,0 @@ -# Below is a list of people and organizations that have contributed -# to the Flutter project. Names should be added to the list like so: -# -# Name/Organization - -Google Inc. -The Chromium Authors -German Saprykin -Benjamin Sauer -larsenthomasj@gmail.com -Ali Bitek -Pol Batlló -Anatoly Pulyaevskiy -Hayden Flinner -Stefano Rodriguez -Salvatore Giordano -Brian Armstrong -Paul DeMarco -Fabricio Nogueira -Simon Lightfoot -Ashton Thomas -Thomas Danner -Diego Velásquez -Hajime Nakamura -Tuyển Vũ Xuân -Miguel Ruivo -Sarthak Verma -Mike Diarmid -Invertase -Elliot Hesp -Vince Varga -Aawaz Gyawali -EUI Limited -Katarina Sheremet -Thomas Stockx -Sarbagya Dhaubanjar -Ozkan Eksi -Rishab Nayak -ko2ic -Jonathan Younger -Jose Sanchez -Debkanchan Samadder -Audrius Karosevicius -Lukasz Piliszczuk -SoundReply Solutions GmbH -Rafal Wachol -Pau Picas -Christian Weder -Alexandru Tuca -Christian Weder -Rhodes Davis Jr. -Luigi Agosti -Quentin Le Guennec -Koushik Ravikumar -Nissim Dsilva -Giancarlo Rocha -Ryo Miyake -Théo Champion -Kazuki Yamaguchi -Eitan Schwartz -Chris Rutkowski -Juan Alvarez -Aleksandr Yurkovskiy -Anton Borries -Alex Li -Rahul Raj <64.rahulraj@gmail.com> -Maurits van Beusekom diff --git a/packages/webview_flutter/webview_flutter_platform_interface/CHANGELOG.md b/packages/webview_flutter/webview_flutter_platform_interface/CHANGELOG.md deleted file mode 100644 index a4be504f3035..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/CHANGELOG.md +++ /dev/null @@ -1,94 +0,0 @@ -## 2.0.0 - -* **Breaking Change**: Releases new interface. See [documentation](https://pub.dev/documentation/webview_flutter_platform_interface/2.0.0/) and [design doc](https://flutter.dev/go/webview_flutter_4_interface) - for more details. -* **Breaking Change**: Removes MethodChannel implementation of interface. All platform - implementations will now need to create their own by implementing `WebViewPlatform`. - -## 1.9.5 - -* Updates code for `no_leading_underscores_for_local_identifiers` lint. - -## 1.9.4 - -* Updates imports for `prefer_relative_imports`. - -## 1.9.3 - -* Updates minimum Flutter version to 2.10. -* Removes `BuildParams` from v4 interface and adds `layoutDirection` to the creation params. - -## 1.9.2 - -* Fixes avoid_redundant_argument_values lint warnings and minor typos. -* Ignores unnecessary import warnings in preparation for [upcoming Flutter changes](https://github.com/flutter/flutter/pull/106316). -* Adds missing build params for v4 WebViewWidget interface. - -## 1.9.1 - -* Ignores unnecessary import warnings in preparation for [upcoming Flutter changes](https://github.com/flutter/flutter/pull/104231). - -## 1.9.0 - -* Adds the first iteration of the v4 webview_flutter interface implementation. -* Removes unnecessary imports. - -## 1.8.2 - -* Migrates from `ui.hash*` to `Object.hash*`. -* Updates minimum Flutter version to 2.5.0. - -## 1.8.1 - -* Update to use the `verify` method introduced in platform_plugin_interface 2.1.0. - -## 1.8.0 - -* Adds the `loadFlutterAsset` method to the platform interface. - -## 1.7.0 - -* Add an option to set the background color of the webview. - -## 1.6.1 - -* Revert deprecation of `clearCookies` in WebViewPlatform for later deprecation. - -## 1.6.0 - -* Adds platform interface for cookie manager. -* Deprecates `clearCookies` in WebViewPlatform in favour of `CookieManager#clearCookies`. -* Expanded `CreationParams` to include cookies to be set at webview creation. - -## 1.5.2 - -* Mirgrates from analysis_options_legacy.yaml to the more strict analysis_options.yaml. - -## 1.5.1 - -* Reverts the addition of `onUrlChanged`, which was unintentionally a breaking - change. - -## 1.5.0 - -* Added `onUrlChanged` callback to platform callback handler. - -## 1.4.0 - -* Added `loadFile` and `loadHtml` interface methods. - -## 1.3.0 - -* Added `loadRequest` method to platform interface. - -## 1.2.0 - -* Added `runJavascript` and `runJavascriptReturningResult` interface methods to supersede `evaluateJavascript`. - -## 1.1.0 - -* Add `zoomEnabled` functionality to `WebSettings`. - -## 1.0.0 - -* Extracted platform interface from `webview_flutter`. diff --git a/packages/webview_flutter/webview_flutter_platform_interface/LICENSE b/packages/webview_flutter/webview_flutter_platform_interface/LICENSE deleted file mode 100644 index c6823b81eb84..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/LICENSE +++ /dev/null @@ -1,25 +0,0 @@ -Copyright 2013 The Flutter Authors. All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, -are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - * Neither the name of Google Inc. nor the names of its - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR -ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES -(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON -ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/webview_flutter/webview_flutter_platform_interface/README.md b/packages/webview_flutter/webview_flutter_platform_interface/README.md deleted file mode 100644 index 10160b3cd132..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# webview_flutter_platform_interface - -A common platform interface for the [`webview_flutter`](https://pub.dev/packages/webview_flutter) plugin. - -This interface allows platform-specific implementations of the `webview_flutter` -plugin, as well as the plugin itself, to ensure they are supporting the -same interface. - -# Usage - -To implement a new platform-specific implementation of `webview_flutter`, extend -[`WebviewPlatform`](lib/src/webview_platform.dart) with an implementation that performs the -platform-specific behavior, and when you register your plugin, set the default -`WebviewPlatform` by calling -`WebviewPlatform.instance = MyPlatformWebview()`. - -# Note on breaking changes - -Strongly prefer non-breaking changes (such as adding a method to the interface) -over breaking changes for this package. - -See https://flutter.dev/go/platform-interface-breaking-changes for a discussion -on why a less-clean interface is preferable to a breaking change. diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/javascript_channel_registry.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/javascript_channel_registry.dart deleted file mode 100644 index 142d8eb00950..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/javascript_channel_registry.dart +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import '../types/javascript_channel.dart'; -import '../types/javascript_message.dart'; - -/// Utility class for managing named JavaScript channels and forwarding incoming -/// messages on the correct channel. -class JavascriptChannelRegistry { - /// Constructs a [JavascriptChannelRegistry] initializing it with the given - /// set of [JavascriptChannel]s. - JavascriptChannelRegistry(Set? channels) { - updateJavascriptChannelsFromSet(channels); - } - - /// Maps a channel name to a channel. - final Map channels = {}; - - /// Invoked when a JavaScript channel message is received. - void onJavascriptChannelMessage(String channel, String message) { - final JavascriptChannel? javascriptChannel = channels[channel]; - - if (javascriptChannel == null) { - throw ArgumentError('No channel registered with name $channel.'); - } - - javascriptChannel.onMessageReceived(JavascriptMessage(message)); - } - - /// Updates the set of [JavascriptChannel]s with the new set. - void updateJavascriptChannelsFromSet(Set? channels) { - this.channels.clear(); - if (channels == null) { - return; - } - - for (final JavascriptChannel channel in channels) { - this.channels[channel.name] = channel; - } - } -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/platform_interface.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/platform_interface.dart deleted file mode 100644 index a6967a5410f4..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/platform_interface.dart +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -export 'javascript_channel_registry.dart'; -export 'webview_cookie_manager.dart'; -export 'webview_platform.dart'; -export 'webview_platform_callbacks_handler.dart'; -export 'webview_platform_controller.dart'; diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_cookie_manager.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_cookie_manager.dart deleted file mode 100644 index 90dfc2a548b5..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_cookie_manager.dart +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:plugin_platform_interface/plugin_platform_interface.dart'; - -import '../types/webview_cookie.dart'; - -/// Interface for a platform implementation of a cookie manager. -/// -/// Platform implementations should extend this class rather than implement it as `webview_flutter` -/// does not consider newly added methods to be breaking changes. Extending this class -/// (using `extends`) ensures that the subclass will get the default implementation, while -/// platform implementations that `implements` this interface will be broken by newly added -/// [WebViewCookieManagerPlatform] methods. -abstract class WebViewCookieManagerPlatform extends PlatformInterface { - /// Constructs a WebViewCookieManagerPlatform. - WebViewCookieManagerPlatform() : super(token: _token); - - static final Object _token = Object(); - - static WebViewCookieManagerPlatform? _instance; - - /// The instance of [WebViewCookieManagerPlatform] to use. - static WebViewCookieManagerPlatform? get instance => _instance; - - /// Platform-specific plugins should set this with their own platform-specific - /// class that extends [WebViewCookieManagerPlatform] when they register themselves. - static set instance(WebViewCookieManagerPlatform? instance) { - if (instance == null) { - throw AssertionError( - 'Platform interfaces can only be set to a non-null instance'); - } - PlatformInterface.verify(instance, _token); - _instance = instance; - } - - /// Clears all cookies for all [WebView] instances. - /// - /// Returns true if cookies were present before clearing, else false. - Future clearCookies() { - throw UnimplementedError( - 'clearCookies is not implemented on the current platform'); - } - - /// Sets a cookie for all [WebView] instances. - Future setCookie(WebViewCookie cookie) { - throw UnimplementedError( - 'setCookie is not implemented on the current platform'); - } -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform.dart deleted file mode 100644 index 8d1df6ae1040..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform.dart +++ /dev/null @@ -1,67 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter/foundation.dart'; -import 'package:flutter/gestures.dart'; -import 'package:flutter/widgets.dart'; - -import '../platform_interface/javascript_channel_registry.dart'; -import '../types/types.dart'; -import 'webview_platform_callbacks_handler.dart'; -import 'webview_platform_controller.dart'; - -/// Signature for callbacks reporting that a [WebViewPlatformController] was created. -/// -/// See also the `onWebViewPlatformCreated` argument for [WebViewPlatform.build]. -typedef WebViewPlatformCreatedCallback = void Function( - WebViewPlatformController? webViewPlatformController); - -/// Interface for a platform implementation of a WebView. -/// -/// [WebView.platform] controls the builder that is used by [WebView]. -/// [AndroidWebViewPlatform] and [CupertinoWebViewPlatform] are the default implementations -/// for Android and iOS respectively. -abstract class WebViewPlatform { - /// Builds a new WebView. - /// - /// Returns a Widget tree that embeds the created webview. - /// - /// `creationParams` are the initial parameters used to setup the webview. - /// - /// `webViewPlatformHandler` will be used for handling callbacks that are made by the created - /// [WebViewPlatformController]. - /// - /// `onWebViewPlatformCreated` will be invoked after the platform specific [WebViewPlatformController] - /// implementation is created with the [WebViewPlatformController] instance as a parameter. - /// - /// `gestureRecognizers` specifies which gestures should be consumed by the web view. - /// It is possible for other gesture recognizers to be competing with the web view on pointer - /// events, e.g if the web view is inside a [ListView] the [ListView] will want to handle - /// vertical drags. The web view will claim gestures that are recognized by any of the - /// recognizers on this list. - /// When `gestureRecognizers` is empty or null, the web view will only handle pointer events for gestures that - /// were not claimed by any other gesture recognizer. - /// - /// `webViewPlatformHandler` must not be null. - Widget build({ - required BuildContext context, - // TODO(amirh): convert this to be the actual parameters. - // I'm starting without it as the PR is starting to become pretty big. - // I'll followup with the conversion PR. - required CreationParams creationParams, - required WebViewPlatformCallbacksHandler webViewPlatformCallbacksHandler, - required JavascriptChannelRegistry javascriptChannelRegistry, - WebViewPlatformCreatedCallback? onWebViewPlatformCreated, - Set>? gestureRecognizers, - }); - - /// Clears all cookies for all [WebView] instances. - /// - /// Returns true if cookies were present before clearing, else false. - /// Soon to be deprecated. 'Use `WebViewCookieManagerPlatform.clearCookies` instead. - Future clearCookies() { - throw UnimplementedError( - 'WebView clearCookies is not implemented on the current platform'); - } -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform_callbacks_handler.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform_callbacks_handler.dart deleted file mode 100644 index 44dae2ece434..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform_callbacks_handler.dart +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:async'; - -import '../types/types.dart'; - -/// Interface for callbacks made by [WebViewPlatformController]. -/// -/// The webview plugin implements this class, and passes an instance to the [WebViewPlatformController]. -/// [WebViewPlatformController] is notifying this handler on events that happened on the platform's webview. -abstract class WebViewPlatformCallbacksHandler { - /// Invoked by [WebViewPlatformController] when a navigation request is pending. - /// - /// If true is returned the navigation is allowed, otherwise it is blocked. - FutureOr onNavigationRequest( - {required String url, required bool isForMainFrame}); - - /// Invoked by [WebViewPlatformController] when a page has started loading. - void onPageStarted(String url); - - /// Invoked by [WebViewPlatformController] when a page has finished loading. - void onPageFinished(String url); - - /// Invoked by [WebViewPlatformController] when a page is loading. - /// /// Only works when [WebSettings.hasProgressTracking] is set to `true`. - void onProgress(int progress); - - /// Report web resource loading error to the host application. - void onWebResourceError(WebResourceError error); -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform_controller.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform_controller.dart deleted file mode 100644 index 3437fe1f2c09..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform_controller.dart +++ /dev/null @@ -1,254 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import '../types/types.dart'; -import 'webview_platform_callbacks_handler.dart'; - -/// Interface for talking to the webview's platform implementation. -/// -/// An instance implementing this interface is passed to the `onWebViewPlatformCreated` callback that is -/// passed to [WebViewPlatformBuilder#onWebViewPlatformCreated]. -/// -/// Platform implementations that live in a separate package should extend this class rather than -/// implement it as webview_flutter does not consider newly added methods to be breaking changes. -/// Extending this class (using `extends`) ensures that the subclass will get the default -/// implementation, while platform implementations that `implements` this interface will be broken -/// by newly added [WebViewPlatformController] methods. -abstract class WebViewPlatformController { - /// Creates a new WebViewPlatform. - /// - /// Callbacks made by the WebView will be delegated to `handler`. - /// - /// The `handler` parameter must not be null. - // TODO(mvanbeusekom): Remove unused constructor parameter with the next - // breaking change (see issue https://github.com/flutter/flutter/issues/94292). - // ignore: avoid_unused_constructor_parameters - WebViewPlatformController(WebViewPlatformCallbacksHandler handler); - - /// Loads the file located on the specified [absoluteFilePath]. - /// - /// The [absoluteFilePath] parameter should contain the absolute path to the - /// file as it is stored on the device. For example: - /// `/Users/username/Documents/www/index.html`. - /// - /// Throws an ArgumentError if the [absoluteFilePath] does not exist. - Future loadFile( - String absoluteFilePath, - ) { - throw UnimplementedError( - 'WebView loadFile is not implemented on the current platform'); - } - - /// Loads the Flutter asset specified in the pubspec.yaml file. - /// - /// Throws an ArgumentError if [key] is not part of the specified assets - /// in the pubspec.yaml file. - Future loadFlutterAsset( - String key, - ) { - throw UnimplementedError( - 'WebView loadFlutterAsset is not implemented on the current platform'); - } - - /// Loads the supplied HTML string. - /// - /// The [baseUrl] parameter is used when resolving relative URLs within the - /// HTML string. - Future loadHtmlString( - String html, { - String? baseUrl, - }) { - throw UnimplementedError( - 'WebView loadHtmlString is not implemented on the current platform'); - } - - /// Loads the specified URL. - /// - /// If `headers` is not null and the URL is an HTTP URL, the key value paris in `headers` will - /// be added as key value pairs of HTTP headers for the request. - /// - /// `url` must not be null. - /// - /// Throws an ArgumentError if `url` is not a valid URL string. - Future loadUrl( - String url, - Map? headers, - ) { - throw UnimplementedError( - 'WebView loadUrl is not implemented on the current platform'); - } - - /// Makes a specific HTTP request ands loads the response in the webview. - /// - /// [WebViewRequest.method] must be one of the supported HTTP methods - /// in [WebViewRequestMethod]. - /// - /// If [WebViewRequest.headers] is not empty, its key-value pairs will be - /// added as the headers for the request. - /// - /// If [WebViewRequest.body] is not null, it will be added as the body - /// for the request. - /// - /// Throws an ArgumentError if [WebViewRequest.uri] has empty scheme. - Future loadRequest( - WebViewRequest request, - ) { - throw UnimplementedError( - 'WebView loadRequest is not implemented on the current platform'); - } - - /// Updates the webview settings. - /// - /// Any non null field in `settings` will be set as the new setting value. - /// All null fields in `settings` are ignored. - Future updateSettings(WebSettings setting) { - throw UnimplementedError( - 'WebView updateSettings is not implemented on the current platform'); - } - - /// Accessor to the current URL that the WebView is displaying. - /// - /// If no URL was ever loaded, returns `null`. - Future currentUrl() { - throw UnimplementedError( - 'WebView currentUrl is not implemented on the current platform'); - } - - /// Checks whether there's a back history item. - Future canGoBack() { - throw UnimplementedError( - 'WebView canGoBack is not implemented on the current platform'); - } - - /// Checks whether there's a forward history item. - Future canGoForward() { - throw UnimplementedError( - 'WebView canGoForward is not implemented on the current platform'); - } - - /// Goes back in the history of this WebView. - /// - /// If there is no back history item this is a no-op. - Future goBack() { - throw UnimplementedError( - 'WebView goBack is not implemented on the current platform'); - } - - /// Goes forward in the history of this WebView. - /// - /// If there is no forward history item this is a no-op. - Future goForward() { - throw UnimplementedError( - 'WebView goForward is not implemented on the current platform'); - } - - /// Reloads the current URL. - Future reload() { - throw UnimplementedError( - 'WebView reload is not implemented on the current platform'); - } - - /// Clears all caches used by the [WebView]. - /// - /// The following caches are cleared: - /// 1. Browser HTTP Cache. - /// 2. [Cache API](https://developers.google.com/web/fundamentals/instant-and-offline/web-storage/cache-api) caches. - /// These are not yet supported in iOS WkWebView. Service workers tend to use this cache. - /// 3. Application cache. - /// 4. Local Storage. - Future clearCache() { - throw UnimplementedError( - 'WebView clearCache is not implemented on the current platform'); - } - - /// Evaluates a JavaScript expression in the context of the current page. - /// - /// The Future completes with an error if a JavaScript error occurred, or if the type of the - /// evaluated expression is not supported (e.g on iOS not all non-primitive types can be evaluated). - Future evaluateJavascript(String javascript) { - throw UnimplementedError( - 'WebView evaluateJavascript is not implemented on the current platform'); - } - - /// Runs the given JavaScript in the context of the current page. - /// - /// The Future completes with an error if a JavaScript error occurred. - Future runJavascript(String javascript) { - throw UnimplementedError( - 'WebView runJavascript is not implemented on the current platform'); - } - - /// Runs the given JavaScript in the context of the current page, and returns the result. - /// - /// The Future completes with an error if a JavaScript error occurred, or if the - /// type the given expression evaluates to is unsupported. Unsupported values include - /// certain non-primitive types on iOS, as well as `undefined` or `null` on iOS 14+. - Future runJavascriptReturningResult(String javascript) { - throw UnimplementedError( - 'WebView runJavascriptReturningResult is not implemented on the current platform'); - } - - /// Adds new JavaScript channels to the set of enabled channels. - /// - /// For each value in this list the platform's webview should make sure that a corresponding - /// property with a postMessage method is set on `window`. For example for a JavaScript channel - /// named `Foo` it should be possible for JavaScript code executing in the webview to do - /// - /// ```javascript - /// Foo.postMessage('hello'); - /// ``` - /// - /// See also: [CreationParams.javascriptChannelNames]. - Future addJavascriptChannels(Set javascriptChannelNames) { - throw UnimplementedError( - 'WebView addJavascriptChannels is not implemented on the current platform'); - } - - /// Removes JavaScript channel names from the set of enabled channels. - /// - /// This disables channels that were previously enabled by [addJavascriptChannels] or through - /// [CreationParams.javascriptChannelNames]. - Future removeJavascriptChannels(Set javascriptChannelNames) { - throw UnimplementedError( - 'WebView removeJavascriptChannels is not implemented on the current platform'); - } - - /// Returns the title of the currently loaded page. - Future getTitle() { - throw UnimplementedError( - 'WebView getTitle is not implemented on the current platform'); - } - - /// Set the scrolled position of this view. - /// - /// The parameters `x` and `y` specify the position to scroll to in WebView pixels. - Future scrollTo(int x, int y) { - throw UnimplementedError( - 'WebView scrollTo is not implemented on the current platform'); - } - - /// Move the scrolled position of this view. - /// - /// The parameters `x` and `y` specify the amount of WebView pixels to scroll by. - Future scrollBy(int x, int y) { - throw UnimplementedError( - 'WebView scrollBy is not implemented on the current platform'); - } - - /// Return the horizontal scroll position of this view. - /// - /// Scroll position is measured from left. - Future getScrollX() { - throw UnimplementedError( - 'WebView getScrollX is not implemented on the current platform'); - } - - /// Return the vertical scroll position of this view. - /// - /// Scroll position is measured from top. - Future getScrollY() { - throw UnimplementedError( - 'WebView getScrollY is not implemented on the current platform'); - } -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/auto_media_playback_policy.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/auto_media_playback_policy.dart deleted file mode 100644 index 7d6927ac7957..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/auto_media_playback_policy.dart +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -/// Specifies possible restrictions on automatic media playback. -/// -/// This is typically used in [WebView.initialMediaPlaybackPolicy]. -// The method channel implementation is marshalling this enum to the value's index, so the order -// is important. -enum AutoMediaPlaybackPolicy { - /// Starting any kind of media playback requires a user action. - /// - /// For example: JavaScript code cannot start playing media unless the code was executed - /// as a result of a user action (like a touch event). - require_user_action_for_all_media_types, - - /// Starting any kind of media playback is always allowed. - /// - /// For example: JavaScript code that's triggered when the page is loaded can start playing - /// video or audio. - always_allow, -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/creation_params.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/creation_params.dart deleted file mode 100644 index 7c3edf3cf8b0..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/creation_params.dart +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter/widgets.dart'; - -import 'types.dart'; - -/// Configuration to use when creating a new [WebViewPlatformController]. -/// -/// The `autoMediaPlaybackPolicy` parameter must not be null. -class CreationParams { - /// Constructs an instance to use when creating a new - /// [WebViewPlatformController]. - /// - /// The `autoMediaPlaybackPolicy` parameter must not be null. - CreationParams({ - this.initialUrl, - this.webSettings, - this.javascriptChannelNames = const {}, - this.userAgent, - this.autoMediaPlaybackPolicy = - AutoMediaPlaybackPolicy.require_user_action_for_all_media_types, - this.backgroundColor, - this.cookies = const [], - }) : assert(autoMediaPlaybackPolicy != null); - - /// The initialUrl to load in the webview. - /// - /// When null the webview will be created without loading any page. - final String? initialUrl; - - /// The initial [WebSettings] for the new webview. - /// - /// This can later be updated with [WebViewPlatformController.updateSettings]. - final WebSettings? webSettings; - - /// The initial set of JavaScript channels that are configured for this webview. - /// - /// For each value in this set the platform's webview should make sure that a corresponding - /// property with a postMessage method is set on `window`. For example for a JavaScript channel - /// named `Foo` it should be possible for JavaScript code executing in the webview to do - /// - /// ```javascript - /// Foo.postMessage('hello'); - /// ``` - // TODO(amirh): describe what should happen when postMessage is called once that code is migrated - // to PlatformWebView. - final Set javascriptChannelNames; - - /// The value used for the HTTP User-Agent: request header. - /// - /// When null the platform's webview default is used for the User-Agent header. - final String? userAgent; - - /// Which restrictions apply on automatic media playback. - final AutoMediaPlaybackPolicy autoMediaPlaybackPolicy; - - /// The background color of the webview. - /// - /// When null the platform's webview default background color is used. - final Color? backgroundColor; - - /// The initial set of cookies to set before the webview does its first load. - final List cookies; - - @override - String toString() { - return 'CreationParams(initialUrl: $initialUrl, settings: $webSettings, javascriptChannelNames: $javascriptChannelNames, UserAgent: $userAgent, backgroundColor: $backgroundColor, cookies: $cookies)'; - } -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_channel.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_channel.dart deleted file mode 100644 index e68cc2ef1291..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_channel.dart +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'javascript_message.dart'; - -/// Callback type for handling messages sent from JavaScript running in a web view. -typedef JavascriptMessageHandler = void Function(JavascriptMessage message); - -final RegExp _validChannelNames = RegExp(r'^[a-zA-Z_][a-zA-Z0-9_]*$'); - -/// A named channel for receiving messaged from JavaScript code running inside a web view. -class JavascriptChannel { - /// Constructs a JavaScript channel. - /// - /// The parameters `name` and `onMessageReceived` must not be null. - JavascriptChannel({ - required this.name, - required this.onMessageReceived, - }) : assert(name != null), - assert(onMessageReceived != null), - assert(_validChannelNames.hasMatch(name)); - - /// The channel's name. - /// - /// Passing this channel object as part of a [WebView.javascriptChannels] adds a channel object to - /// the JavaScript window object's property named `name`. - /// - /// The name must start with a letter or underscore(_), followed by any combination of those - /// characters plus digits. - /// - /// Note that any JavaScript existing `window` property with this name will be overriden. - /// - /// See also [WebView.javascriptChannels] for more details on the channel registration mechanism. - final String name; - - /// A callback that's invoked when a message is received through the channel. - final JavascriptMessageHandler onMessageReceived; -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_message.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_message.dart deleted file mode 100644 index 8d080452c54a..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_message.dart +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -/// A message that was sent by JavaScript code running in a [WebView]. -class JavascriptMessage { - /// Constructs a JavaScript message object. - /// - /// The `message` parameter must not be null. - const JavascriptMessage(this.message) : assert(message != null); - - /// The contents of the message that was sent by the JavaScript code. - final String message; -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_mode.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_mode.dart deleted file mode 100644 index 53d049175907..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_mode.dart +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -/// Describes the state of JavaScript support in a given web view. -enum JavascriptMode { - /// JavaScript execution is disabled. - disabled, - - /// JavaScript execution is not restricted. - unrestricted, -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/types.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/types.dart deleted file mode 100644 index f2bcf19f42fd..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/types.dart +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -export 'auto_media_playback_policy.dart'; -export 'creation_params.dart'; -export 'javascript_channel.dart'; -export 'javascript_message.dart'; -export 'javascript_mode.dart'; -export 'web_resource_error.dart'; -export 'web_resource_error_type.dart'; -export 'web_settings.dart'; -export 'webview_cookie.dart'; -export 'webview_request.dart'; diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_resource_error.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_resource_error.dart deleted file mode 100644 index b61671f0ac45..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_resource_error.dart +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'web_resource_error_type.dart'; - -/// Error returned in `WebView.onWebResourceError` when a web resource loading error has occurred. -class WebResourceError { - /// Creates a new [WebResourceError] - /// - /// A user should not need to instantiate this class, but will receive one in - /// [WebResourceErrorCallback]. - WebResourceError({ - required this.errorCode, - required this.description, - this.domain, - this.errorType, - this.failingUrl, - }) : assert(errorCode != null), - assert(description != null); - - /// Raw code of the error from the respective platform. - /// - /// On Android, the error code will be a constant from a - /// [WebViewClient](https://developer.android.com/reference/android/webkit/WebViewClient#summary) and - /// will have a corresponding [errorType]. - /// - /// On iOS, the error code will be a constant from `NSError.code` in - /// Objective-C. See - /// https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/ErrorObjectsDomains/ErrorObjectsDomains.html - /// for more information on error handling on iOS. Some possible error codes - /// can be found at https://developer.apple.com/documentation/webkit/wkerrorcode?language=objc. - final int errorCode; - - /// The domain of where to find the error code. - /// - /// This field is only available on iOS and represents a "domain" from where - /// the [errorCode] is from. This value is taken directly from an `NSError` - /// in Objective-C. See - /// https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/ErrorObjectsDomains/ErrorObjectsDomains.html - /// for more information on error handling on iOS. - final String? domain; - - /// Description of the error that can be used to communicate the problem to the user. - final String description; - - /// The type this error can be categorized as. - /// - /// This will never be `null` on Android, but can be `null` on iOS. - final WebResourceErrorType? errorType; - - /// Gets the URL for which the resource request was made. - /// - /// This value is not provided on iOS. Alternatively, you can keep track of - /// the last values provided to [WebViewPlatformController.loadUrl]. - final String? failingUrl; -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_resource_error_type.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_resource_error_type.dart deleted file mode 100644 index a45816df8323..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_resource_error_type.dart +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -/// Possible error type categorizations used by [WebResourceError]. -enum WebResourceErrorType { - /// User authentication failed on server. - authentication, - - /// Malformed URL. - badUrl, - - /// Failed to connect to the server. - connect, - - /// Failed to perform SSL handshake. - failedSslHandshake, - - /// Generic file error. - file, - - /// File not found. - fileNotFound, - - /// Server or proxy hostname lookup failed. - hostLookup, - - /// Failed to read or write to the server. - io, - - /// User authentication failed on proxy. - proxyAuthentication, - - /// Too many redirects. - redirectLoop, - - /// Connection timed out. - timeout, - - /// Too many requests during this load. - tooManyRequests, - - /// Generic error. - unknown, - - /// Resource load was canceled by Safe Browsing. - unsafeResource, - - /// Unsupported authentication scheme (not basic or digest). - unsupportedAuthScheme, - - /// Unsupported URI scheme. - unsupportedScheme, - - /// The web content process was terminated. - webContentProcessTerminated, - - /// The web view was invalidated. - webViewInvalidated, - - /// A JavaScript exception occurred. - javaScriptExceptionOccurred, - - /// The result of JavaScript execution could not be returned. - javaScriptResultTypeIsUnsupported, -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_settings.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_settings.dart deleted file mode 100644 index 102ab10ccea7..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_settings.dart +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter/widgets.dart'; - -import 'javascript_mode.dart'; - -/// A single setting for configuring a WebViewPlatform which may be absent. -@immutable -class WebSetting { - /// Constructs an absent setting instance. - /// - /// The [isPresent] field for the instance will be false. - /// - /// Accessing [value] for an absent instance will throw. - const WebSetting.absent() - : _value = null, - isPresent = false; - - /// Constructs a setting of the given `value`. - /// - /// The [isPresent] field for the instance will be true. - const WebSetting.of(T value) - : _value = value, - isPresent = true; - - final T? _value; - - /// The setting's value. - /// - /// Throws if [WebSetting.isPresent] is false. - T get value { - if (!isPresent) { - throw StateError('Cannot access a value of an absent WebSetting'); - } - assert(isPresent); - // The intention of this getter is to return T whether it is nullable or - // not whereas _value is of type T? since _value can be null even when - // T is not nullable (when isPresent == false). - // - // We promote _value to T using `as T` instead of `!` operator to handle - // the case when _value is legitimately null (and T is a nullable type). - // `!` operator would always throw if _value is null. - return _value as T; - } - - /// True when this web setting instance contains a value. - /// - /// When false the [WebSetting.value] getter throws. - final bool isPresent; - - @override - bool operator ==(Object other) { - if (other.runtimeType != runtimeType) { - return false; - } - - return other is WebSetting && - other.isPresent == isPresent && - other._value == _value; - } - - @override - int get hashCode => Object.hash(_value, isPresent); -} - -/// Settings for configuring a WebViewPlatform. -/// -/// Initial settings are passed as part of [CreationParams], settings updates are sent with -/// [WebViewPlatform#updateSettings]. -/// -/// The `userAgent` parameter must not be null. -class WebSettings { - /// Construct an instance with initial settings. Future setting changes can be - /// sent with [WebviewPlatform#updateSettings]. - /// - /// The `userAgent` parameter must not be null. - WebSettings({ - this.javascriptMode, - this.hasNavigationDelegate, - this.hasProgressTracking, - this.debuggingEnabled, - this.gestureNavigationEnabled, - this.allowsInlineMediaPlayback, - this.zoomEnabled, - required this.userAgent, - }) : assert(userAgent != null); - - /// The JavaScript execution mode to be used by the webview. - final JavascriptMode? javascriptMode; - - /// Whether the [WebView] has a [NavigationDelegate] set. - final bool? hasNavigationDelegate; - - /// Whether the [WebView] should track page loading progress. - /// See also: [WebViewPlatformCallbacksHandler.onProgress] to get the progress. - final bool? hasProgressTracking; - - /// Whether to enable the platform's webview content debugging tools. - /// - /// See also: [WebView.debuggingEnabled]. - final bool? debuggingEnabled; - - /// Whether to play HTML5 videos inline or use the native full-screen controller on iOS. - /// - /// This will have no effect on Android. - final bool? allowsInlineMediaPlayback; - - /// The value used for the HTTP `User-Agent:` request header. - /// - /// If [userAgent.value] is null the platform's default user agent should be used. - /// - /// An absent value ([userAgent.isPresent] is false) represents no change to this setting from the - /// last time it was set. - /// - /// See also [WebView.userAgent]. - final WebSetting userAgent; - - /// Sets whether the WebView should support zooming using its on-screen zoom controls and gestures. - final bool? zoomEnabled; - - /// Whether to allow swipe based navigation in iOS. - /// - /// See also: [WebView.gestureNavigationEnabled] - final bool? gestureNavigationEnabled; - - @override - String toString() { - return 'WebSettings(javascriptMode: $javascriptMode, hasNavigationDelegate: $hasNavigationDelegate, hasProgressTracking: $hasProgressTracking, debuggingEnabled: $debuggingEnabled, gestureNavigationEnabled: $gestureNavigationEnabled, userAgent: $userAgent, allowsInlineMediaPlayback: $allowsInlineMediaPlayback)'; - } -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/webview_cookie.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/webview_cookie.dart deleted file mode 100644 index 406c510afd4b..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/webview_cookie.dart +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -/// A cookie that can be set globally for all web views -/// using [WebViewCookieManagerPlatform]. -class WebViewCookie { - /// Constructs a new [WebViewCookie]. - const WebViewCookie( - {required this.name, - required this.value, - required this.domain, - this.path = '/'}); - - /// The cookie-name of the cookie. - /// - /// Its value should match "cookie-name" in RFC6265bis: - /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 - final String name; - - /// The cookie-value of the cookie. - /// - /// Its value should match "cookie-value" in RFC6265bis: - /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 - final String value; - - /// The domain-value of the cookie. - /// - /// Its value should match "domain-value" in RFC6265bis: - /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 - final String domain; - - /// The path-value of the cookie. - /// Is set to `/` in the constructor by default. - /// - /// Its value should match "path-value" in RFC6265bis: - /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 - final String path; - - /// Serializes the [WebViewCookie] to a Map. - Map toJson() { - return { - 'name': name, - 'value': value, - 'domain': domain, - 'path': path - }; - } -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/webview_request.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/webview_request.dart deleted file mode 100644 index 940e3a25f4ba..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/webview_request.dart +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:typed_data'; - -/// Defines the supported HTTP methods for loading a page in [WebView]. -enum WebViewRequestMethod { - /// HTTP GET method. - get, - - /// HTTP POST method. - post, -} - -/// Extension methods on the [WebViewRequestMethod] enum. -extension WebViewRequestMethodExtensions on WebViewRequestMethod { - /// Converts [WebViewRequestMethod] to [String] format. - String serialize() { - switch (this) { - case WebViewRequestMethod.get: - return 'get'; - case WebViewRequestMethod.post: - return 'post'; - } - } -} - -/// Defines the parameters that can be used to load a page in the [WebView]. -class WebViewRequest { - /// Creates the [WebViewRequest]. - WebViewRequest({ - required this.uri, - required this.method, - this.headers = const {}, - this.body, - }); - - /// URI for the request. - final Uri uri; - - /// HTTP method used to make the request. - final WebViewRequestMethod method; - - /// Headers for the request. - final Map headers; - - /// HTTP body for the request. - final Uint8List? body; - - /// Serializes the [WebViewRequest] to JSON. - Map toJson() => { - 'uri': uri.toString(), - 'method': method.serialize(), - 'headers': headers, - 'body': body, - }; -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_navigation_delegate.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_navigation_delegate.dart deleted file mode 100644 index 2df6cff73ab5..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_navigation_delegate.dart +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:async'; - -import 'package:flutter/foundation.dart'; -import 'package:plugin_platform_interface/plugin_platform_interface.dart'; - -import 'webview_platform.dart'; - -/// Signature for callbacks that report a pending navigation request. -typedef NavigationRequestCallback = FutureOr Function( - NavigationRequest navigationRequest); - -/// Signature for callbacks that report page events triggered by the native web view. -typedef PageEventCallback = void Function(String url); - -/// Signature for callbacks that report loading progress of a page. -typedef ProgressCallback = void Function(int progress); - -/// Signature for callbacks that report a resource loading error. -typedef WebResourceErrorCallback = void Function(WebResourceError error); - -/// An interface defining navigation events that occur on the native platform. -/// -/// The [PlatformWebViewController] is notifying this delegate on events that -/// happened on the platform's webview. Platform implementations should -/// implement this class and pass an instance to the [PlatformWebViewController]. -abstract class PlatformNavigationDelegate extends PlatformInterface { - /// Creates a new [PlatformNavigationDelegate] - factory PlatformNavigationDelegate( - PlatformNavigationDelegateCreationParams params) { - final PlatformNavigationDelegate callbackDelegate = - WebViewPlatform.instance!.createPlatformNavigationDelegate(params); - PlatformInterface.verify(callbackDelegate, _token); - return callbackDelegate; - } - - /// Used by the platform implementation to create a new [PlatformNavigationDelegate]. - /// - /// Should only be used by platform implementations because they can't extend - /// a class that only contains a factory constructor. - @protected - PlatformNavigationDelegate.implementation(this.params) : super(token: _token); - - static final Object _token = Object(); - - /// The parameters used to initialize the [PlatformNavigationDelegate]. - final PlatformNavigationDelegateCreationParams params; - - /// Invoked when a navigation request is pending. - /// - /// See [PlatformWebViewController.setPlatformNavigationDelegate]. - Future setOnNavigationRequest( - NavigationRequestCallback onNavigationRequest, - ) { - throw UnimplementedError( - 'setOnNavigationRequest is not implemented on the current platform.'); - } - - /// Invoked when a page has started loading. - /// - /// See [PlatformWebViewController.setPlatformNavigationDelegate]. - Future setOnPageStarted( - PageEventCallback onPageStarted, - ) { - throw UnimplementedError( - 'setOnPageStarted is not implemented on the current platform.'); - } - - /// Invoked when a page has finished loading. - /// - /// See [PlatformWebViewController.setPlatformNavigationDelegate]. - Future setOnPageFinished( - PageEventCallback onPageFinished, - ) { - throw UnimplementedError( - 'setOnPageFinished is not implemented on the current platform.'); - } - - /// Invoked when a page is loading to report the progress. - /// - /// See [PlatformWebViewController.setPlatformNavigationDelegate]. - Future setOnProgress( - ProgressCallback onProgress, - ) { - throw UnimplementedError( - 'setOnProgress is not implemented on the current platform.'); - } - - /// Invoked when a resource loading error occurred. - /// - /// See [PlatformWebViewController.setPlatformNavigationDelegate]. - Future setOnWebResourceError( - WebResourceErrorCallback onWebResourceError, - ) { - throw UnimplementedError( - 'setOnWebResourceError is not implemented on the current platform.'); - } -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_controller.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_controller.dart deleted file mode 100644 index 7bb259c274b1..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_controller.dart +++ /dev/null @@ -1,272 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter/foundation.dart'; -import 'package:flutter/painting.dart'; -import 'package:plugin_platform_interface/plugin_platform_interface.dart'; - -import '../../src/platform_navigation_delegate.dart'; -import 'webview_platform.dart'; - -/// Interface for a platform implementation of a web view controller. -/// -/// Platform implementations should extend this class rather than implement it -/// as `webview_flutter` does not consider newly added methods to be breaking -/// changes. Extending this class (using `extends`) ensures that the subclass -/// will get the default implementation, while platform implementations that -/// `implements` this interface will be broken by newly added -/// [PlatformWebViewCookieManager] methods. -abstract class PlatformWebViewController extends PlatformInterface { - /// Creates a new [PlatformWebViewController] - factory PlatformWebViewController( - PlatformWebViewControllerCreationParams params) { - final PlatformWebViewController webViewControllerDelegate = - WebViewPlatform.instance!.createPlatformWebViewController(params); - PlatformInterface.verify(webViewControllerDelegate, _token); - return webViewControllerDelegate; - } - - /// Used by the platform implementation to create a new [PlatformWebViewController]. - /// - /// Should only be used by platform implementations because they can't extend - /// a class that only contains a factory constructor. - @protected - PlatformWebViewController.implementation(this.params) : super(token: _token); - - static final Object _token = Object(); - - /// The parameters used to initialize the [PlatformWebViewController]. - final PlatformWebViewControllerCreationParams params; - - /// Loads the file located on the specified [absoluteFilePath]. - /// - /// The [absoluteFilePath] parameter should contain the absolute path to the - /// file as it is stored on the device. For example: - /// `/Users/username/Documents/www/index.html`. - /// - /// Throws an ArgumentError if the [absoluteFilePath] does not exist. - Future loadFile( - String absoluteFilePath, - ) { - throw UnimplementedError( - 'loadFile is not implemented on the current platform'); - } - - /// Loads the Flutter asset specified in the pubspec.yaml file. - /// - /// Throws an ArgumentError if [key] is not part of the specified assets - /// in the pubspec.yaml file. - Future loadFlutterAsset( - String key, - ) { - throw UnimplementedError( - 'loadFlutterAsset is not implemented on the current platform'); - } - - /// Loads the supplied HTML string. - /// - /// The [baseUrl] parameter is used when resolving relative URLs within the - /// HTML string. - Future loadHtmlString( - String html, { - String? baseUrl, - }) { - throw UnimplementedError( - 'loadHtmlString is not implemented on the current platform'); - } - - /// Makes a specific HTTP request ands loads the response in the webview. - /// - /// [WebViewRequest.method] must be one of the supported HTTP methods - /// in [WebViewRequestMethod]. - /// - /// If [WebViewRequest.headers] is not empty, its key-value pairs will be - /// added as the headers for the request. - /// - /// If [WebViewRequest.body] is not null, it will be added as the body - /// for the request. - /// - /// Throws an ArgumentError if [WebViewRequest.uri] has empty scheme. - Future loadRequest( - LoadRequestParams params, - ) { - throw UnimplementedError( - 'loadRequest is not implemented on the current platform'); - } - - /// Accessor to the current URL that the WebView is displaying. - /// - /// If no URL was ever loaded, returns `null`. - Future currentUrl() { - throw UnimplementedError( - 'currentUrl is not implemented on the current platform'); - } - - /// Checks whether there's a back history item. - Future canGoBack() { - throw UnimplementedError( - 'canGoBack is not implemented on the current platform'); - } - - /// Checks whether there's a forward history item. - Future canGoForward() { - throw UnimplementedError( - 'canGoForward is not implemented on the current platform'); - } - - /// Goes back in the history of this WebView. - /// - /// If there is no back history item this is a no-op. - Future goBack() { - throw UnimplementedError( - 'goBack is not implemented on the current platform'); - } - - /// Goes forward in the history of this WebView. - /// - /// If there is no forward history item this is a no-op. - Future goForward() { - throw UnimplementedError( - 'goForward is not implemented on the current platform'); - } - - /// Reloads the current URL. - Future reload() { - throw UnimplementedError( - 'reload is not implemented on the current platform'); - } - - /// Clears all caches used by the [WebView]. - /// - /// The following caches are cleared: - /// 1. Browser HTTP Cache. - /// 2. [Cache API](https://developers.google.com/web/fundamentals/instant-and-offline/web-storage/cache-api) caches. - /// These are not yet supported in iOS WkWebView. Service workers tend to use this cache. - /// 3. Application cache. - Future clearCache() { - throw UnimplementedError( - 'clearCache is not implemented on the current platform'); - } - - /// Clears the local storage used by the [WebView]. - Future clearLocalStorage() { - throw UnimplementedError( - 'clearLocalStorage is not implemented on the current platform'); - } - - /// Sets the [PlatformNavigationDelegate] containing the callback methods that - /// are called during navigation events. - Future setPlatformNavigationDelegate( - PlatformNavigationDelegate handler) { - throw UnimplementedError( - 'setPlatformNavigationDelegate is not implemented on the current platform'); - } - - /// Runs the given JavaScript in the context of the current page. - /// - /// The Future completes with an error if a JavaScript error occurred. - Future runJavaScript(String javaScript) { - throw UnimplementedError( - 'runJavaScript is not implemented on the current platform'); - } - - /// Runs the given JavaScript in the context of the current page, and returns the result. - /// - /// The Future completes with an error if a JavaScript error occurred, or if the - /// type the given expression evaluates to is unsupported. Unsupported values include - /// certain non-primitive types on iOS, as well as `undefined` or `null` on iOS 14+. - Future runJavaScriptReturningResult(String javaScript) { - throw UnimplementedError( - 'runJavaScriptReturningResult is not implemented on the current platform'); - } - - /// Adds a new JavaScript channel to the set of enabled channels. - Future addJavaScriptChannel( - JavaScriptChannelParams javaScriptChannelParams, - ) { - throw UnimplementedError( - 'addJavaScriptChannel is not implemented on the current platform'); - } - - /// Removes the JavaScript channel with the matching name from the set of - /// enabled channels. - /// - /// This disables the channel with the matching name if it was previously - /// enabled through the [addJavaScriptChannel]. - Future removeJavaScriptChannel(String javaScriptChannelName) { - throw UnimplementedError( - 'removeJavaScriptChannel is not implemented on the current platform'); - } - - /// Returns the title of the currently loaded page. - Future getTitle() { - throw UnimplementedError( - 'getTitle is not implemented on the current platform'); - } - - /// Set the scrolled position of this view. - /// - /// The parameters `x` and `y` specify the position to scroll to in WebView pixels. - Future scrollTo(int x, int y) { - throw UnimplementedError( - 'scrollTo is not implemented on the current platform'); - } - - /// Move the scrolled position of this view. - /// - /// The parameters `x` and `y` specify the amount of WebView pixels to scroll by. - Future scrollBy(int x, int y) { - throw UnimplementedError( - 'scrollBy is not implemented on the current platform'); - } - - /// Return the current scroll position of this view. - /// - /// Scroll position is measured from the top left. - Future getScrollPosition() { - throw UnimplementedError( - 'getScrollPosition is not implemented on the current platform'); - } - - /// Whether to support zooming using its on-screen zoom controls and gestures. - Future enableZoom(bool enabled) { - throw UnimplementedError( - 'enableZoom is not implemented on the current platform'); - } - - /// Set the current background color of this view. - Future setBackgroundColor(Color color) { - throw UnimplementedError( - 'setBackgroundColor is not implemented on the current platform'); - } - - /// Sets the JavaScript execution mode to be used by the webview. - Future setJavaScriptMode(JavaScriptMode javaScriptMode) { - throw UnimplementedError( - 'setJavaScriptMode is not implemented on the current platform'); - } - - /// Sets the value used for the HTTP `User-Agent:` request header. - Future setUserAgent(String? userAgent) { - throw UnimplementedError( - 'setUserAgent is not implemented on the current platform'); - } -} - -/// Describes the parameters necessary for registering a JavaScript channel. -@immutable -class JavaScriptChannelParams { - /// Creates a new [JavaScriptChannelParams] object. - const JavaScriptChannelParams({ - required this.name, - required this.onMessageReceived, - }); - - /// The name that identifies the JavaScript channel. - final String name; - - /// The callback method that is invoked when a [JavaScriptMessage] is - /// received. - final void Function(JavaScriptMessage) onMessageReceived; -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_cookie_manager.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_cookie_manager.dart deleted file mode 100644 index 9e981c9022c6..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_cookie_manager.dart +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter/foundation.dart'; -import 'package:plugin_platform_interface/plugin_platform_interface.dart'; - -import 'webview_platform.dart'; - -/// Interface for a platform implementation of a cookie manager. -/// -/// Platform implementations should extend this class rather than implement it -/// as `webview_flutter` does not consider newly added methods to be breaking -/// changes. Extending this class (using `extends`) ensures that the subclass -/// will get the default implementation, while platform implementations that -/// `implements` this interface will be broken by newly added -/// [PlatformWebViewCookieManager] methods. -abstract class PlatformWebViewCookieManager extends PlatformInterface { - /// Creates a new [PlatformWebViewCookieManager] - factory PlatformWebViewCookieManager( - PlatformWebViewCookieManagerCreationParams params) { - final PlatformWebViewCookieManager cookieManagerDelegate = - WebViewPlatform.instance!.createPlatformCookieManager(params); - PlatformInterface.verify(cookieManagerDelegate, _token); - return cookieManagerDelegate; - } - - /// Used by the platform implementation to create a new - /// [PlatformWebViewCookieManager]. - /// - /// Should only be used by platform implementations because they can't extend - /// a class that only contains a factory constructor. - @protected - PlatformWebViewCookieManager.implementation(this.params) - : super(token: _token); - - static final Object _token = Object(); - - /// The parameters used to initialize the [PlatformWebViewCookieManager]. - final PlatformWebViewCookieManagerCreationParams params; - - /// Clears all cookies for all [WebView] instances. - /// - /// Returns true if cookies were present before clearing, else false. - Future clearCookies() { - throw UnimplementedError( - 'clearCookies is not implemented on the current platform'); - } - - /// Sets a cookie for all [WebView] instances. - Future setCookie(WebViewCookie cookie) { - throw UnimplementedError( - 'setCookie is not implemented on the current platform'); - } -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_widget.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_widget.dart deleted file mode 100644 index 40334c650b3a..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_widget.dart +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter/widgets.dart'; -import 'package:plugin_platform_interface/plugin_platform_interface.dart'; - -import 'webview_platform.dart'; - -/// Interface for a platform implementation of a web view widget. -abstract class PlatformWebViewWidget extends PlatformInterface { - /// Creates a new [PlatformWebViewWidget] - factory PlatformWebViewWidget(PlatformWebViewWidgetCreationParams params) { - final PlatformWebViewWidget webViewWidgetDelegate = - WebViewPlatform.instance!.createPlatformWebViewWidget(params); - PlatformInterface.verify(webViewWidgetDelegate, _token); - return webViewWidgetDelegate; - } - - /// Used by the platform implementation to create a new - /// [PlatformWebViewWidget]. - /// - /// Should only be used by platform implementations because they can't extend - /// a class that only contains a factory constructor. - @protected - PlatformWebViewWidget.implementation(this.params) : super(token: _token); - - static final Object _token = Object(); - - /// The parameters used to initialize the [PlatformWebViewWidget]. - final PlatformWebViewWidgetCreationParams params; - - /// Builds a new WebView. - /// - /// Returns a Widget tree that embeds the created web view. - Widget build(BuildContext context); -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_message.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_message.dart deleted file mode 100644 index b37661a045a9..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_message.dart +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter/foundation.dart'; - -/// A message that was sent by JavaScript code running in a [WebView]. -/// -/// Platform specific implementations can add additional fields by extending -/// this class and providing a factory method that takes the -/// [JavaScriptMessage] as a parameter. -/// -/// {@tool sample} -/// This example demonstrates how to extend the [JavaScriptMessage] to -/// provide additional platform specific parameters. -/// -/// When extending [JavaScriptMessage] additional parameters should always -/// accept `null` or have a default value to prevent breaking changes. -/// -/// ```dart -/// @immutable -/// class WKWebViewScriptMessage extends JavaScriptMessage { -/// WKWebViewScriptMessage._( -/// JavaScriptMessage javaScriptMessage, -/// this.extraData, -/// ) : super(javaScriptMessage.message); -/// -/// factory WKWebViewScriptMessage.fromJavaScripMessage( -/// JavaScriptMessage javaScripMessage, { -/// String? extraData, -/// }) { -/// return WKWebViewScriptMessage._( -/// javaScriptMessage, -/// extraData: extraData, -/// ); -/// } -/// -/// final String? extraData; -/// } -/// ``` -/// {@end-tool} -@immutable -class JavaScriptMessage { - /// Creates a new JavaScript message object. - const JavaScriptMessage({ - required this.message, - }); - - /// The contents of the message that was sent by the JavaScript code. - final String message; -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_mode.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_mode.dart deleted file mode 100644 index bcbebff8bb1a..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_mode.dart +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -/// Describes the state of JavaScript support in a given web view. -enum JavaScriptMode { - /// JavaScript execution is disabled. - disabled, - - /// JavaScript execution is not restricted. - unrestricted, -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/load_request_params.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/load_request_params.dart deleted file mode 100644 index ad934d6747b7..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/load_request_params.dart +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// TODO(a14n): remove this import once Flutter 3.1 or later reaches stable (including flutter/flutter#104231) -// ignore: unnecessary_import -import 'dart:typed_data'; - -import 'package:flutter/foundation.dart'; - -import '../platform_webview_controller.dart'; - -/// Defines the supported HTTP methods for loading a page in [PlatformWebViewController]. -enum LoadRequestMethod { - /// HTTP GET method. - get, - - /// HTTP POST method. - post, -} - -/// Extension methods on the [LoadRequestMethod] enum. -extension LoadRequestMethodExtensions on LoadRequestMethod { - /// Converts [LoadRequestMethod] to [String] format. - String serialize() { - switch (this) { - case LoadRequestMethod.get: - return 'get'; - case LoadRequestMethod.post: - return 'post'; - } - } -} - -/// Defines the parameters that can be used to load a page with the [PlatformWebViewController]. -/// -/// Platform specific implementations can add additional fields by extending -/// this class. -/// -/// {@tool sample} -/// This example demonstrates how to extend the [LoadRequestParams] to -/// provide additional platform specific parameters. -/// -/// When extending [LoadRequestParams] additional parameters should always -/// accept `null` or have a default value to prevent breaking changes. -/// -/// ```dart -/// class AndroidLoadRequestParams extends LoadRequestParams { -/// AndroidLoadRequestParams._({ -/// required LoadRequestParams params, -/// this.historyUrl, -/// }) : super( -/// uri: params.uri, -/// method: params.method, -/// body: params.body, -/// headers: params.headers, -/// ); -/// -/// factory AndroidLoadRequestParams.fromLoadRequestParams( -/// LoadRequestParams params, { -/// Uri? historyUrl, -/// }) { -/// return AndroidLoadRequestParams._(params, historyUrl: historyUrl); -/// } -/// -/// final Uri? historyUrl; -/// } -/// ``` -/// {@end-tool} -@immutable -class LoadRequestParams { - /// Used by the platform implementation to create a new [LoadRequestParams]. - const LoadRequestParams({ - required this.uri, - this.method = LoadRequestMethod.get, - this.headers = const {}, - this.body, - }); - - /// URI for the request. - final Uri uri; - - /// HTTP method used to make the request. - /// - /// Defaults to [LoadRequestMethod.get]. - final LoadRequestMethod method; - - /// Headers for the request. - final Map headers; - - /// HTTP body for the request. - final Uint8List? body; -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_decision.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_decision.dart deleted file mode 100644 index d8178acd8096..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_decision.dart +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -/// A decision on how to handle a navigation request. -enum NavigationDecision { - /// Prevent the navigation from taking place. - prevent, - - /// Allow the navigation to take place. - navigate, -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_request.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_request.dart deleted file mode 100644 index ee3f1f910f9d..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_request.dart +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -/// Defines the parameters of the pending navigation callback. -class NavigationRequest { - /// Creates a [NavigationRequest]. - const NavigationRequest({ - required this.url, - required this.isMainFrame, - }); - - /// The URL of the pending navigation request. - final String url; - - /// Indicates whether the request was made in the web site's main frame or a subframe. - final bool isMainFrame; -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_navigation_delegate_creation_params.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_navigation_delegate_creation_params.dart deleted file mode 100644 index b20e5eb3ed48..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_navigation_delegate_creation_params.dart +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter/material.dart'; - -/// Object specifying creation parameters for creating a [PlatformNavigationDelegate]. -/// -/// Platform specific implementations can add additional fields by extending -/// this class. -/// -/// {@tool sample} -/// This example demonstrates how to extend the [PlatformNavigationDelegateCreationParams] to -/// provide additional platform specific parameters. -/// -/// When extending [PlatformNavigationDelegateCreationParams] additional -/// parameters should always accept `null` or have a default value to prevent -/// breaking changes. -/// -/// ```dart -/// class AndroidNavigationDelegateCreationParams extends PlatformNavigationDelegateCreationParams { -/// AndroidNavigationDelegateCreationParams._( -/// // This parameter prevents breaking changes later. -/// // ignore: avoid_unused_constructor_parameters -/// PlatformNavigationDelegateCreationParams params, { -/// this.filter, -/// }) : super(); -/// -/// factory AndroidNavigationDelegateCreationParams.fromPlatformNavigationDelegateCreationParams( -/// PlatformNavigationDelegateCreationParams params, { -/// String? filter, -/// }) { -/// return AndroidNavigationDelegateCreationParams._(params, filter: filter); -/// } -/// -/// final String? filter; -/// } -/// ``` -/// {@end-tool} -@immutable -class PlatformNavigationDelegateCreationParams { - /// Used by the platform implementation to create a new [PlatformNavigationkDelegate]. - const PlatformNavigationDelegateCreationParams(); -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_controller_creation_params.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_controller_creation_params.dart deleted file mode 100644 index 778396a79845..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_controller_creation_params.dart +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter/material.dart'; - -/// Object specifying creation parameters for creating a [PlatformWebViewController]. -/// -/// Platform specific implementations can add additional fields by extending -/// this class. -/// -/// {@tool sample} -/// This example demonstrates how to extend the [PlatformWebViewControllerCreationParams] to -/// provide additional platform specific parameters. -/// -/// When extending [PlatformWebViewControllerCreationParams] additional parameters -/// should always accept `null` or have a default value to prevent breaking -/// changes. -/// -/// ```dart -/// class WKWebViewControllerCreationParams -/// extends PlatformWebViewControllerCreationParams { -/// WKWebViewControllerCreationParams._( -/// // This parameter prevents breaking changes later. -/// // ignore: avoid_unused_constructor_parameters -/// PlatformWebViewControllerCreationParams params, { -/// this.domain, -/// }) : super(); -/// -/// factory WKWebViewControllerCreationParams.fromPlatformWebViewControllerCreationParams( -/// PlatformWebViewControllerCreationParams params, { -/// String? domain, -/// }) { -/// return WKWebViewControllerCreationParams._(params, domain: domain); -/// } -/// -/// final String? domain; -/// } -/// ``` -/// {@end-tool} -@immutable -class PlatformWebViewControllerCreationParams { - /// Used by the platform implementation to create a new [PlatformWebViewController]. - const PlatformWebViewControllerCreationParams(); -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_cookie_manager_creation_params.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_cookie_manager_creation_params.dart deleted file mode 100644 index e8c4938f649f..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_cookie_manager_creation_params.dart +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter/material.dart'; - -/// Object specifying creation parameters for creating a [PlatformWebViewCookieManager]. -/// -/// Platform specific implementations can add additional fields by extending -/// this class. -/// -/// {@tool sample} -/// This example demonstrates how to extend the [PlatformWebViewCookieManagerCreationParams] to -/// provide additional platform specific parameters. -/// -/// When extending [PlatformWebViewCookieManagerCreationParams] additional -/// parameters should always accept `null` or have a default value to prevent -/// breaking changes. -/// -/// ```dart -/// class WKWebViewCookieManagerCreationParams -/// extends PlatformWebViewCookieManagerCreationParams { -/// WKWebViewCookieManagerCreationParams._( -/// // This parameter prevents breaking changes later. -/// // ignore: avoid_unused_constructor_parameters -/// PlatformWebViewCookieManagerCreationParams params, { -/// this.uri, -/// }) : super(); -/// -/// factory WKWebViewCookieManagerCreationParams.fromPlatformWebViewCookieManagerCreationParams( -/// PlatformWebViewCookieManagerCreationParams params, { -/// Uri? uri, -/// }) { -/// return WKWebViewCookieManagerCreationParams._(params, uri: uri); -/// } -/// -/// final Uri? uri; -/// } -/// ``` -/// {@end-tool} -@immutable -class PlatformWebViewCookieManagerCreationParams { - /// Used by the platform implementation to create a new [PlatformWebViewCookieManagerDelegate]. - const PlatformWebViewCookieManagerCreationParams(); -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_widget_creation_params.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_widget_creation_params.dart deleted file mode 100644 index 83a73c2a44a3..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_widget_creation_params.dart +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter/foundation.dart'; -import 'package:flutter/gestures.dart'; -import 'package:flutter/painting.dart'; - -import '../platform_webview_controller.dart'; - -/// Object specifying creation parameters for creating a [WebViewWidgetDelegate]. -/// -/// Platform specific implementations can add additional fields by extending -/// this class. -/// -/// {@tool sample} -/// This example demonstrates how to extend the [PlatformWebViewWidgetCreationParams] to -/// provide additional platform specific parameters. -/// -/// When extending [PlatformWebViewWidgetCreationParams] additional parameters -/// should always accept `null` or have a default value to prevent breaking -/// changes. -/// -/// ```dart -/// class AndroidWebViewWidgetCreationParams -/// extends PlatformWebViewWidgetCreationParams { -/// AndroidWebViewWidgetCreationParams({ -/// super.key, -/// super.layoutDirection, -/// super.gestureRecognizers, -/// this.platformSpecificFieldExample, -/// }); -/// -/// WKWebViewWidgetCreationParams.fromPlatformWebViewWidgetCreationParams( -/// PlatformWebViewWidgetCreationParams params, { -/// Object? platformSpecificFieldExample, -/// }) : this( -/// key: params.key, -/// layoutDirection: params.layoutDirection, -/// gestureRecognizers: params.gestureRecognizers, -/// platformSpecificFieldExample: platformSpecificFieldExample, -/// ); -/// -/// final Object? platformSpecificFieldExample; -/// } -/// ``` -/// {@end-tool} -@immutable -class PlatformWebViewWidgetCreationParams { - /// Used by the platform implementation to create a new [PlatformWebViewWidget]. - const PlatformWebViewWidgetCreationParams({ - this.key, - required this.controller, - this.layoutDirection = TextDirection.ltr, - this.gestureRecognizers = const >{}, - }); - - /// Controls how one widget replaces another widget in the tree. - /// - /// See also: - /// - /// * The discussions at [Key] and [GlobalKey]. - final Key? key; - - /// The [PlatformWebViewController] that allows controlling the native web - /// view. - final PlatformWebViewController controller; - - /// The layout direction to use for the embedded WebView. - final TextDirection layoutDirection; - - /// The `gestureRecognizers` specifies which gestures should be consumed by the - /// web view. - /// - /// It is possible for other gesture recognizers to be competing with the web - /// view on pointer events, e.g if the web view is inside a [ListView] the - /// [ListView] will want to handle vertical drags. The web view will claim - /// gestures that are recognized by any of the recognizers on this list. - /// - /// When `gestureRecognizers` is empty (default), the web view will only handle - /// pointer events for gestures that were not claimed by any other gesture - /// recognizer. - final Set> gestureRecognizers; -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/types.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/types.dart deleted file mode 100644 index 4df8800c83e1..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/types.dart +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -export 'javascript_message.dart'; -export 'javascript_mode.dart'; -export 'load_request_params.dart'; -export 'navigation_decision.dart'; -export 'navigation_request.dart'; -export 'platform_navigation_delegate_creation_params.dart'; -export 'platform_webview_controller_creation_params.dart'; -export 'platform_webview_cookie_manager_creation_params.dart'; -export 'platform_webview_widget_creation_params.dart'; -export 'web_resource_error.dart'; -export 'webview_cookie.dart'; diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/web_resource_error.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/web_resource_error.dart deleted file mode 100644 index e2522da859f7..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/web_resource_error.dart +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter/foundation.dart'; - -/// Possible error type categorizations used by [WebResourceError]. -enum WebResourceErrorType { - /// User authentication failed on server. - authentication, - - /// Malformed URL. - badUrl, - - /// Failed to connect to the server. - connect, - - /// Failed to perform SSL handshake. - failedSslHandshake, - - /// Generic file error. - file, - - /// File not found. - fileNotFound, - - /// Server or proxy hostname lookup failed. - hostLookup, - - /// Failed to read or write to the server. - io, - - /// User authentication failed on proxy. - proxyAuthentication, - - /// Too many redirects. - redirectLoop, - - /// Connection timed out. - timeout, - - /// Too many requests during this load. - tooManyRequests, - - /// Generic error. - unknown, - - /// Resource load was canceled by Safe Browsing. - unsafeResource, - - /// Unsupported authentication scheme (not basic or digest). - unsupportedAuthScheme, - - /// Unsupported URI scheme. - unsupportedScheme, - - /// The web content process was terminated. - webContentProcessTerminated, - - /// The web view was invalidated. - webViewInvalidated, - - /// A JavaScript exception occurred. - javaScriptExceptionOccurred, - - /// The result of JavaScript execution could not be returned. - javaScriptResultTypeIsUnsupported, -} - -/// Error returned in `WebView.onWebResourceError` when a web resource loading error has occurred. -/// -/// Platform specific implementations can add additional fields by extending -/// this class. -/// -/// {@tool sample} -/// This example demonstrates how to extend the [WebResourceError] to -/// provide additional platform specific parameters. -/// -/// When extending [WebResourceError] additional parameters should always -/// accept `null` or have a default value to prevent breaking changes. -/// -/// ```dart -/// class IOSWebResourceError extends WebResourceError { -/// IOSWebResourceError._(WebResourceError error, {required this.domain}) -/// : super( -/// errorCode: error.errorCode, -/// description: error.description, -/// errorType: error.errorType, -/// ); -/// -/// factory IOSWebResourceError.fromWebResourceError( -/// WebResourceError error, { -/// required String? domain, -/// }) { -/// return IOSWebResourceError._(error, domain: domain); -/// } -/// -/// final String? domain; -/// } -/// ``` -/// {@end-tool} -@immutable -class WebResourceError { - /// Used by the platform implementation to create a new [WebResourceError]. - const WebResourceError({ - required this.errorCode, - required this.description, - this.errorType, - this.isForMainFrame, - }); - - /// Raw code of the error from the respective platform. - final int errorCode; - - /// Description of the error that can be used to communicate the problem to the user. - final String description; - - /// The type this error can be categorized as. - final WebResourceErrorType? errorType; - - /// Whether the error originated from the main frame. - final bool? isForMainFrame; -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/webview_cookie.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/webview_cookie.dart deleted file mode 100644 index 7f56a312049f..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/webview_cookie.dart +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter/foundation.dart'; - -/// A cookie that can be set globally for all web views using [WebViewCookieManagerPlatform]. -@immutable -class WebViewCookie { - /// Creates a new [WebViewCookieDelegate] - const WebViewCookie({ - required this.name, - required this.value, - required this.domain, - this.path = '/', - }); - - /// The cookie-name of the cookie. - /// - /// Its value should match "cookie-name" in RFC6265bis: - /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 - final String name; - - /// The cookie-value of the cookie. - /// - /// Its value should match "cookie-value" in RFC6265bis: - /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 - final String value; - - /// The domain-value of the cookie. - /// - /// Its value should match "domain-value" in RFC6265bis: - /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 - final String domain; - - /// The path-value of the cookie, set to `/` by default. - /// - /// Its value should match "path-value" in RFC6265bis: - /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 - final String path; -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/webview_flutter_platform_interface_legacy.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/webview_flutter_platform_interface_legacy.dart deleted file mode 100644 index 1964e7089d2d..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/webview_flutter_platform_interface_legacy.dart +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -export 'legacy/platform_interface/platform_interface.dart'; -export 'legacy/types/types.dart'; diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/webview_platform.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/webview_platform.dart deleted file mode 100644 index e91396243ea5..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/webview_platform.dart +++ /dev/null @@ -1,82 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:plugin_platform_interface/plugin_platform_interface.dart'; - -import '../../src/platform_navigation_delegate.dart'; -import 'platform_webview_controller.dart'; -import 'platform_webview_cookie_manager.dart'; -import 'platform_webview_widget.dart'; -import 'types/types.dart'; - -export 'types/types.dart'; - -/// Interface for a platform implementation of a WebView. -abstract class WebViewPlatform extends PlatformInterface { - /// Creates a new [WebViewPlatform]. - WebViewPlatform() : super(token: _token); - - static final Object _token = Object(); - - static WebViewPlatform? _instance; - - /// The instance of [WebViewPlatform] to use. - static WebViewPlatform? get instance => _instance; - - /// Platform-specific plugins should set this with their own platform-specific - /// class that extends [WebViewPlatform] when they register themselves. - static set instance(WebViewPlatform? instance) { - if (instance == null) { - throw AssertionError( - 'Platform interfaces can only be set to a non-null instance'); - } - - PlatformInterface.verify(instance, _token); - _instance = instance; - } - - /// Creates a new [PlatformWebViewCookieManager]. - /// - /// This function should only be called by the app-facing package. - /// Look at using [WebViewCookieManager] in `webview_flutter` instead. - PlatformWebViewCookieManager createPlatformCookieManager( - PlatformWebViewCookieManagerCreationParams params, - ) { - throw UnimplementedError( - 'createPlatformCookieManager is not implemented on the current platform.'); - } - - /// Creates a new [PlatformNavigationDelegate]. - /// - /// This function should only be called by the app-facing package. - /// Look at using [NavigationDelegate] in `webview_flutter` instead. - PlatformNavigationDelegate createPlatformNavigationDelegate( - PlatformNavigationDelegateCreationParams params, - ) { - throw UnimplementedError( - 'createPlatformNavigationDelegate is not implemented on the current platform.'); - } - - /// Create a new [PlatformWebViewController]. - /// - /// This function should only be called by the app-facing package. - /// Look at using [WebViewController] in `webview_flutter` instead. - PlatformWebViewController createPlatformWebViewController( - PlatformWebViewControllerCreationParams params, - ) { - throw UnimplementedError( - 'createPlatformWebViewController is not implemented on the current platform.'); - } - - /// Create a new [PlatformWebViewWidget]. - /// - /// This function should only be called by the app-facing package. - /// Look at using [WebViewWidget] in `webview_flutter` instead. - PlatformWebViewWidget createPlatformWebViewWidget( - PlatformWebViewWidgetCreationParams params, - ) { - throw UnimplementedError( - 'createPlatformWebViewWidget is not implemented on the current platform.'); - } -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/webview_flutter_platform_interface.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/webview_flutter_platform_interface.dart deleted file mode 100644 index d14fec163327..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/lib/webview_flutter_platform_interface.dart +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -export 'src/platform_navigation_delegate.dart'; -export 'src/platform_webview_controller.dart'; -export 'src/platform_webview_cookie_manager.dart'; -export 'src/platform_webview_widget.dart'; -export 'src/types/types.dart'; -export 'src/webview_platform.dart'; diff --git a/packages/webview_flutter/webview_flutter_platform_interface/pubspec.yaml b/packages/webview_flutter/webview_flutter_platform_interface/pubspec.yaml deleted file mode 100644 index 3ba7a567398e..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/pubspec.yaml +++ /dev/null @@ -1,23 +0,0 @@ -name: webview_flutter_platform_interface -description: A common platform interface for the webview_flutter plugin. -repository: https://github.com/flutter/plugins/tree/main/packages/webview_flutter/webview_flutter_platform_interface -issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview_flutter%22 -# NOTE: We strongly prefer non-breaking changes, even at the expense of a -# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes -version: 2.0.0 - -environment: - sdk: ">=2.12.0 <3.0.0" - flutter: ">=2.10.0" - -dependencies: - flutter: - sdk: flutter - meta: ^1.7.0 - plugin_platform_interface: ^2.1.0 - -dev_dependencies: - build_runner: ^2.1.8 - flutter_test: - sdk: flutter - mockito: ^5.0.0 diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/platform_interface/javascript_channel_registry_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/platform_interface/javascript_channel_registry_test.dart deleted file mode 100644 index c9d27c601985..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/platform_interface/javascript_channel_registry_test.dart +++ /dev/null @@ -1,117 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter_test/flutter_test.dart'; -import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; - -void main() { - final Map log = {}; - final Set channels = { - JavascriptChannel( - name: 'js_channel_1', - onMessageReceived: (JavascriptMessage message) => - log['js_channel_1'] = message.message, - ), - JavascriptChannel( - name: 'js_channel_2', - onMessageReceived: (JavascriptMessage message) => - log['js_channel_2'] = message.message, - ), - JavascriptChannel( - name: 'js_channel_3', - onMessageReceived: (JavascriptMessage message) => - log['js_channel_3'] = message.message, - ), - }; - - tearDown(() { - log.clear(); - }); - - test('ctor should initialize with channels.', () { - final JavascriptChannelRegistry registry = - JavascriptChannelRegistry(channels); - - expect(registry.channels.length, 3); - for (final JavascriptChannel channel in channels) { - expect(registry.channels[channel.name], channel); - } - }); - - test('onJavascriptChannelMessage should forward message on correct channel.', - () { - final JavascriptChannelRegistry registry = - JavascriptChannelRegistry(channels); - - registry.onJavascriptChannelMessage( - 'js_channel_2', - 'test message on channel 2', - ); - - expect( - log, - containsPair( - 'js_channel_2', - 'test message on channel 2', - )); - }); - - test( - 'onJavascriptChannelMessage should throw ArgumentError when message arrives on non-existing channel.', - () { - final JavascriptChannelRegistry registry = - JavascriptChannelRegistry(channels); - - expect( - () => registry.onJavascriptChannelMessage( - 'js_channel_4', - 'test message on channel 2', - ), - throwsA( - isA().having((ArgumentError error) => error.message, - 'message', 'No channel registered with name js_channel_4.'), - )); - }); - - test( - 'updateJavascriptChannelsFromSet should clear all channels when null is supplied.', - () { - final JavascriptChannelRegistry registry = - JavascriptChannelRegistry(channels); - - expect(registry.channels.length, 3); - - registry.updateJavascriptChannelsFromSet(null); - - expect(registry.channels, isEmpty); - }); - - test('updateJavascriptChannelsFromSet should update registry with new set.', - () { - final JavascriptChannelRegistry registry = - JavascriptChannelRegistry(channels); - - expect(registry.channels.length, 3); - - final Set newChannels = { - JavascriptChannel( - name: 'new_js_channel_1', - onMessageReceived: (JavascriptMessage message) => - log['new_js_channel_1'] = message.message, - ), - JavascriptChannel( - name: 'new_js_channel_2', - onMessageReceived: (JavascriptMessage message) => - log['new_js_channel_2'] = message.message, - ), - }; - - registry.updateJavascriptChannelsFromSet(newChannels); - - expect(registry.channels.length, 2); - for (final JavascriptChannel channel in newChannels) { - expect(registry.channels[channel.name], channel); - } - }); -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/platform_interface/webview_cookie_manager_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/platform_interface/webview_cookie_manager_test.dart deleted file mode 100644 index a9faea52e407..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/platform_interface/webview_cookie_manager_test.dart +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter_test/flutter_test.dart'; -import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; - -void main() { - WebViewCookieManagerPlatform? cookieManager; - - setUp(() { - cookieManager = TestWebViewCookieManagerPlatform(); - }); - - test('clearCookies should throw UnimplementedError', () { - expect(() => cookieManager!.clearCookies(), throwsUnimplementedError); - }); - - test('setCookie should throw UnimplementedError', () { - const WebViewCookie cookie = - WebViewCookie(domain: 'flutter.dev', name: 'foo', value: 'bar'); - expect(() => cookieManager!.setCookie(cookie), throwsUnimplementedError); - }); -} - -class TestWebViewCookieManagerPlatform extends WebViewCookieManagerPlatform {} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/javascript_channel_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/javascript_channel_test.dart deleted file mode 100644 index ecb9c3fbed10..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/javascript_channel_test.dart +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter_test/flutter_test.dart'; -import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; - -void main() { - final List validChars = - 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_'.split(''); - final List commonInvalidChars = - r'`~!@#$%^&*()-=+[]{}\|"' ':;/?<>,. '.split(''); - final List digits = List.generate(10, (int index) => index++); - - test( - 'ctor should create JavascriptChannel when name starts with a valid character followed by a number.', - () { - for (final String char in validChars) { - for (final int digit in digits) { - final JavascriptChannel channel = - JavascriptChannel(name: '$char$digit', onMessageReceived: (_) {}); - - expect(channel.name, '$char$digit'); - } - } - }); - - test('ctor should assert when channel name starts with a number.', () { - for (final int i in digits) { - expect( - () => JavascriptChannel(name: '$i', onMessageReceived: (_) {}), - throwsAssertionError, - ); - } - }); - - test('ctor should assert when channel contains invalid char.', () { - for (final String validChar in validChars) { - for (final String invalidChar in commonInvalidChars) { - expect( - () => JavascriptChannel( - name: validChar + invalidChar, onMessageReceived: (_) {}), - throwsAssertionError, - ); - } - } - }); -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/webview_cookie_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/webview_cookie_test.dart deleted file mode 100644 index f1702f4ad1c0..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/webview_cookie_test.dart +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter_test/flutter_test.dart'; -import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; - -void main() { - test('WebViewCookie should serialize correctly', () { - WebViewCookie cookie; - Map serializedCookie; - // Test serialization - cookie = const WebViewCookie( - name: 'foo', value: 'bar', domain: 'example.com', path: '/test'); - serializedCookie = cookie.toJson(); - expect(serializedCookie['name'], 'foo'); - expect(serializedCookie['value'], 'bar'); - expect(serializedCookie['domain'], 'example.com'); - expect(serializedCookie['path'], '/test'); - }); -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/webview_request_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/webview_request_test.dart deleted file mode 100644 index fff1a9b19878..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/webview_request_test.dart +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'dart:typed_data'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; - -void main() { - test('WebViewRequestMethod should serialize correctly', () { - expect(WebViewRequestMethod.get.serialize(), 'get'); - expect(WebViewRequestMethod.post.serialize(), 'post'); - }); - - test('WebViewRequest should serialize correctly', () { - WebViewRequest request; - Map serializedRequest; - // Test serialization without headers or a body - request = WebViewRequest( - uri: Uri.parse('https://flutter.dev'), - method: WebViewRequestMethod.get, - ); - serializedRequest = request.toJson(); - expect(serializedRequest['uri'], 'https://flutter.dev'); - expect(serializedRequest['method'], 'get'); - expect(serializedRequest['headers'], {}); - expect(serializedRequest['body'], null); - // Test serialization of headers and body - request = WebViewRequest( - uri: Uri.parse('https://flutter.dev'), - method: WebViewRequestMethod.get, - headers: {'foo': 'bar'}, - body: Uint8List.fromList('Example Body'.codeUnits), - ); - serializedRequest = request.toJson(); - expect(serializedRequest['headers'], {'foo': 'bar'}); - expect(serializedRequest['body'], 'Example Body'.codeUnits); - }); -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/platform_navigation_delegate_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/platform_navigation_delegate_test.dart deleted file mode 100644 index 5e9aa2e12437..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/platform_navigation_delegate_test.dart +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter_test/flutter_test.dart'; -import 'package:mockito/mockito.dart'; -import 'package:plugin_platform_interface/plugin_platform_interface.dart'; -import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; - -import 'webview_platform_test.mocks.dart'; - -void main() { - setUp(() { - WebViewPlatform.instance = MockWebViewPlatformWithMixin(); - }); - - test('Cannot be implemented with `implements`', () { - const PlatformNavigationDelegateCreationParams params = - PlatformNavigationDelegateCreationParams(); - when(WebViewPlatform.instance!.createPlatformNavigationDelegate(params)) - .thenReturn(ImplementsPlatformNavigationDelegate()); - - expect(() { - PlatformNavigationDelegate(params); - // In versions of `package:plugin_platform_interface` prior to fixing - // https://github.com/flutter/flutter/issues/109339, an attempt to - // implement a platform interface using `implements` would sometimes throw - // a `NoSuchMethodError` and other times throw an `AssertionError`. After - // the issue is fixed, an `AssertionError` will always be thrown. For the - // purpose of this test, we don't really care what exception is thrown, so - // just allow any exception. - }, throwsA(anything)); - }); - - test('Can be extended', () { - const PlatformNavigationDelegateCreationParams params = - PlatformNavigationDelegateCreationParams(); - when(WebViewPlatform.instance!.createPlatformNavigationDelegate(params)) - .thenReturn(ExtendsPlatformNavigationDelegate(params)); - - expect(PlatformNavigationDelegate(params), isNotNull); - }); - - test('Can be mocked with `implements`', () { - const PlatformNavigationDelegateCreationParams params = - PlatformNavigationDelegateCreationParams(); - when(WebViewPlatform.instance!.createPlatformNavigationDelegate(params)) - .thenReturn(MockNavigationDelegate()); - - expect(PlatformNavigationDelegate(params), isNotNull); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of setOnNavigationRequest should throw unimplemented error', - () { - final PlatformNavigationDelegate callbackDelegate = - ExtendsPlatformNavigationDelegate( - const PlatformNavigationDelegateCreationParams()); - - expect( - () => callbackDelegate.setOnNavigationRequest( - (NavigationRequest navigationRequest) => NavigationDecision.navigate), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of setOnPageStarted should throw unimplemented error', - () { - final PlatformNavigationDelegate callbackDelegate = - ExtendsPlatformNavigationDelegate( - const PlatformNavigationDelegateCreationParams()); - - expect( - () => callbackDelegate.setOnPageStarted((String url) {}), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of setOnPageFinished should throw unimplemented error', - () { - final PlatformNavigationDelegate callbackDelegate = - ExtendsPlatformNavigationDelegate( - const PlatformNavigationDelegateCreationParams()); - - expect( - () => callbackDelegate.setOnPageFinished((String url) {}), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of setOnProgress should throw unimplemented error', - () { - final PlatformNavigationDelegate callbackDelegate = - ExtendsPlatformNavigationDelegate( - const PlatformNavigationDelegateCreationParams()); - - expect( - () => callbackDelegate.setOnProgress((int progress) {}), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of setOnWebResourceError should throw unimplemented error', - () { - final PlatformNavigationDelegate callbackDelegate = - ExtendsPlatformNavigationDelegate( - const PlatformNavigationDelegateCreationParams()); - - expect( - () => callbackDelegate.setOnWebResourceError((WebResourceError error) {}), - throwsUnimplementedError, - ); - }); -} - -class MockWebViewPlatformWithMixin extends MockWebViewPlatform - with - // ignore: prefer_mixin - MockPlatformInterfaceMixin {} - -class ImplementsPlatformNavigationDelegate - implements PlatformNavigationDelegate { - @override - dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); -} - -class MockNavigationDelegate extends Mock - with - // ignore: prefer_mixin - MockPlatformInterfaceMixin - implements - PlatformNavigationDelegate {} - -class ExtendsPlatformNavigationDelegate extends PlatformNavigationDelegate { - ExtendsPlatformNavigationDelegate( - PlatformNavigationDelegateCreationParams params) - : super.implementation(params); -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.dart deleted file mode 100644 index 6710f34895b7..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.dart +++ /dev/null @@ -1,444 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter/material.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:mockito/annotations.dart'; -import 'package:mockito/mockito.dart'; -import 'package:plugin_platform_interface/plugin_platform_interface.dart'; -import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; - -import 'platform_navigation_delegate_test.dart'; -import 'webview_platform_test.mocks.dart'; - -@GenerateMocks([PlatformNavigationDelegate]) -void main() { - setUp(() { - WebViewPlatform.instance = MockWebViewPlatformWithMixin(); - }); - - test('Cannot be implemented with `implements`', () { - when((WebViewPlatform.instance! as MockWebViewPlatform) - .createPlatformWebViewController(any)) - .thenReturn(ImplementsPlatformWebViewController()); - - expect(() { - PlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - // In versions of `package:plugin_platform_interface` prior to fixing - // https://github.com/flutter/flutter/issues/109339, an attempt to - // implement a platform interface using `implements` would sometimes throw - // a `NoSuchMethodError` and other times throw an `AssertionError`. After - // the issue is fixed, an `AssertionError` will always be thrown. For the - // purpose of this test, we don't really care what exception is thrown, so - // just allow any exception. - }, throwsA(anything)); - }); - - test('Can be extended', () { - const PlatformWebViewControllerCreationParams params = - PlatformWebViewControllerCreationParams(); - when((WebViewPlatform.instance! as MockWebViewPlatform) - .createPlatformWebViewController(any)) - .thenReturn(ExtendsPlatformWebViewController(params)); - - expect(PlatformWebViewController(params), isNotNull); - }); - - test('Can be mocked with `implements`', () { - when((WebViewPlatform.instance! as MockWebViewPlatform) - .createPlatformWebViewController(any)) - .thenReturn(MockWebViewControllerDelegate()); - - expect( - PlatformWebViewController( - const PlatformWebViewControllerCreationParams()), - isNotNull); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of loadFile should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.loadFile(''), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of loadFlutterAsset should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.loadFlutterAsset(''), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of loadHtmlString should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.loadHtmlString(''), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of loadRequest should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.loadRequest(MockLoadRequestParamsDelegate()), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of currentUrl should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.currentUrl(), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of canGoBack should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.canGoBack(), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of canGoForward should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.canGoForward(), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of goBack should throw unimplemented error', () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.goBack(), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of goForward should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.goForward(), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of reload should throw unimplemented error', () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.reload(), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of clearCache should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.clearCache(), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of clearLocalStorage should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.clearLocalStorage(), - throwsUnimplementedError, - ); - }); - - test( - 'Default implementation of the setNavigationCallback should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => - controller.setPlatformNavigationDelegate(MockNavigationDelegate()), - throwsUnimplementedError, - ); - }, - ); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of runJavaScript should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.runJavaScript('javaScript'), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of runJavaScriptReturningResult should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.runJavaScriptReturningResult('javaScript'), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of addJavaScriptChannel should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.addJavaScriptChannel( - JavaScriptChannelParams( - name: 'test', - onMessageReceived: (_) {}, - ), - ), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of removeJavaScriptChannel should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.removeJavaScriptChannel('test'), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of getTitle should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.getTitle(), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of scrollTo should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.scrollTo(0, 0), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of scrollBy should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.scrollBy(0, 0), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of getScrollPosition should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.getScrollPosition(), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of enableZoom should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.enableZoom(true), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of setBackgroundColor should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.setBackgroundColor(Colors.blue), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of setJavaScriptMode should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.setJavaScriptMode(JavaScriptMode.disabled), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of setUserAgent should throw unimplemented error', - () { - final PlatformWebViewController controller = - ExtendsPlatformWebViewController( - const PlatformWebViewControllerCreationParams()); - - expect( - () => controller.setUserAgent(null), - throwsUnimplementedError, - ); - }); -} - -class MockWebViewPlatformWithMixin extends MockWebViewPlatform - with - // ignore: prefer_mixin - MockPlatformInterfaceMixin {} - -class ImplementsPlatformWebViewController implements PlatformWebViewController { - @override - dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); -} - -class MockWebViewControllerDelegate extends Mock - with - // ignore: prefer_mixin - MockPlatformInterfaceMixin - implements - PlatformWebViewController {} - -class ExtendsPlatformWebViewController extends PlatformWebViewController { - ExtendsPlatformWebViewController( - PlatformWebViewControllerCreationParams params) - : super.implementation(params); -} - -// ignore: must_be_immutable -class MockLoadRequestParamsDelegate extends Mock - with - //ignore: prefer_mixin - MockPlatformInterfaceMixin - implements - LoadRequestParams {} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.mocks.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.mocks.dart deleted file mode 100644 index db142fe6a782..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.mocks.dart +++ /dev/null @@ -1,106 +0,0 @@ -// Mocks generated by Mockito 5.3.2 from annotations -// in webview_flutter_platform_interface/test/platform_webview_controller_test.dart. -// Do not manually edit this file. - -// ignore_for_file: no_leading_underscores_for_library_prefixes -import 'dart:async' as _i4; - -import 'package:mockito/mockito.dart' as _i1; -import 'package:webview_flutter_platform_interface/src/platform_navigation_delegate.dart' - as _i3; -import 'package:webview_flutter_platform_interface/src/webview_platform.dart' - as _i2; - -// ignore_for_file: type=lint -// ignore_for_file: avoid_redundant_argument_values -// ignore_for_file: avoid_setters_without_getters -// ignore_for_file: comment_references -// ignore_for_file: implementation_imports -// ignore_for_file: invalid_use_of_visible_for_testing_member -// ignore_for_file: prefer_const_constructors -// ignore_for_file: unnecessary_parenthesis -// ignore_for_file: camel_case_types -// ignore_for_file: subtype_of_sealed_class - -class _FakePlatformNavigationDelegateCreationParams_0 extends _i1.SmartFake - implements _i2.PlatformNavigationDelegateCreationParams { - _FakePlatformNavigationDelegateCreationParams_0( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -/// A class which mocks [PlatformNavigationDelegate]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockPlatformNavigationDelegate extends _i1.Mock - implements _i3.PlatformNavigationDelegate { - MockPlatformNavigationDelegate() { - _i1.throwOnMissingStub(this); - } - - @override - _i2.PlatformNavigationDelegateCreationParams get params => - (super.noSuchMethod( - Invocation.getter(#params), - returnValue: _FakePlatformNavigationDelegateCreationParams_0( - this, - Invocation.getter(#params), - ), - ) as _i2.PlatformNavigationDelegateCreationParams); - @override - _i4.Future setOnNavigationRequest( - _i3.NavigationRequestCallback? onNavigationRequest) => - (super.noSuchMethod( - Invocation.method( - #setOnNavigationRequest, - [onNavigationRequest], - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); - @override - _i4.Future setOnPageStarted(_i3.PageEventCallback? onPageStarted) => - (super.noSuchMethod( - Invocation.method( - #setOnPageStarted, - [onPageStarted], - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); - @override - _i4.Future setOnPageFinished(_i3.PageEventCallback? onPageFinished) => - (super.noSuchMethod( - Invocation.method( - #setOnPageFinished, - [onPageFinished], - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); - @override - _i4.Future setOnProgress(_i3.ProgressCallback? onProgress) => - (super.noSuchMethod( - Invocation.method( - #setOnProgress, - [onProgress], - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); - @override - _i4.Future setOnWebResourceError( - _i3.WebResourceErrorCallback? onWebResourceError) => - (super.noSuchMethod( - Invocation.method( - #setOnWebResourceError, - [onWebResourceError], - ), - returnValue: _i4.Future.value(), - returnValueForMissingStub: _i4.Future.value(), - ) as _i4.Future); -} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_widget_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_widget_test.dart deleted file mode 100644 index 652f326cf20e..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_widget_test.dart +++ /dev/null @@ -1,94 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter/widgets.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:mockito/mockito.dart'; -import 'package:plugin_platform_interface/plugin_platform_interface.dart'; -import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; - -import 'webview_platform_test.mocks.dart'; - -void main() { - setUp(() { - WebViewPlatform.instance = MockWebViewPlatformWithMixin(); - }); - - test('Cannot be implemented with `implements`', () { - final MockWebViewControllerDelegate controller = - MockWebViewControllerDelegate(); - final PlatformWebViewWidgetCreationParams params = - PlatformWebViewWidgetCreationParams(controller: controller); - when(WebViewPlatform.instance!.createPlatformWebViewWidget(params)) - .thenReturn(ImplementsWebViewWidgetDelegate()); - - expect(() { - PlatformWebViewWidget(params); - // In versions of `package:plugin_platform_interface` prior to fixing - // https://github.com/flutter/flutter/issues/109339, an attempt to - // implement a platform interface using `implements` would sometimes throw - // a `NoSuchMethodError` and other times throw an `AssertionError`. After - // the issue is fixed, an `AssertionError` will always be thrown. For the - // purpose of this test, we don't really care what exception is thrown, so - // just allow any exception. - }, throwsA(anything)); - }); - - test('Can be extended', () { - final MockWebViewControllerDelegate controller = - MockWebViewControllerDelegate(); - final PlatformWebViewWidgetCreationParams params = - PlatformWebViewWidgetCreationParams(controller: controller); - when(WebViewPlatform.instance!.createPlatformWebViewWidget(params)) - .thenReturn(ExtendsWebViewWidgetDelegate(params)); - - expect(PlatformWebViewWidget(params), isNotNull); - }); - - test('Can be mocked with `implements`', () { - final MockWebViewControllerDelegate controller = - MockWebViewControllerDelegate(); - final PlatformWebViewWidgetCreationParams params = - PlatformWebViewWidgetCreationParams(controller: controller); - when(WebViewPlatform.instance!.createPlatformWebViewWidget(params)) - .thenReturn(MockWebViewWidgetDelegate()); - - expect(PlatformWebViewWidget(params), isNotNull); - }); -} - -class MockWebViewPlatformWithMixin extends MockWebViewPlatform - with - // ignore: prefer_mixin - MockPlatformInterfaceMixin {} - -class ImplementsWebViewWidgetDelegate implements PlatformWebViewWidget { - @override - dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); -} - -class MockWebViewWidgetDelegate extends Mock - with - // ignore: prefer_mixin - MockPlatformInterfaceMixin - implements - PlatformWebViewWidget {} - -class ExtendsWebViewWidgetDelegate extends PlatformWebViewWidget { - ExtendsWebViewWidgetDelegate(PlatformWebViewWidgetCreationParams params) - : super.implementation(params); - - @override - Widget build(BuildContext context) { - throw UnimplementedError( - 'build is not implemented for ExtendedWebViewWidgetDelegate.'); - } -} - -class MockWebViewControllerDelegate extends Mock - with - // ignore: prefer_mixin - MockPlatformInterfaceMixin - implements - PlatformWebViewController {} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/webview_platform_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/webview_platform_test.dart deleted file mode 100644 index 34f84065e951..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/webview_platform_test.dart +++ /dev/null @@ -1,115 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'package:flutter_test/flutter_test.dart'; -import 'package:mockito/annotations.dart'; -import 'package:mockito/mockito.dart'; -import 'package:plugin_platform_interface/plugin_platform_interface.dart'; -import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; - -import 'webview_platform_test.mocks.dart'; - -@GenerateMocks([WebViewPlatform]) -void main() { - TestWidgetsFlutterBinding.ensureInitialized(); - - test('Default instance WebViewPlatform instance should be null', () { - expect(WebViewPlatform.instance, isNull); - }); - - test('Cannot be implemented with `implements`', () { - expect(() { - WebViewPlatform.instance = ImplementsWebViewPlatform(); - // In versions of `package:plugin_platform_interface` prior to fixing - // https://github.com/flutter/flutter/issues/109339, an attempt to - // implement a platform interface using `implements` would sometimes throw - // a `NoSuchMethodError` and other times throw an `AssertionError`. After - // the issue is fixed, an `AssertionError` will always be thrown. For the - // purpose of this test, we don't really care what exception is thrown, so - // just allow any exception. - }, throwsA(anything)); - }); - - test('Can be extended', () { - WebViewPlatform.instance = ExtendsWebViewPlatform(); - }); - - test('Can be mocked with `implements`', () { - final MockWebViewPlatform mock = MockWebViewPlatformWithMixin(); - WebViewPlatform.instance = mock; - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of createCookieManagerDelegate should throw unimplemented error', - () { - final WebViewPlatform webViewPlatform = ExtendsWebViewPlatform(); - - expect( - () => webViewPlatform.createPlatformCookieManager( - const PlatformWebViewCookieManagerCreationParams()), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of createNavigationCallbackHandlerDelegate should throw unimplemented error', - () { - final WebViewPlatform webViewPlatform = ExtendsWebViewPlatform(); - - expect( - () => webViewPlatform.createPlatformNavigationDelegate( - const PlatformNavigationDelegateCreationParams()), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of createWebViewControllerDelegate should throw unimplemented error', - () { - final WebViewPlatform webViewPlatform = ExtendsWebViewPlatform(); - - expect( - () => webViewPlatform.createPlatformWebViewController( - const PlatformWebViewControllerCreationParams()), - throwsUnimplementedError, - ); - }); - - test( - // ignore: lines_longer_than_80_chars - 'Default implementation of createWebViewWidgetDelegate should throw unimplemented error', - () { - final WebViewPlatform webViewPlatform = ExtendsWebViewPlatform(); - final MockWebViewControllerDelegate controller = - MockWebViewControllerDelegate(); - - expect( - () => webViewPlatform.createPlatformWebViewWidget( - PlatformWebViewWidgetCreationParams(controller: controller)), - throwsUnimplementedError, - ); - }); -} - -class ImplementsWebViewPlatform implements WebViewPlatform { - @override - dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); -} - -class MockWebViewPlatformWithMixin extends MockWebViewPlatform - with - // ignore: prefer_mixin - MockPlatformInterfaceMixin {} - -class ExtendsWebViewPlatform extends WebViewPlatform {} - -class MockWebViewControllerDelegate extends Mock - with - // ignore: prefer_mixin - MockPlatformInterfaceMixin - implements - PlatformWebViewController {} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/webview_platform_test.mocks.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/webview_platform_test.mocks.dart deleted file mode 100644 index d613cddccd54..000000000000 --- a/packages/webview_flutter/webview_flutter_platform_interface/test/webview_platform_test.mocks.dart +++ /dev/null @@ -1,146 +0,0 @@ -// Mocks generated by Mockito 5.3.2 from annotations -// in webview_flutter_platform_interface/test/webview_platform_test.dart. -// Do not manually edit this file. - -// ignore_for_file: no_leading_underscores_for_library_prefixes -import 'package:mockito/mockito.dart' as _i1; -import 'package:webview_flutter_platform_interface/src/platform_navigation_delegate.dart' - as _i3; -import 'package:webview_flutter_platform_interface/src/platform_webview_controller.dart' - as _i4; -import 'package:webview_flutter_platform_interface/src/platform_webview_cookie_manager.dart' - as _i2; -import 'package:webview_flutter_platform_interface/src/platform_webview_widget.dart' - as _i5; -import 'package:webview_flutter_platform_interface/src/types/types.dart' as _i7; -import 'package:webview_flutter_platform_interface/src/webview_platform.dart' - as _i6; - -// ignore_for_file: type=lint -// ignore_for_file: avoid_redundant_argument_values -// ignore_for_file: avoid_setters_without_getters -// ignore_for_file: comment_references -// ignore_for_file: implementation_imports -// ignore_for_file: invalid_use_of_visible_for_testing_member -// ignore_for_file: prefer_const_constructors -// ignore_for_file: unnecessary_parenthesis -// ignore_for_file: camel_case_types -// ignore_for_file: subtype_of_sealed_class - -class _FakePlatformWebViewCookieManager_0 extends _i1.SmartFake - implements _i2.PlatformWebViewCookieManager { - _FakePlatformWebViewCookieManager_0( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakePlatformNavigationDelegate_1 extends _i1.SmartFake - implements _i3.PlatformNavigationDelegate { - _FakePlatformNavigationDelegate_1( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakePlatformWebViewController_2 extends _i1.SmartFake - implements _i4.PlatformWebViewController { - _FakePlatformWebViewController_2( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -class _FakePlatformWebViewWidget_3 extends _i1.SmartFake - implements _i5.PlatformWebViewWidget { - _FakePlatformWebViewWidget_3( - Object parent, - Invocation parentInvocation, - ) : super( - parent, - parentInvocation, - ); -} - -/// A class which mocks [WebViewPlatform]. -/// -/// See the documentation for Mockito's code generation for more information. -class MockWebViewPlatform extends _i1.Mock implements _i6.WebViewPlatform { - MockWebViewPlatform() { - _i1.throwOnMissingStub(this); - } - - @override - _i2.PlatformWebViewCookieManager createPlatformCookieManager( - _i7.PlatformWebViewCookieManagerCreationParams? params) => - (super.noSuchMethod( - Invocation.method( - #createPlatformCookieManager, - [params], - ), - returnValue: _FakePlatformWebViewCookieManager_0( - this, - Invocation.method( - #createPlatformCookieManager, - [params], - ), - ), - ) as _i2.PlatformWebViewCookieManager); - @override - _i3.PlatformNavigationDelegate createPlatformNavigationDelegate( - _i7.PlatformNavigationDelegateCreationParams? params) => - (super.noSuchMethod( - Invocation.method( - #createPlatformNavigationDelegate, - [params], - ), - returnValue: _FakePlatformNavigationDelegate_1( - this, - Invocation.method( - #createPlatformNavigationDelegate, - [params], - ), - ), - ) as _i3.PlatformNavigationDelegate); - @override - _i4.PlatformWebViewController createPlatformWebViewController( - _i7.PlatformWebViewControllerCreationParams? params) => - (super.noSuchMethod( - Invocation.method( - #createPlatformWebViewController, - [params], - ), - returnValue: _FakePlatformWebViewController_2( - this, - Invocation.method( - #createPlatformWebViewController, - [params], - ), - ), - ) as _i4.PlatformWebViewController); - @override - _i5.PlatformWebViewWidget createPlatformWebViewWidget( - _i7.PlatformWebViewWidgetCreationParams? params) => - (super.noSuchMethod( - Invocation.method( - #createPlatformWebViewWidget, - [params], - ), - returnValue: _FakePlatformWebViewWidget_3( - this, - Invocation.method( - #createPlatformWebViewWidget, - [params], - ), - ), - ) as _i5.PlatformWebViewWidget); -} From e42b9ff8c9d6362d0c4f449ef8d39e435164897d Mon Sep 17 00:00:00 2001 From: Maurice Parrish <10687576+bparrishMines@users.noreply.github.com> Date: Thu, 15 Dec 2022 07:47:40 -0500 Subject: [PATCH 5/5] add all back to platform interface --- .../AUTHORS | 67 +++ .../CHANGELOG.md | 94 ++++ .../LICENSE | 25 + .../README.md | 23 + .../javascript_channel_registry.dart | 42 ++ .../platform_interface.dart | 9 + .../webview_cookie_manager.dart | 51 ++ .../platform_interface/webview_platform.dart | 67 +++ .../webview_platform_callbacks_handler.dart | 32 ++ .../webview_platform_controller.dart | 254 ++++++++++ .../types/auto_media_playback_policy.dart | 22 + .../lib/src/legacy/types/creation_params.dart | 71 +++ .../src/legacy/types/javascript_channel.dart | 39 ++ .../src/legacy/types/javascript_message.dart | 14 + .../lib/src/legacy/types/javascript_mode.dart | 12 + .../lib/src/legacy/types/types.dart | 14 + .../src/legacy/types/web_resource_error.dart | 57 +++ .../legacy/types/web_resource_error_type.dart | 66 +++ .../lib/src/legacy/types/web_settings.dart | 132 ++++++ .../lib/src/legacy/types/webview_cookie.dart | 49 ++ .../lib/src/legacy/types/webview_request.dart | 58 +++ .../lib/src/platform_navigation_delegate.dart | 101 ++++ .../lib/src/platform_webview_controller.dart | 272 +++++++++++ .../src/platform_webview_cookie_manager.dart | 55 +++ .../lib/src/platform_webview_widget.dart | 37 ++ .../lib/src/types/javascript_message.dart | 51 ++ .../lib/src/types/javascript_mode.dart | 12 + .../lib/src/types/load_request_params.dart | 93 ++++ .../lib/src/types/navigation_decision.dart | 12 + .../lib/src/types/navigation_request.dart | 18 + ...m_navigation_delegate_creation_params.dart | 44 ++ ...rm_webview_controller_creation_params.dart | 45 ++ ...ebview_cookie_manager_creation_params.dart | 45 ++ ...atform_webview_widget_creation_params.dart | 84 ++++ .../lib/src/types/types.dart | 15 + .../lib/src/types/web_resource_error.dart | 123 +++++ .../lib/src/types/webview_cookie.dart | 41 ++ ...iew_flutter_platform_interface_legacy.dart | 6 + .../lib/src/webview_platform.dart | 82 ++++ .../webview_flutter_platform_interface.dart | 10 + .../pubspec.yaml | 23 + .../javascript_channel_registry_test.dart | 117 +++++ .../webview_cookie_manager_test.dart | 26 + .../legacy/types/javascript_channel_test.dart | 48 ++ .../legacy/types/webview_cookie_test.dart | 21 + .../legacy/types/webview_request_test.dart | 39 ++ .../platform_navigation_delegate_test.dart | 147 ++++++ .../platform_webview_controller_test.dart | 444 ++++++++++++++++++ ...latform_webview_controller_test.mocks.dart | 106 +++++ .../test/platform_webview_widget_test.dart | 94 ++++ .../test/webview_platform_test.dart | 115 +++++ .../test/webview_platform_test.mocks.dart | 146 ++++++ 52 files changed, 3670 insertions(+) create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/AUTHORS create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/CHANGELOG.md create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/LICENSE create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/README.md create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/javascript_channel_registry.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/platform_interface.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_cookie_manager.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform_callbacks_handler.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform_controller.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/auto_media_playback_policy.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/creation_params.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_channel.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_message.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_mode.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/types.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_resource_error.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_resource_error_type.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_settings.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/webview_cookie.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/webview_request.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_navigation_delegate.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_controller.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_cookie_manager.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_widget.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_message.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_mode.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/load_request_params.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_decision.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_request.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_navigation_delegate_creation_params.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_controller_creation_params.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_cookie_manager_creation_params.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_widget_creation_params.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/types.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/web_resource_error.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/webview_cookie.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/webview_flutter_platform_interface_legacy.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/src/webview_platform.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/lib/webview_flutter_platform_interface.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/pubspec.yaml create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/legacy/platform_interface/javascript_channel_registry_test.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/legacy/platform_interface/webview_cookie_manager_test.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/javascript_channel_test.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/webview_cookie_test.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/webview_request_test.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/platform_navigation_delegate_test.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.mocks.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_widget_test.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/webview_platform_test.dart create mode 100644 packages/webview_flutter/webview_flutter_platform_interface/test/webview_platform_test.mocks.dart diff --git a/packages/webview_flutter/webview_flutter_platform_interface/AUTHORS b/packages/webview_flutter/webview_flutter_platform_interface/AUTHORS new file mode 100644 index 000000000000..78f9e5ad9f6b --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/AUTHORS @@ -0,0 +1,67 @@ +# Below is a list of people and organizations that have contributed +# to the Flutter project. Names should be added to the list like so: +# +# Name/Organization + +Google Inc. +The Chromium Authors +German Saprykin +Benjamin Sauer +larsenthomasj@gmail.com +Ali Bitek +Pol Batlló +Anatoly Pulyaevskiy +Hayden Flinner +Stefano Rodriguez +Salvatore Giordano +Brian Armstrong +Paul DeMarco +Fabricio Nogueira +Simon Lightfoot +Ashton Thomas +Thomas Danner +Diego Velásquez +Hajime Nakamura +Tuyển Vũ Xuân +Miguel Ruivo +Sarthak Verma +Mike Diarmid +Invertase +Elliot Hesp +Vince Varga +Aawaz Gyawali +EUI Limited +Katarina Sheremet +Thomas Stockx +Sarbagya Dhaubanjar +Ozkan Eksi +Rishab Nayak +ko2ic +Jonathan Younger +Jose Sanchez +Debkanchan Samadder +Audrius Karosevicius +Lukasz Piliszczuk +SoundReply Solutions GmbH +Rafal Wachol +Pau Picas +Christian Weder +Alexandru Tuca +Christian Weder +Rhodes Davis Jr. +Luigi Agosti +Quentin Le Guennec +Koushik Ravikumar +Nissim Dsilva +Giancarlo Rocha +Ryo Miyake +Théo Champion +Kazuki Yamaguchi +Eitan Schwartz +Chris Rutkowski +Juan Alvarez +Aleksandr Yurkovskiy +Anton Borries +Alex Li +Rahul Raj <64.rahulraj@gmail.com> +Maurits van Beusekom diff --git a/packages/webview_flutter/webview_flutter_platform_interface/CHANGELOG.md b/packages/webview_flutter/webview_flutter_platform_interface/CHANGELOG.md new file mode 100644 index 000000000000..a4be504f3035 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/CHANGELOG.md @@ -0,0 +1,94 @@ +## 2.0.0 + +* **Breaking Change**: Releases new interface. See [documentation](https://pub.dev/documentation/webview_flutter_platform_interface/2.0.0/) and [design doc](https://flutter.dev/go/webview_flutter_4_interface) + for more details. +* **Breaking Change**: Removes MethodChannel implementation of interface. All platform + implementations will now need to create their own by implementing `WebViewPlatform`. + +## 1.9.5 + +* Updates code for `no_leading_underscores_for_local_identifiers` lint. + +## 1.9.4 + +* Updates imports for `prefer_relative_imports`. + +## 1.9.3 + +* Updates minimum Flutter version to 2.10. +* Removes `BuildParams` from v4 interface and adds `layoutDirection` to the creation params. + +## 1.9.2 + +* Fixes avoid_redundant_argument_values lint warnings and minor typos. +* Ignores unnecessary import warnings in preparation for [upcoming Flutter changes](https://github.com/flutter/flutter/pull/106316). +* Adds missing build params for v4 WebViewWidget interface. + +## 1.9.1 + +* Ignores unnecessary import warnings in preparation for [upcoming Flutter changes](https://github.com/flutter/flutter/pull/104231). + +## 1.9.0 + +* Adds the first iteration of the v4 webview_flutter interface implementation. +* Removes unnecessary imports. + +## 1.8.2 + +* Migrates from `ui.hash*` to `Object.hash*`. +* Updates minimum Flutter version to 2.5.0. + +## 1.8.1 + +* Update to use the `verify` method introduced in platform_plugin_interface 2.1.0. + +## 1.8.0 + +* Adds the `loadFlutterAsset` method to the platform interface. + +## 1.7.0 + +* Add an option to set the background color of the webview. + +## 1.6.1 + +* Revert deprecation of `clearCookies` in WebViewPlatform for later deprecation. + +## 1.6.0 + +* Adds platform interface for cookie manager. +* Deprecates `clearCookies` in WebViewPlatform in favour of `CookieManager#clearCookies`. +* Expanded `CreationParams` to include cookies to be set at webview creation. + +## 1.5.2 + +* Mirgrates from analysis_options_legacy.yaml to the more strict analysis_options.yaml. + +## 1.5.1 + +* Reverts the addition of `onUrlChanged`, which was unintentionally a breaking + change. + +## 1.5.0 + +* Added `onUrlChanged` callback to platform callback handler. + +## 1.4.0 + +* Added `loadFile` and `loadHtml` interface methods. + +## 1.3.0 + +* Added `loadRequest` method to platform interface. + +## 1.2.0 + +* Added `runJavascript` and `runJavascriptReturningResult` interface methods to supersede `evaluateJavascript`. + +## 1.1.0 + +* Add `zoomEnabled` functionality to `WebSettings`. + +## 1.0.0 + +* Extracted platform interface from `webview_flutter`. diff --git a/packages/webview_flutter/webview_flutter_platform_interface/LICENSE b/packages/webview_flutter/webview_flutter_platform_interface/LICENSE new file mode 100644 index 000000000000..c6823b81eb84 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/LICENSE @@ -0,0 +1,25 @@ +Copyright 2013 The Flutter Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/webview_flutter/webview_flutter_platform_interface/README.md b/packages/webview_flutter/webview_flutter_platform_interface/README.md new file mode 100644 index 000000000000..10160b3cd132 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/README.md @@ -0,0 +1,23 @@ +# webview_flutter_platform_interface + +A common platform interface for the [`webview_flutter`](https://pub.dev/packages/webview_flutter) plugin. + +This interface allows platform-specific implementations of the `webview_flutter` +plugin, as well as the plugin itself, to ensure they are supporting the +same interface. + +# Usage + +To implement a new platform-specific implementation of `webview_flutter`, extend +[`WebviewPlatform`](lib/src/webview_platform.dart) with an implementation that performs the +platform-specific behavior, and when you register your plugin, set the default +`WebviewPlatform` by calling +`WebviewPlatform.instance = MyPlatformWebview()`. + +# Note on breaking changes + +Strongly prefer non-breaking changes (such as adding a method to the interface) +over breaking changes for this package. + +See https://flutter.dev/go/platform-interface-breaking-changes for a discussion +on why a less-clean interface is preferable to a breaking change. diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/javascript_channel_registry.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/javascript_channel_registry.dart new file mode 100644 index 000000000000..142d8eb00950 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/javascript_channel_registry.dart @@ -0,0 +1,42 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import '../types/javascript_channel.dart'; +import '../types/javascript_message.dart'; + +/// Utility class for managing named JavaScript channels and forwarding incoming +/// messages on the correct channel. +class JavascriptChannelRegistry { + /// Constructs a [JavascriptChannelRegistry] initializing it with the given + /// set of [JavascriptChannel]s. + JavascriptChannelRegistry(Set? channels) { + updateJavascriptChannelsFromSet(channels); + } + + /// Maps a channel name to a channel. + final Map channels = {}; + + /// Invoked when a JavaScript channel message is received. + void onJavascriptChannelMessage(String channel, String message) { + final JavascriptChannel? javascriptChannel = channels[channel]; + + if (javascriptChannel == null) { + throw ArgumentError('No channel registered with name $channel.'); + } + + javascriptChannel.onMessageReceived(JavascriptMessage(message)); + } + + /// Updates the set of [JavascriptChannel]s with the new set. + void updateJavascriptChannelsFromSet(Set? channels) { + this.channels.clear(); + if (channels == null) { + return; + } + + for (final JavascriptChannel channel in channels) { + this.channels[channel.name] = channel; + } + } +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/platform_interface.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/platform_interface.dart new file mode 100644 index 000000000000..a6967a5410f4 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/platform_interface.dart @@ -0,0 +1,9 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +export 'javascript_channel_registry.dart'; +export 'webview_cookie_manager.dart'; +export 'webview_platform.dart'; +export 'webview_platform_callbacks_handler.dart'; +export 'webview_platform_controller.dart'; diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_cookie_manager.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_cookie_manager.dart new file mode 100644 index 000000000000..90dfc2a548b5 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_cookie_manager.dart @@ -0,0 +1,51 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +import '../types/webview_cookie.dart'; + +/// Interface for a platform implementation of a cookie manager. +/// +/// Platform implementations should extend this class rather than implement it as `webview_flutter` +/// does not consider newly added methods to be breaking changes. Extending this class +/// (using `extends`) ensures that the subclass will get the default implementation, while +/// platform implementations that `implements` this interface will be broken by newly added +/// [WebViewCookieManagerPlatform] methods. +abstract class WebViewCookieManagerPlatform extends PlatformInterface { + /// Constructs a WebViewCookieManagerPlatform. + WebViewCookieManagerPlatform() : super(token: _token); + + static final Object _token = Object(); + + static WebViewCookieManagerPlatform? _instance; + + /// The instance of [WebViewCookieManagerPlatform] to use. + static WebViewCookieManagerPlatform? get instance => _instance; + + /// Platform-specific plugins should set this with their own platform-specific + /// class that extends [WebViewCookieManagerPlatform] when they register themselves. + static set instance(WebViewCookieManagerPlatform? instance) { + if (instance == null) { + throw AssertionError( + 'Platform interfaces can only be set to a non-null instance'); + } + PlatformInterface.verify(instance, _token); + _instance = instance; + } + + /// Clears all cookies for all [WebView] instances. + /// + /// Returns true if cookies were present before clearing, else false. + Future clearCookies() { + throw UnimplementedError( + 'clearCookies is not implemented on the current platform'); + } + + /// Sets a cookie for all [WebView] instances. + Future setCookie(WebViewCookie cookie) { + throw UnimplementedError( + 'setCookie is not implemented on the current platform'); + } +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform.dart new file mode 100644 index 000000000000..8d1df6ae1040 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform.dart @@ -0,0 +1,67 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/widgets.dart'; + +import '../platform_interface/javascript_channel_registry.dart'; +import '../types/types.dart'; +import 'webview_platform_callbacks_handler.dart'; +import 'webview_platform_controller.dart'; + +/// Signature for callbacks reporting that a [WebViewPlatformController] was created. +/// +/// See also the `onWebViewPlatformCreated` argument for [WebViewPlatform.build]. +typedef WebViewPlatformCreatedCallback = void Function( + WebViewPlatformController? webViewPlatformController); + +/// Interface for a platform implementation of a WebView. +/// +/// [WebView.platform] controls the builder that is used by [WebView]. +/// [AndroidWebViewPlatform] and [CupertinoWebViewPlatform] are the default implementations +/// for Android and iOS respectively. +abstract class WebViewPlatform { + /// Builds a new WebView. + /// + /// Returns a Widget tree that embeds the created webview. + /// + /// `creationParams` are the initial parameters used to setup the webview. + /// + /// `webViewPlatformHandler` will be used for handling callbacks that are made by the created + /// [WebViewPlatformController]. + /// + /// `onWebViewPlatformCreated` will be invoked after the platform specific [WebViewPlatformController] + /// implementation is created with the [WebViewPlatformController] instance as a parameter. + /// + /// `gestureRecognizers` specifies which gestures should be consumed by the web view. + /// It is possible for other gesture recognizers to be competing with the web view on pointer + /// events, e.g if the web view is inside a [ListView] the [ListView] will want to handle + /// vertical drags. The web view will claim gestures that are recognized by any of the + /// recognizers on this list. + /// When `gestureRecognizers` is empty or null, the web view will only handle pointer events for gestures that + /// were not claimed by any other gesture recognizer. + /// + /// `webViewPlatformHandler` must not be null. + Widget build({ + required BuildContext context, + // TODO(amirh): convert this to be the actual parameters. + // I'm starting without it as the PR is starting to become pretty big. + // I'll followup with the conversion PR. + required CreationParams creationParams, + required WebViewPlatformCallbacksHandler webViewPlatformCallbacksHandler, + required JavascriptChannelRegistry javascriptChannelRegistry, + WebViewPlatformCreatedCallback? onWebViewPlatformCreated, + Set>? gestureRecognizers, + }); + + /// Clears all cookies for all [WebView] instances. + /// + /// Returns true if cookies were present before clearing, else false. + /// Soon to be deprecated. 'Use `WebViewCookieManagerPlatform.clearCookies` instead. + Future clearCookies() { + throw UnimplementedError( + 'WebView clearCookies is not implemented on the current platform'); + } +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform_callbacks_handler.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform_callbacks_handler.dart new file mode 100644 index 000000000000..44dae2ece434 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform_callbacks_handler.dart @@ -0,0 +1,32 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import '../types/types.dart'; + +/// Interface for callbacks made by [WebViewPlatformController]. +/// +/// The webview plugin implements this class, and passes an instance to the [WebViewPlatformController]. +/// [WebViewPlatformController] is notifying this handler on events that happened on the platform's webview. +abstract class WebViewPlatformCallbacksHandler { + /// Invoked by [WebViewPlatformController] when a navigation request is pending. + /// + /// If true is returned the navigation is allowed, otherwise it is blocked. + FutureOr onNavigationRequest( + {required String url, required bool isForMainFrame}); + + /// Invoked by [WebViewPlatformController] when a page has started loading. + void onPageStarted(String url); + + /// Invoked by [WebViewPlatformController] when a page has finished loading. + void onPageFinished(String url); + + /// Invoked by [WebViewPlatformController] when a page is loading. + /// /// Only works when [WebSettings.hasProgressTracking] is set to `true`. + void onProgress(int progress); + + /// Report web resource loading error to the host application. + void onWebResourceError(WebResourceError error); +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform_controller.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform_controller.dart new file mode 100644 index 000000000000..3437fe1f2c09 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/platform_interface/webview_platform_controller.dart @@ -0,0 +1,254 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import '../types/types.dart'; +import 'webview_platform_callbacks_handler.dart'; + +/// Interface for talking to the webview's platform implementation. +/// +/// An instance implementing this interface is passed to the `onWebViewPlatformCreated` callback that is +/// passed to [WebViewPlatformBuilder#onWebViewPlatformCreated]. +/// +/// Platform implementations that live in a separate package should extend this class rather than +/// implement it as webview_flutter does not consider newly added methods to be breaking changes. +/// Extending this class (using `extends`) ensures that the subclass will get the default +/// implementation, while platform implementations that `implements` this interface will be broken +/// by newly added [WebViewPlatformController] methods. +abstract class WebViewPlatformController { + /// Creates a new WebViewPlatform. + /// + /// Callbacks made by the WebView will be delegated to `handler`. + /// + /// The `handler` parameter must not be null. + // TODO(mvanbeusekom): Remove unused constructor parameter with the next + // breaking change (see issue https://github.com/flutter/flutter/issues/94292). + // ignore: avoid_unused_constructor_parameters + WebViewPlatformController(WebViewPlatformCallbacksHandler handler); + + /// Loads the file located on the specified [absoluteFilePath]. + /// + /// The [absoluteFilePath] parameter should contain the absolute path to the + /// file as it is stored on the device. For example: + /// `/Users/username/Documents/www/index.html`. + /// + /// Throws an ArgumentError if the [absoluteFilePath] does not exist. + Future loadFile( + String absoluteFilePath, + ) { + throw UnimplementedError( + 'WebView loadFile is not implemented on the current platform'); + } + + /// Loads the Flutter asset specified in the pubspec.yaml file. + /// + /// Throws an ArgumentError if [key] is not part of the specified assets + /// in the pubspec.yaml file. + Future loadFlutterAsset( + String key, + ) { + throw UnimplementedError( + 'WebView loadFlutterAsset is not implemented on the current platform'); + } + + /// Loads the supplied HTML string. + /// + /// The [baseUrl] parameter is used when resolving relative URLs within the + /// HTML string. + Future loadHtmlString( + String html, { + String? baseUrl, + }) { + throw UnimplementedError( + 'WebView loadHtmlString is not implemented on the current platform'); + } + + /// Loads the specified URL. + /// + /// If `headers` is not null and the URL is an HTTP URL, the key value paris in `headers` will + /// be added as key value pairs of HTTP headers for the request. + /// + /// `url` must not be null. + /// + /// Throws an ArgumentError if `url` is not a valid URL string. + Future loadUrl( + String url, + Map? headers, + ) { + throw UnimplementedError( + 'WebView loadUrl is not implemented on the current platform'); + } + + /// Makes a specific HTTP request ands loads the response in the webview. + /// + /// [WebViewRequest.method] must be one of the supported HTTP methods + /// in [WebViewRequestMethod]. + /// + /// If [WebViewRequest.headers] is not empty, its key-value pairs will be + /// added as the headers for the request. + /// + /// If [WebViewRequest.body] is not null, it will be added as the body + /// for the request. + /// + /// Throws an ArgumentError if [WebViewRequest.uri] has empty scheme. + Future loadRequest( + WebViewRequest request, + ) { + throw UnimplementedError( + 'WebView loadRequest is not implemented on the current platform'); + } + + /// Updates the webview settings. + /// + /// Any non null field in `settings` will be set as the new setting value. + /// All null fields in `settings` are ignored. + Future updateSettings(WebSettings setting) { + throw UnimplementedError( + 'WebView updateSettings is not implemented on the current platform'); + } + + /// Accessor to the current URL that the WebView is displaying. + /// + /// If no URL was ever loaded, returns `null`. + Future currentUrl() { + throw UnimplementedError( + 'WebView currentUrl is not implemented on the current platform'); + } + + /// Checks whether there's a back history item. + Future canGoBack() { + throw UnimplementedError( + 'WebView canGoBack is not implemented on the current platform'); + } + + /// Checks whether there's a forward history item. + Future canGoForward() { + throw UnimplementedError( + 'WebView canGoForward is not implemented on the current platform'); + } + + /// Goes back in the history of this WebView. + /// + /// If there is no back history item this is a no-op. + Future goBack() { + throw UnimplementedError( + 'WebView goBack is not implemented on the current platform'); + } + + /// Goes forward in the history of this WebView. + /// + /// If there is no forward history item this is a no-op. + Future goForward() { + throw UnimplementedError( + 'WebView goForward is not implemented on the current platform'); + } + + /// Reloads the current URL. + Future reload() { + throw UnimplementedError( + 'WebView reload is not implemented on the current platform'); + } + + /// Clears all caches used by the [WebView]. + /// + /// The following caches are cleared: + /// 1. Browser HTTP Cache. + /// 2. [Cache API](https://developers.google.com/web/fundamentals/instant-and-offline/web-storage/cache-api) caches. + /// These are not yet supported in iOS WkWebView. Service workers tend to use this cache. + /// 3. Application cache. + /// 4. Local Storage. + Future clearCache() { + throw UnimplementedError( + 'WebView clearCache is not implemented on the current platform'); + } + + /// Evaluates a JavaScript expression in the context of the current page. + /// + /// The Future completes with an error if a JavaScript error occurred, or if the type of the + /// evaluated expression is not supported (e.g on iOS not all non-primitive types can be evaluated). + Future evaluateJavascript(String javascript) { + throw UnimplementedError( + 'WebView evaluateJavascript is not implemented on the current platform'); + } + + /// Runs the given JavaScript in the context of the current page. + /// + /// The Future completes with an error if a JavaScript error occurred. + Future runJavascript(String javascript) { + throw UnimplementedError( + 'WebView runJavascript is not implemented on the current platform'); + } + + /// Runs the given JavaScript in the context of the current page, and returns the result. + /// + /// The Future completes with an error if a JavaScript error occurred, or if the + /// type the given expression evaluates to is unsupported. Unsupported values include + /// certain non-primitive types on iOS, as well as `undefined` or `null` on iOS 14+. + Future runJavascriptReturningResult(String javascript) { + throw UnimplementedError( + 'WebView runJavascriptReturningResult is not implemented on the current platform'); + } + + /// Adds new JavaScript channels to the set of enabled channels. + /// + /// For each value in this list the platform's webview should make sure that a corresponding + /// property with a postMessage method is set on `window`. For example for a JavaScript channel + /// named `Foo` it should be possible for JavaScript code executing in the webview to do + /// + /// ```javascript + /// Foo.postMessage('hello'); + /// ``` + /// + /// See also: [CreationParams.javascriptChannelNames]. + Future addJavascriptChannels(Set javascriptChannelNames) { + throw UnimplementedError( + 'WebView addJavascriptChannels is not implemented on the current platform'); + } + + /// Removes JavaScript channel names from the set of enabled channels. + /// + /// This disables channels that were previously enabled by [addJavascriptChannels] or through + /// [CreationParams.javascriptChannelNames]. + Future removeJavascriptChannels(Set javascriptChannelNames) { + throw UnimplementedError( + 'WebView removeJavascriptChannels is not implemented on the current platform'); + } + + /// Returns the title of the currently loaded page. + Future getTitle() { + throw UnimplementedError( + 'WebView getTitle is not implemented on the current platform'); + } + + /// Set the scrolled position of this view. + /// + /// The parameters `x` and `y` specify the position to scroll to in WebView pixels. + Future scrollTo(int x, int y) { + throw UnimplementedError( + 'WebView scrollTo is not implemented on the current platform'); + } + + /// Move the scrolled position of this view. + /// + /// The parameters `x` and `y` specify the amount of WebView pixels to scroll by. + Future scrollBy(int x, int y) { + throw UnimplementedError( + 'WebView scrollBy is not implemented on the current platform'); + } + + /// Return the horizontal scroll position of this view. + /// + /// Scroll position is measured from left. + Future getScrollX() { + throw UnimplementedError( + 'WebView getScrollX is not implemented on the current platform'); + } + + /// Return the vertical scroll position of this view. + /// + /// Scroll position is measured from top. + Future getScrollY() { + throw UnimplementedError( + 'WebView getScrollY is not implemented on the current platform'); + } +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/auto_media_playback_policy.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/auto_media_playback_policy.dart new file mode 100644 index 000000000000..7d6927ac7957 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/auto_media_playback_policy.dart @@ -0,0 +1,22 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// Specifies possible restrictions on automatic media playback. +/// +/// This is typically used in [WebView.initialMediaPlaybackPolicy]. +// The method channel implementation is marshalling this enum to the value's index, so the order +// is important. +enum AutoMediaPlaybackPolicy { + /// Starting any kind of media playback requires a user action. + /// + /// For example: JavaScript code cannot start playing media unless the code was executed + /// as a result of a user action (like a touch event). + require_user_action_for_all_media_types, + + /// Starting any kind of media playback is always allowed. + /// + /// For example: JavaScript code that's triggered when the page is loaded can start playing + /// video or audio. + always_allow, +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/creation_params.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/creation_params.dart new file mode 100644 index 000000000000..7c3edf3cf8b0 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/creation_params.dart @@ -0,0 +1,71 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'types.dart'; + +/// Configuration to use when creating a new [WebViewPlatformController]. +/// +/// The `autoMediaPlaybackPolicy` parameter must not be null. +class CreationParams { + /// Constructs an instance to use when creating a new + /// [WebViewPlatformController]. + /// + /// The `autoMediaPlaybackPolicy` parameter must not be null. + CreationParams({ + this.initialUrl, + this.webSettings, + this.javascriptChannelNames = const {}, + this.userAgent, + this.autoMediaPlaybackPolicy = + AutoMediaPlaybackPolicy.require_user_action_for_all_media_types, + this.backgroundColor, + this.cookies = const [], + }) : assert(autoMediaPlaybackPolicy != null); + + /// The initialUrl to load in the webview. + /// + /// When null the webview will be created without loading any page. + final String? initialUrl; + + /// The initial [WebSettings] for the new webview. + /// + /// This can later be updated with [WebViewPlatformController.updateSettings]. + final WebSettings? webSettings; + + /// The initial set of JavaScript channels that are configured for this webview. + /// + /// For each value in this set the platform's webview should make sure that a corresponding + /// property with a postMessage method is set on `window`. For example for a JavaScript channel + /// named `Foo` it should be possible for JavaScript code executing in the webview to do + /// + /// ```javascript + /// Foo.postMessage('hello'); + /// ``` + // TODO(amirh): describe what should happen when postMessage is called once that code is migrated + // to PlatformWebView. + final Set javascriptChannelNames; + + /// The value used for the HTTP User-Agent: request header. + /// + /// When null the platform's webview default is used for the User-Agent header. + final String? userAgent; + + /// Which restrictions apply on automatic media playback. + final AutoMediaPlaybackPolicy autoMediaPlaybackPolicy; + + /// The background color of the webview. + /// + /// When null the platform's webview default background color is used. + final Color? backgroundColor; + + /// The initial set of cookies to set before the webview does its first load. + final List cookies; + + @override + String toString() { + return 'CreationParams(initialUrl: $initialUrl, settings: $webSettings, javascriptChannelNames: $javascriptChannelNames, UserAgent: $userAgent, backgroundColor: $backgroundColor, cookies: $cookies)'; + } +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_channel.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_channel.dart new file mode 100644 index 000000000000..e68cc2ef1291 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_channel.dart @@ -0,0 +1,39 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'javascript_message.dart'; + +/// Callback type for handling messages sent from JavaScript running in a web view. +typedef JavascriptMessageHandler = void Function(JavascriptMessage message); + +final RegExp _validChannelNames = RegExp(r'^[a-zA-Z_][a-zA-Z0-9_]*$'); + +/// A named channel for receiving messaged from JavaScript code running inside a web view. +class JavascriptChannel { + /// Constructs a JavaScript channel. + /// + /// The parameters `name` and `onMessageReceived` must not be null. + JavascriptChannel({ + required this.name, + required this.onMessageReceived, + }) : assert(name != null), + assert(onMessageReceived != null), + assert(_validChannelNames.hasMatch(name)); + + /// The channel's name. + /// + /// Passing this channel object as part of a [WebView.javascriptChannels] adds a channel object to + /// the JavaScript window object's property named `name`. + /// + /// The name must start with a letter or underscore(_), followed by any combination of those + /// characters plus digits. + /// + /// Note that any JavaScript existing `window` property with this name will be overriden. + /// + /// See also [WebView.javascriptChannels] for more details on the channel registration mechanism. + final String name; + + /// A callback that's invoked when a message is received through the channel. + final JavascriptMessageHandler onMessageReceived; +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_message.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_message.dart new file mode 100644 index 000000000000..8d080452c54a --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_message.dart @@ -0,0 +1,14 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// A message that was sent by JavaScript code running in a [WebView]. +class JavascriptMessage { + /// Constructs a JavaScript message object. + /// + /// The `message` parameter must not be null. + const JavascriptMessage(this.message) : assert(message != null); + + /// The contents of the message that was sent by the JavaScript code. + final String message; +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_mode.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_mode.dart new file mode 100644 index 000000000000..53d049175907 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/javascript_mode.dart @@ -0,0 +1,12 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// Describes the state of JavaScript support in a given web view. +enum JavascriptMode { + /// JavaScript execution is disabled. + disabled, + + /// JavaScript execution is not restricted. + unrestricted, +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/types.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/types.dart new file mode 100644 index 000000000000..f2bcf19f42fd --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/types.dart @@ -0,0 +1,14 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +export 'auto_media_playback_policy.dart'; +export 'creation_params.dart'; +export 'javascript_channel.dart'; +export 'javascript_message.dart'; +export 'javascript_mode.dart'; +export 'web_resource_error.dart'; +export 'web_resource_error_type.dart'; +export 'web_settings.dart'; +export 'webview_cookie.dart'; +export 'webview_request.dart'; diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_resource_error.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_resource_error.dart new file mode 100644 index 000000000000..b61671f0ac45 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_resource_error.dart @@ -0,0 +1,57 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'web_resource_error_type.dart'; + +/// Error returned in `WebView.onWebResourceError` when a web resource loading error has occurred. +class WebResourceError { + /// Creates a new [WebResourceError] + /// + /// A user should not need to instantiate this class, but will receive one in + /// [WebResourceErrorCallback]. + WebResourceError({ + required this.errorCode, + required this.description, + this.domain, + this.errorType, + this.failingUrl, + }) : assert(errorCode != null), + assert(description != null); + + /// Raw code of the error from the respective platform. + /// + /// On Android, the error code will be a constant from a + /// [WebViewClient](https://developer.android.com/reference/android/webkit/WebViewClient#summary) and + /// will have a corresponding [errorType]. + /// + /// On iOS, the error code will be a constant from `NSError.code` in + /// Objective-C. See + /// https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/ErrorObjectsDomains/ErrorObjectsDomains.html + /// for more information on error handling on iOS. Some possible error codes + /// can be found at https://developer.apple.com/documentation/webkit/wkerrorcode?language=objc. + final int errorCode; + + /// The domain of where to find the error code. + /// + /// This field is only available on iOS and represents a "domain" from where + /// the [errorCode] is from. This value is taken directly from an `NSError` + /// in Objective-C. See + /// https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/ErrorHandlingCocoa/ErrorObjectsDomains/ErrorObjectsDomains.html + /// for more information on error handling on iOS. + final String? domain; + + /// Description of the error that can be used to communicate the problem to the user. + final String description; + + /// The type this error can be categorized as. + /// + /// This will never be `null` on Android, but can be `null` on iOS. + final WebResourceErrorType? errorType; + + /// Gets the URL for which the resource request was made. + /// + /// This value is not provided on iOS. Alternatively, you can keep track of + /// the last values provided to [WebViewPlatformController.loadUrl]. + final String? failingUrl; +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_resource_error_type.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_resource_error_type.dart new file mode 100644 index 000000000000..a45816df8323 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_resource_error_type.dart @@ -0,0 +1,66 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// Possible error type categorizations used by [WebResourceError]. +enum WebResourceErrorType { + /// User authentication failed on server. + authentication, + + /// Malformed URL. + badUrl, + + /// Failed to connect to the server. + connect, + + /// Failed to perform SSL handshake. + failedSslHandshake, + + /// Generic file error. + file, + + /// File not found. + fileNotFound, + + /// Server or proxy hostname lookup failed. + hostLookup, + + /// Failed to read or write to the server. + io, + + /// User authentication failed on proxy. + proxyAuthentication, + + /// Too many redirects. + redirectLoop, + + /// Connection timed out. + timeout, + + /// Too many requests during this load. + tooManyRequests, + + /// Generic error. + unknown, + + /// Resource load was canceled by Safe Browsing. + unsafeResource, + + /// Unsupported authentication scheme (not basic or digest). + unsupportedAuthScheme, + + /// Unsupported URI scheme. + unsupportedScheme, + + /// The web content process was terminated. + webContentProcessTerminated, + + /// The web view was invalidated. + webViewInvalidated, + + /// A JavaScript exception occurred. + javaScriptExceptionOccurred, + + /// The result of JavaScript execution could not be returned. + javaScriptResultTypeIsUnsupported, +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_settings.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_settings.dart new file mode 100644 index 000000000000..102ab10ccea7 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/web_settings.dart @@ -0,0 +1,132 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; + +import 'javascript_mode.dart'; + +/// A single setting for configuring a WebViewPlatform which may be absent. +@immutable +class WebSetting { + /// Constructs an absent setting instance. + /// + /// The [isPresent] field for the instance will be false. + /// + /// Accessing [value] for an absent instance will throw. + const WebSetting.absent() + : _value = null, + isPresent = false; + + /// Constructs a setting of the given `value`. + /// + /// The [isPresent] field for the instance will be true. + const WebSetting.of(T value) + : _value = value, + isPresent = true; + + final T? _value; + + /// The setting's value. + /// + /// Throws if [WebSetting.isPresent] is false. + T get value { + if (!isPresent) { + throw StateError('Cannot access a value of an absent WebSetting'); + } + assert(isPresent); + // The intention of this getter is to return T whether it is nullable or + // not whereas _value is of type T? since _value can be null even when + // T is not nullable (when isPresent == false). + // + // We promote _value to T using `as T` instead of `!` operator to handle + // the case when _value is legitimately null (and T is a nullable type). + // `!` operator would always throw if _value is null. + return _value as T; + } + + /// True when this web setting instance contains a value. + /// + /// When false the [WebSetting.value] getter throws. + final bool isPresent; + + @override + bool operator ==(Object other) { + if (other.runtimeType != runtimeType) { + return false; + } + + return other is WebSetting && + other.isPresent == isPresent && + other._value == _value; + } + + @override + int get hashCode => Object.hash(_value, isPresent); +} + +/// Settings for configuring a WebViewPlatform. +/// +/// Initial settings are passed as part of [CreationParams], settings updates are sent with +/// [WebViewPlatform#updateSettings]. +/// +/// The `userAgent` parameter must not be null. +class WebSettings { + /// Construct an instance with initial settings. Future setting changes can be + /// sent with [WebviewPlatform#updateSettings]. + /// + /// The `userAgent` parameter must not be null. + WebSettings({ + this.javascriptMode, + this.hasNavigationDelegate, + this.hasProgressTracking, + this.debuggingEnabled, + this.gestureNavigationEnabled, + this.allowsInlineMediaPlayback, + this.zoomEnabled, + required this.userAgent, + }) : assert(userAgent != null); + + /// The JavaScript execution mode to be used by the webview. + final JavascriptMode? javascriptMode; + + /// Whether the [WebView] has a [NavigationDelegate] set. + final bool? hasNavigationDelegate; + + /// Whether the [WebView] should track page loading progress. + /// See also: [WebViewPlatformCallbacksHandler.onProgress] to get the progress. + final bool? hasProgressTracking; + + /// Whether to enable the platform's webview content debugging tools. + /// + /// See also: [WebView.debuggingEnabled]. + final bool? debuggingEnabled; + + /// Whether to play HTML5 videos inline or use the native full-screen controller on iOS. + /// + /// This will have no effect on Android. + final bool? allowsInlineMediaPlayback; + + /// The value used for the HTTP `User-Agent:` request header. + /// + /// If [userAgent.value] is null the platform's default user agent should be used. + /// + /// An absent value ([userAgent.isPresent] is false) represents no change to this setting from the + /// last time it was set. + /// + /// See also [WebView.userAgent]. + final WebSetting userAgent; + + /// Sets whether the WebView should support zooming using its on-screen zoom controls and gestures. + final bool? zoomEnabled; + + /// Whether to allow swipe based navigation in iOS. + /// + /// See also: [WebView.gestureNavigationEnabled] + final bool? gestureNavigationEnabled; + + @override + String toString() { + return 'WebSettings(javascriptMode: $javascriptMode, hasNavigationDelegate: $hasNavigationDelegate, hasProgressTracking: $hasProgressTracking, debuggingEnabled: $debuggingEnabled, gestureNavigationEnabled: $gestureNavigationEnabled, userAgent: $userAgent, allowsInlineMediaPlayback: $allowsInlineMediaPlayback)'; + } +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/webview_cookie.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/webview_cookie.dart new file mode 100644 index 000000000000..406c510afd4b --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/webview_cookie.dart @@ -0,0 +1,49 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// A cookie that can be set globally for all web views +/// using [WebViewCookieManagerPlatform]. +class WebViewCookie { + /// Constructs a new [WebViewCookie]. + const WebViewCookie( + {required this.name, + required this.value, + required this.domain, + this.path = '/'}); + + /// The cookie-name of the cookie. + /// + /// Its value should match "cookie-name" in RFC6265bis: + /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 + final String name; + + /// The cookie-value of the cookie. + /// + /// Its value should match "cookie-value" in RFC6265bis: + /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 + final String value; + + /// The domain-value of the cookie. + /// + /// Its value should match "domain-value" in RFC6265bis: + /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 + final String domain; + + /// The path-value of the cookie. + /// Is set to `/` in the constructor by default. + /// + /// Its value should match "path-value" in RFC6265bis: + /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 + final String path; + + /// Serializes the [WebViewCookie] to a Map. + Map toJson() { + return { + 'name': name, + 'value': value, + 'domain': domain, + 'path': path + }; + } +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/webview_request.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/webview_request.dart new file mode 100644 index 000000000000..940e3a25f4ba --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/legacy/types/webview_request.dart @@ -0,0 +1,58 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:typed_data'; + +/// Defines the supported HTTP methods for loading a page in [WebView]. +enum WebViewRequestMethod { + /// HTTP GET method. + get, + + /// HTTP POST method. + post, +} + +/// Extension methods on the [WebViewRequestMethod] enum. +extension WebViewRequestMethodExtensions on WebViewRequestMethod { + /// Converts [WebViewRequestMethod] to [String] format. + String serialize() { + switch (this) { + case WebViewRequestMethod.get: + return 'get'; + case WebViewRequestMethod.post: + return 'post'; + } + } +} + +/// Defines the parameters that can be used to load a page in the [WebView]. +class WebViewRequest { + /// Creates the [WebViewRequest]. + WebViewRequest({ + required this.uri, + required this.method, + this.headers = const {}, + this.body, + }); + + /// URI for the request. + final Uri uri; + + /// HTTP method used to make the request. + final WebViewRequestMethod method; + + /// Headers for the request. + final Map headers; + + /// HTTP body for the request. + final Uint8List? body; + + /// Serializes the [WebViewRequest] to JSON. + Map toJson() => { + 'uri': uri.toString(), + 'method': method.serialize(), + 'headers': headers, + 'body': body, + }; +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_navigation_delegate.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_navigation_delegate.dart new file mode 100644 index 000000000000..2df6cff73ab5 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_navigation_delegate.dart @@ -0,0 +1,101 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; + +import 'package:flutter/foundation.dart'; +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +import 'webview_platform.dart'; + +/// Signature for callbacks that report a pending navigation request. +typedef NavigationRequestCallback = FutureOr Function( + NavigationRequest navigationRequest); + +/// Signature for callbacks that report page events triggered by the native web view. +typedef PageEventCallback = void Function(String url); + +/// Signature for callbacks that report loading progress of a page. +typedef ProgressCallback = void Function(int progress); + +/// Signature for callbacks that report a resource loading error. +typedef WebResourceErrorCallback = void Function(WebResourceError error); + +/// An interface defining navigation events that occur on the native platform. +/// +/// The [PlatformWebViewController] is notifying this delegate on events that +/// happened on the platform's webview. Platform implementations should +/// implement this class and pass an instance to the [PlatformWebViewController]. +abstract class PlatformNavigationDelegate extends PlatformInterface { + /// Creates a new [PlatformNavigationDelegate] + factory PlatformNavigationDelegate( + PlatformNavigationDelegateCreationParams params) { + final PlatformNavigationDelegate callbackDelegate = + WebViewPlatform.instance!.createPlatformNavigationDelegate(params); + PlatformInterface.verify(callbackDelegate, _token); + return callbackDelegate; + } + + /// Used by the platform implementation to create a new [PlatformNavigationDelegate]. + /// + /// Should only be used by platform implementations because they can't extend + /// a class that only contains a factory constructor. + @protected + PlatformNavigationDelegate.implementation(this.params) : super(token: _token); + + static final Object _token = Object(); + + /// The parameters used to initialize the [PlatformNavigationDelegate]. + final PlatformNavigationDelegateCreationParams params; + + /// Invoked when a navigation request is pending. + /// + /// See [PlatformWebViewController.setPlatformNavigationDelegate]. + Future setOnNavigationRequest( + NavigationRequestCallback onNavigationRequest, + ) { + throw UnimplementedError( + 'setOnNavigationRequest is not implemented on the current platform.'); + } + + /// Invoked when a page has started loading. + /// + /// See [PlatformWebViewController.setPlatformNavigationDelegate]. + Future setOnPageStarted( + PageEventCallback onPageStarted, + ) { + throw UnimplementedError( + 'setOnPageStarted is not implemented on the current platform.'); + } + + /// Invoked when a page has finished loading. + /// + /// See [PlatformWebViewController.setPlatformNavigationDelegate]. + Future setOnPageFinished( + PageEventCallback onPageFinished, + ) { + throw UnimplementedError( + 'setOnPageFinished is not implemented on the current platform.'); + } + + /// Invoked when a page is loading to report the progress. + /// + /// See [PlatformWebViewController.setPlatformNavigationDelegate]. + Future setOnProgress( + ProgressCallback onProgress, + ) { + throw UnimplementedError( + 'setOnProgress is not implemented on the current platform.'); + } + + /// Invoked when a resource loading error occurred. + /// + /// See [PlatformWebViewController.setPlatformNavigationDelegate]. + Future setOnWebResourceError( + WebResourceErrorCallback onWebResourceError, + ) { + throw UnimplementedError( + 'setOnWebResourceError is not implemented on the current platform.'); + } +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_controller.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_controller.dart new file mode 100644 index 000000000000..7bb259c274b1 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_controller.dart @@ -0,0 +1,272 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/painting.dart'; +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +import '../../src/platform_navigation_delegate.dart'; +import 'webview_platform.dart'; + +/// Interface for a platform implementation of a web view controller. +/// +/// Platform implementations should extend this class rather than implement it +/// as `webview_flutter` does not consider newly added methods to be breaking +/// changes. Extending this class (using `extends`) ensures that the subclass +/// will get the default implementation, while platform implementations that +/// `implements` this interface will be broken by newly added +/// [PlatformWebViewCookieManager] methods. +abstract class PlatformWebViewController extends PlatformInterface { + /// Creates a new [PlatformWebViewController] + factory PlatformWebViewController( + PlatformWebViewControllerCreationParams params) { + final PlatformWebViewController webViewControllerDelegate = + WebViewPlatform.instance!.createPlatformWebViewController(params); + PlatformInterface.verify(webViewControllerDelegate, _token); + return webViewControllerDelegate; + } + + /// Used by the platform implementation to create a new [PlatformWebViewController]. + /// + /// Should only be used by platform implementations because they can't extend + /// a class that only contains a factory constructor. + @protected + PlatformWebViewController.implementation(this.params) : super(token: _token); + + static final Object _token = Object(); + + /// The parameters used to initialize the [PlatformWebViewController]. + final PlatformWebViewControllerCreationParams params; + + /// Loads the file located on the specified [absoluteFilePath]. + /// + /// The [absoluteFilePath] parameter should contain the absolute path to the + /// file as it is stored on the device. For example: + /// `/Users/username/Documents/www/index.html`. + /// + /// Throws an ArgumentError if the [absoluteFilePath] does not exist. + Future loadFile( + String absoluteFilePath, + ) { + throw UnimplementedError( + 'loadFile is not implemented on the current platform'); + } + + /// Loads the Flutter asset specified in the pubspec.yaml file. + /// + /// Throws an ArgumentError if [key] is not part of the specified assets + /// in the pubspec.yaml file. + Future loadFlutterAsset( + String key, + ) { + throw UnimplementedError( + 'loadFlutterAsset is not implemented on the current platform'); + } + + /// Loads the supplied HTML string. + /// + /// The [baseUrl] parameter is used when resolving relative URLs within the + /// HTML string. + Future loadHtmlString( + String html, { + String? baseUrl, + }) { + throw UnimplementedError( + 'loadHtmlString is not implemented on the current platform'); + } + + /// Makes a specific HTTP request ands loads the response in the webview. + /// + /// [WebViewRequest.method] must be one of the supported HTTP methods + /// in [WebViewRequestMethod]. + /// + /// If [WebViewRequest.headers] is not empty, its key-value pairs will be + /// added as the headers for the request. + /// + /// If [WebViewRequest.body] is not null, it will be added as the body + /// for the request. + /// + /// Throws an ArgumentError if [WebViewRequest.uri] has empty scheme. + Future loadRequest( + LoadRequestParams params, + ) { + throw UnimplementedError( + 'loadRequest is not implemented on the current platform'); + } + + /// Accessor to the current URL that the WebView is displaying. + /// + /// If no URL was ever loaded, returns `null`. + Future currentUrl() { + throw UnimplementedError( + 'currentUrl is not implemented on the current platform'); + } + + /// Checks whether there's a back history item. + Future canGoBack() { + throw UnimplementedError( + 'canGoBack is not implemented on the current platform'); + } + + /// Checks whether there's a forward history item. + Future canGoForward() { + throw UnimplementedError( + 'canGoForward is not implemented on the current platform'); + } + + /// Goes back in the history of this WebView. + /// + /// If there is no back history item this is a no-op. + Future goBack() { + throw UnimplementedError( + 'goBack is not implemented on the current platform'); + } + + /// Goes forward in the history of this WebView. + /// + /// If there is no forward history item this is a no-op. + Future goForward() { + throw UnimplementedError( + 'goForward is not implemented on the current platform'); + } + + /// Reloads the current URL. + Future reload() { + throw UnimplementedError( + 'reload is not implemented on the current platform'); + } + + /// Clears all caches used by the [WebView]. + /// + /// The following caches are cleared: + /// 1. Browser HTTP Cache. + /// 2. [Cache API](https://developers.google.com/web/fundamentals/instant-and-offline/web-storage/cache-api) caches. + /// These are not yet supported in iOS WkWebView. Service workers tend to use this cache. + /// 3. Application cache. + Future clearCache() { + throw UnimplementedError( + 'clearCache is not implemented on the current platform'); + } + + /// Clears the local storage used by the [WebView]. + Future clearLocalStorage() { + throw UnimplementedError( + 'clearLocalStorage is not implemented on the current platform'); + } + + /// Sets the [PlatformNavigationDelegate] containing the callback methods that + /// are called during navigation events. + Future setPlatformNavigationDelegate( + PlatformNavigationDelegate handler) { + throw UnimplementedError( + 'setPlatformNavigationDelegate is not implemented on the current platform'); + } + + /// Runs the given JavaScript in the context of the current page. + /// + /// The Future completes with an error if a JavaScript error occurred. + Future runJavaScript(String javaScript) { + throw UnimplementedError( + 'runJavaScript is not implemented on the current platform'); + } + + /// Runs the given JavaScript in the context of the current page, and returns the result. + /// + /// The Future completes with an error if a JavaScript error occurred, or if the + /// type the given expression evaluates to is unsupported. Unsupported values include + /// certain non-primitive types on iOS, as well as `undefined` or `null` on iOS 14+. + Future runJavaScriptReturningResult(String javaScript) { + throw UnimplementedError( + 'runJavaScriptReturningResult is not implemented on the current platform'); + } + + /// Adds a new JavaScript channel to the set of enabled channels. + Future addJavaScriptChannel( + JavaScriptChannelParams javaScriptChannelParams, + ) { + throw UnimplementedError( + 'addJavaScriptChannel is not implemented on the current platform'); + } + + /// Removes the JavaScript channel with the matching name from the set of + /// enabled channels. + /// + /// This disables the channel with the matching name if it was previously + /// enabled through the [addJavaScriptChannel]. + Future removeJavaScriptChannel(String javaScriptChannelName) { + throw UnimplementedError( + 'removeJavaScriptChannel is not implemented on the current platform'); + } + + /// Returns the title of the currently loaded page. + Future getTitle() { + throw UnimplementedError( + 'getTitle is not implemented on the current platform'); + } + + /// Set the scrolled position of this view. + /// + /// The parameters `x` and `y` specify the position to scroll to in WebView pixels. + Future scrollTo(int x, int y) { + throw UnimplementedError( + 'scrollTo is not implemented on the current platform'); + } + + /// Move the scrolled position of this view. + /// + /// The parameters `x` and `y` specify the amount of WebView pixels to scroll by. + Future scrollBy(int x, int y) { + throw UnimplementedError( + 'scrollBy is not implemented on the current platform'); + } + + /// Return the current scroll position of this view. + /// + /// Scroll position is measured from the top left. + Future getScrollPosition() { + throw UnimplementedError( + 'getScrollPosition is not implemented on the current platform'); + } + + /// Whether to support zooming using its on-screen zoom controls and gestures. + Future enableZoom(bool enabled) { + throw UnimplementedError( + 'enableZoom is not implemented on the current platform'); + } + + /// Set the current background color of this view. + Future setBackgroundColor(Color color) { + throw UnimplementedError( + 'setBackgroundColor is not implemented on the current platform'); + } + + /// Sets the JavaScript execution mode to be used by the webview. + Future setJavaScriptMode(JavaScriptMode javaScriptMode) { + throw UnimplementedError( + 'setJavaScriptMode is not implemented on the current platform'); + } + + /// Sets the value used for the HTTP `User-Agent:` request header. + Future setUserAgent(String? userAgent) { + throw UnimplementedError( + 'setUserAgent is not implemented on the current platform'); + } +} + +/// Describes the parameters necessary for registering a JavaScript channel. +@immutable +class JavaScriptChannelParams { + /// Creates a new [JavaScriptChannelParams] object. + const JavaScriptChannelParams({ + required this.name, + required this.onMessageReceived, + }); + + /// The name that identifies the JavaScript channel. + final String name; + + /// The callback method that is invoked when a [JavaScriptMessage] is + /// received. + final void Function(JavaScriptMessage) onMessageReceived; +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_cookie_manager.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_cookie_manager.dart new file mode 100644 index 000000000000..9e981c9022c6 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_cookie_manager.dart @@ -0,0 +1,55 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +import 'webview_platform.dart'; + +/// Interface for a platform implementation of a cookie manager. +/// +/// Platform implementations should extend this class rather than implement it +/// as `webview_flutter` does not consider newly added methods to be breaking +/// changes. Extending this class (using `extends`) ensures that the subclass +/// will get the default implementation, while platform implementations that +/// `implements` this interface will be broken by newly added +/// [PlatformWebViewCookieManager] methods. +abstract class PlatformWebViewCookieManager extends PlatformInterface { + /// Creates a new [PlatformWebViewCookieManager] + factory PlatformWebViewCookieManager( + PlatformWebViewCookieManagerCreationParams params) { + final PlatformWebViewCookieManager cookieManagerDelegate = + WebViewPlatform.instance!.createPlatformCookieManager(params); + PlatformInterface.verify(cookieManagerDelegate, _token); + return cookieManagerDelegate; + } + + /// Used by the platform implementation to create a new + /// [PlatformWebViewCookieManager]. + /// + /// Should only be used by platform implementations because they can't extend + /// a class that only contains a factory constructor. + @protected + PlatformWebViewCookieManager.implementation(this.params) + : super(token: _token); + + static final Object _token = Object(); + + /// The parameters used to initialize the [PlatformWebViewCookieManager]. + final PlatformWebViewCookieManagerCreationParams params; + + /// Clears all cookies for all [WebView] instances. + /// + /// Returns true if cookies were present before clearing, else false. + Future clearCookies() { + throw UnimplementedError( + 'clearCookies is not implemented on the current platform'); + } + + /// Sets a cookie for all [WebView] instances. + Future setCookie(WebViewCookie cookie) { + throw UnimplementedError( + 'setCookie is not implemented on the current platform'); + } +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_widget.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_widget.dart new file mode 100644 index 000000000000..40334c650b3a --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/platform_webview_widget.dart @@ -0,0 +1,37 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +import 'webview_platform.dart'; + +/// Interface for a platform implementation of a web view widget. +abstract class PlatformWebViewWidget extends PlatformInterface { + /// Creates a new [PlatformWebViewWidget] + factory PlatformWebViewWidget(PlatformWebViewWidgetCreationParams params) { + final PlatformWebViewWidget webViewWidgetDelegate = + WebViewPlatform.instance!.createPlatformWebViewWidget(params); + PlatformInterface.verify(webViewWidgetDelegate, _token); + return webViewWidgetDelegate; + } + + /// Used by the platform implementation to create a new + /// [PlatformWebViewWidget]. + /// + /// Should only be used by platform implementations because they can't extend + /// a class that only contains a factory constructor. + @protected + PlatformWebViewWidget.implementation(this.params) : super(token: _token); + + static final Object _token = Object(); + + /// The parameters used to initialize the [PlatformWebViewWidget]. + final PlatformWebViewWidgetCreationParams params; + + /// Builds a new WebView. + /// + /// Returns a Widget tree that embeds the created web view. + Widget build(BuildContext context); +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_message.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_message.dart new file mode 100644 index 000000000000..b37661a045a9 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_message.dart @@ -0,0 +1,51 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +/// A message that was sent by JavaScript code running in a [WebView]. +/// +/// Platform specific implementations can add additional fields by extending +/// this class and providing a factory method that takes the +/// [JavaScriptMessage] as a parameter. +/// +/// {@tool sample} +/// This example demonstrates how to extend the [JavaScriptMessage] to +/// provide additional platform specific parameters. +/// +/// When extending [JavaScriptMessage] additional parameters should always +/// accept `null` or have a default value to prevent breaking changes. +/// +/// ```dart +/// @immutable +/// class WKWebViewScriptMessage extends JavaScriptMessage { +/// WKWebViewScriptMessage._( +/// JavaScriptMessage javaScriptMessage, +/// this.extraData, +/// ) : super(javaScriptMessage.message); +/// +/// factory WKWebViewScriptMessage.fromJavaScripMessage( +/// JavaScriptMessage javaScripMessage, { +/// String? extraData, +/// }) { +/// return WKWebViewScriptMessage._( +/// javaScriptMessage, +/// extraData: extraData, +/// ); +/// } +/// +/// final String? extraData; +/// } +/// ``` +/// {@end-tool} +@immutable +class JavaScriptMessage { + /// Creates a new JavaScript message object. + const JavaScriptMessage({ + required this.message, + }); + + /// The contents of the message that was sent by the JavaScript code. + final String message; +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_mode.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_mode.dart new file mode 100644 index 000000000000..bcbebff8bb1a --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/javascript_mode.dart @@ -0,0 +1,12 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// Describes the state of JavaScript support in a given web view. +enum JavaScriptMode { + /// JavaScript execution is disabled. + disabled, + + /// JavaScript execution is not restricted. + unrestricted, +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/load_request_params.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/load_request_params.dart new file mode 100644 index 000000000000..ad934d6747b7 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/load_request_params.dart @@ -0,0 +1,93 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// TODO(a14n): remove this import once Flutter 3.1 or later reaches stable (including flutter/flutter#104231) +// ignore: unnecessary_import +import 'dart:typed_data'; + +import 'package:flutter/foundation.dart'; + +import '../platform_webview_controller.dart'; + +/// Defines the supported HTTP methods for loading a page in [PlatformWebViewController]. +enum LoadRequestMethod { + /// HTTP GET method. + get, + + /// HTTP POST method. + post, +} + +/// Extension methods on the [LoadRequestMethod] enum. +extension LoadRequestMethodExtensions on LoadRequestMethod { + /// Converts [LoadRequestMethod] to [String] format. + String serialize() { + switch (this) { + case LoadRequestMethod.get: + return 'get'; + case LoadRequestMethod.post: + return 'post'; + } + } +} + +/// Defines the parameters that can be used to load a page with the [PlatformWebViewController]. +/// +/// Platform specific implementations can add additional fields by extending +/// this class. +/// +/// {@tool sample} +/// This example demonstrates how to extend the [LoadRequestParams] to +/// provide additional platform specific parameters. +/// +/// When extending [LoadRequestParams] additional parameters should always +/// accept `null` or have a default value to prevent breaking changes. +/// +/// ```dart +/// class AndroidLoadRequestParams extends LoadRequestParams { +/// AndroidLoadRequestParams._({ +/// required LoadRequestParams params, +/// this.historyUrl, +/// }) : super( +/// uri: params.uri, +/// method: params.method, +/// body: params.body, +/// headers: params.headers, +/// ); +/// +/// factory AndroidLoadRequestParams.fromLoadRequestParams( +/// LoadRequestParams params, { +/// Uri? historyUrl, +/// }) { +/// return AndroidLoadRequestParams._(params, historyUrl: historyUrl); +/// } +/// +/// final Uri? historyUrl; +/// } +/// ``` +/// {@end-tool} +@immutable +class LoadRequestParams { + /// Used by the platform implementation to create a new [LoadRequestParams]. + const LoadRequestParams({ + required this.uri, + this.method = LoadRequestMethod.get, + this.headers = const {}, + this.body, + }); + + /// URI for the request. + final Uri uri; + + /// HTTP method used to make the request. + /// + /// Defaults to [LoadRequestMethod.get]. + final LoadRequestMethod method; + + /// Headers for the request. + final Map headers; + + /// HTTP body for the request. + final Uint8List? body; +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_decision.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_decision.dart new file mode 100644 index 000000000000..d8178acd8096 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_decision.dart @@ -0,0 +1,12 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// A decision on how to handle a navigation request. +enum NavigationDecision { + /// Prevent the navigation from taking place. + prevent, + + /// Allow the navigation to take place. + navigate, +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_request.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_request.dart new file mode 100644 index 000000000000..ee3f1f910f9d --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/navigation_request.dart @@ -0,0 +1,18 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +/// Defines the parameters of the pending navigation callback. +class NavigationRequest { + /// Creates a [NavigationRequest]. + const NavigationRequest({ + required this.url, + required this.isMainFrame, + }); + + /// The URL of the pending navigation request. + final String url; + + /// Indicates whether the request was made in the web site's main frame or a subframe. + final bool isMainFrame; +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_navigation_delegate_creation_params.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_navigation_delegate_creation_params.dart new file mode 100644 index 000000000000..b20e5eb3ed48 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_navigation_delegate_creation_params.dart @@ -0,0 +1,44 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; + +/// Object specifying creation parameters for creating a [PlatformNavigationDelegate]. +/// +/// Platform specific implementations can add additional fields by extending +/// this class. +/// +/// {@tool sample} +/// This example demonstrates how to extend the [PlatformNavigationDelegateCreationParams] to +/// provide additional platform specific parameters. +/// +/// When extending [PlatformNavigationDelegateCreationParams] additional +/// parameters should always accept `null` or have a default value to prevent +/// breaking changes. +/// +/// ```dart +/// class AndroidNavigationDelegateCreationParams extends PlatformNavigationDelegateCreationParams { +/// AndroidNavigationDelegateCreationParams._( +/// // This parameter prevents breaking changes later. +/// // ignore: avoid_unused_constructor_parameters +/// PlatformNavigationDelegateCreationParams params, { +/// this.filter, +/// }) : super(); +/// +/// factory AndroidNavigationDelegateCreationParams.fromPlatformNavigationDelegateCreationParams( +/// PlatformNavigationDelegateCreationParams params, { +/// String? filter, +/// }) { +/// return AndroidNavigationDelegateCreationParams._(params, filter: filter); +/// } +/// +/// final String? filter; +/// } +/// ``` +/// {@end-tool} +@immutable +class PlatformNavigationDelegateCreationParams { + /// Used by the platform implementation to create a new [PlatformNavigationkDelegate]. + const PlatformNavigationDelegateCreationParams(); +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_controller_creation_params.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_controller_creation_params.dart new file mode 100644 index 000000000000..778396a79845 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_controller_creation_params.dart @@ -0,0 +1,45 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; + +/// Object specifying creation parameters for creating a [PlatformWebViewController]. +/// +/// Platform specific implementations can add additional fields by extending +/// this class. +/// +/// {@tool sample} +/// This example demonstrates how to extend the [PlatformWebViewControllerCreationParams] to +/// provide additional platform specific parameters. +/// +/// When extending [PlatformWebViewControllerCreationParams] additional parameters +/// should always accept `null` or have a default value to prevent breaking +/// changes. +/// +/// ```dart +/// class WKWebViewControllerCreationParams +/// extends PlatformWebViewControllerCreationParams { +/// WKWebViewControllerCreationParams._( +/// // This parameter prevents breaking changes later. +/// // ignore: avoid_unused_constructor_parameters +/// PlatformWebViewControllerCreationParams params, { +/// this.domain, +/// }) : super(); +/// +/// factory WKWebViewControllerCreationParams.fromPlatformWebViewControllerCreationParams( +/// PlatformWebViewControllerCreationParams params, { +/// String? domain, +/// }) { +/// return WKWebViewControllerCreationParams._(params, domain: domain); +/// } +/// +/// final String? domain; +/// } +/// ``` +/// {@end-tool} +@immutable +class PlatformWebViewControllerCreationParams { + /// Used by the platform implementation to create a new [PlatformWebViewController]. + const PlatformWebViewControllerCreationParams(); +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_cookie_manager_creation_params.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_cookie_manager_creation_params.dart new file mode 100644 index 000000000000..e8c4938f649f --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_cookie_manager_creation_params.dart @@ -0,0 +1,45 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; + +/// Object specifying creation parameters for creating a [PlatformWebViewCookieManager]. +/// +/// Platform specific implementations can add additional fields by extending +/// this class. +/// +/// {@tool sample} +/// This example demonstrates how to extend the [PlatformWebViewCookieManagerCreationParams] to +/// provide additional platform specific parameters. +/// +/// When extending [PlatformWebViewCookieManagerCreationParams] additional +/// parameters should always accept `null` or have a default value to prevent +/// breaking changes. +/// +/// ```dart +/// class WKWebViewCookieManagerCreationParams +/// extends PlatformWebViewCookieManagerCreationParams { +/// WKWebViewCookieManagerCreationParams._( +/// // This parameter prevents breaking changes later. +/// // ignore: avoid_unused_constructor_parameters +/// PlatformWebViewCookieManagerCreationParams params, { +/// this.uri, +/// }) : super(); +/// +/// factory WKWebViewCookieManagerCreationParams.fromPlatformWebViewCookieManagerCreationParams( +/// PlatformWebViewCookieManagerCreationParams params, { +/// Uri? uri, +/// }) { +/// return WKWebViewCookieManagerCreationParams._(params, uri: uri); +/// } +/// +/// final Uri? uri; +/// } +/// ``` +/// {@end-tool} +@immutable +class PlatformWebViewCookieManagerCreationParams { + /// Used by the platform implementation to create a new [PlatformWebViewCookieManagerDelegate]. + const PlatformWebViewCookieManagerCreationParams(); +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_widget_creation_params.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_widget_creation_params.dart new file mode 100644 index 000000000000..83a73c2a44a3 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/platform_webview_widget_creation_params.dart @@ -0,0 +1,84 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; +import 'package:flutter/gestures.dart'; +import 'package:flutter/painting.dart'; + +import '../platform_webview_controller.dart'; + +/// Object specifying creation parameters for creating a [WebViewWidgetDelegate]. +/// +/// Platform specific implementations can add additional fields by extending +/// this class. +/// +/// {@tool sample} +/// This example demonstrates how to extend the [PlatformWebViewWidgetCreationParams] to +/// provide additional platform specific parameters. +/// +/// When extending [PlatformWebViewWidgetCreationParams] additional parameters +/// should always accept `null` or have a default value to prevent breaking +/// changes. +/// +/// ```dart +/// class AndroidWebViewWidgetCreationParams +/// extends PlatformWebViewWidgetCreationParams { +/// AndroidWebViewWidgetCreationParams({ +/// super.key, +/// super.layoutDirection, +/// super.gestureRecognizers, +/// this.platformSpecificFieldExample, +/// }); +/// +/// WKWebViewWidgetCreationParams.fromPlatformWebViewWidgetCreationParams( +/// PlatformWebViewWidgetCreationParams params, { +/// Object? platformSpecificFieldExample, +/// }) : this( +/// key: params.key, +/// layoutDirection: params.layoutDirection, +/// gestureRecognizers: params.gestureRecognizers, +/// platformSpecificFieldExample: platformSpecificFieldExample, +/// ); +/// +/// final Object? platformSpecificFieldExample; +/// } +/// ``` +/// {@end-tool} +@immutable +class PlatformWebViewWidgetCreationParams { + /// Used by the platform implementation to create a new [PlatformWebViewWidget]. + const PlatformWebViewWidgetCreationParams({ + this.key, + required this.controller, + this.layoutDirection = TextDirection.ltr, + this.gestureRecognizers = const >{}, + }); + + /// Controls how one widget replaces another widget in the tree. + /// + /// See also: + /// + /// * The discussions at [Key] and [GlobalKey]. + final Key? key; + + /// The [PlatformWebViewController] that allows controlling the native web + /// view. + final PlatformWebViewController controller; + + /// The layout direction to use for the embedded WebView. + final TextDirection layoutDirection; + + /// The `gestureRecognizers` specifies which gestures should be consumed by the + /// web view. + /// + /// It is possible for other gesture recognizers to be competing with the web + /// view on pointer events, e.g if the web view is inside a [ListView] the + /// [ListView] will want to handle vertical drags. The web view will claim + /// gestures that are recognized by any of the recognizers on this list. + /// + /// When `gestureRecognizers` is empty (default), the web view will only handle + /// pointer events for gestures that were not claimed by any other gesture + /// recognizer. + final Set> gestureRecognizers; +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/types.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/types.dart new file mode 100644 index 000000000000..4df8800c83e1 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/types.dart @@ -0,0 +1,15 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +export 'javascript_message.dart'; +export 'javascript_mode.dart'; +export 'load_request_params.dart'; +export 'navigation_decision.dart'; +export 'navigation_request.dart'; +export 'platform_navigation_delegate_creation_params.dart'; +export 'platform_webview_controller_creation_params.dart'; +export 'platform_webview_cookie_manager_creation_params.dart'; +export 'platform_webview_widget_creation_params.dart'; +export 'web_resource_error.dart'; +export 'webview_cookie.dart'; diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/web_resource_error.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/web_resource_error.dart new file mode 100644 index 000000000000..e2522da859f7 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/web_resource_error.dart @@ -0,0 +1,123 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +/// Possible error type categorizations used by [WebResourceError]. +enum WebResourceErrorType { + /// User authentication failed on server. + authentication, + + /// Malformed URL. + badUrl, + + /// Failed to connect to the server. + connect, + + /// Failed to perform SSL handshake. + failedSslHandshake, + + /// Generic file error. + file, + + /// File not found. + fileNotFound, + + /// Server or proxy hostname lookup failed. + hostLookup, + + /// Failed to read or write to the server. + io, + + /// User authentication failed on proxy. + proxyAuthentication, + + /// Too many redirects. + redirectLoop, + + /// Connection timed out. + timeout, + + /// Too many requests during this load. + tooManyRequests, + + /// Generic error. + unknown, + + /// Resource load was canceled by Safe Browsing. + unsafeResource, + + /// Unsupported authentication scheme (not basic or digest). + unsupportedAuthScheme, + + /// Unsupported URI scheme. + unsupportedScheme, + + /// The web content process was terminated. + webContentProcessTerminated, + + /// The web view was invalidated. + webViewInvalidated, + + /// A JavaScript exception occurred. + javaScriptExceptionOccurred, + + /// The result of JavaScript execution could not be returned. + javaScriptResultTypeIsUnsupported, +} + +/// Error returned in `WebView.onWebResourceError` when a web resource loading error has occurred. +/// +/// Platform specific implementations can add additional fields by extending +/// this class. +/// +/// {@tool sample} +/// This example demonstrates how to extend the [WebResourceError] to +/// provide additional platform specific parameters. +/// +/// When extending [WebResourceError] additional parameters should always +/// accept `null` or have a default value to prevent breaking changes. +/// +/// ```dart +/// class IOSWebResourceError extends WebResourceError { +/// IOSWebResourceError._(WebResourceError error, {required this.domain}) +/// : super( +/// errorCode: error.errorCode, +/// description: error.description, +/// errorType: error.errorType, +/// ); +/// +/// factory IOSWebResourceError.fromWebResourceError( +/// WebResourceError error, { +/// required String? domain, +/// }) { +/// return IOSWebResourceError._(error, domain: domain); +/// } +/// +/// final String? domain; +/// } +/// ``` +/// {@end-tool} +@immutable +class WebResourceError { + /// Used by the platform implementation to create a new [WebResourceError]. + const WebResourceError({ + required this.errorCode, + required this.description, + this.errorType, + this.isForMainFrame, + }); + + /// Raw code of the error from the respective platform. + final int errorCode; + + /// Description of the error that can be used to communicate the problem to the user. + final String description; + + /// The type this error can be categorized as. + final WebResourceErrorType? errorType; + + /// Whether the error originated from the main frame. + final bool? isForMainFrame; +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/webview_cookie.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/webview_cookie.dart new file mode 100644 index 000000000000..7f56a312049f --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/types/webview_cookie.dart @@ -0,0 +1,41 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/foundation.dart'; + +/// A cookie that can be set globally for all web views using [WebViewCookieManagerPlatform]. +@immutable +class WebViewCookie { + /// Creates a new [WebViewCookieDelegate] + const WebViewCookie({ + required this.name, + required this.value, + required this.domain, + this.path = '/', + }); + + /// The cookie-name of the cookie. + /// + /// Its value should match "cookie-name" in RFC6265bis: + /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 + final String name; + + /// The cookie-value of the cookie. + /// + /// Its value should match "cookie-value" in RFC6265bis: + /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 + final String value; + + /// The domain-value of the cookie. + /// + /// Its value should match "domain-value" in RFC6265bis: + /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 + final String domain; + + /// The path-value of the cookie, set to `/` by default. + /// + /// Its value should match "path-value" in RFC6265bis: + /// https://datatracker.ietf.org/doc/html/draft-ietf-httpbis-rfc6265bis-02#section-4.1.1 + final String path; +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/webview_flutter_platform_interface_legacy.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/webview_flutter_platform_interface_legacy.dart new file mode 100644 index 000000000000..1964e7089d2d --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/webview_flutter_platform_interface_legacy.dart @@ -0,0 +1,6 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +export 'legacy/platform_interface/platform_interface.dart'; +export 'legacy/types/types.dart'; diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/src/webview_platform.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/webview_platform.dart new file mode 100644 index 000000000000..e91396243ea5 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/src/webview_platform.dart @@ -0,0 +1,82 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +import '../../src/platform_navigation_delegate.dart'; +import 'platform_webview_controller.dart'; +import 'platform_webview_cookie_manager.dart'; +import 'platform_webview_widget.dart'; +import 'types/types.dart'; + +export 'types/types.dart'; + +/// Interface for a platform implementation of a WebView. +abstract class WebViewPlatform extends PlatformInterface { + /// Creates a new [WebViewPlatform]. + WebViewPlatform() : super(token: _token); + + static final Object _token = Object(); + + static WebViewPlatform? _instance; + + /// The instance of [WebViewPlatform] to use. + static WebViewPlatform? get instance => _instance; + + /// Platform-specific plugins should set this with their own platform-specific + /// class that extends [WebViewPlatform] when they register themselves. + static set instance(WebViewPlatform? instance) { + if (instance == null) { + throw AssertionError( + 'Platform interfaces can only be set to a non-null instance'); + } + + PlatformInterface.verify(instance, _token); + _instance = instance; + } + + /// Creates a new [PlatformWebViewCookieManager]. + /// + /// This function should only be called by the app-facing package. + /// Look at using [WebViewCookieManager] in `webview_flutter` instead. + PlatformWebViewCookieManager createPlatformCookieManager( + PlatformWebViewCookieManagerCreationParams params, + ) { + throw UnimplementedError( + 'createPlatformCookieManager is not implemented on the current platform.'); + } + + /// Creates a new [PlatformNavigationDelegate]. + /// + /// This function should only be called by the app-facing package. + /// Look at using [NavigationDelegate] in `webview_flutter` instead. + PlatformNavigationDelegate createPlatformNavigationDelegate( + PlatformNavigationDelegateCreationParams params, + ) { + throw UnimplementedError( + 'createPlatformNavigationDelegate is not implemented on the current platform.'); + } + + /// Create a new [PlatformWebViewController]. + /// + /// This function should only be called by the app-facing package. + /// Look at using [WebViewController] in `webview_flutter` instead. + PlatformWebViewController createPlatformWebViewController( + PlatformWebViewControllerCreationParams params, + ) { + throw UnimplementedError( + 'createPlatformWebViewController is not implemented on the current platform.'); + } + + /// Create a new [PlatformWebViewWidget]. + /// + /// This function should only be called by the app-facing package. + /// Look at using [WebViewWidget] in `webview_flutter` instead. + PlatformWebViewWidget createPlatformWebViewWidget( + PlatformWebViewWidgetCreationParams params, + ) { + throw UnimplementedError( + 'createPlatformWebViewWidget is not implemented on the current platform.'); + } +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/lib/webview_flutter_platform_interface.dart b/packages/webview_flutter/webview_flutter_platform_interface/lib/webview_flutter_platform_interface.dart new file mode 100644 index 000000000000..d14fec163327 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/lib/webview_flutter_platform_interface.dart @@ -0,0 +1,10 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +export 'src/platform_navigation_delegate.dart'; +export 'src/platform_webview_controller.dart'; +export 'src/platform_webview_cookie_manager.dart'; +export 'src/platform_webview_widget.dart'; +export 'src/types/types.dart'; +export 'src/webview_platform.dart'; diff --git a/packages/webview_flutter/webview_flutter_platform_interface/pubspec.yaml b/packages/webview_flutter/webview_flutter_platform_interface/pubspec.yaml new file mode 100644 index 000000000000..3ba7a567398e --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/pubspec.yaml @@ -0,0 +1,23 @@ +name: webview_flutter_platform_interface +description: A common platform interface for the webview_flutter plugin. +repository: https://github.com/flutter/plugins/tree/main/packages/webview_flutter/webview_flutter_platform_interface +issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+webview_flutter%22 +# NOTE: We strongly prefer non-breaking changes, even at the expense of a +# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes +version: 2.0.0 + +environment: + sdk: ">=2.12.0 <3.0.0" + flutter: ">=2.10.0" + +dependencies: + flutter: + sdk: flutter + meta: ^1.7.0 + plugin_platform_interface: ^2.1.0 + +dev_dependencies: + build_runner: ^2.1.8 + flutter_test: + sdk: flutter + mockito: ^5.0.0 diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/platform_interface/javascript_channel_registry_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/platform_interface/javascript_channel_registry_test.dart new file mode 100644 index 000000000000..c9d27c601985 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/platform_interface/javascript_channel_registry_test.dart @@ -0,0 +1,117 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter_test/flutter_test.dart'; +import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; + +void main() { + final Map log = {}; + final Set channels = { + JavascriptChannel( + name: 'js_channel_1', + onMessageReceived: (JavascriptMessage message) => + log['js_channel_1'] = message.message, + ), + JavascriptChannel( + name: 'js_channel_2', + onMessageReceived: (JavascriptMessage message) => + log['js_channel_2'] = message.message, + ), + JavascriptChannel( + name: 'js_channel_3', + onMessageReceived: (JavascriptMessage message) => + log['js_channel_3'] = message.message, + ), + }; + + tearDown(() { + log.clear(); + }); + + test('ctor should initialize with channels.', () { + final JavascriptChannelRegistry registry = + JavascriptChannelRegistry(channels); + + expect(registry.channels.length, 3); + for (final JavascriptChannel channel in channels) { + expect(registry.channels[channel.name], channel); + } + }); + + test('onJavascriptChannelMessage should forward message on correct channel.', + () { + final JavascriptChannelRegistry registry = + JavascriptChannelRegistry(channels); + + registry.onJavascriptChannelMessage( + 'js_channel_2', + 'test message on channel 2', + ); + + expect( + log, + containsPair( + 'js_channel_2', + 'test message on channel 2', + )); + }); + + test( + 'onJavascriptChannelMessage should throw ArgumentError when message arrives on non-existing channel.', + () { + final JavascriptChannelRegistry registry = + JavascriptChannelRegistry(channels); + + expect( + () => registry.onJavascriptChannelMessage( + 'js_channel_4', + 'test message on channel 2', + ), + throwsA( + isA().having((ArgumentError error) => error.message, + 'message', 'No channel registered with name js_channel_4.'), + )); + }); + + test( + 'updateJavascriptChannelsFromSet should clear all channels when null is supplied.', + () { + final JavascriptChannelRegistry registry = + JavascriptChannelRegistry(channels); + + expect(registry.channels.length, 3); + + registry.updateJavascriptChannelsFromSet(null); + + expect(registry.channels, isEmpty); + }); + + test('updateJavascriptChannelsFromSet should update registry with new set.', + () { + final JavascriptChannelRegistry registry = + JavascriptChannelRegistry(channels); + + expect(registry.channels.length, 3); + + final Set newChannels = { + JavascriptChannel( + name: 'new_js_channel_1', + onMessageReceived: (JavascriptMessage message) => + log['new_js_channel_1'] = message.message, + ), + JavascriptChannel( + name: 'new_js_channel_2', + onMessageReceived: (JavascriptMessage message) => + log['new_js_channel_2'] = message.message, + ), + }; + + registry.updateJavascriptChannelsFromSet(newChannels); + + expect(registry.channels.length, 2); + for (final JavascriptChannel channel in newChannels) { + expect(registry.channels[channel.name], channel); + } + }); +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/platform_interface/webview_cookie_manager_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/platform_interface/webview_cookie_manager_test.dart new file mode 100644 index 000000000000..a9faea52e407 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/platform_interface/webview_cookie_manager_test.dart @@ -0,0 +1,26 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter_test/flutter_test.dart'; +import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; + +void main() { + WebViewCookieManagerPlatform? cookieManager; + + setUp(() { + cookieManager = TestWebViewCookieManagerPlatform(); + }); + + test('clearCookies should throw UnimplementedError', () { + expect(() => cookieManager!.clearCookies(), throwsUnimplementedError); + }); + + test('setCookie should throw UnimplementedError', () { + const WebViewCookie cookie = + WebViewCookie(domain: 'flutter.dev', name: 'foo', value: 'bar'); + expect(() => cookieManager!.setCookie(cookie), throwsUnimplementedError); + }); +} + +class TestWebViewCookieManagerPlatform extends WebViewCookieManagerPlatform {} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/javascript_channel_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/javascript_channel_test.dart new file mode 100644 index 000000000000..ecb9c3fbed10 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/javascript_channel_test.dart @@ -0,0 +1,48 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter_test/flutter_test.dart'; +import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; + +void main() { + final List validChars = + 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_'.split(''); + final List commonInvalidChars = + r'`~!@#$%^&*()-=+[]{}\|"' ':;/?<>,. '.split(''); + final List digits = List.generate(10, (int index) => index++); + + test( + 'ctor should create JavascriptChannel when name starts with a valid character followed by a number.', + () { + for (final String char in validChars) { + for (final int digit in digits) { + final JavascriptChannel channel = + JavascriptChannel(name: '$char$digit', onMessageReceived: (_) {}); + + expect(channel.name, '$char$digit'); + } + } + }); + + test('ctor should assert when channel name starts with a number.', () { + for (final int i in digits) { + expect( + () => JavascriptChannel(name: '$i', onMessageReceived: (_) {}), + throwsAssertionError, + ); + } + }); + + test('ctor should assert when channel contains invalid char.', () { + for (final String validChar in validChars) { + for (final String invalidChar in commonInvalidChars) { + expect( + () => JavascriptChannel( + name: validChar + invalidChar, onMessageReceived: (_) {}), + throwsAssertionError, + ); + } + } + }); +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/webview_cookie_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/webview_cookie_test.dart new file mode 100644 index 000000000000..f1702f4ad1c0 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/webview_cookie_test.dart @@ -0,0 +1,21 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter_test/flutter_test.dart'; +import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; + +void main() { + test('WebViewCookie should serialize correctly', () { + WebViewCookie cookie; + Map serializedCookie; + // Test serialization + cookie = const WebViewCookie( + name: 'foo', value: 'bar', domain: 'example.com', path: '/test'); + serializedCookie = cookie.toJson(); + expect(serializedCookie['name'], 'foo'); + expect(serializedCookie['value'], 'bar'); + expect(serializedCookie['domain'], 'example.com'); + expect(serializedCookie['path'], '/test'); + }); +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/webview_request_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/webview_request_test.dart new file mode 100644 index 000000000000..fff1a9b19878 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/legacy/types/webview_request_test.dart @@ -0,0 +1,39 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:typed_data'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:webview_flutter_platform_interface/src/webview_flutter_platform_interface_legacy.dart'; + +void main() { + test('WebViewRequestMethod should serialize correctly', () { + expect(WebViewRequestMethod.get.serialize(), 'get'); + expect(WebViewRequestMethod.post.serialize(), 'post'); + }); + + test('WebViewRequest should serialize correctly', () { + WebViewRequest request; + Map serializedRequest; + // Test serialization without headers or a body + request = WebViewRequest( + uri: Uri.parse('https://flutter.dev'), + method: WebViewRequestMethod.get, + ); + serializedRequest = request.toJson(); + expect(serializedRequest['uri'], 'https://flutter.dev'); + expect(serializedRequest['method'], 'get'); + expect(serializedRequest['headers'], {}); + expect(serializedRequest['body'], null); + // Test serialization of headers and body + request = WebViewRequest( + uri: Uri.parse('https://flutter.dev'), + method: WebViewRequestMethod.get, + headers: {'foo': 'bar'}, + body: Uint8List.fromList('Example Body'.codeUnits), + ); + serializedRequest = request.toJson(); + expect(serializedRequest['headers'], {'foo': 'bar'}); + expect(serializedRequest['body'], 'Example Body'.codeUnits); + }); +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/platform_navigation_delegate_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/platform_navigation_delegate_test.dart new file mode 100644 index 000000000000..5e9aa2e12437 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/platform_navigation_delegate_test.dart @@ -0,0 +1,147 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; +import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; + +import 'webview_platform_test.mocks.dart'; + +void main() { + setUp(() { + WebViewPlatform.instance = MockWebViewPlatformWithMixin(); + }); + + test('Cannot be implemented with `implements`', () { + const PlatformNavigationDelegateCreationParams params = + PlatformNavigationDelegateCreationParams(); + when(WebViewPlatform.instance!.createPlatformNavigationDelegate(params)) + .thenReturn(ImplementsPlatformNavigationDelegate()); + + expect(() { + PlatformNavigationDelegate(params); + // In versions of `package:plugin_platform_interface` prior to fixing + // https://github.com/flutter/flutter/issues/109339, an attempt to + // implement a platform interface using `implements` would sometimes throw + // a `NoSuchMethodError` and other times throw an `AssertionError`. After + // the issue is fixed, an `AssertionError` will always be thrown. For the + // purpose of this test, we don't really care what exception is thrown, so + // just allow any exception. + }, throwsA(anything)); + }); + + test('Can be extended', () { + const PlatformNavigationDelegateCreationParams params = + PlatformNavigationDelegateCreationParams(); + when(WebViewPlatform.instance!.createPlatformNavigationDelegate(params)) + .thenReturn(ExtendsPlatformNavigationDelegate(params)); + + expect(PlatformNavigationDelegate(params), isNotNull); + }); + + test('Can be mocked with `implements`', () { + const PlatformNavigationDelegateCreationParams params = + PlatformNavigationDelegateCreationParams(); + when(WebViewPlatform.instance!.createPlatformNavigationDelegate(params)) + .thenReturn(MockNavigationDelegate()); + + expect(PlatformNavigationDelegate(params), isNotNull); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of setOnNavigationRequest should throw unimplemented error', + () { + final PlatformNavigationDelegate callbackDelegate = + ExtendsPlatformNavigationDelegate( + const PlatformNavigationDelegateCreationParams()); + + expect( + () => callbackDelegate.setOnNavigationRequest( + (NavigationRequest navigationRequest) => NavigationDecision.navigate), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of setOnPageStarted should throw unimplemented error', + () { + final PlatformNavigationDelegate callbackDelegate = + ExtendsPlatformNavigationDelegate( + const PlatformNavigationDelegateCreationParams()); + + expect( + () => callbackDelegate.setOnPageStarted((String url) {}), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of setOnPageFinished should throw unimplemented error', + () { + final PlatformNavigationDelegate callbackDelegate = + ExtendsPlatformNavigationDelegate( + const PlatformNavigationDelegateCreationParams()); + + expect( + () => callbackDelegate.setOnPageFinished((String url) {}), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of setOnProgress should throw unimplemented error', + () { + final PlatformNavigationDelegate callbackDelegate = + ExtendsPlatformNavigationDelegate( + const PlatformNavigationDelegateCreationParams()); + + expect( + () => callbackDelegate.setOnProgress((int progress) {}), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of setOnWebResourceError should throw unimplemented error', + () { + final PlatformNavigationDelegate callbackDelegate = + ExtendsPlatformNavigationDelegate( + const PlatformNavigationDelegateCreationParams()); + + expect( + () => callbackDelegate.setOnWebResourceError((WebResourceError error) {}), + throwsUnimplementedError, + ); + }); +} + +class MockWebViewPlatformWithMixin extends MockWebViewPlatform + with + // ignore: prefer_mixin + MockPlatformInterfaceMixin {} + +class ImplementsPlatformNavigationDelegate + implements PlatformNavigationDelegate { + @override + dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); +} + +class MockNavigationDelegate extends Mock + with + // ignore: prefer_mixin + MockPlatformInterfaceMixin + implements + PlatformNavigationDelegate {} + +class ExtendsPlatformNavigationDelegate extends PlatformNavigationDelegate { + ExtendsPlatformNavigationDelegate( + PlatformNavigationDelegateCreationParams params) + : super.implementation(params); +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.dart new file mode 100644 index 000000000000..6710f34895b7 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.dart @@ -0,0 +1,444 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; +import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; + +import 'platform_navigation_delegate_test.dart'; +import 'webview_platform_test.mocks.dart'; + +@GenerateMocks([PlatformNavigationDelegate]) +void main() { + setUp(() { + WebViewPlatform.instance = MockWebViewPlatformWithMixin(); + }); + + test('Cannot be implemented with `implements`', () { + when((WebViewPlatform.instance! as MockWebViewPlatform) + .createPlatformWebViewController(any)) + .thenReturn(ImplementsPlatformWebViewController()); + + expect(() { + PlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + // In versions of `package:plugin_platform_interface` prior to fixing + // https://github.com/flutter/flutter/issues/109339, an attempt to + // implement a platform interface using `implements` would sometimes throw + // a `NoSuchMethodError` and other times throw an `AssertionError`. After + // the issue is fixed, an `AssertionError` will always be thrown. For the + // purpose of this test, we don't really care what exception is thrown, so + // just allow any exception. + }, throwsA(anything)); + }); + + test('Can be extended', () { + const PlatformWebViewControllerCreationParams params = + PlatformWebViewControllerCreationParams(); + when((WebViewPlatform.instance! as MockWebViewPlatform) + .createPlatformWebViewController(any)) + .thenReturn(ExtendsPlatformWebViewController(params)); + + expect(PlatformWebViewController(params), isNotNull); + }); + + test('Can be mocked with `implements`', () { + when((WebViewPlatform.instance! as MockWebViewPlatform) + .createPlatformWebViewController(any)) + .thenReturn(MockWebViewControllerDelegate()); + + expect( + PlatformWebViewController( + const PlatformWebViewControllerCreationParams()), + isNotNull); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of loadFile should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.loadFile(''), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of loadFlutterAsset should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.loadFlutterAsset(''), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of loadHtmlString should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.loadHtmlString(''), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of loadRequest should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.loadRequest(MockLoadRequestParamsDelegate()), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of currentUrl should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.currentUrl(), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of canGoBack should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.canGoBack(), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of canGoForward should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.canGoForward(), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of goBack should throw unimplemented error', () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.goBack(), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of goForward should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.goForward(), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of reload should throw unimplemented error', () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.reload(), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of clearCache should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.clearCache(), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of clearLocalStorage should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.clearLocalStorage(), + throwsUnimplementedError, + ); + }); + + test( + 'Default implementation of the setNavigationCallback should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => + controller.setPlatformNavigationDelegate(MockNavigationDelegate()), + throwsUnimplementedError, + ); + }, + ); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of runJavaScript should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.runJavaScript('javaScript'), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of runJavaScriptReturningResult should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.runJavaScriptReturningResult('javaScript'), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of addJavaScriptChannel should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.addJavaScriptChannel( + JavaScriptChannelParams( + name: 'test', + onMessageReceived: (_) {}, + ), + ), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of removeJavaScriptChannel should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.removeJavaScriptChannel('test'), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of getTitle should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.getTitle(), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of scrollTo should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.scrollTo(0, 0), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of scrollBy should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.scrollBy(0, 0), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of getScrollPosition should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.getScrollPosition(), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of enableZoom should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.enableZoom(true), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of setBackgroundColor should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.setBackgroundColor(Colors.blue), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of setJavaScriptMode should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.setJavaScriptMode(JavaScriptMode.disabled), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of setUserAgent should throw unimplemented error', + () { + final PlatformWebViewController controller = + ExtendsPlatformWebViewController( + const PlatformWebViewControllerCreationParams()); + + expect( + () => controller.setUserAgent(null), + throwsUnimplementedError, + ); + }); +} + +class MockWebViewPlatformWithMixin extends MockWebViewPlatform + with + // ignore: prefer_mixin + MockPlatformInterfaceMixin {} + +class ImplementsPlatformWebViewController implements PlatformWebViewController { + @override + dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); +} + +class MockWebViewControllerDelegate extends Mock + with + // ignore: prefer_mixin + MockPlatformInterfaceMixin + implements + PlatformWebViewController {} + +class ExtendsPlatformWebViewController extends PlatformWebViewController { + ExtendsPlatformWebViewController( + PlatformWebViewControllerCreationParams params) + : super.implementation(params); +} + +// ignore: must_be_immutable +class MockLoadRequestParamsDelegate extends Mock + with + //ignore: prefer_mixin + MockPlatformInterfaceMixin + implements + LoadRequestParams {} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.mocks.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.mocks.dart new file mode 100644 index 000000000000..db142fe6a782 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_controller_test.mocks.dart @@ -0,0 +1,106 @@ +// Mocks generated by Mockito 5.3.2 from annotations +// in webview_flutter_platform_interface/test/platform_webview_controller_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'dart:async' as _i4; + +import 'package:mockito/mockito.dart' as _i1; +import 'package:webview_flutter_platform_interface/src/platform_navigation_delegate.dart' + as _i3; +import 'package:webview_flutter_platform_interface/src/webview_platform.dart' + as _i2; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +class _FakePlatformNavigationDelegateCreationParams_0 extends _i1.SmartFake + implements _i2.PlatformNavigationDelegateCreationParams { + _FakePlatformNavigationDelegateCreationParams_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [PlatformNavigationDelegate]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockPlatformNavigationDelegate extends _i1.Mock + implements _i3.PlatformNavigationDelegate { + MockPlatformNavigationDelegate() { + _i1.throwOnMissingStub(this); + } + + @override + _i2.PlatformNavigationDelegateCreationParams get params => + (super.noSuchMethod( + Invocation.getter(#params), + returnValue: _FakePlatformNavigationDelegateCreationParams_0( + this, + Invocation.getter(#params), + ), + ) as _i2.PlatformNavigationDelegateCreationParams); + @override + _i4.Future setOnNavigationRequest( + _i3.NavigationRequestCallback? onNavigationRequest) => + (super.noSuchMethod( + Invocation.method( + #setOnNavigationRequest, + [onNavigationRequest], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + @override + _i4.Future setOnPageStarted(_i3.PageEventCallback? onPageStarted) => + (super.noSuchMethod( + Invocation.method( + #setOnPageStarted, + [onPageStarted], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + @override + _i4.Future setOnPageFinished(_i3.PageEventCallback? onPageFinished) => + (super.noSuchMethod( + Invocation.method( + #setOnPageFinished, + [onPageFinished], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + @override + _i4.Future setOnProgress(_i3.ProgressCallback? onProgress) => + (super.noSuchMethod( + Invocation.method( + #setOnProgress, + [onProgress], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); + @override + _i4.Future setOnWebResourceError( + _i3.WebResourceErrorCallback? onWebResourceError) => + (super.noSuchMethod( + Invocation.method( + #setOnWebResourceError, + [onWebResourceError], + ), + returnValue: _i4.Future.value(), + returnValueForMissingStub: _i4.Future.value(), + ) as _i4.Future); +} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_widget_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_widget_test.dart new file mode 100644 index 000000000000..652f326cf20e --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/platform_webview_widget_test.dart @@ -0,0 +1,94 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter/widgets.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/mockito.dart'; +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; +import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; + +import 'webview_platform_test.mocks.dart'; + +void main() { + setUp(() { + WebViewPlatform.instance = MockWebViewPlatformWithMixin(); + }); + + test('Cannot be implemented with `implements`', () { + final MockWebViewControllerDelegate controller = + MockWebViewControllerDelegate(); + final PlatformWebViewWidgetCreationParams params = + PlatformWebViewWidgetCreationParams(controller: controller); + when(WebViewPlatform.instance!.createPlatformWebViewWidget(params)) + .thenReturn(ImplementsWebViewWidgetDelegate()); + + expect(() { + PlatformWebViewWidget(params); + // In versions of `package:plugin_platform_interface` prior to fixing + // https://github.com/flutter/flutter/issues/109339, an attempt to + // implement a platform interface using `implements` would sometimes throw + // a `NoSuchMethodError` and other times throw an `AssertionError`. After + // the issue is fixed, an `AssertionError` will always be thrown. For the + // purpose of this test, we don't really care what exception is thrown, so + // just allow any exception. + }, throwsA(anything)); + }); + + test('Can be extended', () { + final MockWebViewControllerDelegate controller = + MockWebViewControllerDelegate(); + final PlatformWebViewWidgetCreationParams params = + PlatformWebViewWidgetCreationParams(controller: controller); + when(WebViewPlatform.instance!.createPlatformWebViewWidget(params)) + .thenReturn(ExtendsWebViewWidgetDelegate(params)); + + expect(PlatformWebViewWidget(params), isNotNull); + }); + + test('Can be mocked with `implements`', () { + final MockWebViewControllerDelegate controller = + MockWebViewControllerDelegate(); + final PlatformWebViewWidgetCreationParams params = + PlatformWebViewWidgetCreationParams(controller: controller); + when(WebViewPlatform.instance!.createPlatformWebViewWidget(params)) + .thenReturn(MockWebViewWidgetDelegate()); + + expect(PlatformWebViewWidget(params), isNotNull); + }); +} + +class MockWebViewPlatformWithMixin extends MockWebViewPlatform + with + // ignore: prefer_mixin + MockPlatformInterfaceMixin {} + +class ImplementsWebViewWidgetDelegate implements PlatformWebViewWidget { + @override + dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); +} + +class MockWebViewWidgetDelegate extends Mock + with + // ignore: prefer_mixin + MockPlatformInterfaceMixin + implements + PlatformWebViewWidget {} + +class ExtendsWebViewWidgetDelegate extends PlatformWebViewWidget { + ExtendsWebViewWidgetDelegate(PlatformWebViewWidgetCreationParams params) + : super.implementation(params); + + @override + Widget build(BuildContext context) { + throw UnimplementedError( + 'build is not implemented for ExtendedWebViewWidgetDelegate.'); + } +} + +class MockWebViewControllerDelegate extends Mock + with + // ignore: prefer_mixin + MockPlatformInterfaceMixin + implements + PlatformWebViewController {} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/webview_platform_test.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/webview_platform_test.dart new file mode 100644 index 000000000000..34f84065e951 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/webview_platform_test.dart @@ -0,0 +1,115 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'package:flutter_test/flutter_test.dart'; +import 'package:mockito/annotations.dart'; +import 'package:mockito/mockito.dart'; +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; +import 'package:webview_flutter_platform_interface/webview_flutter_platform_interface.dart'; + +import 'webview_platform_test.mocks.dart'; + +@GenerateMocks([WebViewPlatform]) +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + test('Default instance WebViewPlatform instance should be null', () { + expect(WebViewPlatform.instance, isNull); + }); + + test('Cannot be implemented with `implements`', () { + expect(() { + WebViewPlatform.instance = ImplementsWebViewPlatform(); + // In versions of `package:plugin_platform_interface` prior to fixing + // https://github.com/flutter/flutter/issues/109339, an attempt to + // implement a platform interface using `implements` would sometimes throw + // a `NoSuchMethodError` and other times throw an `AssertionError`. After + // the issue is fixed, an `AssertionError` will always be thrown. For the + // purpose of this test, we don't really care what exception is thrown, so + // just allow any exception. + }, throwsA(anything)); + }); + + test('Can be extended', () { + WebViewPlatform.instance = ExtendsWebViewPlatform(); + }); + + test('Can be mocked with `implements`', () { + final MockWebViewPlatform mock = MockWebViewPlatformWithMixin(); + WebViewPlatform.instance = mock; + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of createCookieManagerDelegate should throw unimplemented error', + () { + final WebViewPlatform webViewPlatform = ExtendsWebViewPlatform(); + + expect( + () => webViewPlatform.createPlatformCookieManager( + const PlatformWebViewCookieManagerCreationParams()), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of createNavigationCallbackHandlerDelegate should throw unimplemented error', + () { + final WebViewPlatform webViewPlatform = ExtendsWebViewPlatform(); + + expect( + () => webViewPlatform.createPlatformNavigationDelegate( + const PlatformNavigationDelegateCreationParams()), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of createWebViewControllerDelegate should throw unimplemented error', + () { + final WebViewPlatform webViewPlatform = ExtendsWebViewPlatform(); + + expect( + () => webViewPlatform.createPlatformWebViewController( + const PlatformWebViewControllerCreationParams()), + throwsUnimplementedError, + ); + }); + + test( + // ignore: lines_longer_than_80_chars + 'Default implementation of createWebViewWidgetDelegate should throw unimplemented error', + () { + final WebViewPlatform webViewPlatform = ExtendsWebViewPlatform(); + final MockWebViewControllerDelegate controller = + MockWebViewControllerDelegate(); + + expect( + () => webViewPlatform.createPlatformWebViewWidget( + PlatformWebViewWidgetCreationParams(controller: controller)), + throwsUnimplementedError, + ); + }); +} + +class ImplementsWebViewPlatform implements WebViewPlatform { + @override + dynamic noSuchMethod(Invocation invocation) => super.noSuchMethod(invocation); +} + +class MockWebViewPlatformWithMixin extends MockWebViewPlatform + with + // ignore: prefer_mixin + MockPlatformInterfaceMixin {} + +class ExtendsWebViewPlatform extends WebViewPlatform {} + +class MockWebViewControllerDelegate extends Mock + with + // ignore: prefer_mixin + MockPlatformInterfaceMixin + implements + PlatformWebViewController {} diff --git a/packages/webview_flutter/webview_flutter_platform_interface/test/webview_platform_test.mocks.dart b/packages/webview_flutter/webview_flutter_platform_interface/test/webview_platform_test.mocks.dart new file mode 100644 index 000000000000..d613cddccd54 --- /dev/null +++ b/packages/webview_flutter/webview_flutter_platform_interface/test/webview_platform_test.mocks.dart @@ -0,0 +1,146 @@ +// Mocks generated by Mockito 5.3.2 from annotations +// in webview_flutter_platform_interface/test/webview_platform_test.dart. +// Do not manually edit this file. + +// ignore_for_file: no_leading_underscores_for_library_prefixes +import 'package:mockito/mockito.dart' as _i1; +import 'package:webview_flutter_platform_interface/src/platform_navigation_delegate.dart' + as _i3; +import 'package:webview_flutter_platform_interface/src/platform_webview_controller.dart' + as _i4; +import 'package:webview_flutter_platform_interface/src/platform_webview_cookie_manager.dart' + as _i2; +import 'package:webview_flutter_platform_interface/src/platform_webview_widget.dart' + as _i5; +import 'package:webview_flutter_platform_interface/src/types/types.dart' as _i7; +import 'package:webview_flutter_platform_interface/src/webview_platform.dart' + as _i6; + +// ignore_for_file: type=lint +// ignore_for_file: avoid_redundant_argument_values +// ignore_for_file: avoid_setters_without_getters +// ignore_for_file: comment_references +// ignore_for_file: implementation_imports +// ignore_for_file: invalid_use_of_visible_for_testing_member +// ignore_for_file: prefer_const_constructors +// ignore_for_file: unnecessary_parenthesis +// ignore_for_file: camel_case_types +// ignore_for_file: subtype_of_sealed_class + +class _FakePlatformWebViewCookieManager_0 extends _i1.SmartFake + implements _i2.PlatformWebViewCookieManager { + _FakePlatformWebViewCookieManager_0( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakePlatformNavigationDelegate_1 extends _i1.SmartFake + implements _i3.PlatformNavigationDelegate { + _FakePlatformNavigationDelegate_1( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakePlatformWebViewController_2 extends _i1.SmartFake + implements _i4.PlatformWebViewController { + _FakePlatformWebViewController_2( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +class _FakePlatformWebViewWidget_3 extends _i1.SmartFake + implements _i5.PlatformWebViewWidget { + _FakePlatformWebViewWidget_3( + Object parent, + Invocation parentInvocation, + ) : super( + parent, + parentInvocation, + ); +} + +/// A class which mocks [WebViewPlatform]. +/// +/// See the documentation for Mockito's code generation for more information. +class MockWebViewPlatform extends _i1.Mock implements _i6.WebViewPlatform { + MockWebViewPlatform() { + _i1.throwOnMissingStub(this); + } + + @override + _i2.PlatformWebViewCookieManager createPlatformCookieManager( + _i7.PlatformWebViewCookieManagerCreationParams? params) => + (super.noSuchMethod( + Invocation.method( + #createPlatformCookieManager, + [params], + ), + returnValue: _FakePlatformWebViewCookieManager_0( + this, + Invocation.method( + #createPlatformCookieManager, + [params], + ), + ), + ) as _i2.PlatformWebViewCookieManager); + @override + _i3.PlatformNavigationDelegate createPlatformNavigationDelegate( + _i7.PlatformNavigationDelegateCreationParams? params) => + (super.noSuchMethod( + Invocation.method( + #createPlatformNavigationDelegate, + [params], + ), + returnValue: _FakePlatformNavigationDelegate_1( + this, + Invocation.method( + #createPlatformNavigationDelegate, + [params], + ), + ), + ) as _i3.PlatformNavigationDelegate); + @override + _i4.PlatformWebViewController createPlatformWebViewController( + _i7.PlatformWebViewControllerCreationParams? params) => + (super.noSuchMethod( + Invocation.method( + #createPlatformWebViewController, + [params], + ), + returnValue: _FakePlatformWebViewController_2( + this, + Invocation.method( + #createPlatformWebViewController, + [params], + ), + ), + ) as _i4.PlatformWebViewController); + @override + _i5.PlatformWebViewWidget createPlatformWebViewWidget( + _i7.PlatformWebViewWidgetCreationParams? params) => + (super.noSuchMethod( + Invocation.method( + #createPlatformWebViewWidget, + [params], + ), + returnValue: _FakePlatformWebViewWidget_3( + this, + Invocation.method( + #createPlatformWebViewWidget, + [params], + ), + ), + ) as _i5.PlatformWebViewWidget); +}