<rdar://problem/8752200> and https://bugs.webkit.org/show_bug.cgi?id=52664
authorbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Jan 2011 01:37:05 +0000 (01:37 +0000)
committerbeidson@apple.com <beidson@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 19 Jan 2011 01:37:05 +0000 (01:37 +0000)
Need WebKit2 API to asynchronously get the resource data for a URL

Reviewed by Maciej Stachowiak.

Rename WKFrameGetMainResourceDataFunction to WKFrameGetResourceDataFunction, and add
new API to get a resource by URL:
* UIProcess/API/C/WKFrame.cpp:
(WKFrameGetMainResourceData):
(WKFrameGetResourceData):
(callGetResourceDataBlockAndDispose):
(WKFrameGetMainResourceData_b):
(WKFrameGetResourceData_b):
* UIProcess/API/C/WKFrame.h:

Implement the new API in the UIProcess side:
* UIProcess/WebFrameProxy.cpp:
(WebKit::WebFrameProxy::getResourceData):
* UIProcess/WebFrameProxy.h:
* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::getResourceDataFromFrame):
* UIProcess/WebPageProxy.h:

Have the WebProcess get the data and call back to the UIProcess:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::getResourceDataFromFrame):
* WebProcess/WebPage/WebPage.h:
* WebProcess/WebPage/WebPage.messages.in:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@76087 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit2/ChangeLog
Source/WebKit2/UIProcess/API/C/WKFrame.cpp
Source/WebKit2/UIProcess/API/C/WKFrame.h
Source/WebKit2/UIProcess/WebFrameProxy.cpp
Source/WebKit2/UIProcess/WebFrameProxy.h
Source/WebKit2/UIProcess/WebPageProxy.cpp
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in

index bce8a6c..4304c57 100644 (file)
@@ -1,3 +1,34 @@
+2011-01-18  Brady Eidson  <beidson@apple.com>
+
+        Reviewed by Maciej Stachowiak. 
+
+        <rdar://problem/8752200> and https://bugs.webkit.org/show_bug.cgi?id=52664
+        Need WebKit2 API to asynchronously get the resource data for a URL
+
+        Rename WKFrameGetMainResourceDataFunction to WKFrameGetResourceDataFunction, and add
+        new API to get a resource by URL:
+        * UIProcess/API/C/WKFrame.cpp:
+        (WKFrameGetMainResourceData):
+        (WKFrameGetResourceData):
+        (callGetResourceDataBlockAndDispose):
+        (WKFrameGetMainResourceData_b):
+        (WKFrameGetResourceData_b):
+        * UIProcess/API/C/WKFrame.h:
+
+        Implement the new API in the UIProcess side:
+        * UIProcess/WebFrameProxy.cpp:
+        (WebKit::WebFrameProxy::getResourceData):
+        * UIProcess/WebFrameProxy.h:
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::getResourceDataFromFrame):
+        * UIProcess/WebPageProxy.h:
+
+        Have the WebProcess get the data and call back to the UIProcess:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::getResourceDataFromFrame):
+        * WebProcess/WebPage/WebPage.h:
+        * WebProcess/WebPage/WebPage.messages.in:
+
 2011-01-18  Anders Carlsson  <andersca@apple.com>
 
         Reviewed by Dan Bernstein.
index 7c9ae11..a245786 100644 (file)
@@ -125,22 +125,32 @@ bool WKFrameIsFrameSet(WKFrameRef frameRef)
     return toImpl(frameRef)->isFrameSet();
 }
 
-void WKFrameGetMainResourceData(WKFrameRef frameRef, WKFrameGetMainResourceDataFunction callback, void* context)
+void WKFrameGetMainResourceData(WKFrameRef frameRef, WKFrameGetResourceDataFunction callback, void* context)
 {
     toImpl(frameRef)->getMainResourceData(DataCallback::create(context, callback));
 }
 
+void WKFrameGetResourceData(WKFrameRef frameRef, WKURLRef resourceURL, WKFrameGetResourceDataFunction callback, void* context)
+{
+    toImpl(frameRef)->getResourceData(toImpl(resourceURL), DataCallback::create(context, callback));
+}
+
 #ifdef __BLOCKS__
-static void callGetMainResourceDataBlockAndDispose(WKDataRef data, WKErrorRef error, void* context)
+static void callGetResourceDataBlockAndDispose(WKDataRef data, WKErrorRef error, void* context)
 {
-    WKFrameGetMainResourceDataBlock block = (WKFrameGetMainResourceDataBlock)context;
+    WKFrameGetResourceDataBlock block = (WKFrameGetResourceDataBlock)context;
     block(data, error);
     Block_release(block);
 }
 
-void WKFrameGetMainResourceData_b(WKFrameRef frameRef, WKFrameGetMainResourceDataBlock block)
+void WKFrameGetMainResourceData_b(WKFrameRef frameRef, WKFrameGetResourceDataBlock block)
+{
+    WKFrameGetMainResourceData(frameRef, callGetResourceDataBlockAndDispose, Block_copy(block));
+}
+
+void WKFrameGetResourceData_b(WKFrameRef frameRef, WKURLRef resourceURL, WKFrameGetResourceDataBlock block)
 {
-    WKFrameGetMainResourceData(frameRef, callGetMainResourceDataBlockAndDispose, Block_copy(block));
+    WKFrameGetResourceData(frameRef, resourceURL, callGetResourceDataBlockAndDispose, Block_copy(block));
 }
 #endif
 
index f812aeb..6538628 100644 (file)
@@ -68,11 +68,13 @@ WK_EXPORT bool WKFrameIsDisplayingMarkupDocument(WKFrameRef frame);
 
 WK_EXPORT bool WKFrameIsFrameSet(WKFrameRef frame);
 
-typedef void (*WKFrameGetMainResourceDataFunction)(WKDataRef data, WKErrorRef error, void* functionContext);
-WK_EXPORT void WKFrameGetMainResourceData(WKFrameRef frame, WKFrameGetMainResourceDataFunction function, void* functionContext);
+typedef void (*WKFrameGetResourceDataFunction)(WKDataRef data, WKErrorRef error, void* functionContext);
+WK_EXPORT void WKFrameGetMainResourceData(WKFrameRef frame, WKFrameGetResourceDataFunction function, void* functionContext);
+WK_EXPORT void WKFrameGetResourceData(WKFrameRef frame, WKURLRef resourceURL, WKFrameGetResourceDataFunction function, void* functionContext);
 #ifdef __BLOCKS__
-typedef void (^WKFrameGetMainResourceDataBlock)(WKDataRef data, WKErrorRef error);
-WK_EXPORT void WKFrameGetMainResourceData_b(WKFrameRef frame, WKFrameGetMainResourceDataBlock block);
+typedef void (^WKFrameGetResourceDataBlock)(WKDataRef data, WKErrorRef error);
+WK_EXPORT void WKFrameGetMainResourceData_b(WKFrameRef frame, WKFrameGetResourceDataBlock block);
+WK_EXPORT void WKFrameGetResourceData_b(WKFrameRef frame, WKURLRef resourceURL, WKFrameGetResourceDataBlock block);
 #endif
 
 typedef void (*WKFrameGetWebArchiveFunction)(WKDataRef archiveData, WKErrorRef error, void* functionContext);
index 9e9b4b7..77a2b19 100644 (file)
@@ -302,4 +302,14 @@ void WebFrameProxy::getMainResourceData(PassRefPtr<DataCallback> callback)
     m_page->getMainResourceDataOfFrame(this, callback);
 }
 
+void WebFrameProxy::getResourceData(WebURL* resourceURL, PassRefPtr<DataCallback> callback)
+{
+    if (!m_page) {
+        callback->invalidate();
+        return;
+    }
+
+    m_page->getResourceDataFromFrame(this, resourceURL, callback);
+}
+
 } // namespace WebKit
index 84c1eb8..ae97a78 100644 (file)
@@ -107,6 +107,7 @@ public:
 
     void getWebArchive(PassRefPtr<DataCallback>);
     void getMainResourceData(PassRefPtr<DataCallback>);
+    void getResourceData(WebURL*, PassRefPtr<DataCallback>);
 
     void didStartProvisionalLoad(const String& url);
     void didReceiveServerRedirectForProvisionalLoad(const String& url);
index ae01ad6..d012ce7 100644 (file)
@@ -965,6 +965,14 @@ void WebPageProxy::getMainResourceDataOfFrame(WebFrameProxy* frame, PassRefPtr<D
     process()->send(Messages::WebPage::GetMainResourceDataOfFrame(frame->frameID(), callbackID), m_pageID);
 }
 
+void WebPageProxy::getResourceDataFromFrame(WebFrameProxy* frame, WebURL* resourceURL, PassRefPtr<DataCallback> prpCallback)
+{
+    RefPtr<DataCallback> callback = prpCallback;
+    uint64_t callbackID = callback->callbackID();
+    m_dataCallbacks.set(callbackID, callback.get());
+    process()->send(Messages::WebPage::GetResourceDataFromFrame(frame->frameID(), resourceURL->string(), callbackID), m_pageID);
+}
+
 void WebPageProxy::getWebArchiveOfFrame(WebFrameProxy* frame, PassRefPtr<DataCallback> prpCallback)
 {
     RefPtr<DataCallback> callback = prpCallback;
index a1570a1..2435d7e 100644 (file)
@@ -266,6 +266,7 @@ public:
 
     void getContentsAsString(PassRefPtr<StringCallback>);
     void getMainResourceDataOfFrame(WebFrameProxy*, PassRefPtr<DataCallback>);
+    void getResourceDataFromFrame(WebFrameProxy*, WebURL*, PassRefPtr<DataCallback>);
     void getRenderTreeExternalRepresentation(PassRefPtr<StringCallback>);
     void getSelectionOrContentsAsString(PassRefPtr<StringCallback>);
     void getSourceForFrame(WebFrameProxy*, PassRefPtr<StringCallback>);
index 55f6eac..242d599 100644 (file)
@@ -1134,6 +1134,23 @@ void WebPage::getMainResourceDataOfFrame(uint64_t frameID, uint64_t callbackID)
     send(Messages::WebPageProxy::DataCallback(dataReference, callbackID));
 }
 
+void WebPage::getResourceDataFromFrame(uint64_t frameID, const String& resourceURL, uint64_t callbackID)
+{
+    CoreIPC::DataReference dataReference;
+
+    RefPtr<SharedBuffer> buffer;
+    if (WebFrame* frame = WebProcess::shared().webFrame(frameID)) {
+        if (DocumentLoader* loader = frame->coreFrame()->loader()->documentLoader()) {
+            if (RefPtr<ArchiveResource> subresource = loader->subresource(KURL(KURL(), resourceURL))) {
+                if (buffer = subresource->data())
+                    dataReference = CoreIPC::DataReference(reinterpret_cast<const uint8_t*>(buffer->data()), buffer->size());
+            }
+        }
+    }
+
+    send(Messages::WebPageProxy::DataCallback(dataReference, callbackID));
+}
+
 void WebPage::getWebArchiveOfFrame(uint64_t frameID, uint64_t callbackID)
 {
     CoreIPC::DataReference dataReference;
index 7649ab6..4618625 100644 (file)
@@ -364,6 +364,7 @@ private:
 
     void getContentsAsString(uint64_t callbackID);
     void getMainResourceDataOfFrame(uint64_t frameID, uint64_t callbackID);
+    void getResourceDataFromFrame(uint64_t frameID, const String& resourceURL, uint64_t callbackID);
     void getRenderTreeExternalRepresentation(uint64_t callbackID);
     void getSelectionOrContentsAsString(uint64_t callbackID);
     void getSourceForFrame(uint64_t frameID, uint64_t callbackID);
index bd6bf1a..c697c13 100644 (file)
@@ -56,6 +56,7 @@ messages -> WebPage {
     # Callbacks.
     GetContentsAsString(uint64_t callbackID)
     GetMainResourceDataOfFrame(uint64_t frameID, uint64_t callbackID)
+    GetResourceDataFromFrame(uint64_t frameID, WTF::String resourceURL, uint64_t callbackID)
     GetRenderTreeExternalRepresentation(uint64_t callbackID)
     GetSelectionOrContentsAsString(uint64_t callbackID)
     GetSourceForFrame(uint64_t frameID, uint64_t callbackID)