Title: [95122] trunk
Revision
95122
Author
[email protected]
Date
2011-09-14 14:29:41 -0700 (Wed, 14 Sep 2011)

Log Message

Source/WebKit2: 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.

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:

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (95121 => 95122)


--- trunk/Source/WebKit2/ChangeLog	2011-09-14 21:15:56 UTC (rev 95121)
+++ trunk/Source/WebKit2/ChangeLog	2011-09-14 21:29:41 UTC (rev 95122)
@@ -1,3 +1,19 @@
+2011-09-14  Ada Chan  <[email protected]>
+
+        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  <[email protected]>
 
         Web Process doesn't need a permission to look up WebProcess service any more

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp (95121 => 95122)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp	2011-09-14 21:15:56 UTC (rev 95121)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.cpp	2011-09-14 21:29:41 UTC (rev 95122)
@@ -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 @@
 {
     toImpl(frameRef)->setTextDirection(toImpl(directionRef)->string());
 }
+
+WKDataRef WKBundleFrameCopyWebArchive(WKBundleFrameRef frameRef)
+{
+#if PLATFORM(MAC) || PLATFORM(WIN)
+    RetainPtr<CFDataRef> data = ""
+    if (data)
+        return WKDataCreate(CFDataGetBytePtr(data.get()), CFDataGetLength(data.get()));
+#endif
+    
+    return 0;
+}

Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.h (95121 => 95122)


--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.h	2011-09-14 21:15:56 UTC (rev 95121)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundleFrame.h	2011-09-14 21:29:41 UTC (rev 95122)
@@ -70,6 +70,8 @@
 
 WK_EXPORT WKStringRef WKBundleFrameCopySuggestedFilenameForResourceWithURL(WKBundleFrameRef frame, WKURLRef url);
 WK_EXPORT WKStringRef WKBundleFrameCopyMIMETypeForResourceWithURL(WKBundleFrameRef frame, WKURLRef url);
+    
+WK_EXPORT WKDataRef WKBundleFrameCopyWebArchive(WKBundleFrameRef frame);
 
 #ifdef __cplusplus
 }

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebFrame.cpp (95121 => 95122)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebFrame.cpp	2011-09-14 21:15:56 UTC (rev 95121)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebFrame.cpp	2011-09-14 21:29:41 UTC (rev 95122)
@@ -57,6 +57,10 @@
 #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 @@
         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

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebFrame.h (95121 => 95122)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebFrame.h	2011-09-14 21:15:56 UTC (rev 95121)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebFrame.h	2011-09-14 21:29:41 UTC (rev 95122)
@@ -133,6 +133,10 @@
     };
     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();

Modified: trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp (95121 => 95122)


--- trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2011-09-14 21:15:56 UTC (rev 95121)
+++ trunk/Source/WebKit2/WebProcess/WebPage/WebPage.cpp	2011-09-14 21:29:41 UTC (rev 95122)
@@ -112,10 +112,6 @@
 #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 @@
 #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 = ""
-                dataReference = CoreIPC::DataReference(CFDataGetBytePtr(data.get()), CFDataGetLength(data.get()));
-        }
+        if ((data = ""
+            dataReference = CoreIPC::DataReference(CFDataGetBytePtr(data.get()), CFDataGetLength(data.get()));
     }
 #endif
 

Modified: trunk/Tools/ChangeLog (95121 => 95122)


--- trunk/Tools/ChangeLog	2011-09-14 21:15:56 UTC (rev 95121)
+++ trunk/Tools/ChangeLog	2011-09-14 21:29:41 UTC (rev 95122)
@@ -1,3 +1,27 @@
+2011-09-14  Ada Chan  <[email protected]>
+
+        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  <[email protected]>
 
         committers.py should support multiple IRC nicknames

Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (95121 => 95122)


--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2011-09-14 21:15:56 UTC (rev 95121)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj	2011-09-14 21:29:41 UTC (rev 95122)
@@ -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 */; };
@@ -153,6 +155,8 @@
 		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>"; };
@@ -364,6 +368,8 @@
 				BC7B619A1299FE9E00D174A4 /* WKPreferences.cpp */,
 				BC90995D12567BC100083756 /* WKString.cpp */,
 				BC9099931256ACF100083756 /* WKStringJSString.cpp */,
+				520BCF4A141EB09E00937EA8 /* WebArchive_Bundle.cpp */,
+				520BCF4B141EB09E00937EA8 /* WebArchive.cpp */,
 			);
 			path = WebKit2;
 			sourceTree = "<group>";
@@ -589,6 +595,7 @@
 				939BA91714103412001A01BD /* DeviceScaleFactorOnBack.mm in Sources */,
 				3799AD3A14120A43005EB0C6 /* StringByEvaluatingJavaScriptFromString.mm in Sources */,
 				33DC8911141953A300747EF7 /* LoadCanceledNoServerRedirectCallback.cpp in Sources */,
+				520BCF4D141EB09E00937EA8 /* WebArchive.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -608,6 +615,7 @@
 				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;
 		};

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/WebArchive.cpp (0 => 95122)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/WebArchive.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/WebArchive.cpp	2011-09-14 21:29:41 UTC (rev 95122)
@@ -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 = "" 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

Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/WebArchive_Bundle.cpp (0 => 95122)


--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/WebArchive_Bundle.cpp	                        (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/WebArchive_Bundle.cpp	2011-09-14 21:29:41 UTC (rev 95122)
@@ -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

Modified: trunk/Tools/TestWebKitAPI/win/TestWebKitAPI.vcproj (95121 => 95122)


--- trunk/Tools/TestWebKitAPI/win/TestWebKitAPI.vcproj	2011-09-14 21:15:56 UTC (rev 95121)
+++ trunk/Tools/TestWebKitAPI/win/TestWebKitAPI.vcproj	2011-09-14 21:29:41 UTC (rev 95122)
@@ -389,6 +389,10 @@
 			Name="win"
 			>
 			<File
+				RelativePath=".\InjectedBundleControllerWin.cpp"
+				>
+			</File>
+			<File
 				RelativePath=".\main.cpp"
 				>
 			</File>
@@ -401,10 +405,6 @@
 				>
 			</File>
 			<File
-				RelativePath=".\InjectedBundleControllerWin.cpp"
-				>
-			</File>
-			<File
 				RelativePath=".\WindowMessageObserver.h"
 				>
 			</File>
@@ -540,6 +540,10 @@
 					>
 				</File>
 				<File
+					RelativePath="..\Tests\WebKit2\WebArchive.cpp"
+					>
+				</File>
+				<File
 					RelativePath="..\Tests\WebKit2\WKPreferences.cpp"
 					>
 				</File>

Modified: trunk/Tools/TestWebKitAPI/win/TestWebKitAPIInjectedBundle.vcproj (95121 => 95122)


--- trunk/Tools/TestWebKitAPI/win/TestWebKitAPIInjectedBundle.vcproj	2011-09-14 21:15:56 UTC (rev 95121)
+++ trunk/Tools/TestWebKitAPI/win/TestWebKitAPIInjectedBundle.vcproj	2011-09-14 21:29:41 UTC (rev 95122)
@@ -431,6 +431,10 @@
 					RelativePath="..\Tests\WebKit2\ResponsivenessTimerDoesntFireEarly_Bundle.cpp"
 					>
 				</File>
+				<File
+					RelativePath="..\Tests\WebKit2\WebArchive_Bundle.cpp"
+					>
+				</File>
 			</Filter>
 		</Filter>
 		<File
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to