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/06/20 18:34:12 UTC
android commit: Add a whitelist to PluginManager to be used by App
Harness
Repository: cordova-android
Updated Branches:
refs/heads/4.0.x 8ac067da8 -> 98246c0e3
Add a whitelist to PluginManager to be used by App Harness
App Harness needs a way to restrict which plugins get loaded for
embedded apps. This seemed like the simplest way, although a better
API would be to have PluginManager recieve the list of PluginEntry.
Project: http://git-wip-us.apache.org/repos/asf/cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-android/commit/98246c0e
Tree: http://git-wip-us.apache.org/repos/asf/cordova-android/tree/98246c0e
Diff: http://git-wip-us.apache.org/repos/asf/cordova-android/diff/98246c0e
Branch: refs/heads/4.0.x
Commit: 98246c0e35cf35028576ed2a8b0650745027b9e5
Parents: 8ac067d
Author: Andrew Grieve <ag...@chromium.org>
Authored: Fri Jun 20 12:32:53 2014 -0400
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Fri Jun 20 12:34:08 2014 -0400
----------------------------------------------------------------------
.../src/org/apache/cordova/PluginManager.java | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-android/blob/98246c0e/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 f095722..e6a8325 100755
--- a/framework/src/org/apache/cordova/PluginManager.java
+++ b/framework/src/org/apache/cordova/PluginManager.java
@@ -23,6 +23,7 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.cordova.CordovaArgs;
@@ -37,7 +38,6 @@ 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;
@@ -66,6 +66,8 @@ public class PluginManager {
protected HashMap<String, List<String>> urlMap = new HashMap<String, List<String>>();
private AtomicInteger numPendingUiExecs;
+
+ private Set<String> pluginIdWhitelist;
/**
* Constructor.
@@ -79,6 +81,10 @@ public class PluginManager {
this.firstRun = true;
this.numPendingUiExecs = new AtomicInteger(0);
}
+
+ public void setPluginIdWhitelist(Set<String> pluginIdWhitelist) {
+ this.pluginIdWhitelist = pluginIdWhitelist;
+ }
/**
* Init when loading a new HTML page into webview.
@@ -192,7 +198,9 @@ public class PluginManager {
public void startupPlugins() {
for (PluginEntry entry : this.entries.values()) {
if (entry.onload) {
- entry.createPlugin(this.app, this.ctx);
+ if (pluginIdWhitelist == null || pluginIdWhitelist.contains(entry.service)) {
+ entry.createPlugin(this.app, this.ctx);
+ }
}
}
}
@@ -278,7 +286,11 @@ public class PluginManager {
}
CordovaPlugin plugin = entry.plugin;
if (plugin == null) {
- plugin = entry.createPlugin(this.app, this.ctx);
+ if (pluginIdWhitelist == null || pluginIdWhitelist.contains(entry.service)) {
+ plugin = entry.createPlugin(this.app, this.ctx);
+ } else {
+ Log.e(TAG, "Attempted to access non-whitelisted plugin: " + entry.service);
+ }
}
return plugin;
}