Merge branch 'master' into CB-7179

This commit is contained in:
Dave Alden
2018-10-09 11:15:23 +01:00
6 changed files with 134 additions and 20 deletions
+1
View File
@@ -45,6 +45,7 @@
@property (nonatomic, assign) BOOL suppressesincrementalrendering;
@property (nonatomic, assign) BOOL hidden;
@property (nonatomic, assign) BOOL disallowoverscroll;
@property (nonatomic, assign) BOOL beforeload;
+ (CDVInAppBrowserOptions*)parseOptions:(NSString*)options;
+5
View File
@@ -33,6 +33,10 @@
@interface CDVUIInAppBrowser : CDVPlugin {
UIWindow * tmpWindow;
@private
BOOL _useBeforeload;
BOOL _waitForBeforeload;
}
@property (nonatomic, retain) CDVUIInAppBrowserViewController* inAppBrowserViewController;
@@ -45,6 +49,7 @@
- (void)injectScriptCode:(CDVInvokedUrlCommand*)command;
- (void)show:(CDVInvokedUrlCommand*)command;
- (void)hide:(CDVInvokedUrlCommand*)command;
- (void)loadAfterBeforeload:(CDVInvokedUrlCommand*)command;
@end
+46 -4
View File
@@ -53,6 +53,8 @@ static CDVUIInAppBrowser* instance = nil;
instance = self;
_previousStatusBarStyle = -1;
_callbackIdPattern = nil;
_useBeforeload = NO;
_waitForBeforeload = NO;
}
- (id)settingForKey:(NSString*)key
@@ -216,6 +218,10 @@ static CDVUIInAppBrowser* instance = nil;
self.inAppBrowserViewController.webView.suppressesIncrementalRendering = browserOptions.suppressesincrementalrendering;
}
// use of beforeload event
_useBeforeload = browserOptions.beforeload;
_waitForBeforeload = browserOptions.beforeload;
[self.inAppBrowserViewController navigateTo:url];
if (!browserOptions.hidden) {
[self show:nil];
@@ -312,6 +318,27 @@ static CDVUIInAppBrowser* instance = nil;
}
}
- (void)loadAfterBeforeload:(CDVInvokedUrlCommand*)command
{
NSString* urlStr = [command argumentAtIndex:0];
if (!_useBeforeload) {
NSLog(@"unexpected loadAfterBeforeload called without feature beforeload=yes");
}
if (self.inAppBrowserViewController == nil) {
NSLog(@"Tried to invoke loadAfterBeforeload on IAB after it was closed.");
return;
}
if (urlStr == nil) {
NSLog(@"loadAfterBeforeload called with nil argument, ignoring.");
return;
}
NSURL* url = [NSURL URLWithString:urlStr];
_waitForBeforeload = NO;
[self.inAppBrowserViewController navigateTo:url];
}
// This is a helper method for the inject{Script|Style}{Code|File} API calls, which
// provides a consistent method for injecting JavaScript code into the document.
//
@@ -421,6 +448,7 @@ static CDVUIInAppBrowser* instance = nil;
{
NSURL* url = request.URL;
BOOL isTopLevelNavigation = [request.URL isEqual:[request mainDocumentURL]];
BOOL shouldStart = YES;
// 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.
@@ -448,11 +476,22 @@ static CDVUIInAppBrowser* instance = nil;
return NO;
}
}
// When beforeload=yes, on first URL change, initiate JS callback. Only after the beforeload event, continue.
if (_waitForBeforeload && isTopLevelNavigation) {
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:@{@"type":@"beforeload", @"url":[url absoluteString]}];
[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
return NO;
}
//if is an app store link, let the system handle it, otherwise it fails to load it
else if ([[ url scheme] isEqualToString:@"itms-appss"] || [[ url scheme] isEqualToString:@"itms-apps"]) {
if ([[ url scheme] isEqualToString:@"itms-appss"] || [[ url scheme] isEqualToString:@"itms-apps"]) {
[theWebView stopLoading];
[self openInSystem:url];
return NO;
shouldStart = NO;
}
else if ((self.callbackId != nil) && isTopLevelNavigation) {
// Send a loadstart event for each top-level navigation (includes redirects).
@@ -463,8 +502,11 @@ static CDVUIInAppBrowser* instance = nil;
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
}
return YES;
}
if (_useBeforeload && isTopLevelNavigation) {
_waitForBeforeload = YES;
}
return shouldStart;
- (void)webViewDidStartLoad:(UIWebView*)theWebView
{