ios: added InAppBrowserStatusBarStyle preference (#728)

This commit is contained in:
Moses Berra 2020-08-18 12:40:13 -05:00
parent 91ebdf2776
commit 2a28e09a70

View File

@ -6,9 +6,9 @@
to you under the Apache License, Version 2.0 (the to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0 http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@ -73,7 +73,7 @@ static CDVWKInAppBrowser* instance = nil;
NSLog(@"IAB.close() called but it was already closed."); NSLog(@"IAB.close() called but it was already closed.");
return; return;
} }
// Things are cleaned up in browserExit. // Things are cleaned up in browserExit.
[self.inAppBrowserViewController close]; [self.inAppBrowserViewController close];
} }
@ -83,28 +83,28 @@ static CDVWKInAppBrowser* instance = nil;
if ([[url host] isEqualToString:@"itunes.apple.com"]) { if ([[url host] isEqualToString:@"itunes.apple.com"]) {
return YES; return YES;
} }
return NO; return NO;
} }
- (void)open:(CDVInvokedUrlCommand*)command - (void)open:(CDVInvokedUrlCommand*)command
{ {
CDVPluginResult* pluginResult; CDVPluginResult* pluginResult;
NSString* url = [command argumentAtIndex:0]; NSString* url = [command argumentAtIndex:0];
NSString* target = [command argumentAtIndex:1 withDefault:kInAppBrowserTargetSelf]; NSString* target = [command argumentAtIndex:1 withDefault:kInAppBrowserTargetSelf];
NSString* options = [command argumentAtIndex:2 withDefault:@"" andClass:[NSString class]]; NSString* options = [command argumentAtIndex:2 withDefault:@"" andClass:[NSString class]];
self.callbackId = command.callbackId; self.callbackId = command.callbackId;
if (url != nil) { if (url != nil) {
NSURL* baseUrl = [self.webViewEngine URL]; NSURL* baseUrl = [self.webViewEngine URL];
NSURL* absoluteUrl = [[NSURL URLWithString:url relativeToURL:baseUrl] absoluteURL]; NSURL* absoluteUrl = [[NSURL URLWithString:url relativeToURL:baseUrl] absoluteURL];
if ([self isSystemUrl:absoluteUrl]) { if ([self isSystemUrl:absoluteUrl]) {
target = kInAppBrowserTargetSystem; target = kInAppBrowserTargetSystem;
} }
if ([target isEqualToString:kInAppBrowserTargetSelf]) { if ([target isEqualToString:kInAppBrowserTargetSelf]) {
[self openInCordovaWebView:absoluteUrl withOptions:options]; [self openInCordovaWebView:absoluteUrl withOptions:options];
} else if ([target isEqualToString:kInAppBrowserTargetSystem]) { } else if ([target isEqualToString:kInAppBrowserTargetSystem]) {
@ -112,12 +112,12 @@ static CDVWKInAppBrowser* instance = nil;
} else { // _blank or anything else } else { // _blank or anything else
[self openInInAppBrowser:absoluteUrl withOptions:options]; [self openInInAppBrowser:absoluteUrl withOptions:options];
} }
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} else { } else {
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"incorrect number of arguments"]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"incorrect number of arguments"];
} }
[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]]; [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
} }
@ -125,17 +125,17 @@ static CDVWKInAppBrowser* instance = nil;
- (void)openInInAppBrowser:(NSURL*)url withOptions:(NSString*)options - (void)openInInAppBrowser:(NSURL*)url withOptions:(NSString*)options
{ {
CDVInAppBrowserOptions* browserOptions = [CDVInAppBrowserOptions parseOptions:options]; CDVInAppBrowserOptions* browserOptions = [CDVInAppBrowserOptions parseOptions:options];
WKWebsiteDataStore* dataStore = [WKWebsiteDataStore defaultDataStore]; WKWebsiteDataStore* dataStore = [WKWebsiteDataStore defaultDataStore];
if (browserOptions.cleardata) { if (browserOptions.cleardata) {
NSDate* dateFrom = [NSDate dateWithTimeIntervalSince1970:0]; NSDate* dateFrom = [NSDate dateWithTimeIntervalSince1970:0];
[dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:dateFrom completionHandler:^{ [dataStore removeDataOfTypes:[WKWebsiteDataStore allWebsiteDataTypes] modifiedSince:dateFrom completionHandler:^{
NSLog(@"Removed all WKWebView data"); NSLog(@"Removed all WKWebView data");
self.inAppBrowserViewController.webView.configuration.processPool = [[WKProcessPool alloc] init]; // create new process pool to flush all data self.inAppBrowserViewController.webView.configuration.processPool = [[WKProcessPool alloc] init]; // create new process pool to flush all data
}]; }];
} }
if (browserOptions.clearcache) { if (browserOptions.clearcache) {
bool isAtLeastiOS11 = false; bool isAtLeastiOS11 = false;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
@ -143,7 +143,7 @@ static CDVWKInAppBrowser* instance = nil;
isAtLeastiOS11 = true; isAtLeastiOS11 = true;
} }
#endif #endif
if(isAtLeastiOS11){ if(isAtLeastiOS11){
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
// Deletes all cookies // Deletes all cookies
@ -171,7 +171,7 @@ static CDVWKInAppBrowser* instance = nil;
}]; }];
} }
} }
if (browserOptions.clearsessioncache) { if (browserOptions.clearsessioncache) {
bool isAtLeastiOS11 = false; bool isAtLeastiOS11 = false;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
@ -200,12 +200,12 @@ static CDVWKInAppBrowser* instance = nil;
if (self.inAppBrowserViewController == nil) { if (self.inAppBrowserViewController == nil) {
self.inAppBrowserViewController = [[CDVWKInAppBrowserViewController alloc] initWithBrowserOptions: browserOptions andSettings:self.commandDelegate.settings]; self.inAppBrowserViewController = [[CDVWKInAppBrowserViewController alloc] initWithBrowserOptions: browserOptions andSettings:self.commandDelegate.settings];
self.inAppBrowserViewController.navigationDelegate = self; self.inAppBrowserViewController.navigationDelegate = self;
if ([self.viewController conformsToProtocol:@protocol(CDVScreenOrientationDelegate)]) { if ([self.viewController conformsToProtocol:@protocol(CDVScreenOrientationDelegate)]) {
self.inAppBrowserViewController.orientationDelegate = (UIViewController <CDVScreenOrientationDelegate>*)self.viewController; self.inAppBrowserViewController.orientationDelegate = (UIViewController <CDVScreenOrientationDelegate>*)self.viewController;
} }
} }
[self.inAppBrowserViewController showLocationBar:browserOptions.location]; [self.inAppBrowserViewController showLocationBar:browserOptions.location];
[self.inAppBrowserViewController showToolBar:browserOptions.toolbar :browserOptions.toolbarposition]; [self.inAppBrowserViewController showToolBar:browserOptions.toolbar :browserOptions.toolbarposition];
if (browserOptions.closebuttoncaption != nil || browserOptions.closebuttoncolor != nil) { if (browserOptions.closebuttoncaption != nil || browserOptions.closebuttoncolor != nil) {
@ -222,7 +222,7 @@ static CDVWKInAppBrowser* instance = nil;
} }
} }
self.inAppBrowserViewController.modalPresentationStyle = presentationStyle; self.inAppBrowserViewController.modalPresentationStyle = presentationStyle;
// Set Transition Style // Set Transition Style
UIModalTransitionStyle transitionStyle = UIModalTransitionStyleCoverVertical; // default UIModalTransitionStyle transitionStyle = UIModalTransitionStyleCoverVertical; // default
if (browserOptions.transitionstyle != nil) { if (browserOptions.transitionstyle != nil) {
@ -233,7 +233,7 @@ static CDVWKInAppBrowser* instance = nil;
} }
} }
self.inAppBrowserViewController.modalTransitionStyle = transitionStyle; self.inAppBrowserViewController.modalTransitionStyle = transitionStyle;
//prevent webView from bouncing //prevent webView from bouncing
if (browserOptions.disallowoverscroll) { if (browserOptions.disallowoverscroll) {
if ([self.inAppBrowserViewController.webView respondsToSelector:@selector(scrollView)]) { if ([self.inAppBrowserViewController.webView respondsToSelector:@selector(scrollView)]) {
@ -246,7 +246,7 @@ static CDVWKInAppBrowser* instance = nil;
} }
} }
} }
// use of beforeload event // use of beforeload event
if([browserOptions.beforeload isKindOfClass:[NSString class]]){ if([browserOptions.beforeload isKindOfClass:[NSString class]]){
_beforeload = browserOptions.beforeload; _beforeload = browserOptions.beforeload;
@ -254,7 +254,7 @@ static CDVWKInAppBrowser* instance = nil;
_beforeload = @"yes"; _beforeload = @"yes";
} }
_waitForBeforeload = ![_beforeload isEqualToString:@""]; _waitForBeforeload = ![_beforeload isEqualToString:@""];
[self.inAppBrowserViewController navigateTo:url]; [self.inAppBrowserViewController navigateTo:url];
if (!browserOptions.hidden) { if (!browserOptions.hidden) {
[self show:nil withNoAnimate:browserOptions.hidden]; [self show:nil withNoAnimate:browserOptions.hidden];
@ -271,7 +271,7 @@ static CDVWKInAppBrowser* instance = nil;
if(command == nil && noAnimate == YES){ if(command == nil && noAnimate == YES){
initHidden = YES; initHidden = YES;
} }
if (self.inAppBrowserViewController == nil) { if (self.inAppBrowserViewController == nil) {
NSLog(@"Tried to show IAB after it was closed."); NSLog(@"Tried to show IAB after it was closed.");
return; return;
@ -280,20 +280,20 @@ static CDVWKInAppBrowser* instance = nil;
NSLog(@"Tried to show IAB while already shown"); NSLog(@"Tried to show IAB while already shown");
return; return;
} }
if(!initHidden){ if(!initHidden){
_previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle; _previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle;
} }
__block CDVInAppBrowserNavigationController* nav = [[CDVInAppBrowserNavigationController alloc] __block CDVInAppBrowserNavigationController* nav = [[CDVInAppBrowserNavigationController alloc]
initWithRootViewController:self.inAppBrowserViewController]; initWithRootViewController:self.inAppBrowserViewController];
nav.orientationDelegate = self.inAppBrowserViewController; nav.orientationDelegate = self.inAppBrowserViewController;
nav.navigationBarHidden = YES; nav.navigationBarHidden = YES;
nav.modalPresentationStyle = self.inAppBrowserViewController.modalPresentationStyle; nav.modalPresentationStyle = self.inAppBrowserViewController.modalPresentationStyle;
nav.presentationController.delegate = self.inAppBrowserViewController; nav.presentationController.delegate = self.inAppBrowserViewController;
__weak CDVWKInAppBrowser* weakSelf = self; __weak CDVWKInAppBrowser* weakSelf = self;
// Run later to avoid the "took a long time" log message. // Run later to avoid the "took a long time" log message.
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
if (weakSelf.inAppBrowserViewController != nil) { if (weakSelf.inAppBrowserViewController != nil) {
@ -328,16 +328,16 @@ static CDVWKInAppBrowser* instance = nil;
if (self.inAppBrowserViewController == nil) { if (self.inAppBrowserViewController == nil) {
NSLog(@"Tried to hide IAB after it was closed."); NSLog(@"Tried to hide IAB after it was closed.");
return; return;
} }
if (_previousStatusBarStyle == -1) { if (_previousStatusBarStyle == -1) {
NSLog(@"Tried to hide IAB while already hidden"); NSLog(@"Tried to hide IAB while already hidden");
return; return;
} }
_previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle; _previousStatusBarStyle = [UIApplication sharedApplication].statusBarStyle;
// Run later to avoid the "took a long time" log message. // Run later to avoid the "took a long time" log message.
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
if (self.inAppBrowserViewController != nil) { if (self.inAppBrowserViewController != nil) {
@ -398,7 +398,7 @@ static CDVWKInAppBrowser* instance = nil;
{ {
// Ensure a message handler bridge is created to communicate with the CDVWKInAppBrowserViewController // Ensure a message handler bridge is created to communicate with the CDVWKInAppBrowserViewController
[self evaluateJavaScript: [NSString stringWithFormat:@"(function(w){if(!w._cdvMessageHandler) {w._cdvMessageHandler = function(id,d){w.webkit.messageHandlers.%@.postMessage({d:d, id:id});}}})(window)", IAB_BRIDGE_NAME]]; [self evaluateJavaScript: [NSString stringWithFormat:@"(function(w){if(!w._cdvMessageHandler) {w._cdvMessageHandler = function(id,d){w.webkit.messageHandlers.%@.postMessage({d:d, id:id});}}})(window)", IAB_BRIDGE_NAME]];
if (jsWrapper != nil) { if (jsWrapper != nil) {
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:@[source] options:0 error:nil]; NSData* jsonData = [NSJSONSerialization dataWithJSONObject:@[source] options:0 error:nil];
NSString* sourceArrayString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; NSString* sourceArrayString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
@ -430,7 +430,7 @@ static CDVWKInAppBrowser* instance = nil;
- (void)injectScriptCode:(CDVInvokedUrlCommand*)command - (void)injectScriptCode:(CDVInvokedUrlCommand*)command
{ {
NSString* jsWrapper = nil; NSString* jsWrapper = nil;
if ((command.callbackId != nil) && ![command.callbackId isEqualToString:@"INVALID"]) { if ((command.callbackId != nil) && ![command.callbackId isEqualToString:@"INVALID"]) {
jsWrapper = [NSString stringWithFormat:@"_cdvMessageHandler('%@',JSON.stringify([eval(%%@)]));", command.callbackId]; jsWrapper = [NSString stringWithFormat:@"_cdvMessageHandler('%@',JSON.stringify([eval(%%@)]));", command.callbackId];
} }
@ -440,7 +440,7 @@ static CDVWKInAppBrowser* instance = nil;
- (void)injectScriptFile:(CDVInvokedUrlCommand*)command - (void)injectScriptFile:(CDVInvokedUrlCommand*)command
{ {
NSString* jsWrapper; NSString* jsWrapper;
if ((command.callbackId != nil) && ![command.callbackId isEqualToString:@"INVALID"]) { if ((command.callbackId != nil) && ![command.callbackId isEqualToString:@"INVALID"]) {
jsWrapper = [NSString stringWithFormat:@"(function(d) { var c = d.createElement('script'); c.src = %%@; c.onload = function() { _cdvMessageHandler('%@'); }; d.body.appendChild(c); })(document)", command.callbackId]; jsWrapper = [NSString stringWithFormat:@"(function(d) { var c = d.createElement('script'); c.src = %%@; c.onload = function() { _cdvMessageHandler('%@'); }; d.body.appendChild(c); })(document)", command.callbackId];
} else { } else {
@ -452,7 +452,7 @@ static CDVWKInAppBrowser* instance = nil;
- (void)injectStyleCode:(CDVInvokedUrlCommand*)command - (void)injectStyleCode:(CDVInvokedUrlCommand*)command
{ {
NSString* jsWrapper; NSString* jsWrapper;
if ((command.callbackId != nil) && ![command.callbackId isEqualToString:@"INVALID"]) { if ((command.callbackId != nil) && ![command.callbackId isEqualToString:@"INVALID"]) {
jsWrapper = [NSString stringWithFormat:@"(function(d) { var c = d.createElement('style'); c.innerHTML = %%@; c.onload = function() { _cdvMessageHandler('%@'); }; d.body.appendChild(c); })(document)", command.callbackId]; jsWrapper = [NSString stringWithFormat:@"(function(d) { var c = d.createElement('style'); c.innerHTML = %%@; c.onload = function() { _cdvMessageHandler('%@'); }; d.body.appendChild(c); })(document)", command.callbackId];
} else { } else {
@ -464,7 +464,7 @@ static CDVWKInAppBrowser* instance = nil;
- (void)injectStyleFile:(CDVInvokedUrlCommand*)command - (void)injectStyleFile:(CDVInvokedUrlCommand*)command
{ {
NSString* jsWrapper; NSString* jsWrapper;
if ((command.callbackId != nil) && ![command.callbackId isEqualToString:@"INVALID"]) { if ((command.callbackId != nil) && ![command.callbackId isEqualToString:@"INVALID"]) {
jsWrapper = [NSString stringWithFormat:@"(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %%@; c.onload = function() { _cdvMessageHandler('%@'); }; d.body.appendChild(c); })(document)", command.callbackId]; jsWrapper = [NSString stringWithFormat:@"(function(d) { var c = d.createElement('link'); c.rel='stylesheet'; c.type='text/css'; c.href = %%@; c.onload = function() { _cdvMessageHandler('%@'); }; d.body.appendChild(c); })(document)", command.callbackId];
} else { } else {
@ -496,7 +496,7 @@ static CDVWKInAppBrowser* instance = nil;
* other code execution is possible. * other code execution is possible.
*/ */
- (void)webView:(WKWebView *)theWebView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler { - (void)webView:(WKWebView *)theWebView decidePolicyForNavigationAction:(WKNavigationAction *)navigationAction decisionHandler:(void (^)(WKNavigationActionPolicy))decisionHandler {
NSURL* url = navigationAction.request.URL; NSURL* url = navigationAction.request.URL;
NSURL* mainDocumentURL = navigationAction.request.mainDocumentURL; NSURL* mainDocumentURL = navigationAction.request.mainDocumentURL;
BOOL isTopLevelNavigation = [url isEqual:mainDocumentURL]; BOOL isTopLevelNavigation = [url isEqual:mainDocumentURL];
@ -504,7 +504,7 @@ static CDVWKInAppBrowser* instance = nil;
BOOL useBeforeLoad = NO; BOOL useBeforeLoad = NO;
NSString* httpMethod = navigationAction.request.HTTPMethod; NSString* httpMethod = navigationAction.request.HTTPMethod;
NSString* errorMessage = nil; NSString* errorMessage = nil;
if([_beforeload isEqualToString:@"post"]){ if([_beforeload isEqualToString:@"post"]){
//TODO handle POST requests by preserving POST data then remove this condition //TODO handle POST requests by preserving POST data then remove this condition
errorMessage = @"beforeload doesn't yet support POST requests"; errorMessage = @"beforeload doesn't yet support POST requests";
@ -523,12 +523,12 @@ static CDVWKInAppBrowser* instance = nil;
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:@{@"type":@"beforeload", @"url":[url absoluteString]}]; messageAsDictionary:@{@"type":@"beforeload", @"url":[url absoluteString]}];
[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]]; [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
decisionHandler(WKNavigationActionPolicyCancel); decisionHandler(WKNavigationActionPolicyCancel);
return; return;
} }
if(errorMessage != nil){ if(errorMessage != nil){
NSLog(errorMessage); NSLog(errorMessage);
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
@ -536,7 +536,7 @@ static CDVWKInAppBrowser* instance = nil;
[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]]; [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
} }
//if is an app store link, let the system handle it, otherwise it fails to load it //if is an app store link, let the system handle it, otherwise it fails to load it
if ([[ url scheme] isEqualToString:@"itms-appss"] || [[ url scheme] isEqualToString:@"itms-apps"]) { if ([[ url scheme] isEqualToString:@"itms-appss"] || [[ url scheme] isEqualToString:@"itms-apps"]) {
[theWebView stopLoading]; [theWebView stopLoading];
@ -548,14 +548,14 @@ static CDVWKInAppBrowser* instance = nil;
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:@{@"type":@"loadstart", @"url":[url absoluteString]}]; messageAsDictionary:@{@"type":@"loadstart", @"url":[url absoluteString]}];
[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]]; [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
} }
if (useBeforeLoad) { if (useBeforeLoad) {
_waitForBeforeload = YES; _waitForBeforeload = YES;
} }
if(shouldStart){ if(shouldStart){
// Fix GH-417 & GH-424: Handle non-default target attribute // Fix GH-417 & GH-424: Handle non-default target attribute
// Based on https://stackoverflow.com/a/25713070/777265 // Based on https://stackoverflow.com/a/25713070/777265
@ -572,13 +572,13 @@ static CDVWKInAppBrowser* instance = nil;
#pragma mark WKScriptMessageHandler delegate #pragma mark WKScriptMessageHandler delegate
- (void)userContentController:(nonnull WKUserContentController *)userContentController didReceiveScriptMessage:(nonnull WKScriptMessage *)message { - (void)userContentController:(nonnull WKUserContentController *)userContentController didReceiveScriptMessage:(nonnull WKScriptMessage *)message {
CDVPluginResult* pluginResult = nil; CDVPluginResult* pluginResult = nil;
if([message.body isKindOfClass:[NSDictionary class]]){ if([message.body isKindOfClass:[NSDictionary class]]){
NSDictionary* messageContent = (NSDictionary*) message.body; NSDictionary* messageContent = (NSDictionary*) message.body;
NSString* scriptCallbackId = messageContent[@"id"]; NSString* scriptCallbackId = messageContent[@"id"];
if([messageContent objectForKey:@"d"]){ if([messageContent objectForKey:@"d"]){
NSString* scriptResult = messageContent[@"d"]; NSString* scriptResult = messageContent[@"d"];
NSError* __autoreleasing error = nil; NSError* __autoreleasing error = nil;
@ -628,7 +628,7 @@ static CDVWKInAppBrowser* instance = nil;
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsDictionary:@{@"type":@"loadstop", @"url":url}]; messageAsDictionary:@{@"type":@"loadstop", @"url":url}];
[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]]; [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
} }
} }
@ -647,7 +647,7 @@ static CDVWKInAppBrowser* instance = nil;
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR
messageAsDictionary:@{@"type":@"loaderror", @"url":url, @"code": [NSNumber numberWithInteger:error.code], @"message": error.localizedDescription}]; messageAsDictionary:@{@"type":@"loaderror", @"url":url, @"code": [NSNumber numberWithInteger:error.code], @"message": error.localizedDescription}];
[pluginResult setKeepCallback:[NSNumber numberWithBool:YES]]; [pluginResult setKeepCallback:[NSNumber numberWithBool:YES]];
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
} }
} }
@ -660,16 +660,16 @@ static CDVWKInAppBrowser* instance = nil;
[self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId]; [self.commandDelegate sendPluginResult:pluginResult callbackId:self.callbackId];
self.callbackId = nil; self.callbackId = nil;
} }
[self.inAppBrowserViewController.configuration.userContentController removeScriptMessageHandlerForName:IAB_BRIDGE_NAME]; [self.inAppBrowserViewController.configuration.userContentController removeScriptMessageHandlerForName:IAB_BRIDGE_NAME];
self.inAppBrowserViewController.configuration = nil; self.inAppBrowserViewController.configuration = nil;
[self.inAppBrowserViewController.webView stopLoading]; [self.inAppBrowserViewController.webView stopLoading];
[self.inAppBrowserViewController.webView removeFromSuperview]; [self.inAppBrowserViewController.webView removeFromSuperview];
[self.inAppBrowserViewController.webView setUIDelegate:nil]; [self.inAppBrowserViewController.webView setUIDelegate:nil];
[self.inAppBrowserViewController.webView setNavigationDelegate:nil]; [self.inAppBrowserViewController.webView setNavigationDelegate:nil];
self.inAppBrowserViewController.webView = nil; self.inAppBrowserViewController.webView = nil;
// Set navigationDelegate to nil to ensure no callbacks are received from it. // Set navigationDelegate to nil to ensure no callbacks are received from it.
self.inAppBrowserViewController.navigationDelegate = nil; self.inAppBrowserViewController.navigationDelegate = nil;
self.inAppBrowserViewController = nil; self.inAppBrowserViewController = nil;
@ -682,10 +682,10 @@ static CDVWKInAppBrowser* instance = nil;
if (IsAtLeastiOSVersion(@"7.0")) { if (IsAtLeastiOSVersion(@"7.0")) {
if (_previousStatusBarStyle != -1) { if (_previousStatusBarStyle != -1) {
[[UIApplication sharedApplication] setStatusBarStyle:_previousStatusBarStyle]; [[UIApplication sharedApplication] setStatusBarStyle:_previousStatusBarStyle];
} }
} }
_previousStatusBarStyle = -1; // this value was reset before reapplying it. caused statusbar to stay black on ios7 _previousStatusBarStyle = -1; // this value was reset before reapplying it. caused statusbar to stay black on ios7
} }
@ -708,10 +708,10 @@ BOOL isExiting = FALSE;
_settings = settings; _settings = settings;
self.webViewUIDelegate = [[CDVWKInAppBrowserUIDelegate alloc] initWithTitle:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]]; self.webViewUIDelegate = [[CDVWKInAppBrowserUIDelegate alloc] initWithTitle:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]];
[self.webViewUIDelegate setViewController:self]; [self.webViewUIDelegate setViewController:self];
[self createViews]; [self createViews];
} }
return self; return self;
} }
@ -722,14 +722,14 @@ BOOL isExiting = FALSE;
- (void)createViews - (void)createViews
{ {
// We create the views in code for primarily for ease of upgrades and not requiring an external .xib to be included // We create the views in code for primarily for ease of upgrades and not requiring an external .xib to be included
CGRect webViewBounds = self.view.bounds; CGRect webViewBounds = self.view.bounds;
BOOL toolbarIsAtBottom = ![_browserOptions.toolbarposition isEqualToString:kInAppBrowserToolbarBarPositionTop]; BOOL toolbarIsAtBottom = ![_browserOptions.toolbarposition isEqualToString:kInAppBrowserToolbarBarPositionTop];
webViewBounds.size.height -= _browserOptions.location ? FOOTER_HEIGHT : TOOLBAR_HEIGHT; webViewBounds.size.height -= _browserOptions.location ? FOOTER_HEIGHT : TOOLBAR_HEIGHT;
WKUserContentController* userContentController = [[WKUserContentController alloc] init]; WKUserContentController* userContentController = [[WKUserContentController alloc] init];
WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init]; WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init];
NSString *userAgent = configuration.applicationNameForUserAgent; NSString *userAgent = configuration.applicationNameForUserAgent;
if ( if (
[self settingForKey:@"OverrideUserAgent"] == nil && [self settingForKey:@"OverrideUserAgent"] == nil &&
@ -743,7 +743,7 @@ BOOL isExiting = FALSE;
configuration.processPool = [[CDVWKProcessPoolFactory sharedFactory] sharedProcessPool]; configuration.processPool = [[CDVWKProcessPoolFactory sharedFactory] sharedProcessPool];
#endif #endif
[configuration.userContentController addScriptMessageHandler:self name:IAB_BRIDGE_NAME]; [configuration.userContentController addScriptMessageHandler:self name:IAB_BRIDGE_NAME];
//WKWebView options //WKWebView options
configuration.allowsInlineMediaPlayback = _browserOptions.allowinlinemediaplayback; configuration.allowsInlineMediaPlayback = _browserOptions.allowinlinemediaplayback;
if (IsAtLeastiOSVersion(@"10.0")) { if (IsAtLeastiOSVersion(@"10.0")) {
@ -756,22 +756,22 @@ BOOL isExiting = FALSE;
}else{ // iOS 9 }else{ // iOS 9
configuration.mediaPlaybackRequiresUserAction = _browserOptions.mediaplaybackrequiresuseraction; configuration.mediaPlaybackRequiresUserAction = _browserOptions.mediaplaybackrequiresuseraction;
} }
self.webView = [[WKWebView alloc] initWithFrame:webViewBounds configuration:configuration]; self.webView = [[WKWebView alloc] initWithFrame:webViewBounds configuration:configuration];
[self.view addSubview:self.webView]; [self.view addSubview:self.webView];
[self.view sendSubviewToBack:self.webView]; [self.view sendSubviewToBack:self.webView];
self.webView.navigationDelegate = self; self.webView.navigationDelegate = self;
self.webView.UIDelegate = self.webViewUIDelegate; self.webView.UIDelegate = self.webViewUIDelegate;
self.webView.backgroundColor = [UIColor whiteColor]; self.webView.backgroundColor = [UIColor whiteColor];
if ([self settingForKey:@"OverrideUserAgent"] != nil) { if ([self settingForKey:@"OverrideUserAgent"] != nil) {
self.webView.customUserAgent = [self settingForKey:@"OverrideUserAgent"]; self.webView.customUserAgent = [self settingForKey:@"OverrideUserAgent"];
} }
self.webView.clearsContextBeforeDrawing = YES; self.webView.clearsContextBeforeDrawing = YES;
self.webView.clipsToBounds = YES; self.webView.clipsToBounds = YES;
self.webView.contentMode = UIViewContentModeScaleToFill; self.webView.contentMode = UIViewContentModeScaleToFill;
@ -782,13 +782,13 @@ BOOL isExiting = FALSE;
[self.webView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth]; [self.webView setAutoresizingMask:UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth];
self.webView.allowsLinkPreview = NO; self.webView.allowsLinkPreview = NO;
self.webView.allowsBackForwardNavigationGestures = NO; self.webView.allowsBackForwardNavigationGestures = NO;
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000
if (@available(iOS 11.0, *)) { if (@available(iOS 11.0, *)) {
[self.webView.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever]; [self.webView.scrollView setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
} }
#endif #endif
self.spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray]; self.spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
self.spinner.alpha = 1.000; self.spinner.alpha = 1.000;
self.spinner.autoresizesSubviews = YES; self.spinner.autoresizesSubviews = YES;
@ -803,18 +803,18 @@ BOOL isExiting = FALSE;
self.spinner.opaque = NO; self.spinner.opaque = NO;
self.spinner.userInteractionEnabled = NO; self.spinner.userInteractionEnabled = NO;
[self.spinner stopAnimating]; [self.spinner stopAnimating];
self.closeButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(close)]; self.closeButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(close)];
self.closeButton.enabled = YES; self.closeButton.enabled = YES;
UIBarButtonItem* flexibleSpaceButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; UIBarButtonItem* flexibleSpaceButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem* fixedSpaceButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil]; UIBarButtonItem* fixedSpaceButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
fixedSpaceButton.width = 20; fixedSpaceButton.width = 20;
float toolbarY = toolbarIsAtBottom ? self.view.bounds.size.height - TOOLBAR_HEIGHT : 0.0; float toolbarY = toolbarIsAtBottom ? self.view.bounds.size.height - TOOLBAR_HEIGHT : 0.0;
CGRect toolbarFrame = CGRectMake(0.0, toolbarY, self.view.bounds.size.width, TOOLBAR_HEIGHT); CGRect toolbarFrame = CGRectMake(0.0, toolbarY, self.view.bounds.size.width, TOOLBAR_HEIGHT);
self.toolbar = [[UIToolbar alloc] initWithFrame:toolbarFrame]; self.toolbar = [[UIToolbar alloc] initWithFrame:toolbarFrame];
self.toolbar.alpha = 1.000; self.toolbar.alpha = 1.000;
self.toolbar.autoresizesSubviews = YES; self.toolbar.autoresizesSubviews = YES;
@ -833,10 +833,10 @@ BOOL isExiting = FALSE;
if (!_browserOptions.toolbartranslucent) { // Set toolbar translucent to no if user sets it in options if (!_browserOptions.toolbartranslucent) { // Set toolbar translucent to no if user sets it in options
self.toolbar.translucent = NO; self.toolbar.translucent = NO;
} }
CGFloat labelInset = 5.0; CGFloat labelInset = 5.0;
float locationBarY = toolbarIsAtBottom ? self.view.bounds.size.height - FOOTER_HEIGHT : self.view.bounds.size.height - LOCATIONBAR_HEIGHT; float locationBarY = toolbarIsAtBottom ? self.view.bounds.size.height - FOOTER_HEIGHT : self.view.bounds.size.height - LOCATIONBAR_HEIGHT;
self.addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(labelInset, locationBarY, self.view.bounds.size.width - labelInset, LOCATIONBAR_HEIGHT)]; self.addressLabel = [[UILabel alloc] initWithFrame:CGRectMake(labelInset, locationBarY, self.view.bounds.size.width - labelInset, LOCATIONBAR_HEIGHT)];
self.addressLabel.adjustsFontSizeToFitWidth = NO; self.addressLabel.adjustsFontSizeToFitWidth = NO;
self.addressLabel.alpha = 1.000; self.addressLabel.alpha = 1.000;
@ -850,13 +850,13 @@ BOOL isExiting = FALSE;
self.addressLabel.enabled = YES; self.addressLabel.enabled = YES;
self.addressLabel.hidden = NO; self.addressLabel.hidden = NO;
self.addressLabel.lineBreakMode = NSLineBreakByTruncatingTail; self.addressLabel.lineBreakMode = NSLineBreakByTruncatingTail;
if ([self.addressLabel respondsToSelector:NSSelectorFromString(@"setMinimumScaleFactor:")]) { if ([self.addressLabel respondsToSelector:NSSelectorFromString(@"setMinimumScaleFactor:")]) {
[self.addressLabel setValue:@(10.0/[UIFont labelFontSize]) forKey:@"minimumScaleFactor"]; [self.addressLabel setValue:@(10.0/[UIFont labelFontSize]) forKey:@"minimumScaleFactor"];
} else if ([self.addressLabel respondsToSelector:NSSelectorFromString(@"setMinimumFontSize:")]) { } else if ([self.addressLabel respondsToSelector:NSSelectorFromString(@"setMinimumFontSize:")]) {
[self.addressLabel setValue:@(10.0) forKey:@"minimumFontSize"]; [self.addressLabel setValue:@(10.0) forKey:@"minimumFontSize"];
} }
self.addressLabel.multipleTouchEnabled = NO; self.addressLabel.multipleTouchEnabled = NO;
self.addressLabel.numberOfLines = 1; self.addressLabel.numberOfLines = 1;
self.addressLabel.opaque = NO; self.addressLabel.opaque = NO;
@ -865,7 +865,7 @@ BOOL isExiting = FALSE;
self.addressLabel.textAlignment = NSTextAlignmentLeft; self.addressLabel.textAlignment = NSTextAlignmentLeft;
self.addressLabel.textColor = [UIColor colorWithWhite:1.000 alpha:1.000]; self.addressLabel.textColor = [UIColor colorWithWhite:1.000 alpha:1.000];
self.addressLabel.userInteractionEnabled = NO; self.addressLabel.userInteractionEnabled = NO;
NSString* frontArrowString = NSLocalizedString(@"►", nil); // create arrow from Unicode char NSString* frontArrowString = NSLocalizedString(@"►", nil); // create arrow from Unicode char
self.forwardButton = [[UIBarButtonItem alloc] initWithTitle:frontArrowString style:UIBarButtonItemStylePlain target:self action:@selector(goForward:)]; self.forwardButton = [[UIBarButtonItem alloc] initWithTitle:frontArrowString style:UIBarButtonItemStylePlain target:self action:@selector(goForward:)];
self.forwardButton.enabled = YES; self.forwardButton.enabled = YES;
@ -894,7 +894,7 @@ BOOL isExiting = FALSE;
} else { } else {
[self.toolbar setItems:@[self.closeButton, flexibleSpaceButton, self.backButton, fixedSpaceButton, self.forwardButton]]; [self.toolbar setItems:@[self.closeButton, flexibleSpaceButton, self.backButton, fixedSpaceButton, self.forwardButton]];
} }
self.view.backgroundColor = [UIColor clearColor]; self.view.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.toolbar]; [self.view addSubview:self.toolbar];
[self.view addSubview:self.addressLabel]; [self.view addSubview:self.addressLabel];
@ -921,7 +921,7 @@ BOOL isExiting = FALSE;
self.closeButton.enabled = YES; self.closeButton.enabled = YES;
// If color on closebutton is requested then initialize with that that color, otherwise use initialize with default // If color on closebutton is requested then initialize with that that color, otherwise use initialize with default
self.closeButton.tintColor = colorString != nil ? [self colorFromHexString:colorString] : [UIColor colorWithRed:60.0 / 255.0 green:136.0 / 255.0 blue:230.0 / 255.0 alpha:1]; self.closeButton.tintColor = colorString != nil ? [self colorFromHexString:colorString] : [UIColor colorWithRed:60.0 / 255.0 green:136.0 / 255.0 blue:230.0 / 255.0 alpha:1];
NSMutableArray* items = [self.toolbar.items mutableCopy]; NSMutableArray* items = [self.toolbar.items mutableCopy];
[items replaceObjectAtIndex:buttonIndex withObject:self.closeButton]; [items replaceObjectAtIndex:buttonIndex withObject:self.closeButton];
[self.toolbar setItems:items]; [self.toolbar setItems:items];
@ -930,43 +930,43 @@ BOOL isExiting = FALSE;
- (void)showLocationBar:(BOOL)show - (void)showLocationBar:(BOOL)show
{ {
CGRect locationbarFrame = self.addressLabel.frame; CGRect locationbarFrame = self.addressLabel.frame;
BOOL toolbarVisible = !self.toolbar.hidden; BOOL toolbarVisible = !self.toolbar.hidden;
// prevent double show/hide // prevent double show/hide
if (show == !(self.addressLabel.hidden)) { if (show == !(self.addressLabel.hidden)) {
return; return;
} }
if (show) { if (show) {
self.addressLabel.hidden = NO; self.addressLabel.hidden = NO;
if (toolbarVisible) { if (toolbarVisible) {
// toolBar at the bottom, leave as is // toolBar at the bottom, leave as is
// put locationBar on top of the toolBar // put locationBar on top of the toolBar
CGRect webViewBounds = self.view.bounds; CGRect webViewBounds = self.view.bounds;
webViewBounds.size.height -= FOOTER_HEIGHT; webViewBounds.size.height -= FOOTER_HEIGHT;
[self setWebViewFrame:webViewBounds]; [self setWebViewFrame:webViewBounds];
locationbarFrame.origin.y = webViewBounds.size.height; locationbarFrame.origin.y = webViewBounds.size.height;
self.addressLabel.frame = locationbarFrame; self.addressLabel.frame = locationbarFrame;
} else { } else {
// no toolBar, so put locationBar at the bottom // no toolBar, so put locationBar at the bottom
CGRect webViewBounds = self.view.bounds; CGRect webViewBounds = self.view.bounds;
webViewBounds.size.height -= LOCATIONBAR_HEIGHT; webViewBounds.size.height -= LOCATIONBAR_HEIGHT;
[self setWebViewFrame:webViewBounds]; [self setWebViewFrame:webViewBounds];
locationbarFrame.origin.y = webViewBounds.size.height; locationbarFrame.origin.y = webViewBounds.size.height;
self.addressLabel.frame = locationbarFrame; self.addressLabel.frame = locationbarFrame;
} }
} else { } else {
self.addressLabel.hidden = YES; self.addressLabel.hidden = YES;
if (toolbarVisible) { if (toolbarVisible) {
// locationBar is on top of toolBar, hide locationBar // locationBar is on top of toolBar, hide locationBar
// webView take up whole height less toolBar height // webView take up whole height less toolBar height
CGRect webViewBounds = self.view.bounds; CGRect webViewBounds = self.view.bounds;
webViewBounds.size.height -= TOOLBAR_HEIGHT; webViewBounds.size.height -= TOOLBAR_HEIGHT;
@ -982,18 +982,18 @@ BOOL isExiting = FALSE;
{ {
CGRect toolbarFrame = self.toolbar.frame; CGRect toolbarFrame = self.toolbar.frame;
CGRect locationbarFrame = self.addressLabel.frame; CGRect locationbarFrame = self.addressLabel.frame;
BOOL locationbarVisible = !self.addressLabel.hidden; BOOL locationbarVisible = !self.addressLabel.hidden;
// prevent double show/hide // prevent double show/hide
if (show == !(self.toolbar.hidden)) { if (show == !(self.toolbar.hidden)) {
return; return;
} }
if (show) { if (show) {
self.toolbar.hidden = NO; self.toolbar.hidden = NO;
CGRect webViewBounds = self.view.bounds; CGRect webViewBounds = self.view.bounds;
if (locationbarVisible) { if (locationbarVisible) {
// locationBar at the bottom, move locationBar up // locationBar at the bottom, move locationBar up
// put toolBar at the bottom // put toolBar at the bottom
@ -1007,7 +1007,7 @@ BOOL isExiting = FALSE;
webViewBounds.size.height -= TOOLBAR_HEIGHT; webViewBounds.size.height -= TOOLBAR_HEIGHT;
self.toolbar.frame = toolbarFrame; self.toolbar.frame = toolbarFrame;
} }
if ([toolbarPosition isEqualToString:kInAppBrowserToolbarBarPositionTop]) { if ([toolbarPosition isEqualToString:kInAppBrowserToolbarBarPositionTop]) {
toolbarFrame.origin.y = 0; toolbarFrame.origin.y = 0;
webViewBounds.origin.y += toolbarFrame.size.height; webViewBounds.origin.y += toolbarFrame.size.height;
@ -1016,19 +1016,19 @@ BOOL isExiting = FALSE;
toolbarFrame.origin.y = (webViewBounds.size.height + LOCATIONBAR_HEIGHT); toolbarFrame.origin.y = (webViewBounds.size.height + LOCATIONBAR_HEIGHT);
} }
[self setWebViewFrame:webViewBounds]; [self setWebViewFrame:webViewBounds];
} else { } else {
self.toolbar.hidden = YES; self.toolbar.hidden = YES;
if (locationbarVisible) { if (locationbarVisible) {
// locationBar is on top of toolBar, hide toolBar // locationBar is on top of toolBar, hide toolBar
// put locationBar at the bottom // put locationBar at the bottom
// webView take up whole height less locationBar height // webView take up whole height less locationBar height
CGRect webViewBounds = self.view.bounds; CGRect webViewBounds = self.view.bounds;
webViewBounds.size.height -= LOCATIONBAR_HEIGHT; webViewBounds.size.height -= LOCATIONBAR_HEIGHT;
[self setWebViewFrame:webViewBounds]; [self setWebViewFrame:webViewBounds];
// move locationBar down // move locationBar down
locationbarFrame.origin.y = webViewBounds.size.height; locationbarFrame.origin.y = webViewBounds.size.height;
self.addressLabel.frame = locationbarFrame; self.addressLabel.frame = locationbarFrame;
@ -1055,7 +1055,12 @@ BOOL isExiting = FALSE;
- (UIStatusBarStyle)preferredStatusBarStyle - (UIStatusBarStyle)preferredStatusBarStyle
{ {
return UIStatusBarStyleDefault; NSString* statusBarStylePreference = [self settingForKey:@"InAppBrowserStatusBarStyle"];
if (statusBarStylePreference && [statusBarStylePreference isEqualToString:@"lightcontent"]) {
return UIStatusBarStyleLightContent;
} else {
return UIStatusBarStyleDefault;
}
} }
- (BOOL)prefersStatusBarHidden { - (BOOL)prefersStatusBarHidden {
@ -1065,9 +1070,9 @@ BOOL isExiting = FALSE;
- (void)close - (void)close
{ {
self.currentURL = nil; self.currentURL = nil;
__weak UIViewController* weakSelf = self; __weak UIViewController* weakSelf = self;
// Run later to avoid the "took a long time" log message. // Run later to avoid the "took a long time" log message.
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
isExiting = TRUE; isExiting = TRUE;
@ -1103,7 +1108,7 @@ BOOL isExiting = FALSE;
- (void)viewWillAppear:(BOOL)animated - (void)viewWillAppear:(BOOL)animated
{ {
[self rePositionViews]; [self rePositionViews];
[super viewWillAppear:animated]; [super viewWillAppear:animated];
} }
@ -1119,21 +1124,21 @@ BOOL isExiting = FALSE;
- (void) rePositionViews { - (void) rePositionViews {
CGRect viewBounds = [self.webView bounds]; CGRect viewBounds = [self.webView bounds];
CGFloat statusBarHeight = [self getStatusBarOffset]; CGFloat statusBarHeight = [self getStatusBarOffset];
// orientation portrait or portraitUpsideDown: status bar is on the top and web view is to be aligned to the bottom of the status bar // orientation portrait or portraitUpsideDown: status bar is on the top and web view is to be aligned to the bottom of the status bar
// orientation landscapeLeft or landscapeRight: status bar height is 0 in but lets account for it in case things ever change in the future // orientation landscapeLeft or landscapeRight: status bar height is 0 in but lets account for it in case things ever change in the future
viewBounds.origin.y = statusBarHeight; viewBounds.origin.y = statusBarHeight;
// account for web view height portion that may have been reduced by a previous call to this method // account for web view height portion that may have been reduced by a previous call to this method
viewBounds.size.height = viewBounds.size.height - statusBarHeight + lastReducedStatusBarHeight; viewBounds.size.height = viewBounds.size.height - statusBarHeight + lastReducedStatusBarHeight;
lastReducedStatusBarHeight = statusBarHeight; lastReducedStatusBarHeight = statusBarHeight;
if ((_browserOptions.toolbar) && ([_browserOptions.toolbarposition isEqualToString:kInAppBrowserToolbarBarPositionTop])) { if ((_browserOptions.toolbar) && ([_browserOptions.toolbarposition isEqualToString:kInAppBrowserToolbarBarPositionTop])) {
// if we have to display the toolbar on top of the web view, we need to account for its height // if we have to display the toolbar on top of the web view, we need to account for its height
viewBounds.origin.y += TOOLBAR_HEIGHT; viewBounds.origin.y += TOOLBAR_HEIGHT;
self.toolbar.frame = CGRectMake(self.toolbar.frame.origin.x, statusBarHeight, self.toolbar.frame.size.width, self.toolbar.frame.size.height); self.toolbar.frame = CGRectMake(self.toolbar.frame.origin.x, statusBarHeight, self.toolbar.frame.size.width, self.toolbar.frame.size.height);
} }
self.webView.frame = viewBounds; self.webView.frame = viewBounds;
} }
@ -1151,18 +1156,18 @@ BOOL isExiting = FALSE;
#pragma mark WKNavigationDelegate #pragma mark WKNavigationDelegate
- (void)webView:(WKWebView *)theWebView didStartProvisionalNavigation:(WKNavigation *)navigation{ - (void)webView:(WKWebView *)theWebView didStartProvisionalNavigation:(WKNavigation *)navigation{
// loading url, start spinner, update back/forward // loading url, start spinner, update back/forward
self.addressLabel.text = NSLocalizedString(@"Loading...", nil); self.addressLabel.text = NSLocalizedString(@"Loading...", nil);
self.backButton.enabled = theWebView.canGoBack; self.backButton.enabled = theWebView.canGoBack;
self.forwardButton.enabled = theWebView.canGoForward; self.forwardButton.enabled = theWebView.canGoForward;
NSLog(_browserOptions.hidespinner ? @"Yes" : @"No"); NSLog(_browserOptions.hidespinner ? @"Yes" : @"No");
if(!_browserOptions.hidespinner) { if(!_browserOptions.hidespinner) {
[self.spinner startAnimating]; [self.spinner startAnimating];
} }
return [self.navigationDelegate didStartProvisionalNavigation:theWebView]; return [self.navigationDelegate didStartProvisionalNavigation:theWebView];
} }
@ -1170,40 +1175,40 @@ BOOL isExiting = FALSE;
{ {
NSURL *url = navigationAction.request.URL; NSURL *url = navigationAction.request.URL;
NSURL *mainDocumentURL = navigationAction.request.mainDocumentURL; NSURL *mainDocumentURL = navigationAction.request.mainDocumentURL;
BOOL isTopLevelNavigation = [url isEqual:mainDocumentURL]; BOOL isTopLevelNavigation = [url isEqual:mainDocumentURL];
if (isTopLevelNavigation) { if (isTopLevelNavigation) {
self.currentURL = url; self.currentURL = url;
} }
[self.navigationDelegate webView:theWebView decidePolicyForNavigationAction:navigationAction decisionHandler:decisionHandler]; [self.navigationDelegate webView:theWebView decidePolicyForNavigationAction:navigationAction decisionHandler:decisionHandler];
} }
- (void)webView:(WKWebView *)theWebView didFinishNavigation:(WKNavigation *)navigation - (void)webView:(WKWebView *)theWebView didFinishNavigation:(WKNavigation *)navigation
{ {
// update url, stop spinner, update back/forward // update url, stop spinner, update back/forward
self.addressLabel.text = [self.currentURL absoluteString]; self.addressLabel.text = [self.currentURL absoluteString];
self.backButton.enabled = theWebView.canGoBack; self.backButton.enabled = theWebView.canGoBack;
self.forwardButton.enabled = theWebView.canGoForward; self.forwardButton.enabled = theWebView.canGoForward;
theWebView.scrollView.contentInset = UIEdgeInsetsZero; theWebView.scrollView.contentInset = UIEdgeInsetsZero;
[self.spinner stopAnimating]; [self.spinner stopAnimating];
[self.navigationDelegate didFinishNavigation:theWebView]; [self.navigationDelegate didFinishNavigation:theWebView];
} }
- (void)webView:(WKWebView*)theWebView failedNavigation:(NSString*) delegateName withError:(nonnull NSError *)error{ - (void)webView:(WKWebView*)theWebView failedNavigation:(NSString*) delegateName withError:(nonnull NSError *)error{
// log fail message, stop spinner, update back/forward // log fail message, stop spinner, update back/forward
NSLog(@"webView:%@ - %ld: %@", delegateName, (long)error.code, [error localizedDescription]); NSLog(@"webView:%@ - %ld: %@", delegateName, (long)error.code, [error localizedDescription]);
self.backButton.enabled = theWebView.canGoBack; self.backButton.enabled = theWebView.canGoBack;
self.forwardButton.enabled = theWebView.canGoForward; self.forwardButton.enabled = theWebView.canGoForward;
[self.spinner stopAnimating]; [self.spinner stopAnimating];
self.addressLabel.text = NSLocalizedString(@"Load Error", nil); self.addressLabel.text = NSLocalizedString(@"Load Error", nil);
[self.navigationDelegate webView:theWebView didFailNavigation:error]; [self.navigationDelegate webView:theWebView didFailNavigation:error];
} }
@ -1211,7 +1216,7 @@ BOOL isExiting = FALSE;
{ {
[self webView:theWebView failedNavigation:@"didFailNavigation" withError:error]; [self webView:theWebView failedNavigation:@"didFailNavigation" withError:error];
} }
- (void)webView:(WKWebView*)theWebView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(nonnull NSError *)error - (void)webView:(WKWebView*)theWebView didFailProvisionalNavigation:(null_unspecified WKNavigation *)navigation withError:(nonnull NSError *)error
{ {
[self webView:theWebView failedNavigation:@"didFailProvisionalNavigation" withError:error]; [self webView:theWebView failedNavigation:@"didFailProvisionalNavigation" withError:error];
@ -1241,7 +1246,7 @@ BOOL isExiting = FALSE;
if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector(supportedInterfaceOrientations)]) { if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector(supportedInterfaceOrientations)]) {
return [self.orientationDelegate supportedInterfaceOrientations]; return [self.orientationDelegate supportedInterfaceOrientations];
} }
return 1 << UIInterfaceOrientationPortrait; return 1 << UIInterfaceOrientationPortrait;
} }