Title: [247414] trunk
- Revision
- 247414
- Author
- [email protected]
- Date
- 2019-07-12 22:14:00 -0700 (Fri, 12 Jul 2019)
Log Message
[Cocoa] -loadFileURL:allowingReadAccessToURL: should fully resolve file URLs
https://bugs.webkit.org/show_bug.cgi?id=199768
<rdar://problem/52002206>
Reviewed by Geoffrey Garen.
Source/WebKit:
-loadFileURL:allowingReadAccessToURL: used -_web_originalDataAsWTFString from WKNSURLExtras
to convert the file and read access NSURLs to strings, which under the hood calls
CFURLGetBytes(). CFURLGetBytes() gets the URL's string without considering the base URL, so
if the client creates a URL like this:
NSURL *url = "" fileURLWithPath:@"tmpfile.txt" relativeToURL:[NSURL fileURLWithPath:@"/tmp"]]
... then -_web_originalDataAsWTFString will merely return the string "tmpfile.txt". When
that is later converted back to a URL in WebPageProxy::loadFile(), we lose track of the base
component and refuse to load something that no longer looks like a file: URL.
Fixed this by fully resolving the URLs passed to -loadFileURL:allowingReadAccessToURL: when
converting to strings by using -[NSURL absoluteString] instead of -_web_originalDataAsWTFString.
* Shared/Cocoa/WKNSURLExtras.mm:
(-[NSURL _web_originalDataAsWTFString]):
* UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView loadFileURL:allowingReadAccessToURL:]):
Tools:
* TestWebKitAPI/Tests/WebKitCocoa/LoadFileURL.mm:
(TEST):
Modified Paths
Diff
Modified: trunk/Source/WebKit/ChangeLog (247413 => 247414)
--- trunk/Source/WebKit/ChangeLog 2019-07-13 03:22:35 UTC (rev 247413)
+++ trunk/Source/WebKit/ChangeLog 2019-07-13 05:14:00 UTC (rev 247414)
@@ -1,3 +1,30 @@
+2019-07-12 Andy Estes <[email protected]>
+
+ [Cocoa] -loadFileURL:allowingReadAccessToURL: should fully resolve file URLs
+ https://bugs.webkit.org/show_bug.cgi?id=199768
+ <rdar://problem/52002206>
+
+ Reviewed by Geoffrey Garen.
+
+ -loadFileURL:allowingReadAccessToURL: used -_web_originalDataAsWTFString from WKNSURLExtras
+ to convert the file and read access NSURLs to strings, which under the hood calls
+ CFURLGetBytes(). CFURLGetBytes() gets the URL's string without considering the base URL, so
+ if the client creates a URL like this:
+
+ NSURL *url = "" fileURLWithPath:@"tmpfile.txt" relativeToURL:[NSURL fileURLWithPath:@"/tmp"]]
+
+ ... then -_web_originalDataAsWTFString will merely return the string "tmpfile.txt". When
+ that is later converted back to a URL in WebPageProxy::loadFile(), we lose track of the base
+ component and refuse to load something that no longer looks like a file: URL.
+
+ Fixed this by fully resolving the URLs passed to -loadFileURL:allowingReadAccessToURL: when
+ converting to strings by using -[NSURL absoluteString] instead of -_web_originalDataAsWTFString.
+
+ * Shared/Cocoa/WKNSURLExtras.mm:
+ (-[NSURL _web_originalDataAsWTFString]):
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (-[WKWebView loadFileURL:allowingReadAccessToURL:]):
+
2019-07-12 Megan Gardner <[email protected]>
Turn off two finger gestures for editable non-scaled content
Modified: trunk/Source/WebKit/Shared/Cocoa/WKNSURLExtras.mm (247413 => 247414)
--- trunk/Source/WebKit/Shared/Cocoa/WKNSURLExtras.mm 2019-07-13 03:22:35 UTC (rev 247413)
+++ trunk/Source/WebKit/Shared/Cocoa/WKNSURLExtras.mm 2019-07-13 05:14:00 UTC (rev 247414)
@@ -47,6 +47,7 @@
- (String)_web_originalDataAsWTFString
{
+ // FIXME: Why is it OK to ignore base URL here?
CString originalData;
WTF::getURLBytes((__bridge CFURLRef)self, originalData);
return String::fromUTF8(originalData);
Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm (247413 => 247414)
--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm 2019-07-13 03:22:35 UTC (rev 247413)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm 2019-07-13 05:14:00 UTC (rev 247414)
@@ -952,7 +952,7 @@
if (![readAccessURL isFileURL])
[NSException raise:NSInvalidArgumentException format:@"%@ is not a file URL", readAccessURL];
- return wrapper(_page->loadFile([URL _web_originalDataAsWTFString], [readAccessURL _web_originalDataAsWTFString]));
+ return wrapper(_page->loadFile(URL.absoluteString, readAccessURL.absoluteString));
}
- (WKNavigation *)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL
Modified: trunk/Tools/ChangeLog (247413 => 247414)
--- trunk/Tools/ChangeLog 2019-07-13 03:22:35 UTC (rev 247413)
+++ trunk/Tools/ChangeLog 2019-07-13 05:14:00 UTC (rev 247414)
@@ -1,3 +1,14 @@
+2019-07-12 Andy Estes <[email protected]>
+
+ [Cocoa] -loadFileURL:allowingReadAccessToURL: should fully resolve file URLs
+ https://bugs.webkit.org/show_bug.cgi?id=199768
+ <rdar://problem/52002206>
+
+ Reviewed by Geoffrey Garen.
+
+ * TestWebKitAPI/Tests/WebKitCocoa/LoadFileURL.mm:
+ (TEST):
+
2019-07-12 Aakash Jain <[email protected]>
[ews-build] Remove wincairo queue from old EWS and dashboard
Modified: trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/LoadFileURL.mm (247413 => 247414)
--- trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/LoadFileURL.mm 2019-07-13 03:22:35 UTC (rev 247413)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKitCocoa/LoadFileURL.mm 2019-07-13 05:14:00 UTC (rev 247414)
@@ -66,3 +66,18 @@
[delegate waitForDidFinishNavigation];
EXPECT_WK_STREQ(webView.get()._resourceDirectoryURL.path, file.URLByDeletingLastPathComponent.path);
}
+
+TEST(WKWebView, LoadRelativeFileURL)
+{
+ auto webView = adoptNS([[WKWebView alloc] initWithFrame:NSMakeRect(0, 0, 800, 600)]);
+
+ auto delegate = adoptNS([[TestNavigationDelegate alloc] init]);
+ [webView setNavigationDelegate:delegate.get()];
+
+ NSString *path = [NSBundle.mainBundle pathForResource:@"simple" ofType:@"html" inDirectory:@"TestWebKitAPI.resources"];
+ NSURL *baseURL = [NSURL fileURLWithPath:path.stringByDeletingLastPathComponent];
+ NSURL *fileURL = [NSURL fileURLWithPath:path.lastPathComponent relativeToURL:baseURL];
+ EXPECT_NOT_NULL([webView loadFileURL:fileURL allowingReadAccessToURL:fileURL.URLByDeletingLastPathComponent]);
+ [delegate waitForDidFinishNavigation];
+ EXPECT_WK_STREQ([webView _resourceDirectoryURL].path, fileURL.URLByDeletingLastPathComponent.path);
+}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes