Repository: cordova-ios Updated Branches: refs/heads/master 10bd67c22 -> 842517eb7
CB-10272 - Improve <allow-intent> and <allow-navigation> error logs Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/842517eb Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/842517eb Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/842517eb Branch: refs/heads/master Commit: 842517eb7b5b0fdf8aefd3102372d182b155f7c4 Parents: 10bd67c Author: Shazron Abdullah <shaz...@apache.org> Authored: Mon Jan 11 16:51:36 2016 -0800 Committer: Shazron Abdullah <shaz...@apache.org> Committed: Mon Jan 11 16:51:36 2016 -0800 ---------------------------------------------------------------------- .../CDVIntentAndNavigationFilter.m | 26 +++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/842517eb/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.m ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.m b/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.m index 67eb2e5..365db3f 100644 --- a/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.m +++ b/CordovaLib/Classes/Private/Plugins/CDVIntentAndNavigationFilter/CDVIntentAndNavigationFilter.m @@ -54,11 +54,7 @@ - (void)parserDidEndDocument:(NSXMLParser*)parser { self.allowIntentsWhitelist = [[CDVWhitelist alloc] initWithArray:self.allowIntents]; - self.allowIntentsWhitelist.whitelistRejectionFormatString = @"ERROR External navigation rejected - <allow-intent> not set for url='%@'"; - self.allowNavigationsWhitelist = [[CDVWhitelist alloc] initWithArray:self.allowNavigations]; - self.allowNavigationsWhitelist.whitelistRejectionFormatString = @"ERROR Internal navigation rejected - <allow-navigation> not set for url='%@'"; - } - (void)parser:(NSXMLParser*)parser parseErrorOccurred:(NSError*)parseError @@ -77,21 +73,39 @@ - (BOOL)shouldOverrideLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType { + NSString* allowIntents_whitelistRejectionFormatString = @"ERROR External navigation rejected - <allow-intent> not set for url='%@'"; + NSString* allowNavigations_whitelistRejectionFormatString = @"ERROR Internal navigation rejected - <allow-navigation> not set for url='%@'"; + NSURL* url = [request URL]; + BOOL allowNavigationsPass = NO; + NSMutableArray* errorLogs = [NSMutableArray array]; switch (navigationType) { case UIWebViewNavigationTypeLinkClicked: // Note that the rejection strings will *only* print if // it's a link click (and url is not whitelisted by <allow-*>) - if ([self.allowIntentsWhitelist URLIsAllowed:url]) { + if ([self.allowIntentsWhitelist URLIsAllowed:url logFailure:NO]) { // the url *is* in a <allow-intent> tag, push to the system [[UIApplication sharedApplication] openURL:url]; return NO; + } else { + [errorLogs addObject:[NSString stringWithFormat:allowIntents_whitelistRejectionFormatString, [url absoluteString]]]; } // 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]); + allowNavigationsPass = [self.allowNavigationsWhitelist URLIsAllowed:url logFailure:NO]; + // log all failures only when this last filter fails + if (!allowNavigationsPass){ + [errorLogs addObject:[NSString stringWithFormat:allowNavigations_whitelistRejectionFormatString, [url absoluteString]]]; + + // this is the last filter and it failed, now print out all previous error logs + for (NSString* errorLog in errorLogs) { + NSLog(@"%@", errorLog); + } + } + + return allowNavigationsPass; } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org For additional commands, e-mail: commits-h...@cordova.apache.org