From 7533996fac26ee24fc0b1ba6428f6e48d9ddfeb5 Mon Sep 17 00:00:00 2001 From: Ian Clelland Date: Wed, 22 Oct 2014 15:52:09 -0400 Subject: [PATCH 1/9] Add hooks in CordovaPlugin and PluginManager for whitelist plugins This adds three hooks to CordovaPlugin objects. In each case, a null value can be returned to indicate "I don't care". This null value is the default. public Boolean shouldAllowRequest(String url) public Boolean shouldAllowNavigation(String url) public Boolean shouldOpenExternalUrl(String url) --- .../src/org/apache/cordova/CordovaPlugin.java | 60 +++++++++- .../src/org/apache/cordova/PluginManager.java | 104 ++++++++++++++++++ 2 files changed, 158 insertions(+), 6 deletions(-) diff --git a/framework/src/org/apache/cordova/CordovaPlugin.java b/framework/src/org/apache/cordova/CordovaPlugin.java index cee6754a..71bf5cd6 100644 --- a/framework/src/org/apache/cordova/CordovaPlugin.java +++ b/framework/src/org/apache/cordova/CordovaPlugin.java @@ -162,19 +162,67 @@ public class CordovaPlugin { * 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. * - * @param requestCode The request code originally supplied to startActivityForResult(), - * allowing you to identify who this result came from. - * @param resultCode The integer result code returned by the child activity through its setResult(). - * @param intent An Intent, which can return result data to the caller (various data can be attached to Intent "extras"). + * @param requestCode The request code originally supplied to startActivityForResult(), + * allowing you to identify who this result came from. + * @param resultCode The integer result code returned by the child activity through its setResult(). + * @param intent An Intent, which can return result data to the caller (various data can be + * attached to Intent "extras"). */ public void onActivityResult(int requestCode, int resultCode, Intent intent) { } + /** + * Hook for blocking the loading of external resources. + * + * This will be called when the WebView's shouldInterceptRequest wants to + * know whether to open a connection to an external resource. Return false + * to block the request: if any plugin returns false, Cordova will block + * the request. If all plugins return null, the default policy will be + * enforced. If at least one plugin returns true, and no plugins return + * false, then the request will proceed. + * + * Note that this only affects resource requests which are routed through + * WebViewClient.shouldInterceptRequest, such as XMLHttpRequest requests and + * img tag loads. WebSockets and media requests (such as