mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-07 23:03:11 +08:00
Add configurable start location to config.xml and template
Still possible to hardcode, there's a comment in the template showing how that can be done.
This commit is contained in:
parent
8ac15048cd
commit
ae431aec12
@ -29,7 +29,8 @@ public class __ACTIVITY__ extends DroidGap
|
|||||||
{
|
{
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
Config.init(this);
|
Config.init(this);
|
||||||
super.loadUrl("file:///android_asset/www/index.html");
|
super.loadUrl(Config.getStartUrl());
|
||||||
|
//super.loadUrl("file:///android_asset/www/index.html")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -29,6 +29,9 @@
|
|||||||
<!-- <access origin="https://example.com" subdomains="true" /> such as above, but including subdomains, such as www -->
|
<!-- <access origin="https://example.com" subdomains="true" /> such as above, but including subdomains, such as www -->
|
||||||
<access origin=".*"/>
|
<access origin=".*"/>
|
||||||
|
|
||||||
|
<!-- <content src="http://mysite.com/myapp.html" /> for external pages -->
|
||||||
|
<content src="index.html" />
|
||||||
|
|
||||||
<log level="DEBUG"/>
|
<log level="DEBUG"/>
|
||||||
<preference name="useBrowserHistory" value="true" />
|
<preference name="useBrowserHistory" value="true" />
|
||||||
<preference name="exit-on-suspend" value="false" />
|
<preference name="exit-on-suspend" value="false" />
|
||||||
|
@ -44,6 +44,7 @@ public class Config {
|
|||||||
|
|
||||||
private ArrayList<Pattern> whiteList = new ArrayList<Pattern>();
|
private ArrayList<Pattern> whiteList = new ArrayList<Pattern>();
|
||||||
private HashMap<String, Boolean> whiteListCache = new HashMap<String, Boolean>();
|
private HashMap<String, Boolean> whiteListCache = new HashMap<String, Boolean>();
|
||||||
|
private String startUrl;
|
||||||
|
|
||||||
private static Config self = null;
|
private static Config self = null;
|
||||||
|
|
||||||
@ -90,7 +91,7 @@ public class Config {
|
|||||||
String origin = xml.getAttributeValue(null, "origin");
|
String origin = xml.getAttributeValue(null, "origin");
|
||||||
String subdomains = xml.getAttributeValue(null, "subdomains");
|
String subdomains = xml.getAttributeValue(null, "subdomains");
|
||||||
if (origin != null) {
|
if (origin != null) {
|
||||||
addWhiteListEntry(origin, (subdomains != null) && (subdomains.compareToIgnoreCase("true") == 0));
|
this._addWhiteListEntry(origin, (subdomains != null) && (subdomains.compareToIgnoreCase("true") == 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (strNode.equals("log")) {
|
else if (strNode.equals("log")) {
|
||||||
@ -109,6 +110,25 @@ public class Config {
|
|||||||
|
|
||||||
action.getIntent().putExtra(name, value);
|
action.getIntent().putExtra(name, value);
|
||||||
}
|
}
|
||||||
|
else if (strNode.equals("content")) {
|
||||||
|
String src = xml.getAttributeValue(null, "src");
|
||||||
|
|
||||||
|
LOG.i("CordovaLog", "Found start page location: %s", src);
|
||||||
|
|
||||||
|
if (src != null) {
|
||||||
|
Pattern schemeRegex = Pattern.compile("^[a-z]+://");
|
||||||
|
Matcher matcher = schemeRegex.matcher(src);
|
||||||
|
if (matcher.find()) {
|
||||||
|
startUrl = src;
|
||||||
|
} else {
|
||||||
|
if (src.charAt(0) == '/') {
|
||||||
|
src = src.substring(1);
|
||||||
|
}
|
||||||
|
startUrl = "file:///android_asset/www/" + src;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -132,28 +152,33 @@ public class Config {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self._addWhiteListEntry(origin, subdomains);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void _addWhiteListEntry(String origin, boolean subdomains) {
|
||||||
try {
|
try {
|
||||||
// Unlimited access to network resources
|
// Unlimited access to network resources
|
||||||
if (origin.compareTo("*") == 0) {
|
if (origin.compareTo("*") == 0) {
|
||||||
LOG.d(TAG, "Unlimited access to network resources");
|
LOG.d(TAG, "Unlimited access to network resources");
|
||||||
self.whiteList.add(Pattern.compile(".*"));
|
this.whiteList.add(Pattern.compile(".*"));
|
||||||
} else { // specific access
|
} else { // specific access
|
||||||
// check if subdomains should be included
|
// check if subdomains should be included
|
||||||
// TODO: we should not add more domains if * has already been added
|
// TODO: we should not add more domains if * has already been added
|
||||||
if (subdomains) {
|
if (subdomains) {
|
||||||
// XXX making it stupid friendly for people who forget to include protocol/SSL
|
// XXX making it stupid friendly for people who forget to include protocol/SSL
|
||||||
if (origin.startsWith("http")) {
|
if (origin.startsWith("http")) {
|
||||||
self.whiteList.add(Pattern.compile(origin.replaceFirst("https?://", "^https?://(.*\\.)?")));
|
this.whiteList.add(Pattern.compile(origin.replaceFirst("https?://", "^https?://(.*\\.)?")));
|
||||||
} else {
|
} else {
|
||||||
self.whiteList.add(Pattern.compile("^https?://(.*\\.)?" + origin));
|
this.whiteList.add(Pattern.compile("^https?://(.*\\.)?" + origin));
|
||||||
}
|
}
|
||||||
LOG.d(TAG, "Origin to allow with subdomains: %s", origin);
|
LOG.d(TAG, "Origin to allow with subdomains: %s", origin);
|
||||||
} else {
|
} else {
|
||||||
// XXX making it stupid friendly for people who forget to include protocol/SSL
|
// XXX making it stupid friendly for people who forget to include protocol/SSL
|
||||||
if (origin.startsWith("http")) {
|
if (origin.startsWith("http")) {
|
||||||
self.whiteList.add(Pattern.compile(origin.replaceFirst("https?://", "^https?://")));
|
this.whiteList.add(Pattern.compile(origin.replaceFirst("https?://", "^https?://")));
|
||||||
} else {
|
} else {
|
||||||
self.whiteList.add(Pattern.compile("^https?://" + origin));
|
this.whiteList.add(Pattern.compile("^https?://" + origin));
|
||||||
}
|
}
|
||||||
LOG.d(TAG, "Origin to allow: %s", origin);
|
LOG.d(TAG, "Origin to allow: %s", origin);
|
||||||
}
|
}
|
||||||
@ -193,4 +218,11 @@ public class Config {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String getStartUrl() {
|
||||||
|
if (self == null || self.startUrl == null) {
|
||||||
|
return "file:///android_asset/www/index.html";
|
||||||
|
}
|
||||||
|
return self.startUrl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user