You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by mm...@apache.org on 2013/02/25 14:41:02 UTC

[12/50] ios commit: [CB-2276] Add whitelist method to CommandDelegate

[CB-2276] Add whitelist method to CommandDelegate

Use it in CDVInAppBrowser


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

Branch: refs/heads/multipart_plugin_result
Commit: a606ee20bdd545c39d70e03041e6c0ef049535d0
Parents: 81e3332
Author: Andrew Grieve <ag...@chromium.org>
Authored: Wed Feb 13 14:38:48 2013 -0500
Committer: Andrew Grieve <ag...@chromium.org>
Committed: Thu Feb 14 11:06:21 2013 -0500

----------------------------------------------------------------------
 CordovaLib/Classes/CDVCommandDelegate.h     |    3 +++
 CordovaLib/Classes/CDVCommandDelegateImpl.m |    6 ++++++
 CordovaLib/Classes/CDVInAppBrowser.m        |   14 +-------------
 3 files changed, 10 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/a606ee20/CordovaLib/Classes/CDVCommandDelegate.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCommandDelegate.h b/CordovaLib/Classes/CDVCommandDelegate.h
index 6b1dedd..fdc033e 100644
--- a/CordovaLib/Classes/CDVCommandDelegate.h
+++ b/CordovaLib/Classes/CDVCommandDelegate.h
@@ -22,6 +22,7 @@
 
 @class CDVPlugin;
 @class CDVPluginResult;
+@class CDVWhitelist;
 
 @protocol CDVCommandDelegate <NSObject>
 
@@ -46,5 +47,7 @@
 - (void)runInBackground:(void (^)())block;
 // Returns the User-Agent of the associated UIWebView.
 - (NSString*)userAgent;
+// Returns whether the given URL passes the white-list.
+- (BOOL)URLIsWhitelisted:(NSURL*)url;
 
 @end

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/a606ee20/CordovaLib/Classes/CDVCommandDelegateImpl.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCommandDelegateImpl.m b/CordovaLib/Classes/CDVCommandDelegateImpl.m
index 8845e40..8ff60ee 100644
--- a/CordovaLib/Classes/CDVCommandDelegateImpl.m
+++ b/CordovaLib/Classes/CDVCommandDelegateImpl.m
@@ -137,4 +137,10 @@
     return [_viewController userAgent];
 }
 
+- (BOOL)URLIsWhitelisted:(NSURL*)url
+{
+    return ![_viewController.whitelist schemeIsAllowed:[url scheme]] ||
+           [_viewController.whitelist URLIsAllowed:url];
+}
+
 @end

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/a606ee20/CordovaLib/Classes/CDVInAppBrowser.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVInAppBrowser.m b/CordovaLib/Classes/CDVInAppBrowser.m
index fd4c5f4..14671a5 100644
--- a/CordovaLib/Classes/CDVInAppBrowser.m
+++ b/CordovaLib/Classes/CDVInAppBrowser.m
@@ -19,7 +19,6 @@
 
 #import "CDVInAppBrowser.h"
 #import "CDVPluginResult.h"
-#import "CDVViewController.h"
 #import "CDVUserAgentUtil.h"
 
 #define    kInAppBrowserTargetSelf @"_self"
@@ -143,18 +142,7 @@
 
 - (void)openInCordovaWebView:(NSURL*)url withOptions:(NSString*)options
 {
-    BOOL passesWhitelist = YES;
-
-    if ([self.viewController isKindOfClass:[CDVViewController class]]) {
-        CDVViewController* vc = (CDVViewController*)self.viewController;
-        if ([vc.whitelist schemeIsAllowed:[url scheme]]) {
-            passesWhitelist = [vc.whitelist URLIsAllowed:url];
-        }
-    } else { // something went wrong, we can't get the whitelist
-        passesWhitelist = NO;
-    }
-
-    if (passesWhitelist) {
+    if ([self.commandDelegate URLIsWhitelisted:url]) {
         NSURLRequest* request = [NSURLRequest requestWithURL:url];
         [self.webView loadRequest:request];
     } else { // this assumes the InAppBrowser can be excepted from the white-list