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/03/07 01:18:34 UTC
[21/43] ios commit: Renamed CDVWebViewOperationsDelegate to
CDVWebViewProxy (plus uncrustify style fixups)
Renamed CDVWebViewOperationsDelegate to CDVWebViewProxy (plus uncrustify style fixups)
Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/46910664
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/46910664
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/46910664
Branch: refs/heads/4.0.x
Commit: 46910664ac236c2d75d9c5e7c9a0134a8e3b2e40
Parents: 3a41824
Author: Shazron Abdullah <sh...@apache.org>
Authored: Sun Nov 2 00:07:21 2014 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Sun Nov 2 00:07:21 2014 -0700
----------------------------------------------------------------------
CordovaLib/Classes/CDV.h | 2 +-
CordovaLib/Classes/CDVCommandDelegateImpl.m | 27 +++--
CordovaLib/Classes/CDVCommandQueue.m | 4 +-
CordovaLib/Classes/CDVPlugin.m | 2 +-
CordovaLib/Classes/CDVViewController.h | 6 +-
CordovaLib/Classes/CDVViewController.m | 20 ++--
.../Classes/CDVWebViewOperationsDelegate.h | 39 -------
.../Classes/CDVWebViewOperationsDelegate.m | 104 -------------------
CordovaLib/Classes/CDVWebViewProxy.h | 39 +++++++
CordovaLib/Classes/CDVWebViewProxy.m | 104 +++++++++++++++++++
CordovaLib/CordovaLib.xcodeproj/project.pbxproj | 20 ++--
11 files changed, 183 insertions(+), 184 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/46910664/CordovaLib/Classes/CDV.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDV.h b/CordovaLib/Classes/CDV.h
index d368961..771bdc5 100644
--- a/CordovaLib/Classes/CDV.h
+++ b/CordovaLib/Classes/CDV.h
@@ -32,7 +32,7 @@
#import "CDVScreenOrientationDelegate.h"
#import "CDVTimer.h"
#import "CDVWebViewPreferences.h"
-#import "CDVWebViewOperationsDelegate.h"
+#import "CDVWebViewProxy.h"
#import "NSArray+Comparisons.h"
#import "NSData+Base64.h"
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/46910664/CordovaLib/Classes/CDVCommandDelegateImpl.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCommandDelegateImpl.m b/CordovaLib/Classes/CDVCommandDelegateImpl.m
index 02e3064..9a5f2aa 100644
--- a/CordovaLib/Classes/CDVCommandDelegateImpl.m
+++ b/CordovaLib/Classes/CDVCommandDelegateImpl.m
@@ -6,9 +6,9 @@
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
@@ -31,7 +31,7 @@
if (self != nil) {
_viewController = viewController;
_commandQueue = _viewController.commandQueue;
-
+
NSError* err = nil;
_callbackIdPattern = [NSRegularExpression regularExpressionWithPattern:@"[^A-Za-z0-9._-]" options:0 error:&err];
if (err != nil) {
@@ -48,16 +48,16 @@
NSBundle* mainBundle = [NSBundle mainBundle];
NSMutableArray* directoryParts = [NSMutableArray arrayWithArray:[resourcepath componentsSeparatedByString:@"/"]];
NSString* filename = [directoryParts lastObject];
-
+
[directoryParts removeLastObject];
-
+
NSString* directoryPartsJoined = [directoryParts componentsJoinedByString:@"/"];
NSString* directoryStr = _viewController.wwwFolderName;
-
+
if ([directoryPartsJoined length] > 0) {
directoryStr = [NSString stringWithFormat:@"%@/%@", _viewController.wwwFolderName, [directoryParts componentsJoinedByString:@"/"]];
}
-
+
return [mainBundle pathForResource:filename ofType:@"" inDirectory:directoryStr];
}
@@ -71,14 +71,14 @@
- (void)evalJsHelper2:(NSString*)js
{
CDV_EXEC_LOG(@"Exec: evalling: %@", [js substringToIndex:MIN([js length], 160)]);
- [_viewController.webViewOperationsDelegate evaluateJavaScript:js completionHandler:^(id obj, NSError* error) {
+ [_viewController.webViewProxy evaluateJavaScript:js completionHandler:^(id obj, NSError* error) {
// TODO: obj can be something other than string
if ([obj isKindOfClass:[NSString class]]) {
NSString* commandsJSON = (NSString*)obj;
if ([commandsJSON length] > 0) {
CDV_EXEC_LOG(@"Exec: Retrieved new exec messages by chaining.");
}
-
+
[_commandQueue enqueueCommandBatch:commandsJSON];
[_commandQueue executePending];
}
@@ -109,8 +109,7 @@
- (BOOL)isValidCallbackId:(NSString*)callbackId
{
-
- if (callbackId == nil || _callbackIdPattern == nil) {
+ if ((callbackId == nil) || (_callbackIdPattern == nil)) {
return NO;
}
@@ -136,9 +135,9 @@
int status = [result.status intValue];
BOOL keepCallback = [result.keepCallback boolValue];
NSString* argumentsAsJSON = [result argumentsAsJSON];
-
+
NSString* js = [NSString stringWithFormat:@"cordova.require('cordova/exec').nativeCallback('%@',%d,%@,%d)", callbackId, status, argumentsAsJSON, keepCallback];
-
+
[self evalJsHelper:js];
}
@@ -175,7 +174,7 @@
- (BOOL)URLIsWhitelisted:(NSURL*)url
{
return ![_viewController.whitelist schemeIsAllowed:[url scheme]] ||
- [_viewController.whitelist URLIsAllowed:url logFailure:NO];
+ [_viewController.whitelist URLIsAllowed:url logFailure:NO];
}
- (NSDictionary*)settings
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/46910664/CordovaLib/Classes/CDVCommandQueue.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVCommandQueue.m b/CordovaLib/Classes/CDVCommandQueue.m
index bb2788b..21a6489 100644
--- a/CordovaLib/Classes/CDVCommandQueue.m
+++ b/CordovaLib/Classes/CDVCommandQueue.m
@@ -112,8 +112,8 @@ static const double MAX_EXECUTION_TIME = .008; // Half of a 60fps frame.
__weak CDVCommandQueue* weakSelf = self;
NSString* js = @"cordova.require('cordova/exec').nativeFetchMessages()";
- [_viewController.webViewOperationsDelegate evaluateJavaScript:js
- completionHandler:^(id obj, NSError* error) {
+ [_viewController.webViewProxy evaluateJavaScript:js
+ completionHandler:^(id obj, NSError* error) {
if ((error == nil) && [obj isKindOfClass:[NSString class]]) {
NSString* queuedCommandsJSON = (NSString*)obj;
CDV_EXEC_LOG(@"Exec: Flushed JS->native queue (hadCommands=%d).", [queuedCommandsJSON length] > 0);
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/46910664/CordovaLib/Classes/CDVPlugin.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVPlugin.m b/CordovaLib/Classes/CDVPlugin.m
index 5f90311..bae6926 100644
--- a/CordovaLib/Classes/CDVPlugin.m
+++ b/CordovaLib/Classes/CDVPlugin.m
@@ -132,7 +132,7 @@ NSString* const CDVRemoteNotificationError = @"CDVRemoteNotificationError";
- (NSString*)writeJavascript:(NSString*)javascript
{
// TODO: although deprecated, should have some solution here instead of removing it
- [((CDVViewController*)self.viewController).webViewOperationsDelegate evaluateJavaScript : javascript completionHandler : nil]; // bad cast, but ok for now
+ [((CDVViewController*)self.viewController).webViewProxy evaluateJavaScript : javascript completionHandler : nil]; // bad cast, but ok for now
return @"";
}
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/46910664/CordovaLib/Classes/CDVViewController.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVViewController.h b/CordovaLib/Classes/CDVViewController.h
index 7bc005a..e5acc20 100644
--- a/CordovaLib/Classes/CDVViewController.h
+++ b/CordovaLib/Classes/CDVViewController.h
@@ -26,7 +26,7 @@
#import "CDVWhitelist.h"
#import "CDVScreenOrientationDelegate.h"
#import "CDVPlugin.h"
-#import "CDVWebViewOperationsDelegate.h"
+#import "CDVWebViewProxy.h"
#ifdef __IPHONE_8_0
#import <WebKit/WebKit.h>
#else
@@ -38,7 +38,7 @@
@interface CDVViewController : UIViewController <UIWebViewDelegate, CDVScreenOrientationDelegate, WKScriptMessageHandler>{
@protected
- CDVWebViewOperationsDelegate* _webViewOperationsDelegate;
+ CDVWebViewProxy* _webViewProxy;
@protected
id <CDVCommandDelegate> _commandDelegate;
@protected
@@ -58,7 +58,7 @@
@property (nonatomic, readwrite, copy) NSString* wwwFolderName;
@property (nonatomic, readwrite, copy) NSString* startPage;
@property (nonatomic, readonly, strong) CDVCommandQueue* commandQueue;
-@property (nonatomic, readonly, strong) CDVWebViewOperationsDelegate* webViewOperationsDelegate;
+@property (nonatomic, readonly, strong) CDVWebViewProxy* webViewProxy;
@property (nonatomic, readonly, strong) id <CDVCommandDelegate> commandDelegate;
/**
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/46910664/CordovaLib/Classes/CDVViewController.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVViewController.m b/CordovaLib/Classes/CDVViewController.m
index f8ced8b..3456c17 100644
--- a/CordovaLib/Classes/CDVViewController.m
+++ b/CordovaLib/Classes/CDVViewController.m
@@ -57,7 +57,7 @@
@synthesize wwwFolderName, startPage, initialized, openURL, baseUserAgent;
@synthesize commandDelegate = _commandDelegate;
@synthesize commandQueue = _commandQueue;
-@synthesize webViewOperationsDelegate = _webViewOperationsDelegate;
+@synthesize webViewProxy = _webViewProxy;
- (void)__init
{
@@ -322,7 +322,7 @@
[CDVUserAgentUtil setUserAgent:self.userAgent lockToken:lockToken];
if (appURL) {
NSURLRequest* appReq = [NSURLRequest requestWithURL:appURL cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:20.0];
- [_webViewOperationsDelegate loadRequest:appReq];
+ [_webViewProxy loadRequest:appReq];
} else {
NSString* loadErr = [NSString stringWithFormat:@"ERROR: Start Page at '%@/%@' was not found.", self.wwwFolderName, self.startPage];
NSLog(@"%@", loadErr);
@@ -331,10 +331,10 @@
if (errorUrl) {
errorUrl = [NSURL URLWithString:[NSString stringWithFormat:@"?error=%@", [loadErr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] relativeToURL:errorUrl];
NSLog(@"%@", [errorUrl absoluteString]);
- [_webViewOperationsDelegate loadRequest:[NSURLRequest requestWithURL:errorUrl]];
+ [_webViewProxy loadRequest:[NSURLRequest requestWithURL:errorUrl]];
} else {
NSString* html = [NSString stringWithFormat:@"<html><body> %@ </body></html>", loadErr];
- [_webViewOperationsDelegate loadHTMLString:html baseURL:nil];
+ [_webViewProxy loadHTMLString:html baseURL:nil];
}
}
}];
@@ -407,7 +407,7 @@
, (long)[self mapIosOrientationToJsOrientation:interfaceOrientation]];
__weak CDVViewController* weakSelf = self;
- [_webViewOperationsDelegate evaluateJavaScript:jsCall completionHandler:^(NSString* obj, NSError* error) {
+ [_webViewProxy evaluateJavaScript:jsCall completionHandler:^(NSString* obj, NSError* error) {
if ([obj length] > 0) {
completionHandler([obj boolValue]);
} else {
@@ -505,7 +505,7 @@
self.webView = [self newCordovaViewWithFrame:webViewBounds];
self.webView.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
- _webViewOperationsDelegate = [[CDVWebViewOperationsDelegate alloc] initWithWebView:self.webView];
+ _webViewProxy = [[CDVWebViewProxy alloc] initWithWebView:self.webView];
[self.view addSubview:self.webView];
[self.view sendSubviewToBack:self.webView];
@@ -900,8 +900,8 @@
dispatch_block_t handleOpenUrl = ^(void) {
NSString* jsString = [NSString stringWithFormat:@"if (typeof handleOpenURL === 'function') { handleOpenURL(\"%@\");}", url];
- [_webViewOperationsDelegate evaluateJavaScript:jsString
- completionHandler:^(id object, NSError* error) {
+ [_webViewProxy evaluateJavaScript:jsString
+ completionHandler:^(id object, NSError* error) {
if (error == nil) {
weakSelf.openURL = nil;
}
@@ -911,8 +911,8 @@
if (!pageLoaded) {
// query the webview for readystate
NSString* jsString = @"document.readystate";
- [_webViewOperationsDelegate evaluateJavaScript:jsString
- completionHandler:^(id object, NSError* error) {
+ [_webViewProxy evaluateJavaScript:jsString
+ completionHandler:^(id object, NSError* error) {
if ((error == nil) && [object isKindOfClass:[NSString class]]) {
NSString* readyState = (NSString*)object;
BOOL ready = [readyState isEqualToString:@"loaded"] || [readyState isEqualToString:@"complete"];
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/46910664/CordovaLib/Classes/CDVWebViewOperationsDelegate.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVWebViewOperationsDelegate.h b/CordovaLib/Classes/CDVWebViewOperationsDelegate.h
deleted file mode 100644
index ee539f7..0000000
--- a/CordovaLib/Classes/CDVWebViewOperationsDelegate.h
+++ /dev/null
@@ -1,39 +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 <Foundation/Foundation.h>
-#import <UIKit/UIKit.h>
-
-#ifdef __IPHONE_8_0
- #pragma message("For iOS 8 - Please add WebKit.framework into your 'Link Binary with Libraries' Build Phase Project Setting. This will be baked in once Xcode 6 is required.")
-#endif /* ifdef __IPHONE_8_0 */
-
-@interface CDVWebViewOperationsDelegate : NSObject {
- @private
- __weak UIView* _webView;
-}
-
-- (instancetype)initWithWebView:(UIView*)webView;
-
-- (void)loadRequest:(NSURLRequest*)request;
-- (void)loadHTMLString:(NSString*)string baseURL:(NSURL*)baseURL;
-- (void)evaluateJavaScript:(NSString*)javaScriptString completionHandler:(void (^)(id, NSError*))completionHandler;
-- (void)loadFileURL:(NSURL*)URL allowingReadAccessToURL:(NSURL*)readAccessURL;
-
-@end
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/46910664/CordovaLib/Classes/CDVWebViewOperationsDelegate.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVWebViewOperationsDelegate.m b/CordovaLib/Classes/CDVWebViewOperationsDelegate.m
deleted file mode 100644
index 8f32539..0000000
--- a/CordovaLib/Classes/CDVWebViewOperationsDelegate.m
+++ /dev/null
@@ -1,104 +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 <objc/message.h>
-#import "CDVWebViewOperationsDelegate.h"
-
-@implementation CDVWebViewOperationsDelegate
-
-- (instancetype)initWithWebView:(UIView*)webView
-{
- self = [super init];
- if (self) {
- Class wk_class = NSClassFromString(@"WKWebView");
- if (!([webView isKindOfClass:wk_class] || [webView isKindOfClass:[UIWebView class]])) {
- return nil;
- }
- _webView = webView;
- }
-
- return self;
-}
-
-- (void)loadRequest:(NSURLRequest*)request
-{
- SEL selector = @selector(loadRequest:);
-
- if ([_webView respondsToSelector:selector]) {
- // UIKit operations have to be on the main thread. and this method is synchronous
- [_webView performSelectorOnMainThread:selector withObject:request waitUntilDone:YES];
- }
-}
-
-- (void)loadFileURL:(NSURL*)url allowingReadAccessToURL:(NSURL*)readAccessURL
-{
- SEL wk_sel = @selector(loadFileURL:allowingReadAccessToURL:);
- __weak CDVWebViewOperationsDelegate* weakSelf = self;
-
- // UIKit operations have to be on the main thread. This method does not need to be synchronous
- dispatch_async(dispatch_get_main_queue(), ^{
- if ([_webView respondsToSelector:wk_sel] && [[url scheme] isEqualToString:@"file"]) {
- ((id (*)(id, SEL, id, id))objc_msgSend)(_webView, wk_sel, url, readAccessURL);
- } else {
- [weakSelf loadRequest:[NSURLRequest requestWithURL:url]];
- }
- });
-}
-
-- (void)loadHTMLString:(NSString*)string baseURL:(NSURL*)baseURL
-{
- SEL selector = @selector(loadHTMLString:baseURL:);
-
- dispatch_block_t invoke = ^(void) {
- ((void (*)(id, SEL, id, id))objc_msgSend)(_webView, selector, string, baseURL);
- };
-
- if ([_webView respondsToSelector:selector]) {
- // UIKit operations have to be on the main thread.
- // perform a synchronous invoke on the main thread without deadlocking
- if ([NSThread isMainThread]) {
- invoke();
- } else {
- dispatch_sync(dispatch_get_main_queue(), invoke);
- }
- }
-}
-
-- (void)evaluateJavaScript:(NSString*)javaScriptString completionHandler:(void (^)(id, NSError*))completionHandler
-{
- SEL ui_sel = @selector(stringByEvaluatingJavaScriptFromString:);
- SEL wk_sel = @selector(evaluateJavaScript:completionHandler:);
-
- // UIKit operations have to be on the main thread. This method does not need to be synchronous
- dispatch_async(dispatch_get_main_queue(), ^{
- if ([_webView respondsToSelector:ui_sel]) {
- NSString* ret = ((NSString * (*)(id, SEL, id))objc_msgSend)(_webView, ui_sel, javaScriptString);
- completionHandler(ret, nil);
- } else if ([_webView respondsToSelector:wk_sel]) {
- ((void (*)(id, SEL, id, id))objc_msgSend)(_webView, wk_sel, javaScriptString, completionHandler);
- }
- });
-}
-
-- (id)forwardingTargetForSelector:(SEL)aSelector
-{
- return _webView;
-}
-
-@end
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/46910664/CordovaLib/Classes/CDVWebViewProxy.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVWebViewProxy.h b/CordovaLib/Classes/CDVWebViewProxy.h
new file mode 100644
index 0000000..32b9839
--- /dev/null
+++ b/CordovaLib/Classes/CDVWebViewProxy.h
@@ -0,0 +1,39 @@
+/*
+ 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 <Foundation/Foundation.h>
+#import <UIKit/UIKit.h>
+
+#ifdef __IPHONE_8_0
+ #pragma message("For iOS 8 - Please add WebKit.framework into your 'Link Binary with Libraries' Build Phase Project Setting. This will be baked in once Xcode 6 is required.")
+#endif /* ifdef __IPHONE_8_0 */
+
+@interface CDVWebViewProxy : NSObject {
+ @private
+ __weak UIView* _webView;
+}
+
+- (instancetype)initWithWebView:(UIView*)webView;
+
+- (void)loadRequest:(NSURLRequest*)request;
+- (void)loadHTMLString:(NSString*)string baseURL:(NSURL*)baseURL;
+- (void)evaluateJavaScript:(NSString*)javaScriptString completionHandler:(void (^)(id, NSError*))completionHandler;
+- (void)loadFileURL:(NSURL*)URL allowingReadAccessToURL:(NSURL*)readAccessURL;
+
+@end
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/46910664/CordovaLib/Classes/CDVWebViewProxy.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVWebViewProxy.m b/CordovaLib/Classes/CDVWebViewProxy.m
new file mode 100644
index 0000000..dad0a15
--- /dev/null
+++ b/CordovaLib/Classes/CDVWebViewProxy.m
@@ -0,0 +1,104 @@
+/*
+ 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 <objc/message.h>
+#import "CDVWebViewProxy.h"
+
+@implementation CDVWebViewProxy
+
+- (instancetype)initWithWebView:(UIView*)webView
+{
+ self = [super init];
+ if (self) {
+ Class wk_class = NSClassFromString(@"WKWebView");
+ if (!([webView isKindOfClass:wk_class] || [webView isKindOfClass:[UIWebView class]])) {
+ return nil;
+ }
+ _webView = webView;
+ }
+
+ return self;
+}
+
+- (void)loadRequest:(NSURLRequest*)request
+{
+ SEL selector = @selector(loadRequest:);
+
+ if ([_webView respondsToSelector:selector]) {
+ // UIKit operations have to be on the main thread. and this method is synchronous
+ [_webView performSelectorOnMainThread:selector withObject:request waitUntilDone:YES];
+ }
+}
+
+- (void)loadFileURL:(NSURL*)url allowingReadAccessToURL:(NSURL*)readAccessURL
+{
+ SEL wk_sel = @selector(loadFileURL:allowingReadAccessToURL:);
+ __weak CDVWebViewProxy* weakSelf = self;
+
+ // UIKit operations have to be on the main thread. This method does not need to be synchronous
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if ([_webView respondsToSelector:wk_sel] && [[url scheme] isEqualToString:@"file"]) {
+ ((id (*)(id, SEL, id, id))objc_msgSend)(_webView, wk_sel, url, readAccessURL);
+ } else {
+ [weakSelf loadRequest:[NSURLRequest requestWithURL:url]];
+ }
+ });
+}
+
+- (void)loadHTMLString:(NSString*)string baseURL:(NSURL*)baseURL
+{
+ SEL selector = @selector(loadHTMLString:baseURL:);
+
+ dispatch_block_t invoke = ^(void) {
+ ((void (*)(id, SEL, id, id))objc_msgSend)(_webView, selector, string, baseURL);
+ };
+
+ if ([_webView respondsToSelector:selector]) {
+ // UIKit operations have to be on the main thread.
+ // perform a synchronous invoke on the main thread without deadlocking
+ if ([NSThread isMainThread]) {
+ invoke();
+ } else {
+ dispatch_sync(dispatch_get_main_queue(), invoke);
+ }
+ }
+}
+
+- (void)evaluateJavaScript:(NSString*)javaScriptString completionHandler:(void (^)(id, NSError*))completionHandler
+{
+ SEL ui_sel = @selector(stringByEvaluatingJavaScriptFromString:);
+ SEL wk_sel = @selector(evaluateJavaScript:completionHandler:);
+
+ // UIKit operations have to be on the main thread. This method does not need to be synchronous
+ dispatch_async(dispatch_get_main_queue(), ^{
+ if ([_webView respondsToSelector:ui_sel]) {
+ NSString* ret = ((NSString * (*)(id, SEL, id))objc_msgSend)(_webView, ui_sel, javaScriptString);
+ completionHandler(ret, nil);
+ } else if ([_webView respondsToSelector:wk_sel]) {
+ ((void (*)(id, SEL, id, id))objc_msgSend)(_webView, wk_sel, javaScriptString, completionHandler);
+ }
+ });
+}
+
+- (id)forwardingTargetForSelector:(SEL)aSelector
+{
+ return _webView;
+}
+
+@end
http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/46910664/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
----------------------------------------------------------------------
diff --git a/CordovaLib/CordovaLib.xcodeproj/project.pbxproj b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
index 8d43b0b..8e3c7a6 100644
--- a/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
+++ b/CordovaLib/CordovaLib.xcodeproj/project.pbxproj
@@ -12,10 +12,10 @@
1F92F4A11314023E0046367C /* CDVPluginResult.m in Sources */ = {isa = PBXBuildFile; fileRef = 1F92F49F1314023E0046367C /* CDVPluginResult.m */; };
301F2F2A14F3C9CA003FE9FC /* CDV.h in Headers */ = {isa = PBXBuildFile; fileRef = 301F2F2914F3C9CA003FE9FC /* CDV.h */; settings = {ATTRIBUTES = (Public, ); }; };
302965BC13A94E9D007046C5 /* CDVDebug.h in Headers */ = {isa = PBXBuildFile; fileRef = 302965BB13A94E9D007046C5 /* CDVDebug.h */; settings = {ATTRIBUTES = (Public, ); }; };
- 302D72FC19554BFC0028C99F /* CDVWebViewOperationsDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 302D72FA19554BFC0028C99F /* CDVWebViewOperationsDelegate.m */; };
+ 302D72FC19554BFC0028C99F /* CDVWebViewProxy.m in Sources */ = {isa = PBXBuildFile; fileRef = 302D72FA19554BFC0028C99F /* CDVWebViewProxy.m */; };
3034979C1513D56A0090E688 /* CDVLocalStorage.h in Headers */ = {isa = PBXBuildFile; fileRef = 3034979A1513D56A0090E688 /* CDVLocalStorage.h */; settings = {ATTRIBUTES = (Public, ); }; };
3034979E1513D56A0090E688 /* CDVLocalStorage.m in Sources */ = {isa = PBXBuildFile; fileRef = 3034979B1513D56A0090E688 /* CDVLocalStorage.m */; };
- 303820731955603600C91592 /* CDVWebViewOperationsDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 302D72F919554BFC0028C99F /* CDVWebViewOperationsDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 303820731955603600C91592 /* CDVWebViewProxy.h in Headers */ = {isa = PBXBuildFile; fileRef = 302D72F919554BFC0028C99F /* CDVWebViewProxy.h */; settings = {ATTRIBUTES = (Public, ); }; };
30392E4E14F4FCAB00B9E0B8 /* CDVAvailability.h in Headers */ = {isa = PBXBuildFile; fileRef = 30392E4D14F4FCAB00B9E0B8 /* CDVAvailability.h */; settings = {ATTRIBUTES = (Public, ); }; };
3062D120151D0EDB000D9128 /* UIDevice+Extensions.h in Headers */ = {isa = PBXBuildFile; fileRef = 3062D11E151D0EDB000D9128 /* UIDevice+Extensions.h */; settings = {ATTRIBUTES = (Public, ); }; };
3062D122151D0EDB000D9128 /* UIDevice+Extensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 3062D11F151D0EDB000D9128 /* UIDevice+Extensions.m */; };
@@ -33,10 +33,10 @@
30F5EBAB14CA26E700987760 /* CDVCommandDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 30F5EBA914CA26E700987760 /* CDVCommandDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
7E14B5A81705050A0032169E /* CDVTimer.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E14B5A61705050A0032169E /* CDVTimer.h */; settings = {ATTRIBUTES = (Public, ); }; };
7E14B5A91705050A0032169E /* CDVTimer.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E14B5A71705050A0032169E /* CDVTimer.m */; };
+ 7E22B88519E4C0210026F95E /* CDVAvailabilityDeprecated.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E22B88419E4C0210026F95E /* CDVAvailabilityDeprecated.h */; settings = {ATTRIBUTES = (Public, ); }; };
7E785B9A196F508900ABBDC8 /* CDVWebViewUIDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E785B98196F508900ABBDC8 /* CDVWebViewUIDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
7E785B9B196F508900ABBDC8 /* CDVWebViewUIDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7E785B99196F508900ABBDC8 /* CDVWebViewUIDelegate.m */; };
7EE9ECF819525D24004CA6B9 /* CDVWebViewPreferences.h in Headers */ = {isa = PBXBuildFile; fileRef = 7EE9ECF619525D24004CA6B9 /* CDVWebViewPreferences.h */; settings = {ATTRIBUTES = (Public, ); }; };
- 7E22B88519E4C0210026F95E /* CDVAvailabilityDeprecated.h in Headers */ = {isa = PBXBuildFile; fileRef = 7E22B88419E4C0210026F95E /* CDVAvailabilityDeprecated.h */; settings = {ATTRIBUTES = (Public, ); }; };
7EE9ECF919525D24004CA6B9 /* CDVWebViewPreferences.m in Sources */ = {isa = PBXBuildFile; fileRef = 7EE9ECF719525D24004CA6B9 /* CDVWebViewPreferences.m */; };
8852C43A14B65FD800F0E735 /* CDVViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = 8852C43614B65FD800F0E735 /* CDVViewController.h */; settings = {ATTRIBUTES = (Public, ); }; };
8852C43C14B65FD800F0E735 /* CDVViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 8852C43714B65FD800F0E735 /* CDVViewController.m */; };
@@ -66,8 +66,8 @@
1F92F49F1314023E0046367C /* CDVPluginResult.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CDVPluginResult.m; path = Classes/CDVPluginResult.m; sourceTree = "<group>"; };
301F2F2914F3C9CA003FE9FC /* CDV.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDV.h; path = Classes/CDV.h; sourceTree = "<group>"; };
302965BB13A94E9D007046C5 /* CDVDebug.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVDebug.h; path = Classes/CDVDebug.h; sourceTree = "<group>"; };
- 302D72F919554BFC0028C99F /* CDVWebViewOperationsDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVWebViewOperationsDelegate.h; path = Classes/CDVWebViewOperationsDelegate.h; sourceTree = "<group>"; };
- 302D72FA19554BFC0028C99F /* CDVWebViewOperationsDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CDVWebViewOperationsDelegate.m; path = Classes/CDVWebViewOperationsDelegate.m; sourceTree = "<group>"; };
+ 302D72F919554BFC0028C99F /* CDVWebViewProxy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVWebViewProxy.h; path = Classes/CDVWebViewProxy.h; sourceTree = "<group>"; };
+ 302D72FA19554BFC0028C99F /* CDVWebViewProxy.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CDVWebViewProxy.m; path = Classes/CDVWebViewProxy.m; sourceTree = "<group>"; };
30325A0B136B343700982B63 /* VERSION */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = VERSION; sourceTree = "<group>"; };
3034979A1513D56A0090E688 /* CDVLocalStorage.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVLocalStorage.h; path = Classes/CDVLocalStorage.h; sourceTree = "<group>"; };
3034979B1513D56A0090E688 /* CDVLocalStorage.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CDVLocalStorage.m; path = Classes/CDVLocalStorage.m; sourceTree = "<group>"; };
@@ -100,10 +100,10 @@
68A32D7414103017006B237C /* AddressBook.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AddressBook.framework; path = System/Library/Frameworks/AddressBook.framework; sourceTree = SDKROOT; };
7E14B5A61705050A0032169E /* CDVTimer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVTimer.h; path = Classes/CDVTimer.h; sourceTree = "<group>"; };
7E14B5A71705050A0032169E /* CDVTimer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CDVTimer.m; path = Classes/CDVTimer.m; sourceTree = "<group>"; };
+ 7E22B88419E4C0210026F95E /* CDVAvailabilityDeprecated.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVAvailabilityDeprecated.h; path = Classes/CDVAvailabilityDeprecated.h; sourceTree = "<group>"; };
7E785B98196F508900ABBDC8 /* CDVWebViewUIDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVWebViewUIDelegate.h; path = Classes/CDVWebViewUIDelegate.h; sourceTree = "<group>"; };
7E785B99196F508900ABBDC8 /* CDVWebViewUIDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CDVWebViewUIDelegate.m; path = Classes/CDVWebViewUIDelegate.m; sourceTree = "<group>"; };
7EE9ECF619525D24004CA6B9 /* CDVWebViewPreferences.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVWebViewPreferences.h; path = Classes/CDVWebViewPreferences.h; sourceTree = "<group>"; };
- 7E22B88419E4C0210026F95E /* CDVAvailabilityDeprecated.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVAvailabilityDeprecated.h; path = Classes/CDVAvailabilityDeprecated.h; sourceTree = "<group>"; };
7EE9ECF719525D24004CA6B9 /* CDVWebViewPreferences.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CDVWebViewPreferences.m; path = Classes/CDVWebViewPreferences.m; sourceTree = "<group>"; };
8220B5C316D5427E00EC3921 /* AssetsLibrary.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AssetsLibrary.framework; path = System/Library/Frameworks/AssetsLibrary.framework; sourceTree = SDKROOT; };
8852C43614B65FD800F0E735 /* CDVViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CDVViewController.h; path = Classes/CDVViewController.h; sourceTree = "<group>"; };
@@ -190,8 +190,8 @@
EB3B3546161CB44D003DBE7D /* CDVCommandQueue.m */,
7EE9ECF619525D24004CA6B9 /* CDVWebViewPreferences.h */,
7EE9ECF719525D24004CA6B9 /* CDVWebViewPreferences.m */,
- 302D72F919554BFC0028C99F /* CDVWebViewOperationsDelegate.h */,
- 302D72FA19554BFC0028C99F /* CDVWebViewOperationsDelegate.m */,
+ 302D72F919554BFC0028C99F /* CDVWebViewProxy.h */,
+ 302D72FA19554BFC0028C99F /* CDVWebViewProxy.m */,
7E785B98196F508900ABBDC8 /* CDVWebViewUIDelegate.h */,
7E785B99196F508900ABBDC8 /* CDVWebViewUIDelegate.m */,
);
@@ -304,7 +304,7 @@
EB96673B16A8970A00D86CDF /* CDVUserAgentUtil.h in Headers */,
7E14B5A81705050A0032169E /* CDVTimer.h in Headers */,
7E785B9A196F508900ABBDC8 /* CDVWebViewUIDelegate.h in Headers */,
- 303820731955603600C91592 /* CDVWebViewOperationsDelegate.h in Headers */,
+ 303820731955603600C91592 /* CDVWebViewProxy.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -383,7 +383,7 @@
EB96673C16A8970A00D86CDF /* CDVUserAgentUtil.m in Sources */,
EBFF4DBC16D3FE2E008F452B /* CDVWebViewDelegate.m in Sources */,
7E14B5A91705050A0032169E /* CDVTimer.m in Sources */,
- 302D72FC19554BFC0028C99F /* CDVWebViewOperationsDelegate.m in Sources */,
+ 302D72FC19554BFC0028C99F /* CDVWebViewProxy.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org