You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by sh...@apache.org on 2015/09/10 09:03:21 UTC
cordova-plugins git commit: CB-9566 Renamed wkwebview-engine folder
to wkwebview-engine-localhost
Repository: cordova-plugins
Updated Branches:
refs/heads/master 3d7110af9 -> e6d0cc095
CB-9566 Renamed wkwebview-engine folder to wkwebview-engine-localhost
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugins/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugins/commit/e6d0cc09
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugins/tree/e6d0cc09
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugins/diff/e6d0cc09
Branch: refs/heads/master
Commit: e6d0cc0954a325298cd6540454d915862d408810
Parents: 3d7110a
Author: Shazron Abdullah <sh...@apache.org>
Authored: Thu Sep 10 00:03:12 2015 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Thu Sep 10 00:03:12 2015 -0700
----------------------------------------------------------------------
wkwebview-engine-localhost/README.md | 40 ++++
wkwebview-engine-localhost/plugin.xml | 38 +++
.../src/ios/CDVWKWebViewEngine.h | 27 +++
.../src/ios/CDVWKWebViewEngine.m | 235 +++++++++++++++++++
.../src/ios/CDVWKWebViewUIDelegate.h | 28 +++
.../src/ios/CDVWKWebViewUIDelegate.m | 123 ++++++++++
wkwebview-engine/README.md | 40 ----
wkwebview-engine/plugin.xml | 38 ---
wkwebview-engine/src/ios/CDVWKWebViewEngine.h | 27 ---
wkwebview-engine/src/ios/CDVWKWebViewEngine.m | 235 -------------------
.../src/ios/CDVWKWebViewUIDelegate.h | 28 ---
.../src/ios/CDVWKWebViewUIDelegate.m | 123 ----------
12 files changed, 491 insertions(+), 491 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/e6d0cc09/wkwebview-engine-localhost/README.md
----------------------------------------------------------------------
diff --git a/wkwebview-engine-localhost/README.md b/wkwebview-engine-localhost/README.md
new file mode 100644
index 0000000..1c84cb5
--- /dev/null
+++ b/wkwebview-engine-localhost/README.md
@@ -0,0 +1,40 @@
+Cordova WKWebView Engine
+======
+
+This plugin makes `Cordova` use the `WKWebView` component (new in iOS 8.0) instead of the default `UIWebView` component.
+
+This will also install the `Cordova Local WebServer` plugin.
+
+This plugin currently needs to use the `4.0.x` branch of `cordova-ios`.
+
+To `alpha test` this:
+
+ cordova create wkwvtest my.project.id wkwvtest
+ cd wkwvtest
+ cordova platform add https://github.com/apache/cordova-ios.git#master
+ cordova plugin add https://github.com/apache/cordova-plugins.git#master:wkwebview-engine
+
+Permissions
+-----------
+
+#### config.xml
+
+ <feature name="CDVWKWebViewEngine">
+ <param name="ios-package" value="CDVWKWebViewEngine" />
+ </feature>
+
+ <preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
+
+Supported Platforms
+-------------------
+
+- iOS
+
+Known Issues
+-------------------
+
+When you build, it might complain of a linking error. This is a `plugman` bug that does not install `WebKit.framework` properly. Open up your project file in `Xcode` and add it manually.
+
+If you are using the CLI, open `Xcode` by:
+
+ open -a Xcode platforms/ios
http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/e6d0cc09/wkwebview-engine-localhost/plugin.xml
----------------------------------------------------------------------
diff --git a/wkwebview-engine-localhost/plugin.xml b/wkwebview-engine-localhost/plugin.xml
new file mode 100644
index 0000000..b2de8e6
--- /dev/null
+++ b/wkwebview-engine-localhost/plugin.xml
@@ -0,0 +1,38 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
+ xmlns:rim="http://www.blackberry.com/ns/widgets"
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ id="cordova-labs-wkwebviewengine"
+ version="0.3.0">
+ <name>Cordova WKWebView Engine</name>
+ <description>Cordova WKWebView Engine Plugin</description>
+ <license>Apache 2.0</license>
+ <keywords>cordova,wkwebview,webview</keywords>
+ <repo>https://git-wip-us.apache.org/repos/asf/cordova-plugins.git</repo>
+
+ <engines>
+ <engine name="cordova-ios" version=">=4.0.0-dev" />
+ </engines>
+
+ <dependency id="cordova-labs-local-webserver" url="https://git-wip-us.apache.org/repos/asf/cordova-plugins.git#master:local-webserver" version=">=2.3.1" />
+
+ <!-- ios -->
+ <platform name="ios">
+ <config-file target="config.xml" parent="/*">
+ <feature name="CDVWKWebViewEngine">
+ <param name="ios-package" value="CDVWKWebViewEngine" />
+ </feature>
+ <preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
+ </config-file>
+
+ <framework src="WebKit.framework" weak="true" />
+
+ <header-file src="src/ios/CDVWKWebViewEngine.h" />
+ <source-file src="src/ios/CDVWKWebViewEngine.m" />
+ <header-file src="src/ios/CDVWKWebViewUIDelegate.h" />
+ <source-file src="src/ios/CDVWKWebViewUIDelegate.m" />
+
+ </platform>
+
+</plugin>
http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/e6d0cc09/wkwebview-engine-localhost/src/ios/CDVWKWebViewEngine.h
----------------------------------------------------------------------
diff --git a/wkwebview-engine-localhost/src/ios/CDVWKWebViewEngine.h b/wkwebview-engine-localhost/src/ios/CDVWKWebViewEngine.h
new file mode 100644
index 0000000..2fe4bc2
--- /dev/null
+++ b/wkwebview-engine-localhost/src/ios/CDVWKWebViewEngine.h
@@ -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 <WebKit/WebKit.h>
+#import <Cordova/CDV.h>
+
+@interface CDVWKWebViewEngine : CDVPlugin <CDVWebViewEngineProtocol, WKScriptMessageHandler, WKNavigationDelegate>
+
+@property (nonatomic, strong, readonly) id <WKUIDelegate> uiDelegate;
+
+@end
http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/e6d0cc09/wkwebview-engine-localhost/src/ios/CDVWKWebViewEngine.m
----------------------------------------------------------------------
diff --git a/wkwebview-engine-localhost/src/ios/CDVWKWebViewEngine.m b/wkwebview-engine-localhost/src/ios/CDVWKWebViewEngine.m
new file mode 100644
index 0000000..fa0ce26
--- /dev/null
+++ b/wkwebview-engine-localhost/src/ios/CDVWKWebViewEngine.m
@@ -0,0 +1,235 @@
+/*
+ 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 "CDVWKWebViewEngine.h"
+#import "CDVWKWebViewUIDelegate.h"
+#import <Cordova/NSDictionary+CordovaPreferences.h>
+
+#import <objc/message.h>
+
+#define CDV_BRIDGE_NAME @"cordova"
+
+@interface CDVWKWebViewEngine ()
+
+@property (nonatomic, strong, readwrite) UIView* engineWebView;
+@property (nonatomic, strong, readwrite) id <WKUIDelegate> uiDelegate;
+
+@end
+
+// see forwardingTargetForSelector: selector comment for the reason for this pragma
+#pragma clang diagnostic ignored "-Wprotocol"
+
+@implementation CDVWKWebViewEngine
+
+@synthesize engineWebView = _engineWebView;
+
+- (instancetype)initWithFrame:(CGRect)frame
+{
+ self = [super init];
+ if (self) {
+ if (!IsAtLeastiOSVersion(@"8.0")) {
+ 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;
+
+ NSLog(@"Using WKWebView");
+ }
+
+ return self;
+}
+
+- (void)pluginInitialize
+{
+ // viewController would be available now. we attempt to set all possible delegates to it, by default
+
+ WKWebView* wkWebView = (WKWebView*)_engineWebView;
+
+ if ([self.viewController conformsToProtocol:@protocol(WKUIDelegate)]) {
+ wkWebView.UIDelegate = (id <WKUIDelegate>)self.viewController;
+ }
+
+ if ([self.viewController conformsToProtocol:@protocol(WKNavigationDelegate)]) {
+ wkWebView.navigationDelegate = (id <WKNavigationDelegate>)self.viewController;
+ } else {
+ wkWebView.navigationDelegate = (id <WKNavigationDelegate>)self;
+ }
+
+ if ([self.viewController conformsToProtocol:@protocol(WKScriptMessageHandler)]) {
+ [wkWebView.configuration.userContentController addScriptMessageHandler:(id < WKScriptMessageHandler >)self.viewController name:@"cordova"];
+ }
+
+ [self updateSettings:self.commandDelegate.settings];
+}
+
+- (id)loadRequest:(NSURLRequest*)request
+{
+ SEL wk_sel = NSSelectorFromString(@"loadFileURL:allowingReadAccessToURL:");
+
+ // the URL needs to be a file reference
+ NSURL* url = request.URL;
+
+ if ([_engineWebView respondsToSelector:wk_sel] && [url isFileReferenceURL]) {
+ // allow the folder containing the file reference to be read as well
+ NSURL* readAccessUrl = [request.URL URLByDeletingLastPathComponent];
+ return ((id (*)(id, SEL, id, id))objc_msgSend)(_engineWebView, wk_sel, url, readAccessUrl);
+ } else {
+ return [(WKWebView*)_engineWebView loadRequest:request];
+ }
+}
+
+- (id)loadHTMLString:(NSString*)string baseURL:(NSURL*)baseURL
+{
+ return [(WKWebView*)_engineWebView loadHTMLString:string baseURL:baseURL];
+}
+
+- (NSURL*) URL
+{
+ return [(WKWebView*)_engineWebView URL];
+}
+
+- (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];
+ wkWebView.configuration.preferences.javaScriptCanOpenWindowsAutomatically = [settings cordovaBoolSettingForKey:@"JavaScriptCanOpenWindowsAutomatically" default:NO];
+ */
+
+ // By default, DisallowOverscroll is false (thus bounce is allowed)
+ BOOL bounceAllowed = !([settings cordovaBoolSettingForKey:@"DisallowOverscroll" defaultValue:NO]);
+
+ // prevent webView from bouncing
+ if (!bounceAllowed) {
+ if ([wkWebView respondsToSelector:@selector(scrollView)]) {
+ ((UIScrollView*)[wkWebView scrollView]).bounces = NO;
+ } else {
+ for (id subview in wkWebView.subviews) {
+ if ([[subview class] isSubclassOfClass:[UIScrollView class]]) {
+ ((UIScrollView*)subview).bounces = NO;
+ }
+ }
+ }
+ }
+}
+
+- (void)updateWithInfo:(NSDictionary*)info
+{
+ NSDictionary* scriptMessageHandlers = [info objectForKey:kCDVWebViewEngineScriptMessageHandlers];
+ NSDictionary* settings = [info objectForKey:kCDVWebViewEngineWebViewPreferences];
+ id navigationDelegate = [info objectForKey:kCDVWebViewEngineWKNavigationDelegate];
+ id uiDelegate = [info objectForKey:kCDVWebViewEngineWKUIDelegate];
+
+ WKWebView* wkWebView = (WKWebView*)_engineWebView;
+
+ if (scriptMessageHandlers && [scriptMessageHandlers isKindOfClass:[NSDictionary class]]) {
+ NSArray* allKeys = [scriptMessageHandlers allKeys];
+
+ for (NSString* key in allKeys) {
+ id object = [scriptMessageHandlers objectForKey:key];
+ if ([object conformsToProtocol:@protocol(WKScriptMessageHandler)]) {
+ [wkWebView.configuration.userContentController addScriptMessageHandler:object name:key];
+ }
+ }
+ }
+
+ if (navigationDelegate && [navigationDelegate conformsToProtocol:@protocol(WKNavigationDelegate)]) {
+ wkWebView.navigationDelegate = navigationDelegate;
+ }
+
+ if (uiDelegate && [uiDelegate conformsToProtocol:@protocol(WKUIDelegate)]) {
+ wkWebView.UIDelegate = uiDelegate;
+ }
+
+ if (settings && [settings isKindOfClass:[NSDictionary class]]) {
+ [self updateSettings:settings];
+ }
+}
+
+// This forwards the methods that are in the header that are not implemented here.
+// Both WKWebView and UIWebView implement the below:
+// loadHTMLString:baseURL:
+// loadRequest:
+- (id)forwardingTargetForSelector:(SEL)aSelector
+{
+ return _engineWebView;
+}
+
+#pragma mark WKScriptMessageHandler implementation
+
+- (void)userContentController:(WKUserContentController*)userContentController didReceiveScriptMessage:(WKScriptMessage*)message
+{
+ if (![message.name isEqualToString:CDV_BRIDGE_NAME]) {
+ return;
+ }
+
+ CDVViewController* vc = (CDVViewController*)self.viewController;
+
+ NSArray* jsonEntry = message.body; // NSString:callbackId, NSString:service, NSString:action, NSArray:args
+ CDVInvokedUrlCommand* command = [CDVInvokedUrlCommand commandFromJson:jsonEntry];
+ CDV_EXEC_LOG(@"Exec(%@): Calling %@.%@", command.callbackId, command.className, command.methodName);
+
+ if (![vc.commandQueue execute:command]) {
+#ifdef DEBUG
+ NSError* error = nil;
+ NSString* commandJson = nil;
+ NSData* jsonData = [NSJSONSerialization dataWithJSONObject:jsonEntry
+ options:0
+ error:&error];
+
+ if (error == nil) {
+ commandJson = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
+ }
+
+ static NSUInteger maxLogLength = 1024;
+ NSString* commandString = ([commandJson length] > maxLogLength) ?
+ [NSString stringWithFormat : @"%@[...]", [commandJson substringToIndex:maxLogLength]] :
+ commandJson;
+
+ NSLog(@"FAILED pluginJSON = %@", commandString);
+#endif
+ }
+}
+
+#pragma mark WKNavigationDelegate implementation
+
+- (void)webView:(WKWebView*)webView didFinishNavigation:(WKNavigation*)navigation
+{
+ [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPageDidLoadNotification object:webView]];
+}
+
+@end
http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/e6d0cc09/wkwebview-engine-localhost/src/ios/CDVWKWebViewUIDelegate.h
----------------------------------------------------------------------
diff --git a/wkwebview-engine-localhost/src/ios/CDVWKWebViewUIDelegate.h b/wkwebview-engine-localhost/src/ios/CDVWKWebViewUIDelegate.h
new file mode 100644
index 0000000..33a179b
--- /dev/null
+++ b/wkwebview-engine-localhost/src/ios/CDVWKWebViewUIDelegate.h
@@ -0,0 +1,28 @@
+/*
+ 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 CDVWKWebViewUIDelegate : NSObject <WKUIDelegate>
+
+@property (nonatomic, copy) NSString* title;
+
+- (instancetype)initWithTitle:(NSString*)title;
+
+@end
http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/e6d0cc09/wkwebview-engine-localhost/src/ios/CDVWKWebViewUIDelegate.m
----------------------------------------------------------------------
diff --git a/wkwebview-engine-localhost/src/ios/CDVWKWebViewUIDelegate.m b/wkwebview-engine-localhost/src/ios/CDVWKWebViewUIDelegate.m
new file mode 100644
index 0000000..c9e5ce9
--- /dev/null
+++ b/wkwebview-engine-localhost/src/ios/CDVWKWebViewUIDelegate.m
@@ -0,0 +1,123 @@
+/*
+ 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 "CDVWKWebViewUIDelegate.h"
+
+@implementation CDVWKWebViewUIDelegate
+
+- (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 (^)())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];
+
+ UIViewController* rootController = [UIApplication sharedApplication].delegate.window.rootViewController;
+
+ [rootController 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];
+
+ UIViewController* rootController = [UIApplication sharedApplication].delegate.window.rootViewController;
+
+ [rootController 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;
+ }];
+
+ UIViewController* rootController = [UIApplication sharedApplication].delegate.window.rootViewController;
+
+ [rootController presentViewController:alert animated:YES completion:nil];
+}
+
+@end
http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/e6d0cc09/wkwebview-engine/README.md
----------------------------------------------------------------------
diff --git a/wkwebview-engine/README.md b/wkwebview-engine/README.md
deleted file mode 100644
index 1c84cb5..0000000
--- a/wkwebview-engine/README.md
+++ /dev/null
@@ -1,40 +0,0 @@
-Cordova WKWebView Engine
-======
-
-This plugin makes `Cordova` use the `WKWebView` component (new in iOS 8.0) instead of the default `UIWebView` component.
-
-This will also install the `Cordova Local WebServer` plugin.
-
-This plugin currently needs to use the `4.0.x` branch of `cordova-ios`.
-
-To `alpha test` this:
-
- cordova create wkwvtest my.project.id wkwvtest
- cd wkwvtest
- cordova platform add https://github.com/apache/cordova-ios.git#master
- cordova plugin add https://github.com/apache/cordova-plugins.git#master:wkwebview-engine
-
-Permissions
------------
-
-#### config.xml
-
- <feature name="CDVWKWebViewEngine">
- <param name="ios-package" value="CDVWKWebViewEngine" />
- </feature>
-
- <preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
-
-Supported Platforms
--------------------
-
-- iOS
-
-Known Issues
--------------------
-
-When you build, it might complain of a linking error. This is a `plugman` bug that does not install `WebKit.framework` properly. Open up your project file in `Xcode` and add it manually.
-
-If you are using the CLI, open `Xcode` by:
-
- open -a Xcode platforms/ios
http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/e6d0cc09/wkwebview-engine/plugin.xml
----------------------------------------------------------------------
diff --git a/wkwebview-engine/plugin.xml b/wkwebview-engine/plugin.xml
deleted file mode 100644
index b2de8e6..0000000
--- a/wkwebview-engine/plugin.xml
+++ /dev/null
@@ -1,38 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
- xmlns:rim="http://www.blackberry.com/ns/widgets"
- xmlns:android="http://schemas.android.com/apk/res/android"
- id="cordova-labs-wkwebviewengine"
- version="0.3.0">
- <name>Cordova WKWebView Engine</name>
- <description>Cordova WKWebView Engine Plugin</description>
- <license>Apache 2.0</license>
- <keywords>cordova,wkwebview,webview</keywords>
- <repo>https://git-wip-us.apache.org/repos/asf/cordova-plugins.git</repo>
-
- <engines>
- <engine name="cordova-ios" version=">=4.0.0-dev" />
- </engines>
-
- <dependency id="cordova-labs-local-webserver" url="https://git-wip-us.apache.org/repos/asf/cordova-plugins.git#master:local-webserver" version=">=2.3.1" />
-
- <!-- ios -->
- <platform name="ios">
- <config-file target="config.xml" parent="/*">
- <feature name="CDVWKWebViewEngine">
- <param name="ios-package" value="CDVWKWebViewEngine" />
- </feature>
- <preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
- </config-file>
-
- <framework src="WebKit.framework" weak="true" />
-
- <header-file src="src/ios/CDVWKWebViewEngine.h" />
- <source-file src="src/ios/CDVWKWebViewEngine.m" />
- <header-file src="src/ios/CDVWKWebViewUIDelegate.h" />
- <source-file src="src/ios/CDVWKWebViewUIDelegate.m" />
-
- </platform>
-
-</plugin>
http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/e6d0cc09/wkwebview-engine/src/ios/CDVWKWebViewEngine.h
----------------------------------------------------------------------
diff --git a/wkwebview-engine/src/ios/CDVWKWebViewEngine.h b/wkwebview-engine/src/ios/CDVWKWebViewEngine.h
deleted file mode 100644
index 2fe4bc2..0000000
--- a/wkwebview-engine/src/ios/CDVWKWebViewEngine.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
- */
-
-#import <WebKit/WebKit.h>
-#import <Cordova/CDV.h>
-
-@interface CDVWKWebViewEngine : CDVPlugin <CDVWebViewEngineProtocol, WKScriptMessageHandler, WKNavigationDelegate>
-
-@property (nonatomic, strong, readonly) id <WKUIDelegate> uiDelegate;
-
-@end
http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/e6d0cc09/wkwebview-engine/src/ios/CDVWKWebViewEngine.m
----------------------------------------------------------------------
diff --git a/wkwebview-engine/src/ios/CDVWKWebViewEngine.m b/wkwebview-engine/src/ios/CDVWKWebViewEngine.m
deleted file mode 100644
index fa0ce26..0000000
--- a/wkwebview-engine/src/ios/CDVWKWebViewEngine.m
+++ /dev/null
@@ -1,235 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
- */
-
-#import "CDVWKWebViewEngine.h"
-#import "CDVWKWebViewUIDelegate.h"
-#import <Cordova/NSDictionary+CordovaPreferences.h>
-
-#import <objc/message.h>
-
-#define CDV_BRIDGE_NAME @"cordova"
-
-@interface CDVWKWebViewEngine ()
-
-@property (nonatomic, strong, readwrite) UIView* engineWebView;
-@property (nonatomic, strong, readwrite) id <WKUIDelegate> uiDelegate;
-
-@end
-
-// see forwardingTargetForSelector: selector comment for the reason for this pragma
-#pragma clang diagnostic ignored "-Wprotocol"
-
-@implementation CDVWKWebViewEngine
-
-@synthesize engineWebView = _engineWebView;
-
-- (instancetype)initWithFrame:(CGRect)frame
-{
- self = [super init];
- if (self) {
- if (!IsAtLeastiOSVersion(@"8.0")) {
- 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;
-
- NSLog(@"Using WKWebView");
- }
-
- return self;
-}
-
-- (void)pluginInitialize
-{
- // viewController would be available now. we attempt to set all possible delegates to it, by default
-
- WKWebView* wkWebView = (WKWebView*)_engineWebView;
-
- if ([self.viewController conformsToProtocol:@protocol(WKUIDelegate)]) {
- wkWebView.UIDelegate = (id <WKUIDelegate>)self.viewController;
- }
-
- if ([self.viewController conformsToProtocol:@protocol(WKNavigationDelegate)]) {
- wkWebView.navigationDelegate = (id <WKNavigationDelegate>)self.viewController;
- } else {
- wkWebView.navigationDelegate = (id <WKNavigationDelegate>)self;
- }
-
- if ([self.viewController conformsToProtocol:@protocol(WKScriptMessageHandler)]) {
- [wkWebView.configuration.userContentController addScriptMessageHandler:(id < WKScriptMessageHandler >)self.viewController name:@"cordova"];
- }
-
- [self updateSettings:self.commandDelegate.settings];
-}
-
-- (id)loadRequest:(NSURLRequest*)request
-{
- SEL wk_sel = NSSelectorFromString(@"loadFileURL:allowingReadAccessToURL:");
-
- // the URL needs to be a file reference
- NSURL* url = request.URL;
-
- if ([_engineWebView respondsToSelector:wk_sel] && [url isFileReferenceURL]) {
- // allow the folder containing the file reference to be read as well
- NSURL* readAccessUrl = [request.URL URLByDeletingLastPathComponent];
- return ((id (*)(id, SEL, id, id))objc_msgSend)(_engineWebView, wk_sel, url, readAccessUrl);
- } else {
- return [(WKWebView*)_engineWebView loadRequest:request];
- }
-}
-
-- (id)loadHTMLString:(NSString*)string baseURL:(NSURL*)baseURL
-{
- return [(WKWebView*)_engineWebView loadHTMLString:string baseURL:baseURL];
-}
-
-- (NSURL*) URL
-{
- return [(WKWebView*)_engineWebView URL];
-}
-
-- (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];
- wkWebView.configuration.preferences.javaScriptCanOpenWindowsAutomatically = [settings cordovaBoolSettingForKey:@"JavaScriptCanOpenWindowsAutomatically" default:NO];
- */
-
- // By default, DisallowOverscroll is false (thus bounce is allowed)
- BOOL bounceAllowed = !([settings cordovaBoolSettingForKey:@"DisallowOverscroll" defaultValue:NO]);
-
- // prevent webView from bouncing
- if (!bounceAllowed) {
- if ([wkWebView respondsToSelector:@selector(scrollView)]) {
- ((UIScrollView*)[wkWebView scrollView]).bounces = NO;
- } else {
- for (id subview in wkWebView.subviews) {
- if ([[subview class] isSubclassOfClass:[UIScrollView class]]) {
- ((UIScrollView*)subview).bounces = NO;
- }
- }
- }
- }
-}
-
-- (void)updateWithInfo:(NSDictionary*)info
-{
- NSDictionary* scriptMessageHandlers = [info objectForKey:kCDVWebViewEngineScriptMessageHandlers];
- NSDictionary* settings = [info objectForKey:kCDVWebViewEngineWebViewPreferences];
- id navigationDelegate = [info objectForKey:kCDVWebViewEngineWKNavigationDelegate];
- id uiDelegate = [info objectForKey:kCDVWebViewEngineWKUIDelegate];
-
- WKWebView* wkWebView = (WKWebView*)_engineWebView;
-
- if (scriptMessageHandlers && [scriptMessageHandlers isKindOfClass:[NSDictionary class]]) {
- NSArray* allKeys = [scriptMessageHandlers allKeys];
-
- for (NSString* key in allKeys) {
- id object = [scriptMessageHandlers objectForKey:key];
- if ([object conformsToProtocol:@protocol(WKScriptMessageHandler)]) {
- [wkWebView.configuration.userContentController addScriptMessageHandler:object name:key];
- }
- }
- }
-
- if (navigationDelegate && [navigationDelegate conformsToProtocol:@protocol(WKNavigationDelegate)]) {
- wkWebView.navigationDelegate = navigationDelegate;
- }
-
- if (uiDelegate && [uiDelegate conformsToProtocol:@protocol(WKUIDelegate)]) {
- wkWebView.UIDelegate = uiDelegate;
- }
-
- if (settings && [settings isKindOfClass:[NSDictionary class]]) {
- [self updateSettings:settings];
- }
-}
-
-// This forwards the methods that are in the header that are not implemented here.
-// Both WKWebView and UIWebView implement the below:
-// loadHTMLString:baseURL:
-// loadRequest:
-- (id)forwardingTargetForSelector:(SEL)aSelector
-{
- return _engineWebView;
-}
-
-#pragma mark WKScriptMessageHandler implementation
-
-- (void)userContentController:(WKUserContentController*)userContentController didReceiveScriptMessage:(WKScriptMessage*)message
-{
- if (![message.name isEqualToString:CDV_BRIDGE_NAME]) {
- return;
- }
-
- CDVViewController* vc = (CDVViewController*)self.viewController;
-
- NSArray* jsonEntry = message.body; // NSString:callbackId, NSString:service, NSString:action, NSArray:args
- CDVInvokedUrlCommand* command = [CDVInvokedUrlCommand commandFromJson:jsonEntry];
- CDV_EXEC_LOG(@"Exec(%@): Calling %@.%@", command.callbackId, command.className, command.methodName);
-
- if (![vc.commandQueue execute:command]) {
-#ifdef DEBUG
- NSError* error = nil;
- NSString* commandJson = nil;
- NSData* jsonData = [NSJSONSerialization dataWithJSONObject:jsonEntry
- options:0
- error:&error];
-
- if (error == nil) {
- commandJson = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
- }
-
- static NSUInteger maxLogLength = 1024;
- NSString* commandString = ([commandJson length] > maxLogLength) ?
- [NSString stringWithFormat : @"%@[...]", [commandJson substringToIndex:maxLogLength]] :
- commandJson;
-
- NSLog(@"FAILED pluginJSON = %@", commandString);
-#endif
- }
-}
-
-#pragma mark WKNavigationDelegate implementation
-
-- (void)webView:(WKWebView*)webView didFinishNavigation:(WKNavigation*)navigation
-{
- [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:CDVPageDidLoadNotification object:webView]];
-}
-
-@end
http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/e6d0cc09/wkwebview-engine/src/ios/CDVWKWebViewUIDelegate.h
----------------------------------------------------------------------
diff --git a/wkwebview-engine/src/ios/CDVWKWebViewUIDelegate.h b/wkwebview-engine/src/ios/CDVWKWebViewUIDelegate.h
deleted file mode 100644
index 33a179b..0000000
--- a/wkwebview-engine/src/ios/CDVWKWebViewUIDelegate.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
- */
-
-#import <WebKit/WebKit.h>
-
-@interface CDVWKWebViewUIDelegate : NSObject <WKUIDelegate>
-
-@property (nonatomic, copy) NSString* title;
-
-- (instancetype)initWithTitle:(NSString*)title;
-
-@end
http://git-wip-us.apache.org/repos/asf/cordova-plugins/blob/e6d0cc09/wkwebview-engine/src/ios/CDVWKWebViewUIDelegate.m
----------------------------------------------------------------------
diff --git a/wkwebview-engine/src/ios/CDVWKWebViewUIDelegate.m b/wkwebview-engine/src/ios/CDVWKWebViewUIDelegate.m
deleted file mode 100644
index c9e5ce9..0000000
--- a/wkwebview-engine/src/ios/CDVWKWebViewUIDelegate.m
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
- */
-
-#import "CDVWKWebViewUIDelegate.h"
-
-@implementation CDVWKWebViewUIDelegate
-
-- (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 (^)())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];
-
- UIViewController* rootController = [UIApplication sharedApplication].delegate.window.rootViewController;
-
- [rootController 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];
-
- UIViewController* rootController = [UIApplication sharedApplication].delegate.window.rootViewController;
-
- [rootController 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;
- }];
-
- UIViewController* rootController = [UIApplication sharedApplication].delegate.window.rootViewController;
-
- [rootController presentViewController:alert animated:YES completion:nil];
-}
-
-@end
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org