You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by er...@apache.org on 2021/07/30 08:08:28 UTC
[cordova-android] branch master updated: feat: support http w/
content src fix (#1298)
This is an automated email from the ASF dual-hosted git repository.
erisu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cordova-android.git
The following commit(s) were added to refs/heads/master by this push:
new 1636d70 feat: support http w/ content src fix (#1298)
1636d70 is described below
commit 1636d70f253e3acf364dd90d8db0788e8a445844
Author: エリス <er...@users.noreply.github.com>
AuthorDate: Fri Jul 30 17:08:23 2021 +0900
feat: support http w/ content src fix (#1298)
---
.../src/org/apache/cordova/ConfigXmlParser.java | 50 ++++++++++++++++------
1 file changed, 36 insertions(+), 14 deletions(-)
diff --git a/framework/src/org/apache/cordova/ConfigXmlParser.java b/framework/src/org/apache/cordova/ConfigXmlParser.java
index 9c14e55..e936517 100644
--- a/framework/src/org/apache/cordova/ConfigXmlParser.java
+++ b/framework/src/org/apache/cordova/ConfigXmlParser.java
@@ -24,16 +24,19 @@ import java.util.ArrayList;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
-
import android.content.Context;
public class ConfigXmlParser {
private static String TAG = "ConfigXmlParser";
- private String launchUrl = null;
+ private static String SCHEME_HTTP = "http";
+ private static String SCHEME_HTTPS = "https";
+ private static String DEFAULT_HOSTNAME = "localhost";
+
+ private String launchUrl;
+ private String contentSrc;
private CordovaPreferences prefs = new CordovaPreferences();
private ArrayList<PluginEntry> pluginEntries = new ArrayList<PluginEntry>(20);
@@ -47,11 +50,7 @@ public class ConfigXmlParser {
public String getLaunchUrl() {
if (launchUrl == null) {
- launchUrl = "https://" + this.prefs.getString("hostname", "localhost");
- }
-
- if (this.prefs.getBoolean("AndroidInsecureFileModeEnabled", false)) {
- launchUrl = "file:///android_asset/www/index.html";
+ setStartUrl(contentSrc);
}
return launchUrl;
@@ -130,7 +129,10 @@ public class ConfigXmlParser {
else if (strNode.equals("content")) {
String src = xml.getAttributeValue(null, "src");
if (src != null) {
- setStartUrl(src);
+ contentSrc = src;
+ } else {
+ // Default
+ contentSrc = "index.html";
}
}
}
@@ -147,20 +149,40 @@ public class ConfigXmlParser {
}
}
+ private String getLaunchUrlPrefix() {
+ if (prefs.getBoolean("AndroidInsecureFileModeEnabled", false)) {
+ return "file:///android_asset/www/";
+ } else {
+ String scheme = prefs.getString("scheme", SCHEME_HTTPS).toLowerCase();
+ String hostname = prefs.getString("hostname", DEFAULT_HOSTNAME);
+
+ if (!scheme.contentEquals(SCHEME_HTTP) && !scheme.contentEquals(SCHEME_HTTPS)) {
+ LOG.d(TAG, "The provided scheme \"" + scheme + "\" is not valid. " +
+ "Defaulting to \"" + SCHEME_HTTPS + "\". " +
+ "(Valid Options=" + SCHEME_HTTP + "," + SCHEME_HTTPS + ")");
+
+ scheme = SCHEME_HTTPS;
+ }
+
+ return scheme + "://" + hostname + '/';
+ }
+ }
+
private void setStartUrl(String src) {
Pattern schemeRegex = Pattern.compile("^[a-z-]+://");
Matcher matcher = schemeRegex.matcher(src);
+
if (matcher.find()) {
launchUrl = src;
} else {
+ String launchUrlPrefix = getLaunchUrlPrefix();
+
+ // remove leading slash, "/", from content src if existing,
if (src.charAt(0) == '/') {
src = src.substring(1);
}
- if (this.prefs.getBoolean("AndroidInsecureFileModeEnabled", false)) {
- launchUrl = "file:///android_asset/www/" + src;
- } else {
- launchUrl = "https://" + this.prefs.getString("hostname", "localhost") + "/" + src;
- }
+
+ launchUrl = launchUrlPrefix + src;
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org