From c0a10b72c00d44eae4e5a5af90c7abfdfa153881 Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Thu, 4 Aug 2016 15:47:59 -0700 Subject: [PATCH 01/17] CB-11496 - Add obj-c unit tests for WKWebViewConfiguration, WKPreference --- .../CDVWKWebViewEngineTest.m | 70 +++++++++++++++++-- .../project.pbxproj | 2 + 2 files changed, 67 insertions(+), 5 deletions(-) diff --git a/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineLibTests/CDVWKWebViewEngineTest.m b/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineLibTests/CDVWKWebViewEngineTest.m index 73b5b0a..af736b8 100644 --- a/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineLibTests/CDVWKWebViewEngineTest.m +++ b/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineLibTests/CDVWKWebViewEngineTest.m @@ -20,10 +20,12 @@ Licensed to the Apache Software Foundation (ASF) under one #import #import #import "CDVWKWebViewEngine.h" +#import @interface CDVWKWebViewEngineTest : XCTestCase @property (nonatomic, strong) CDVWKWebViewEngine* plugin; +@property (nonatomic, strong) CDVViewController* viewController; @end @@ -39,7 +41,11 @@ - (void)setUp { [super setUp]; // Put setup code here. This method is called before the invocation of each test method in the class. - self.plugin = [[CDVWKWebViewEngine alloc] init]; + self.plugin = [[CDVWKWebViewEngine alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; + self.viewController = [[CDVViewController alloc] init]; + [self.viewController registerPlugin:self.plugin withClassName:NSStringFromClass([self.plugin class])]; + + XCTAssert([self.plugin conformsToProtocol:@protocol(CDVWebViewEngineProtocol)], @"Plugin does not conform to CDVWebViewEngineProtocol"); } - (void)tearDown { @@ -47,11 +53,65 @@ - (void)tearDown { [super tearDown]; } -- (void) testCDVWKWebViewEngine { +- (void) testCanLoadRequest { + NSURLRequest* fileUrlRequest = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:@"path/to/file.html"]]; + NSURLRequest* httpUrlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://apache.org"]]; + NSURLRequest* miscUrlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"foo://bar"]]; + id webViewEngineProtocol = self.plugin; + + SEL wk_sel = NSSelectorFromString(@"loadFileURL:allowingReadAccessToURL:"); + if ([self.plugin.engineWebView respondsToSelector:wk_sel]) { + XCTAssertTrue([webViewEngineProtocol canLoadRequest:fileUrlRequest]); + } else { + XCTAssertFalse([webViewEngineProtocol canLoadRequest:fileUrlRequest]); + } + + XCTAssertTrue([webViewEngineProtocol canLoadRequest:httpUrlRequest]); + XCTAssertTrue([webViewEngineProtocol canLoadRequest:miscUrlRequest]); +} + +- (void) testUpdateInfo { + // Add -ObjC to Other Linker Flags to test project, to load Categories + // Update objc test template generator as well + + id webViewEngineProtocol = self.plugin; + WKWebView* wkWebView = (WKWebView*)self.plugin.engineWebView; + + NSDictionary* preferences = @{ + [@"MinimumFontSize" lowercaseString] : @1.1, // default is 0.0 + [@"AllowInlineMediaPlayback" lowercaseString] : @YES, // default is NO + [@"MediaPlaybackRequiresUserAction" lowercaseString] : @NO, // default is YES + [@"SuppressesIncrementalRendering" lowercaseString] : @YES, // default is NO + [@"MediaPlaybackAllowsAirPlay" lowercaseString] : @NO, // default is YES + [@"DisallowOverscroll" lowercaseString] : @YES, // so bounces is to be NO. defaults to NO + [@"WKWebViewDecelerationSpeed" lowercaseString] : @"fast" // default is 'normal' + }; + NSDictionary* info = @{ + kCDVWebViewEngineWebViewPreferences : preferences + }; + [webViewEngineProtocol updateWithInfo:info]; + + // the only preference we can set, we **can** change this during runtime + XCTAssertEqualWithAccuracy(wkWebView.configuration.preferences.minimumFontSize, 1.1, 0.0001); + + // the WKWebViewConfiguration properties, we **cannot** change outside of initialization + XCTAssertFalse(wkWebView.configuration.allowsInlineMediaPlayback); + XCTAssertTrue(wkWebView.configuration.mediaPlaybackRequiresUserAction); + XCTAssertFalse(wkWebView.configuration.suppressesIncrementalRendering); + XCTAssertTrue(wkWebView.configuration.mediaPlaybackAllowsAirPlay); + + // in the test above, DisallowOverscroll is YES, so no bounce + if ([wkWebView respondsToSelector:@selector(scrollView)]) { + XCTAssertFalse(((UIScrollView*)[wkWebView scrollView]).bounces); + } else { + for (id subview in wkWebView.subviews) { + if ([[subview class] isSubclassOfClass:[UIScrollView class]]) { + XCTAssertFalse(((UIScrollView*)subview).bounces = NO); + } + } + } - // Failing tests - XCTAssertTrue(NO); - XCTAssertFalse(YES); + XCTAssertTrue(wkWebView.scrollView.decelerationRate == UIScrollViewDecelerationRateFast); } @end diff --git a/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineTest.xcodeproj/project.pbxproj b/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineTest.xcodeproj/project.pbxproj index caa1c1e..74436bd 100644 --- a/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineTest.xcodeproj/project.pbxproj +++ b/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineTest.xcodeproj/project.pbxproj @@ -285,12 +285,14 @@ 7E9F517619DA09CE00DA31AC /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + OTHER_LDFLAGS = "-ObjC"; }; name = Debug; }; 7E9F517719DA09CE00DA31AC /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + OTHER_LDFLAGS = "-ObjC"; }; name = Release; }; From dce192abdf24d631a37e1ace9fe5b72b44c74ecf Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Thu, 4 Aug 2016 15:48:44 -0700 Subject: [PATCH 02/17] Add ability to set the deceleration rate for the scrollview to 'fast' --- src/ios/CDVWKWebViewEngine.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ios/CDVWKWebViewEngine.m b/src/ios/CDVWKWebViewEngine.m index 9224e31..bd1d8fb 100644 --- a/src/ios/CDVWKWebViewEngine.m +++ b/src/ios/CDVWKWebViewEngine.m @@ -208,6 +208,8 @@ - (void)updateSettings:(NSDictionary*)settings if (![@"fast" isEqualToString:decelerationSetting]) { [wkWebView.scrollView setDecelerationRate:UIScrollViewDecelerationRateNormal]; + } else { + [wkWebView.scrollView setDecelerationRate:UIScrollViewDecelerationRateFast]; } } From 42c847b2680a80e52ffd3617119ddd6634751453 Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Thu, 4 Aug 2016 15:47:59 -0700 Subject: [PATCH 03/17] CB-11074 - Ensure settings from config.xml are taken into consideration Note that there is a skipped unit test "testConfigurationWithMediaPlaybackAllowsAirPlay", which deals with an Apple bug in setting the WKWebViewConfiguration.allowsAirPlayForMediaPlayback value. This closes #13, closes #7, closes #8 --- src/ios/CDVWKWebViewEngine.m | 50 +++++++---- .../CDVWKWebViewEngineTest.m | 87 ++++++++++++++++++- .../CDVWKWebViewEngineLibTests.xcscheme | 16 +++- 3 files changed, 128 insertions(+), 25 deletions(-) diff --git a/src/ios/CDVWKWebViewEngine.m b/src/ios/CDVWKWebViewEngine.m index bd1d8fb..70482a0 100644 --- a/src/ios/CDVWKWebViewEngine.m +++ b/src/ios/CDVWKWebViewEngine.m @@ -47,31 +47,45 @@ - (instancetype)initWithFrame:(CGRect)frame if (NSClassFromString(@"WKWebView") == nil) { return nil; } - self.uiDelegate = [[CDVWKWebViewUIDelegate alloc] initWithTitle:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]]; - WKUserContentController* userContentController = [[WKUserContentController alloc] init]; - [userContentController addScriptMessageHandler:self name:CDV_BRIDGE_NAME]; - - WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init]; - configuration.userContentController = userContentController; - - WKWebView* wkWebView = [[WKWebView alloc] initWithFrame:frame configuration:configuration]; - - wkWebView.UIDelegate = self.uiDelegate; + self.engineWebView = [[WKWebView alloc] initWithFrame:frame]; + } - self.engineWebView = wkWebView; + return self; +} - NSLog(@"Using WKWebView"); +- (WKWebViewConfiguration*) createConfigurationFromSettings:(NSDictionary*)settings +{ + WKWebViewConfiguration* configuration = [[WKWebViewConfiguration alloc] init]; + if (settings == nil) { + return configuration; } - return self; + configuration.allowsInlineMediaPlayback = [settings cordovaBoolSettingForKey:@"AllowInlineMediaPlayback" defaultValue:NO]; + configuration.mediaPlaybackRequiresUserAction = [settings cordovaBoolSettingForKey:@"MediaPlaybackRequiresUserAction" defaultValue:YES]; + configuration.suppressesIncrementalRendering = [settings cordovaBoolSettingForKey:@"SuppressesIncrementalRendering" defaultValue:NO]; + configuration.mediaPlaybackAllowsAirPlay = [settings cordovaBoolSettingForKey:@"MediaPlaybackAllowsAirPlay" defaultValue:YES]; + + return configuration; } - (void)pluginInitialize { // viewController would be available now. we attempt to set all possible delegates to it, by default + NSDictionary* settings = self.commandDelegate.settings; - WKWebView* wkWebView = (WKWebView*)_engineWebView; + self.uiDelegate = [[CDVWKWebViewUIDelegate alloc] initWithTitle:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]]; + + WKUserContentController* userContentController = [[WKUserContentController alloc] init]; + [userContentController addScriptMessageHandler:self name:CDV_BRIDGE_NAME]; + + WKWebViewConfiguration* configuration = [self createConfigurationFromSettings:settings]; + configuration.userContentController = userContentController; + + // re-create WKWebView, since we need to update configuration + WKWebView* wkWebView = [[WKWebView alloc] initWithFrame:self.engineWebView.frame configuration:configuration]; + wkWebView.UIDelegate = self.uiDelegate; + self.engineWebView = wkWebView; if ([self.viewController conformsToProtocol:@protocol(WKUIDelegate)]) { wkWebView.UIDelegate = (id )self.viewController; @@ -87,7 +101,7 @@ - (void)pluginInitialize [wkWebView.configuration.userContentController addScriptMessageHandler:(id < WKScriptMessageHandler >)self.viewController name:@"cordova"]; } - [self updateSettings:self.commandDelegate.settings]; + [self updateSettings:settings]; // check if content thread has died on resume NSLog(@"%@", @"CDVWKWebViewEngine will reload WKWebView if required on resume"); @@ -95,6 +109,8 @@ - (void)pluginInitialize addObserver:self selector:@selector(onAppWillEnterForeground:) name:UIApplicationWillEnterForegroundNotification object:nil]; + + NSLog(@"Using WKWebView"); } - (void) onAppWillEnterForeground:(NSNotification*)notification { @@ -174,10 +190,6 @@ - (void)updateSettings:(NSDictionary*)settings WKWebView* wkWebView = (WKWebView*)_engineWebView; wkWebView.configuration.preferences.minimumFontSize = [settings cordovaFloatSettingForKey:@"MinimumFontSize" defaultValue:0.0]; - wkWebView.configuration.allowsInlineMediaPlayback = [settings cordovaBoolSettingForKey:@"AllowInlineMediaPlayback" defaultValue:NO]; - wkWebView.configuration.mediaPlaybackRequiresUserAction = [settings cordovaBoolSettingForKey:@"MediaPlaybackRequiresUserAction" defaultValue:YES]; - wkWebView.configuration.suppressesIncrementalRendering = [settings cordovaBoolSettingForKey:@"SuppressesIncrementalRendering" defaultValue:NO]; - wkWebView.configuration.mediaPlaybackAllowsAirPlay = [settings cordovaBoolSettingForKey:@"MediaPlaybackAllowsAirPlay" defaultValue:YES]; /* wkWebView.configuration.preferences.javaScriptEnabled = [settings cordovaBoolSettingForKey:@"JavaScriptEnabled" default:YES]; diff --git a/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineLibTests/CDVWKWebViewEngineTest.m b/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineLibTests/CDVWKWebViewEngineTest.m index af736b8..6d9a907 100644 --- a/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineLibTests/CDVWKWebViewEngineTest.m +++ b/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineLibTests/CDVWKWebViewEngineTest.m @@ -21,6 +21,7 @@ Licensed to the Apache Software Foundation (ASF) under one #import #import "CDVWKWebViewEngine.h" #import +#import @interface CDVWKWebViewEngineTest : XCTestCase @@ -35,12 +36,20 @@ @interface CDVWKWebViewEngine () @end +@interface CDVViewController () + +// expose property as readwrite, for test purposes +@property (nonatomic, readwrite, strong) NSMutableDictionary* settings; + +@end + @implementation CDVWKWebViewEngineTest - (void)setUp { [super setUp]; // Put setup code here. This method is called before the invocation of each test method in the class. + // NOTE: no app settings are set, so it will rely on default WKWebViewConfiguration settings self.plugin = [[CDVWKWebViewEngine alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; self.viewController = [[CDVViewController alloc] init]; [self.viewController registerPlugin:self.plugin withClassName:NSStringFromClass([self.plugin class])]; @@ -77,10 +86,13 @@ - (void) testUpdateInfo { id webViewEngineProtocol = self.plugin; WKWebView* wkWebView = (WKWebView*)self.plugin.engineWebView; + // iOS >=10 defaults to NO, < 10 defaults to YES. + BOOL mediaPlaybackRequiresUserActionDefault = IsAtLeastiOSVersion(@"10.0")? NO : YES; + NSDictionary* preferences = @{ [@"MinimumFontSize" lowercaseString] : @1.1, // default is 0.0 [@"AllowInlineMediaPlayback" lowercaseString] : @YES, // default is NO - [@"MediaPlaybackRequiresUserAction" lowercaseString] : @NO, // default is YES + [@"MediaPlaybackRequiresUserAction" lowercaseString] : @(!mediaPlaybackRequiresUserActionDefault), // default is NO on iOS >= 10, YES for < 10 [@"SuppressesIncrementalRendering" lowercaseString] : @YES, // default is NO [@"MediaPlaybackAllowsAirPlay" lowercaseString] : @NO, // default is YES [@"DisallowOverscroll" lowercaseString] : @YES, // so bounces is to be NO. defaults to NO @@ -95,8 +107,12 @@ - (void) testUpdateInfo { XCTAssertEqualWithAccuracy(wkWebView.configuration.preferences.minimumFontSize, 1.1, 0.0001); // the WKWebViewConfiguration properties, we **cannot** change outside of initialization + if (IsAtLeastiOSVersion(@"10.0")) { + XCTAssertFalse(wkWebView.configuration.mediaPlaybackRequiresUserAction); + } else { + XCTAssertTrue(wkWebView.configuration.mediaPlaybackRequiresUserAction); + } XCTAssertFalse(wkWebView.configuration.allowsInlineMediaPlayback); - XCTAssertTrue(wkWebView.configuration.mediaPlaybackRequiresUserAction); XCTAssertFalse(wkWebView.configuration.suppressesIncrementalRendering); XCTAssertTrue(wkWebView.configuration.mediaPlaybackAllowsAirPlay); @@ -114,4 +130,71 @@ - (void) testUpdateInfo { XCTAssertTrue(wkWebView.scrollView.decelerationRate == UIScrollViewDecelerationRateFast); } +- (void) testConfigurationFromSettings { + // we need to re-set the plugin from the "setup" to take in the app settings we need + self.plugin = [[CDVWKWebViewEngine alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; + self.viewController = [[CDVViewController alloc] init]; + + // generate the app settings + // iOS >=10 defaults to NO, < 10 defaults to YES. + BOOL mediaPlaybackRequiresUserActionDefault = IsAtLeastiOSVersion(@"10.0")? NO : YES; + + NSDictionary* settings = @{ + [@"MinimumFontSize" lowercaseString] : @1.1, // default is 0.0 + [@"AllowInlineMediaPlayback" lowercaseString] : @YES, // default is NO + [@"MediaPlaybackRequiresUserAction" lowercaseString] : @(!mediaPlaybackRequiresUserActionDefault), // default is NO on iOS >= 10, YES for < 10 + [@"SuppressesIncrementalRendering" lowercaseString] : @YES, // default is NO + [@"MediaPlaybackAllowsAirPlay" lowercaseString] : @NO, // default is YES + [@"DisallowOverscroll" lowercaseString] : @YES, // so bounces is to be NO. defaults to NO + [@"WKWebViewDecelerationSpeed" lowercaseString] : @"fast" // default is 'normal' + }; + // this can be set because of the Category at the top of the file + self.viewController.settings = [settings mutableCopy]; + + // app settings are read after you register the plugin + [self.viewController registerPlugin:self.plugin withClassName:NSStringFromClass([self.plugin class])]; + XCTAssert([self.plugin conformsToProtocol:@protocol(CDVWebViewEngineProtocol)], @"Plugin does not conform to CDVWebViewEngineProtocol"); + + // after registering (thus plugin initialization), we can grab the webview configuration + WKWebView* wkWebView = (WKWebView*)self.plugin.engineWebView; + + // the only preference we can set, we **can** change this during runtime + XCTAssertEqualWithAccuracy(wkWebView.configuration.preferences.minimumFontSize, 1.1, 0.0001); + + // the WKWebViewConfiguration properties, we **cannot** change outside of initialization + if (IsAtLeastiOSVersion(@"10.0")) { + XCTAssertTrue(wkWebView.configuration.mediaPlaybackRequiresUserAction); + } else { + XCTAssertFalse(wkWebView.configuration.mediaPlaybackRequiresUserAction); + } + XCTAssertTrue(wkWebView.configuration.allowsInlineMediaPlayback); + XCTAssertTrue(wkWebView.configuration.suppressesIncrementalRendering); + // The test case below is in a separate test "testConfigurationWithMediaPlaybackAllowsAirPlay" (Apple bug) + // XCTAssertFalse(wkWebView.configuration.mediaPlaybackAllowsAirPlay); + + // in the test above, DisallowOverscroll is YES, so no bounce + if ([wkWebView respondsToSelector:@selector(scrollView)]) { + XCTAssertFalse(((UIScrollView*)[wkWebView scrollView]).bounces); + } else { + for (id subview in wkWebView.subviews) { + if ([[subview class] isSubclassOfClass:[UIScrollView class]]) { + XCTAssertFalse(((UIScrollView*)subview).bounces = NO); + } + } + } + + XCTAssertTrue(wkWebView.scrollView.decelerationRate == UIScrollViewDecelerationRateFast); +} + +- (void) testConfigurationWithMediaPlaybackAllowsAirPlay { + WKWebViewConfiguration* configuration = [WKWebViewConfiguration new]; + configuration.allowsAirPlayForMediaPlayback = NO; + + WKWebView* wkWebView = [[WKWebView alloc] initWithFrame:CGRectMake(0, 0, 100, 100) configuration:configuration]; + + XCTAssertFalse(configuration.allowsAirPlayForMediaPlayback); + // Uh-oh, bug in WKWebView below. Tested on iOS 9, iOS 10 beta 3 + XCTAssertFalse(wkWebView.configuration.allowsAirPlayForMediaPlayback); +} + @end diff --git a/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineTest.xcodeproj/xcshareddata/xcschemes/CDVWKWebViewEngineLibTests.xcscheme b/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineTest.xcodeproj/xcshareddata/xcschemes/CDVWKWebViewEngineLibTests.xcscheme index c002a4e..6fc153f 100644 --- a/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineTest.xcodeproj/xcshareddata/xcschemes/CDVWKWebViewEngineLibTests.xcscheme +++ b/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineTest.xcodeproj/xcshareddata/xcschemes/CDVWKWebViewEngineLibTests.xcscheme @@ -23,10 +23,10 @@ + shouldUseLaunchSchemeArgsEnv = "YES"> @@ -37,6 +37,11 @@ BlueprintName = "CDVWKWebViewEngineLibTests" ReferencedContainer = "container:CDVWKWebViewEngineTest.xcodeproj"> + + + + @@ -48,15 +53,18 @@ ReferencedContainer = "container:CDVWKWebViewEngineTest.xcodeproj"> + + Date: Fri, 26 Aug 2016 18:05:22 -0700 Subject: [PATCH 04/17] CB-11554 - too 'brutal' app reload when title is empty This closes #16 --- src/ios/CDVWKWebViewEngine.m | 32 +++++++++++------- .../CDVWKWebViewEngineTest.m | 33 +++++++++++++++++++ 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/src/ios/CDVWKWebViewEngine.m b/src/ios/CDVWKWebViewEngine.m index 70482a0..8039dcc 100644 --- a/src/ios/CDVWKWebViewEngine.m +++ b/src/ios/CDVWKWebViewEngine.m @@ -114,28 +114,36 @@ - (void)pluginInitialize } - (void) onAppWillEnterForeground:(NSNotification*)notification { - [self reloadIfRequired]; + if ([self shouldReloadWebView]) { + NSLog(@"%@", @"CDVWKWebViewEngine reloading!"); + [(WKWebView*)_engineWebView reload]; + } } -- (BOOL)reloadIfRequired +- (BOOL)shouldReloadWebView { WKWebView* wkWebView = (WKWebView*)_engineWebView; - NSString* title = wkWebView.title; - BOOL reload = ((title == nil) || [title isEqualToString:@""]); + return [self shouldReloadWebView:wkWebView.URL title:wkWebView.title]; +} +- (BOOL)shouldReloadWebView:(NSURL*)location title:(NSString*)title +{ + BOOL title_is_nil = (title == nil); + BOOL location_is_blank = [[location absoluteString] isEqualToString:@"about:blank"]; + + BOOL reload = (title_is_nil || location_is_blank); + #ifdef DEBUG - NSLog(@"%@", @"CDVWKWebViewEngine reloadIfRequired"); - NSLog(@"CDVWKWebViewEngine reloadIfRequired WKWebView.title: %@", title); - NSLog(@"CDVWKWebViewEngine reloadIfRequired reload: %u", reload); + NSLog(@"%@", @"CDVWKWebViewEngine shouldReloadWebView::"); + NSLog(@"CDVWKWebViewEngine shouldReloadWebView title: %@", title); + NSLog(@"CDVWKWebViewEngine shouldReloadWebView location: %@", [location absoluteString]); + NSLog(@"CDVWKWebViewEngine shouldReloadWebView reload: %u", reload); #endif - - if (reload) { - NSLog(@"%@", @"CDVWKWebViewEngine reloading!"); - [wkWebView reload]; - } + return reload; } + - (id)loadRequest:(NSURLRequest*)request { if ([self canLoadRequest:request]) { // can load, differentiate between file urls and other schemes diff --git a/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineLibTests/CDVWKWebViewEngineTest.m b/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineLibTests/CDVWKWebViewEngineTest.m index 6d9a907..d306b79 100644 --- a/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineLibTests/CDVWKWebViewEngineTest.m +++ b/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineLibTests/CDVWKWebViewEngineTest.m @@ -33,6 +33,8 @@ @interface CDVWKWebViewEngineTest : XCTestCase @interface CDVWKWebViewEngine () // TODO: expose private interface, if needed +- (BOOL)shouldReloadWebView; +- (BOOL)shouldReloadWebView:(NSURL*)location title:(NSString*)title; @end @@ -186,6 +188,37 @@ - (void) testConfigurationFromSettings { XCTAssertTrue(wkWebView.scrollView.decelerationRate == UIScrollViewDecelerationRateFast); } +- (void) testShouldReloadWebView { + WKWebView* wkWebView = (WKWebView*)self.plugin.engineWebView; + + NSURL* about_blank = [NSURL URLWithString:@"about:blank"]; + NSURL* real_site = [NSURL URLWithString:@"https://cordova.apache.org"]; + NSString* empty_title_document = @""; + + // about:blank should reload + [wkWebView loadRequest:[NSURLRequest requestWithURL:about_blank]]; + XCTAssertTrue([self.plugin shouldReloadWebView]); + + // a network location should *not* reload + [wkWebView loadRequest:[NSURLRequest requestWithURL:real_site]]; + XCTAssertFalse([self.plugin shouldReloadWebView]); + + // document with empty title should *not* reload + [wkWebView loadHTMLString:empty_title_document baseURL:nil]; + XCTAssertFalse([self.plugin shouldReloadWebView]); + + // Anecdotal assertion that when the WKWebView process has died, + // the title is nil, should always reload + XCTAssertTrue([self.plugin shouldReloadWebView:about_blank title:nil]); + XCTAssertTrue([self.plugin shouldReloadWebView:real_site title:nil]); + + // about:blank should always reload + XCTAssertTrue([self.plugin shouldReloadWebView:about_blank title:@"some title"]); + + // non about:blank with a non-nil title should **not** reload + XCTAssertFalse([self.plugin shouldReloadWebView:real_site title:@""]); +} + - (void) testConfigurationWithMediaPlaybackAllowsAirPlay { WKWebViewConfiguration* configuration = [WKWebViewConfiguration new]; configuration.allowsAirPlayForMediaPlayback = NO; From a4f3e8848508ea8e12e03e168f6cf398400ede1c Mon Sep 17 00:00:00 2001 From: Luca Torella Date: Wed, 7 Sep 2016 09:35:52 +0200 Subject: [PATCH 05/17] CB-11815: (iOS) Fix hard-coded bridge name "cordova" This closes #18 --- src/ios/CDVWKWebViewEngine.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ios/CDVWKWebViewEngine.m b/src/ios/CDVWKWebViewEngine.m index 8039dcc..f60eace 100644 --- a/src/ios/CDVWKWebViewEngine.m +++ b/src/ios/CDVWKWebViewEngine.m @@ -98,7 +98,7 @@ - (void)pluginInitialize } if ([self.viewController conformsToProtocol:@protocol(WKScriptMessageHandler)]) { - [wkWebView.configuration.userContentController addScriptMessageHandler:(id < WKScriptMessageHandler >)self.viewController name:@"cordova"]; + [wkWebView.configuration.userContentController addScriptMessageHandler:(id < WKScriptMessageHandler >)self.viewController name:CDV_BRIDGE_NAME]; } [self updateSettings:settings]; From 88054455c24f0d66e907c1019c7baa96c64ebf5e Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Thu, 8 Sep 2016 02:53:52 -0700 Subject: [PATCH 06/17] CB-11554 - fixed unit tests --- .../CDVWKWebViewEngineLibTests/CDVWKWebViewEngineTest.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineLibTests/CDVWKWebViewEngineTest.m b/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineLibTests/CDVWKWebViewEngineTest.m index d306b79..0c359c2 100644 --- a/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineLibTests/CDVWKWebViewEngineTest.m +++ b/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineLibTests/CDVWKWebViewEngineTest.m @@ -204,7 +204,8 @@ - (void) testShouldReloadWebView { XCTAssertFalse([self.plugin shouldReloadWebView]); // document with empty title should *not* reload - [wkWebView loadHTMLString:empty_title_document baseURL:nil]; + // baseURL:nil results in about:blank, so we use a dummy here + [wkWebView loadHTMLString:empty_title_document baseURL:[NSURL URLWithString:@"about:"]]; XCTAssertFalse([self.plugin shouldReloadWebView]); // Anecdotal assertion that when the WKWebView process has died, From f9fa06ff036ba668beca2f70bf16e9bae864b4de Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Thu, 8 Sep 2016 02:43:50 -0700 Subject: [PATCH 07/17] CB-11824 - Update tests to include objective-c tests This closes #19 --- .travis.yml | 14 +++++++++++--- package.json | 9 ++++----- .../project.pbxproj | 13 ++----------- tests/ios/package.json | 2 +- 4 files changed, 18 insertions(+), 20 deletions(-) diff --git a/.travis.yml b/.travis.yml index b9af4c5..83aaf0d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,12 @@ -language: node_js +osx_image: xcode7.3 +language: objective-c sudo: false -node_js: - - "4.2" +before_install: + - npm cache clean -f + - npm install -g n + - n stable + - node --version +install: + - npm install +script: + - npm test diff --git a/package.json b/package.json index 1065738..506ad1c 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,6 @@ "version": "1.0.4-dev", "description": "The official Apache Cordova WKWebView Engine Plugin", "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1" - }, "repository": { "type": "git", "url": "https://git-wip-us.apache.org/repos/asf/cordova-plugin-wkwebview-engine.git" @@ -15,8 +12,10 @@ "wkwebview" ], "scripts": { - "test": "npm run jshint", - "jshint": "node node_modules/jshint/bin/jshint src" + "test": "npm run jshint && npm run objc-tests", + "objc-tests": "cd tests/ios && npm test", + "preobjc-tests": "cd tests/ios && npm install", + "jshint": "node_modules/.bin/jshint src" }, "author": "Apache Cordova", "license": "Apache-2.0", diff --git a/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineTest.xcodeproj/project.pbxproj b/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineTest.xcodeproj/project.pbxproj index 74436bd..14a8d3b 100644 --- a/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineTest.xcodeproj/project.pbxproj +++ b/tests/ios/CDVWKWebViewEngineTest/CDVWKWebViewEngineTest.xcodeproj/project.pbxproj @@ -329,12 +329,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = ( - "$(inherited)", - "\"$(TARGET_BUILD_DIR)/usr/local/lib/include\"", - "\"$(OBJROOT)/UninstalledProducts/include\"", - "\"$(BUILT_PRODUCTS_DIR)\"", - ); + HEADER_SEARCH_PATHS = "$(inherited)"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; @@ -372,11 +367,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = ( - "$(inherited)", - "\"$(TARGET_BUILD_DIR)/usr/local/lib/include\"", - "\n\"$(OBJROOT)/UninstalledProducts/include\"\n\"$(BUILT_PRODUCTS_DIR)\"", - ); + HEADER_SEARCH_PATHS = "$(inherited)"; IPHONEOS_DEPLOYMENT_TARGET = 8.0; MTL_ENABLE_DEBUG_INFO = NO; OTHER_LDFLAGS = "-ObjC"; diff --git a/tests/ios/package.json b/tests/ios/package.json index 4c1ace3..e747d3b 100644 --- a/tests/ios/package.json +++ b/tests/ios/package.json @@ -8,6 +8,6 @@ "cordova-ios": "*" }, "scripts": { - "test": "xcodebuild test -workspace CDVWKWebViewEngineTest.xcworkspace -scheme CDVWKWebViewEngineLibTests -destination 'platform=iOS Simulator,name=iPhone 5' CONFIGURATION_BUILD_DIR='/tmp' HEADER_SEARCH_PATHS='$(OBJROOT)/UninstalledProducts/$(PLATFORM_NAME)/include'" + "test": "xcodebuild test -workspace CDVWKWebViewEngineTest.xcworkspace -scheme CDVWKWebViewEngineLibTests -destination \"platform=iOS Simulator,name=iPhone 5\"" } } From d97b63bd7ac0f9a1a25cad451cd5acba8c3cd18f Mon Sep 17 00:00:00 2001 From: Steve Gill Date: Thu, 8 Sep 2016 23:38:55 -0700 Subject: [PATCH 08/17] CB-11832 Updated version and RELEASENOTES.md for release 1.1.0 --- RELEASENOTES.md | 46 +++++++++++++++++++++++++++++++--------------- package.json | 2 +- plugin.xml | 2 +- tests/plugin.xml | 2 +- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 007962d..dbdfc9f 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -21,8 +21,24 @@ # Release Notes +### 1.1.0 (Sep 08, 2016) +* [CB-11824](https://issues.apache.org/jira/browse/CB-11824) - Update tests to include objective-c tests +* [CB-11554](https://issues.apache.org/jira/browse/CB-11554) - fixed unit tests +* [CB-11815](https://issues.apache.org/jira/browse/CB-11815) (**iOS**) Fix hard-coded bridge name "cordova" +* [CB-11554](https://issues.apache.org/jira/browse/CB-11554) - too 'brutal' app reload when title is empty +* [CB-11074](https://issues.apache.org/jira/browse/CB-11074) - Ensure settings from `config.xml` are taken into consideration +* Add ability to set the deceleration rate for the scrollview to 'fast' +* [CB-11496](https://issues.apache.org/jira/browse/CB-11496) - Add obj-c unit tests for `WKWebViewConfiguration`, `WKPreference` +* [CB-11496](https://issues.apache.org/jira/browse/CB-11496) - Create Obj-C unit-tests for `wkwebview-engine` (fix linker error) +* [CB-11452](https://issues.apache.org/jira/browse/CB-11452) - Update README.md with latest news about `AllowInlineMediaPlayback` fix +* [CB-9888](https://issues.apache.org/jira/browse/CB-9888) (**iOS**) check & reload `WKWebView` +* [CB-11375](https://issues.apache.org/jira/browse/CB-11375) - `onReset` method of `CDVPlugin` is never called +* Add pull request template. +* [CB-10818](https://issues.apache.org/jira/browse/CB-10818) - Support the scroll deceleration speed preference. +* [CB-10817](https://issues.apache.org/jira/browse/CB-10817) - Will now reload the `webView` if a crash occurs + ### 1.0.3 (Apr 15, 2016) -* CB-10636 Add `JSHint` for plugins +* [CB-10636](https://issues.apache.org/jira/browse/CB-10636) Add `JSHint` for plugins ### 1.0.2 (Feb 09, 2016) * [CB-10269](https://issues.apache.org/jira/browse/CB-10269) - Replace cordova exec only when present in wkwebview @@ -31,22 +47,22 @@ ### 1.0.1 (Dec 11, 2015) -* CB-10190 - WKWebView engine is not releasing the user-agent lock +* [CB-10190](https://issues.apache.org/jira/browse/CB-10190) - WKWebView engine is not releasing the user-agent lock ### 1.0.0 (Dec 04, 2015) -* CB-10146 - Add to README WKWebViewEngine quirks that will affect migration from UIWebView -* CB-10133 - DataClone DOM Exception 25 thrown for postMessage -* CB-10106 - added bridge proxy -* CB-10107 - nativeEvalAndFetch called for all bridges -* CB-10106 - iOS bridges need to take into account bridge changes -* CB-10073 - WKWebViewEngine should post CDVPluginResetNotification -* CB-10035 Updated RELEASENOTES to be newest to oldest -* CB-10002 - WKWebView should propagate shouldOverrideLoadWithRequest to plugins -* CB-9979 CB-9972 Change ATS link to new link -* CB-9636 - Plugin should detect at runtime iOS 8 and use of file:// url and present an error -* CB-8839 - WKWebView ignores DisallowOverscroll preference -* CB-8556 - fix handleOpenURL for WKWebViewEngine plugin -* CB-8666 - Update CDVWKWebViewEngine plugin to use 4.0.x branch code +* [CB-10146](https://issues.apache.org/jira/browse/CB-10146) - Add to README WKWebViewEngine quirks that will affect migration from UIWebView +* [CB-10133](https://issues.apache.org/jira/browse/CB-10133) - DataClone DOM Exception 25 thrown for postMessage +* [CB-10106](https://issues.apache.org/jira/browse/CB-10106) - added bridge proxy +* [CB-10107](https://issues.apache.org/jira/browse/CB-10107) - nativeEvalAndFetch called for all bridges +* [CB-10106](https://issues.apache.org/jira/browse/CB-10106) - iOS bridges need to take into account bridge changes +* [CB-10073](https://issues.apache.org/jira/browse/CB-10073) - WKWebViewEngine should post CDVPluginResetNotification +* [CB-10035](https://issues.apache.org/jira/browse/CB-10035) Updated RELEASENOTES to be newest to oldest +* [CB-10002](https://issues.apache.org/jira/browse/CB-10002) - WKWebView should propagate shouldOverrideLoadWithRequest to plugins +* [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 +* [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 +* [CB-8839](https://issues.apache.org/jira/browse/CB-8839) - WKWebView ignores DisallowOverscroll preference +* [CB-8556](https://issues.apache.org/jira/browse/CB-8556) - fix handleOpenURL for WKWebViewEngine plugin +* [CB-8666](https://issues.apache.org/jira/browse/CB-8666) - Update CDVWKWebViewEngine plugin to use 4.0.x branch code diff --git a/package.json b/package.json index 506ad1c..956cf20 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-wkwebview-engine", - "version": "1.0.4-dev", + "version": "1.1.0", "description": "The official Apache Cordova WKWebView Engine Plugin", "main": "index.js", "repository": { diff --git a/plugin.xml b/plugin.xml index 2208a36..9b7abed 100644 --- a/plugin.xml +++ b/plugin.xml @@ -23,7 +23,7 @@ xmlns:rim="http://www.blackberry.com/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-wkwebview-engine" - version="1.0.4-dev"> + version="1.1.0"> Cordova WKWebView Engine Cordova WKWebView Engine Plugin Apache 2.0 diff --git a/tests/plugin.xml b/tests/plugin.xml index e58d83c..a6a4235 100644 --- a/tests/plugin.xml +++ b/tests/plugin.xml @@ -20,7 +20,7 @@ + version="1.1.0"> cordova-plugin-wkwebview-engine Tests Apache 2.0 From 10075b9625eb6aece2dd8c7a4d5ba451fc7f2e76 Mon Sep 17 00:00:00 2001 From: Steve Gill Date: Fri, 9 Sep 2016 16:08:04 -0700 Subject: [PATCH 09/17] CB-11832 Incremented plugin version. --- package.json | 2 +- plugin.xml | 2 +- tests/plugin.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 956cf20..d83af19 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-wkwebview-engine", - "version": "1.1.0", + "version": "1.1.1-dev", "description": "The official Apache Cordova WKWebView Engine Plugin", "main": "index.js", "repository": { diff --git a/plugin.xml b/plugin.xml index 9b7abed..102f7c6 100644 --- a/plugin.xml +++ b/plugin.xml @@ -23,7 +23,7 @@ xmlns:rim="http://www.blackberry.com/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-wkwebview-engine" - version="1.1.0"> + version="1.1.1-dev"> Cordova WKWebView Engine Cordova WKWebView Engine Plugin Apache 2.0 diff --git a/tests/plugin.xml b/tests/plugin.xml index a6a4235..378cb46 100644 --- a/tests/plugin.xml +++ b/tests/plugin.xml @@ -20,7 +20,7 @@ + version="1.1.1-dev"> cordova-plugin-wkwebview-engine Tests Apache 2.0 From 608855bbcb2f16e307f45aca6beef5a4f75e1b36 Mon Sep 17 00:00:00 2001 From: Luca Torella Date: Mon, 5 Sep 2016 23:53:17 +0200 Subject: [PATCH 10/17] CB-11818 - Avoid retain cycle: WKUserContentController retains its message handler, to break it we cannot pass directly CDVWKWebViewEngine's instance This closes #17 --- src/ios/CDVWKWebViewEngine.m | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/src/ios/CDVWKWebViewEngine.m b/src/ios/CDVWKWebViewEngine.m index f60eace..50a872c 100644 --- a/src/ios/CDVWKWebViewEngine.m +++ b/src/ios/CDVWKWebViewEngine.m @@ -26,10 +26,20 @@ Licensed to the Apache Software Foundation (ASF) under one #define CDV_BRIDGE_NAME @"cordova" #define CDV_WKWEBVIEW_FILE_URL_LOAD_SELECTOR @"loadFileURL:allowingReadAccessToURL:" +@interface CDVWKWeakScriptMessageHandler : NSObject + +@property (nonatomic, weak, readonly) idscriptMessageHandler; + +- (instancetype)initWithScriptMessageHandler:(id)scriptMessageHandler; + +@end + + @interface CDVWKWebViewEngine () @property (nonatomic, strong, readwrite) UIView* engineWebView; @property (nonatomic, strong, readwrite) id uiDelegate; +@property (nonatomic, weak) id weakScriptMessageHandler; @end @@ -76,8 +86,10 @@ - (void)pluginInitialize self.uiDelegate = [[CDVWKWebViewUIDelegate alloc] initWithTitle:[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleDisplayName"]]; + CDVWKWeakScriptMessageHandler *weakScriptMessageHandler = [[CDVWKWeakScriptMessageHandler alloc] initWithScriptMessageHandler:self]; + WKUserContentController* userContentController = [[WKUserContentController alloc] init]; - [userContentController addScriptMessageHandler:self name:CDV_BRIDGE_NAME]; + [userContentController addScriptMessageHandler:weakScriptMessageHandler name:CDV_BRIDGE_NAME]; WKWebViewConfiguration* configuration = [self createConfigurationFromSettings:settings]; configuration.userContentController = userContentController; @@ -401,4 +413,25 @@ - (void) webView: (WKWebView *) webView decidePolicyForNavigationAction: (WKNavi return decisionHandler(NO); } + +@end + +#pragma mark - CDVWKWeakScriptMessageHandler + +@implementation CDVWKWeakScriptMessageHandler + +- (instancetype)initWithScriptMessageHandler:(id)scriptMessageHandler +{ + self = [super init]; + if (self) { + _scriptMessageHandler = scriptMessageHandler; + } + return self; +} + +- (void)userContentController:(WKUserContentController *)userContentController didReceiveScriptMessage:(WKScriptMessage *)message +{ + [self.scriptMessageHandler userContentController:userContentController didReceiveScriptMessage:message]; +} + @end From 81e889854a5ca8b7bd620f91e945998a280305c3 Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Wed, 28 Sep 2016 01:29:03 -0700 Subject: [PATCH 11/17] =?UTF-8?q?CB-11917=20-=20Remove=20pull=20request=20?= =?UTF-8?q?template=20checklist=20item:=20"iCLA=20has=20been=20submitted?= =?UTF-8?q?=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This closes #21 --- .github/PULL_REQUEST_TEMPLATE.md | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 4bd6da9..91582f4 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -17,7 +17,6 @@ Thanks! ### Checklist -- [ ] [ICLA](http://www.apache.org/licenses/icla.txt) has been signed and submitted to secretary@apache.org. - [ ] [Reported an issue](http://cordova.apache.org/contribute/issues.html) in the JIRA database - [ ] 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. - [ ] Added automated test coverage as appropriate for this change. From d9d30f2cf91f307b44ecc5efe1763ae7d0b3bdb3 Mon Sep 17 00:00:00 2001 From: Connor Pearson Date: Tue, 11 Oct 2016 14:04:37 -0400 Subject: [PATCH 12/17] CB-11997: Add crash recovery for iOS 8 --- src/ios/CDVWKWebViewEngine.m | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/ios/CDVWKWebViewEngine.m b/src/ios/CDVWKWebViewEngine.m index 50a872c..9ab0d5c 100644 --- a/src/ios/CDVWKWebViewEngine.m +++ b/src/ios/CDVWKWebViewEngine.m @@ -123,6 +123,32 @@ - (void)pluginInitialize name:UIApplicationWillEnterForegroundNotification object:nil]; NSLog(@"Using WKWebView"); + + [self addURLObserver]; +} + +- (void)onReset { + [self addURLObserver]; +} + +static void * KVOContext = &KVOContext; + +- (void)addURLObserver { + if(![[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){.majorVersion = 9, .minorVersion = 0, .patchVersion = 0 }]){ + [self.webView addObserver:self forKeyPath:@"URL" options:0 context:KVOContext]; + } +} + +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context +{ + if (context == KVOContext) { + if (object == [self webView] && [keyPath isEqualToString: @"URL"] && [object valueForKeyPath:keyPath] == nil){ + NSLog(@"URL is nil. Reloading WebView"); + [(WKWebView*)_engineWebView reload]; + } + } else { + [super observeValueForKeyPath:keyPath ofObject:object change:change context:context]; + } } - (void) onAppWillEnterForeground:(NSNotification*)notification { From d5591deceba8936b9bfb7a0d04e60504ed12e407 Mon Sep 17 00:00:00 2001 From: Connor Pearson Date: Wed, 30 Nov 2016 07:29:10 -0500 Subject: [PATCH 13/17] CB-11997: Code review comments This closes #23 --- src/ios/CDVWKWebViewEngine.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ios/CDVWKWebViewEngine.m b/src/ios/CDVWKWebViewEngine.m index 9ab0d5c..e43c7ba 100644 --- a/src/ios/CDVWKWebViewEngine.m +++ b/src/ios/CDVWKWebViewEngine.m @@ -134,7 +134,7 @@ - (void)onReset { static void * KVOContext = &KVOContext; - (void)addURLObserver { - if(![[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:(NSOperatingSystemVersion){.majorVersion = 9, .minorVersion = 0, .patchVersion = 0 }]){ + if(!IsAtLeastiOSVersion(@"9.0")){ [self.webView addObserver:self forKeyPath:@"URL" options:0 context:KVOContext]; } } @@ -143,7 +143,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(N { if (context == KVOContext) { if (object == [self webView] && [keyPath isEqualToString: @"URL"] && [object valueForKeyPath:keyPath] == nil){ - NSLog(@"URL is nil. Reloading WebView"); + NSLog(@"URL is nil. Reloading WKWebView"); [(WKWebView*)_engineWebView reload]; } } else { From bf24bb63416a7961196a1ba70023c5ebdad5c955 Mon Sep 17 00:00:00 2001 From: kelvinho Date: Tue, 29 Nov 2016 17:20:02 +0800 Subject: [PATCH 14/17] CB-10228:(iOS) AppendUserAgent not working with WKWebView --- src/ios/CDVWKWebViewEngine.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ios/CDVWKWebViewEngine.m b/src/ios/CDVWKWebViewEngine.m index e43c7ba..5d361c5 100644 --- a/src/ios/CDVWKWebViewEngine.m +++ b/src/ios/CDVWKWebViewEngine.m @@ -99,6 +99,10 @@ - (void)pluginInitialize wkWebView.UIDelegate = self.uiDelegate; self.engineWebView = wkWebView; + if ([self.viewController isKindOfClass:[CDVViewController class]]) { + wkWebView.customUserAgent = ((CDVViewController*) self.viewController).userAgent; + } + if ([self.viewController conformsToProtocol:@protocol(WKUIDelegate)]) { wkWebView.UIDelegate = (id )self.viewController; } From c28423b9a51b0b4932430ac0dc34f1eb04dacdd1 Mon Sep 17 00:00:00 2001 From: kelvinho Date: Thu, 1 Dec 2016 00:14:06 +0800 Subject: [PATCH 15/17] added check for at least iOS 9.0 This closes #24 --- src/ios/CDVWKWebViewEngine.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ios/CDVWKWebViewEngine.m b/src/ios/CDVWKWebViewEngine.m index 5d361c5..0985316 100644 --- a/src/ios/CDVWKWebViewEngine.m +++ b/src/ios/CDVWKWebViewEngine.m @@ -99,7 +99,7 @@ - (void)pluginInitialize wkWebView.UIDelegate = self.uiDelegate; self.engineWebView = wkWebView; - if ([self.viewController isKindOfClass:[CDVViewController class]]) { + if (IsAtLeastiOSVersion(@"9.0") && [self.viewController isKindOfClass:[CDVViewController class]]) { wkWebView.customUserAgent = ((CDVViewController*) self.viewController).userAgent; } From 4cd73e0969303ca6bf1f1d1767162692fd8fddb8 Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Mon, 5 Dec 2016 14:57:13 -0800 Subject: [PATCH 16/17] Updated README.md --- README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 11ca96d..7c416e7 100644 --- a/README.md +++ b/README.md @@ -45,13 +45,14 @@ To test the development version: cordova platform add https://github.com/apache/cordova-ios.git#master cordova plugin add https://github.com/apache/cordova-plugin-wkwebview-engine.git#master -You also must have Xcode 7 (iOS 9 SDK) installed. Check your Xcode version by running: +You also must have at least Xcode 7 (iOS 9 SDK) installed. Check your Xcode version by running: xcode-select --print-path Required Permissions ----------- -WKWebView may not fully launch (the deviceready event may not fire) unless if the following is included in config.xml: +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. + #### config.xml @@ -71,7 +72,9 @@ We have an [experimental plugin](https://github.com/apache/cordova-plugins/tree/ Application Transport Security (ATS) in iOS 9 ----------- -The next released version of the [cordova-cli 5.4.0](https://www.npmjs.com/package/cordova) will support automatic conversion of the [<access>](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. +Starting with [cordova-cli 5.4.0](https://www.npmjs.com/package/cordova), it will support automatic conversion of the [<access>](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 at least version 5.4.0 of the cordova-cli to use this new functionality. Limitations -------- From 91e9d74e78ccec5f77837475937553003b710b01 Mon Sep 17 00:00:00 2001 From: Shazron Abdullah Date: Wed, 7 Dec 2016 16:39:47 -0800 Subject: [PATCH 17/17] CB-12224 Updated version and RELEASENOTES.md for release 1.1.1 --- RELEASENOTES.md | 10 ++++++++++ package.json | 2 +- plugin.xml | 2 +- tests/plugin.xml | 2 +- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index dbdfc9f..b89b5df 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -21,6 +21,16 @@ # Release Notes +### 1.1.1 (Dec 07, 2016) +* Updated README.md +* added check for at least iOS 9.0 +* CB-10228:(iOS) AppendUserAgent not working with WKWebView +* [CB-11997](https://issues.apache.org/jira/browse/CB-11997) Code review comments +* [CB-11997](https://issues.apache.org/jira/browse/CB-11997) Add crash recovery for iOS 8 +* [CB-11917](https://issues.apache.org/jira/browse/CB-11917) - Remove pull request template checklist item: "iCLA has been submitted…" +* [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 +* [CB-11832](https://issues.apache.org/jira/browse/CB-11832) Incremented plugin version. + ### 1.1.0 (Sep 08, 2016) * [CB-11824](https://issues.apache.org/jira/browse/CB-11824) - Update tests to include objective-c tests * [CB-11554](https://issues.apache.org/jira/browse/CB-11554) - fixed unit tests diff --git a/package.json b/package.json index d83af19..c38e3c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-wkwebview-engine", - "version": "1.1.1-dev", + "version": "1.1.1", "description": "The official Apache Cordova WKWebView Engine Plugin", "main": "index.js", "repository": { diff --git a/plugin.xml b/plugin.xml index 102f7c6..b129754 100644 --- a/plugin.xml +++ b/plugin.xml @@ -23,7 +23,7 @@ xmlns:rim="http://www.blackberry.com/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-wkwebview-engine" - version="1.1.1-dev"> + version="1.1.1"> Cordova WKWebView Engine Cordova WKWebView Engine Plugin Apache 2.0 diff --git a/tests/plugin.xml b/tests/plugin.xml index 378cb46..6f06fff 100644 --- a/tests/plugin.xml +++ b/tests/plugin.xml @@ -20,7 +20,7 @@ + version="1.1.1"> cordova-plugin-wkwebview-engine Tests Apache 2.0