cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From i..@apache.org
Subject [2/9] ios commit: Add hooks for whitelist plugins
Date Thu, 26 Mar 2015 17:52:35 GMT
Add hooks for whitelist plugins

This allows plugins to implement two methods:
- (BOOL)shouldAllowRequestForURL:(NSURL *)url
- (BOOL)shouldAllowNavigationToURL:(NSURL *)url
- (BOOL)shouldOpenExternalURL:(NSURL *)url


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

Branch: refs/heads/4.0.x
Commit: c52e7ecf687c7fb310f696fdb81ec56122f732c8
Parents: 9ad1c7c
Author: Ian Clelland <iclelland@chromium.org>
Authored: Fri Oct 24 16:09:07 2014 -0400
Committer: Ian Clelland <iclelland@chromium.org>
Committed: Thu Mar 19 11:06:29 2015 -0400

----------------------------------------------------------------------
 CordovaLib/Classes/Public/CDVViewController.h |  3 +
 CordovaLib/Classes/Public/CDVViewController.m | 72 ++++++++++++++++++++++
 2 files changed, 75 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/c52e7ecf/CordovaLib/Classes/Public/CDVViewController.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/Public/CDVViewController.h b/CordovaLib/Classes/Public/CDVViewController.h
index 534c649..693b1e8 100644
--- a/CordovaLib/Classes/Public/CDVViewController.h
+++ b/CordovaLib/Classes/Public/CDVViewController.h
@@ -83,6 +83,9 @@
 - (void)registerPlugin:(CDVPlugin*)plugin withPluginName:(NSString*)pluginName;
 
 - (BOOL)URLisAllowed:(NSURL*)url;
+- (BOOL)shouldAllowRequestForURL:(NSURL *)url;
+- (BOOL)shouldAllowNavigationToURL:(NSURL *)url;
+- (BOOL)shouldOpenExternalURL:(NSURL *)url;
 
 - (void)parseSettingsWithParser:(NSObject<NSXMLParserDelegate> *)delegate;
 

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/c52e7ecf/CordovaLib/Classes/Public/CDVViewController.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/Public/CDVViewController.m b/CordovaLib/Classes/Public/CDVViewController.m
index a6b7fae..aeade66 100644
--- a/CordovaLib/Classes/Public/CDVViewController.m
+++ b/CordovaLib/Classes/Public/CDVViewController.m
@@ -684,6 +684,78 @@
     return YES;
 }
 
+#pragma mark Network Policy Plugin (Whitelist) hooks
+
+- (BOOL)shouldAllowRequestForURL:(NSURL *)url
+{
+    BOOL anyPluginsResponded = NO;
+    BOOL shouldAllowRequest = NO;
+    for (NSString* pluginName in pluginObjects) {
+        CDVPlugin* plugin = [pluginObjects objectForKey:pluginName];
+        SEL selector = NSSelectorFromString(@"shouldAllowRequestForURL:");
+        if ([plugin respondsToSelector:selector]) {
+            anyPluginsResponded = YES;
+            shouldAllowRequest = ((BOOL (*)(id, SEL, id))objc_msgSend)(plugin, selector,
url);
+            if (shouldAllowRequest == NO) {
+                break;
+            }
+        }
+    }
+    if (anyPluginsResponded) {
+        return shouldAllowRequest;
+    }
+
+    /* Default Policy */
+    return NO;
+}
+
+
+- (BOOL)shouldAllowNavigationToURL:(NSURL *)url
+{
+    BOOL anyPluginsResponded = NO;
+    BOOL shouldAllowNavigation = NO;
+    for (NSString* pluginName in pluginObjects) {
+        CDVPlugin* plugin = [pluginObjects objectForKey:pluginName];
+        SEL selector = NSSelectorFromString(@"shouldAllowNavigationToURL:");
+        if ([plugin respondsToSelector:selector]) {
+            anyPluginsResponded = YES;
+            shouldAllowNavigation = ((BOOL (*)(id, SEL, id))objc_msgSend)(plugin, selector,
url);
+            if (shouldAllowNavigation == NO) {
+                break;
+            }
+        }
+    }
+    if (anyPluginsResponded) {
+        return shouldAllowNavigation;
+    }
+
+    /* Default Policy */
+    return NO;
+}
+
+- (BOOL)shouldOpenExternalURL:(NSURL *)url
+{
+    BOOL anyPluginsResponded = NO;
+    BOOL shouldOpenExternalURL = NO;
+    for (NSString* pluginName in pluginObjects) {
+        CDVPlugin* plugin = [pluginObjects objectForKey:pluginName];
+        SEL selector = NSSelectorFromString(@"shouldOpenExternalURL:");
+        if ([plugin respondsToSelector:selector]) {
+            anyPluginsResponded = YES;
+            shouldOpenExternalURL = ((BOOL (*)(id, SEL, id))objc_msgSend)(plugin, selector,
url);
+            if (shouldOpenExternalURL == NO) {
+                break;
+            }
+        }
+    }
+    if (anyPluginsResponded) {
+        return shouldOpenExternalURL;
+    }
+
+    /* Default policy */
+    return NO;
+}
+
 #pragma mark GapHelpers
 
 - (void)javascriptAlert:(NSString*)text


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


Mime
View raw message