cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject spec commit: Android: Update whitelist tests to work with Cordova-Android 4.0
Date Wed, 18 Feb 2015 21:59:43 GMT
Repository: cordova-mobile-spec
Updated Branches:
  refs/heads/master b0fa40051 -> 420e330ee


Android: Update whitelist tests to work with Cordova-Android 4.0


Project: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/commit/420e330e
Tree: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/tree/420e330e
Diff: http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/diff/420e330e

Branch: refs/heads/master
Commit: 420e330eeb8f73f8599f6feb8e6a8b4be67dd3c0
Parents: b0fa400
Author: Ian Clelland <iclelland@chromium.org>
Authored: Wed Feb 18 16:59:06 2015 -0500
Committer: Ian Clelland <iclelland@chromium.org>
Committed: Wed Feb 18 16:59:27 2015 -0500

----------------------------------------------------------------------
 .../src/android/WhitelistAPI.java               | 33 +++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-mobile-spec/blob/420e330e/cordova-plugin-whitelist/src/android/WhitelistAPI.java
----------------------------------------------------------------------
diff --git a/cordova-plugin-whitelist/src/android/WhitelistAPI.java b/cordova-plugin-whitelist/src/android/WhitelistAPI.java
index 1d67992..934ffb9 100644
--- a/cordova-plugin-whitelist/src/android/WhitelistAPI.java
+++ b/cordova-plugin-whitelist/src/android/WhitelistAPI.java
@@ -27,6 +27,10 @@ import org.apache.cordova.PluginResult;
 import org.json.JSONArray;
 import org.json.JSONException;
 
+import org.apache.cordova.PluginManager;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
 public class WhitelistAPI extends CordovaPlugin {
     /**
      * Executes the request and returns PluginResult.
@@ -50,7 +54,34 @@ public class WhitelistAPI extends CordovaPlugin {
             return true;
         } else if (action.equals("URLIsAllowed")) {
             String url = args.getString(0);
-            boolean isAllowed = Config.isUrlWhiteListed(url);
+            /* This code exists for compatibility between 3.x and 4.x versions of Cordova.
+             * Previously the CordovaWebView class had a method, getWhitelist, which would
+             * return a Whitelist object. Since the fixed whitelist is removed in Cordova
4.x,
+             * the correct call now is to shouldAllowRequest from the plugin manager.
+             */
+            Boolean isAllowed = null;
+            try {
+                Method isUrlWhiteListed = Config.class.getDeclaredMethod("isUrlWhitelisted",
String.class);
+                isAllowed = (Boolean)isUrlWhiteListed.invoke(url);
+            } catch (NoSuchMethodException e) {
+            } catch (IllegalAccessException e) {
+            } catch (InvocationTargetException e) {
+            }
+            if (isAllowed == null) {
+                try {
+                    Method gpm = webView.getClass().getMethod("getPluginManager");
+                    PluginManager pm = (PluginManager)gpm.invoke(webView);
+                    Method isAllowedMethod = pm.getClass().getMethod("shouldAllowRequest",
String.class);
+                    isAllowed = (Boolean)isAllowedMethod.invoke(pm, url);
+                    if (isAllowed == null) {
+                        isAllowed = false;
+                    }
+                } catch (NoSuchMethodException e) {
+                } catch (IllegalAccessException e) {
+                } catch (InvocationTargetException e) {
+                }
+            }
+
             callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, isAllowed));
             return true;
         }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message