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 2014/11/02 08:02:10 UTC

ios commit: Add support for loadFileUrl (and style mixups)

Repository: cordova-ios
Updated Branches:
  refs/heads/wkwebview f13ba3a49 -> 3a4182461


Add support for loadFileUrl (and style mixups)


Project: http://git-wip-us.apache.org/repos/asf/cordova-ios/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-ios/commit/3a418246
Tree: http://git-wip-us.apache.org/repos/asf/cordova-ios/tree/3a418246
Diff: http://git-wip-us.apache.org/repos/asf/cordova-ios/diff/3a418246

Branch: refs/heads/wkwebview
Commit: 3a4182461d22c2477dab58e8ebe0d3604216b2e4
Parents: f13ba3a
Author: Shazron Abdullah <sh...@apache.org>
Authored: Sun Nov 2 00:02:07 2014 -0700
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Sun Nov 2 00:02:07 2014 -0700

----------------------------------------------------------------------
 .../Classes/CDVWebViewOperationsDelegate.h      | 10 ++--
 .../Classes/CDVWebViewOperationsDelegate.m      | 55 ++++++++++++++------
 2 files changed, 43 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-ios/blob/3a418246/CordovaLib/Classes/CDVWebViewOperationsDelegate.h
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVWebViewOperationsDelegate.h b/CordovaLib/Classes/CDVWebViewOperationsDelegate.h
index 34330a1..ee539f7 100644
--- a/CordovaLib/Classes/CDVWebViewOperationsDelegate.h
+++ b/CordovaLib/Classes/CDVWebViewOperationsDelegate.h
@@ -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
@@ -21,19 +21,19 @@
 #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.")
+    #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;
+- (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/3a418246/CordovaLib/Classes/CDVWebViewOperationsDelegate.m
----------------------------------------------------------------------
diff --git a/CordovaLib/Classes/CDVWebViewOperationsDelegate.m b/CordovaLib/Classes/CDVWebViewOperationsDelegate.m
index d243aba..8f32539 100644
--- a/CordovaLib/Classes/CDVWebViewOperationsDelegate.m
+++ b/CordovaLib/Classes/CDVWebViewOperationsDelegate.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
@@ -22,37 +22,53 @@
 
 @implementation CDVWebViewOperationsDelegate
 
-- (instancetype) initWithWebView:(UIView*)webView
+- (instancetype)initWithWebView:(UIView*)webView
 {
     self = [super init];
     if (self) {
         Class wk_class = NSClassFromString(@"WKWebView");
-        if ( !([webView isKindOfClass:wk_class] || [webView isKindOfClass:[UIWebView class]] )) {
+        if (!([webView isKindOfClass:wk_class] || [webView isKindOfClass:[UIWebView class]])) {
             return nil;
         }
         _webView = webView;
     }
-    
+
     return self;
 }
 
 - (void)loadRequest:(NSURLRequest*)request
 {
-    SEL selector = NSSelectorFromString(@"loadRequest:");
+    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 = NSSelectorFromString(@"loadHTMLString: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
@@ -66,18 +82,23 @@
 
 - (void)evaluateJavaScript:(NSString*)javaScriptString completionHandler:(void (^)(id, NSError*))completionHandler
 {
-    SEL ui_sel = NSSelectorFromString(@"stringByEvaluatingJavaScriptFromString:");
-    SEL wk_sel = NSSelectorFromString(@"evaluateJavaScript: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);
-        }
-    });
+            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


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org