2010-12-21 Darin Adler <darin@apple.com>
authordarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Dec 2010 20:22:50 +0000 (20:22 +0000)
committerdarin@apple.com <darin@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 22 Dec 2010 20:22:50 +0000 (20:22 +0000)
        Reviewed by Brady Eidson and Sam Weinig.

        Add a way to get a web archive in WebKit2
        https://bugs.webkit.org/show_bug.cgi?id=51437

        * UIProcess/API/C/WKFrame.cpp:
        (WKFrameGetWebArchive): Added.
        (callGetWebArchiveBlockAndDispose): Added.
        (WKFrameGetWebArchive_b): Added.
        * UIProcess/API/C/WKFrame.h: Added functions above.
        * UIProcess/WebPageProxy.cpp:
        (WebKit::WebPageProxy::close): Clear out m_webArchiveCallbacks.
        (WebKit::WebPageProxy::getWebArchiveOfFrame): Added.
        (WebKit::WebPageProxy::didGetWebArchiveOfFrame): Added.
        (WebKit::WebPageProxy::processDidCrash): Clear out m_webArchiveCallbacks.
        * UIProcess/WebPageProxy.h: Added functions above.
        * UIProcess/WebPageProxy.messages.in: Added DidGetWebArchiveOfFrame.
        * WebProcess/WebPage/WebPage.cpp:
        (WebKit::WebPage::getWebArchiveOfFrame): Added.
        * WebProcess/WebPage/WebPage.h: Added function above.
        * WebProcess/WebPage/WebPage.messages.in: Added GetWebArchiveOfFrame.

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

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

index 97e0bb2381eb6c0fde5ab97fb5e0d4bbacfc25a9..7c75084dfccfc783c8f882e7e00617c071919924 100644 (file)
@@ -1,3 +1,27 @@
+2010-12-21  Darin Adler  <darin@apple.com>
+
+        Reviewed by Brady Eidson and Sam Weinig.
+
+        Add a way to get a web archive in WebKit2
+        https://bugs.webkit.org/show_bug.cgi?id=51437
+
+        * UIProcess/API/C/WKFrame.cpp:
+        (WKFrameGetWebArchive): Added.
+        (callGetWebArchiveBlockAndDispose): Added.
+        (WKFrameGetWebArchive_b): Added.
+        * UIProcess/API/C/WKFrame.h: Added functions above.
+        * UIProcess/WebPageProxy.cpp:
+        (WebKit::WebPageProxy::close): Clear out m_webArchiveCallbacks.
+        (WebKit::WebPageProxy::getWebArchiveOfFrame): Added.
+        (WebKit::WebPageProxy::didGetWebArchiveOfFrame): Added.
+        (WebKit::WebPageProxy::processDidCrash): Clear out m_webArchiveCallbacks.
+        * UIProcess/WebPageProxy.h: Added functions above.
+        * UIProcess/WebPageProxy.messages.in: Added DidGetWebArchiveOfFrame.
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::getWebArchiveOfFrame): Added.
+        * WebProcess/WebPage/WebPage.h: Added function above.
+        * WebProcess/WebPage/WebPage.messages.in: Added GetWebArchiveOfFrame.
+
 2010-12-21  Siddharth Mathur  <siddharth.mathur@nokia.com>
 
         Reviewed by Laszlo Gombos.
index 84acb4f01bd662440e5f697eb2acfaa553ee5df5..a5bc71d5b13b622cdc66258ea47bd239927c71ee 100644 (file)
 #include "WKAPICast.h"
 #include "WebFrameProxy.h"
 
+#ifdef __BLOCKS__
+#include <Block.h>
+#endif
+
 using namespace WebKit;
 
 WKTypeID WKFrameGetTypeID()
@@ -115,3 +119,22 @@ bool WKFrameIsFrameSet(WKFrameRef frameRef)
 {
     return toImpl(frameRef)->isFrameSet();
 }
+
+void WKFrameGetWebArchive(WKFrameRef frameRef, WKFrameGetWebArchiveFunction callback, void* context)
+{
+    toImpl(frameRef)->getWebArchive(WebArchiveCallback::create(context, callback));
+}
+
+#ifdef __BLOCKS__
+static void callGetWebArchiveBlockAndDispose(WKDataRef archiveData, WKErrorRef error, void* context)
+{
+    WKFrameGetWebArchiveBlock block = (WKFrameGetWebArchiveBlock)context;
+    block(archiveData, error);
+    Block_release(block);
+}
+
+void WKFrameGetWebArchive_b(WKFrameRef frameRef, WKFrameGetWebArchiveBlock block)
+{
+    WKFrameGetWebArchive(frameRef, callGetWebArchiveBlockAndDispose, Block_copy(block));
+}
+#endif
index 0784bf0952943722d011b6c4310833bf1484998e..2ab5c9f2afa6c192f464aa56c815760598aa7802 100644 (file)
@@ -66,6 +66,13 @@ WK_EXPORT bool WKFrameIsDisplayingMarkupDocument(WKFrameRef frame);
 
 WK_EXPORT bool WKFrameIsFrameSet(WKFrameRef frame);
 
+typedef void (*WKFrameGetWebArchiveFunction)(WKDataRef archiveData, WKErrorRef error, void* functionContext);
+WK_EXPORT void WKFrameGetWebArchive(WKFrameRef frame, WKFrameGetWebArchiveFunction function, void* functionContext);
+#ifdef __BLOCKS__
+typedef void (^WKFrameGetWebArchiveBlock)(WKDataRef archiveData, WKErrorRef error);
+WK_EXPORT void WKFrameGetWebArchive_b(WKFrameRef frame, WKFrameGetWebArchiveBlock block);
+#endif
+
 #ifdef __cplusplus
 }
 #endif
index 04e3b5283c5441d379adfc854075a577d2eeac3a..46d64ff526e464a90dff64efac69fe23d3dcd79e 100644 (file)
@@ -195,4 +195,14 @@ WebFormSubmissionListenerProxy* WebFrameProxy::setUpFormSubmissionListenerProxy(
     return static_cast<WebFormSubmissionListenerProxy*>(m_activeListener.get());
 }
 
+void WebFrameProxy::getWebArchive(PassRefPtr<WebArchiveCallback> callback)
+{
+    if (!m_page) {
+        callback->invalidate();
+        return;
+    }
+
+    m_page->getWebArchiveOfFrame(this, callback);
+}
+
 } // namespace WebKit
index 01a9233d2983cc40087194b5f6694860675455ea..e0159bbd3d2b7a8ed4e9cc9fc6d226211ac591c3 100644 (file)
@@ -27,6 +27,7 @@
 #define WebFrameProxy_h
 
 #include "APIObject.h"
+#include "GenericCallback.h"
 #include "WebFrameListenerProxy.h"
 #include <WebCore/FrameLoaderTypes.h>
 #include <wtf/Forward.h>
@@ -47,6 +48,8 @@ class WebFormSubmissionListenerProxy;
 class WebFramePolicyListenerProxy;
 class WebPageProxy;
 
+typedef GenericCallback<WKDataRef> WebArchiveCallback;
+
 class WebFrameProxy : public APIObject {
 public:
     static const Type APIType = TypeFrame;
@@ -95,6 +98,8 @@ public:
     bool isDisplayingStandaloneImageDocument() const;
     bool isDisplayingMarkupDocument() const;
 
+    void getWebArchive(PassRefPtr<WebArchiveCallback>);
+
     void didStartProvisionalLoad(const String& url);
     void didReceiveServerRedirectForProvisionalLoad(const String& url);
     void didFailProvisionalLoad();
index bef2e2d982577815d5da7fc0043b237b2eff13f3..abd6add1510eeaf0581ba6dae4191ab5ec4b8123 100644 (file)
@@ -249,6 +249,7 @@ void WebPageProxy::close()
     invalidateCallbackMap(m_frameSourceCallbacks);
     invalidateCallbackMap(m_renderTreeExternalRepresentationCallbacks);
     invalidateCallbackMap(m_scriptReturnValueCallbacks);
+    invalidateCallbackMap(m_webArchiveCallbacks);
 
     Vector<WebEditCommandProxy*> editCommandVector;
     copyToVector(m_editCommandSet, editCommandVector);
@@ -815,6 +816,14 @@ void WebPageProxy::getContentsAsString(PassRefPtr<ContentsAsStringCallback> prpC
     process()->send(Messages::WebPage::GetContentsAsString(callbackID), m_pageID);
 }
 
+void WebPageProxy::getWebArchiveOfFrame(WebFrameProxy* frame, PassRefPtr<WebArchiveCallback> prpCallback)
+{
+    RefPtr<WebArchiveCallback> callback = prpCallback;
+    uint64_t callbackID = callback->callbackID();
+    m_webArchiveCallbacks.set(callbackID, callback.get());
+    process()->send(Messages::WebPage::GetWebArchiveOfFrame(frame->frameID(), callbackID), m_pageID);
+}
+
 void WebPageProxy::preferencesDidChange()
 {
     if (!isValid())
@@ -1746,6 +1755,21 @@ void WebPageProxy::didGetSourceForFrame(const String& resultString, uint64_t cal
     callback->performCallbackWithReturnValue(resultString.impl());
 }
 
+void WebPageProxy::didGetWebArchiveOfFrame(const CoreIPC::DataReference& dataReference, uint64_t callbackID)
+{
+    RefPtr<WebArchiveCallback> callback = m_webArchiveCallbacks.take(callbackID);
+    if (!callback) {
+        // FIXME: Log error or assert.
+        return;
+    }
+
+    RefPtr<WebData> data;
+    if (size_t size = dataReference.size())
+        data = WebData::create(dataReference.data(), size);
+
+    callback->performCallbackWithReturnValue(data.get());
+}
+
 void WebPageProxy::focusedFrameChanged(uint64_t frameID)
 {
     m_focusedFrame = frameID ? process()->webFrame(frameID) : 0;
@@ -1802,6 +1826,7 @@ void WebPageProxy::processDidCrash()
     invalidateCallbackMap(m_frameSourceCallbacks);
     invalidateCallbackMap(m_renderTreeExternalRepresentationCallbacks);
     invalidateCallbackMap(m_scriptReturnValueCallbacks);
+    invalidateCallbackMap(m_webArchiveCallbacks);
 
     Vector<WebEditCommandProxy*> editCommandVector;
     copyToVector(m_editCommandSet, editCommandVector);
index 49866cf53351c40cc441631c9cdde1e7ea546520..18c191ab03deef03533b1cd1c63148607df235d9 100644 (file)
@@ -28,7 +28,6 @@
 
 #include "APIObject.h"
 #include "DrawingAreaProxy.h"
-#include "GenericCallback.h"
 #include "SharedMemory.h"
 #include "WKBase.h"
 #include "WebContextMenuItemData.h"
@@ -245,6 +244,7 @@ public:
     void getRenderTreeExternalRepresentation(PassRefPtr<RenderTreeExternalRepresentationCallback>);
     void getSourceForFrame(WebFrameProxy*, PassRefPtr<FrameSourceCallback>);
     void getContentsAsString(PassRefPtr<ContentsAsStringCallback>);
+    void getWebArchiveOfFrame(WebFrameProxy*, PassRefPtr<WebArchiveCallback>);
 
     void receivedPolicyDecision(WebCore::PolicyAction, WebFrameProxy*, uint64_t listenerID);
 
@@ -424,6 +424,7 @@ private:
     void didRunJavaScriptInMainFrame(const String&, uint64_t);
     void didGetRenderTreeExternalRepresentation(const String&, uint64_t);
     void didGetSourceForFrame(const String&, uint64_t);
+    void didGetWebArchiveOfFrame(const CoreIPC::DataReference&, uint64_t);
 
     void focusedFrameChanged(uint64_t frameID);
 
@@ -470,6 +471,7 @@ private:
     HashMap<uint64_t, RefPtr<FrameSourceCallback> > m_frameSourceCallbacks;
     HashMap<uint64_t, RefPtr<RenderTreeExternalRepresentationCallback> > m_renderTreeExternalRepresentationCallbacks;
     HashMap<uint64_t, RefPtr<ScriptReturnValueCallback> > m_scriptReturnValueCallbacks;
+    HashMap<uint64_t, RefPtr<WebArchiveCallback> > m_webArchiveCallbacks;
 
     HashSet<WebEditCommandProxy*> m_editCommandSet;
 
index 61681234244b25531fa60a6823513f0c273eb9a9..6da2f0368f0df9673254ce1cbe5072a5a8df015f 100644 (file)
@@ -111,6 +111,7 @@ messages -> WebPageProxy {
     DidGetContentsAsString(WTF::String resultString, uint64_t callbackID)
     DidGetRenderTreeExternalRepresentation(WTF::String resultString, uint64_t callbackID)
     DidGetSourceForFrame(WTF::String resultString, uint64_t callbackID)
+    DidGetWebArchiveOfFrame(CoreIPC::DataReference archiveData, uint64_t callbackID)
     DidRunJavaScriptInMainFrame(WTF::String resultString, uint64_t callbackID)
 
 #if PLATFORM(MAC)
index bf8dc7142da107f0a24901a186acbc8e05e97412..6df0ebfdc3ff18399f1fbf384bd9044e63bdba4d 100644 (file)
@@ -26,6 +26,7 @@
 #include "WebPage.h"
 
 #include "Arguments.h"
+#include "DataReference.h"
 #include "DrawingArea.h"
 #include "InjectedBundle.h"
 #include "InjectedBundleBackForwardList.h"
 #include <runtime/JSLock.h>
 #include <runtime/JSValue.h>
 
+#if PLATFORM(MAC) || PLATFORM(WIN)
+#include <WebCore/LegacyWebArchive.h>
+#endif
+
 #if ENABLE(PLUGIN_PROCESS)
 // FIXME: This is currently Mac-specific!
 #include "MachPort.h"
@@ -930,6 +935,23 @@ void WebPage::getSourceForFrame(uint64_t frameID, uint64_t callbackID)
     send(Messages::WebPageProxy::DidGetSourceForFrame(resultString, callbackID));
 }
 
+void WebPage::getWebArchiveOfFrame(uint64_t frameID, uint64_t callbackID)
+{
+    CoreIPC::DataReference dataReference;
+
+#if PLATFORM(MAC) || PLATFORM(WIN)
+    RetainPtr<CFDataRef> data;
+    if (WebFrame* frame = WebProcess::shared().webFrame(frameID)) {
+        if (RefPtr<LegacyWebArchive> archive = LegacyWebArchive::create(frame->coreFrame())) {
+            if ((data = archive->rawDataRepresentation()))
+                dataReference = CoreIPC::DataReference(CFDataGetBytePtr(data.get()), CFDataGetLength(data.get()));
+        }
+    }
+#endif
+
+    send(Messages::WebPageProxy::DidGetWebArchiveOfFrame(dataReference, callbackID));
+}
+
 void WebPage::preferencesDidChange(const WebPreferencesStore& store)
 {
     WebPreferencesStore::removeTestRunnerOverrides();
index 3339c3d87c6dcc771cc020ad580420bc85e63fbe..cacfd0ba59efe43255618f69a7dd3e40ca52f830 100644 (file)
@@ -310,6 +310,7 @@ private:
     void getContentsAsString(uint64_t callbackID);
     void getRenderTreeExternalRepresentation(uint64_t callbackID);
     void getSourceForFrame(uint64_t frameID, uint64_t callbackID);
+    void getWebArchiveOfFrame(uint64_t frameID, uint64_t callbackID);
     void runJavaScriptInMainFrame(const String&, uint64_t callbackID);
 
     void preferencesDidChange(const WebPreferencesStore&);
index b898c14801ff76fda3db9e2a012ed77964724f93..37b860f7d2d2753e07530eae6dd0eb29d80df6f6 100644 (file)
@@ -53,6 +53,7 @@ messages -> WebPage {
     GetRenderTreeExternalRepresentation(uint64_t callbackID)
     GetContentsAsString(uint64_t callbackID)
     GetSourceForFrame(uint64_t frameID, uint64_t callbackID)
+    GetWebArchiveOfFrame(uint64_t frameID, uint64_t callbackID)
     RunJavaScriptInMainFrame(WTF::String script, uint64_t callbackID)
 
     PreferencesDidChange(WebKit::WebPreferencesStore store)