diff --git a/flutter_inappwebview_android/CHANGELOG.md b/flutter_inappwebview_android/CHANGELOG.md index 3c73e8c1..c149f379 100644 --- a/flutter_inappwebview_android/CHANGELOG.md +++ b/flutter_inappwebview_android/CHANGELOG.md @@ -1,3 +1,8 @@ +## 1.0.6 + +- Fixed "getFavicons: _TypeError: type '_Map' is not a subtype of type 'Iterable'" [#1897](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1897) +- Fixed "onClosed not considering back navigation or up button / close button in ChromeSafariBrowser when using noHistory: true" [#1882](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1882) + ## 1.0.5 - Call `super.dispose();` on `InAppBrowser` and `ChromeSafari` implementations diff --git a/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/InAppWebViewFlutterPlugin.java b/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/InAppWebViewFlutterPlugin.java index 56bd6ac8..b475a0e3 100755 --- a/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/InAppWebViewFlutterPlugin.java +++ b/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/InAppWebViewFlutterPlugin.java @@ -8,6 +8,7 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import com.pichillilorenzo.flutter_inappwebview_android.chrome_custom_tabs.ChromeSafariBrowserManager; +import com.pichillilorenzo.flutter_inappwebview_android.chrome_custom_tabs.NoHistoryCustomTabsActivityCallbacks; import com.pichillilorenzo.flutter_inappwebview_android.credential_database.CredentialDatabaseHandler; import com.pichillilorenzo.flutter_inappwebview_android.headless_in_app_webview.HeadlessInAppWebViewManager; import com.pichillilorenzo.flutter_inappwebview_android.in_app_browser.InAppBrowserManager; @@ -40,6 +41,8 @@ public class InAppWebViewFlutterPlugin implements FlutterPlugin, ActivityAware { @Nullable public ChromeSafariBrowserManager chromeSafariBrowserManager; @Nullable + public NoHistoryCustomTabsActivityCallbacks noHistoryCustomTabsActivityCallbacks; + @Nullable public InAppWebViewManager inAppWebViewManager; @Nullable public MyCookieManager myCookieManager; @@ -103,6 +106,7 @@ public class InAppWebViewFlutterPlugin implements FlutterPlugin, ActivityAware { inAppBrowserManager = new InAppBrowserManager(this); headlessInAppWebViewManager = new HeadlessInAppWebViewManager(this); chromeSafariBrowserManager = new ChromeSafariBrowserManager(this); + noHistoryCustomTabsActivityCallbacks = new NoHistoryCustomTabsActivityCallbacks(this); flutterWebViewFactory = new FlutterWebViewFactory(this); platformViewRegistry.registerViewFactory( FlutterWebViewFactory.VIEW_TYPE_ID, flutterWebViewFactory); @@ -144,6 +148,10 @@ public class InAppWebViewFlutterPlugin implements FlutterPlugin, ActivityAware { chromeSafariBrowserManager.dispose(); chromeSafariBrowserManager = null; } + if (noHistoryCustomTabsActivityCallbacks != null) { + noHistoryCustomTabsActivityCallbacks.dispose(); + noHistoryCustomTabsActivityCallbacks = null; + } if (myCookieManager != null) { myCookieManager.dispose(); myCookieManager = null; @@ -190,23 +198,39 @@ public class InAppWebViewFlutterPlugin implements FlutterPlugin, ActivityAware { public void onAttachedToActivity(ActivityPluginBinding activityPluginBinding) { this.activityPluginBinding = activityPluginBinding; this.activity = activityPluginBinding.getActivity(); + + if (noHistoryCustomTabsActivityCallbacks != null) { + this.activity.getApplication().registerActivityLifecycleCallbacks(noHistoryCustomTabsActivityCallbacks.activityLifecycleCallbacks); + } } @Override public void onDetachedFromActivityForConfigChanges() { - this.activityPluginBinding = null; - this.activity = null; + if (activity != null && noHistoryCustomTabsActivityCallbacks != null) { + this.activity.getApplication().unregisterActivityLifecycleCallbacks(noHistoryCustomTabsActivityCallbacks.activityLifecycleCallbacks); + } + + activityPluginBinding = null; + activity = null; } @Override public void onReattachedToActivityForConfigChanges(ActivityPluginBinding activityPluginBinding) { this.activityPluginBinding = activityPluginBinding; this.activity = activityPluginBinding.getActivity(); + + if (noHistoryCustomTabsActivityCallbacks != null) { + this.activity.getApplication().registerActivityLifecycleCallbacks(noHistoryCustomTabsActivityCallbacks.activityLifecycleCallbacks); + } } @Override public void onDetachedFromActivity() { - this.activityPluginBinding = null; - this.activity = null; + if (activity != null && noHistoryCustomTabsActivityCallbacks != null) { + this.activity.getApplication().unregisterActivityLifecycleCallbacks(noHistoryCustomTabsActivityCallbacks.activityLifecycleCallbacks); + } + + activityPluginBinding = null; + activity = null; } } diff --git a/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/chrome_custom_tabs/ChromeCustomTabsActivity.java b/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/chrome_custom_tabs/ChromeCustomTabsActivity.java index 05d41a26..444bc25d 100755 --- a/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/chrome_custom_tabs/ChromeCustomTabsActivity.java +++ b/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/chrome_custom_tabs/ChromeCustomTabsActivity.java @@ -47,7 +47,8 @@ public class ChromeCustomTabsActivity extends Activity implements Disposable { public CustomTabActivityHelper customTabActivityHelper = new CustomTabActivityHelper(); @Nullable public CustomTabsSession customTabsSession; - protected final int CHROME_CUSTOM_TAB_REQUEST_CODE = 100; + public final static int CHROME_CUSTOM_TAB_REQUEST_CODE = 100; + public final static int NO_HISTORY_CHROME_CUSTOM_TAB_REQUEST_CODE = 101; protected boolean onOpened = false; protected boolean onCompletedInitialLoad = false; protected boolean isBindSuccess = false; @@ -104,6 +105,10 @@ public class ChromeCustomTabsActivity extends Activity implements Disposable { menuItems.add(CustomTabsMenuItem.fromMap(menuItem)); } + if (customSettings.noHistory && manager.plugin.noHistoryCustomTabsActivityCallbacks != null) { + manager.plugin.noHistoryCustomTabsActivityCallbacks.noHistoryBrowserIDs.put(id, id); + } + final ChromeCustomTabsActivity chromeCustomTabsActivity = this; customTabActivityHelper.setConnectionCallback(new CustomTabActivityHelper.ConnectionCallback() { diff --git a/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/chrome_custom_tabs/NoHistoryCustomTabsActivityCallbacks.java b/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/chrome_custom_tabs/NoHistoryCustomTabsActivityCallbacks.java new file mode 100644 index 00000000..3ada33e7 --- /dev/null +++ b/flutter_inappwebview_android/android/src/main/java/com/pichillilorenzo/flutter_inappwebview_android/chrome_custom_tabs/NoHistoryCustomTabsActivityCallbacks.java @@ -0,0 +1,77 @@ +package com.pichillilorenzo.flutter_inappwebview_android.chrome_custom_tabs; + +import android.app.Activity; +import android.app.Application; +import android.os.Bundle; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import com.pichillilorenzo.flutter_inappwebview_android.InAppWebViewFlutterPlugin; +import com.pichillilorenzo.flutter_inappwebview_android.types.Disposable; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import io.flutter.embedding.android.FlutterActivity; + +public class NoHistoryCustomTabsActivityCallbacks implements Disposable { + @Nullable + public InAppWebViewFlutterPlugin plugin; + + public final Map noHistoryBrowserIDs = new HashMap<>(); + + public NoHistoryCustomTabsActivityCallbacks(@NonNull final InAppWebViewFlutterPlugin plugin) { + this.plugin = plugin; + } + + public Application.ActivityLifecycleCallbacks activityLifecycleCallbacks = new Application.ActivityLifecycleCallbacks() { + @Override + public void onActivityCreated(@NonNull Activity activity, @Nullable Bundle savedInstanceState) { + } + + @Override + public void onActivityStarted(@NonNull Activity activity) { + } + + @Override + public void onActivityResumed(@NonNull Activity activity) { + if (activity instanceof FlutterActivity && plugin != null && plugin.chromeSafariBrowserManager != null) { + Collection browserIds = noHistoryBrowserIDs.values(); + for (String browserId : browserIds) { + if (browserId != null) { + noHistoryBrowserIDs.put(browserId, null); + ChromeCustomTabsActivity browser = plugin.chromeSafariBrowserManager.browsers.get(browserId); + if (browser != null) { + browser.close(); + browser.dispose(); + } + } + } + } + } + + @Override + public void onActivityPaused(@NonNull Activity activity) { + } + + @Override + public void onActivityStopped(@NonNull Activity activity) { + } + + @Override + public void onActivitySaveInstanceState(@NonNull Activity activity, @NonNull Bundle outState) { + } + + @Override + public void onActivityDestroyed(@NonNull Activity activity) { + } + }; + + @Override + public void dispose() { + noHistoryBrowserIDs.clear(); + plugin = null; + } +} 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 deb5e076..5bf7a958 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 @@ -1712,7 +1712,7 @@ class AndroidInAppWebViewController extends PlatformInAppWebViewController manifestResponse.headers.contentType?.mimeType == "application/json"; } catch (e) { developer.log("Manifest file not found: " + e.toString(), - name: this.runtimeType.toString()); + name: runtimeType.toString()); } if (manifestFound) { @@ -1725,9 +1725,12 @@ class AndroidInAppWebViewController extends PlatformInAppWebViewController icon["src"], icon["rel"], icon["sizes"], true)); } } - } on FormatException catch (_) { - /// The [manifestResponse] might not has a valid JSON string, catch and - /// ignore the error + } catch (e) { + developer.log( + "Cannot get favicons from Manifest file. It might not have a valid format: " + + e.toString(), + error: e, + name: runtimeType.toString()); } } diff --git a/flutter_inappwebview_android/pubspec.yaml b/flutter_inappwebview_android/pubspec.yaml index 8d9c7f69..e7cbe12c 100644 --- a/flutter_inappwebview_android/pubspec.yaml +++ b/flutter_inappwebview_android/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_inappwebview_android description: Android implementation of the flutter_inappwebview plugin. -version: 1.0.5 +version: 1.0.6 homepage: https://inappwebview.dev/ repository: https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_android issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues diff --git a/flutter_inappwebview_ios/CHANGELOG.md b/flutter_inappwebview_ios/CHANGELOG.md index ebe7f664..4194ec02 100644 --- a/flutter_inappwebview_ios/CHANGELOG.md +++ b/flutter_inappwebview_ios/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.7 + +- Fixed "getFavicons: _TypeError: type '_Map' is not a subtype of type 'Iterable'" [#1897](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1897) + ## 1.0.6 - Possible fix for "iOS Fatal Crash" [#1894](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1894) diff --git a/flutter_inappwebview_ios/lib/src/in_app_webview/in_app_webview_controller.dart b/flutter_inappwebview_ios/lib/src/in_app_webview/in_app_webview_controller.dart index e51f3490..6447b15f 100644 --- a/flutter_inappwebview_ios/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/flutter_inappwebview_ios/lib/src/in_app_webview/in_app_webview_controller.dart @@ -1689,7 +1689,7 @@ class IOSInAppWebViewController extends PlatformInAppWebViewController } } catch (e) { developer.log("/favicon.ico file not found: " + e.toString(), - name: this.runtimeType.toString()); + name: runtimeType.toString()); } // try to get the manifest file @@ -1721,9 +1721,12 @@ class IOSInAppWebViewController extends PlatformInAppWebViewController icon["src"], icon["rel"], icon["sizes"], true)); } } - } on FormatException catch (_) { - /// The [manifestResponse] might not has a valid JSON string, catch and - /// ignore the error + } catch (e) { + developer.log( + "Cannot get favicons from Manifest file. It might not have a valid format: " + + e.toString(), + error: e, + name: runtimeType.toString()); } } diff --git a/flutter_inappwebview_ios/pubspec.yaml b/flutter_inappwebview_ios/pubspec.yaml index fd11fd00..5a7d624d 100644 --- a/flutter_inappwebview_ios/pubspec.yaml +++ b/flutter_inappwebview_ios/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_inappwebview_ios description: iOS implementation of the flutter_inappwebview plugin. -version: 1.0.6 +version: 1.0.7 homepage: https://inappwebview.dev/ repository: https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_ios issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues diff --git a/flutter_inappwebview_macos/CHANGELOG.md b/flutter_inappwebview_macos/CHANGELOG.md index 0370a153..e94eeb23 100644 --- a/flutter_inappwebview_macos/CHANGELOG.md +++ b/flutter_inappwebview_macos/CHANGELOG.md @@ -1,3 +1,7 @@ +## 1.0.5 + +- Fixed "getFavicons: _TypeError: type '_Map' is not a subtype of type 'Iterable'" [#1897](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1897) + ## 1.0.4 - Possible fix for "iOS Fatal Crash" [#1894](https://github.com/pichillilorenzo/flutter_inappwebview/issues/1894) diff --git a/flutter_inappwebview_macos/lib/src/in_app_webview/in_app_webview_controller.dart b/flutter_inappwebview_macos/lib/src/in_app_webview/in_app_webview_controller.dart index 4c34d299..ef49f5cf 100644 --- a/flutter_inappwebview_macos/lib/src/in_app_webview/in_app_webview_controller.dart +++ b/flutter_inappwebview_macos/lib/src/in_app_webview/in_app_webview_controller.dart @@ -1690,7 +1690,7 @@ class MacOSInAppWebViewController extends PlatformInAppWebViewController } } catch (e) { developer.log("/favicon.ico file not found: " + e.toString(), - name: this.runtimeType.toString()); + name: runtimeType.toString()); } // try to get the manifest file @@ -1722,9 +1722,12 @@ class MacOSInAppWebViewController extends PlatformInAppWebViewController icon["src"], icon["rel"], icon["sizes"], true)); } } - } on FormatException catch (_) { - /// The [manifestResponse] might not has a valid JSON string, catch and - /// ignore the error + } catch (e) { + developer.log( + "Cannot get favicons from Manifest file. It might not have a valid format: " + + e.toString(), + error: e, + name: runtimeType.toString()); } } diff --git a/flutter_inappwebview_macos/pubspec.yaml b/flutter_inappwebview_macos/pubspec.yaml index 33732b60..818f5471 100644 --- a/flutter_inappwebview_macos/pubspec.yaml +++ b/flutter_inappwebview_macos/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_inappwebview_macos description: macOS implementation of the flutter_inappwebview plugin. -version: 1.0.4 +version: 1.0.5 homepage: https://inappwebview.dev/ repository: https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_macos issue_tracker: https://github.com/pichillilorenzo/flutter_inappwebview/issues