breaking(ios): remove UIWebView (#635)
This commit is contained in:
+21
-62
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user