Source/WebKit2: Implement WKBundleFrameCopyWebArchive().
authoradachan@apple.com <adachan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Sep 2011 21:29:41 +0000 (21:29 +0000)
committeradachan@apple.com <adachan@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 14 Sep 2011 21:29:41 +0000 (21:29 +0000)
http://bugs.webkit.org/show_bug.cgi?id=67857

Reviewed by Anders Carlsson.

* WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp:
(WKBundleFrameCopyWebArchive): Call WebFrame::webArchiveData() and create a WKDataRef from the returned CFDataRef.
* WebProcess/InjectedBundle/API/c/WKBundleFrame.h:
* WebProcess/WebPage/WebFrame.cpp:
(WebKit::WebFrame::webArchiveData): Add WebFrame::webArchiveData().
* WebProcess/WebPage/WebFrame.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::getWebArchiveOfFrame): Move the logic to WebFrame::webArchiveData() and call that method here.

Tools: Add test for WKBundleFrameCopyWebArchive().
https://bugs.webkit.org/show_bug.cgi?id=67857

Reviewed by Anders Carlsson.

* TestWebKitAPI/Tests/WebKit2/WebArchive.cpp: Added.
(TestWebKitAPI::didReceiveMessageFromInjectedBundle): Do some basic sanity checks to make sure
the returned data is a valid webarchive.
(TestWebKitAPI::setInjectedBundleClient):
(TestWebKitAPI::didFinishLoadForFrame):
(TestWebKitAPI::TEST): Load simple.html in a WebView.  Wait for it to finish loading, and then ask the
injected bundle for the webarchive and check the returned webarchive.
* TestWebKitAPI/Tests/WebKit2/WebArchive_Bundle.cpp: Added.
(TestWebKitAPI::WebArchiveTest::WebArchiveTest):
(TestWebKitAPI::WebArchiveTest::didReceiveMessage): Handle the "GetWebArchive" message and return
the web archive.

Add files to project.
* TestWebKitAPI/win/TestWebKitAPI.vcproj: Also let Visual Studio reorder a file.
* TestWebKitAPI/win/TestWebKitAPIInjectedBundle.vcproj:
* TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:

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

12 files changed:
Source/WebKit2/ChangeLog
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp
Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.h
Source/WebKit2/WebProcess/WebPage/WebFrame.cpp
Source/WebKit2/WebProcess/WebPage/WebFrame.h
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Tools/ChangeLog
Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
Tools/TestWebKitAPI/Tests/WebKit2/WebArchive.cpp [new file with mode: 0644]
Tools/TestWebKitAPI/Tests/WebKit2/WebArchive_Bundle.cpp [new file with mode: 0644]
Tools/TestWebKitAPI/win/TestWebKitAPI.vcproj
Tools/TestWebKitAPI/win/TestWebKitAPIInjectedBundle.vcproj

index 96b8885..058ede6 100644 (file)
@@ -1,3 +1,19 @@
+2011-09-14  Ada Chan  <adachan@apple.com>
+
+        Implement WKBundleFrameCopyWebArchive().
+        http://bugs.webkit.org/show_bug.cgi?id=67857
+
+        Reviewed by Anders Carlsson.
+
+        * WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp:
+        (WKBundleFrameCopyWebArchive): Call WebFrame::webArchiveData() and create a WKDataRef from the returned CFDataRef.
+        * WebProcess/InjectedBundle/API/c/WKBundleFrame.h:
+        * WebProcess/WebPage/WebFrame.cpp:
+        (WebKit::WebFrame::webArchiveData): Add WebFrame::webArchiveData().
+        * WebProcess/WebPage/WebFrame.h:
+        * WebProcess/WebPage/WebPage.cpp:
+        (WebKit::WebPage::getWebArchiveOfFrame): Move the logic to WebFrame::webArchiveData() and call that method here.
+
 2011-09-14  Alexey Proskuryakov  <ap@apple.com>
 
         Web Process doesn't need a permission to look up WebProcess service any more
index 5455e60..d6d1bb3 100644 (file)
@@ -29,6 +29,7 @@
 
 #include "WKAPICast.h"
 #include "WKBundleAPICast.h"
+#include "WKData.h"
 #include "WebFrame.h"
 #include <WebCore/Frame.h>
 #include <WebCore/FrameView.h>
@@ -240,3 +241,14 @@ void WKBundleFrameSetTextDirection(WKBundleFrameRef frameRef, WKStringRef direct
 {
     toImpl(frameRef)->setTextDirection(toImpl(directionRef)->string());
 }
+
+WKDataRef WKBundleFrameCopyWebArchive(WKBundleFrameRef frameRef)
+{
+#if PLATFORM(MAC) || PLATFORM(WIN)
+    RetainPtr<CFDataRef> data = toImpl(frameRef)->webArchiveData();
+    if (data)
+        return WKDataCreate(CFDataGetBytePtr(data.get()), CFDataGetLength(data.get()));
+#endif
+    
+    return 0;
+}
index 727ea53..ce94bad 100644 (file)
@@ -70,6 +70,8 @@ WK_EXPORT bool WKBundleFrameGetDocumentBackgroundColor(WKBundleFrameRef frame, d
 
 WK_EXPORT WKStringRef WKBundleFrameCopySuggestedFilenameForResourceWithURL(WKBundleFrameRef frame, WKURLRef url);
 WK_EXPORT WKStringRef WKBundleFrameCopyMIMETypeForResourceWithURL(WKBundleFrameRef frame, WKURLRef url);
+    
+WK_EXPORT WKDataRef WKBundleFrameCopyWebArchive(WKBundleFrameRef frame);
 
 #ifdef __cplusplus
 }
index 92aadc6..45feab1 100644 (file)
 #include <WebCore/TextResourceDecoder.h>
 #include <wtf/text/StringBuilder.h>
 
+#if PLATFORM(MAC) || PLATFORM(WIN)
+#include <WebCore/LegacyWebArchive.h>
+#endif
+
 #ifndef NDEBUG
 #include <wtf/RefCountedLeakCounter.h>
 #endif
@@ -723,4 +727,14 @@ void WebFrame::setTextDirection(const String& direction)
         m_coreFrame->editor()->setBaseWritingDirection(RightToLeftWritingDirection);
 }
 
+#if PLATFORM(MAC) || PLATFORM(WIN)
+RetainPtr<CFDataRef> WebFrame::webArchiveData() const
+{
+    if (RefPtr<LegacyWebArchive> archive = LegacyWebArchive::create(coreFrame()->document()))
+        return archive->rawDataRepresentation();
+    
+    return 0;
+}
+#endif
+    
 } // namespace WebKit
index 975712d..633634c 100644 (file)
@@ -133,6 +133,10 @@ public:
     };
     void setLoadListener(LoadListener* loadListener) { m_loadListener = loadListener; }
     LoadListener* loadListener() const { return m_loadListener; }
+    
+#if PLATFORM(MAC) || PLATFORM(WIN)
+    RetainPtr<CFDataRef> webArchiveData() const;
+#endif
 
 private:
     static PassRefPtr<WebFrame> create();
index 6e9382b..e2d67fc 100644 (file)
 #include <WebCore/Range.h>
 #include <WebCore/VisiblePosition.h>
 
-#if PLATFORM(MAC) || PLATFORM(WIN)
-#include <WebCore/LegacyWebArchive.h>
-#endif
-
 #if ENABLE(PLUGIN_PROCESS)
 #if PLATFORM(MAC)
 #include "MachPort.h"
@@ -1497,10 +1493,8 @@ void WebPage::getWebArchiveOfFrame(uint64_t frameID, uint64_t callbackID)
 #if PLATFORM(MAC) || PLATFORM(WIN)
     RetainPtr<CFDataRef> data;
     if (WebFrame* frame = WebProcess::shared().webFrame(frameID)) {
-        if (RefPtr<LegacyWebArchive> archive = LegacyWebArchive::create(frame->coreFrame()->document())) {
-            if ((data = archive->rawDataRepresentation()))
-                dataReference = CoreIPC::DataReference(CFDataGetBytePtr(data.get()), CFDataGetLength(data.get()));
-        }
+        if ((data = frame->webArchiveData()))
+            dataReference = CoreIPC::DataReference(CFDataGetBytePtr(data.get()), CFDataGetLength(data.get()));
     }
 #endif
 
index be0df92..b6af7da 100644 (file)
@@ -1,3 +1,27 @@
+2011-09-14  Ada Chan  <adachan@apple.com>
+
+        Add test for WKBundleFrameCopyWebArchive().
+        https://bugs.webkit.org/show_bug.cgi?id=67857
+
+        Reviewed by Anders Carlsson.
+
+        * TestWebKitAPI/Tests/WebKit2/WebArchive.cpp: Added.
+        (TestWebKitAPI::didReceiveMessageFromInjectedBundle): Do some basic sanity checks to make sure
+        the returned data is a valid webarchive.
+        (TestWebKitAPI::setInjectedBundleClient):
+        (TestWebKitAPI::didFinishLoadForFrame):
+        (TestWebKitAPI::TEST): Load simple.html in a WebView.  Wait for it to finish loading, and then ask the
+        injected bundle for the webarchive and check the returned webarchive.
+        * TestWebKitAPI/Tests/WebKit2/WebArchive_Bundle.cpp: Added.
+        (TestWebKitAPI::WebArchiveTest::WebArchiveTest):
+        (TestWebKitAPI::WebArchiveTest::didReceiveMessage): Handle the "GetWebArchive" message and return
+        the web archive.
+
+        Add files to project.
+        * TestWebKitAPI/win/TestWebKitAPI.vcproj: Also let Visual Studio reorder a file.
+        * TestWebKitAPI/win/TestWebKitAPIInjectedBundle.vcproj:
+        * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+
 2011-09-14  Ryosuke Niwa  <rniwa@webkit.org>
 
         committers.py should support multiple IRC nicknames
index 9eff04c..fa1d023 100644 (file)
@@ -29,6 +29,8 @@
                37DC6791140D7D7600ABCCDB /* DOMRangeOfString.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = 37DC678F140D7D3A00ABCCDB /* DOMRangeOfString.html */; };
                4BFDFFA71314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BFDFFA61314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp */; };
                4BFDFFA9131477770061F24B /* HitTestResultNodeHandle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BFDFFA8131477770061F24B /* HitTestResultNodeHandle.cpp */; };
+               520BCF4C141EB09E00937EA8 /* WebArchive_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 520BCF4A141EB09E00937EA8 /* WebArchive_Bundle.cpp */; };
+               520BCF4D141EB09E00937EA8 /* WebArchive.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 520BCF4B141EB09E00937EA8 /* WebArchive.cpp */; };
                939BA91714103412001A01BD /* DeviceScaleFactorOnBack.mm in Sources */ = {isa = PBXBuildFile; fileRef = 939BA91614103412001A01BD /* DeviceScaleFactorOnBack.mm */; };
                A7A966DB140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A7A966DA140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp */; };
                BC131885117114B600B69727 /* PlatformUtilitiesMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC131884117114B600B69727 /* PlatformUtilitiesMac.mm */; };
                37DC678F140D7D3A00ABCCDB /* DOMRangeOfString.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = DOMRangeOfString.html; sourceTree = "<group>"; };
                4BFDFFA61314776C0061F24B /* HitTestResultNodeHandle_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HitTestResultNodeHandle_Bundle.cpp; sourceTree = "<group>"; };
                4BFDFFA8131477770061F24B /* HitTestResultNodeHandle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = HitTestResultNodeHandle.cpp; sourceTree = "<group>"; };
+               520BCF4A141EB09E00937EA8 /* WebArchive_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebArchive_Bundle.cpp; sourceTree = "<group>"; };
+               520BCF4B141EB09E00937EA8 /* WebArchive.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebArchive.cpp; sourceTree = "<group>"; };
                8DD76FA10486AA7600D96B5E /* TestWebKitAPI */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = TestWebKitAPI; sourceTree = BUILT_PRODUCTS_DIR; };
                939BA91614103412001A01BD /* DeviceScaleFactorOnBack.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DeviceScaleFactorOnBack.mm; sourceTree = "<group>"; };
                A7A966DA140ECCC8005EF9B4 /* CheckedArithmeticOperations.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = CheckedArithmeticOperations.cpp; path = WTF/CheckedArithmeticOperations.cpp; sourceTree = "<group>"; };
                                BC7B619A1299FE9E00D174A4 /* WKPreferences.cpp */,
                                BC90995D12567BC100083756 /* WKString.cpp */,
                                BC9099931256ACF100083756 /* WKStringJSString.cpp */,
+                               520BCF4A141EB09E00937EA8 /* WebArchive_Bundle.cpp */,
+                               520BCF4B141EB09E00937EA8 /* WebArchive.cpp */,
                        );
                        path = WebKit2;
                        sourceTree = "<group>";
                                939BA91714103412001A01BD /* DeviceScaleFactorOnBack.mm in Sources */,
                                3799AD3A14120A43005EB0C6 /* StringByEvaluatingJavaScriptFromString.mm in Sources */,
                                33DC8911141953A300747EF7 /* LoadCanceledNoServerRedirectCallback.cpp in Sources */,
+                               520BCF4D141EB09E00937EA8 /* WebArchive.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                33BE5AF9137B5AAE00705813 /* MouseMoveAfterCrash_Bundle.cpp in Sources */,
                                1AEDE22613E5E7E700E62FE8 /* InjectedBundleControllerMac.mm in Sources */,
                                33DC89141419579F00747EF7 /* LoadCanceledNoServerRedirectCallback_Bundle.cpp in Sources */,
+                               520BCF4C141EB09E00937EA8 /* WebArchive_Bundle.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WebArchive.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WebArchive.cpp
new file mode 100644 (file)
index 0000000..4f28e5c
--- /dev/null
@@ -0,0 +1,127 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "PlatformUtilities.h"
+#include "PlatformWebView.h"
+#include <CoreFoundation/CoreFoundation.h>
+#include <WebKit2/WKURLCF.h>
+#include <WebKit2/WKContextPrivate.h>
+#include <wtf/RetainPtr.h>
+
+namespace TestWebKitAPI {
+
+static bool didFinishLoad;
+static bool didReceiveMessage;
+    
+static void didReceiveMessageFromInjectedBundle(WKContextRef, WKStringRef messageName, WKTypeRef body, const void*)
+{
+    didReceiveMessage = true;
+
+    EXPECT_WK_STREQ("DidGetWebArchive", messageName);
+    EXPECT_TRUE(body);
+    EXPECT_EQ(WKDataGetTypeID(), WKGetTypeID(body));
+    WKDataRef receivedData = static_cast<WKDataRef>(body);
+        
+    // Do basic sanity checks on the returned webarchive. We have more thorough checks in LayoutTests.
+    size_t size = WKDataGetSize(receivedData);
+    const unsigned char* bytes = WKDataGetBytes(receivedData);
+    RetainPtr<CFDataRef> data(AdoptCF, CFDataCreate(0, bytes, size));
+    CFPropertyListFormat format = kCFPropertyListXMLFormat_v1_0 | kCFPropertyListBinaryFormat_v1_0;
+    RetainPtr<CFPropertyListRef> propertyList(AdoptCF, CFPropertyListCreateWithData(0, data.get(), kCFPropertyListImmutable, &format, 0));
+    EXPECT_TRUE(propertyList);
+    
+    // It should be a dictionary.
+    EXPECT_EQ(CFDictionaryGetTypeID(), CFGetTypeID(propertyList.get()));
+    CFDictionaryRef dictionary = (CFDictionaryRef)propertyList.get();
+    
+    // It should have a main resource.
+    CFTypeRef mainResource = CFDictionaryGetValue(dictionary, CFSTR("WebMainResource"));
+    EXPECT_TRUE(mainResource);
+    EXPECT_EQ(CFDictionaryGetTypeID(), CFGetTypeID(mainResource));
+    CFDictionaryRef mainResourceDictionary = (CFDictionaryRef)mainResource;
+    
+    // Main resource should have a non-empty url and mime type.
+    CFTypeRef url = CFDictionaryGetValue(mainResourceDictionary, CFSTR("WebResourceURL"));
+    EXPECT_TRUE(url);
+    EXPECT_EQ(CFStringGetTypeID(), CFGetTypeID(url));
+    EXPECT_NE(CFStringGetLength((CFStringRef)url), 0);
+    
+    CFTypeRef mimeType = CFDictionaryGetValue(mainResourceDictionary, CFSTR("WebResourceMIMEType"));
+    EXPECT_TRUE(mimeType);
+    EXPECT_EQ(CFStringGetTypeID(), CFGetTypeID(mimeType));
+    EXPECT_NE(CFStringGetLength((CFStringRef)mimeType), 0);
+    
+    // Main resource dictionary should have a "WebResourceData" key.
+    CFTypeRef resourceData = CFDictionaryGetValue(mainResourceDictionary, CFSTR("WebResourceData"));
+    EXPECT_TRUE(resourceData);
+    EXPECT_EQ(CFDataGetTypeID(), CFGetTypeID(resourceData));
+    
+    RetainPtr<CFStringRef> stringData(AdoptCF, CFStringCreateFromExternalRepresentation(0, (CFDataRef)resourceData, kCFStringEncodingUTF8));
+    EXPECT_TRUE(stringData);
+    
+    // It should contain the string "Simple HTML file." in it.
+    bool foundString = CFStringFind(stringData.get(), CFSTR("Simple HTML file."), 0).location != kCFNotFound;
+    EXPECT_TRUE(foundString);
+}
+
+static void setInjectedBundleClient(WKContextRef context)
+{
+    WKContextInjectedBundleClient injectedBundleClient;
+    memset(&injectedBundleClient, 0, sizeof(injectedBundleClient));
+    injectedBundleClient.didReceiveMessageFromInjectedBundle = didReceiveMessageFromInjectedBundle;
+
+    WKContextSetInjectedBundleClient(context, &injectedBundleClient);
+}
+
+static void didFinishLoadForFrame(WKPageRef page, WKFrameRef, WKTypeRef, const void*)
+{
+    didFinishLoad = true;
+}
+
+TEST(WebKit2, WebArchive)
+{
+    WKRetainPtr<WKContextRef> context = adoptWK(Util::createContextForInjectedBundleTest("WebArchiveTest"));
+    setInjectedBundleClient(context.get());
+
+    PlatformWebView webView(context.get());
+
+    WKPageLoaderClient loaderClient;
+    memset(&loaderClient, 0, sizeof(loaderClient));
+    
+    loaderClient.version = kWKPageLoaderClientCurrentVersion;
+    loaderClient.didFinishLoadForFrame = didFinishLoadForFrame;
+    WKPageSetPageLoaderClient(webView.page(), &loaderClient);
+
+    WKPageLoadURL(webView.page(), adoptWK(Util::createURLForResource("simple", "html")).get());
+
+    // Wait till the load finishes before getting the web archive.
+    Util::run(&didFinishLoad);
+    WKContextPostMessageToInjectedBundle(context.get(), Util::toWK("GetWebArchive").get(), webView.page());
+
+    // Wait till we have received the web archive from the injected bundle.
+    Util::run(&didReceiveMessage);
+}
+
+} // namespace TestWebKitAPI
diff --git a/Tools/TestWebKitAPI/Tests/WebKit2/WebArchive_Bundle.cpp b/Tools/TestWebKitAPI/Tests/WebKit2/WebArchive_Bundle.cpp
new file mode 100644 (file)
index 0000000..4a35b6a
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "InjectedBundleTest.h"
+
+#include "PlatformUtilities.h"
+#include <WebKit2/WKBundlePage.h>
+#include <WebKit2/WKBundleFrame.h>
+
+namespace TestWebKitAPI {
+
+class WebArchiveTest : public InjectedBundleTest {
+public:
+    WebArchiveTest(const std::string& identifier);
+
+private:
+    virtual void didReceiveMessage(WKBundleRef, WKStringRef messageName, WKTypeRef messageBody);
+};
+
+static InjectedBundleTest::Register<WebArchiveTest> registrar("WebArchiveTest");
+
+WebArchiveTest::WebArchiveTest(const std::string& identifier)
+    : InjectedBundleTest(identifier)
+{
+}
+
+void WebArchiveTest::didReceiveMessage(WKBundleRef bundle, WKStringRef messageName, WKTypeRef body)
+{
+    if (!WKStringIsEqualToUTF8CString(messageName, "GetWebArchive"))
+        return;
+
+    if (WKGetTypeID(body) != WKBundlePageGetTypeID())
+        return;
+    
+    WKBundleFrameRef frame = WKBundlePageGetMainFrame(static_cast<WKBundlePageRef>(body));
+    if (!frame)
+        return;
+    WKBundlePostMessage(bundle, Util::toWK("DidGetWebArchive").get(), adoptWK(WKBundleFrameCopyWebArchive(frame)).get());
+}
+
+} // namespace TestWebKitAPI
index b55c035..aabb50f 100644 (file)
                        Name="win"
                        >
                        <File
-                               RelativePath=".\main.cpp"
+                               RelativePath=".\InjectedBundleControllerWin.cpp"
                                >
                        </File>
                        <File
-                               RelativePath=".\PlatformUtilitiesWin.cpp"
+                               RelativePath=".\main.cpp"
                                >
                        </File>
                        <File
-                               RelativePath=".\PlatformWebViewWin.cpp"
+                               RelativePath=".\PlatformUtilitiesWin.cpp"
                                >
                        </File>
                        <File
-                               RelativePath=".\InjectedBundleControllerWin.cpp"
+                               RelativePath=".\PlatformWebViewWin.cpp"
                                >
                        </File>
                        <File
                                        >
                                </File>
                                <File
+                                       RelativePath="..\Tests\WebKit2\WebArchive.cpp"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\Tests\WebKit2\WKPreferences.cpp"
                                        >
                                </File>
index 61195cd..b05ca83 100644 (file)
                                        RelativePath="..\Tests\WebKit2\ResponsivenessTimerDoesntFireEarly_Bundle.cpp"
                                        >
                                </File>
+                               <File
+                                       RelativePath="..\Tests\WebKit2\WebArchive_Bundle.cpp"
+                                       >
+                               </File>
                        </Filter>
                </Filter>
                <File