diff --git a/CHANGELOG.md b/CHANGELOG.md index ece99b390..f639eef3b 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 5.7.1+1 + +- Fixed User Script remove methods +- Fixed missing `break` statement on Android when parsing `ChromeCustomTabsOptions.displayMode` in Java code + ## 5.7.1 - Exposed "shared" property of HttpServer bind method to support more use-cases. (thanks to [LugonjaAleksandar](https://github.com/LugonjaAleksandar)) diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsOptions.java b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsOptions.java index 4d5c076b7..5ace66e3e 100755 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsOptions.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappwebview/chrome_custom_tabs/ChromeCustomTabsOptions.java @@ -90,8 +90,10 @@ public ChromeCustomTabsOptions parse(Map options) { boolean isSticky = (boolean) displayModeMap.get("isSticky"); int layoutInDisplayCutoutMode = (int) displayModeMap.get("layoutInDisplayCutoutMode"); displayMode = new TrustedWebActivityDisplayMode.ImmersiveMode(isSticky, layoutInDisplayCutoutMode); + break; case "DEFAULT_MODE": displayMode = new TrustedWebActivityDisplayMode.DefaultMode(); + break; } } break; diff --git a/example/ios/Flutter/Flutter.podspec b/example/ios/Flutter/Flutter.podspec new file mode 100644 index 000000000..8ce439439 --- /dev/null +++ b/example/ios/Flutter/Flutter.podspec @@ -0,0 +1,18 @@ +# +# NOTE: This podspec is NOT to be published. It is only used as a local source! +# This is a generated file; do not edit or check into version control. +# + +Pod::Spec.new do |s| + s.name = 'Flutter' + s.version = '1.0.0' + s.summary = 'A UI toolkit for beautiful and fast apps.' + s.homepage = 'https://flutter.dev' + s.license = { :type => 'BSD' } + s.author = { 'Flutter Dev Team' => 'flutter-dev@googlegroups.com' } + s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s } + s.ios.deployment_target = '11.0' + # Framework linking is handled by Flutter tooling, not CocoaPods. + # Add a placeholder to satisfy `s.dependency 'Flutter'` plugin podspecs. + s.vendored_frameworks = 'path/to/nothing' +end diff --git a/example/ios/Flutter/flutter_export_environment.sh b/example/ios/Flutter/flutter_export_environment.sh index ee7ac300e..4f083fcfd 100755 --- a/example/ios/Flutter/flutter_export_environment.sh +++ b/example/ios/Flutter/flutter_export_environment.sh @@ -1,13 +1,14 @@ #!/bin/sh # This is a generated file; do not edit or check into version control. -export "FLUTTER_ROOT=/Users/lorenzopichilli/fvm/versions/2.10.4" +export "FLUTTER_ROOT=/Users/lorenzopichilli/fvm/versions/3.3.5" export "FLUTTER_APPLICATION_PATH=/Users/lorenzopichilli/flutter_inappwebview_v5/example" export "COCOAPODS_PARALLEL_CODE_SIGN=true" -export "FLUTTER_TARGET=lib/main.dart" +export "FLUTTER_TARGET=/Users/lorenzopichilli/flutter_inappwebview_v5/example/lib/main.dart" export "FLUTTER_BUILD_DIR=build" export "FLUTTER_BUILD_NAME=1.0.0" export "FLUTTER_BUILD_NUMBER=1" +export "DART_DEFINES=Zmx1dHRlci5pbnNwZWN0b3Iuc3RydWN0dXJlZEVycm9ycz10cnVl,RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ==" export "DART_OBFUSCATION=false" export "TRACK_WIDGET_CREATION=true" export "TREE_SHAKE_ICONS=false" -export "PACKAGE_CONFIG=.dart_tool/package_config.json" +export "PACKAGE_CONFIG=/Users/lorenzopichilli/flutter_inappwebview_v5/example/.dart_tool/package_config.json" diff --git a/ios/Classes/Types/WKUserContentController.swift b/ios/Classes/Types/WKUserContentController.swift index 53c901a7a..eecba322b 100644 --- a/ios/Classes/Types/WKUserContentController.swift +++ b/ios/Classes/Types/WKUserContentController.swift @@ -276,7 +276,7 @@ extension WKUserContentController { var userScriptsUpdated: [WKUserScript] = [] for script in userScripts { - if !userScripts.contains(script) { + if !scriptsToRemove.contains(script) { userScriptsUpdated.append(script) } } @@ -296,6 +296,7 @@ extension WKUserContentController { for script in allUserOnlyScripts { if let scriptName = script.groupName, scriptName == groupName { scriptsToRemove.append(script) + userOnlyScripts[script.injectionTime]!.remove(script) } } removeUserScripts(scriptsToRemove: scriptsToRemove, shouldAddPreviousScripts: shouldAddPreviousScripts) @@ -307,6 +308,7 @@ extension WKUserContentController { for script in allPluginScripts { if let scriptName = script.groupName, scriptName == groupName { scriptsToRemove.append(script) + pluginScripts[script.injectionTime]!.remove(script) } } removeUserScripts(scriptsToRemove: scriptsToRemove, shouldAddPreviousScripts: shouldAddPreviousScripts) diff --git a/lib/src/in_app_webview/in_app_webview_controller.dart b/lib/src/in_app_webview/in_app_webview_controller.dart index d38edb060..0d16b9baa 100644 --- a/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/lib/src/in_app_webview/in_app_webview_controller.dart @@ -51,7 +51,10 @@ class InAppWebViewController { static MethodChannel _staticChannel = IN_APP_WEBVIEW_STATIC_CHANNEL; Map javaScriptHandlersMap = HashMap(); - List _userScripts = []; + final Map> _userScripts = { + UserScriptInjectionTime.AT_DOCUMENT_START: [], + UserScriptInjectionTime.AT_DOCUMENT_END: [] + }; Set _webMessageListenerObjNames = Set(); Map _injectedScriptsFromURL = {}; @@ -75,8 +78,22 @@ class InAppWebViewController { MethodChannel('com.pichillilorenzo/flutter_inappwebview_$id'); this._channel.setMethodCallHandler(handleMethod); this._webview = webview; - this._userScripts = - List.from(webview.initialUserScripts ?? []); + + final initialUserScripts = webview.initialUserScripts; + if (initialUserScripts != null) { + for (final userScript in initialUserScripts) { + if (userScript.injectionTime == + UserScriptInjectionTime.AT_DOCUMENT_START) { + this + ._userScripts[UserScriptInjectionTime.AT_DOCUMENT_START] + ?.add(userScript); + } else { + this + ._userScripts[UserScriptInjectionTime.AT_DOCUMENT_END] + ?.add(userScript); + } + } + } this._init(); } @@ -86,8 +103,22 @@ class InAppWebViewController { UnmodifiableListView? initialUserScripts) { this._channel = channel; this._inAppBrowser = inAppBrowser; - this._userScripts = - List.from(initialUserScripts ?? []); + + if (initialUserScripts != null) { + for (final userScript in initialUserScripts) { + if (userScript.injectionTime == + UserScriptInjectionTime.AT_DOCUMENT_START) { + this + ._userScripts[UserScriptInjectionTime.AT_DOCUMENT_START] + ?.add(userScript); + } else { + this + ._userScripts[UserScriptInjectionTime.AT_DOCUMENT_END] + ?.add(userScript); + } + } + } + this._init(); } @@ -2117,8 +2148,9 @@ class InAppWebViewController { Map args = {}; args.putIfAbsent('userScript', () => userScript.toMap()); - if (!_userScripts.contains(userScript)) { - _userScripts.add(userScript); + if (!(_userScripts[userScript.injectionTime]?.contains(userScript) ?? + false)) { + _userScripts[userScript.injectionTime]?.add(userScript); await _channel.invokeMethod('addUserScript', args); } } @@ -2148,12 +2180,12 @@ class InAppWebViewController { assert(_webview?.windowId == null || defaultTargetPlatform != TargetPlatform.iOS); - var index = _userScripts.indexOf(userScript); - if (index == -1) { + var index = _userScripts[userScript.injectionTime]?.indexOf(userScript); + if (index == null || index == -1) { return false; } - _userScripts.remove(userScript); + _userScripts[userScript.injectionTime]?.remove(userScript); Map args = {}; args.putIfAbsent('userScript', () => userScript.toMap()); args.putIfAbsent('index', () => index); @@ -2172,6 +2204,22 @@ class InAppWebViewController { assert(_webview?.windowId == null || defaultTargetPlatform != TargetPlatform.iOS); + final List userScriptsAtDocumentStart = List.from( + _userScripts[UserScriptInjectionTime.AT_DOCUMENT_START] ?? []); + for (final userScript in userScriptsAtDocumentStart) { + if (userScript.groupName == groupName) { + _userScripts[userScript.injectionTime]?.remove(userScript); + } + } + + final List userScriptsAtDocumentEnd = + List.from(_userScripts[UserScriptInjectionTime.AT_DOCUMENT_END] ?? []); + for (final userScript in userScriptsAtDocumentEnd) { + if (userScript.groupName == groupName) { + _userScripts[userScript.injectionTime]?.remove(userScript); + } + } + Map args = {}; args.putIfAbsent('groupName', () => groupName); await _channel.invokeMethod('removeUserScriptsByGroupName', args); @@ -2188,8 +2236,8 @@ class InAppWebViewController { assert(_webview?.windowId == null || defaultTargetPlatform != TargetPlatform.iOS); - for (var i = 0; i < userScripts.length; i++) { - await removeUserScript(userScript: userScripts[i]); + for (final userScript in userScripts) { + await removeUserScript(userScript: userScript); } } @@ -2204,7 +2252,9 @@ class InAppWebViewController { assert(_webview?.windowId == null || defaultTargetPlatform != TargetPlatform.iOS); - _userScripts.clear(); + _userScripts[UserScriptInjectionTime.AT_DOCUMENT_START]?.clear(); + _userScripts[UserScriptInjectionTime.AT_DOCUMENT_END]?.clear(); + Map args = {}; await _channel.invokeMethod('removeAllUserScripts', args); } diff --git a/pubspec.yaml b/pubspec.yaml index c061c2e3a..a6b7ff061 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_inappwebview description: A Flutter plugin that allows you to add an inline webview, to use an headless webview, and to open an in-app browser window. -version: 5.7.1 +version: 5.7.1+1 homepage: https://inappwebview.dev/ repository: https://github.com/pichillilorenzo/flutter_inappwebview issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues