From 38aa5cf11f2b9c301076f72f9131a24f233905b6 Mon Sep 17 00:00:00 2001 From: Koji Nakamaru Date: Fri, 9 Aug 2024 18:39:45 +0900 Subject: [PATCH 1/2] introduced SetMixedContentMode (cf. #1084). --- .../net/gree/unitywebview/CWebViewPlugin.java | 16 ++++++++++++++++ .../net/gree/unitywebview/CWebViewPlugin.java | 16 ++++++++++++++++ plugins/WebViewObject.cs | 15 +++++++++++++++ 3 files changed, 47 insertions(+) diff --git a/plugins/Android/webview-nofragment/src/main/java/net/gree/unitywebview/CWebViewPlugin.java b/plugins/Android/webview-nofragment/src/main/java/net/gree/unitywebview/CWebViewPlugin.java index 5a8b9896..3efd55a3 100644 --- a/plugins/Android/webview-nofragment/src/main/java/net/gree/unitywebview/CWebViewPlugin.java +++ b/plugins/Android/webview-nofragment/src/main/java/net/gree/unitywebview/CWebViewPlugin.java @@ -1062,4 +1062,20 @@ public void SetTextZoom(final int textZoom) mWebView.getSettings().setTextZoom(textZoom); }}); } + + public void SetMixedContentMode(final int mode) + { + final Activity a = UnityPlayer.currentActivity; + if (CWebViewPlugin.isDestroyed(a)) { + return; + } + a.runOnUiThread(new Runnable() {public void run() { + if (mWebView == null) { + return; + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + mWebView.getSettings().setMixedContentMode(mode); + } + }}); + } } diff --git a/plugins/Android/webview/src/main/java/net/gree/unitywebview/CWebViewPlugin.java b/plugins/Android/webview/src/main/java/net/gree/unitywebview/CWebViewPlugin.java index 7d873865..15d8fdb3 100644 --- a/plugins/Android/webview/src/main/java/net/gree/unitywebview/CWebViewPlugin.java +++ b/plugins/Android/webview/src/main/java/net/gree/unitywebview/CWebViewPlugin.java @@ -1422,4 +1422,20 @@ public void SetTextZoom(final int textZoom) mWebView.getSettings().setTextZoom(textZoom); }}); } + + public void SetMixedContentMode(final int mode) + { + final Activity a = UnityPlayer.currentActivity; + if (CWebViewPlugin.isDestroyed(a)) { + return; + } + a.runOnUiThread(new Runnable() {public void run() { + if (mWebView == null) { + return; + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + mWebView.getSettings().setMixedContentMode(mode); + } + }}); + } } diff --git a/plugins/WebViewObject.cs b/plugins/WebViewObject.cs index cb6d34ec..324580f7 100644 --- a/plugins/WebViewObject.cs +++ b/plugins/WebViewObject.cs @@ -1484,6 +1484,21 @@ public void SetTextZoom(int textZoom) #endif } + public void SetMixedContentMode(int mode) // 0: MIXED_CONTENT_ALWAYS_ALLOW, 1: MIXED_CONTENT_NEVER_ALLOW, 2: MIXED_CONTENT_COMPATIBILITY_MODE + { +#if UNITY_WEBPLAYER || UNITY_WEBGL + //TODO: UNSUPPORTED +#elif UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_EDITOR_LINUX + //TODO: UNSUPPORTED +#elif UNITY_IPHONE && !UNITY_EDITOR + //TODO: UNSUPPORTED +#elif UNITY_ANDROID && !UNITY_EDITOR + if (webView == null) + return; + webView.Call("SetMixedContentMode", mode); +#endif + } + #if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX void OnApplicationFocus(bool focus) { From 1b837227d8a0861512c4e647e3694fdaa869d734 Mon Sep 17 00:00:00 2001 From: Koji Nakamaru Date: Fri, 9 Aug 2024 19:36:03 +0900 Subject: [PATCH 2/2] added a comment about SetMixedContentMode in SampleWebView.cs. --- sample/Assets/Scripts/SampleWebView.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/sample/Assets/Scripts/SampleWebView.cs b/sample/Assets/Scripts/SampleWebView.cs index f2d2515b..9f2d025f 100644 --- a/sample/Assets/Scripts/SampleWebView.cs +++ b/sample/Assets/Scripts/SampleWebView.cs @@ -152,6 +152,7 @@ IEnumerator Start() webViewObject.SetMargins(5, 100, 5, Screen.height / 4); webViewObject.SetTextZoom(100); // android only. cf. https://stackoverflow.com/questions/21647641/android-webview-set-font-size-system-default/47017410#47017410 + //webViewObject.SetMixedContentMode(2); // android only. 0: MIXED_CONTENT_ALWAYS_ALLOW, 1: MIXED_CONTENT_NEVER_ALLOW, 2: MIXED_CONTENT_COMPATIBILITY_MODE webViewObject.SetVisibility(true); #if !UNITY_WEBPLAYER && !UNITY_WEBGL