Skip to content

Commit 486d412

Browse files
authored
feat: Allows configuration of Mixed Content Mode (#240)
BREAKING CHANGE: changes the default from 1 (never) to 0 (always) #231
1 parent f7a551e commit 486d412

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,23 @@ Preferences available for both iOS and Android platforms
5454

5555
The default port the server will listen on. _You should change this to a random port number!_
5656

57+
#### MixedContentMode
58+
59+
60+
```xml
61+
<preference name="MixedContentMode" value="2" />
62+
```
63+
64+
Configures the WebView's behavior when an origin attempts to load a resource from a different origin.
65+
66+
Default value is `0` (`MIXED_CONTENT_ALWAYS_ALLOW`), which allows loading resources from other origins.
67+
68+
Other possible values are `1` (`MIXED_CONTENT_NEVER_ALLOW`) and `2` (`MIXED_CONTENT_COMPATIBILITY_MODE`)
69+
70+
71+
[Android documentation](https://developer.android.com/reference/android/webkit/WebSettings.html#setMixedContentMode(int))
72+
73+
5774
### iOS Preferences
5875

5976
Preferences only available for iOS platform

src/android/com/ionicframework/cordova/webview/IonicWebViewEngine.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import android.util.Log;
1313
import android.webkit.WebResourceRequest;
1414
import android.webkit.WebResourceResponse;
15+
import android.webkit.WebSettings;
1516
import android.webkit.WebView;
1617
import org.apache.cordova.ConfigXmlParser;
1718
import org.apache.cordova.CordovaInterface;
@@ -67,6 +68,11 @@ public void init(CordovaWebView parentWebView, CordovaInterface cordova, final C
6768
webView.setWebViewClient(new ServerClient(this, parser));
6869

6970
super.init(parentWebView, cordova, client, resourceApi, pluginManager, nativeToJsMessageQueue);
71+
if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
72+
final WebSettings settings = webView.getSettings();
73+
int mode = preferences.getInteger("MixedContentMode", 0);
74+
settings.setMixedContentMode(mode);
75+
}
7076
SharedPreferences prefs = cordova.getActivity().getApplicationContext().getSharedPreferences(IonicWebView.WEBVIEW_PREFS_NAME, Activity.MODE_PRIVATE);
7177
String path = prefs.getString(IonicWebView.CDV_SERVER_PATH, null);
7278
if (!isDeployDisabled() && !isNewBinary() && path != null && !path.isEmpty()) {

0 commit comments

Comments
 (0)