cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From shaz...@apache.org
Subject ios commit: CB-10001 CB-10003 Handle <allow-navigation> and <allow-intent>
Date Tue, 17 Nov 2015 23:28:37 GMT
Repository: cordova-ios
Updated Branches:
  refs/heads/master 10e17d6d0 -> 34da32625


CB-10001 CB-10003 Handle <allow-navigation> and <allow-intent>


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 <shazron@apache.org>
Authored: Tue Nov 17 15:28:57 2015 -0800
Committer: Shazron Abdullah <shazron@apache.org>
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 <NSXMLParserDelegate>
 
 @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 <Cordova/CDV.h>
 
 @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 <allow-navigations> 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 - <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
+{
+    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 <allow-*>)
+            if ([self.allowIntentsWhitelist URLIsAllowed:url]) {
+                // the url *is* in a <allow-intent> 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 @@
         <param name="ios-package" value="CDVHandleOpenURL"/>
         <param name="onload" value="true"/>
     </feature>
+    <feature name="SystemSchemes">
+        <param name="ios-package" value="CDVSystemSchemes"/>
+        <param name="onload" value="true"/>
+    </feature>
     <feature name="GestureHandler">
         <param name="ios-package" value="CDVGestureHandler"/>
         <param name="onload" value="true"/>


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message