You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by ag...@apache.org on 2014/07/04 17:49:23 UTC

[1/6] android commit: Refactor Config into ConfigXmlParser, CordovaPreferences

Repository: cordova-android
Updated Branches:
  refs/heads/4.0.x a8330773c -> bdf2f22f8
  refs/heads/master 95118398d -> 79aa3e159


Refactor Config into ConfigXmlParser, CordovaPreferences

Intention here is to be 100% backwards compatible.


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

Branch: refs/heads/4.0.x
Commit: 3bab41f138d57a7a92ab01586dd8f58bc91dddfd
Parents: f577af0
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Jul 4 11:31:32 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Jul 4 11:31:32 2014 -0400

----------------------------------------------------------------------
 framework/src/org/apache/cordova/Config.java    | 189 ++-----------------
 .../src/org/apache/cordova/ConfigXmlParser.java | 163 ++++++++++++++++
 .../org/apache/cordova/CordovaPreferences.java  | 158 ++++++++++++++++
 .../src/org/apache/cordova/PluginManager.java   | 100 +---------
 framework/src/org/apache/cordova/Whitelist.java |   4 +
 5 files changed, 351 insertions(+), 263 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/3bab41f1/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 5da0856..7865e00 100644
--- a/framework/src/org/apache/cordova/Config.java
+++ b/framework/src/org/apache/cordova/Config.java
@@ -19,184 +19,31 @@
 
 package org.apache.cordova;
 
-import java.io.IOException;
-import java.util.Locale;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.apache.cordova.LOG;
-import org.xmlpull.v1.XmlPullParserException;
-
 import android.app.Activity;
-import android.content.res.XmlResourceParser;
-import android.graphics.Color;
 import android.util.Log;
 
 public class Config {
+    private static final String TAG = "Config";
 
-    public static final String TAG = "Config";
-
-    private Whitelist whitelist = new Whitelist();
-    private String startUrl;
-
-    private static String errorUrl;
+    private static ConfigXmlParser parser;
 
-    private static Config self = null;
+    private Config() {
+    }
 
     public static void init(Activity action) {
-        //Just re-initialize this! Seriously, we lose this all the time
-        self = new Config(action);
+        parser = new ConfigXmlParser();
+        parser.parse(action);
+        parser.getPreferences().setPreferencesBundle(action.getIntent().getExtras());
+        parser.getPreferences().copyIntoIntentExtras(action);
     }
 
     // Intended to be used for testing only; creates an empty configuration.
     public static void init() {
-        if (self == null) {
-            self = new Config();
+        if (parser == null) {
+            parser = new ConfigXmlParser();
         }
     }
-
-    // Intended to be used for testing only; creates an empty configuration.
-    private Config() {
-    }
-
-    private Config(Activity action) {
-        if (action == null) {
-            LOG.i("CordovaLog", "There is no activity. Is this on the lock screen?");
-            return;
-        }
-
-        // First checking the class namespace for config.xml
-        int id = action.getResources().getIdentifier("config", "xml", action.getClass().getPackage().getName());
-        if (id == 0) {
-            // If we couldn't find config.xml there, we'll look in the namespace from AndroidManifest.xml
-            id = action.getResources().getIdentifier("config", "xml", action.getPackageName());
-            if (id == 0) {
-                LOG.i("CordovaLog", "config.xml missing. Ignoring...");
-                return;
-            }
-        }
-
-        // Add implicitly allowed URLs
-        whitelist.addWhiteListEntry("file:///*", false);
-        whitelist.addWhiteListEntry("content:///*", false);
-        whitelist.addWhiteListEntry("data:*", false);
-
-        XmlResourceParser xml = action.getResources().getXml(id);
-        int eventType = -1;
-        while (eventType != XmlResourceParser.END_DOCUMENT) {
-            if (eventType == XmlResourceParser.START_TAG) {
-                String strNode = xml.getName();
-
-                if (strNode.equals("access")) {
-                    String origin = xml.getAttributeValue(null, "origin");
-                    String subdomains = xml.getAttributeValue(null, "subdomains");
-                    if (origin != null) {
-                        whitelist.addWhiteListEntry(origin, (subdomains != null) && (subdomains.compareToIgnoreCase("true") == 0));
-                    }
-                }
-                else if (strNode.equals("log")) {
-                    String level = xml.getAttributeValue(null, "level");
-                    Log.d(TAG, "The <log> tag is deprecated. Use <preference name=\"loglevel\" value=\"" + level + "\"/> instead.");
-                    if (level != null) {
-                        LOG.setLogLevel(level);
-                    }
-                }
-                else if (strNode.equals("preference")) {
-                    String name = xml.getAttributeValue(null, "name").toLowerCase(Locale.getDefault());
-                    /* Java 1.6 does not support switch-based strings
-                       Java 7 does, but we're using Dalvik, which is apparently not Java.
-                       Since we're reading XML, this has to be an ugly if/else.
-                       
-                       Also, due to cast issues, each of them has to call their separate putExtra!  
-                       Wheee!!! Isn't Java FUN!?!?!?
-                       
-                       Note: We should probably pass in the classname for the variable splash on splashscreen!
-                       */
-                    if (name.equalsIgnoreCase("LogLevel")) {
-                        String level = xml.getAttributeValue(null, "value");
-                        LOG.setLogLevel(level);
-                    } else if (name.equalsIgnoreCase("SplashScreen")) {
-                        String value = xml.getAttributeValue(null, "value");
-                        int resource = 0;
-                        if (value == null)
-                        {
-                            value = "splash";
-                        }
-                        resource = action.getResources().getIdentifier(value, "drawable", action.getClass().getPackage().getName());
-                        
-                        action.getIntent().putExtra(name, resource);
-                    }
-                    else if(name.equalsIgnoreCase("BackgroundColor")) {
-                        int value = xml.getAttributeIntValue(null, "value", Color.BLACK);
-                        action.getIntent().putExtra(name, value);
-                    }
-                    else if(name.equalsIgnoreCase("LoadUrlTimeoutValue")) {
-                        int value = xml.getAttributeIntValue(null, "value", 20000);
-                        action.getIntent().putExtra(name, value);
-                    }
-                    else if(name.equalsIgnoreCase("SplashScreenDelay")) {
-                        int value = xml.getAttributeIntValue(null, "value", 3000);
-                        action.getIntent().putExtra(name, value);
-                    }
-                    else if(name.equalsIgnoreCase("KeepRunning"))
-                    {
-                        boolean value = xml.getAttributeValue(null, "value").equals("true");
-                        action.getIntent().putExtra(name, value);
-                    }
-                    else if(name.equalsIgnoreCase("InAppBrowserStorageEnabled"))
-                    {
-                        boolean value = xml.getAttributeValue(null, "value").equals("true");
-                        action.getIntent().putExtra(name, value);
-                    }
-                    else if(name.equalsIgnoreCase("DisallowOverscroll"))
-                    {
-                        boolean value = xml.getAttributeValue(null, "value").equals("true");
-                        action.getIntent().putExtra(name, value);
-                    }
-                    else if(name.equalsIgnoreCase("errorurl"))
-                    {
-                        errorUrl = xml.getAttributeValue(null, "value");
-                    }
-                    else
-                    {
-                        String value = xml.getAttributeValue(null, "value");
-                        action.getIntent().putExtra(name, value);
-                    }
-                    /*
-                    LOG.i("CordovaLog", "Found preference for %s=%s", 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 {
-                eventType = xml.next();
-            } catch (XmlPullParserException e) {
-                e.printStackTrace();
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
-        }
-    }
-
+    
     /**
      * Add entry to approved list of URLs (whitelist)
      *
@@ -204,11 +51,11 @@ public class Config {
      * @param subdomains    T=include all subdomains under origin
      */
     public static void addWhiteListEntry(String origin, boolean subdomains) {
-        if (self == null) {
+        if (parser == null) {
             Log.e(TAG, "Config was not initialised. Did you forget to Config.init(this)?");
             return;
         }
-        self.whitelist.addWhiteListEntry(origin, subdomains);
+        parser.getWhitelist().addWhiteListEntry(origin, subdomains);
     }
 
     /**
@@ -218,21 +65,21 @@ public class Config {
      * @return true if whitelisted
      */
     public static boolean isUrlWhiteListed(String url) {
-        if (self == null) {
+        if (parser == null) {
             Log.e(TAG, "Config was not initialised. Did you forget to Config.init(this)?");
             return false;
         }
-        return self.whitelist.isUrlWhiteListed(url);
+        return parser.getWhitelist().isUrlWhiteListed(url);
     }
 
     public static String getStartUrl() {
-        if (self == null || self.startUrl == null) {
+        if (parser == null) {
             return "file:///android_asset/www/index.html";
         }
-        return self.startUrl;
+        return parser.getLaunchUrl();
     }
 
     public static String getErrorUrl() {
-        return errorUrl;
+        return parser.getPreferences().getString("errorurl", null);
     }
 }

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/3bab41f1/framework/src/org/apache/cordova/ConfigXmlParser.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/ConfigXmlParser.java b/framework/src/org/apache/cordova/ConfigXmlParser.java
new file mode 100644
index 0000000..8062168
--- /dev/null
+++ b/framework/src/org/apache/cordova/ConfigXmlParser.java
@@ -0,0 +1,163 @@
+/*
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+*/
+
+package org.apache.cordova;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+import org.apache.cordova.LOG;
+import org.xmlpull.v1.XmlPullParserException;
+
+import android.app.Activity;
+import android.content.res.XmlResourceParser;
+import android.util.Log;
+
+public class ConfigXmlParser {
+    private static String TAG = "ConfigXmlParser";
+
+    private String launchUrl = "file:///android_asset/www/index.html";
+    private CordovaPreferences prefs = new CordovaPreferences();
+    private Whitelist whitelist = new Whitelist();
+    private ArrayList<PluginEntry> pluginEntries = new ArrayList<PluginEntry>(20);
+    private HashMap<String, List<String>> urlMap = new HashMap<String, List<String>>();
+
+    public Whitelist getWhitelist() {
+        return whitelist;
+    }
+
+    public CordovaPreferences getPreferences() {
+        return prefs;
+    }
+
+    public ArrayList<PluginEntry> getPluginEntries() {
+        return pluginEntries;
+    }
+
+    public String getLaunchUrl() {
+        return launchUrl;
+    }
+    
+    public HashMap<String, List<String>> getPluginUrlMap() {
+    	return urlMap;
+    }
+
+    public void parse(Activity action) {
+        // First checking the class namespace for config.xml
+        int id = action.getResources().getIdentifier("config", "xml", action.getClass().getPackage().getName());
+        if (id == 0) {
+            // If we couldn't find config.xml there, we'll look in the namespace from AndroidManifest.xml
+            id = action.getResources().getIdentifier("config", "xml", action.getPackageName());
+            if (id == 0) {
+                LOG.e(TAG, "res/xml/config.xml is missing!");
+                return;
+            }
+        }
+        parse(action.getResources().getXml(id));
+    }
+
+    public void parse(XmlResourceParser xml) {
+        int eventType = -1;
+        String service = "", pluginClass = "", paramType = "";
+        boolean onload = false;
+        boolean insideFeature = false;
+        while (eventType != XmlResourceParser.END_DOCUMENT) {
+            if (eventType == XmlResourceParser.START_TAG) {
+                String strNode = xml.getName();
+                if (strNode.equals("url-filter")) {
+                    Log.w(TAG, "Plugin " + service + " is using deprecated tag <url-filter>");
+                    if (urlMap.get(service) == null) {
+                        urlMap.put(service, new ArrayList<String>(2));
+                    }
+                    List<String> filters = urlMap.get(service);
+                    filters.add(xml.getAttributeValue(null, "value"));
+                } else if (strNode.equals("feature")) {
+                    //Check for supported feature sets  aka. plugins (Accelerometer, Geolocation, etc)
+                    //Set the bit for reading params
+                    insideFeature = true;
+                    service = xml.getAttributeValue(null, "name");
+                }
+                else if (insideFeature && strNode.equals("param")) {
+                    paramType = xml.getAttributeValue(null, "name");
+                    if (paramType.equals("service")) // check if it is using the older service param
+                        service = xml.getAttributeValue(null, "value");
+                    else if (paramType.equals("package") || paramType.equals("android-package"))
+                        pluginClass = xml.getAttributeValue(null,"value");
+                    else if (paramType.equals("onload"))
+                        onload = "true".equals(xml.getAttributeValue(null, "value"));
+                }
+                else if (strNode.equals("access")) {
+                    String origin = xml.getAttributeValue(null, "origin");
+                    String subdomains = xml.getAttributeValue(null, "subdomains");
+                    if (origin != null) {
+                        whitelist.addWhiteListEntry(origin, (subdomains != null) && (subdomains.compareToIgnoreCase("true") == 0));
+                    }
+                }
+                else if (strNode.equals("preference")) {
+                    String name = xml.getAttributeValue(null, "name").toLowerCase(Locale.ENGLISH);
+                    String value = xml.getAttributeValue(null, "value");
+                    prefs.set(name, value);
+                }
+                else if (strNode.equals("content")) {
+                    String src = xml.getAttributeValue(null, "src");
+                    if (src != null) {
+                        setStartUrl(src);
+                    }
+                }
+            }
+            else if (eventType == XmlResourceParser.END_TAG)
+            {
+                String strNode = xml.getName();
+                if (strNode.equals("feature")) {
+                    pluginEntries.add(new PluginEntry(service, pluginClass, onload));
+
+                    service = "";
+                    pluginClass = "";
+                    insideFeature = false;
+                    onload = false;
+                }
+            }
+            try {
+                eventType = xml.next();
+            } catch (XmlPullParserException e) {
+                e.printStackTrace();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
+    private void setStartUrl(String src) {
+        Pattern schemeRegex = Pattern.compile("^[a-z-]+://");
+        Matcher matcher = schemeRegex.matcher(src);
+        if (matcher.find()) {
+            launchUrl = src;
+        } else {
+            if (src.charAt(0) == '/') {
+                src = src.substring(1);
+            }
+            launchUrl = "file:///android_asset/www/" + src;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/3bab41f1/framework/src/org/apache/cordova/CordovaPreferences.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaPreferences.java b/framework/src/org/apache/cordova/CordovaPreferences.java
new file mode 100644
index 0000000..9fa1898
--- /dev/null
+++ b/framework/src/org/apache/cordova/CordovaPreferences.java
@@ -0,0 +1,158 @@
+/*
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+*/
+
+package org.apache.cordova;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+import org.apache.cordova.LOG;
+
+import android.app.Activity;
+import android.os.Bundle;
+
+public class CordovaPreferences {
+    private HashMap<String, String> prefs = new HashMap<String, String>(20);
+    private Bundle preferencesBundleExtras;
+
+    public void setPreferencesBundle(Bundle extras) {
+        preferencesBundleExtras = extras;
+    }
+
+    public void set(String name, String value) {
+        prefs.put(name.toLowerCase(Locale.ENGLISH), value);
+    }
+
+    public Map<String, String> getAll() {
+        return prefs;
+    }
+
+    public boolean getBoolean(String name, boolean defaultValue) {
+        name = name.toLowerCase(Locale.ENGLISH);
+        String value = prefs.get(name);
+        if (value != null) {
+            return "true".equals(value);
+        } else if (preferencesBundleExtras != null) {
+            Object bundleValue = preferencesBundleExtras.get(name);
+            if (bundleValue instanceof String) {
+                return "true".equals(bundleValue);
+            }
+            // Gives a nice warning if type is wrong.
+            return preferencesBundleExtras.getBoolean(name, defaultValue);
+        }
+        return defaultValue;
+    }
+
+    public int getInteger(String name, int defaultValue) {
+        name = name.toLowerCase(Locale.ENGLISH);
+        String value = prefs.get(name);
+        if (value != null) {
+            return Integer.valueOf(value);
+        } else if (preferencesBundleExtras != null) {
+            Object bundleValue = preferencesBundleExtras.get(name);
+            if (bundleValue instanceof String) {
+                return Integer.valueOf((String)bundleValue);
+            }
+            // Gives a nice warning if type is wrong.
+            return preferencesBundleExtras.getInt(name, defaultValue);
+        }
+        return defaultValue;
+    }
+
+    public double getDouble(String name, double defaultValue) {
+        name = name.toLowerCase(Locale.ENGLISH);
+        String value = prefs.get(name);
+        if (value != null) {
+            return Double.valueOf(value);
+        } else if (preferencesBundleExtras != null) {
+            Object bundleValue = preferencesBundleExtras.get(name);
+            if (bundleValue instanceof String) {
+                return Double.valueOf((String)bundleValue);
+            }
+            // Gives a nice warning if type is wrong.
+            return preferencesBundleExtras.getDouble(name, defaultValue);
+        }
+        return defaultValue;
+    }
+
+    public String getString(String name, String defaultValue) {
+        name = name.toLowerCase(Locale.ENGLISH);
+        String value = prefs.get(name);
+        if (value != null) {
+            return value;
+        } else if (preferencesBundleExtras != null && !"errorurl".equals(name)) {
+            Object bundleValue = preferencesBundleExtras.get(name);
+            if (bundleValue != null) {
+                return bundleValue.toString();
+            }
+        }
+        return defaultValue;
+    }
+
+    // Plugins should not rely on values within the intent since this does not work
+    // for apps with multiple webviews. Instead, they should retrieve prefs from the
+    // Config object associated with their webview.
+    public void copyIntoIntentExtras(Activity action) {
+        for (String name : prefs.keySet()) {
+            String value = prefs.get(name);
+            if (value == null) {
+                continue;
+            }
+            if (name.equals("loglevel")) {
+                LOG.setLogLevel(value);
+            } else if (name.equals("splashscreen")) {
+                // Note: We should probably pass in the classname for the variable splash on splashscreen!
+                int resource = action.getResources().getIdentifier(value, "drawable", action.getClass().getPackage().getName());
+                action.getIntent().putExtra(name, resource);
+            }
+            else if(name.equals("backgroundcolor")) {
+                int asInt = Integer.valueOf(value);
+                action.getIntent().putExtra(name, asInt);
+            }
+            else if(name.equals("loadurltimeoutvalue")) {
+                int asInt = Integer.valueOf(value);
+                action.getIntent().putExtra(name, asInt);
+            }
+            else if(name.equals("splashscreendelay")) {
+                int asInt = Integer.valueOf(value);
+                action.getIntent().putExtra(name, asInt);
+            }
+            else if(name.equals("keeprunning"))
+            {
+                boolean asBool = "true".equals(value);
+                action.getIntent().putExtra(name, asBool);
+            }
+            else if(name.equals("inappbrowserstorageenabled"))
+            {
+                boolean asBool = "true".equals(value);
+                action.getIntent().putExtra(name, asBool);
+            }
+            else if(name.equals("disallowoverscroll"))
+            {
+                boolean asBool = "true".equals(value);
+                action.getIntent().putExtra(name, asBool);
+            }
+            else
+            {
+                action.getIntent().putExtra(name, value);
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/3bab41f1/framework/src/org/apache/cordova/PluginManager.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/PluginManager.java b/framework/src/org/apache/cordova/PluginManager.java
index 02536ba..c5ffd6c 100755
--- a/framework/src/org/apache/cordova/PluginManager.java
+++ b/framework/src/org/apache/cordova/PluginManager.java
@@ -18,8 +18,6 @@
  */
 package org.apache.cordova;
 
-import java.io.IOException;
-import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -31,11 +29,8 @@ import org.apache.cordova.CordovaPlugin;
 import org.apache.cordova.PluginEntry;
 import org.apache.cordova.PluginResult;
 import org.json.JSONException;
-import org.xmlpull.v1.XmlPullParserException;
 
 import android.content.Intent;
-import android.content.res.XmlResourceParser;
-
 import android.net.Uri;
 import android.os.Debug;
 import android.util.Log;
@@ -56,23 +51,13 @@ public class PluginManager {
     private final CordovaInterface ctx;
     private final CordovaWebView app;
 
-    // Flag to track first time through
-    private boolean firstRun;
-
     // Stores mapping of Plugin Name -> <url-filter> values.
     // Using <url-filter> is deprecated.
-    protected HashMap<String, List<String>> urlMap = new HashMap<String, List<String>>();
+    protected HashMap<String, List<String>> urlMap;
 
-    /**
-     * Constructor.
-     *
-     * @param app
-     * @param ctx
-     */
     public PluginManager(CordovaWebView app, CordovaInterface ctx) {
         this.ctx = ctx;
         this.app = app;
-        this.firstRun = true;
     }
 
     /**
@@ -82,9 +67,8 @@ public class PluginManager {
         LOG.d(TAG, "init()");
 
         // If first time, then load plugins from config.xml file
-        if (this.firstRun) {
+        if (urlMap == null) {
             this.loadPlugins();
-            this.firstRun = false;
         }
 
         // Stop plugins on current HTML page and discard plugin objects
@@ -102,72 +86,12 @@ public class PluginManager {
      * Load plugins from res/xml/config.xml
      */
     public void loadPlugins() {
-        // First checking the class namespace for config.xml
-        int id = this.ctx.getActivity().getResources().getIdentifier("config", "xml", this.ctx.getActivity().getClass().getPackage().getName());
-        if (id == 0) {
-            // If we couldn't find config.xml there, we'll look in the namespace from AndroidManifest.xml
-            id = this.ctx.getActivity().getResources().getIdentifier("config", "xml", this.ctx.getActivity().getPackageName());
-            if (id == 0) {
-                this.pluginConfigurationMissing();
-                //We have the error, we need to exit without crashing!
-                return;
-            }
-        }
-        XmlResourceParser xml = this.ctx.getActivity().getResources().getXml(id);
-        int eventType = -1;
-        String service = "", pluginClass = "", paramType = "";
-        boolean onload = false;
-        boolean insideFeature = false;
-        while (eventType != XmlResourceParser.END_DOCUMENT) {
-            if (eventType == XmlResourceParser.START_TAG) {
-                String strNode = xml.getName();
-                if (strNode.equals("url-filter")) {
-                    Log.w(TAG, "Plugin " + service + " is using deprecated tag <url-filter>");
-                    if (urlMap.get(service) == null) {
-                        urlMap.put(service, new ArrayList<String>(2));
-                    }
-                    List<String> filters = urlMap.get(service);
-                    filters.add(xml.getAttributeValue(null, "value"));
-                }
-                else if (strNode.equals("feature")) {
-                    //Check for supported feature sets  aka. plugins (Accelerometer, Geolocation, etc)
-                    //Set the bit for reading params
-                    insideFeature = true;
-                    service = xml.getAttributeValue(null, "name");
-                }
-                else if (insideFeature && strNode.equals("param")) {
-                    paramType = xml.getAttributeValue(null, "name");
-                    if (paramType.equals("service")) // check if it is using the older service param
-                        service = xml.getAttributeValue(null, "value");
-                    else if (paramType.equals("package") || paramType.equals("android-package"))
-                        pluginClass = xml.getAttributeValue(null,"value");
-                    else if (paramType.equals("onload"))
-                        onload = "true".equals(xml.getAttributeValue(null, "value"));
-                }
-            }
-            else if (eventType == XmlResourceParser.END_TAG)
-            {
-                String strNode = xml.getName();
-                if (strNode.equals("feature") || strNode.equals("plugin"))
-                {
-                    PluginEntry entry = new PluginEntry(service, pluginClass, onload);
-                    this.addService(entry);
-
-                    //Empty the strings to prevent plugin loading bugs
-                    service = "";
-                    pluginClass = "";
-                    insideFeature = false;
-                    onload = false;
-                }
-            }
-            try {
-                eventType = xml.next();
-            } catch (XmlPullParserException e) {
-                e.printStackTrace();
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
-        }
+    	ConfigXmlParser parser = new ConfigXmlParser();
+    	parser.parse(ctx.getActivity());
+    	for (PluginEntry entry : parser.getPluginEntries()) {
+    		addService(entry);
+    	}
+    	urlMap = parser.getPluginUrlMap();
     }
 
     /**
@@ -396,14 +320,6 @@ public class PluginManager {
         }
     }
 
-
-    private void pluginConfigurationMissing() {
-        LOG.e(TAG, "=====================================================================================");
-        LOG.e(TAG, "ERROR: config.xml is missing.  Add res/xml/config.xml to your project.");
-        LOG.e(TAG, "https://git-wip-us.apache.org/repos/asf?p=cordova-android.git;a=blob;f=framework/res/xml/config.xml");
-        LOG.e(TAG, "=====================================================================================");
-    }
-
     Uri remapUri(Uri uri) {
         for (PluginEntry entry : this.entries.values()) {
             if (entry.plugin != null) {

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/3bab41f1/framework/src/org/apache/cordova/Whitelist.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/Whitelist.java b/framework/src/org/apache/cordova/Whitelist.java
index a01d7aa..ecbb7f6 100644
--- a/framework/src/org/apache/cordova/Whitelist.java
+++ b/framework/src/org/apache/cordova/Whitelist.java
@@ -98,6 +98,10 @@ public class Whitelist {
 
     public Whitelist() {
         this.whiteList = new ArrayList<URLPattern>();
+        // Add implicitly allowed URLs
+        addWhiteListEntry("file:///*", false);
+        addWhiteListEntry("content:///*", false);
+        addWhiteListEntry("data:*", false);
     }
 
     /* Match patterns (from http://developer.chrome.com/extensions/match_patterns.html)


[4/6] android commit: Delete dead code from CordovaActivity

Posted by ag...@apache.org.
Delete dead code from CordovaActivity


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

Branch: refs/heads/4.0.x
Commit: 79aa3e159d21466cdb44719e52dc65ae6167feae
Parents: 9511839
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Jul 4 11:46:03 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Jul 4 11:46:03 2014 -0400

----------------------------------------------------------------------
 .../src/org/apache/cordova/CordovaActivity.java | 87 ++------------------
 1 file changed, 6 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/79aa3e15/framework/src/org/apache/cordova/CordovaActivity.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java
index 005bad3..18ac670 100755
--- a/framework/src/org/apache/cordova/CordovaActivity.java
+++ b/framework/src/org/apache/cordova/CordovaActivity.java
@@ -37,7 +37,6 @@ import android.app.ProgressDialog;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
-import android.content.res.Configuration;
 import android.graphics.Color;
 import android.media.AudioManager;
 import android.net.Uri;
@@ -52,7 +51,6 @@ import android.view.View;
 import android.view.ViewGroup;
 import android.view.Window;
 import android.view.WindowManager;
-import android.widget.ImageView;
 import android.webkit.ValueCallback;
 import android.webkit.WebViewClient;
 import android.widget.LinearLayout;
@@ -96,15 +94,9 @@ public class CordovaActivity extends Activity implements CordovaInterface {
     protected CordovaWebViewClient webViewClient;
 
     protected LinearLayout root;
-    protected boolean cancelLoadUrl = false;
     protected ProgressDialog spinnerDialog = null;
     private final ExecutorService threadPool = Executors.newCachedThreadPool();
 
-
-    // The initial URL for our app
-    // ie http://server/path/index.html#abc?query
-    //private String url = null;
-
     private static int ACTIVITY_STARTING = 0;
     private static int ACTIVITY_RUNNING = 1;
     private static int ACTIVITY_EXITING = 2;
@@ -135,18 +127,8 @@ public class CordovaActivity extends Activity implements CordovaInterface {
     // when another application (activity) is started.
     protected boolean keepRunning = true;
 
-    private int lastRequestCode;
-
-    private Object responseCode;
-
-    private Intent lastIntent;
-
-    private Object lastResponseCode;
-
     private String initCallbackClass;
 
-    private Object LOG_TAG;
-
     /**
     * Sets the authentication token.
     *
@@ -207,14 +189,12 @@ public class CordovaActivity extends Activity implements CordovaInterface {
 
     /**
      * Called when the activity is first created.
-     *
-     * @param savedInstanceState
      */
     @SuppressWarnings("deprecation")
     @Override
     public void onCreate(Bundle savedInstanceState) {
         Config.init(this);
-        LOG.i(TAG, "Apache Cordova native platform version " + appView.CORDOVA_VERSION + " is starting");
+        LOG.i(TAG, "Apache Cordova native platform version " + CordovaWebView.CORDOVA_VERSION + " is starting");
         LOG.d(TAG, "CordovaActivity.onCreate()");
         super.onCreate(savedInstanceState);
 
@@ -344,16 +324,10 @@ public class CordovaActivity extends Activity implements CordovaInterface {
         this.appView.setVisibility(View.INVISIBLE);
         this.root.addView(this.appView);
         setContentView(this.root);
-
-        // Clear cancel flag
-        this.cancelLoadUrl = false;
-        
     }
 
     /**
      * Load the url into the webview.
-     *
-     * @param url
      */
     public void loadUrl(String url) {
 
@@ -408,18 +382,6 @@ public class CordovaActivity extends Activity implements CordovaInterface {
 
         this.splashscreenTime = time;
         this.loadUrl(url);
-        
-        /*
-        // Init web view if not already done
-        if (this.appView == null) {
-            this.init();
-        }
-
-        this.splashscreenTime = time;
-        this.splashscreen = this.getIntegerProperty("SplashScreen", 0);
-        this.showSplashScreen(this.splashscreenTime);
-        this.appView.loadUrl(url, time);
-        */
     }
     
     /*
@@ -455,14 +417,8 @@ public class CordovaActivity extends Activity implements CordovaInterface {
         }
     }
 
-
-    /**
-     * Cancel loadUrl before it has been loaded.
-     */
-    // TODO NO-OP
     @Deprecated
     public void cancelLoadUrl() {
-        this.cancelLoadUrl = true;
     }
 
     /**
@@ -494,17 +450,6 @@ public class CordovaActivity extends Activity implements CordovaInterface {
         return false;
     }
 
-    @Override
-    /**
-     * Called by the system when the device configuration changes while your activity is running.
-     *
-     * @param Configuration newConfig
-     */
-    public void onConfigurationChanged(Configuration newConfig) {
-        //don't reload the current page when the orientation is changed
-        super.onConfigurationChanged(newConfig);
-    }
-
     /**
      * Get boolean property for activity.
      *
@@ -666,10 +611,10 @@ public class CordovaActivity extends Activity implements CordovaInterface {
         this.getIntent().putExtra(name.toLowerCase(), value);
     }
 
-    @Override
     /**
      * Called when the system is about to start resuming a previous activity.
      */
+    @Override
     protected void onPause() {
         super.onPause();
 
@@ -692,10 +637,10 @@ public class CordovaActivity extends Activity implements CordovaInterface {
         this.removeSplashScreen();
     }
 
-    @Override
     /**
      * Called when the activity receives a new intent
      **/
+    @Override
     protected void onNewIntent(Intent intent) {
         super.onNewIntent(intent);
         //Forward to plugins
@@ -703,10 +648,10 @@ public class CordovaActivity extends Activity implements CordovaInterface {
            this.appView.onNewIntent(intent);
     }
 
-    @Override
     /**
      * Called when the activity will start interacting with the user.
      */
+    @Override
     protected void onResume() {
         super.onResume();
         LOG.d(TAG, "Resuming the App");
@@ -735,10 +680,10 @@ public class CordovaActivity extends Activity implements CordovaInterface {
         }
     }
 
-    @Override
     /**
      * The final call you receive before your activity is destroyed.
      */
+    @Override
     public void onDestroy() {
         LOG.d(TAG, "CordovaActivity.onDestroy()");
         super.onDestroy();
@@ -756,9 +701,6 @@ public class CordovaActivity extends Activity implements CordovaInterface {
 
     /**
      * Send a message to all plugins.
-     *
-     * @param id            The message id
-     * @param data          The message data
      */
     public void postMessage(String id, Object data) {
         if (this.appView != null) {
@@ -771,9 +713,6 @@ public class CordovaActivity extends Activity implements CordovaInterface {
      * Add services to res/xml/plugins.xml instead.
      *
      * Add a class that implements a service.
-     *
-     * @param serviceType
-     * @param className
      */
     @Deprecated
     public void addService(String serviceType, String className) {
@@ -854,7 +793,6 @@ public class CordovaActivity extends Activity implements CordovaInterface {
         super.startActivityForResult(intent, requestCode);
     }
 
-    @Override
     /**
      * Called when an activity you launched exits, giving you the requestCode you started it with,
      * the resultCode it returned, and any additional data from it.
@@ -864,6 +802,7 @@ public class CordovaActivity extends Activity implements CordovaInterface {
      * @param resultCode        The integer result code returned by the child activity through its setResult().
      * @param data              An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
      */
+    @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
         LOG.d(TAG, "Incoming Result");
         super.onActivityResult(requestCode, resultCode, intent);
@@ -875,8 +814,6 @@ public class CordovaActivity extends Activity implements CordovaInterface {
                 return;
             Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData();
             Log.d(TAG, "result = " + result);
-//            Uri filepath = Uri.parse("file://" + FileUtils.getRealPathFromURI(result, this));
-//            Log.d(TAG, "result = " + filepath);
             mUploadMessage.onReceiveValue(result);
             mUploadMessage = null;
         }
@@ -937,11 +874,6 @@ public class CordovaActivity extends Activity implements CordovaInterface {
 
     /**
      * Display an error dialog and optionally exit application.
-     *
-     * @param title
-     * @param message
-     * @param button
-     * @param exit
      */
     public void displayError(final String title, final String message, final String button, final boolean exit) {
         final CordovaActivity me = this;
@@ -972,9 +904,6 @@ public class CordovaActivity extends Activity implements CordovaInterface {
 
     /**
      * Determine if URL is in approved list of URLs to load.
-     *
-     * @param url
-     * @return true if the url is whitelisted
      */
     public boolean isUrlWhiteListed(String url) {
         return Config.isUrlWhiteListed(url);
@@ -982,7 +911,6 @@ public class CordovaActivity extends Activity implements CordovaInterface {
 
     /*
      * Hook in Cordova for menu plugins
-     *
      */
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
@@ -1004,9 +932,6 @@ public class CordovaActivity extends Activity implements CordovaInterface {
 
     /**
      * Get Activity context.
-     *
-     * @return self
-     * @deprecated
      */
     @Deprecated
     public Context getContext() {


[3/6] android commit: Update .classpath to make Eclipse happy (just re-orders one line)

Posted by ag...@apache.org.
Update .classpath to make Eclipse happy (just re-orders one line)


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

Branch: refs/heads/4.0.x
Commit: 95118398dd7c415872203ede81205485b1d4d1aa
Parents: 4d18a8e
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Jul 4 11:38:31 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Jul 4 11:38:31 2014 -0400

----------------------------------------------------------------------
 framework/.classpath | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/95118398/framework/.classpath
----------------------------------------------------------------------
diff --git a/framework/.classpath b/framework/.classpath
index e418986..0461652 100644
--- a/framework/.classpath
+++ b/framework/.classpath
@@ -2,8 +2,8 @@
 <classpath>
 	<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
 	<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+	<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
 	<classpathentry kind="src" path="src"/>
 	<classpathentry kind="src" path="gen"/>
-	<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
 	<classpathentry kind="output" path="bin/classes"/>
 </classpath>


[6/6] android commit: Merge branch 'master' into 4.0.x (ConfigXmlParser breakout)

Posted by ag...@apache.org.
Merge branch 'master' into 4.0.x (ConfigXmlParser breakout)

Conflicts:
	framework/src/org/apache/cordova/CordovaActivity.java
	framework/src/org/apache/cordova/PluginManager.java


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

Branch: refs/heads/4.0.x
Commit: bdf2f22f81632ffe8e81678a36b2a78b2e2c5a63
Parents: a833077 79aa3e1
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Jul 4 11:48:49 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Jul 4 11:48:49 2014 -0400

----------------------------------------------------------------------
 framework/.classpath                            |   2 +-
 framework/src/org/apache/cordova/Config.java    | 189 ++-----------------
 .../src/org/apache/cordova/ConfigXmlParser.java | 163 ++++++++++++++++
 .../src/org/apache/cordova/CordovaActivity.java |  78 +-------
 .../org/apache/cordova/CordovaPreferences.java  | 158 ++++++++++++++++
 .../src/org/apache/cordova/PluginManager.java   |  99 +---------
 framework/src/org/apache/cordova/Whitelist.java |   4 +
 7 files changed, 359 insertions(+), 334 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/bdf2f22f/framework/src/org/apache/cordova/CordovaActivity.java
----------------------------------------------------------------------
diff --cc framework/src/org/apache/cordova/CordovaActivity.java
index 77e896c,18ac670..d8e218a
--- a/framework/src/org/apache/cordova/CordovaActivity.java
+++ b/framework/src/org/apache/cordova/CordovaActivity.java
@@@ -137,23 -127,68 +129,10 @@@ public class CordovaActivity extends Ac
      // when another application (activity) is started.
      protected boolean keepRunning = true;
  
-     private int lastRequestCode;
- 
-     private Object responseCode;
- 
-     private Intent lastIntent;
- 
-     private Object lastResponseCode;
- 
      private String initCallbackClass;
  
-     private Object LOG_TAG;
- 
- 
      /**
 -    * Sets the authentication token.
 -    *
 -    * @param authenticationToken
 -    * @param host
 -    * @param realm
 -    */
 -    public void setAuthenticationToken(AuthenticationToken authenticationToken, String host, String realm) {
 -        if (this.appView != null && this.appView.viewClient != null) {
 -            this.appView.viewClient.setAuthenticationToken(authenticationToken, host, realm);
 -        }
 -    }
 -
 -    /**
 -     * Removes the authentication token.
 -     *
 -     * @param host
 -     * @param realm
 -     *
 -     * @return the authentication token or null if did not exist
 -     */
 -    public AuthenticationToken removeAuthenticationToken(String host, String realm) {
 -        if (this.appView != null && this.appView.viewClient != null) {
 -            return this.appView.viewClient.removeAuthenticationToken(host, realm);
 -        }
 -        return null;
 -    }
 -
 -    /**
 -     * Gets the authentication token.
 -     *
 -     * In order it tries:
 -     * 1- host + realm
 -     * 2- host
 -     * 3- realm
 -     * 4- no host, no realm
 -     *
 -     * @param host
 -     * @param realm
 -     *
 -     * @return the authentication token
 -     */
 -    public AuthenticationToken getAuthenticationToken(String host, String realm) {
 -        if (this.appView != null && this.appView.viewClient != null) {
 -            return this.appView.viewClient.getAuthenticationToken(host, realm);
 -        }
 -        return null;
 -    }
 -
 -    /**
 -     * Clear all authentication tokens.
 -     */
 -    public void clearAuthenticationTokens() {
 -        if (this.appView != null && this.appView.viewClient != null) {
 -            this.appView.viewClient.clearAuthenticationTokens();
 -        }
 -    }
 -
 -    /**
       * Called when the activity is first created.
-      *
-      * @param savedInstanceState
       */
      @SuppressWarnings("deprecation")
      @Override
@@@ -314,12 -322,8 +293,8 @@@
  
          // Add web view but make it invisible while loading URL
          this.appView.setVisibility(View.INVISIBLE);
 -        this.root.addView(this.appView);
 +        this.root.addView((View) this.appView.getView());
          setContentView(this.root);
- 
-         // Clear cancel flag
-         this.cancelLoadUrl = false;
-         
      }
  
      /**
@@@ -416,7 -417,10 +388,6 @@@
          }
      }
  
- 
 -    @Deprecated
 -    public void cancelLoadUrl() {
 -    }
 -
      /**
       * Clear the resource cache.
       */
@@@ -558,10 -551,70 +518,10 @@@
          return p.doubleValue();
      }
  
-     @Override
      /**
 -     * Set boolean property on activity.
 -     * This method has been deprecated in 3.0 and will be removed at a future
 -     * time. Please use config.xml instead.
 -     *
 -     * @param name
 -     * @param value
 -     * @deprecated
 -     */
 -    @Deprecated
 -    public void setBooleanProperty(String name, boolean value) {
 -        Log.d(TAG, "Setting boolean properties in CordovaActivity will be deprecated in 3.0 on July 2013, please use config.xml");
 -        this.getIntent().putExtra(name.toLowerCase(), value);
 -    }
 -
 -    /**
 -     * Set int property on activity.
 -     * This method has been deprecated in 3.0 and will be removed at a future
 -     * time. Please use config.xml instead.
 -     *
 -     * @param name
 -     * @param value
 -     * @deprecated
 -     */
 -    @Deprecated
 -    public void setIntegerProperty(String name, int value) {
 -        Log.d(TAG, "Setting integer properties in CordovaActivity will be deprecated in 3.0 on July 2013, please use config.xml");
 -        this.getIntent().putExtra(name.toLowerCase(), value);
 -    }
 -
 -    /**
 -     * Set string property on activity.
 -     * This method has been deprecated in 3.0 and will be removed at a future
 -     * time. Please use config.xml instead.
 -     *
 -     * @param name
 -     * @param value
 -     * @deprecated
 -     */
 -    @Deprecated
 -    public void setStringProperty(String name, String value) {
 -        Log.d(TAG, "Setting string properties in CordovaActivity will be deprecated in 3.0 on July 2013, please use config.xml");
 -        this.getIntent().putExtra(name.toLowerCase(), value);
 -    }
 -
 -    /**
 -     * Set double property on activity.
 -     * This method has been deprecated in 3.0 and will be removed at a future
 -     * time. Please use config.xml instead.
 -     *
 -     * @param name
 -     * @param value
 -     * @deprecated
 -     */
 -    @Deprecated
 -    public void setDoubleProperty(String name, double value) {
 -        Log.d(TAG, "Setting double properties in CordovaActivity will be deprecated in 3.0 on July 2013, please use config.xml");
 -        this.getIntent().putExtra(name.toLowerCase(), value);
 -    }
 -
 -    /**
       * Called when the system is about to start resuming a previous activity.
       */
+     @Override
      protected void onPause() {
          super.onPause();
  
@@@ -664,8 -708,20 +615,7 @@@
          }
      }
  
- 
      /**
 -     * @deprecated
 -     * Add services to res/xml/plugins.xml instead.
 -     *
 -     * Add a class that implements a service.
 -     */
 -    @Deprecated
 -    public void addService(String serviceType, String className) {
 -        if (this.appView != null && this.appView.pluginManager != null) {
 -            this.appView.pluginManager.addService(serviceType, className);
 -        }
 -    }
 -
 -    /**
       * Send JavaScript statement back to JavaScript.
       * (This is a convenience method)
       *

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/bdf2f22f/framework/src/org/apache/cordova/PluginManager.java
----------------------------------------------------------------------
diff --cc framework/src/org/apache/cordova/PluginManager.java
index feb5680,c5ffd6c..13c55c8
--- a/framework/src/org/apache/cordova/PluginManager.java
+++ b/framework/src/org/apache/cordova/PluginManager.java
@@@ -56,30 -51,14 +52,20 @@@ public class PluginManager 
      private final CordovaInterface ctx;
      private final CordovaWebView app;
  
-     // Flag to track first time through
-     private boolean firstRun;
- 
      // Stores mapping of Plugin Name -> <url-filter> values.
      // Using <url-filter> is deprecated.
-     protected HashMap<String, List<String>> urlMap = new HashMap<String, List<String>>();
+     protected HashMap<String, List<String>> urlMap;
  
 +    private Set<String> pluginIdWhitelist;
 +
      public PluginManager(CordovaWebView app, CordovaInterface ctx) {
          this.ctx = ctx;
          this.app = app;
-         this.firstRun = true;
      }
 +    
 +    public void setPluginIdWhitelist(Set<String> pluginIdWhitelist) {
 +        this.pluginIdWhitelist = pluginIdWhitelist;
 +    }
  
      /**
       * Init when loading a new HTML page into webview.


[5/6] android commit: Delete dead code from CordovaActivity

Posted by ag...@apache.org.
Delete dead code from CordovaActivity


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

Branch: refs/heads/master
Commit: 79aa3e159d21466cdb44719e52dc65ae6167feae
Parents: 9511839
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Jul 4 11:46:03 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Jul 4 11:46:03 2014 -0400

----------------------------------------------------------------------
 .../src/org/apache/cordova/CordovaActivity.java | 87 ++------------------
 1 file changed, 6 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/79aa3e15/framework/src/org/apache/cordova/CordovaActivity.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java
index 005bad3..18ac670 100755
--- a/framework/src/org/apache/cordova/CordovaActivity.java
+++ b/framework/src/org/apache/cordova/CordovaActivity.java
@@ -37,7 +37,6 @@ import android.app.ProgressDialog;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
-import android.content.res.Configuration;
 import android.graphics.Color;
 import android.media.AudioManager;
 import android.net.Uri;
@@ -52,7 +51,6 @@ import android.view.View;
 import android.view.ViewGroup;
 import android.view.Window;
 import android.view.WindowManager;
-import android.widget.ImageView;
 import android.webkit.ValueCallback;
 import android.webkit.WebViewClient;
 import android.widget.LinearLayout;
@@ -96,15 +94,9 @@ public class CordovaActivity extends Activity implements CordovaInterface {
     protected CordovaWebViewClient webViewClient;
 
     protected LinearLayout root;
-    protected boolean cancelLoadUrl = false;
     protected ProgressDialog spinnerDialog = null;
     private final ExecutorService threadPool = Executors.newCachedThreadPool();
 
-
-    // The initial URL for our app
-    // ie http://server/path/index.html#abc?query
-    //private String url = null;
-
     private static int ACTIVITY_STARTING = 0;
     private static int ACTIVITY_RUNNING = 1;
     private static int ACTIVITY_EXITING = 2;
@@ -135,18 +127,8 @@ public class CordovaActivity extends Activity implements CordovaInterface {
     // when another application (activity) is started.
     protected boolean keepRunning = true;
 
-    private int lastRequestCode;
-
-    private Object responseCode;
-
-    private Intent lastIntent;
-
-    private Object lastResponseCode;
-
     private String initCallbackClass;
 
-    private Object LOG_TAG;
-
     /**
     * Sets the authentication token.
     *
@@ -207,14 +189,12 @@ public class CordovaActivity extends Activity implements CordovaInterface {
 
     /**
      * Called when the activity is first created.
-     *
-     * @param savedInstanceState
      */
     @SuppressWarnings("deprecation")
     @Override
     public void onCreate(Bundle savedInstanceState) {
         Config.init(this);
-        LOG.i(TAG, "Apache Cordova native platform version " + appView.CORDOVA_VERSION + " is starting");
+        LOG.i(TAG, "Apache Cordova native platform version " + CordovaWebView.CORDOVA_VERSION + " is starting");
         LOG.d(TAG, "CordovaActivity.onCreate()");
         super.onCreate(savedInstanceState);
 
@@ -344,16 +324,10 @@ public class CordovaActivity extends Activity implements CordovaInterface {
         this.appView.setVisibility(View.INVISIBLE);
         this.root.addView(this.appView);
         setContentView(this.root);
-
-        // Clear cancel flag
-        this.cancelLoadUrl = false;
-        
     }
 
     /**
      * Load the url into the webview.
-     *
-     * @param url
      */
     public void loadUrl(String url) {
 
@@ -408,18 +382,6 @@ public class CordovaActivity extends Activity implements CordovaInterface {
 
         this.splashscreenTime = time;
         this.loadUrl(url);
-        
-        /*
-        // Init web view if not already done
-        if (this.appView == null) {
-            this.init();
-        }
-
-        this.splashscreenTime = time;
-        this.splashscreen = this.getIntegerProperty("SplashScreen", 0);
-        this.showSplashScreen(this.splashscreenTime);
-        this.appView.loadUrl(url, time);
-        */
     }
     
     /*
@@ -455,14 +417,8 @@ public class CordovaActivity extends Activity implements CordovaInterface {
         }
     }
 
-
-    /**
-     * Cancel loadUrl before it has been loaded.
-     */
-    // TODO NO-OP
     @Deprecated
     public void cancelLoadUrl() {
-        this.cancelLoadUrl = true;
     }
 
     /**
@@ -494,17 +450,6 @@ public class CordovaActivity extends Activity implements CordovaInterface {
         return false;
     }
 
-    @Override
-    /**
-     * Called by the system when the device configuration changes while your activity is running.
-     *
-     * @param Configuration newConfig
-     */
-    public void onConfigurationChanged(Configuration newConfig) {
-        //don't reload the current page when the orientation is changed
-        super.onConfigurationChanged(newConfig);
-    }
-
     /**
      * Get boolean property for activity.
      *
@@ -666,10 +611,10 @@ public class CordovaActivity extends Activity implements CordovaInterface {
         this.getIntent().putExtra(name.toLowerCase(), value);
     }
 
-    @Override
     /**
      * Called when the system is about to start resuming a previous activity.
      */
+    @Override
     protected void onPause() {
         super.onPause();
 
@@ -692,10 +637,10 @@ public class CordovaActivity extends Activity implements CordovaInterface {
         this.removeSplashScreen();
     }
 
-    @Override
     /**
      * Called when the activity receives a new intent
      **/
+    @Override
     protected void onNewIntent(Intent intent) {
         super.onNewIntent(intent);
         //Forward to plugins
@@ -703,10 +648,10 @@ public class CordovaActivity extends Activity implements CordovaInterface {
            this.appView.onNewIntent(intent);
     }
 
-    @Override
     /**
      * Called when the activity will start interacting with the user.
      */
+    @Override
     protected void onResume() {
         super.onResume();
         LOG.d(TAG, "Resuming the App");
@@ -735,10 +680,10 @@ public class CordovaActivity extends Activity implements CordovaInterface {
         }
     }
 
-    @Override
     /**
      * The final call you receive before your activity is destroyed.
      */
+    @Override
     public void onDestroy() {
         LOG.d(TAG, "CordovaActivity.onDestroy()");
         super.onDestroy();
@@ -756,9 +701,6 @@ public class CordovaActivity extends Activity implements CordovaInterface {
 
     /**
      * Send a message to all plugins.
-     *
-     * @param id            The message id
-     * @param data          The message data
      */
     public void postMessage(String id, Object data) {
         if (this.appView != null) {
@@ -771,9 +713,6 @@ public class CordovaActivity extends Activity implements CordovaInterface {
      * Add services to res/xml/plugins.xml instead.
      *
      * Add a class that implements a service.
-     *
-     * @param serviceType
-     * @param className
      */
     @Deprecated
     public void addService(String serviceType, String className) {
@@ -854,7 +793,6 @@ public class CordovaActivity extends Activity implements CordovaInterface {
         super.startActivityForResult(intent, requestCode);
     }
 
-    @Override
     /**
      * Called when an activity you launched exits, giving you the requestCode you started it with,
      * the resultCode it returned, and any additional data from it.
@@ -864,6 +802,7 @@ public class CordovaActivity extends Activity implements CordovaInterface {
      * @param resultCode        The integer result code returned by the child activity through its setResult().
      * @param data              An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
      */
+    @Override
     protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
         LOG.d(TAG, "Incoming Result");
         super.onActivityResult(requestCode, resultCode, intent);
@@ -875,8 +814,6 @@ public class CordovaActivity extends Activity implements CordovaInterface {
                 return;
             Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData();
             Log.d(TAG, "result = " + result);
-//            Uri filepath = Uri.parse("file://" + FileUtils.getRealPathFromURI(result, this));
-//            Log.d(TAG, "result = " + filepath);
             mUploadMessage.onReceiveValue(result);
             mUploadMessage = null;
         }
@@ -937,11 +874,6 @@ public class CordovaActivity extends Activity implements CordovaInterface {
 
     /**
      * Display an error dialog and optionally exit application.
-     *
-     * @param title
-     * @param message
-     * @param button
-     * @param exit
      */
     public void displayError(final String title, final String message, final String button, final boolean exit) {
         final CordovaActivity me = this;
@@ -972,9 +904,6 @@ public class CordovaActivity extends Activity implements CordovaInterface {
 
     /**
      * Determine if URL is in approved list of URLs to load.
-     *
-     * @param url
-     * @return true if the url is whitelisted
      */
     public boolean isUrlWhiteListed(String url) {
         return Config.isUrlWhiteListed(url);
@@ -982,7 +911,6 @@ public class CordovaActivity extends Activity implements CordovaInterface {
 
     /*
      * Hook in Cordova for menu plugins
-     *
      */
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
@@ -1004,9 +932,6 @@ public class CordovaActivity extends Activity implements CordovaInterface {
 
     /**
      * Get Activity context.
-     *
-     * @return self
-     * @deprecated
      */
     @Deprecated
     public Context getContext() {


[2/6] android commit: Delete "CB-3064: The errorUrl is..." Log message left over from debugging presumably

Posted by ag...@apache.org.
Delete "CB-3064: The errorUrl is..." Log message left over from debugging presumably


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

Branch: refs/heads/4.0.x
Commit: 4d18a8e55fe638bb0e50a126f7dcb9b88da92198
Parents: 3bab41f
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Jul 4 11:38:16 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Jul 4 11:38:16 2014 -0400

----------------------------------------------------------------------
 framework/src/org/apache/cordova/CordovaActivity.java | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/4d18a8e5/framework/src/org/apache/cordova/CordovaActivity.java
----------------------------------------------------------------------
diff --git a/framework/src/org/apache/cordova/CordovaActivity.java b/framework/src/org/apache/cordova/CordovaActivity.java
index 1cfe265..005bad3 100755
--- a/framework/src/org/apache/cordova/CordovaActivity.java
+++ b/framework/src/org/apache/cordova/CordovaActivity.java
@@ -709,16 +709,10 @@ public class CordovaActivity extends Activity implements CordovaInterface {
      */
     protected void onResume() {
         super.onResume();
+        LOG.d(TAG, "Resuming the App");
         //Reload the configuration
         Config.init(this);
-
-        LOG.d(TAG, "Resuming the App");
         
-
-        //Code to test CB-3064
-        String errorUrl = Config.getErrorUrl();
-        LOG.d(TAG, "CB-3064: The errorUrl is " + errorUrl);
-          
         if (this.activityState == ACTIVITY_STARTING) {
             this.activityState = ACTIVITY_RUNNING;
             return;