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 DB6B5105AF for ; Mon, 29 Apr 2013 16:30:57 +0000 (UTC) Received: (qmail 36116 invoked by uid 500); 29 Apr 2013 16:30:57 -0000 Delivered-To: apmail-cordova-commits-archive@cordova.apache.org Received: (qmail 36094 invoked by uid 500); 29 Apr 2013 16:30:57 -0000 Mailing-List: contact commits-help@cordova.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: callback-dev@cordova.apache.org Delivered-To: mailing list commits@cordova.apache.org Received: (qmail 36086 invoked by uid 99); 29 Apr 2013 16:30:57 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 29 Apr 2013 16:30:57 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 8FE9A883968; Mon, 29 Apr 2013 16:30:57 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: agrieve@apache.org To: commits@cordova.apache.org Message-Id: <7d52caf184934a6fbbad3efc77e80aeb@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: ios commit: [CB-3295] Send InAppBrowser loadstart events when redirects occur Date: Mon, 29 Apr 2013 16:30:57 +0000 (UTC) Updated Branches: refs/heads/master 944912878 -> 3ac92e817 [CB-3295] Send InAppBrowser loadstart events when redirects occur Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/3ac92e81 Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/3ac92e81 Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/3ac92e81 Branch: refs/heads/master Commit: 3ac92e817c59996bb5a046081e3a39256dfc0358 Parents: 9449128 Author: Andrew Grieve Authored: Mon Apr 29 12:29:35 2013 -0400 Committer: Andrew Grieve Committed: Mon Apr 29 12:29:35 2013 -0400 ---------------------------------------------------------------------- CordovaLib/Classes/CDVInAppBrowser.h | 2 +- CordovaLib/Classes/CDVInAppBrowser.m | 34 +++++++++++++++++------------ 2 files changed, 21 insertions(+), 15 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/3ac92e81/CordovaLib/Classes/CDVInAppBrowser.h ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVInAppBrowser.h b/CordovaLib/Classes/CDVInAppBrowser.h index 343f40d..765326a 100644 --- a/CordovaLib/Classes/CDVInAppBrowser.h +++ b/CordovaLib/Classes/CDVInAppBrowser.h @@ -55,7 +55,7 @@ @property (nonatomic, weak) id orientationDelegate; @property (nonatomic, weak) CDVInAppBrowser* navigationDelegate; -@property (nonatomic) NSURL* requestedURL; +@property (nonatomic) NSURL* currentURL; - (void)close; - (void)navigateTo:(NSURL*)url; http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/3ac92e81/CordovaLib/Classes/CDVInAppBrowser.m ---------------------------------------------------------------------- diff --git a/CordovaLib/Classes/CDVInAppBrowser.m b/CordovaLib/Classes/CDVInAppBrowser.m index f366bd8..b03d1fe 100644 --- a/CordovaLib/Classes/CDVInAppBrowser.m +++ b/CordovaLib/Classes/CDVInAppBrowser.m @@ -253,6 +253,7 @@ - (BOOL)webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType { NSURL* url = request.URL; + BOOL isTopLevelNavigation = [request.URL isEqual:[request mainDocumentURL]]; // See if the url uses the 'gap-iab' protocol. If so, the host should be the id of a callback to execute, // and the path, if present, should be a JSON-encoded value to pass to the callback. @@ -279,28 +280,28 @@ [self.commandDelegate sendPluginResult:pluginResult callbackId:scriptCallbackId]; return NO; } + } else if ((self.callbackId != nil) && isTopLevelNavigation) { + // Send a loadstart event for each top-level navigation (includes redirects). + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK + messageAsDictionary:@{@"type":@"loadstart", @"url":[url absoluteString]}]; + [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]]; + + [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; } + return YES; } - (void)webViewDidStartLoad:(UIWebView*)theWebView { _injectedIframeBridge = NO; - if (self.callbackId != nil) { - NSString* url = [[self.inAppBrowserViewController requestedURL] absoluteString]; - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK - messageAsDictionary:@{@"type":@"loadstart", @"url":url}]; - [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]]; - - [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; - } } - (void)webViewDidFinishLoad:(UIWebView*)theWebView { if (self.callbackId != nil) { // TODO: It would be more useful to return the URL the page is actually on (e.g. if it's been redirected). - NSString* url = [[self.inAppBrowserViewController requestedURL] absoluteString]; + NSString* url = [self.inAppBrowserViewController.currentURL absoluteString]; CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:@{@"type":@"loadstop", @"url":url}]; [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]]; @@ -312,7 +313,7 @@ - (void)webView:(UIWebView*)theWebView didFailLoadWithError:(NSError*)error { if (self.callbackId != nil) { - NSString* url = [[self.inAppBrowserViewController requestedURL] absoluteString]; + NSString* url = [self.inAppBrowserViewController.currentURL absoluteString]; CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:@{@"type":@"loaderror", @"url":url, @"code": [NSNumber numberWithInt:error.code], @"message": error.localizedDescription}]; [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]]; @@ -341,7 +342,7 @@ @implementation CDVInAppBrowserViewController -@synthesize requestedURL = _requestedURL; +@synthesize currentURL; - (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent { @@ -517,6 +518,8 @@ [[self parentViewController] dismissModalViewControllerAnimated:YES]; } + self.currentURL = nil; + if ((self.navigationDelegate != nil) && [self.navigationDelegate respondsToSelector:@selector(browserExit)]) { [self.navigationDelegate browserExit]; } @@ -526,8 +529,6 @@ { NSURLRequest* request = [NSURLRequest requestWithURL:url]; - _requestedURL = url; - if (_userAgentLockToken != 0) { [self.webView loadRequest:request]; } else { @@ -566,6 +567,11 @@ - (BOOL)webView:(UIWebView*)theWebView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType { + BOOL isTopLevelNavigation = [request.URL isEqual:[request mainDocumentURL]]; + + if (isTopLevelNavigation) { + self.currentURL = request.URL; + } return [self.navigationDelegate webView:theWebView shouldStartLoadWithRequest:request navigationType:navigationType]; } @@ -573,7 +579,7 @@ { // update url, stop spinner, update back/forward - self.addressLabel.text = theWebView.request.URL.absoluteString; + self.addressLabel.text = [self.currentURL absoluteString]; self.backButton.enabled = theWebView.canGoBack; self.forwardButton.enabled = theWebView.canGoForward;