From 7ff9638cd54416b7580c052c04d44390a35470e2 Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Wed, 28 Apr 2021 11:23:10 +0200 Subject: [PATCH 1/3] add backwards compatibility mode for WebViewAssetLoader --- framework/src/org/apache/cordova/ConfigXmlParser.java | 7 ++++++- .../org/apache/cordova/engine/SystemWebViewEngine.java | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/framework/src/org/apache/cordova/ConfigXmlParser.java b/framework/src/org/apache/cordova/ConfigXmlParser.java index ae9b57fd1b..bdb02ef668 100644 --- a/framework/src/org/apache/cordova/ConfigXmlParser.java +++ b/framework/src/org/apache/cordova/ConfigXmlParser.java @@ -46,9 +46,14 @@ public ArrayList getPluginEntries() { } public String getLaunchUrl() { - if (launchUrl == null) { + if (launchUrl == null) { launchUrl = "https://" + this.prefs.getString("hostname", "localhost"); } + + if (this.prefs.getBoolean("InsecureFileMode", false)) { + launchUrl = "file:///android_asset/www/index.html"; + } + return launchUrl; } diff --git a/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java b/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java index 2921d3d091..436c1020b0 100755 --- a/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java +++ b/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java @@ -159,6 +159,14 @@ private void initWebViewSettings() { settings.setSaveFormData(false); settings.setSavePassword(false); + if (preferences.getBoolean("InsecureFileMode", false)) { + //These settings are deprecated and loading content via file:// URLs is generally discouraged, + //but we allow this for compatibility reasons + LOG.d(TAG, "Enabled insecure file access"); + settings.setAllowFileAccess(true); + settings.setAllowUniversalAccessFromFileURLs(true); + } + settings.setMediaPlaybackRequiresUserGesture(false); // Enable database From fce8f2a36fa5d98e298e6ba2d3adaba4053bfaad Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Mon, 3 May 2021 10:00:01 +0200 Subject: [PATCH 2/3] change preference name --- framework/src/org/apache/cordova/ConfigXmlParser.java | 2 +- .../src/org/apache/cordova/engine/SystemWebViewEngine.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/framework/src/org/apache/cordova/ConfigXmlParser.java b/framework/src/org/apache/cordova/ConfigXmlParser.java index bdb02ef668..c754ed344b 100644 --- a/framework/src/org/apache/cordova/ConfigXmlParser.java +++ b/framework/src/org/apache/cordova/ConfigXmlParser.java @@ -50,7 +50,7 @@ public String getLaunchUrl() { launchUrl = "https://" + this.prefs.getString("hostname", "localhost"); } - if (this.prefs.getBoolean("InsecureFileMode", false)) { + if (this.prefs.getBoolean("AndroidInsecureFileModeEnabled", false)) { launchUrl = "file:///android_asset/www/index.html"; } diff --git a/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java b/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java index 436c1020b0..ff37f9b6dd 100755 --- a/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java +++ b/framework/src/org/apache/cordova/engine/SystemWebViewEngine.java @@ -159,7 +159,7 @@ private void initWebViewSettings() { settings.setSaveFormData(false); settings.setSavePassword(false); - if (preferences.getBoolean("InsecureFileMode", false)) { + if (preferences.getBoolean("AndroidInsecureFileModeEnabled", false)) { //These settings are deprecated and loading content via file:// URLs is generally discouraged, //but we allow this for compatibility reasons LOG.d(TAG, "Enabled insecure file access"); From 615f9461c3798f8c4729097d02f3241d30feb8a2 Mon Sep 17 00:00:00 2001 From: Niklas Merz Date: Mon, 3 May 2021 15:06:32 +0200 Subject: [PATCH 3/3] Support AndroidInsecureFileModeEnabled in setStartUrl --- framework/src/org/apache/cordova/ConfigXmlParser.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/framework/src/org/apache/cordova/ConfigXmlParser.java b/framework/src/org/apache/cordova/ConfigXmlParser.java index c754ed344b..17b47b06c4 100644 --- a/framework/src/org/apache/cordova/ConfigXmlParser.java +++ b/framework/src/org/apache/cordova/ConfigXmlParser.java @@ -147,7 +147,11 @@ private void setStartUrl(String src) { if (src.charAt(0) == '/') { src = src.substring(1); } - launchUrl = "https://" + this.prefs.getString("hostname", "localhost") + "/" + src; + if (this.prefs.getBoolean("AndroidInsecureFileModeEnabled", false)) { + launchUrl = "file:///android_asset/www/" + src; + } else { + launchUrl = "https://" + this.prefs.getString("hostname", "localhost") + "/" + src; + } } } }