You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cordova.apache.org by sh...@apache.org on 2015/09/09 00:02:42 UTC

[05/19] cordova-plugin-wkwebview-engine git commit: Changes in CDWKWebViewEngine to reflect changes in CDVWebViewEngineProtocol.

Changes in CDWKWebViewEngine to reflect changes in CDVWebViewEngineProtocol.

Made loadHTMLString and loadRequest explicit - loadRequest implicitly handles file urls by attempting to use loadFileURL if available.


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-wkwebview-engine/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-wkwebview-engine/commit/b9349f08
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-wkwebview-engine/tree/b9349f08
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-wkwebview-engine/diff/b9349f08

Branch: refs/heads/master
Commit: b9349f08f009c9f175def0494cf55764c0e9cc0d
Parents: 2d5732d
Author: Shazron Abdullah <sh...@apache.org>
Authored: Wed Nov 12 07:05:52 2014 -0800
Committer: Shazron Abdullah <sh...@apache.org>
Committed: Wed Nov 12 07:05:52 2014 -0800

----------------------------------------------------------------------
 src/ios/CDVWKWebViewEngine.m | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-wkwebview-engine/blob/b9349f08/src/ios/CDVWKWebViewEngine.m
----------------------------------------------------------------------
diff --git a/src/ios/CDVWKWebViewEngine.m b/src/ios/CDVWKWebViewEngine.m
index fd81e37..de69ddd 100644
--- a/src/ios/CDVWKWebViewEngine.m
+++ b/src/ios/CDVWKWebViewEngine.m
@@ -86,22 +86,25 @@
     [self updateSettings:self.commandDelegate.settings];
 }
 
-// We implement this here because certain versions of iOS 8 do not implement this
-// in WKWebView, so we need to test for this during runtime.
-// It is speculated that this selector will be available in iOS 8.2 for WKWebView
-- (void)loadFileURL:(NSURL*)url allowingReadAccessToURL:(NSURL*)readAccessURL
+- (id)loadRequest:(NSURLRequest*)request
 {
-    SEL wk_sel = @selector(loadFileURL:allowingReadAccessToURL:);
-    __weak CDVWKWebViewEngine* 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 ([_engineWebView respondsToSelector:wk_sel] && [[url scheme] isEqualToString:@"file"]) {
-            ((id (*)(id, SEL, id, id))objc_msgSend)(_engineWebView, wk_sel, url, readAccessURL);
-        } else {
-            [weakSelf loadRequest:[NSURLRequest requestWithURL:url]];
-        }
-    });
+    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];
 }
 
 - (void)updateSettings:(NSDictionary*)settings


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