CB-7179 (iOS): Add support to optionally use WKWebView for iOS
This commit is contained in:
parent
a0783378fc
commit
dc7fa34bbe
@ -28,9 +28,9 @@ matrix:
|
||||
os: linux
|
||||
language: node_js
|
||||
node_js: '4.2'
|
||||
- env: PLATFORM=ios-9.3
|
||||
- env: PLATFORM=ios-10.0
|
||||
os: osx
|
||||
osx_image: xcode7.3
|
||||
osx_image: xcode8.3
|
||||
language: node_js
|
||||
node_js: '4.2'
|
||||
# TBD SKIP for now:
|
||||
|
14
README.md
14
README.md
@ -136,9 +136,11 @@ 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.
|
||||
- __clearcache__: set to `yes` to have the browser's cookie cache cleared before the new window is opened
|
||||
- __clearsessioncache__: set to `yes` to have the session cookie cache cleared before the new window is opened
|
||||
- __clearsessioncache__: set to `yes` to have the session cookie cache cleared before the new window is opened. For WKWebView, requires iOS 11+ on target device.
|
||||
- __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.
|
||||
@ -147,11 +149,11 @@ instance, or the system browser.
|
||||
- __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.
|
||||
- __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`)
|
||||
- __keyboardDisplayRequiresUserAction__: Set to `yes` or `no` to open the keyboard when form elements receive focus via JavaScript's `focus()` call (defaults to `yes`).
|
||||
- __suppressesIncrementalRendering__: Set to `yes` or `no` to wait until all new view content is received before being rendered (defaults to `no`).
|
||||
- __enableViewportScale__: Set to `yes` or `no` to prevent viewport scaling through a meta tag (defaults to `no`). Only applicable to UIWebView (`usewkwebview=no`).
|
||||
- __mediaPlaybackRequiresUserAction__: Set to `yes` to prevent HTML5 audio or video from autoplaying (defaults to `no`). Only applicable to UIWebView (`usewkwebview=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`) Only applicable to UIWebView (`usewkwebview=no`).
|
||||
- __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`).
|
||||
- __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.
|
||||
|
@ -20,6 +20,9 @@
|
||||
-->
|
||||
# Release Notes
|
||||
|
||||
### 3.1.0-dev (Unreleased)
|
||||
* CB-7179 (iOS): Add support to optionally use WKWebView for iOS
|
||||
|
||||
### 3.0.0 (Apr 12, 2018)
|
||||
* [CB-13659](https://issues.apache.org/jira/browse/CB-13659) **iOS** Add hidespinner option
|
||||
* In file `AppBrowser.java`: New code within `shouldOverrideUrlLoading()` to check for whitelisting custom schemes via a new `AllowedSchemes` preference configuration item. Allows custom schemes like `mycoolapp://` or `wevotetwitterscheme://`
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cordova-plugin-inappbrowser",
|
||||
"version": "3.0.1-dev",
|
||||
"version": "3.1.0-dev",
|
||||
"description": "Cordova InAppBrowser Plugin",
|
||||
"types": "./types/index.d.ts",
|
||||
"cordova": {
|
||||
|
22
plugin.xml
22
plugin.xml
@ -20,7 +20,7 @@
|
||||
|
||||
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
|
||||
id="cordova-plugin-inappbrowser"
|
||||
version="3.0.1-dev">
|
||||
version="3.1.0-dev">
|
||||
|
||||
<name>InAppBrowser</name>
|
||||
<description>Cordova InAppBrowser Plugin</description>
|
||||
@ -76,11 +76,31 @@
|
||||
<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" />
|
||||
<source-file src="src/ios/CDVWKInAppBrowserUIDelegate.m" />
|
||||
|
||||
|
||||
<framework src="CoreGraphics.framework" />
|
||||
</platform>
|
||||
|
@ -19,23 +19,11 @@
|
||||
|
||||
#import <Cordova/CDVPlugin.h>
|
||||
#import <Cordova/CDVInvokedUrlCommand.h>
|
||||
#import <Cordova/CDVScreenOrientationDelegate.h>
|
||||
|
||||
#ifdef __CORDOVA_4_0_0
|
||||
#import <Cordova/CDVUIWebViewDelegate.h>
|
||||
#else
|
||||
#import <Cordova/CDVWebViewDelegate.h>
|
||||
#endif
|
||||
@interface CDVInAppBrowser : CDVPlugin {}
|
||||
|
||||
@class CDVInAppBrowserViewController;
|
||||
|
||||
@interface CDVInAppBrowser : CDVPlugin {
|
||||
UIWindow * tmpWindow;
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) CDVInAppBrowserViewController* inAppBrowserViewController;
|
||||
@property (nonatomic, copy) NSString* callbackId;
|
||||
@property (nonatomic, copy) NSRegularExpression *callbackIdPattern;
|
||||
@property (nonatomic, assign) BOOL wkwebviewavailable;
|
||||
@property (nonatomic, assign) BOOL usewkwebview;
|
||||
|
||||
- (void)open:(CDVInvokedUrlCommand*)command;
|
||||
- (void)close:(CDVInvokedUrlCommand*)command;
|
||||
@ -45,75 +33,3 @@
|
||||
|
||||
@end
|
||||
|
||||
@interface CDVInAppBrowserOptions : NSObject {}
|
||||
|
||||
@property (nonatomic, assign) BOOL location;
|
||||
@property (nonatomic, assign) BOOL toolbar;
|
||||
@property (nonatomic, copy) NSString* closebuttoncaption;
|
||||
@property (nonatomic, copy) NSString* closebuttoncolor;
|
||||
@property (nonatomic, copy) NSString* toolbarposition;
|
||||
@property (nonatomic, copy) NSString* toolbarcolor;
|
||||
@property (nonatomic, assign) BOOL toolbartranslucent;
|
||||
@property (nonatomic, assign) BOOL hidenavigationbuttons;
|
||||
@property (nonatomic, copy) NSString* navigationbuttoncolor;
|
||||
@property (nonatomic, assign) BOOL clearcache;
|
||||
@property (nonatomic, assign) BOOL clearsessioncache;
|
||||
@property (nonatomic, assign) BOOL hidespinner;
|
||||
|
||||
@property (nonatomic, copy) NSString* presentationstyle;
|
||||
@property (nonatomic, copy) NSString* transitionstyle;
|
||||
|
||||
@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;
|
||||
|
||||
+ (CDVInAppBrowserOptions*)parseOptions:(NSString*)options;
|
||||
|
||||
@end
|
||||
|
||||
@interface CDVInAppBrowserViewController : 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) CDVInAppBrowser* 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;
|
||||
|
||||
- (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent browserOptions: (CDVInAppBrowserOptions*) browserOptions;
|
||||
|
||||
@end
|
||||
|
||||
@interface CDVInAppBrowserNavigationController : UINavigationController
|
||||
|
||||
@property (nonatomic, weak) id <CDVScreenOrientationDelegate> orientationDelegate;
|
||||
|
||||
@end
|
||||
|
File diff suppressed because it is too large
Load Diff
27
src/ios/CDVInAppBrowserNavigationController.h
Normal file
27
src/ios/CDVInAppBrowserNavigationController.h
Normal file
@ -0,0 +1,27 @@
|
||||
/*
|
||||
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/CDVScreenOrientationDelegate.h>
|
||||
|
||||
|
||||
@interface CDVInAppBrowserNavigationController : UINavigationController
|
||||
|
||||
@property (nonatomic, weak) id <CDVScreenOrientationDelegate> orientationDelegate;
|
||||
|
||||
@end
|
85
src/ios/CDVInAppBrowserNavigationController.m
Normal file
85
src/ios/CDVInAppBrowserNavigationController.m
Normal file
@ -0,0 +1,85 @@
|
||||
/*
|
||||
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 "CDVInAppBrowserNavigationController.h"
|
||||
|
||||
#define STATUSBAR_HEIGHT 20.0
|
||||
|
||||
@implementation CDVInAppBrowserNavigationController : UINavigationController
|
||||
|
||||
- (void) dismissViewControllerAnimated:(BOOL)flag completion:(void (^)(void))completion {
|
||||
if ( self.presentedViewController) {
|
||||
[super dismissViewControllerAnimated:flag completion:completion];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) viewDidLoad {
|
||||
|
||||
CGRect statusBarFrame = [self invertFrameIfNeeded:[UIApplication sharedApplication].statusBarFrame];
|
||||
statusBarFrame.size.height = STATUSBAR_HEIGHT;
|
||||
// simplified from: http://stackoverflow.com/a/25669695/219684
|
||||
|
||||
UIToolbar* bgToolbar = [[UIToolbar alloc] initWithFrame:statusBarFrame];
|
||||
bgToolbar.barStyle = UIBarStyleDefault;
|
||||
[bgToolbar setAutoresizingMask:UIViewAutoresizingFlexibleWidth];
|
||||
[self.view addSubview:bgToolbar];
|
||||
|
||||
[super viewDidLoad];
|
||||
}
|
||||
|
||||
- (CGRect) invertFrameIfNeeded:(CGRect)rect {
|
||||
if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
|
||||
CGFloat temp = rect.size.width;
|
||||
rect.size.width = rect.size.height;
|
||||
rect.size.height = temp;
|
||||
}
|
||||
rect.origin = CGPointZero;
|
||||
return rect;
|
||||
}
|
||||
|
||||
#pragma mark CDVScreenOrientationDelegate
|
||||
|
||||
- (BOOL)shouldAutorotate
|
||||
{
|
||||
if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector(shouldAutorotate)]) {
|
||||
return [self.orientationDelegate shouldAutorotate];
|
||||
}
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (NSUInteger)supportedInterfaceOrientations
|
||||
{
|
||||
if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector(supportedInterfaceOrientations)]) {
|
||||
return [self.orientationDelegate supportedInterfaceOrientations];
|
||||
}
|
||||
|
||||
return 1 << UIInterfaceOrientationPortrait;
|
||||
}
|
||||
|
||||
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
|
||||
{
|
||||
if ((self.orientationDelegate != nil) && [self.orientationDelegate respondsToSelector:@selector(shouldAutorotateToInterfaceOrientation:)]) {
|
||||
return [self.orientationDelegate shouldAutorotateToInterfaceOrientation:interfaceOrientation];
|
||||
}
|
||||
|
||||
return YES;
|
||||
}
|
||||
|
||||
|
||||
@end
|
51
src/ios/CDVInAppBrowserOptions.h
Normal file
51
src/ios/CDVInAppBrowserOptions.h
Normal file
@ -0,0 +1,51 @@
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
|
||||
@interface CDVInAppBrowserOptions : NSObject {}
|
||||
|
||||
@property (nonatomic, assign) BOOL usewkwebview;
|
||||
@property (nonatomic, assign) BOOL location;
|
||||
@property (nonatomic, assign) BOOL toolbar;
|
||||
@property (nonatomic, copy) NSString* closebuttoncaption;
|
||||
@property (nonatomic, copy) NSString* closebuttoncolor;
|
||||
@property (nonatomic, copy) NSString* toolbarposition;
|
||||
@property (nonatomic, copy) NSString* toolbarcolor;
|
||||
@property (nonatomic, assign) BOOL toolbartranslucent;
|
||||
@property (nonatomic, assign) BOOL hidenavigationbuttons;
|
||||
@property (nonatomic, copy) NSString* navigationbuttoncolor;
|
||||
@property (nonatomic, assign) BOOL cleardata;
|
||||
@property (nonatomic, assign) BOOL clearcache;
|
||||
@property (nonatomic, assign) BOOL clearsessioncache;
|
||||
@property (nonatomic, assign) BOOL hidespinner;
|
||||
|
||||
@property (nonatomic, copy) NSString* presentationstyle;
|
||||
@property (nonatomic, copy) NSString* transitionstyle;
|
||||
|
||||
@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;
|
||||
|
||||
+ (CDVInAppBrowserOptions*)parseOptions:(NSString*)options;
|
||||
|
||||
@end
|
91
src/ios/CDVInAppBrowserOptions.m
Normal file
91
src/ios/CDVInAppBrowserOptions.m
Normal file
@ -0,0 +1,91 @@
|
||||
/*
|
||||
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 "CDVInAppBrowserOptions.h"
|
||||
|
||||
@implementation CDVInAppBrowserOptions
|
||||
|
||||
- (id)init
|
||||
{
|
||||
if (self = [super init]) {
|
||||
// default values
|
||||
self.usewkwebview = NO;
|
||||
self.location = YES;
|
||||
self.toolbar = YES;
|
||||
self.closebuttoncaption = nil;
|
||||
self.toolbarposition = @"bottom";
|
||||
self.cleardata = NO;
|
||||
self.clearcache = NO;
|
||||
self.clearsessioncache = NO;
|
||||
self.hidespinner = NO;
|
||||
|
||||
self.enableviewportscale = NO;
|
||||
self.mediaplaybackrequiresuseraction = NO;
|
||||
self.allowinlinemediaplayback = NO;
|
||||
self.keyboarddisplayrequiresuseraction = YES;
|
||||
self.suppressesincrementalrendering = NO;
|
||||
self.hidden = NO;
|
||||
self.disallowoverscroll = NO;
|
||||
self.hidenavigationbuttons = NO;
|
||||
self.closebuttoncolor = nil;
|
||||
self.toolbarcolor = nil;
|
||||
self.toolbartranslucent = YES;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (CDVInAppBrowserOptions*)parseOptions:(NSString*)options
|
||||
{
|
||||
CDVInAppBrowserOptions* obj = [[CDVInAppBrowserOptions alloc] init];
|
||||
|
||||
// NOTE: this parsing does not handle quotes within values
|
||||
NSArray* pairs = [options componentsSeparatedByString:@","];
|
||||
|
||||
// parse keys and values, set the properties
|
||||
for (NSString* pair in pairs) {
|
||||
NSArray* keyvalue = [pair componentsSeparatedByString:@"="];
|
||||
|
||||
if ([keyvalue count] == 2) {
|
||||
NSString* key = [[keyvalue objectAtIndex:0] lowercaseString];
|
||||
NSString* value = [keyvalue objectAtIndex:1];
|
||||
NSString* value_lc = [value lowercaseString];
|
||||
|
||||
BOOL isBoolean = [value_lc isEqualToString:@"yes"] || [value_lc isEqualToString:@"no"];
|
||||
NSNumberFormatter* numberFormatter = [[NSNumberFormatter alloc] init];
|
||||
[numberFormatter setAllowsFloats:YES];
|
||||
BOOL isNumber = [numberFormatter numberFromString:value_lc] != nil;
|
||||
|
||||
// set the property according to the key name
|
||||
if ([obj respondsToSelector:NSSelectorFromString(key)]) {
|
||||
if (isNumber) {
|
||||
[obj setValue:[numberFormatter numberFromString:value_lc] forKey:key];
|
||||
} else if (isBoolean) {
|
||||
[obj setValue:[NSNumber numberWithBool:[value_lc isEqualToString:@"yes"]] forKey:key];
|
||||
} else {
|
||||
[obj setValue:value forKey:key];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
@end
|
86
src/ios/CDVUIInAppBrowser.h
Normal file
86
src/ios/CDVUIInAppBrowser.h
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
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>
|
||||
#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;
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
@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;
|
||||
|
||||
- (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent browserOptions: (CDVInAppBrowserOptions*) browserOptions;
|
||||
|
||||
@end
|
1029
src/ios/CDVUIInAppBrowser.m
Normal file
1029
src/ios/CDVUIInAppBrowser.m
Normal file
File diff suppressed because it is too large
Load Diff
76
src/ios/CDVWKInAppBrowser.h
Normal file
76
src/ios/CDVWKInAppBrowser.h
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
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>
|
||||
#import <Cordova/CDVScreenOrientationDelegate.h>
|
||||
#import "CDVWKInAppBrowserUIDelegate.h"
|
||||
#import "CDVInAppBrowserOptions.h"
|
||||
#import "CDVInAppBrowserNavigationController.h"
|
||||
|
||||
@class CDVWKInAppBrowserViewController;
|
||||
|
||||
@interface CDVWKInAppBrowser : CDVPlugin {
|
||||
}
|
||||
|
||||
@property (nonatomic, retain) CDVWKInAppBrowser* instance;
|
||||
@property (nonatomic, retain) CDVWKInAppBrowserViewController* 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;
|
||||
|
||||
@end
|
||||
|
||||
@interface CDVWKInAppBrowserViewController : UIViewController <CDVScreenOrientationDelegate,WKNavigationDelegate,WKUIDelegate,WKScriptMessageHandler>{
|
||||
@private
|
||||
NSString* _userAgent;
|
||||
NSString* _prevUserAgent;
|
||||
NSInteger _userAgentLockToken;
|
||||
CDVInAppBrowserOptions *_browserOptions;
|
||||
}
|
||||
|
||||
@property (nonatomic, strong) IBOutlet WKWebView* webView;
|
||||
@property (nonatomic, strong) IBOutlet WKWebViewConfiguration* configuration;
|
||||
@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, strong) IBOutlet CDVWKInAppBrowserUIDelegate* webViewUIDelegate;
|
||||
|
||||
@property (nonatomic, weak) id <CDVScreenOrientationDelegate> orientationDelegate;
|
||||
@property (nonatomic, weak) CDVWKInAppBrowser* 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;
|
||||
|
||||
- (id)initWithUserAgent:(NSString*)userAgent prevUserAgent:(NSString*)prevUserAgent browserOptions: (CDVInAppBrowserOptions*) browserOptions;
|
||||
|
||||
@end
|
1181
src/ios/CDVWKInAppBrowser.m
Normal file
1181
src/ios/CDVWKInAppBrowser.m
Normal file
File diff suppressed because it is too large
Load Diff
32
src/ios/CDVWKInAppBrowserUIDelegate.h
Normal file
32
src/ios/CDVWKInAppBrowserUIDelegate.h
Normal file
@ -0,0 +1,32 @@
|
||||
/*
|
||||
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 <WebKit/WebKit.h>
|
||||
|
||||
@interface CDVWKInAppBrowserUIDelegate : NSObject <WKUIDelegate>{
|
||||
@private
|
||||
UIViewController* _viewController;
|
||||
}
|
||||
|
||||
@property (nonatomic, copy) NSString* title;
|
||||
|
||||
- (instancetype)initWithTitle:(NSString*)title;
|
||||
-(void) setViewController:(UIViewController*) viewController;
|
||||
|
||||
@end
|
127
src/ios/CDVWKInAppBrowserUIDelegate.m
Normal file
127
src/ios/CDVWKInAppBrowserUIDelegate.m
Normal file
@ -0,0 +1,127 @@
|
||||
/*
|
||||
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 "CDVWKInAppBrowserUIDelegate.h"
|
||||
|
||||
@implementation CDVWKInAppBrowserUIDelegate
|
||||
|
||||
- (instancetype)initWithTitle:(NSString*)title
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
self.title = title;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) webView:(WKWebView*)webView runJavaScriptAlertPanelWithMessage:(NSString*)message
|
||||
initiatedByFrame:(WKFrameInfo*)frame completionHandler:(void (^)(void))completionHandler
|
||||
{
|
||||
UIAlertController* alert = [UIAlertController alertControllerWithTitle:self.title
|
||||
message:message
|
||||
preferredStyle:UIAlertControllerStyleAlert];
|
||||
|
||||
UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK")
|
||||
style:UIAlertActionStyleDefault
|
||||
handler:^(UIAlertAction* action)
|
||||
{
|
||||
completionHandler();
|
||||
[alert dismissViewControllerAnimated:YES completion:nil];
|
||||
}];
|
||||
|
||||
[alert addAction:ok];
|
||||
|
||||
[[self getViewController] presentViewController:alert animated:YES completion:nil];
|
||||
}
|
||||
|
||||
- (void) webView:(WKWebView*)webView runJavaScriptConfirmPanelWithMessage:(NSString*)message
|
||||
initiatedByFrame:(WKFrameInfo*)frame completionHandler:(void (^)(BOOL result))completionHandler
|
||||
{
|
||||
UIAlertController* alert = [UIAlertController alertControllerWithTitle:self.title
|
||||
message:message
|
||||
preferredStyle:UIAlertControllerStyleAlert];
|
||||
|
||||
UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK")
|
||||
style:UIAlertActionStyleDefault
|
||||
handler:^(UIAlertAction* action)
|
||||
{
|
||||
completionHandler(YES);
|
||||
[alert dismissViewControllerAnimated:YES completion:nil];
|
||||
}];
|
||||
|
||||
[alert addAction:ok];
|
||||
|
||||
UIAlertAction* cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel")
|
||||
style:UIAlertActionStyleDefault
|
||||
handler:^(UIAlertAction* action)
|
||||
{
|
||||
completionHandler(NO);
|
||||
[alert dismissViewControllerAnimated:YES completion:nil];
|
||||
}];
|
||||
[alert addAction:cancel];
|
||||
|
||||
[[self getViewController] presentViewController:alert animated:YES completion:nil];
|
||||
}
|
||||
|
||||
- (void) webView:(WKWebView*)webView runJavaScriptTextInputPanelWithPrompt:(NSString*)prompt
|
||||
defaultText:(NSString*)defaultText initiatedByFrame:(WKFrameInfo*)frame
|
||||
completionHandler:(void (^)(NSString* result))completionHandler
|
||||
{
|
||||
UIAlertController* alert = [UIAlertController alertControllerWithTitle:self.title
|
||||
message:prompt
|
||||
preferredStyle:UIAlertControllerStyleAlert];
|
||||
|
||||
UIAlertAction* ok = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK", @"OK")
|
||||
style:UIAlertActionStyleDefault
|
||||
handler:^(UIAlertAction* action)
|
||||
{
|
||||
completionHandler(((UITextField*)alert.textFields[0]).text);
|
||||
[alert dismissViewControllerAnimated:YES completion:nil];
|
||||
}];
|
||||
|
||||
[alert addAction:ok];
|
||||
|
||||
UIAlertAction* cancel = [UIAlertAction actionWithTitle:NSLocalizedString(@"Cancel", @"Cancel")
|
||||
style:UIAlertActionStyleDefault
|
||||
handler:^(UIAlertAction* action)
|
||||
{
|
||||
completionHandler(nil);
|
||||
[alert dismissViewControllerAnimated:YES completion:nil];
|
||||
}];
|
||||
[alert addAction:cancel];
|
||||
|
||||
[alert addTextFieldWithConfigurationHandler:^(UITextField* textField) {
|
||||
textField.text = defaultText;
|
||||
}];
|
||||
|
||||
[[self getViewController] presentViewController:alert animated:YES completion:nil];
|
||||
}
|
||||
|
||||
-(UIViewController*) getViewController
|
||||
{
|
||||
return _viewController;
|
||||
}
|
||||
|
||||
-(void) setViewController:(UIViewController*) viewController
|
||||
{
|
||||
_viewController = viewController;
|
||||
}
|
||||
|
||||
@end
|
@ -29,5 +29,11 @@
|
||||
<js-module src="tests.js" name="tests">
|
||||
</js-module>
|
||||
|
||||
<platform name="ios">
|
||||
<!-- The WKWebView implementation for inappbrowser requires the presence of this plugin -->
|
||||
<dependency id="cordova-plugin-wkwebview-engine" />
|
||||
</platform>
|
||||
|
||||
|
||||
<asset src="resources" target="cdvtests/iab-resources" />
|
||||
</plugin>
|
||||
|
292
tests/tests.js
292
tests/tests.js
@ -19,10 +19,11 @@
|
||||
*
|
||||
*/
|
||||
|
||||
/* global MSApp */
|
||||
/* global MSApp, alert */
|
||||
|
||||
var cordova = require('cordova');
|
||||
var isWindows = cordova.platformId === 'windows';
|
||||
var isIos = cordova.platformId === 'ios';
|
||||
var isBrowser = cordova.platformId === 'browser';
|
||||
|
||||
window.alert = window.alert || navigator.notification.alert;
|
||||
@ -33,122 +34,133 @@ if (isWindows && navigator && navigator.notification && navigator.notification.a
|
||||
|
||||
exports.defineAutoTests = function () {
|
||||
|
||||
describe('cordova.InAppBrowser', function () {
|
||||
var createTests = function (platformOpts) {
|
||||
platformOpts = platformOpts || '';
|
||||
|
||||
it('inappbrowser.spec.1 should exist', function () {
|
||||
expect(cordova.InAppBrowser).toBeDefined();
|
||||
});
|
||||
describe('cordova.InAppBrowser', function () {
|
||||
|
||||
it('inappbrowser.spec.2 should contain open function', function () {
|
||||
expect(cordova.InAppBrowser.open).toBeDefined();
|
||||
expect(cordova.InAppBrowser.open).toEqual(jasmine.any(Function));
|
||||
});
|
||||
});
|
||||
|
||||
describe('open method', function () {
|
||||
|
||||
if (cordova.platformId === 'osx') {
|
||||
pending('Open method not fully supported on OSX.');
|
||||
return;
|
||||
}
|
||||
|
||||
var iabInstance;
|
||||
var originalTimeout;
|
||||
var url = 'https://dist.apache.org/repos/dist/dev/cordova/';
|
||||
var badUrl = 'http://bad-uri/';
|
||||
|
||||
beforeEach(function () {
|
||||
// increase timeout to ensure test url could be loaded within test time
|
||||
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
|
||||
|
||||
iabInstance = null;
|
||||
});
|
||||
|
||||
afterEach(function (done) {
|
||||
// restore original timeout
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
||||
|
||||
if (iabInstance !== null && iabInstance.close) {
|
||||
iabInstance.close();
|
||||
}
|
||||
iabInstance = null;
|
||||
// add some extra time so that iab dialog is closed
|
||||
setTimeout(done, 2000);
|
||||
});
|
||||
|
||||
function verifyEvent (evt, type) {
|
||||
expect(evt).toBeDefined();
|
||||
expect(evt.type).toEqual(type);
|
||||
// `exit` event does not have url field, browser returns null url for CORS requests
|
||||
if (type !== 'exit' && !isBrowser) {
|
||||
expect(evt.url).toEqual(url);
|
||||
}
|
||||
}
|
||||
|
||||
function verifyLoadErrorEvent (evt) {
|
||||
expect(evt).toBeDefined();
|
||||
expect(evt.type).toEqual('loaderror');
|
||||
expect(evt.url).toEqual(badUrl);
|
||||
expect(evt.code).toEqual(jasmine.any(Number));
|
||||
expect(evt.message).toEqual(jasmine.any(String));
|
||||
}
|
||||
|
||||
it('inappbrowser.spec.3 should return InAppBrowser instance with required methods', function () {
|
||||
iabInstance = cordova.InAppBrowser.open(url, '_blank');
|
||||
|
||||
expect(iabInstance).toBeDefined();
|
||||
|
||||
expect(iabInstance.addEventListener).toEqual(jasmine.any(Function));
|
||||
expect(iabInstance.removeEventListener).toEqual(jasmine.any(Function));
|
||||
expect(iabInstance.close).toEqual(jasmine.any(Function));
|
||||
expect(iabInstance.show).toEqual(jasmine.any(Function));
|
||||
expect(iabInstance.hide).toEqual(jasmine.any(Function));
|
||||
expect(iabInstance.executeScript).toEqual(jasmine.any(Function));
|
||||
expect(iabInstance.insertCSS).toEqual(jasmine.any(Function));
|
||||
});
|
||||
|
||||
it('inappbrowser.spec.4 should support loadstart and loadstop events', function (done) {
|
||||
var onLoadStart = jasmine.createSpy('loadstart event callback').and.callFake(function (evt) {
|
||||
verifyEvent(evt, 'loadstart');
|
||||
it('inappbrowser.spec.1 should exist', function () {
|
||||
expect(cordova.InAppBrowser).toBeDefined();
|
||||
});
|
||||
|
||||
iabInstance = cordova.InAppBrowser.open(url, '_blank');
|
||||
iabInstance.addEventListener('loadstart', onLoadStart);
|
||||
iabInstance.addEventListener('loadstop', function (evt) {
|
||||
verifyEvent(evt, 'loadstop');
|
||||
if (!isBrowser) {
|
||||
// according to documentation, "loadstart" event is not supported on browser
|
||||
// https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1
|
||||
expect(onLoadStart).toHaveBeenCalled();
|
||||
it('inappbrowser.spec.2 should contain open function', function () {
|
||||
expect(cordova.InAppBrowser.open).toBeDefined();
|
||||
expect(cordova.InAppBrowser.open).toEqual(jasmine.any(Function));
|
||||
});
|
||||
});
|
||||
|
||||
describe('open method', function () {
|
||||
|
||||
if (cordova.platformId === 'osx') {
|
||||
pending('Open method not fully supported on OSX.');
|
||||
return;
|
||||
}
|
||||
|
||||
var iabInstance;
|
||||
var originalTimeout;
|
||||
var url = 'https://dist.apache.org/repos/dist/dev/cordova/';
|
||||
var badUrl = 'http://bad-uri/';
|
||||
|
||||
beforeEach(function () {
|
||||
// increase timeout to ensure test url could be loaded within test time
|
||||
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = 30000;
|
||||
|
||||
iabInstance = null;
|
||||
});
|
||||
|
||||
afterEach(function (done) {
|
||||
// restore original timeout
|
||||
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
|
||||
|
||||
if (iabInstance !== null && iabInstance.close) {
|
||||
iabInstance.close();
|
||||
}
|
||||
done();
|
||||
iabInstance = null;
|
||||
// add some extra time so that iab dialog is closed
|
||||
setTimeout(done, 2000);
|
||||
});
|
||||
});
|
||||
|
||||
it('inappbrowser.spec.5 should support exit event', function (done) {
|
||||
iabInstance = cordova.InAppBrowser.open(url, '_blank');
|
||||
iabInstance.addEventListener('exit', function (evt) {
|
||||
verifyEvent(evt, 'exit');
|
||||
done();
|
||||
});
|
||||
iabInstance.close();
|
||||
iabInstance = null;
|
||||
});
|
||||
|
||||
it('inappbrowser.spec.6 should support loaderror event', function (done) {
|
||||
if (isBrowser) {
|
||||
// according to documentation, "loaderror" event is not supported on browser
|
||||
// https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1
|
||||
pending('Browser platform doesn\'t support loaderror event');
|
||||
function verifyEvent (evt, type) {
|
||||
expect(evt).toBeDefined();
|
||||
expect(evt.type).toEqual(type);
|
||||
// `exit` event does not have url field, browser returns null url for CORS requests
|
||||
if (type !== 'exit' && !isBrowser) {
|
||||
expect(evt.url).toEqual(url);
|
||||
}
|
||||
}
|
||||
iabInstance = cordova.InAppBrowser.open(badUrl, '_blank');
|
||||
iabInstance.addEventListener('loaderror', function (evt) {
|
||||
verifyLoadErrorEvent(evt);
|
||||
done();
|
||||
|
||||
function verifyLoadErrorEvent (evt) {
|
||||
expect(evt).toBeDefined();
|
||||
expect(evt.type).toEqual('loaderror');
|
||||
expect(evt.url).toEqual(badUrl);
|
||||
expect(evt.code).toEqual(jasmine.any(Number));
|
||||
expect(evt.message).toEqual(jasmine.any(String));
|
||||
}
|
||||
|
||||
it('inappbrowser.spec.3 should return InAppBrowser instance with required methods', function () {
|
||||
iabInstance = cordova.InAppBrowser.open(url, '_blank', platformOpts);
|
||||
|
||||
expect(iabInstance).toBeDefined();
|
||||
|
||||
expect(iabInstance.addEventListener).toEqual(jasmine.any(Function));
|
||||
expect(iabInstance.removeEventListener).toEqual(jasmine.any(Function));
|
||||
expect(iabInstance.close).toEqual(jasmine.any(Function));
|
||||
expect(iabInstance.show).toEqual(jasmine.any(Function));
|
||||
expect(iabInstance.hide).toEqual(jasmine.any(Function));
|
||||
expect(iabInstance.executeScript).toEqual(jasmine.any(Function));
|
||||
expect(iabInstance.insertCSS).toEqual(jasmine.any(Function));
|
||||
});
|
||||
|
||||
it('inappbrowser.spec.4 should support loadstart and loadstop events', function (done) {
|
||||
var onLoadStart = jasmine.createSpy('loadstart event callback').and.callFake(function (evt) {
|
||||
verifyEvent(evt, 'loadstart');
|
||||
});
|
||||
|
||||
iabInstance = cordova.InAppBrowser.open(url, '_blank', platformOpts);
|
||||
iabInstance.addEventListener('loadstart', onLoadStart);
|
||||
iabInstance.addEventListener('loadstop', function (evt) {
|
||||
verifyEvent(evt, 'loadstop');
|
||||
if (!isBrowser) {
|
||||
// according to documentation, "loadstart" event is not supported on browser
|
||||
// https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1
|
||||
expect(onLoadStart).toHaveBeenCalled();
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('inappbrowser.spec.5 should support exit event', function (done) {
|
||||
iabInstance = cordova.InAppBrowser.open(url, '_blank', platformOpts);
|
||||
iabInstance.addEventListener('exit', function (evt) {
|
||||
verifyEvent(evt, 'exit');
|
||||
done();
|
||||
});
|
||||
iabInstance.close();
|
||||
iabInstance = null;
|
||||
});
|
||||
|
||||
it('inappbrowser.spec.6 should support loaderror event', function (done) {
|
||||
if (isBrowser) {
|
||||
// according to documentation, "loaderror" event is not supported on browser
|
||||
// https://github.com/apache/cordova-plugin-inappbrowser#browser-quirks-1
|
||||
pending('Browser platform doesn\'t support loaderror event');
|
||||
}
|
||||
iabInstance = cordova.InAppBrowser.open(badUrl, '_blank', platformOpts);
|
||||
iabInstance.addEventListener('loaderror', function (evt) {
|
||||
verifyLoadErrorEvent(evt);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
if (isIos) {
|
||||
createTests('usewkwebview=no');
|
||||
createTests('usewkwebview=yes');
|
||||
} else {
|
||||
createTests();
|
||||
}
|
||||
};
|
||||
|
||||
exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
@ -161,6 +173,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
var counts;
|
||||
var lastLoadStartURL;
|
||||
var wasReset = false;
|
||||
|
||||
function reset () {
|
||||
counts = {
|
||||
'loaderror': 0,
|
||||
@ -170,6 +183,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
};
|
||||
lastLoadStartURL = '';
|
||||
}
|
||||
|
||||
reset();
|
||||
|
||||
var iab;
|
||||
@ -183,6 +197,9 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
console.log('Use window.open() for url');
|
||||
iab = window.open(url, target, params, callbacks);
|
||||
} else {
|
||||
if (platformOpts) {
|
||||
params += (params ? ',' : '') + platformOpts;
|
||||
}
|
||||
iab = cordova.InAppBrowser.open(url, target, params, callbacks);
|
||||
}
|
||||
if (!iab) {
|
||||
@ -260,11 +277,11 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
};
|
||||
if (cssUrl) {
|
||||
iab.addEventListener('loadstop', function (event) {
|
||||
iab.insertCSS({ file: cssUrl }, useCallback && callback);
|
||||
iab.insertCSS({file: cssUrl}, useCallback && callback);
|
||||
});
|
||||
} else {
|
||||
iab.addEventListener('loadstop', function (event) {
|
||||
iab.insertCSS({ code: '#style-update-literal { \ndisplay: block !important; \n}' },
|
||||
iab.insertCSS({code: '#style-update-literal { \ndisplay: block !important; \n}'},
|
||||
useCallback && callback);
|
||||
});
|
||||
}
|
||||
@ -274,7 +291,7 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
var iab = doOpen(url, '_blank', 'location=yes');
|
||||
if (jsUrl) {
|
||||
iab.addEventListener('loadstop', function (event) {
|
||||
iab.executeScript({ file: jsUrl }, useCallback && function (results) {
|
||||
iab.executeScript({file: jsUrl}, useCallback && function (results) {
|
||||
if (results && results.length === 0) {
|
||||
alert('Results verified'); // eslint-disable-line no-undef
|
||||
} else {
|
||||
@ -286,11 +303,11 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
} else {
|
||||
iab.addEventListener('loadstop', function (event) {
|
||||
var code = '(function(){\n' +
|
||||
' var header = document.getElementById("header");\n' +
|
||||
' header.innerHTML = "Script literal successfully injected";\n' +
|
||||
' return "abc";\n' +
|
||||
'})()';
|
||||
iab.executeScript({ code: code }, useCallback && function (results) {
|
||||
' var header = document.getElementById("header");\n' +
|
||||
' header.innerHTML = "Script literal successfully injected";\n' +
|
||||
' return "abc";\n' +
|
||||
'})()';
|
||||
iab.executeScript({code: code}, useCallback && function (results) {
|
||||
if (results && results.length === 1 && results[0] === 'abc') {
|
||||
alert('Results verified'); // eslint-disable-line no-undef
|
||||
} else {
|
||||
@ -301,10 +318,16 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var hiddenwnd = null;
|
||||
var loadlistener = function (event) { alert('background window loaded '); }; // eslint-disable-line no-undef
|
||||
var loadlistener = function (event) {
|
||||
alert('background window loaded ');
|
||||
}; // eslint-disable-line no-undef
|
||||
function openHidden (url, startHidden) {
|
||||
var shopt = (startHidden) ? 'hidden=yes' : '';
|
||||
if (platformOpts) {
|
||||
shopt += (shopt ? ',' : '') + platformOpts;
|
||||
}
|
||||
hiddenwnd = cordova.InAppBrowser.open(url, 'random_string', shopt);
|
||||
if (!hiddenwnd) {
|
||||
alert('cordova.InAppBrowser.open returned ' + hiddenwnd); // eslint-disable-line no-undef
|
||||
@ -312,11 +335,13 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
}
|
||||
if (startHidden) hiddenwnd.addEventListener('loadstop', loadlistener);
|
||||
}
|
||||
|
||||
function showHidden () {
|
||||
if (hiddenwnd) {
|
||||
hiddenwnd.show();
|
||||
}
|
||||
}
|
||||
|
||||
function closeHidden () {
|
||||
if (hiddenwnd) {
|
||||
hiddenwnd.removeEventListener('loadstop', loadlistener);
|
||||
@ -333,6 +358,15 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
'<h4>User-Agent: <span id="user-agent"> </span></hr>' +
|
||||
'</div>';
|
||||
|
||||
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>';
|
||||
}
|
||||
|
||||
var local_tests = '<h1>Local URL</h1>' +
|
||||
'<div id="openLocal"></div>' +
|
||||
'Expected result: opens successfully in CordovaWebView.' +
|
||||
@ -471,11 +505,11 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
// see http://msdn.microsoft.com/en-us/library/windows/apps/hh465380.aspx#differences for details
|
||||
if (window.MSApp && window.MSApp.execUnsafeLocalFunction) {
|
||||
MSApp.execUnsafeLocalFunction(function () {
|
||||
contentEl.innerHTML = info_div + local_tests + white_listed_tests + non_white_listed_tests + page_with_redirects_tests + pdf_url_tests + invalid_url_tests +
|
||||
contentEl.innerHTML = info_div + platform_info + local_tests + white_listed_tests + non_white_listed_tests + page_with_redirects_tests + pdf_url_tests + invalid_url_tests +
|
||||
css_js_injection_tests + open_hidden_tests + clearing_cache_tests + video_tag_tests + local_with_anchor_tag_tests + hardwareback_tests;
|
||||
});
|
||||
} else {
|
||||
contentEl.innerHTML = info_div + local_tests + white_listed_tests + non_white_listed_tests + page_with_redirects_tests + pdf_url_tests + invalid_url_tests +
|
||||
contentEl.innerHTML = info_div + platform_info + local_tests + white_listed_tests + non_white_listed_tests + page_with_redirects_tests + pdf_url_tests + invalid_url_tests +
|
||||
css_js_injection_tests + open_hidden_tests + clearing_cache_tests + video_tag_tests + local_with_anchor_tag_tests + hardwareback_tests;
|
||||
}
|
||||
|
||||
@ -490,6 +524,22 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
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 () {
|
||||
doOpen(localhtml);
|
||||
@ -679,17 +729,17 @@ exports.defineManualTests = function (contentEl, createActionButton) {
|
||||
doOpen('http://cordova.apache.org', '_blank', 'hardwareback=no');
|
||||
}, 'openHardwareBackNo');
|
||||
createActionButton('no hardwareback -> hardwareback=no -> no hardwareback', function () {
|
||||
var ref = cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes');
|
||||
var ref = cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes' + (platformOpts ? ',' + platformOpts : ''));
|
||||
ref.addEventListener('loadstop', function () {
|
||||
ref.close();
|
||||
});
|
||||
ref.addEventListener('exit', function () {
|
||||
var ref2 = cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes,hardwareback=no');
|
||||
var ref2 = cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes,hardwareback=no' + (platformOpts ? ',' + platformOpts : ''));
|
||||
ref2.addEventListener('loadstop', function () {
|
||||
ref2.close();
|
||||
});
|
||||
ref2.addEventListener('exit', function () {
|
||||
cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes');
|
||||
cordova.InAppBrowser.open('https://google.com', '_blank', 'location=yes' + (platformOpts ? ',' + platformOpts : ''));
|
||||
});
|
||||
});
|
||||
}, 'openHardwareBackDefaultAfterNo');
|
||||
|
Loading…
Reference in New Issue
Block a user