cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From agri...@apache.org
Subject [4/4] ios commit: Fix InAppBrowser handling of NSNull relative URLS.
Date Fri, 23 Nov 2012 02:38:31 GMT
Fix InAppBrowser handling of NSNull relative URLS.

It now works with the mobile-spec test page for it.


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

Branch: refs/heads/master
Commit: 66fed794b0a105816172c2cfd2757b04ceb8ef46
Parents: eb48666
Author: Andrew Grieve <agrieve@chromium.org>
Authored: Thu Nov 22 21:26:02 2012 -0500
Committer: Andrew Grieve <agrieve@chromium.org>
Committed: Thu Nov 22 21:26:02 2012 -0500

----------------------------------------------------------------------
 CordovaLib/Classes/CDVInAppBrowser.h |    2 +-
 CordovaLib/Classes/CDVInAppBrowser.m |   43 +++++++++++++---------------
 2 files changed, 21 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/66fed794/CordovaLib/Classes/CDVInAppBrowser.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVInAppBrowser.h b/CordovaLib/Classes/CDVInAppBrowser.h
index 100d3ee..9a74fdd 100644
--- a/CordovaLib/Classes/CDVInAppBrowser.h
+++ b/CordovaLib/Classes/CDVInAppBrowser.h
@@ -46,7 +46,7 @@
 @property (nonatomic, strong) NSString* userAgent;
 
 - (void)close;
-- (void)navigateTo:(NSString*)url;
+- (void)navigateTo:(NSURL*)url;
 - (void)showLocationBar:(BOOL)show;
 
 - (id)initWithUserAgent:(NSString*)userAgent;

http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/66fed794/CordovaLib/Classes/CDVInAppBrowser.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVInAppBrowser.m b/CordovaLib/Classes/CDVInAppBrowser.m
index b263534..006eb41 100644
--- a/CordovaLib/Classes/CDVInAppBrowser.m
+++ b/CordovaLib/Classes/CDVInAppBrowser.m
@@ -52,21 +52,21 @@
 
 - (void)open:(CDVInvokedUrlCommand*)command
 {
-    NSArray* arguments = command.arguments;
-    int argc = [arguments count];
     CDVPluginResult* pluginResult;
 
-    if (argc > 0) {
-        NSString* url = [arguments objectAtIndex:0];
-        NSString* target = (argc > 1) ? [arguments objectAtIndex:1] : kInAppBrowserTargetSelf;
-        NSString* options = (argc > 2) ? [arguments objectAtIndex:2] : @"";
+    NSString* url = [command argumentAtIndex:0];
+    NSString* target = [command argumentAtIndex:1 withDefault:kInAppBrowserTargetSelf];
+    NSString* options = [command argumentAtIndex:2 withDefault:@""];
 
+    if (url != nil) {
+        NSURL* baseUrl = [self.webView.request URL];
+        NSURL* absoluteUrl = [[NSURL URLWithString:url relativeToURL:baseUrl] absoluteURL];
         if ([target isEqualToString:kInAppBrowserTargetSelf]) {
-            [self openInCordovaWebView:url withOptions:options];
+            [self openInCordovaWebView:absoluteUrl withOptions:options];
         } else if ([target isEqualToString:kInAppBrowserTargetSystem]) {
-            [self openInSystem:url];
+            [self openInSystem:absoluteUrl];
         } else { // _blank or anything else
-            [self openInInAppBrowser:url withOptions:options];
+            [self openInInAppBrowser:absoluteUrl withOptions:options];
         }
 
         pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
@@ -77,7 +77,7 @@
     [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
 }
 
-- (void)openInInAppBrowser:(NSString*)url withOptions:(NSString*)options
+- (void)openInInAppBrowser:(NSURL*)url withOptions:(NSString*)options
 {
     if (self.inAppBrowserViewController == nil) {
         NSString* originalUA = [self.webView stringByEvaluatingJavaScriptFromString:@"navigator.userAgent"];
@@ -103,36 +103,33 @@
     [self.inAppBrowserViewController navigateTo:url];
 }
 
-- (void)openInCordovaWebView:(NSString*)url withOptions:(NSString*)options
+- (void)openInCordovaWebView:(NSURL*)url withOptions:(NSString*)options
 {
-    NSURL* urlObj = [NSURL URLWithString:url];
     BOOL passesWhitelist = YES;
 
     if ([self.viewController isKindOfClass:[CDVViewController class]]) {
         CDVViewController* vc = (CDVViewController*)self.viewController;
-        if ([vc.whitelist schemeIsAllowed:[urlObj scheme]]) {
-            passesWhitelist = [vc.whitelist URLIsAllowed:urlObj];
+        if ([vc.whitelist schemeIsAllowed:[url scheme]]) {
+            passesWhitelist = [vc.whitelist URLIsAllowed:url];
         }
     } else { // something went wrong, we can't get the whitelist
         passesWhitelist = NO;
     }
 
     if (passesWhitelist) {
-        NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
+        NSURLRequest* request = [NSURLRequest requestWithURL:url];
         [self.webView loadRequest:request];
     } else { // this assumes the InAppBrowser can be excepted from the white-list
         [self openInInAppBrowser:url withOptions:options];
     }
 }
 
-- (void)openInSystem:(NSString*)url
+- (void)openInSystem:(NSURL*)url
 {
-    NSURL* urlObj = [NSURL URLWithString:url];
-
-    if ([[UIApplication sharedApplication] canOpenURL:urlObj]) {
-        [[UIApplication sharedApplication] openURL:urlObj];
+    if ([[UIApplication sharedApplication] canOpenURL:url]) {
+        [[UIApplication sharedApplication] openURL:url];
     } else { // handle any custom schemes to plugins
-        [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification
object:urlObj]];
+        [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPluginHandleOpenURLNotification
object:url]];
     }
 }
 
@@ -314,9 +311,9 @@
     }
 }
 
-- (void)navigateTo:(NSString*)url
+- (void)navigateTo:(NSURL*)url
 {
-    NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
+    NSURLRequest* request = [NSURLRequest requestWithURL:url];
 
     [self.webView loadRequest:request];
 }


Mime
View raw message