Diff
Modified: trunk/Source/WebKit2/ChangeLog (174028 => 174029)
--- trunk/Source/WebKit2/ChangeLog 2014-09-26 23:25:17 UTC (rev 174028)
+++ trunk/Source/WebKit2/ChangeLog 2014-09-26 23:38:30 UTC (rev 174029)
@@ -1,3 +1,21 @@
+2014-09-26 Anders Carlsson <[email protected]>
+
+ Add API for loading local files
+ https://bugs.webkit.org/show_bug.cgi?id=137153
+ rdar://problem/17761459
+
+ Reviewed by Oliver Hunt.
+
+ * UIProcess/API/Cocoa/WKWebView.h:
+ * UIProcess/API/Cocoa/WKWebView.mm:
+ (-[WKWebView loadFileURL:allowingReadAccessToURL:]):
+ Load the file, wrapping the navigation ID in a WKNavigation using createLoadRequestNavigation.
+
+ * UIProcess/WebPageProxy.cpp:
+ (WebKit::WebPageProxy::loadFile):
+ * UIProcess/WebPageProxy.h:
+ Return the navigation ID (or 0 if the navigation failed).
+
2014-09-26 Timothy Hatcher <[email protected]>
Add WKInspector back function stubs that went missing from r173929.
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h (174028 => 174029)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h 2014-09-26 23:25:17 UTC (rev 174028)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.h 2014-09-26 23:38:30 UTC (rev 174029)
@@ -89,6 +89,15 @@
*/
- (WKNavigation *)loadRequest:(NSURLRequest *)request;
+/*! @abstract Navigates to the requested file URL on the filesystem.
+ @param URL The file URL to which to navigate.
+ @param readAccessURL The URL to allow read access to.
+ @discussion If readAccessURL references a single file, only that file may be loaded by WebKit.
+ If readAccessURL references a directory, files inside that file may be loaded by WebKit.
+ @result A new navigation for the given file URL.
+ */
+- (WKNavigation *)loadFileURL:(NSURL *)URL allowingReadAccessToURL:(NSURL *)readAccessURL WK_AVAILABLE(WK_MAC_TBA, WK_IOS_TBA);
+
/*! @abstract Sets the webpage contents and base URL.
@param string The string to use as the contents of the webpage.
@param baseURL A URL that is used to resolve relative URLs within the document.
Modified: trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm (174028 => 174029)
--- trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2014-09-26 23:25:17 UTC (rev 174028)
+++ trunk/Source/WebKit2/UIProcess/API/Cocoa/WKWebView.mm 2014-09-26 23:38:30 UTC (rev 174029)
@@ -406,6 +406,23 @@
return navigation.autorelease();
}
+- (WKNavigation *)loadFileURL:(NSURL *)URL allowingReadAccessToURL:(NSURL *)readAccessURL
+{
+ if (![URL isFileURL])
+ [NSException raise:NSInvalidArgumentException format:@"%@ is not a file URL", URL];
+
+ if (![readAccessURL isFileURL])
+ [NSException raise:NSInvalidArgumentException format:@"%@ is not a file URL", readAccessURL];
+
+ uint64_t navigationID = _page->loadFile([URL _web_originalDataAsWTFString], [readAccessURL _web_originalDataAsWTFString]);
+ if (!navigationID)
+ return nil;
+
+ auto navigation = _navigationState->createLoadRequestNavigation(navigationID, [NSURLRequest requestWithURL:URL]);
+
+ return navigation.autorelease();
+}
+
- (WKNavigation *)loadHTMLString:(NSString *)string baseURL:(NSURL *)baseURL
{
uint64_t navigationID = _page->loadHTMLString(string, baseURL.absoluteString);
Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp (174028 => 174029)
--- trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp 2014-09-26 23:25:17 UTC (rev 174028)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.cpp 2014-09-26 23:38:30 UTC (rev 174029)
@@ -740,17 +740,17 @@
return navigationID;
}
-void WebPageProxy::loadFile(const String& fileURLString, const String& resourceDirectoryURLString, API::Object* userData)
+uint64_t WebPageProxy::loadFile(const String& fileURLString, const String& resourceDirectoryURLString, API::Object* userData)
{
if (m_isClosed)
- return;
+ return 0;
if (!isValid())
reattachToWebProcess();
URL fileURL = URL(URL(), fileURLString);
if (!fileURL.isLocalFile())
- return;
+ return 0;
URL resourceDirectoryURL;
if (resourceDirectoryURLString.isNull())
@@ -758,16 +758,24 @@
else {
resourceDirectoryURL = URL(URL(), resourceDirectoryURLString);
if (!resourceDirectoryURL.isLocalFile())
- return;
+ return 0;
}
+ uint64_t navigationID = generateNavigationID();
+
+ auto transaction = m_pageLoadState.transaction();
+
+ m_pageLoadState.setPendingAPIRequestURL(transaction, fileURLString);
+
String resourceDirectoryPath = resourceDirectoryURL.fileSystemPath();
SandboxExtension::Handle sandboxExtensionHandle;
SandboxExtension::createHandle(resourceDirectoryPath, SandboxExtension::ReadOnly, sandboxExtensionHandle);
m_process->assumeReadAccessToBaseURL(resourceDirectoryURL);
- m_process->send(Messages::WebPage::LoadRequest(generateNavigationID(), fileURL, sandboxExtensionHandle, WebContextUserMessageEncoder(userData, process())), m_pageID);
+ m_process->send(Messages::WebPage::LoadRequest(navigationID, fileURL, sandboxExtensionHandle, WebContextUserMessageEncoder(userData, process())), m_pageID);
m_process->responsivenessTimer()->start();
+
+ return navigationID;
}
void WebPageProxy::loadData(API::Data* data, const String& MIMEType, const String& encoding, const String& baseURL, API::Object* userData)
Modified: trunk/Source/WebKit2/UIProcess/WebPageProxy.h (174028 => 174029)
--- trunk/Source/WebKit2/UIProcess/WebPageProxy.h 2014-09-26 23:25:17 UTC (rev 174028)
+++ trunk/Source/WebKit2/UIProcess/WebPageProxy.h 2014-09-26 23:38:30 UTC (rev 174029)
@@ -302,7 +302,7 @@
bool isClosed() const { return m_isClosed; }
uint64_t loadRequest(const WebCore::ResourceRequest&, API::Object* userData = nullptr);
- void loadFile(const String& fileURL, const String& resourceDirectoryURL, API::Object* userData = nullptr);
+ uint64_t loadFile(const String& fileURL, const String& resourceDirectoryURL, API::Object* userData = nullptr);
void loadData(API::Data*, const String& MIMEType, const String& encoding, const String& baseURL, API::Object* userData = nullptr);
uint64_t loadHTMLString(const String& htmlString, const String& baseURL, API::Object* userData = nullptr);
void loadAlternateHTMLString(const String& htmlString, const String& baseURL, const String& unreachableURL, API::Object* userData = nullptr);