Skip to content

Commit 04a5524

Browse files
author
Martin Bektchiev
authored
Merge pull request #2 from Telerik-Verified-Plugins/bektchiev/merge-1.1.1
Merge tag 1.1.1 from apache
2 parents aa5a9d5 + dc1031d commit 04a5524

File tree

12 files changed

+381
-83
lines changed

12 files changed

+381
-83
lines changed

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ Thanks!
1717

1818

1919
### Checklist
20-
- [ ] [ICLA](http://www.apache.org/licenses/icla.txt) has been signed and submitted to secretary@apache.org.
2120
- [ ] [Reported an issue](http://cordova.apache.org/contribute/issues.html) in the JIRA database
2221
- [ ] Commit message follows the format: "CB-3232: (android) Fix bug with resolving file paths", where CB-xxxx is the JIRA ID & "android" is the platform affected.
2322
- [ ] Added automated test coverage as appropriate for this change.

.travis.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
language: node_js
1+
osx_image: xcode7.3
2+
language: objective-c
23
sudo: false
3-
node_js:
4-
- "4.2"
4+
before_install:
5+
- npm cache clean -f
6+
- npm install -g n
7+
- n stable
8+
- node --version
9+
install:
10+
- npm install
11+
script:
12+
- npm test

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,14 @@ To test the development version:
4545
cordova platform add https://github.com/apache/cordova-ios.git#master
4646
cordova plugin add https://github.com/apache/cordova-plugin-wkwebview-engine.git#master
4747

48-
You also must have Xcode 7 (iOS 9 SDK) installed. Check your Xcode version by running:
48+
You also must have at least Xcode 7 (iOS 9 SDK) installed. Check your Xcode version by running:
4949

5050
xcode-select --print-path
5151

5252
Required Permissions
5353
-----------
54-
WKWebView may not fully launch (the deviceready event may not fire) unless if the following is included in config.xml:
54+
WKWebView may not fully launch (the deviceready event may not fire) unless if the following is included in config.xml. This should already be installed by Cordova in your platform config.xml when the plugin is installed.
55+
5556
#### config.xml
5657

5758
<feature name="CDVWKWebViewEngine">
@@ -71,7 +72,9 @@ We have an [experimental plugin](https://github.com/apache/cordova-plugins/tree/
7172
Application Transport Security (ATS) in iOS 9
7273
-----------
7374

74-
The next released version of the [cordova-cli 5.4.0](https://www.npmjs.com/package/cordova) will support automatic conversion of the [&lt;access&gt;](http://cordova.apache.org/docs/en/edge/guide/appdev/whitelist/index.html) tags in config.xml to Application Transport Security [ATS](https://developer.apple.com/library/prerelease/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW33) directives. Upgrade to the version 5.4.0 to use this new functionality.
75+
Starting with [cordova-cli 5.4.0](https://www.npmjs.com/package/cordova), it will support automatic conversion of the [&lt;access&gt;](http://cordova.apache.org/docs/en/edge/guide/appdev/whitelist/index.html) tags in config.xml to Application Transport Security [ATS](https://developer.apple.com/library/prerelease/ios/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW33) directives.
76+
77+
Upgrade to at least version 5.4.0 of the cordova-cli to use this new functionality.
7578

7679
Limitations
7780
--------

RELEASENOTES.md

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,34 @@
2121

2222
# Release Notes
2323

24+
### 1.1.1 (Dec 07, 2016)
25+
* Updated README.md
26+
* added check for at least iOS 9.0
27+
* CB-10228:(iOS) AppendUserAgent not working with WKWebView
28+
* [CB-11997](https://issues.apache.org/jira/browse/CB-11997) Code review comments
29+
* [CB-11997](https://issues.apache.org/jira/browse/CB-11997) Add crash recovery for iOS 8
30+
* [CB-11917](https://issues.apache.org/jira/browse/CB-11917) - Remove pull request template checklist item: "iCLA has been submitted…"
31+
* [CB-11818](https://issues.apache.org/jira/browse/CB-11818) - Avoid retain cycle: WKUserContentController retains its message handler, to break it we cannot pass directly CDVWKWebViewEngine's instance
32+
* [CB-11832](https://issues.apache.org/jira/browse/CB-11832) Incremented plugin version.
33+
34+
### 1.1.0 (Sep 08, 2016)
35+
* [CB-11824](https://issues.apache.org/jira/browse/CB-11824) - Update tests to include objective-c tests
36+
* [CB-11554](https://issues.apache.org/jira/browse/CB-11554) - fixed unit tests
37+
* [CB-11815](https://issues.apache.org/jira/browse/CB-11815) (**iOS**) Fix hard-coded bridge name "cordova"
38+
* [CB-11554](https://issues.apache.org/jira/browse/CB-11554) - too 'brutal' app reload when title is empty
39+
* [CB-11074](https://issues.apache.org/jira/browse/CB-11074) - Ensure settings from `config.xml` are taken into consideration
40+
* Add ability to set the deceleration rate for the scrollview to 'fast'
41+
* [CB-11496](https://issues.apache.org/jira/browse/CB-11496) - Add obj-c unit tests for `WKWebViewConfiguration`, `WKPreference`
42+
* [CB-11496](https://issues.apache.org/jira/browse/CB-11496) - Create Obj-C unit-tests for `wkwebview-engine` (fix linker error)
43+
* [CB-11452](https://issues.apache.org/jira/browse/CB-11452) - Update README.md with latest news about `AllowInlineMediaPlayback` fix
44+
* [CB-9888](https://issues.apache.org/jira/browse/CB-9888) (**iOS**) check & reload `WKWebView`
45+
* [CB-11375](https://issues.apache.org/jira/browse/CB-11375) - `onReset` method of `CDVPlugin` is never called
46+
* Add pull request template.
47+
* [CB-10818](https://issues.apache.org/jira/browse/CB-10818) - Support the scroll deceleration speed preference.
48+
* [CB-10817](https://issues.apache.org/jira/browse/CB-10817) - Will now reload the `webView` if a crash occurs
49+
2450
### 1.0.3 (Apr 15, 2016)
25-
* CB-10636 Add `JSHint` for plugins
51+
* [CB-10636](https://issues.apache.org/jira/browse/CB-10636) Add `JSHint` for plugins
2652

2753
### 1.0.2 (Feb 09, 2016)
2854
* [CB-10269](https://issues.apache.org/jira/browse/CB-10269) - Replace cordova exec only when present in wkwebview
@@ -31,22 +57,22 @@
3157

3258
### 1.0.1 (Dec 11, 2015)
3359

34-
* CB-10190 - WKWebView engine is not releasing the user-agent lock
60+
* [CB-10190](https://issues.apache.org/jira/browse/CB-10190) - WKWebView engine is not releasing the user-agent lock
3561

3662
### 1.0.0 (Dec 04, 2015)
3763

38-
* CB-10146 - Add to README WKWebViewEngine quirks that will affect migration from UIWebView
39-
* CB-10133 - DataClone DOM Exception 25 thrown for postMessage
40-
* CB-10106 - added bridge proxy
41-
* CB-10107 - nativeEvalAndFetch called for all bridges
42-
* CB-10106 - iOS bridges need to take into account bridge changes
43-
* CB-10073 - WKWebViewEngine should post CDVPluginResetNotification
44-
* CB-10035 Updated RELEASENOTES to be newest to oldest
45-
* CB-10002 - WKWebView should propagate shouldOverrideLoadWithRequest to plugins
46-
* CB-9979 CB-9972 Change ATS link to new link
47-
* CB-9636 - Plugin should detect at runtime iOS 8 and use of file:// url and present an error
48-
* CB-8839 - WKWebView ignores DisallowOverscroll preference
49-
* CB-8556 - fix handleOpenURL for WKWebViewEngine plugin
50-
* CB-8666 - Update CDVWKWebViewEngine plugin to use 4.0.x branch code
64+
* [CB-10146](https://issues.apache.org/jira/browse/CB-10146) - Add to README WKWebViewEngine quirks that will affect migration from UIWebView
65+
* [CB-10133](https://issues.apache.org/jira/browse/CB-10133) - DataClone DOM Exception 25 thrown for postMessage
66+
* [CB-10106](https://issues.apache.org/jira/browse/CB-10106) - added bridge proxy
67+
* [CB-10107](https://issues.apache.org/jira/browse/CB-10107) - nativeEvalAndFetch called for all bridges
68+
* [CB-10106](https://issues.apache.org/jira/browse/CB-10106) - iOS bridges need to take into account bridge changes
69+
* [CB-10073](https://issues.apache.org/jira/browse/CB-10073) - WKWebViewEngine should post CDVPluginResetNotification
70+
* [CB-10035](https://issues.apache.org/jira/browse/CB-10035) Updated RELEASENOTES to be newest to oldest
71+
* [CB-10002](https://issues.apache.org/jira/browse/CB-10002) - WKWebView should propagate shouldOverrideLoadWithRequest to plugins
72+
* [CB-9979](https://issues.apache.org/jira/browse/CB-9979) [CB-9972](https://issues.apache.org/jira/browse/CB-9972) Change ATS link to new link
73+
* [CB-9636](https://issues.apache.org/jira/browse/CB-9636) - Plugin should detect at runtime iOS 8 and use of file:// url and present an error
74+
* [CB-8839](https://issues.apache.org/jira/browse/CB-8839) - WKWebView ignores DisallowOverscroll preference
75+
* [CB-8556](https://issues.apache.org/jira/browse/CB-8556) - fix handleOpenURL for WKWebViewEngine plugin
76+
* [CB-8666](https://issues.apache.org/jira/browse/CB-8666) - Update CDVWKWebViewEngine plugin to use 4.0.x branch code
5177

5278

package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
{
22
"name": "cordova-plugin-wkwebview-engine",
3-
"version": "1.0.4-dev",
3+
"version": "1.1.1",
44
"description": "The official Apache Cordova WKWebView Engine Plugin",
55
"main": "index.js",
6-
"scripts": {
7-
"test": "echo \"Error: no test specified\" && exit 1"
8-
},
96
"repository": {
107
"type": "git",
118
"url": "https://git-wip-us.apache.org/repos/asf/cordova-plugin-wkwebview-engine.git"
@@ -15,8 +12,10 @@
1512
"wkwebview"
1613
],
1714
"scripts": {
18-
"test": "npm run jshint",
19-
"jshint": "node node_modules/jshint/bin/jshint src"
15+
"test": "npm run jshint && npm run objc-tests",
16+
"objc-tests": "cd tests/ios && npm test",
17+
"preobjc-tests": "cd tests/ios && npm install",
18+
"jshint": "node_modules/.bin/jshint src"
2019
},
2120
"author": "Apache Cordova",
2221
"license": "Apache-2.0",

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
xmlns:rim="http://www.blackberry.com/ns/widgets"
2424
xmlns:android="http://schemas.android.com/apk/res/android"
2525
id="cordova-plugin-wkwebview-engine"
26-
version="1.0.4-dev">
26+
version="1.1.1">
2727
<name>Cordova WKWebView Engine</name>
2828
<description>Cordova WKWebView Engine Plugin</description>
2929
<license>Apache 2.0</license>

src/ios/CDVWKWebViewEngine.m

Lines changed: 117 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,20 @@ Licensed to the Apache Software Foundation (ASF) under one
2626
#define CDV_BRIDGE_NAME @"cordova"
2727
#define CDV_WKWEBVIEW_FILE_URL_LOAD_SELECTOR @"loadFileURL:allowingReadAccessToURL:"
2828

29+
@interface CDVWKWeakScriptMessageHandler : NSObject <WKScriptMessageHandler>
30+
31+
@property (nonatomic, weak, readonly) id<WKScriptMessageHandler>scriptMessageHandler;
32+
33+
- (instancetype)initWithScriptMessageHandler:(id<WKScriptMessageHandler>)scriptMessageHandler;
34+
35+
@end
36+
37+
2938
@interface CDVWKWebViewEngine ()
3039

3140
@property (nonatomic, strong, readwrite) UIView* engineWebView;
3241
@property (nonatomic, strong, readwrite) id <WKUIDelegate> uiDelegate;
42+
@property (nonatomic, weak) id <WKScriptMessageHandler> weakScriptMessageHandler;
3343

3444
@end
3545

@@ -47,31 +57,51 @@ - (instancetype)initWithFrame:(CGRect)frame
4757
if (NSClassFromString(@"WKWebView") == nil) {
4858
return nil;
4959
}
50-
self.uiDelegate = [[CDVWKWebViewUIDelegate alloc] initWithTitle:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]];
51-
52-
WKUserContentController* userContentController = [[WKUserContentController alloc] init];
53-
[userContentController addScriptMessageHandler:self name:CDV_BRIDGE_NAME];
54-
55-
WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init];
56-
configuration.userContentController = userContentController;
5760

58-
WKWebView* wkWebView = [[WKWebView alloc] initWithFrame:frame configuration:configuration];
59-
60-
wkWebView.UIDelegate = self.uiDelegate;
61+
self.engineWebView = [[WKWebView alloc] initWithFrame:frame];
62+
}
6163

62-
self.engineWebView = wkWebView;
64+
return self;
65+
}
6366

64-
NSLog(@"Using WKWebView");
67+
- (WKWebViewConfiguration*) createConfigurationFromSettings:(NSDictionary*)settings
68+
{
69+
WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init];
70+
if (settings == nil) {
71+
return configuration;
6572
}
6673

67-
return self;
74+
configuration.allowsInlineMediaPlayback = [settings cordovaBoolSettingForKey:@"AllowInlineMediaPlayback" defaultValue:NO];
75+
configuration.mediaPlaybackRequiresUserAction = [settings cordovaBoolSettingForKey:@"MediaPlaybackRequiresUserAction" defaultValue:YES];
76+
configuration.suppressesIncrementalRendering = [settings cordovaBoolSettingForKey:@"SuppressesIncrementalRendering" defaultValue:NO];
77+
configuration.mediaPlaybackAllowsAirPlay = [settings cordovaBoolSettingForKey:@"MediaPlaybackAllowsAirPlay" defaultValue:YES];
78+
79+
return configuration;
6880
}
6981

7082
- (void)pluginInitialize
7183
{
7284
// viewController would be available now. we attempt to set all possible delegates to it, by default
85+
NSDictionary* settings = self.commandDelegate.settings;
7386

74-
WKWebView* wkWebView = (WKWebView*)_engineWebView;
87+
self.uiDelegate = [[CDVWKWebViewUIDelegate alloc] initWithTitle:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]];
88+
89+
CDVWKWeakScriptMessageHandler *weakScriptMessageHandler = [[CDVWKWeakScriptMessageHandler alloc] initWithScriptMessageHandler:self];
90+
91+
WKUserContentController* userContentController = [[WKUserContentController alloc] init];
92+
[userContentController addScriptMessageHandler:weakScriptMessageHandler name:CDV_BRIDGE_NAME];
93+
94+
WKWebViewConfiguration* configuration = [self createConfigurationFromSettings:settings];
95+
configuration.userContentController = userContentController;
96+
97+
// re-create WKWebView, since we need to update configuration
98+
WKWebView* wkWebView = [[WKWebView alloc] initWithFrame:self.engineWebView.frame configuration:configuration];
99+
wkWebView.UIDelegate = self.uiDelegate;
100+
self.engineWebView = wkWebView;
101+
102+
if (IsAtLeastiOSVersion(@"9.0") && [self.viewController isKindOfClass:[CDVViewController class]]) {
103+
wkWebView.customUserAgent = ((CDVViewController*) self.viewController).userAgent;
104+
}
75105

76106
if ([self.viewController conformsToProtocol:@protocol(WKUIDelegate)]) {
77107
wkWebView.UIDelegate = (id <WKUIDelegate>)self.viewController;
@@ -84,42 +114,78 @@ - (void)pluginInitialize
84114
}
85115

86116
if ([self.viewController conformsToProtocol:@protocol(WKScriptMessageHandler)]) {
87-
[wkWebView.configuration.userContentController addScriptMessageHandler:(id < WKScriptMessageHandler >)self.viewController name:@"cordova"];
117+
[wkWebView.configuration.userContentController addScriptMessageHandler:(id < WKScriptMessageHandler >)self.viewController name:CDV_BRIDGE_NAME];
88118
}
89119

90-
[self updateSettings:self.commandDelegate.settings];
120+
[self updateSettings:settings];
91121

92122
// check if content thread has died on resume
93123
NSLog(@"%@", @"CDVWKWebViewEngine will reload WKWebView if required on resume");
94124
[[NSNotificationCenter defaultCenter]
95125
addObserver:self
96126
selector:@selector(onAppWillEnterForeground:)
97127
name:UIApplicationWillEnterForegroundNotification object:nil];
128+
129+
NSLog(@"Using WKWebView");
130+
131+
[self addURLObserver];
132+
}
133+
134+
- (void)onReset {
135+
[self addURLObserver];
136+
}
137+
138+
static void * KVOContext = &KVOContext;
139+
140+
- (void)addURLObserver {
141+
if(!IsAtLeastiOSVersion(@"9.0")){
142+
[self.webView addObserver:self forKeyPath:@"URL" options:0 context:KVOContext];
143+
}
144+
}
145+
146+
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context
147+
{
148+
if (context == KVOContext) {
149+
if (object == [self webView] && [keyPath isEqualToString: @"URL"] && [object valueForKeyPath:keyPath] == nil){
150+
NSLog(@"URL is nil. Reloading WKWebView");
151+
[(WKWebView*)_engineWebView reload];
152+
}
153+
} else {
154+
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
155+
}
98156
}
99157

100158
- (void) onAppWillEnterForeground:(NSNotification*)notification {
101-
[self reloadIfRequired];
159+
if ([self shouldReloadWebView]) {
160+
NSLog(@"%@", @"CDVWKWebViewEngine reloading!");
161+
[(WKWebView*)_engineWebView reload];
162+
}
102163
}
103164

104-
- (BOOL)reloadIfRequired
165+
- (BOOL)shouldReloadWebView
105166
{
106167
WKWebView* wkWebView = (WKWebView*)_engineWebView;
107-
NSString* title = wkWebView.title;
108-
BOOL reload = ((title == nil) || [title isEqualToString:@""]);
168+
return [self shouldReloadWebView:wkWebView.URL title:wkWebView.title];
169+
}
109170

171+
- (BOOL)shouldReloadWebView:(NSURL*)location title:(NSString*)title
172+
{
173+
BOOL title_is_nil = (title == nil);
174+
BOOL location_is_blank = [[location absoluteString] isEqualToString:@"about:blank"];
175+
176+
BOOL reload = (title_is_nil || location_is_blank);
177+
110178
#ifdef DEBUG
111-
NSLog(@"%@", @"CDVWKWebViewEngine reloadIfRequired");
112-
NSLog(@"CDVWKWebViewEngine reloadIfRequired WKWebView.title: %@", title);
113-
NSLog(@"CDVWKWebViewEngine reloadIfRequired reload: %u", reload);
179+
NSLog(@"%@", @"CDVWKWebViewEngine shouldReloadWebView::");
180+
NSLog(@"CDVWKWebViewEngine shouldReloadWebView title: %@", title);
181+
NSLog(@"CDVWKWebViewEngine shouldReloadWebView location: %@", [location absoluteString]);
182+
NSLog(@"CDVWKWebViewEngine shouldReloadWebView reload: %u", reload);
114183
#endif
115-
116-
if (reload) {
117-
NSLog(@"%@", @"CDVWKWebViewEngine reloading!");
118-
[wkWebView reload];
119-
}
184+
120185
return reload;
121186
}
122187

188+
123189
- (id)loadRequest:(NSURLRequest*)request
124190
{
125191
if ([self canLoadRequest:request]) { // can load, differentiate between file urls and other schemes
@@ -174,10 +240,6 @@ - (void)updateSettings:(NSDictionary*)settings
174240
WKWebView* wkWebView = (WKWebView*)_engineWebView;
175241

176242
wkWebView.configuration.preferences.minimumFontSize = [settings cordovaFloatSettingForKey:@"MinimumFontSize" defaultValue:0.0];
177-
wkWebView.configuration.allowsInlineMediaPlayback = [settings cordovaBoolSettingForKey:@"AllowInlineMediaPlayback" defaultValue:NO];
178-
wkWebView.configuration.mediaPlaybackRequiresUserAction = [settings cordovaBoolSettingForKey:@"MediaPlaybackRequiresUserAction" defaultValue:YES];
179-
wkWebView.configuration.suppressesIncrementalRendering = [settings cordovaBoolSettingForKey:@"SuppressesIncrementalRendering" defaultValue:NO];
180-
wkWebView.configuration.mediaPlaybackAllowsAirPlay = [settings cordovaBoolSettingForKey:@"MediaPlaybackAllowsAirPlay" defaultValue:YES];
181243

182244
/*
183245
wkWebView.configuration.preferences.javaScriptEnabled = [settings cordovaBoolSettingForKey:@"JavaScriptEnabled" default:YES];
@@ -208,6 +270,8 @@ - (void)updateSettings:(NSDictionary*)settings
208270

209271
if (![@"fast" isEqualToString:decelerationSetting]) {
210272
[wkWebView.scrollView setDecelerationRate:UIScrollViewDecelerationRateNormal];
273+
} else {
274+
[wkWebView.scrollView setDecelerationRate:UIScrollViewDecelerationRateFast];
211275
}
212276
}
213277

@@ -379,4 +443,25 @@ - (void) webView: (WKWebView *) webView decidePolicyForNavigationAction: (WKNavi
379443

380444
return decisionHandler(NO);
381445
}
446+
447+
@end
448+
449+
#pragma mark - CDVWKWeakScriptMessageHandler
450+
451+
@implementation CDVWKWeakScriptMessageHandler
452+
453+
- (instancetype)initWithScriptMessageHandler:(id<WKScriptMessageHandler>)scriptMessageHandler
454+
{
455+
self = [super init];
456+
if (self) {
457+
_scriptMessageHandler = scriptMessageHandler;
458+
}
459+
return self;
460+
}
461+
462+
- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message
463+
{
464+
[self.scriptMessageHandler userContentController:userContentController didReceiveScriptMessage:message];
465+
}
466+
382467
@end

0 commit comments

Comments
 (0)