Commit 53329382 authored by beidson@apple.com's avatar beidson@apple.com
Browse files

<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

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: http://svn.webkit.org/repository/webkit/trunk@76087 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 7e17fdb5
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.
......@@ -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
......
......@@ -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);
......
......@@ -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
......@@ -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);
......
......@@ -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;
......
......@@ -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>);
......
......@@ -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;
......
......@@ -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);
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment