cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject android commit: CB-5191 Deprecate <url-filter>
Date Thu, 24 Oct 2013 02:04:51 GMT
Updated Branches:
  refs/heads/master 001570e94 -> 4437d7f3c


CB-5191 Deprecate <url-filter>


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

Branch: refs/heads/master
Commit: 4437d7f3c45a56dd4014d79f414c6ee492f29b6f
Parents: 001570e
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Wed Oct 23 22:01:50 2013 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Wed Oct 23 22:02:49 2013 -0400

----------------------------------------------------------------------
 .../src/org/apache/cordova/PluginManager.java   | 37 ++++++++++++++------
 1 file changed, 27 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/4437d7f3/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 514fa58..9f636a8 100755
--- a/framework/src/org/apache/cordova/PluginManager.java
+++ b/framework/src/org/apache/cordova/PluginManager.java
@@ -19,9 +19,10 @@
 package org.apache.cordova;
 
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Iterator;
-import java.util.Map.Entry;
+import java.util.List;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import org.apache.cordova.CordovaArgs;
@@ -60,9 +61,9 @@ public class PluginManager {
     // Flag to track first time through
     private boolean firstRun;
 
-    // Map URL schemes like foo: to plugins that want to handle those schemes
-    // This would allow how all URLs are handled to be offloaded to a plugin
-    protected HashMap<String, String> urlMap = new HashMap<String, String>();
+    // Stores mapping of Plugin Name -> <url-filter> values.
+    // Using <url-filter> is deprecated.
+    protected HashMap<String, List<String>> urlMap = new HashMap<String, List<String>>();
 
     private AtomicInteger numPendingUiExecs;
 
@@ -124,7 +125,12 @@ public class PluginManager {
             if (eventType == XmlResourceParser.START_TAG) {
                 String strNode = xml.getName();
                 if (strNode.equals("url-filter")) {
-                    this.urlMap.put(xml.getAttributeValue(null, "value"), service);
+                    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)
@@ -369,11 +375,22 @@ public class PluginManager {
      * @return                  Return false to allow the URL to load, return true to prevent
the URL from loading.
      */
     public boolean onOverrideUrlLoading(String url) {
-        Iterator<Entry<String, String>> it = this.urlMap.entrySet().iterator();
-        while (it.hasNext()) {
-            HashMap.Entry<String, String> pairs = it.next();
-            if (url.startsWith(pairs.getKey())) {
-                return this.getPlugin(pairs.getValue()).onOverrideUrlLoading(url);
+        // Deprecated way to intercept URLs. (process <url-filter> tags).
+        // Instead, plugins should not include <url-filter> and instead ensure
+        // that they are loaded before this function is called (either by setting
+        // the onload <param> or by making an exec() call to them)
+        for (PluginEntry entry : this.entries.values()) {
+            List<String> urlFilters = urlMap.get(entry.service);
+            if (urlFilters != null) {
+                for (String s : urlFilters) {
+                    if (url.startsWith(s)) {
+                        return getPlugin(entry.service).onOverrideUrlLoading(url);
+                    }
+                }
+            } else if (entry.plugin != null) {
+                if (entry.plugin.onOverrideUrlLoading(url)) {
+                    return true;
+                }
             }
         }
         return false;


Mime
View raw message