Return-Path: X-Original-To: apmail-cordova-commits-archive@www.apache.org Delivered-To: apmail-cordova-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8501018F2D for ; Tue, 17 Nov 2015 23:28:37 +0000 (UTC) Received: (qmail 13323 invoked by uid 500); 17 Nov 2015 23:28:37 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 13295 invoked by uid 500); 17 Nov 2015 23:28:37 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 13286 invoked by uid 99); 17 Nov 2015 23:28:37 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Nov 2015 23:28:37 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 45F18DFF7E; Tue, 17 Nov 2015 23:28:37 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: shazron@apache.org To: commits@cordova.apache.org Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: ios commit: CB-10001 CB-10003 Handle and Date: Tue, 17 Nov 2015 23:28:37 +0000 (UTC) Repository: cordova-ios Updated Branches: refs/heads/master 10e17d6d0 -> 34da32625 CB-10001 CB-10003 Handle and Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/34da3262 Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/34da3262 Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/34da3262 Branch: refs/heads/master Commit: 34da326258efbf1f54531a464cfb88b1d91079a7 Parents: 10e17d6 Author: Shazron Abdullah Authored: Tue Nov 17 15:28:57 2015 -0800 Committer: Shazron Abdullah Committed: Tue Nov 17 15:28:57 2015 -0800 ---------------------------------------------------------------------- .../Plugins/CDVSystemSchemes/CDVSystemSchemes.h | 4 +- .../Plugins/CDVSystemSchemes/CDVSystemSchemes.m | 76 +++++++++++++++----- .../CDVUIWebViewNavigationDelegate.m | 34 ++++----- tests/CordovaLibTests/CordovaLibApp/config.xml | 4 ++ 4 files changed, 76 insertions(+), 42 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/34da3262/CordovaLib/Classes/Private/Plugins/CDVSystemSchemes/CDVSystemSchemes.h ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/Private/Plugins/CDVSystemSchemes/CDVSystemSchemes.h b/CordovaLib/Classes/Private/Plugins/CDVSystemSchemes/CDVSystemSchemes.h index 48d1ff5..429e244 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVSystemSchemes/CDVSystemSchemes.h +++ b/CordovaLib/Classes/Private/Plugins/CDVSystemSchemes/CDVSystemSchemes.h @@ -19,8 +19,6 @@ #import "CDVPlugin.h" -@interface CDVSystemSchemes : CDVPlugin - -@property (nonatomic, readonly) NSArray* systemSchemes; +@interface CDVSystemSchemes : CDVPlugin @end http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/34da3262/CordovaLib/Classes/Private/Plugins/CDVSystemSchemes/CDVSystemSchemes.m ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/Private/Plugins/CDVSystemSchemes/CDVSystemSchemes.m b/CordovaLib/Classes/Private/Plugins/CDVSystemSchemes/CDVSystemSchemes.m index 7f54663..b7eaea5 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVSystemSchemes/CDVSystemSchemes.m +++ b/CordovaLib/Classes/Private/Plugins/CDVSystemSchemes/CDVSystemSchemes.m @@ -18,41 +18,81 @@ */ #import "CDVSystemSchemes.h" -#import "NSDictionary+CordovaPreferences.h" -#import "CDV.h" +#import @interface CDVSystemSchemes () -@property (nonatomic, readwrite) NSArray* systemSchemes; +@property (nonatomic, readwrite) NSMutableArray* allowIntents; +@property (nonatomic, readwrite) NSMutableArray* allowNavigations; +@property (nonatomic, readwrite) CDVWhitelist* allowIntentsWhitelist; +@property (nonatomic, readwrite) CDVWhitelist* allowNavigationsWhitelist; @end @implementation CDVSystemSchemes +#pragma mark NSXMLParserDelegate + +- (void)parser:(NSXMLParser*)parser didStartElement:(NSString*)elementName namespaceURI:(NSString*)namespaceURI qualifiedName:(NSString*)qualifiedName attributes:(NSDictionary*)attributeDict +{ + if ([elementName isEqualToString:@"allow-navigation"]) { + [self.allowNavigations addObject:attributeDict[@"href"]]; + } + if ([elementName isEqualToString:@"allow-intent"]) { + [self.allowIntents addObject:attributeDict[@"href"]]; + } +} + +- (void)parserDidStartDocument:(NSXMLParser*)parser +{ + // file: url are added by default + self.allowNavigations = [[NSMutableArray alloc] initWithArray:@[ @"file://" ]]; + // no intents are added by default + self.allowIntents = [[NSMutableArray alloc] init]; +} + +- (void)parserDidEndDocument:(NSXMLParser*)parser +{ + self.allowIntentsWhitelist = [[CDVWhitelist alloc] initWithArray:self.allowIntents]; + self.allowIntentsWhitelist.whitelistRejectionFormatString = @"ERROR External navigation rejected - not set for url='%@'"; + + self.allowNavigationsWhitelist = [[CDVWhitelist alloc] initWithArray:self.allowNavigations]; + self.allowNavigationsWhitelist.whitelistRejectionFormatString = @"ERROR Internal navigation rejected - not set for url='%@'"; + +} + +- (void)parser:(NSXMLParser*)parser parseErrorOccurred:(NSError*)parseError +{ + NSAssert(NO, @"config.xml parse error line %ld col %ld", (long)[parser lineNumber], (long)[parser columnNumber]); +} + +#pragma mark CDVPlugin + - (void)pluginInitialize { - // Read from preference, if not use default - NSString* schemesToOverride = [[self.commandDelegate settings] cordovaSettingForKey:@"CDVSystemSchemesOverride"]; - - if ((schemesToOverride == nil) || ([schemesToOverride length] == 0)) { - self.systemSchemes = @[@"maps", @"tel", @"telprompt"]; - } else { - // parse csv naïvely - self.systemSchemes = [schemesToOverride componentsSeparatedByString:@","]; + if ([self.viewController isKindOfClass:[CDVViewController class]]) { + [(CDVViewController*)self.viewController parseSettingsWithParser:self]; } } - (BOOL)shouldOverrideLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType { NSURL* url = [request URL]; - - // Push these system schemes off to the system, and do not let the UIWebView handle them - if ([self.systemSchemes indexOfObject:[url scheme]] != NSNotFound) { - [[UIApplication sharedApplication] openURL:url]; - return YES; + + switch (navigationType) { + case UIWebViewNavigationTypeLinkClicked: + // Note that the rejection strings will *only* print if + // it's a link click (and url is not whitelisted by ) + if ([self.allowIntentsWhitelist URLIsAllowed:url]) { + // the url *is* in a tag, push to the system + [[UIApplication sharedApplication] openURL:url]; + return NO; + } + // fall through, to check whether you can load this in the webview + default: + // check whether we can internally navigate to this url + return ([self.allowNavigationsWhitelist URLIsAllowed:url]); } - - return NO; } @end http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/34da3262/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m index 48edd31..6e31659 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m +++ b/CordovaLib/Classes/Private/Plugins/CDVUIWebViewEngine/CDVUIWebViewNavigationDelegate.m @@ -87,29 +87,12 @@ - (BOOL)defaultResourcePolicyForURL:(NSURL*)url { /* - * If a URL is being loaded that's a file/http/https URL, just load it internally + * If a URL is being loaded that's a file url, just load it internally */ if ([url isFileURL]) { return YES; } - /* - * Reject disallowed schemes - */ - NSString* scheme = [url scheme]; - NSArray* disallowedSchemes = [NSArray arrayWithObjects:@"about", nil]; - if([disallowedSchemes containsObject:scheme]) { - return NO; - } - - /* - * Accept allowed schemes - */ - NSArray* allowedSchemes = [NSArray arrayWithObjects:@"blob", nil]; - if([allowedSchemes containsObject:scheme]) { - return YES; - } - return NO; } @@ -133,15 +116,24 @@ /* * Give plugins the chance to handle the url */ + BOOL anyPluginsResponded = NO; + BOOL shouldAllowRequest = NO; + for (NSString* pluginName in vc.pluginObjects) { CDVPlugin* plugin = [vc.pluginObjects objectForKey:pluginName]; SEL selector = NSSelectorFromString(@"shouldOverrideLoadWithRequest:navigationType:"); if ([plugin respondsToSelector:selector]) { - if (((BOOL (*)(id, SEL, id, int))objc_msgSend)(plugin, selector, request, navigationType)) { - return NO; + anyPluginsResponded = YES; + shouldAllowRequest = (((BOOL (*)(id, SEL, id, int))objc_msgSend)(plugin, selector, request, navigationType)); + if (!shouldAllowRequest) { + break; } } } + + if (anyPluginsResponded) { + return shouldAllowRequest; + } /* * Handle all other types of urls (tel:, sms:), and requests to load a url in the main webview. @@ -152,7 +144,7 @@ } else { [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification object:url]]; } - + return NO; } http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/34da3262/tests/CordovaLibTests/CordovaLibApp/config.xml ---------------------------------------------------------------------- diff --git a/tests/CordovaLibTests/CordovaLibApp/config.xml b/tests/CordovaLibTests/CordovaLibApp/config.xml index 6d48e7b..6bc52d0 100644 --- a/tests/CordovaLibTests/CordovaLibApp/config.xml +++ b/tests/CordovaLibTests/CordovaLibApp/config.xml @@ -57,6 +57,10 @@ + + + + --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org For additional commands, e-mail: commits-help@cordova.apache.org