Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduced SetMixedContentMode #1085

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}});
}
}
15 changes: 15 additions & 0 deletions plugins/WebViewObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
1 change: 1 addition & 0 deletions sample/Assets/Scripts/SampleWebView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down