Repository: cordova-ios Updated Branches: refs/heads/master d5f570efa -> cf367cb49
CB-7560 - Tel and Mailto links don't work in iframe Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/cf367cb4 Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/cf367cb4 Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/cf367cb4 Branch: refs/heads/master Commit: cf367cb49916196ce6009b54c4a6dfa9779be20c Parents: d5f570e Author: Shazron Abdullah <shaz...@apache.org> Authored: Mon Sep 15 23:04:38 2014 -0700 Committer: Shazron Abdullah <shaz...@apache.org> Committed: Mon Sep 15 23:04:38 2014 -0700 ---------------------------------------------------------------------- CordovaLib/Classes/CDVWebViewDelegate.m | 13 ++++++++++++- CordovaLibTests/CDVWebViewDelegateTests.m | 21 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/cf367cb4/CordovaLib/Classes/CDVWebViewDelegate.m ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVWebViewDelegate.m b/CordovaLib/Classes/CDVWebViewDelegate.m index 6bac3fa..cdc3980 100644 --- a/CordovaLib/Classes/CDVWebViewDelegate.m +++ b/CordovaLib/Classes/CDVWebViewDelegate.m @@ -198,6 +198,17 @@ static NSString *stripFragment(NSString* url) } } +- (BOOL)shouldLoadRequest:(NSURLRequest*)request +{ + NSString* scheme = [[request URL] scheme]; + + if ([scheme isEqualToString:@"mailto"] || [scheme isEqualToString:@"tel"]) { + return YES; + } + + return [NSURLConnection canHandleRequest:request]; +} + - (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType { BOOL shouldLoad = YES; @@ -259,7 +270,7 @@ static NSString *stripFragment(NSString* url) } else { // Deny invalid URLs so that we don't get the case where we go straight from // webViewShouldLoad -> webViewDidFailLoad (messes up _loadCount). - shouldLoad = shouldLoad && [NSURLConnection canHandleRequest:request]; + shouldLoad = shouldLoad && [self shouldLoadRequest:request]; } VerboseLog(@"webView shouldLoad=%d (after) isTopLevelNavigation=%d state=%d loadCount=%d", shouldLoad, isTopLevelNavigation, _state, _loadCount); } http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/cf367cb4/CordovaLibTests/CDVWebViewDelegateTests.m ---------------------------------------------------------------------- diff --git a/CordovaLibTests/CDVWebViewDelegateTests.m b/CordovaLibTests/CDVWebViewDelegateTests.m index 15af654..7edd189 100644 --- a/CordovaLibTests/CDVWebViewDelegateTests.m +++ b/CordovaLibTests/CDVWebViewDelegateTests.m @@ -21,6 +21,13 @@ #import <Cordova/CDVWebViewDelegate.h> +@interface CDVWebViewDelegate () + +// expose private interface +- (BOOL)shouldLoadRequest:(NSURLRequest*)request; + +@end + @interface CDVWebViewDelegateTests : XCTestCase @end @@ -36,6 +43,20 @@ [super tearDown]; } +- (void)testShouldLoadRequest +{ + CDVWebViewDelegate* wvd = [[CDVWebViewDelegate alloc] initWithDelegate:nil]; // not really testing delegate handling + + NSURLRequest* mailtoUrl = [NSURLRequest requestWithURL:[NSURL URLWithString:@"mailto:d...@cordova.apache.org"]]; + NSURLRequest* telUrl = [NSURLRequest requestWithURL:[NSURL URLWithString:@"tel:12345"]]; + NSURLRequest* plainUrl = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://apache.org"]]; + + XCTAssertTrue([wvd shouldLoadRequest:mailtoUrl], @"mailto urls should be allowed"); + XCTAssertTrue([wvd shouldLoadRequest:telUrl], @"tel urls should be allowed"); + // as long as this is in the whitelist it should pass + XCTAssertTrue([wvd shouldLoadRequest:plainUrl], @"http urls should be allowed"); +} + - (void)testFragmentIdentifiersWithHttpUrl { [self doTestFragmentIdentifiersWithBaseUrl:@"http://cordova.apache.org" fragment:@"myfragment"];