breaking(ios): remove UIWebView (#635)

This commit is contained in:
jcesarmobile 2020-03-05 15:51:31 +01:00 committed by GitHub
parent 09ad59f7ef
commit 6c55e6172c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 28 additions and 1552 deletions

View File

@ -131,7 +131,6 @@ instance, or the system browser.
iOS supports these additional options:
- __usewkwebview__: set to `yes` to use WKWebView engine for the InappBrowser. Omit or set to `no` (default) to use UIWebView. Note: Using `usewkwebview=yes` requires that a WKWebView engine plugin be installed in the Cordova project (e.g. [cordova-plugin-wkwebview-engine](https://github.com/apache/cordova-plugin-wkwebview-engine) or [cordova-plugin-ionic-webview](https://github.com/ionic-team/cordova-plugin-ionic-webview)).
- __hidden__: set to `yes` to create the browser and load the page, but not show it. The loadstop event fires when loading is complete. Omit or set to `no` (default) to have the browser open and load normally.
- __beforeload__: set to enable the `beforeload` event to modify which pages are actually loaded in the browser. Accepted values are `get` to intercept only GET requests, `post` to intercept on POST requests or `yes` to intercept both GET & POST requests. Note that POST requests are not currently supported and will be ignored (if you set `beforeload=post` it will raise an error).
- __clearcache__: set to `yes` to have the browser's cookie cache cleared before the new window is opened
@ -139,18 +138,16 @@ instance, or the system browser.
- __cleardata__: set to `yes` to have the browser's entire local storage cleared (cookies, HTML5 local storage, IndexedDB, etc.) before the new window is opened
- __closebuttoncolor__: set as a valid hex color string, for example: `#00ff00`, to change from the default __Done__ button's color. Only applicable if toolbar is not disabled.
- __closebuttoncaption__: set to a string to use as the __Done__ button's caption. Note that you need to localize this value yourself.
- __disallowoverscroll__: Set to `yes` or `no` (default is `no`). Turns on/off the UIWebViewBounce property.
- __disallowoverscroll__: Set to `yes` or `no` (default is `no`). Turns on/off the the bounce of the WKWebView's UIScrollView.
- __hidenavigationbuttons__: set to `yes` or `no` to turn the toolbar navigation buttons on or off (defaults to `no`). Only applicable if toolbar is not disabled.
- __navigationbuttoncolor__: set as a valid hex color string, for example: `#00ff00`, to change from the default color. Only applicable if navigation buttons are visible.
- __toolbar__: set to `yes` or `no` to turn the toolbar on or off for the InAppBrowser (defaults to `yes`)
- __toolbarcolor__: set as a valid hex color string, for example: `#00ff00`, to change from the default color of the toolbar. Only applicable if toolbar is not disabled.
- __toolbartranslucent__: set to `yes` or `no` to make the toolbar translucent(semi-transparent) (defaults to `yes`). Only applicable if toolbar is not disabled.
- __lefttoright__: Set to `yes` to swap positions of the navigation buttons and the close button. Specifically, close button goes to the right and navigation buttons to the left.
- __enableViewportScale__: Set to `yes` or `no` to prevent viewport scaling through a meta tag (defaults to `no`). Only applicable to UIWebView (`usewkwebview=no`) and WKWebView (`usewkwebview=yes`) on iOS 10+.
- __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`). Applicable to UIWebView (`usewkwebview=no`) and WKWebView (`usewkwebview=yes`).
- __allowInlineMediaPlayback__: Set to `yes` or `no` to allow in-line HTML5 media playback, displaying within the browser window rather than a device-specific playback interface. The HTML's `video` element must also include the `webkit-playsinline` attribute (defaults to `no`). Applicable to UIWebView (`usewkwebview=no`) and WKWebView (`usewkwebview=yes`).
- __keyboardDisplayRequiresUserAction__: Set to `yes` or `no` to open the keyboard when form elements receive focus via JavaScript's `focus()` call (defaults to `yes`). Only applicable to UIWebView (`usewkwebview=no`).
- __suppressesIncrementalRendering__: Set to `yes` or `no` to wait until all new view content is received before being rendered (defaults to `no`). Only applicable to UIWebView (`usewkwebview=no`).
- __enableViewportScale__: Set to `yes` or `no` to prevent viewport scaling through a meta tag (defaults to `no`).
- __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`).
- __allowInlineMediaPlayback__: Set to `yes` or `no` to allow in-line HTML5 media playback, displaying within the browser window rather than a device-specific playback interface. The HTML's `video` element must also include the `webkit-playsinline` attribute (defaults to `no`).
- __presentationstyle__: Set to `pagesheet`, `formsheet` or `fullscreen` to set the [presentation style](http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalPresentationStyle) (defaults to `fullscreen`).
- __transitionstyle__: Set to `fliphorizontal`, `crossdissolve` or `coververtical` to set the [transition style](http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instp/UIViewController/modalTransitionStyle) (defaults to `coververtical`).
- __toolbarposition__: Set to `top` or `bottom` (default is `bottom`). Causes the toolbar to be at the top or bottom of the window.

View File

@ -75,27 +75,14 @@
</js-module>
<config-file target="config.xml" parent="/*">
<feature name="InAppBrowser">
<param name="ios-package" value="CDVInAppBrowser" />
<param name="onload" value="true" />
</feature>
<feature name="UIInAppBrowser">
<param name="ios-package" value="CDVUIInAppBrowser" />
<param name="onload" value="true" />
</feature>
<feature name="WKInAppBrowser">
<param name="ios-package" value="CDVWKInAppBrowser" />
<param name="onload" value="true" />
</feature>
</config-file>
<header-file src="src/ios/CDVInAppBrowser.h" />
<source-file src="src/ios/CDVInAppBrowser.m" />
<header-file src="src/ios/CDVInAppBrowserOptions.h" />
<source-file src="src/ios/CDVInAppBrowserOptions.m" />
<header-file src="src/ios/CDVInAppBrowserNavigationController.h" />
<source-file src="src/ios/CDVInAppBrowserNavigationController.m" />
<header-file src="src/ios/CDVUIInAppBrowser.h" />
<source-file src="src/ios/CDVUIInAppBrowser.m" />
<header-file src="src/ios/CDVWKInAppBrowser.h" />
<source-file src="src/ios/CDVWKInAppBrowser.m" />
<header-file src="src/ios/CDVWKInAppBrowserUIDelegate.h" />

View File

@ -1,36 +0,0 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
#import <Cordova/CDVPlugin.h>
#import <Cordova/CDVInvokedUrlCommand.h>
@interface CDVInAppBrowser : CDVPlugin {}
@property (nonatomic, assign) BOOL wkwebviewavailable;
@property (nonatomic, assign) BOOL usewkwebview;
- (void)open:(CDVInvokedUrlCommand*)command;
- (void)close:(CDVInvokedUrlCommand*)command;
- (void)injectScriptCode:(CDVInvokedUrlCommand*)command;
- (void)show:(CDVInvokedUrlCommand*)command;
- (void)hide:(CDVInvokedUrlCommand*)command;
- (void)loadAfterBeforeload:(CDVInvokedUrlCommand*)command;
@end

View File

@ -1,172 +0,0 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
#import "CDVInAppBrowser.h"
#import "CDVInAppBrowserOptions.h"
#if !WK_WEB_VIEW_ONLY
#import "CDVUIInAppBrowser.h"
#endif
#import "CDVWKInAppBrowser.h"
#import <Cordova/CDVPluginResult.h>
#pragma mark CDVInAppBrowser
@implementation CDVInAppBrowser
- (void)pluginInitialize
{
// default values
self.usewkwebview = NO;
#if __has_include("CDVWKWebViewEngine.h")
self.wkwebviewavailable = YES;
#else
self.wkwebviewavailable = NO;
#endif
}
- (void)open:(CDVInvokedUrlCommand*)command
{
NSString* options = [command argumentAtIndex:2 withDefault:@"" andClass:[NSString class]];
CDVInAppBrowserOptions* browserOptions = [CDVInAppBrowserOptions parseOptions:options];
if(browserOptions.usewkwebview && !self.wkwebviewavailable){
[self.commandDelegate sendPluginResult:[CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:@{@"type":@"loaderror", @"message": @"usewkwebview option specified but but no plugin that supplies a WKWebView engine is present"}] callbackId:command.callbackId];
return;
}
self.usewkwebview = browserOptions.usewkwebview;
#if WK_WEB_VIEW_ONLY
[[CDVWKInAppBrowser getInstance] open:command];
#else
if(self.usewkwebview){
[[CDVWKInAppBrowser getInstance] open:command];
}else{
[[CDVUIInAppBrowser getInstance] open:command];
}
#endif
}
- (void)close:(CDVInvokedUrlCommand*)command
{
#if WK_WEB_VIEW_ONLY
[[CDVWKInAppBrowser getInstance] close:command];
#else
if(self.usewkwebview){
[[CDVWKInAppBrowser getInstance] close:command];
}else{
[[CDVUIInAppBrowser getInstance] close:command];
}
#endif
}
- (void)show:(CDVInvokedUrlCommand*)command
{
#if WK_WEB_VIEW_ONLY
[[CDVWKInAppBrowser getInstance] show:command];
#else
if(self.usewkwebview){
[[CDVWKInAppBrowser getInstance] show:command];
}else{
[[CDVUIInAppBrowser getInstance] show:command];
}
#endif
}
- (void)hide:(CDVInvokedUrlCommand*)command
{
#if WK_WEB_VIEW_ONLY
[[CDVWKInAppBrowser getInstance] hide:command];
#else
if(self.usewkwebview){
[[CDVWKInAppBrowser getInstance] hide:command];
}else{
[[CDVUIInAppBrowser getInstance] hide:command];
}
#endif
}
- (void)injectScriptCode:(CDVInvokedUrlCommand*)command
{
#if WK_WEB_VIEW_ONLY
[[CDVWKInAppBrowser getInstance] injectScriptCode:command];
#else
if(self.usewkwebview){
[[CDVWKInAppBrowser getInstance] injectScriptCode:command];
}else{
[[CDVUIInAppBrowser getInstance] injectScriptCode:command];
}
#endif
}
- (void)injectScriptFile:(CDVInvokedUrlCommand*)command
{
#if WK_WEB_VIEW_ONLY
[[CDVWKInAppBrowser getInstance] injectScriptFile:command];
#else
if(self.usewkwebview){
[[CDVWKInAppBrowser getInstance] injectScriptFile:command];
}else{
[[CDVUIInAppBrowser getInstance] injectScriptFile:command];
}
#endif
}
- (void)injectStyleCode:(CDVInvokedUrlCommand*)command
{
#if WK_WEB_VIEW_ONLY
[[CDVWKInAppBrowser getInstance] injectStyleCode:command];
#else
if(self.usewkwebview){
[[CDVWKInAppBrowser getInstance] injectStyleCode:command];
}else{
[[CDVUIInAppBrowser getInstance] injectStyleCode:command];
}
#endif
}
- (void)injectStyleFile:(CDVInvokedUrlCommand*)command
{
#if WK_WEB_VIEW_ONLY
[[CDVWKInAppBrowser getInstance] injectStyleFile:command];
#else
if(self.usewkwebview){
[[CDVWKInAppBrowser getInstance] injectStyleFile:command];
}else{
[[CDVUIInAppBrowser getInstance] injectStyleFile:command];
}
#endif
}
- (void)loadAfterBeforeload:(CDVInvokedUrlCommand*)command
{
#if WK_WEB_VIEW_ONLY
[[CDVWKInAppBrowser getInstance] loadAfterBeforeload:command];
#else
if(self.usewkwebview){
[[CDVWKInAppBrowser getInstance] loadAfterBeforeload:command];
}else{
[[CDVUIInAppBrowser getInstance] loadAfterBeforeload:command];
}
#endif
}
@end

View File

@ -20,7 +20,6 @@
@interface CDVInAppBrowserOptions : NSObject {}
@property (nonatomic, assign) BOOL usewkwebview;
@property (nonatomic, assign) BOOL location;
@property (nonatomic, assign) BOOL toolbar;
@property (nonatomic, copy) NSString* closebuttoncaption;
@ -42,8 +41,6 @@
@property (nonatomic, assign) BOOL enableviewportscale;
@property (nonatomic, assign) BOOL mediaplaybackrequiresuseraction;
@property (nonatomic, assign) BOOL allowinlinemediaplayback;
@property (nonatomic, assign) BOOL keyboarddisplayrequiresuseraction;
@property (nonatomic, assign) BOOL suppressesincrementalrendering;
@property (nonatomic, assign) BOOL hidden;
@property (nonatomic, assign) BOOL disallowoverscroll;
@property (nonatomic, copy) NSString* beforeload;

View File

@ -25,7 +25,6 @@
{
if (self = [super init]) {
// default values
self.usewkwebview = NO;
self.location = YES;
self.toolbar = YES;
self.closebuttoncaption = nil;
@ -38,8 +37,6 @@
self.enableviewportscale = NO;
self.mediaplaybackrequiresuseraction = NO;
self.allowinlinemediaplayback = NO;
self.keyboarddisplayrequiresuseraction = YES;
self.suppressesincrementalrendering = NO;
self.hidden = NO;
self.disallowoverscroll = NO;
self.hidenavigationbuttons = NO;

View File

@ -1,95 +0,0 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
#if !WK_WEB_VIEW_ONLY
#import <Cordova/CDVPlugin.h>
#import <Cordova/CDVInvokedUrlCommand.h>
#import <Cordova/CDVScreenOrientationDelegate.h>
#import "CDVInAppBrowserOptions.h"
#import "CDVInAppBrowserNavigationController.h"
#ifdef __CORDOVA_4_0_0
#import <Cordova/CDVUIWebViewDelegate.h>
#else
#import <Cordova/CDVWebViewDelegate.h>
#endif
@class CDVUIInAppBrowserViewController;
@interface CDVUIInAppBrowser : CDVPlugin {
UIWindow * tmpWindow;
@private
NSString* _beforeload;
BOOL _waitForBeforeload;
}
@property (nonatomic, retain) CDVUIInAppBrowserViewController* inAppBrowserViewController;
@property (nonatomic, copy) NSString* callbackId;
@property (nonatomic, copy) NSRegularExpression *callbackIdPattern;
+ (id) getInstance;
- (void)open:(CDVInvokedUrlCommand*)command;
- (void)close:(CDVInvokedUrlCommand*)command;
- (void)injectScriptCode:(CDVInvokedUrlCommand*)command;
- (void)show:(CDVInvokedUrlCommand*)command;
- (void)hide:(CDVInvokedUrlCommand*)command;
- (void)loadAfterBeforeload:(CDVInvokedUrlCommand*)command;
@end
@interface CDVUIInAppBrowserViewController : UIViewController <UIWebViewDelegate, CDVScreenOrientationDelegate>{
@private
NSString* _userAgent;
NSString* _prevUserAgent;
NSInteger _userAgentLockToken;
CDVInAppBrowserOptions *_browserOptions;
#ifdef __CORDOVA_4_0_0
CDVUIWebViewDelegate* _webViewDelegate;
#else
CDVWebViewDelegate* _webViewDelegate;
#endif
}
@property (nonatomic, strong) IBOutlet UIWebView* webView;
@property (nonatomic, strong) IBOutlet UIBarButtonItem* closeButton;
@property (nonatomic, strong) IBOutlet UILabel* addressLabel;
@property (nonatomic, strong) IBOutlet UIBarButtonItem* backButton;
@property (nonatomic, strong) IBOutlet UIBarButtonItem* forwardButton;
@property (nonatomic, strong) IBOutlet UIActivityIndicatorView* spinner;
@property (nonatomic, strong) IBOutlet UIToolbar* toolbar;
@property (nonatomic, weak) id <CDVScreenOrientationDelegate> orientationDelegate;
@property (nonatomic, weak) CDVUIInAppBrowser* navigationDelegate;
@property (nonatomic) NSURL* currentURL;
- (void)close;
- (void)navigateTo:(NSURL*)url;
- (void)showLocationBar:(BOOL)show;
- (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition;
- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString : (int) buttonIndex;
- (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent browserOptions: (CDVInAppBrowserOptions*) browserOptions;
@end
#endif

File diff suppressed because it is too large Load Diff

View File

@ -51,10 +51,8 @@
@interface CDVWKInAppBrowserViewController : UIViewController <CDVScreenOrientationDelegate,WKNavigationDelegate,WKUIDelegate,WKScriptMessageHandler>{
@private
NSString* _userAgent;
NSString* _prevUserAgent;
NSInteger _userAgentLockToken;
CDVInAppBrowserOptions *_browserOptions;
NSDictionary *_settings;
}
@property (nonatomic, strong) IBOutlet WKWebView* webView;
@ -77,6 +75,6 @@
- (void)showToolBar:(BOOL)show : (NSString *) toolbarPosition;
- (void)setCloseButtonTitle:(NSString*)title : (NSString*) colorString : (int) buttonIndex;
- (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent browserOptions: (CDVInAppBrowserOptions*) browserOptions;
- (id)initWithBrowserOptions: (CDVInAppBrowserOptions*) browserOptions andSettings:(NSDictionary*) settings;
@end

View File

@ -24,7 +24,6 @@
#endif
#import <Cordova/CDVPluginResult.h>
#import <Cordova/CDVUserAgentUtil.h>
#define kInAppBrowserTargetSelf @"_self"
#define kInAppBrowserTargetSystem @"_system"
@ -64,11 +63,6 @@ static CDVWKInAppBrowser* instance = nil;
_waitForBeforeload = NO;
}
- (id)settingForKey:(NSString*)key
{
return [self.commandDelegate.settings objectForKey:[key lowercaseString]];
}
- (void)onReset
{
[self close:nil];
@ -105,11 +99,7 @@ static CDVWKInAppBrowser* instance = nil;
self.callbackId = command.callbackId;
if (url != nil) {
#ifdef __CORDOVA_4_0_0
NSURL* baseUrl = [self.webViewEngine URL];
#else
NSURL* baseUrl = [self.webView.request URL];
#endif
NSURL* absoluteUrl = [[NSURL URLWithString:url relativeToURL:baseUrl] absoluteURL];
if ([self isSystemUrl:absoluteUrl]) {
@ -209,16 +199,7 @@ static CDVWKInAppBrowser* instance = nil;
}
if (self.inAppBrowserViewController == nil) {
NSString* userAgent = [CDVUserAgentUtil originalUserAgent];
NSString* overrideUserAgent = [self settingForKey:@"OverrideUserAgent"];
NSString* appendUserAgent = [self settingForKey:@"AppendUserAgent"];
if(overrideUserAgent){
userAgent = overrideUserAgent;
}
if(appendUserAgent){
userAgent = [userAgent stringByAppendingString: appendUserAgent];
}
self.inAppBrowserViewController = [[CDVWKInAppBrowserViewController alloc] initWithUserAgent:userAgent prevUserAgent:[self.commandDelegate userAgent] browserOptions: browserOptions];
self.inAppBrowserViewController = [[CDVWKInAppBrowserViewController alloc] initWithBrowserOptions: browserOptions andSettings:self.commandDelegate.settings];
self.inAppBrowserViewController.navigationDelegate = self;
if ([self.viewController conformsToProtocol:@protocol(CDVScreenOrientationDelegate)]) {
@ -369,18 +350,9 @@ static CDVWKInAppBrowser* instance = nil;
- (void)openInCordovaWebView:(NSURL*)url withOptions:(NSString*)options
{
NSURLRequest* request = [NSURLRequest requestWithURL:url];
#ifdef __CORDOVA_4_0_0
// the webview engine itself will filter for this according to <allow-navigation> 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];
}

View File

@ -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 = '<h1>Webview</h1>' +
'<p>Use this button to toggle the Webview implementation.</p>' +
'<div id="webviewToggle"></div>';
}
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 () {