diff --git a/analysis_options.yaml b/analysis_options.yaml index 24ec4a21..c98f8e5d 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -3,9 +3,11 @@ include: package:flutter_lints/flutter.yaml linter: rules: constant_identifier_names: ignore + deprecated_member_use_from_same_package: ignore # Additional information about this file can be found at # https://dart.dev/guides/language/analysis-options analyzer: errors: - deprecated_member_use_from_same_package: ignore \ No newline at end of file + deprecated_member_use: ignore + deprecated_member_use_from_same_package: ignore diff --git a/example/integration_test/process_global_config/main.dart b/example/integration_test/process_global_config/main.dart index aef30436..07643c25 100644 --- a/example/integration_test/process_global_config/main.dart +++ b/example/integration_test/process_global_config/main.dart @@ -1,12 +1,8 @@ -import 'dart:async'; - import 'package:flutter/foundation.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:path_provider/path_provider.dart'; -import '../constants.dart'; -import '../env.dart'; import '../util.dart'; part 'apply.dart'; diff --git a/example/integration_test/webview_flutter_test.dart b/example/integration_test/webview_flutter_test.dart index 2d7f9ec1..5d02287f 100644 --- a/example/integration_test/webview_flutter_test.dart +++ b/example/integration_test/webview_flutter_test.dart @@ -1,4 +1,3 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter_inappwebview/flutter_inappwebview.dart'; import 'package:integration_test/integration_test.dart'; diff --git a/flutter_inappwebview_android/analysis_options.yaml b/flutter_inappwebview_android/analysis_options.yaml index 24ec4a21..c98f8e5d 100644 --- a/flutter_inappwebview_android/analysis_options.yaml +++ b/flutter_inappwebview_android/analysis_options.yaml @@ -3,9 +3,11 @@ include: package:flutter_lints/flutter.yaml linter: rules: constant_identifier_names: ignore + deprecated_member_use_from_same_package: ignore # Additional information about this file can be found at # https://dart.dev/guides/language/analysis-options analyzer: errors: - deprecated_member_use_from_same_package: ignore \ No newline at end of file + deprecated_member_use: ignore + deprecated_member_use_from_same_package: ignore diff --git a/flutter_inappwebview_android/lib/src/chrome_safari_browser/chrome_safari_browser.dart b/flutter_inappwebview_android/lib/src/chrome_safari_browser/chrome_safari_browser.dart index fbedd340..af770c3f 100755 --- a/flutter_inappwebview_android/lib/src/chrome_safari_browser/chrome_safari_browser.dart +++ b/flutter_inappwebview_android/lib/src/chrome_safari_browser/chrome_safari_browser.dart @@ -111,8 +111,9 @@ class AndroidChromeSafariBrowser extends PlatformChromeSafariBrowser break; case "onClosed": _isOpened = false; + final onClosed = eventHandler?.onClosed; dispose(); - eventHandler?.onClosed(); + onClosed?.call(); break; case "onItemActionPerform": String url = call.arguments["url"]; @@ -402,5 +403,6 @@ class AndroidChromeSafariBrowser extends PlatformChromeSafariBrowser @mustCallSuper void dispose() { disposeChannel(); + eventHandler = null; } } diff --git a/flutter_inappwebview_android/lib/src/in_app_browser/in_app_browser.dart b/flutter_inappwebview_android/lib/src/in_app_browser/in_app_browser.dart index 0b8cafd4..b625f5fa 100755 --- a/flutter_inappwebview_android/lib/src/in_app_browser/in_app_browser.dart +++ b/flutter_inappwebview_android/lib/src/in_app_browser/in_app_browser.dart @@ -131,8 +131,9 @@ class AndroidInAppBrowser extends PlatformInAppBrowser with ChannelController { case "onExit": _debugLog(call.method, call.arguments); _isOpened = false; + final onExit = eventHandler?.onExit; dispose(); - eventHandler?.onExit(); + onExit?.call(); break; default: return _webViewController?.handleMethod(call); diff --git a/flutter_inappwebview_android/lib/src/in_app_webview/in_app_webview_controller.dart b/flutter_inappwebview_android/lib/src/in_app_webview/in_app_webview_controller.dart index 3034d7e3..4142f77e 100644 --- a/flutter_inappwebview_android/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/flutter_inappwebview_android/lib/src/in_app_webview/in_app_webview_controller.dart @@ -164,8 +164,9 @@ class AndroidInAppWebViewController extends PlatformInAppWebViewController params.webviewParams?.controllerFromPlatform?.call(this) ?? this; webStorage = AndroidWebStorage(AndroidWebStorageCreationParams( - localStorage: AndroidLocalStorage.defaultStorage(), - sessionStorage: AndroidSessionStorage.defaultStorage())); + localStorage: AndroidLocalStorage.defaultStorage(controller: this), + sessionStorage: + AndroidSessionStorage.defaultStorage(controller: this))); if (params.webviewParams is PlatformInAppWebViewWidgetCreationParams) { final keepAlive = @@ -1018,7 +1019,6 @@ class AndroidInAppWebViewController extends PlatformInAppWebViewController _controllerFromPlatform, permissionRequest)) ?.toMap(); else { - // ignore: deprecated_member_use_from_same_package return (await webviewParams!.androidOnPermissionRequest!( _controllerFromPlatform, origin, resources)) ?.toMap(); diff --git a/flutter_inappwebview_android/lib/src/inappwebview_platform.dart b/flutter_inappwebview_android/lib/src/inappwebview_platform.dart index 46e73778..cf497e38 100644 --- a/flutter_inappwebview_android/lib/src/inappwebview_platform.dart +++ b/flutter_inappwebview_android/lib/src/inappwebview_platform.dart @@ -150,16 +150,6 @@ class AndroidInAppWebViewPlatform extends InAppWebViewPlatform { return AndroidWebStorage(params); } - /// Creates a new [AndroidStorage]. - /// - /// This function should only be called by the app-facing package. - /// Look at using [AndroidStorage] in `flutter_inappwebview` instead. - AndroidStorage createPlatformStorage( - PlatformStorageCreationParams params, - ) { - return AndroidStorage(params); - } - /// Creates a new [AndroidLocalStorage]. /// /// This function should only be called by the app-facing package. @@ -266,16 +256,6 @@ class AndroidInAppWebViewPlatform extends InAppWebViewPlatform { return AndroidTracingController(params); } - /// Creates a new [AndroidPathHandler]. - /// - /// This function should only be called by the app-facing package. - /// Look at using [PathHandler] in `flutter_inappwebview` instead. - AndroidPathHandler createPlatformPathHandler( - PlatformPathHandlerCreationParams params, - ) { - return AndroidPathHandler(params); - } - /// Creates a new [AndroidAssetsPathHandler]. /// /// This function should only be called by the app-facing package. diff --git a/flutter_inappwebview_android/lib/src/service_worker_controller.dart b/flutter_inappwebview_android/lib/src/service_worker_controller.dart index 8a5a7919..646b958a 100644 --- a/flutter_inappwebview_android/lib/src/service_worker_controller.dart +++ b/flutter_inappwebview_android/lib/src/service_worker_controller.dart @@ -75,19 +75,15 @@ class AndroidServiceWorkerController extends PlatformServiceWorkerController } Future _handleMethod(MethodCall call) async { - AndroidServiceWorkerController controller = - AndroidServiceWorkerController.instance(); - ServiceWorkerClient? serviceWorkerClient = controller._serviceWorkerClient; - switch (call.method) { case "shouldInterceptRequest": if (serviceWorkerClient != null && - serviceWorkerClient.shouldInterceptRequest != null) { + serviceWorkerClient!.shouldInterceptRequest != null) { Map arguments = call.arguments.cast(); WebResourceRequest request = WebResourceRequest.fromMap(arguments)!; - return (await serviceWorkerClient.shouldInterceptRequest!(request)) + return (await serviceWorkerClient!.shouldInterceptRequest!(request)) ?.toMap(); } break; diff --git a/flutter_inappwebview_android/lib/src/web_storage/web_storage.dart b/flutter_inappwebview_android/lib/src/web_storage/web_storage.dart index efafb429..fdcefd6f 100644 --- a/flutter_inappwebview_android/lib/src/web_storage/web_storage.dart +++ b/flutter_inappwebview_android/lib/src/web_storage/web_storage.dart @@ -56,33 +56,27 @@ class AndroidWebStorage extends PlatformWebStorage { /// more information. class AndroidStorageCreationParams extends PlatformStorageCreationParams { /// Creates a new [AndroidStorageCreationParams] instance. - AndroidStorageCreationParams({required super.webStorageType}); + AndroidStorageCreationParams( + {required super.controller, required super.webStorageType}); /// Creates a [AndroidStorageCreationParams] instance based on [PlatformStorageCreationParams]. factory AndroidStorageCreationParams.fromPlatformStorageCreationParams( // Recommended placeholder to prevent being broken by platform interface. // ignore: avoid_unused_constructor_parameters PlatformStorageCreationParams params) { - return AndroidStorageCreationParams(webStorageType: params.webStorageType); + return AndroidStorageCreationParams( + controller: params.controller, webStorageType: params.webStorageType); } } ///{@macro flutter_inappwebview_platform_interface.PlatformStorage} -class AndroidStorage extends PlatformStorage { - /// Constructs a [AndroidStorage]. - AndroidStorage(PlatformStorageCreationParams params) - : super.implementation( - params is AndroidStorageCreationParams - ? params - : AndroidStorageCreationParams.fromPlatformStorageCreationParams( - params), - ); - - AndroidInAppWebViewController? _controller; +abstract class AndroidStorage implements PlatformStorage { + @override + AndroidInAppWebViewController? controller; @override Future length() async { - var result = await _controller?.evaluateJavascript(source: """ + var result = await controller?.evaluateJavascript(source: """ window.$webStorageType.length; """); return result != null ? int.parse(json.decode(result)) : null; @@ -91,14 +85,14 @@ class AndroidStorage extends PlatformStorage { @override Future setItem({required String key, required dynamic value}) async { var encodedValue = json.encode(value); - await _controller?.evaluateJavascript(source: """ + await controller?.evaluateJavascript(source: """ window.$webStorageType.setItem("$key", ${value is String ? encodedValue : "JSON.stringify($encodedValue)"}); """); } @override Future getItem({required String key}) async { - var itemValue = await _controller?.evaluateJavascript(source: """ + var itemValue = await controller?.evaluateJavascript(source: """ window.$webStorageType.getItem("$key"); """); @@ -115,7 +109,7 @@ class AndroidStorage extends PlatformStorage { @override Future removeItem({required String key}) async { - await _controller?.evaluateJavascript(source: """ + await controller?.evaluateJavascript(source: """ window.$webStorageType.removeItem("$key"); """); } @@ -125,7 +119,7 @@ class AndroidStorage extends PlatformStorage { var webStorageItems = []; List>? items = - (await _controller?.evaluateJavascript(source: """ + (await controller?.evaluateJavascript(source: """ (function() { var webStorageItems = []; for(var i = 0; i < window.$webStorageType.length; i++){ @@ -139,7 +133,7 @@ class AndroidStorage extends PlatformStorage { } return webStorageItems; })(); - """)).cast>(); + """))?.cast>(); if (items == null) { return webStorageItems; @@ -155,14 +149,14 @@ class AndroidStorage extends PlatformStorage { @override Future clear() async { - await _controller?.evaluateJavascript(source: """ + await controller?.evaluateJavascript(source: """ window.$webStorageType.clear(); """); } @override Future key({required int index}) async { - var result = await _controller?.evaluateJavascript(source: """ + var result = await controller?.evaluateJavascript(source: """ window.$webStorageType.key($index); """); return result != null ? json.decode(result) : null; @@ -170,7 +164,7 @@ class AndroidStorage extends PlatformStorage { @override void dispose() { - _controller = null; + controller = null; } } @@ -194,11 +188,10 @@ class AndroidLocalStorageCreationParams } ///{@macro flutter_inappwebview_platform_interface.PlatformLocalStorage} -class AndroidLocalStorage extends AndroidStorage - implements PlatformLocalStorage { +class AndroidLocalStorage extends PlatformLocalStorage with AndroidStorage { /// Constructs a [AndroidLocalStorage]. AndroidLocalStorage(PlatformLocalStorageCreationParams params) - : super( + : super.implementation( params is AndroidLocalStorageCreationParams ? params : AndroidLocalStorageCreationParams @@ -206,11 +199,17 @@ class AndroidLocalStorage extends AndroidStorage ); /// Default storage - factory AndroidLocalStorage.defaultStorage() { + factory AndroidLocalStorage.defaultStorage( + {required PlatformInAppWebViewController? controller}) { return AndroidLocalStorage(AndroidLocalStorageCreationParams( PlatformLocalStorageCreationParams(PlatformStorageCreationParams( + controller: controller, webStorageType: WebStorageType.LOCAL_STORAGE)))); } + + @override + AndroidInAppWebViewController? get controller => + params.controller as AndroidInAppWebViewController?; } /// Object specifying creation parameters for creating a [AndroidSessionStorage]. @@ -233,11 +232,10 @@ class AndroidSessionStorageCreationParams } ///{@macro flutter_inappwebview_platform_interface.PlatformSessionStorage} -class AndroidSessionStorage extends AndroidStorage - implements PlatformSessionStorage { +class AndroidSessionStorage extends PlatformSessionStorage with AndroidStorage { /// Constructs a [AndroidSessionStorage]. AndroidSessionStorage(PlatformSessionStorageCreationParams params) - : super( + : super.implementation( params is AndroidSessionStorageCreationParams ? params : AndroidSessionStorageCreationParams @@ -245,9 +243,15 @@ class AndroidSessionStorage extends AndroidStorage ); /// Default storage - factory AndroidSessionStorage.defaultStorage() { + factory AndroidSessionStorage.defaultStorage( + {required PlatformInAppWebViewController? controller}) { return AndroidSessionStorage(AndroidSessionStorageCreationParams( PlatformSessionStorageCreationParams(PlatformStorageCreationParams( + controller: controller, webStorageType: WebStorageType.SESSION_STORAGE)))); } + + @override + AndroidInAppWebViewController? get controller => + params.controller as AndroidInAppWebViewController?; } diff --git a/flutter_inappwebview_android/lib/src/webview_asset_loader.dart b/flutter_inappwebview_android/lib/src/webview_asset_loader.dart index bb555364..db56f1a5 100644 --- a/flutter_inappwebview_android/lib/src/webview_asset_loader.dart +++ b/flutter_inappwebview_android/lib/src/webview_asset_loader.dart @@ -25,26 +25,24 @@ class AndroidPathHandlerCreationParams } ///{@macro flutter_inappwebview_platform_interface.PlatformPathHandler} -class AndroidPathHandler extends PlatformPathHandler with ChannelController { - /// Creates a new [AndroidPathHandler]. - AndroidPathHandler(PlatformPathHandlerCreationParams params) - : super.implementation( - params is AndroidPathHandlerCreationParams - ? params - : AndroidPathHandlerCreationParams - .fromPlatformPathHandlerCreationParams(params), - ) { - _type = this.runtimeType.toString(); - _id = IdGenerator.generate(); +abstract class AndroidPathHandler + implements ChannelController, PlatformPathHandler { + final String _id = IdGenerator.generate(); + + @override + late final PlatformPathHandlerEvents? eventHandler; + + @override + late final String path; + + void _init(PlatformPathHandlerCreationParams params) { + this.path = params.path; channel = MethodChannel( 'com.pichillilorenzo/flutter_inappwebview_custompathhandler_${_id}'); handler = _handleMethod; initMethodCallHandler(); } - late final String _type; - late final String _id; - Future _handleMethod(MethodCall call) async { switch (call.method) { case "handle": @@ -57,7 +55,7 @@ class AndroidPathHandler extends PlatformPathHandler with ChannelController { @override Map toMap() { - return {"path": path, "type": _type, "id": _id}; + return {"path": path, "type": type, "id": _id}; } @override @@ -67,7 +65,7 @@ class AndroidPathHandler extends PlatformPathHandler with ChannelController { @override String toString() { - return 'AndroidPathHandler{path: $path}'; + return 'AndroidPathHandler{path: $path, type: $type}'; } @override @@ -100,16 +98,18 @@ class AndroidAssetsPathHandlerCreationParams } ///{@macro flutter_inappwebview_platform_interface.PlatformAssetsPathHandler} -class AndroidAssetsPathHandler extends AndroidPathHandler - implements PlatformAssetsPathHandler { +class AndroidAssetsPathHandler extends PlatformAssetsPathHandler + with AndroidPathHandler, ChannelController { /// Constructs a [AndroidAssetsPathHandler]. AndroidAssetsPathHandler(PlatformAssetsPathHandlerCreationParams params) - : super( + : super.implementation( params is AndroidAssetsPathHandlerCreationParams ? params : AndroidAssetsPathHandlerCreationParams .fromPlatformAssetsPathHandlerCreationParams(params), - ); + ) { + _init(params); + } } /// Object specifying creation parameters for creating a [AndroidResourcesPathHandler]. @@ -135,16 +135,18 @@ class AndroidResourcesPathHandlerCreationParams } ///{@macro flutter_inappwebview_platform_interface.PlatformResourcesPathHandler} -class AndroidResourcesPathHandler extends AndroidPathHandler - implements PlatformResourcesPathHandler { +class AndroidResourcesPathHandler extends PlatformResourcesPathHandler + with AndroidPathHandler, ChannelController { /// Constructs a [AndroidResourcesPathHandler]. AndroidResourcesPathHandler(PlatformResourcesPathHandlerCreationParams params) - : super( + : super.implementation( params is AndroidResourcesPathHandlerCreationParams ? params : AndroidResourcesPathHandlerCreationParams .fromPlatformResourcesPathHandlerCreationParams(params), - ); + ) { + _init(params); + } } /// Object specifying creation parameters for creating a [AndroidInternalStoragePathHandler]. @@ -170,17 +172,20 @@ class AndroidInternalStoragePathHandlerCreationParams } ///{@macro flutter_inappwebview_platform_interface.PlatformInternalStoragePathHandler} -class AndroidInternalStoragePathHandler extends AndroidPathHandler - implements PlatformInternalStoragePathHandler { +class AndroidInternalStoragePathHandler + extends PlatformInternalStoragePathHandler + with AndroidPathHandler, ChannelController { /// Constructs a [AndroidInternalStoragePathHandler]. AndroidInternalStoragePathHandler( PlatformInternalStoragePathHandlerCreationParams params) - : super( + : super.implementation( params is AndroidInternalStoragePathHandlerCreationParams ? params : AndroidInternalStoragePathHandlerCreationParams .fromPlatformInternalStoragePathHandlerCreationParams(params), - ); + ) { + _init(params); + } AndroidInternalStoragePathHandlerCreationParams get _internalParams => params as AndroidInternalStoragePathHandlerCreationParams; diff --git a/flutter_inappwebview_platform_interface/analysis_options.yaml b/flutter_inappwebview_platform_interface/analysis_options.yaml index 24ec4a21..c98f8e5d 100644 --- a/flutter_inappwebview_platform_interface/analysis_options.yaml +++ b/flutter_inappwebview_platform_interface/analysis_options.yaml @@ -3,9 +3,11 @@ include: package:flutter_lints/flutter.yaml linter: rules: constant_identifier_names: ignore + deprecated_member_use_from_same_package: ignore # Additional information about this file can be found at # https://dart.dev/guides/language/analysis-options analyzer: errors: - deprecated_member_use_from_same_package: ignore \ No newline at end of file + deprecated_member_use: ignore + deprecated_member_use_from_same_package: ignore diff --git a/flutter_inappwebview_platform_interface/lib/src/chrome_safari_browser/platform_chrome_safari_browser.dart b/flutter_inappwebview_platform_interface/lib/src/chrome_safari_browser/platform_chrome_safari_browser.dart index af26858d..c221d1cd 100755 --- a/flutter_inappwebview_platform_interface/lib/src/chrome_safari_browser/platform_chrome_safari_browser.dart +++ b/flutter_inappwebview_platform_interface/lib/src/chrome_safari_browser/platform_chrome_safari_browser.dart @@ -463,7 +463,7 @@ abstract class PlatformChromeSafariBrowser extends PlatformInterface } ///{@template flutter_inappwebview_platform_interface.PlatformChromeSafariBrowser.dispose} - ///Disposes the channel. + ///Disposes the channel and event handler. ///{@endtemplate} @override void dispose() { diff --git a/flutter_inappwebview_platform_interface/lib/src/in_app_browser/in_app_browser_settings.dart b/flutter_inappwebview_platform_interface/lib/src/in_app_browser/in_app_browser_settings.dart index c87aec88..d75cafb8 100755 --- a/flutter_inappwebview_platform_interface/lib/src/in_app_browser/in_app_browser_settings.dart +++ b/flutter_inappwebview_platform_interface/lib/src/in_app_browser/in_app_browser_settings.dart @@ -1,6 +1,5 @@ import 'dart:ui'; -import 'package:flutter/foundation.dart'; import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart'; import '../types/in_app_webview_rect.dart'; diff --git a/flutter_inappwebview_platform_interface/lib/src/inappwebview_platform.dart b/flutter_inappwebview_platform_interface/lib/src/inappwebview_platform.dart index 069e0e56..ef96c5d2 100644 --- a/flutter_inappwebview_platform_interface/lib/src/inappwebview_platform.dart +++ b/flutter_inappwebview_platform_interface/lib/src/inappwebview_platform.dart @@ -209,17 +209,6 @@ abstract class InAppWebViewPlatform extends PlatformInterface { 'createPlatformWebStorage is not implemented on the current platform.'); } - /// Creates a new [PlatformStorage]. - /// - /// This function should only be called by the app-facing package. - /// Look at using [Storage] in `flutter_inappwebview` instead. - PlatformStorage createPlatformStorage( - PlatformStorageCreationParams params, - ) { - throw UnimplementedError( - 'createPlatformStorage is not implemented on the current platform.'); - } - /// Creates a new [PlatformLocalStorage]. /// /// This function should only be called by the app-facing package. @@ -349,17 +338,6 @@ abstract class InAppWebViewPlatform extends PlatformInterface { 'createPlatformTracingController is not implemented on the current platform.'); } - /// Creates a new [PlatformPathHandler]. - /// - /// This function should only be called by the app-facing package. - /// Look at using [PathHandler] in `flutter_inappwebview` instead. - PlatformPathHandler createPlatformPathHandler( - PlatformPathHandlerCreationParams params, - ) { - throw UnimplementedError( - 'createPlatformPathHandler is not implemented on the current platform.'); - } - /// Creates a new [PlatformAssetsPathHandler]. /// /// This function should only be called by the app-facing package. diff --git a/flutter_inappwebview_platform_interface/lib/src/platform_webview_asset_loader.dart b/flutter_inappwebview_platform_interface/lib/src/platform_webview_asset_loader.dart index ef42e4fe..15947eb8 100644 --- a/flutter_inappwebview_platform_interface/lib/src/platform_webview_asset_loader.dart +++ b/flutter_inappwebview_platform_interface/lib/src/platform_webview_asset_loader.dart @@ -36,28 +36,11 @@ class WebViewAssetLoader_ { /// ///[WebViewAssetLoader] will try Path Handlers in the order they're registered, ///and will use whichever is the first to return a non-null. - List? pathHandlers; + List? pathHandlers; WebViewAssetLoader_({this.domain, this.httpAllowed, this.pathHandlers}); } -///[PlatformPathHandler] interface. -abstract class IPathHandler { - String get path { - throw UnimplementedError('path is not implemented on the current platform'); - } - - Map toMap() { - throw UnimplementedError( - 'toMap is not implemented on the current platform'); - } - - Map toJson() { - throw UnimplementedError( - 'toJson is not implemented on the current platform'); - } -} - /// Object specifying creation parameters for creating a [PlatformPathHandler]. /// /// Platform specific implementations can add additional fields by extending @@ -76,45 +59,25 @@ class PlatformPathHandlerCreationParams { /// ///Implement this interface to handle other use-cases according to your app's needs. ///{@endtemplate} -abstract class PlatformPathHandler extends PlatformInterface - implements IPathHandler { - /// Creates a new [PlatformWebViewAssetLoader] - factory PlatformPathHandler(PlatformPathHandlerCreationParams params) { - assert( - InAppWebViewPlatform.instance != null, - 'A platform implementation for `flutter_inappwebview` has not been set. Please ' - 'ensure that an implementation of `InAppWebViewPlatform` has been set to ' - '`WebViewPlatform.instance` before use. For unit testing, ' - '`WebViewPlatform.instance` can be set with your own test implementation.', - ); - final PlatformPathHandler pathHandler = - InAppWebViewPlatform.instance!.createPlatformPathHandler(params); - PlatformInterface.verify(pathHandler, _token); - return pathHandler; - } - - /// Used by the platform implementation to create a new - /// [PlatformPathHandler]. - /// - /// Should only be used by platform implementations because they can't extend - /// a class that only contains a factory constructor. - @protected - PlatformPathHandler.implementation(this.params) : super(token: _token); - - static final Object _token = Object(); - - /// The parameters used to initialize the [PlatformPathHandler]. - final PlatformPathHandlerCreationParams params; - +abstract class PlatformPathHandler { /// Event handler object that handles the [PlatformPathHandler] events. - PlatformPathHandlerEvents? eventHandler; + late final PlatformPathHandlerEvents? eventHandler; + + ///{@template flutter_inappwebview_platform_interface.PlatformPathHandler.type} + ///The path handler type. + ///{@endtemplate} + String get type { + throw UnimplementedError('type is not implemented on the current platform'); + } ///{@template flutter_inappwebview_platform_interface.PlatformPathHandler.path} ///The suffix path to be handled. /// ///The path should start and end with a `"/"` and it shouldn't collide with a real web path. ///{@endtemplate} - String get path => params.path; + String get path { + throw UnimplementedError('path is not implemented on the current platform'); + } Map toMap() { throw UnimplementedError( @@ -181,7 +144,7 @@ class PlatformAssetsPathHandlerCreationParams ///Developers should ensure that asset files are named using standard file extensions. ///If the file does not have a recognised extension, `text/plain` will be used by default. ///{@endtemplate} -abstract class PlatformAssetsPathHandler extends PlatformPathHandler { +abstract class PlatformAssetsPathHandler extends PlatformInterface implements PlatformPathHandler { /// Creates a new [PlatformAssetsPathHandler] factory PlatformAssetsPathHandler( PlatformAssetsPathHandlerCreationParams params) { @@ -203,16 +166,18 @@ abstract class PlatformAssetsPathHandler extends PlatformPathHandler { /// Should only be used by platform implementations because they can't extend /// a class that only contains a factory constructor. @protected - PlatformAssetsPathHandler.implementation( - PlatformPathHandlerCreationParams params) - : super.implementation( - params is PlatformAssetsPathHandlerCreationParams - ? params - : PlatformAssetsPathHandlerCreationParams - .fromPlatformPathHandlerCreationParams(params), - ); + PlatformAssetsPathHandler.implementation(this.params) : super(token: _token); static final Object _token = Object(); + + /// The parameters used to initialize the [PlatformAssetsPathHandler]. + final PlatformAssetsPathHandlerCreationParams params; + + @override + String get type => 'AssetsPathHandler'; + + @override + String get path => params.path; } /// Object specifying creation parameters for creating a [PlatformResourcesPathHandler]. @@ -251,7 +216,7 @@ class PlatformResourcesPathHandlerCreationParams ///Developers should ensure that asset files are named using standard file extensions. ///If the file does not have a recognised extension, `text/plain` will be used by default. ///{@endtemplate} -abstract class PlatformResourcesPathHandler extends PlatformPathHandler { +abstract class PlatformResourcesPathHandler extends PlatformInterface implements PlatformPathHandler { /// Creates a new [PlatformResourcesPathHandler] factory PlatformResourcesPathHandler( PlatformResourcesPathHandlerCreationParams params) { @@ -274,16 +239,18 @@ abstract class PlatformResourcesPathHandler extends PlatformPathHandler { /// Should only be used by platform implementations because they can't extend /// a class that only contains a factory constructor. @protected - PlatformResourcesPathHandler.implementation( - PlatformPathHandlerCreationParams params) - : super.implementation( - params is PlatformResourcesPathHandlerCreationParams - ? params - : PlatformResourcesPathHandlerCreationParams - .fromPlatformPathHandlerCreationParams(params), - ); + PlatformResourcesPathHandler.implementation(this.params) : super(token: _token); static final Object _token = Object(); + + /// The parameters used to initialize the [PlatformResourcesPathHandler]. + final PlatformResourcesPathHandlerCreationParams params; + + @override + String get type => 'ResourcesPathHandler'; + + @override + String get path => params.path; } /// Object specifying creation parameters for creating a [PlatformInternalStoragePathHandler]. @@ -332,7 +299,7 @@ class PlatformInternalStoragePathHandlerCreationParams ///Developers should ensure that asset files are named using standard file extensions. ///If the file does not have a recognised extension, `text/plain` will be used by default. ///{@endtemplate} -abstract class PlatformInternalStoragePathHandler extends PlatformPathHandler { +abstract class PlatformInternalStoragePathHandler extends PlatformInterface implements PlatformPathHandler { /// Creates a new [PlatformResourcesPathHandler] factory PlatformInternalStoragePathHandler( PlatformInternalStoragePathHandlerCreationParams params) { @@ -355,21 +322,18 @@ abstract class PlatformInternalStoragePathHandler extends PlatformPathHandler { /// Should only be used by platform implementations because they can't extend /// a class that only contains a factory constructor. @protected - PlatformInternalStoragePathHandler.implementation( - PlatformPathHandlerCreationParams params, - {required String directory}) - : super.implementation( - params is PlatformInternalStoragePathHandlerCreationParams - ? params - : PlatformInternalStoragePathHandlerCreationParams - .fromPlatformPathHandlerCreationParams(params, - directory: directory), - ); + PlatformInternalStoragePathHandler.implementation(this.params) : super(token: _token); static final Object _token = Object(); - PlatformInternalStoragePathHandlerCreationParams get _internalParams => - params as PlatformInternalStoragePathHandlerCreationParams; + /// The parameters used to initialize the [PlatformInternalStoragePathHandler]. + final PlatformInternalStoragePathHandlerCreationParams params; - String get directory => _internalParams.directory; + @override + String get type => 'InternalStoragePathHandler'; + + @override + String get path => params.path; + + String get directory => params.directory; } diff --git a/flutter_inappwebview_platform_interface/lib/src/platform_webview_asset_loader.g.dart b/flutter_inappwebview_platform_interface/lib/src/platform_webview_asset_loader.g.dart index 9ccbe5e5..ce8f96df 100644 --- a/flutter_inappwebview_platform_interface/lib/src/platform_webview_asset_loader.g.dart +++ b/flutter_inappwebview_platform_interface/lib/src/platform_webview_asset_loader.g.dart @@ -34,7 +34,7 @@ class WebViewAssetLoader { /// ///[WebViewAssetLoader] will try Path Handlers in the order they're registered, ///and will use whichever is the first to return a non-null. - List? pathHandlers; + List? pathHandlers; WebViewAssetLoader({this.domain, this.httpAllowed, this.pathHandlers}); ///Gets a possible [WebViewAssetLoader] instance from a [Map] value. @@ -46,7 +46,7 @@ class WebViewAssetLoader { domain: map['domain'], httpAllowed: map['httpAllowed'], pathHandlers: map['pathHandlers'] != null - ? List.from(map['pathHandlers'].map((e) => e)) + ? List.from(map['pathHandlers'].map((e) => e)) : null, ); return instance; diff --git a/flutter_inappwebview_platform_interface/lib/src/types/ssl_certificate.dart b/flutter_inappwebview_platform_interface/lib/src/types/ssl_certificate.dart index 0a457944..041cfabd 100644 --- a/flutter_inappwebview_platform_interface/lib/src/types/ssl_certificate.dart +++ b/flutter_inappwebview_platform_interface/lib/src/types/ssl_certificate.dart @@ -1,4 +1,3 @@ -import 'package:flutter/foundation.dart'; import 'package:flutter_inappwebview_internal_annotations/flutter_inappwebview_internal_annotations.dart'; import '../util.dart'; diff --git a/flutter_inappwebview_platform_interface/lib/src/web_storage/platform_web_storage.dart b/flutter_inappwebview_platform_interface/lib/src/web_storage/platform_web_storage.dart index 2ef7d98a..1e2991f4 100644 --- a/flutter_inappwebview_platform_interface/lib/src/web_storage/platform_web_storage.dart +++ b/flutter_inappwebview_platform_interface/lib/src/web_storage/platform_web_storage.dart @@ -89,7 +89,11 @@ abstract class PlatformWebStorage extends PlatformInterface @immutable class PlatformStorageCreationParams { /// Used by the platform implementation to create a new [PlatformStorage]. - const PlatformStorageCreationParams({required this.webStorageType}); + const PlatformStorageCreationParams( + {required this.controller, required this.webStorageType}); + + ///{@macro flutter_inappwebview_platform_interface.PlatformStorage.controller} + final PlatformInAppWebViewController? controller; ///{@macro flutter_inappwebview_platform_interface.PlatformStorage.webStorageType} final WebStorageType webStorageType; @@ -99,38 +103,19 @@ class PlatformStorageCreationParams { ///Class that provides methods to manage the JavaScript [Storage](https://developer.mozilla.org/en-US/docs/Web/API/Storage) object. ///It is used by [PlatformLocalStorage] and [PlatformSessionStorage]. ///{@endtemplate} -abstract class PlatformStorage extends PlatformInterface implements Disposable { - /// Creates a new [PlatformStorage] - factory PlatformStorage(PlatformStorageCreationParams params) { - assert( - InAppWebViewPlatform.instance != null, - 'A platform implementation for `flutter_inappwebview` has not been set. Please ' - 'ensure that an implementation of `InAppWebViewPlatform` has been set to ' - '`InAppWebViewPlatform.instance` before use. For unit testing, ' - '`InAppWebViewPlatform.instance` can be set with your own test implementation.', - ); - final PlatformStorage storage = - InAppWebViewPlatform.instance!.createPlatformStorage(params); - PlatformInterface.verify(storage, _token); - return storage; - } - - /// Used by the platform implementation to create a new [PlatformStorage]. - /// - /// Should only be used by platform implementations because they can't extend - /// a class that only contains a factory constructor. - @protected - PlatformStorage.implementation(this.params) : super(token: _token); - - static final Object _token = Object(); - - /// The parameters used to initialize the [PlatformStorage]. - final PlatformStorageCreationParams params; +abstract class PlatformStorage implements Disposable { + ///{@template flutter_inappwebview_platform_interface.PlatformStorage.controller} + ///Controller used to interact with storage. + ///{@endtemplate} + PlatformInAppWebViewController? get controller; ///{@template flutter_inappwebview_platform_interface.PlatformStorage.webStorageType} ///The web storage type: `window.sessionStorage` or `window.localStorage`. ///{@endtemplate} - WebStorageType get webStorageType => params.webStorageType; + WebStorageType get webStorageType { + throw UnimplementedError( + 'webStorageType is not implemented on the current platform'); + } ///{@template flutter_inappwebview_platform_interface.PlatformStorage.length} ///Returns an integer representing the number of data items stored in the Storage object. @@ -251,11 +236,13 @@ abstract class PlatformStorage extends PlatformInterface implements Disposable { @immutable class PlatformLocalStorageCreationParams extends PlatformStorageCreationParams { /// Used by the platform implementation to create a new [PlatformLocalStorage]. - const PlatformLocalStorageCreationParams( + PlatformLocalStorageCreationParams( // This parameter prevents breaking changes later. // ignore: avoid_unused_constructor_parameters PlatformStorageCreationParams params, - ) : super(webStorageType: WebStorageType.LOCAL_STORAGE); + ) : super( + controller: params.controller, + webStorageType: WebStorageType.LOCAL_STORAGE); /// Creates a [AndroidCookieManagerCreationParams] instance based on [PlatformCookieManagerCreationParams]. factory PlatformLocalStorageCreationParams.fromPlatformStorageCreationParams( @@ -268,7 +255,8 @@ class PlatformLocalStorageCreationParams extends PlatformStorageCreationParams { ///Class that provides methods to manage the JavaScript `window.localStorage` object. ///It used by [PlatformWebStorage]. ///{@endtemplate} -abstract class PlatformLocalStorage extends PlatformStorage { +abstract class PlatformLocalStorage extends PlatformInterface + with PlatformStorage { /// Creates a new [PlatformLocalStorage] factory PlatformLocalStorage(PlatformLocalStorageCreationParams params) { assert( @@ -289,15 +277,15 @@ abstract class PlatformLocalStorage extends PlatformStorage { /// Should only be used by platform implementations because they can't extend /// a class that only contains a factory constructor. @protected - PlatformLocalStorage.implementation(PlatformStorageCreationParams params) - : super.implementation( - params is PlatformLocalStorageCreationParams - ? params - : PlatformLocalStorageCreationParams - .fromPlatformStorageCreationParams(params), - ); + PlatformLocalStorage.implementation(this.params) : super(token: _token); static final Object _token = Object(); + + /// The parameters used to initialize the [PlatformLocalStorage]. + final PlatformLocalStorageCreationParams params; + + @override + WebStorageType get webStorageType => params.webStorageType; } /// Object specifying creation parameters for creating a [PlatformSessionStorage]. @@ -308,11 +296,13 @@ abstract class PlatformLocalStorage extends PlatformStorage { class PlatformSessionStorageCreationParams extends PlatformStorageCreationParams { /// Used by the platform implementation to create a new [PlatformSessionStorage]. - const PlatformSessionStorageCreationParams( + PlatformSessionStorageCreationParams( // This parameter prevents breaking changes later. // ignore: avoid_unused_constructor_parameters PlatformStorageCreationParams params, - ) : super(webStorageType: WebStorageType.SESSION_STORAGE); + ) : super( + controller: params.controller, + webStorageType: WebStorageType.SESSION_STORAGE); /// Creates a [AndroidCookieManagerCreationParams] instance based on [PlatformCookieManagerCreationParams]. factory PlatformSessionStorageCreationParams.fromPlatformStorageCreationParams( @@ -325,7 +315,8 @@ class PlatformSessionStorageCreationParams ///Class that provides methods to manage the JavaScript `window.sessionStorage` object. ///It used by [PlatformWebStorage]. ///{@endtemplate} -abstract class PlatformSessionStorage extends PlatformStorage { +abstract class PlatformSessionStorage extends PlatformInterface + with PlatformStorage { /// Creates a new [PlatformSessionStorage] factory PlatformSessionStorage(PlatformSessionStorageCreationParams params) { assert( @@ -346,13 +337,13 @@ abstract class PlatformSessionStorage extends PlatformStorage { /// Should only be used by platform implementations because they can't extend /// a class that only contains a factory constructor. @protected - PlatformSessionStorage.implementation(PlatformStorageCreationParams params) - : super.implementation( - params is PlatformSessionStorageCreationParams - ? params - : PlatformSessionStorageCreationParams - .fromPlatformStorageCreationParams(params), - ); + PlatformSessionStorage.implementation(this.params) : super(token: _token); static final Object _token = Object(); + + /// The parameters used to initialize the [PlatformSessionStorage]. + final PlatformSessionStorageCreationParams params; + + @override + WebStorageType get webStorageType => params.webStorageType; } diff --git a/lib/src/cookie_manager.dart b/lib/src/cookie_manager.dart index 9805080d..843aa0b4 100755 --- a/lib/src/cookie_manager.dart +++ b/lib/src/cookie_manager.dart @@ -3,7 +3,6 @@ import 'dart:async'; import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart'; import 'in_app_webview/in_app_webview_controller.dart'; -import 'in_app_webview/headless_in_app_webview.dart'; ///{@macro flutter_inappwebview_platform_interface.PlatformCookieManager} class CookieManager { diff --git a/lib/src/in_app_browser/in_app_browser.dart b/lib/src/in_app_browser/in_app_browser.dart index 3d297985..93acc9c5 100755 --- a/lib/src/in_app_browser/in_app_browser.dart +++ b/lib/src/in_app_browser/in_app_browser.dart @@ -11,7 +11,6 @@ import '../find_interaction/find_interaction_controller.dart'; import '../pull_to_refresh/main.dart'; import '../in_app_webview/in_app_webview_controller.dart'; -import '../print_job/main.dart'; ///{@macro flutter_inappwebview_platform_interface.PlatformInAppBrowser} class InAppBrowser implements PlatformInAppBrowserEvents { diff --git a/lib/src/web_storage/web_storage.dart b/lib/src/web_storage/web_storage.dart index dc3945e4..72a02e2e 100644 --- a/lib/src/web_storage/web_storage.dart +++ b/lib/src/web_storage/web_storage.dart @@ -1,5 +1,7 @@ import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart'; +import '../in_app_webview/in_app_webview_controller.dart'; + ///{@macro flutter_inappwebview_platform_interface.PlatformWebStorage} class WebStorage { ///{@macro flutter_inappwebview_platform_interface.PlatformWebStorage} @@ -37,27 +39,16 @@ class WebStorage { } ///{@macro flutter_inappwebview_platform_interface.PlatformStorage} -class Storage { - ///{@macro flutter_inappwebview_platform_interface.PlatformStorage} - Storage({required WebStorageType webStorageType}) - : this.fromPlatformCreationParams( - params: - PlatformStorageCreationParams(webStorageType: webStorageType)); - - /// Constructs a [Storage]. - /// - /// See [Storage.fromPlatformCreationParams] for setting parameters for - /// a specific platform. - Storage.fromPlatformCreationParams({ - required PlatformStorageCreationParams params, - }) : this.fromPlatform(platform: PlatformStorage(params)); - +abstract class Storage implements PlatformStorage { /// Constructs a [Storage] from a specific platform implementation. Storage.fromPlatform({required this.platform}); /// Implementation of [PlatformStorage] for the current platform. final PlatformStorage platform; + ///{@macro flutter_inappwebview_platform_interface.PlatformStorage.controller} + PlatformInAppWebViewController? get controller => platform.controller; + ///{@macro flutter_inappwebview_platform_interface.PlatformStorage.webStorageType} WebStorageType get webStorageType => platform.webStorageType; @@ -91,10 +82,11 @@ class Storage { ///{@macro flutter_inappwebview_platform_interface.PlatformLocalStorage} class LocalStorage extends Storage { ///{@macro flutter_inappwebview_platform_interface.PlatformLocalStorage} - LocalStorage() + LocalStorage({required InAppWebViewController? controller}) : this.fromPlatformCreationParams( params: PlatformLocalStorageCreationParams( PlatformStorageCreationParams( + controller: controller?.platform, webStorageType: WebStorageType.LOCAL_STORAGE))); /// Constructs a [LocalStorage]. @@ -116,10 +108,11 @@ class LocalStorage extends Storage { ///{@macro flutter_inappwebview_platform_interface.PlatformSessionStorage} class SessionStorage extends Storage { ///{@macro flutter_inappwebview_platform_interface.PlatformSessionStorage} - SessionStorage() + SessionStorage({required InAppWebViewController? controller}) : this.fromPlatformCreationParams( params: PlatformSessionStorageCreationParams( PlatformStorageCreationParams( + controller: controller?.platform, webStorageType: WebStorageType.SESSION_STORAGE))); /// Constructs a [SessionStorage]. diff --git a/lib/src/webview_asset_loader.dart b/lib/src/webview_asset_loader.dart index 2fb0794b..ce3cfe44 100644 --- a/lib/src/webview_asset_loader.dart +++ b/lib/src/webview_asset_loader.dart @@ -1,32 +1,26 @@ import 'package:flutter_inappwebview_platform_interface/flutter_inappwebview_platform_interface.dart'; ///{@macro flutter_inappwebview_platform_interface.PlatformPathHandler} -abstract class PathHandler implements IPathHandler, PlatformPathHandlerEvents { - ///{@macro flutter_inappwebview_platform_interface.PlatformPathHandler} - PathHandler({required String path}) - : this.fromPlatformCreationParams( - params: PlatformPathHandlerCreationParams(path: path)); - - /// Constructs a [PathHandler]. - /// - /// See [PathHandler.fromPlatformCreationParams] for setting parameters for - /// a specific platform. - PathHandler.fromPlatformCreationParams({ - required PlatformPathHandlerCreationParams params, - }) : this.fromPlatform(platform: PlatformPathHandler(params)); - +abstract class PathHandler + implements PlatformPathHandler, PlatformPathHandlerEvents { /// Constructs a [PathHandler] from a specific platform implementation. PathHandler.fromPlatform({required this.platform}) { this.platform.eventHandler = this; } + @override + late final PlatformPathHandlerEvents? eventHandler; + /// Implementation of [PlatformPathHandler] for the current platform. final PlatformPathHandler platform; - ///{@macro flutter_inappwebview_platform_interface.PlatformPathHandler.path} + @override + String get type => platform.type; + + @override String get path => platform.path; - ///{@macro flutter_inappwebview_platform_interface.PlatformPathHandler.handle} + @override Future handle(String path) async { return null; } diff --git a/test_node_server/index.js b/test_node_server/index.js index aeb07c7d..ad68fb3a 100755 --- a/test_node_server/index.js +++ b/test_node_server/index.js @@ -167,7 +167,7 @@ app.get("/echo-headers", (req, res) => { }) app.get('/test-index', (req, res) => { - res.sendFile(__dirname + '/public/index.html'); + res.sendFile(__dirname + '/public/test-index.html'); }) app.post("/test-post", (req, res) => {