You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2012/11/29 02:38:34 UTC
ios commit: [CB-1949][iOS] InAppBrowser - support events (loadstart,
loadstop, exit)
Updated Branches:
refs/heads/master 2ba2b3933 -> 02b5fee98
[CB-1949][iOS] InAppBrowser - support events (loadstart, loadstop, exit)
Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/02b5fee9
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/02b5fee9
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/02b5fee9
Branch: refs/heads/master
Commit: 02b5fee9828b4323d0985928795b154132ac1613
Parents: 2ba2b39
Author: Shazron Abdullah <sh...@apache.org>
Authored: Wed Nov 28 17:38:29 2012 -0800
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Wed Nov 28 17:38:29 2012 -0800
----------------------------------------------------------------------
CordovaLib/Classes/CDVInAppBrowser.h | 12 ++++++-
CordovaLib/Classes/CDVInAppBrowser.m | 55 +++++++++++++++++++++++++++-
2 files changed, 64 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/02b5fee9/CordovaLib/Classes/CDVInAppBrowser.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVInAppBrowser.h b/CordovaLib/Classes/CDVInAppBrowser.h
index 9a74fdd..51199ed 100644
--- a/CordovaLib/Classes/CDVInAppBrowser.h
+++ b/CordovaLib/Classes/CDVInAppBrowser.h
@@ -23,9 +23,18 @@
@class CDVInAppBrowserViewController;
-@interface CDVInAppBrowser : CDVPlugin {}
+@protocol CDVInAppBrowserNavigationDelegate <NSObject>
+
+- (void)browserLoadStart:(NSURL*)url;
+- (void)browserLoadStop:(NSURL*)url;
+- (void)browserExit;
+
+@end
+
+@interface CDVInAppBrowser : CDVPlugin <CDVInAppBrowserNavigationDelegate>{}
@property (nonatomic, retain) CDVInAppBrowserViewController* inAppBrowserViewController;
+@property (nonatomic, copy) NSString* callbackId;
- (void)open:(CDVInvokedUrlCommand*)command;
- (void)close:(CDVInvokedUrlCommand*)command;
@@ -43,6 +52,7 @@
@property (nonatomic, strong) IBOutlet UIToolbar* toolbar;
@property (nonatomic, weak) id <CDVScreenOrientationDelegate> orientationDelegate;
+@property (nonatomic, weak) id <CDVInAppBrowserNavigationDelegate> navigationDelegate;
@property (nonatomic, strong) NSString* userAgent;
- (void)close;
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/02b5fee9/CordovaLib/Classes/CDVInAppBrowser.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVInAppBrowser.m b/CordovaLib/Classes/CDVInAppBrowser.m
index 5a07f7d..06000e7 100644
--- a/CordovaLib/Classes/CDVInAppBrowser.m
+++ b/CordovaLib/Classes/CDVInAppBrowser.m
@@ -48,6 +48,8 @@
if (self.inAppBrowserViewController != nil) {
[self.inAppBrowserViewController close];
}
+
+ self.callbackId = nil;
}
- (void)open:(CDVInvokedUrlCommand*)command
@@ -58,6 +60,8 @@
NSString* target = [command argumentAtIndex:1 withDefault:kInAppBrowserTargetSelf];
NSString* options = [command argumentAtIndex:2 withDefault:@"" andClass:[NSString class]];
+ self.callbackId = command.callbackId;
+
if (url != nil) {
NSURL* baseUrl = [self.webView.request URL];
NSURL* absoluteUrl = [[NSURL URLWithString:url relativeToURL:baseUrl] absoluteURL];
@@ -74,6 +78,7 @@
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"incorrect number of arguments"];
}
+ [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
@@ -82,6 +87,7 @@
if (self.inAppBrowserViewController == nil) {
NSString* originalUA = [CDVViewController originalUserAgent];
self.inAppBrowserViewController = [[CDVInAppBrowserViewController alloc] initWithUserAgent:originalUA];
+ self.inAppBrowserViewController.navigationDelegate = self;
if ([self.viewController conformsToProtocol:@protocol(CDVScreenOrientationDelegate)]) {
self.inAppBrowserViewController.orientationDelegate = (UIViewController <CDVScreenOrientationDelegate>*)self.viewController;
@@ -127,6 +133,41 @@
}
}
+#pragma mark CDVInAppBrowserNavigationDelegate
+
+- (void)browserLoadStart:(NSURL*)url
+{
+ if (self.callbackId != nil) {
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
+ messageAsDictionary:@ {@"type":@"loadstart", @"url":[url absoluteString]}];
+ [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
+
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
+ }
+}
+
+- (void)browserLoadStop:(NSURL*)url
+{
+ if (self.callbackId != nil) {
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
+ messageAsDictionary:@ {@"type":@"loadstop", @"url":[url absoluteString]}];
+ [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
+
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
+ }
+}
+
+- (void)browserExit
+{
+ if (self.callbackId != nil) {
+ CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
+ messageAsDictionary:@ {@"type":@"exit"}];
+ [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
+
+ [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
+ }
+}
+
@end
#pragma mark CDVInAppBrowserViewController
@@ -178,8 +219,6 @@
self.webView.userInteractionEnabled = YES;
}
- // TODO: create nav bar, location bar
-
self.spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite];
self.spinner.alpha = 1.000;
self.spinner.autoresizesSubviews = YES;
@@ -305,6 +344,10 @@
} else {
[[self parentViewController] dismissModalViewControllerAnimated:YES];
}
+
+ if ((self.navigationDelegate != nil) && [self.navigationDelegate respondsToSelector:@selector(browserExit)]) {
+ [self.navigationDelegate browserExit];
+ }
}
- (void)navigateTo:(NSURL*)url
@@ -335,6 +378,10 @@
self.forwardButton.enabled = theWebView.canGoForward;
[self.spinner startAnimating];
+
+ if ((self.navigationDelegate != nil) && [self.navigationDelegate respondsToSelector:@selector(browserLoadStart:)]) {
+ [self.navigationDelegate browserLoadStart:theWebView.request.URL];
+ }
}
- (void)webViewDidFinishLoad:(UIWebView*)theWebView
@@ -346,6 +393,10 @@
self.forwardButton.enabled = theWebView.canGoForward;
[self.spinner stopAnimating];
+
+ if ((self.navigationDelegate != nil) && [self.navigationDelegate respondsToSelector:@selector(browserLoadStop:)]) {
+ [self.navigationDelegate browserLoadStop:theWebView.request.URL];
+ }
}
- (void)webView:(UIWebView*)theWebView didFailLoadWithError:(NSError*)error