policy
// in config.xml for cordova-ios-4.0
[self.webViewEngine loadRequest:request];
-#else
- if ([self.commandDelegate URLIsWhitelisted:url]) {
- [self.webView loadRequest:request];
- } else { // this assumes the InAppBrowser can be excepted from the white-list
- [self openInInAppBrowser:url withOptions:options];
- }
-#endif
}
- (void)openInSystem:(NSURL*)url
@@ -725,13 +697,12 @@ static CDVWKInAppBrowser* instance = nil;
BOOL viewRenderedAtLeastOnce = FALSE;
BOOL isExiting = FALSE;
-- (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent browserOptions: (CDVInAppBrowserOptions*) browserOptions
+- (id)initWithBrowserOptions: (CDVInAppBrowserOptions*) browserOptions andSettings:(NSDictionary *)settings
{
self = [super init];
if (self != nil) {
- _userAgent = userAgent;
- _prevUserAgent = prevUserAgent;
_browserOptions = browserOptions;
+ _settings = settings;
self.webViewUIDelegate = [[CDVWKInAppBrowserUIDelegate alloc] initWithTitle:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]];
[self.webViewUIDelegate setViewController:self];
@@ -755,6 +726,15 @@ BOOL isExiting = FALSE;
WKUserContentController* userContentController = [[WKUserContentController alloc] init];
WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init];
+
+ NSString *userAgent = configuration.applicationNameForUserAgent;
+ if (
+ [self settingForKey:@"OverrideUserAgent"] == nil &&
+ [self settingForKey:@"AppendUserAgent"] != nil
+ ) {
+ userAgent = [NSString stringWithFormat:@"%@ %@", userAgent, [self settingForKey:@"AppendUserAgent"]];
+ }
+ configuration.applicationNameForUserAgent = userAgent;
configuration.userContentController = userContentController;
#if __has_include("CDVWKProcessPoolFactory.h")
configuration.processPool = [[CDVWKProcessPoolFactory sharedFactory] sharedProcessPool];
@@ -785,6 +765,9 @@ BOOL isExiting = FALSE;
self.webView.navigationDelegate = self;
self.webView.UIDelegate = self.webViewUIDelegate;
self.webView.backgroundColor = [UIColor whiteColor];
+ if ([self settingForKey:@"OverrideUserAgent"] != nil) {
+ self.webView.customUserAgent = [self settingForKey:@"OverrideUserAgent"];
+ }
self.webView.clearsContextBeforeDrawing = YES;
self.webView.clipsToBounds = YES;
@@ -915,6 +898,11 @@ BOOL isExiting = FALSE;
[self.view addSubview:self.spinner];
}
+- (id)settingForKey:(NSString*)key
+{
+ return [_settings objectForKey:[key lowercaseString]];
+}
+
- (void) setWebViewFrame : (CGRect) frame {
NSLog(@"Setting the WebView's frame to %@", NSStringFromCGRect(frame));
[self.webView setFrame:frame];
@@ -1074,7 +1062,6 @@ BOOL isExiting = FALSE;
- (void)close
{
- [CDVUserAgentUtil releaseLock:&_userAgentLockToken];
self.currentURL = nil;
__weak UIViewController* weakSelf = self;
@@ -1093,17 +1080,7 @@ BOOL isExiting = FALSE;
- (void)navigateTo:(NSURL*)url
{
NSURLRequest* request = [NSURLRequest requestWithURL:url];
-
- if (_userAgentLockToken != 0) {
- [self.webView loadRequest:request];
- } else {
- __weak CDVWKInAppBrowserViewController* weakSelf = self;
- [CDVUserAgentUtil acquireLock:^(NSInteger lockToken) {
- _userAgentLockToken = lockToken;
- [CDVUserAgentUtil setUserAgent:_userAgent lockToken:lockToken];
- [weakSelf.webView loadRequest:request];
- }];
- }
+ [self.webView loadRequest:request];
}
- (void)goBack:(id)sender
@@ -1203,24 +1180,6 @@ BOOL isExiting = FALSE;
[self.spinner stopAnimating];
- // Work around a bug where the first time a PDF is opened, all UIWebViews
- // reload their User-Agent from NSUserDefaults.
- // This work-around makes the following assumptions:
- // 1. The app has only a single Cordova Webview. If not, then the app should
- // take it upon themselves to load a PDF in the background as a part of
- // their start-up flow.
- // 2. That the PDF does not require any additional network requests. We change
- // the user-agent here back to that of the CDVViewController, so requests
- // from it must pass through its white-list. This *does* break PDFs that
- // contain links to other remote PDF/websites.
- // More info at https://issues.apache.org/jira/browse/CB-2225
- BOOL isPDF = NO;
- //TODO webview class
- //BOOL isPDF = [@"true" isEqualToString :[theWebView evaluateJavaScript:@"document.body==null"]];
- if (isPDF) {
- [CDVUserAgentUtil setUserAgent:_prevUserAgent lockToken:_userAgentLockToken];
- }
-
[self.navigationDelegate didFinishNavigation:theWebView];
}
diff --git a/tests/tests.js b/tests/tests.js
index b4d2e68..85d5eba 100644
--- a/tests/tests.js
+++ b/tests/tests.js
@@ -182,24 +182,13 @@ exports.defineAutoTests = function () {
});
});
};
- if (isIos) {
- createTests('usewkwebview=no');
- createTests('usewkwebview=yes');
- } else {
- createTests();
- }
+ createTests();
};
exports.defineManualTests = function (contentEl, createActionButton) {
var platformOpts = '';
var platform_info = '';
- if (isIos) {
- platformOpts = 'usewkwebview=no';
- platform_info = 'Webview
' +
- 'Use this button to toggle the Webview implementation.
' +
- '';
- }
function doOpen (url, target, params, numExpectedRedirects, useWindowOpen) {
numExpectedRedirects = numExpectedRedirects || 0;
@@ -543,20 +532,6 @@ exports.defineManualTests = function (contentEl, createActionButton) {
var injectjs = isWindows ? basePath + 'inject.js' : 'inject.js';
var injectcss = isWindows ? basePath + 'inject.css' : 'inject.css';
var videohtml = basePath + 'video.html';
- if (isIos) {
- createActionButton('Webview=UIWebView', function () {
- var webviewOption = 'usewkwebview=';
- var webviewToggle = document.getElementById('webviewToggle');
- var button = webviewToggle.getElementsByClassName('topcoat-button')[0];
- if (platformOpts === webviewOption + 'yes') {
- platformOpts = webviewOption + 'no';
- button.textContent = 'Webview=UIWebView';
- } else {
- platformOpts = webviewOption + 'yes';
- button.textContent = 'Webview=WKWebView';
- }
- }, 'webviewToggle');
- }
// Local
createActionButton('target=Default', function () {