cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [10/10] android commit: Merge branch 'master' into 4.0.x (PluginEntry refactor)
Date Mon, 14 Jul 2014 18:18:41 GMT
Merge branch 'master' into 4.0.x (PluginEntry refactor)

Conflicts:
	framework/src/org/apache/cordova/PluginEntry.java
	framework/src/org/apache/cordova/PluginManager.java
	test/src/org/apache/cordova/test/CordovaWebViewTestActivity.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/e2b3f76a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/e2b3f76a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/e2b3f76a

Branch: refs/heads/4.0.x
Commit: e2b3f76a106a3bcc8f822f32275007d63657954f
Parents: b277202 b934c1b
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Mon Jul 14 14:18:10 2014 -0400
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Mon Jul 14 14:18:10 2014 -0400

----------------------------------------------------------------------
 bin/lib/check_reqs.js                           |   8 +-
 .../src/org/apache/cordova/PluginEntry.java     |  75 ++---------
 .../src/org/apache/cordova/PluginManager.java   | 135 +++++++++++--------
 .../test/CordovaWebViewTestActivity.java        |   3 +-
 4 files changed, 99 insertions(+), 122 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-android/blob/e2b3f76a/bin/lib/check_reqs.js
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/e2b3f76a/framework/src/org/apache/cordova/PluginEntry.java
----------------------------------------------------------------------
diff --cc framework/src/org/apache/cordova/PluginEntry.java
index e0acfac,03a44da..9782825
--- a/framework/src/org/apache/cordova/PluginEntry.java
+++ b/framework/src/org/apache/cordova/PluginEntry.java
@@@ -18,11 -18,10 +18,8 @@@
   */
  package org.apache.cordova;
  
- import org.apache.cordova.CordovaWebView;
- import org.apache.cordova.CordovaInterface;
 -import java.util.List;
 -
  import org.apache.cordova.CordovaPlugin;
  
- 
  /**
   * This class represents a service entry object.
   */
@@@ -48,15 -45,16 +43,13 @@@ public class PluginEntry 
      /**
       * Flag that indicates the plugin object should be created when PluginManager is initialized.
       */
-     public boolean onload = false;
+     public boolean onload;
  
 -    private List<String> urlFilters;
 -
 -
      /**
-      * @param service               The name of the service
-      * @param plugin                The plugin associated with this entry
+      * Constructs with a CordovaPlugin already instantiated.
       */
      public PluginEntry(String service, CordovaPlugin plugin) {
-         this(service, plugin.getClass().getName(), true);
-         this.plugin = plugin;
 -        this(service, plugin.getClass().getName(), true, plugin, null);
++        this(service, plugin.getClass().getName(), true, plugin);
      }
  
      /**
@@@ -65,57 -63,27 +58,13 @@@
       * @param onload                Create plugin object when HTML page is loaded
       */
      public PluginEntry(String service, String pluginClass, boolean onload) {
 -        this(service, pluginClass, onload, null, null);
 -    }
 -    
 -    @Deprecated // urlFilters are going away
 -    public PluginEntry(String service, String pluginClass, boolean onload, List<String>
urlFilters) {
 -        this.service = service;
 -        this.pluginClass = pluginClass;
 -        this.onload = onload;
 -        this.urlFilters = urlFilters;
 -        plugin = null;
++        this(service, pluginClass, onload, null);
+     }
+ 
 -    private PluginEntry(String service, String pluginClass, boolean onload, CordovaPlugin
plugin, List<String> urlFilters) {
++    private PluginEntry(String service, String pluginClass, boolean onload, CordovaPlugin
plugin) {
          this.service = service;
          this.pluginClass = pluginClass;
          this.onload = onload;
-     }
-     
-     /**
-      * Create plugin object.
-      * If plugin is already created, then just return it.
-      *
-      * @return                      The plugin object
-      */
-     public CordovaPlugin createPlugin(CordovaWebView webView, CordovaInterface ctx) {
-         if (this.plugin != null) {
-             return this.plugin;
-         }
-         try {
-             Class<?> c = getClassByName(this.pluginClass);
-             if (isCordovaPlugin(c)) {
-                 this.plugin = (CordovaPlugin) c.newInstance();
-                 this.plugin.privateInitialize(ctx, webView, webView.getPreferences());
-                 return plugin;
-             }
-         } catch (Exception e) {
-             e.printStackTrace();
-             System.out.println("Error adding plugin " + this.pluginClass + ".");
-         }
-         return null;
-     }
- 
-     /**
-      * Get the class.
-      *
-      * @param clazz
-      * @return a reference to the named class
-      * @throws ClassNotFoundException
-      */
-     private Class<?> getClassByName(final String clazz) throws ClassNotFoundException
{
-         Class<?> c = null;
-         if ((clazz != null) && !("".equals(clazz))) {
-             c = Class.forName(clazz);
-         }
-         return c;
-     }
- 
-     /**
-      * Returns whether the given class extends CordovaPlugin.
-      */
-     private boolean isCordovaPlugin(Class<?> c) {
-         if (c != null) {
-             return CordovaPlugin.class.isAssignableFrom(c);
-         }
-         return false;
 -        this.urlFilters = urlFilters;
+         this.plugin = plugin;
      }
 -
 -    public List<String> getUrlFilters() {
 -        return urlFilters;
 -    }
  }

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/e2b3f76a/framework/src/org/apache/cordova/PluginManager.java
----------------------------------------------------------------------
diff --cc framework/src/org/apache/cordova/PluginManager.java
index 23be8e4,689c3c8..9530fef
--- a/framework/src/org/apache/cordova/PluginManager.java
+++ b/framework/src/org/apache/cordova/PluginManager.java
@@@ -56,15 -66,16 +57,15 @@@ public class PluginManager 
          setPluginEntries(pluginEntries);
      }
  
 -    public void setPluginEntries(List<PluginEntry> pluginEntries) {
 +    public Collection<PluginEntry> getPluginEntries() {
-         return entries.values();
++        return entryMap.values();
 +    }
 +
 +    public void setPluginEntries(Collection<PluginEntry> pluginEntries) {
          this.onPause(false);
          this.onDestroy();
-         this.clearPluginObjects();
-         entries.clear();
+         pluginMap.clear();
 -        urlMap.clear();
++        entryMap.clear();
          for (PluginEntry entry : pluginEntries) {
              addService(entry);
          }
@@@ -187,7 -214,16 +195,11 @@@
       * @param entry             The plugin entry
       */
      public void addService(PluginEntry entry) {
-         this.entries.put(entry.service, entry);
+         this.entryMap.put(entry.service, entry);
 -        List<String> urlFilters = entry.getUrlFilters();
 -        if (urlFilters != null) {
 -            urlMap.put(entry.service, urlFilters);
 -        }
+         if (entry.plugin != null) {
+             entry.plugin.privateInitialize(ctx, app, app.getPreferences());
+             pluginMap.put(entry.service, entry.plugin);
+         }
 -
      }
  
      /**
@@@ -272,11 -303,19 +279,10 @@@
          // 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()) {
-             if (entry.plugin != null) {
-                 if (entry.plugin.onOverrideUrlLoading(url)) {
-                     return true;
-                 }
+         for (PluginEntry entry : this.entryMap.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 {
 -                CordovaPlugin plugin = pluginMap.get(entry.service);
 -                if (plugin != null && plugin.onOverrideUrlLoading(url)) {
 -                    return true;
 -                }
++            CordovaPlugin plugin = pluginMap.get(entry.service);
++            if (plugin != null && plugin.onOverrideUrlLoading(url)) {
++                return true;
              }
          }
          return false;

http://git-wip-us.apache.org/repos/asf/cordova-android/blob/e2b3f76a/test/src/org/apache/cordova/test/CordovaWebViewTestActivity.java
----------------------------------------------------------------------
diff --cc test/src/org/apache/cordova/test/CordovaWebViewTestActivity.java
index a078f21,06070cc..6f96e83
--- a/test/src/org/apache/cordova/test/CordovaWebViewTestActivity.java
+++ b/test/src/org/apache/cordova/test/CordovaWebViewTestActivity.java
@@@ -46,7 -48,8 +46,8 @@@ public class CordovaWebViewTestActivit
          setContentView(R.layout.main);
  
          cordovaWebView = (CordovaWebView) findViewById(R.id.cordovaWebView);
+         Config.init(this);
 -        cordovaWebView.init(this, new CordovaWebViewClient(this, cordovaWebView), new CordovaChromeClient(this,
cordovaWebView),
 +        cordovaWebView.init(this,
                  Config.getPluginEntries(), Config.getWhitelist(), Config.getPreferences());
  
          cordovaWebView.loadUrl("file:///android_asset/www/index.html");
@@@ -100,4 -103,4 +101,4 @@@
              cordovaWebView.handleDestroy();
          }
      }
--}
++}


Mime
View raw message