From 499ab2a0bc0b507624bf7667465e1b8191fe8636 Mon Sep 17 00:00:00 2001 From: Xu Mengtong <> Date: Fri, 24 May 2019 18:00:38 +0800 Subject: [PATCH] add new option to control the contentMode in Android platform --- .../InAppWebView/InAppWebView.java | 20 +++++++++++++++++++ .../InAppWebView/InAppWebViewOptions.java | 1 + 2 files changed, 21 insertions(+) diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java index cdf8e313..a7c6d8f6 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebView.java @@ -191,6 +191,16 @@ public class InAppWebView extends WebView { if (options.transparentBackground) { setBackgroundColor(Color.TRANSPARENT); } + + if (!options.mixedContentMode.isEmpty()) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + if (options.mixedContentMode.equals("MIXED_CONTENT_COMPATIBILITY_MODE")) { + settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE); + } else if (options.mixedContentMode.equals("MIXED_CONTENT_ALWAYS_ALLOW")) { + settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); + } + } + } } public void loadUrl(String url, MethodChannel.Result result) { @@ -355,6 +365,16 @@ public class InAppWebView extends WebView { } } + if (newOptionsMap.get("mixedContentMode") != null && options.mixedContentMode != newOptions.mixedContentMode) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + if (newOptions.mixedContentMode.equals("MIXED_CONTENT_COMPATIBILITY_MODE")) { + settings.setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE); + } else if (newOptions.mixedContentMode.equals("MIXED_CONTENT_ALWAYS_ALLOW")) { + settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); + } + } + } + options = newOptions; } diff --git a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewOptions.java b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewOptions.java index 9391ada7..056cb88c 100644 --- a/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewOptions.java +++ b/android/src/main/java/com/pichillilorenzo/flutter_inappbrowser/InAppWebView/InAppWebViewOptions.java @@ -24,4 +24,5 @@ public class InAppWebViewOptions extends Options { public boolean useWideViewPort = true; public boolean safeBrowsingEnabled = true; public boolean transparentBackground = false; + public String mixedContentMode = "MIXED_CONTENT_NEVER_ALLOW"; }