You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bo...@apache.org on 2013/01/11 19:25:01 UTC

[5/10] android commit: Add configurable start location to config.xml and template

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.


Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/958424ce
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/958424ce
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/958424ce

Branch: refs/heads/master
Commit: 958424ce590e6314cae10e511db096b999f20096
Parents: d04fc28
Author: Braden Shepherdson <br...@chromium.org>
Authored: Wed Jan 9 16:48:43 2013 -0500
Committer: Joe Bowser <bo...@apache.org>
Committed: Fri Jan 11 10:24:02 2013 -0800

----------------------------------------------------------------------
 bin/templates/project/Activity.java          |    3 +-
 framework/res/xml/config.xml                 |    3 +
 framework/src/org/apache/cordova/Config.java |   44 ++++++++++++++++++---
 3 files changed, 43 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/958424ce/bin/templates/project/Activity.java
----------------------------------------------------------------------
diff --git a/bin/templates/project/Activity.java b/bin/templates/project/Activity.java
index 4f87f9f..0f42d8e 100644
--- a/bin/templates/project/Activity.java
+++ b/bin/templates/project/Activity.java
@@ -29,7 +29,8 @@ public class __ACTIVITY__ extends DroidGap
     {
         super.onCreate(savedInstanceState);
         Config.init(this);
-        super.loadUrl("file:///android_asset/www/index.html");
+        super.loadUrl(Config.getStartUrl());
+        //super.loadUrl("file:///android_asset/www/index.html")
     }
 }
 

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/958424ce/framework/res/xml/config.xml
----------------------------------------------------------------------
diff --git a/framework/res/xml/config.xml b/framework/res/xml/config.xml
index b690007..bc6ca0c 100644
--- a/framework/res/xml/config.xml
+++ b/framework/res/xml/config.xml
@@ -29,6 +29,9 @@
     <!-- <access origin="https://example.com" subdomains="true" /> such as above, but including subdomains, such as www -->
     <access origin=".*"/>
 
+    <!-- <content src="http://mysite.com/myapp.html" /> for external pages -->
+    <content src="index.html" />
+
     <log level="DEBUG"/>
     <preference name="useBrowserHistory" value="true" />
     <preference name="exit-on-suspend" value="false" />

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/958424ce/framework/src/org/apache/cordova/Config.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/Config.java b/framework/src/org/apache/cordova/Config.java
index 1713d44..8353668 100644
--- a/framework/src/org/apache/cordova/Config.java
+++ b/framework/src/org/apache/cordova/Config.java
@@ -44,6 +44,7 @@ public class Config {
 
     private ArrayList<Pattern> whiteList = new ArrayList<Pattern>();
     private HashMap<String, Boolean> whiteListCache = new HashMap<String, Boolean>();
+    private String startUrl;
 
     private static Config self = null;
 
@@ -90,7 +91,7 @@ public class Config {
                     String origin = xml.getAttributeValue(null, "origin");
                     String subdomains = xml.getAttributeValue(null, "subdomains");
                     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")) {
@@ -109,6 +110,25 @@ public class Config {
 
                     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 {
@@ -132,28 +152,33 @@ public class Config {
             return;
         }
 
+        self._addWhiteListEntry(origin, subdomains);
+    }
+
+
+    private void _addWhiteListEntry(String origin, boolean subdomains) {
         try {
             // Unlimited access to network resources
             if (origin.compareTo("*") == 0) {
                 LOG.d(TAG, "Unlimited access to network resources");
-                self.whiteList.add(Pattern.compile(".*"));
+                this.whiteList.add(Pattern.compile(".*"));
             } else { // specific access
                 // check if subdomains should be included
                 // TODO: we should not add more domains if * has already been added
                 if (subdomains) {
                     // XXX making it stupid friendly for people who forget to include protocol/SSL
                     if (origin.startsWith("http")) {
-                        self.whiteList.add(Pattern.compile(origin.replaceFirst("https?://", "^https?://(.*\\.)?")));
+                        this.whiteList.add(Pattern.compile(origin.replaceFirst("https?://", "^https?://(.*\\.)?")));
                     } 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);
                 } else {
                     // XXX making it stupid friendly for people who forget to include protocol/SSL
                     if (origin.startsWith("http")) {
-                        self.whiteList.add(Pattern.compile(origin.replaceFirst("https?://", "^https?://")));
+                        this.whiteList.add(Pattern.compile(origin.replaceFirst("https?://", "^https?://")));
                     } else {
-                        self.whiteList.add(Pattern.compile("^https?://" + origin));
+                        this.whiteList.add(Pattern.compile("^https?://" + origin));
                     }
                     LOG.d(TAG, "Origin to allow: %s", origin);
                 }
@@ -193,4 +218,11 @@ public class Config {
         }
         return false;
     }
+
+    public static String getStartUrl() {
+        if (self == null || self.startUrl == null) {
+            return "file:///android_asset/www/index.html";
+        }
+        return self.startUrl;
+    }
 }