You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2012/09/12 08:38:01 UTC

ios commit: [CB-1412] iOS Whitelist is never used, all urls will pass the whitelist

Updated Branches:
  refs/heads/master 132fd93cd -> 8e2825b7f


[CB-1412] iOS Whitelist is never used, all urls will pass the whitelist


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

Branch: refs/heads/master
Commit: 8e2825b7f3e81da9ac8e7db3300686ad8ea1b142
Parents: 132fd93
Author: Shazron Abdullah <sh...@apache.org>
Authored: Tue Sep 11 23:37:53 2012 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Tue Sep 11 23:37:53 2012 -0700

----------------------------------------------------------------------
 CordovaLib/Classes/CDVURLProtocol.m    |    8 ++++++++
 CordovaLib/Classes/CDVViewController.m |   22 +++++++++++++---------
 CordovaLib/Classes/CDVWhitelist.m      |    1 -
 3 files changed, 21 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/8e2825b7/CordovaLib/Classes/CDVURLProtocol.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVURLProtocol.m b/CordovaLib/Classes/CDVURLProtocol.m
index 42dbef7..48133f8 100644
--- a/CordovaLib/Classes/CDVURLProtocol.m
+++ b/CordovaLib/Classes/CDVURLProtocol.m
@@ -42,6 +42,14 @@ static NSMutableSet* gRegisteredControllers = nil;
         gRegisteredControllers = [[NSMutableSet alloc] initWithCapacity:8];
         // The whitelist doesn't change, so grab the first one and store it.
         gWhitelist = viewController.whitelist;
+        
+        // Note that we grab the whitelist from the first viewcontroller for now - but this will change
+        // when we allow a registered viewcontroller to have its own whitelist (e.g InAppBrowser)
+        // Differentiating the requests will be through the 'vc' http header below as used for the js->objc bridge.
+        //  The 'vc' value is generated by casting the viewcontroller object to a (long long) value (see CDVViewController::webViewDidFinishLoad)
+        if (gWhitelist == nil) {
+            NSLog(@"WARNING: NO whitelist has been set in CDVURLProtocol.");
+        }
     }
     @synchronized (gRegisteredControllers) {
         [gRegisteredControllers addObject:[NSNumber numberWithLongLong:(long long)viewController]];

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/8e2825b7/CordovaLib/Classes/CDVViewController.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVViewController.m b/CordovaLib/Classes/CDVViewController.m
index da6baa0..2ad8972 100644
--- a/CordovaLib/Classes/CDVViewController.m
+++ b/CordovaLib/Classes/CDVViewController.m
@@ -80,6 +80,12 @@
         [self printMultitaskingInfo];
         [self printDeprecationNotice];
         self.initialized = YES;
+        
+        // load Cordova.plist settings
+        [self loadSettings];
+        // set the whitelist
+        self.whitelist = [[CDVWhitelist alloc] initWithArray:[self.settings objectForKey:@"ExternalHosts"]];
+        // register this viewcontroller with the NSURLProtocol
         [CDVURLProtocol registerViewController:self];
     }
     
@@ -139,11 +145,8 @@
     NSLog(@"Multi-tasking -> Device: %@, App: %@", (backgroundSupported? @"YES" : @"NO"), (![exitsOnSuspend intValue])? @"YES" : @"NO");
 }
 
-// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
-- (void) viewDidLoad 
+- (void) loadSettings
 {
-    [super viewDidLoad];
-	
     self.pluginObjects = [[NSMutableDictionary alloc] initWithCapacity:4];
     
     // read from Cordova.plist in the app bundle
@@ -163,12 +166,13 @@
         return;
     }
     
-    // set the whitelist
-    self.whitelist = [[CDVWhitelist alloc] initWithArray:[self.settings objectForKey:@"ExternalHosts"]];
-	
     self.pluginsMap = [pluginsDict dictionaryWithLowercaseKeys];
-    
-    ///////////////////
+}
+
+// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
+- (void) viewDidLoad 
+{
+    [super viewDidLoad];
     
 	NSString* startFilePath = [self pathForResource:self.startPage];
 	NSURL* appURL  = nil;

http://git-wip-us.apache.org/repos/asf/incubator-cordova-ios/blob/8e2825b7/CordovaLib/Classes/CDVWhitelist.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVWhitelist.m b/CordovaLib/Classes/CDVWhitelist.m
index a050794..149daf5 100644
--- a/CordovaLib/Classes/CDVWhitelist.m
+++ b/CordovaLib/Classes/CDVWhitelist.m
@@ -154,7 +154,6 @@
 - (BOOL) URLIsAllowed:(NSURL*)url
 {
     if (self.expandedWhitelist == nil) {
-        NSLog(@"ERROR: CDVWhitelist was not initialized properly, all urls will be disallowed.");
         return NO;
     }