Diff
Modified: trunk/Source/WebKit2/ChangeLog (102483 => 102484)
--- trunk/Source/WebKit2/ChangeLog 2011-12-09 23:43:52 UTC (rev 102483)
+++ trunk/Source/WebKit2/ChangeLog 2011-12-09 23:45:49 UTC (rev 102484)
@@ -1,3 +1,41 @@
+2011-12-09 Sam Weinig <s...@webkit.org>
+
+ Expose a WKConnectionRef which represents the connection to/from the WebProcess/UIProcess
+ https://bugs.webkit.org/show_bug.cgi?id=74218
+
+ Reviewed by Anders Carlsson.
+
+ Test: WebKit2.WKConnectionTest in TestWebKitAPI
+
+ * Shared/WebConnection.cpp:
+ (WebKit::WebConnection::forwardDidReceiveMessageToClient):
+ * Shared/WebConnection.h:
+ Add helper for connection subclasses to dispatch to the client.
+
+ * UIProcess/WebConnectionToWebProcess.cpp:
+ (WebKit::WebConnectionToWebProcess::didReceiveMessage):
+ Handle postMessage messages from the WebProcess.
+
+ * UIProcess/WebContext.cpp:
+ (WebKit::WebContext::processDidFinishLaunching):
+ Dispatch the notification that a connection to the WebProcess has
+ been established.
+
+ * WebProcess/InjectedBundle/API/c/WKBundle.cpp:
+ (WKBundleGetApplicationConnection):
+ * WebProcess/InjectedBundle/API/c/WKBundle.h:
+ * WebProcess/InjectedBundle/InjectedBundle.cpp:
+ (WebKit::InjectedBundle::webConnectionToUIProcess):
+ * WebProcess/InjectedBundle/InjectedBundle.h:
+ (WebKit::WebProcess::webConnectionToUIProcess):
+ Add accessor to get the connection to the UIProcess from
+ the bundle.
+
+ * WebProcess/WebConnectionToUIProcess.cpp:
+ (WebKit::WebConnectionToUIProcess::didReceiveMessage):
+ Handle postMessage messages from the UIProcess.
+ * WebProcess/WebProcess.h:
+
2011-12-08 Jocelyn Turcotte <jocelyn.turco...@nokia.com>
[Qt] Update WebGraphicLayer's child content scale in all child binding method.
Modified: trunk/Source/WebKit2/Shared/WebConnection.cpp (102483 => 102484)
--- trunk/Source/WebKit2/Shared/WebConnection.cpp 2011-12-09 23:43:52 UTC (rev 102483)
+++ trunk/Source/WebKit2/Shared/WebConnection.cpp 2011-12-09 23:45:49 UTC (rev 102484)
@@ -37,4 +37,9 @@
m_client.initialize(client);
}
+void WebConnection::forwardDidReceiveMessageToClient(const String& messageName, APIObject* messageBody)
+{
+ m_client.didReceiveMessage(this, messageName, messageBody);
+}
+
} // namespace WebKit
Modified: trunk/Source/WebKit2/Shared/WebConnection.h (102483 => 102484)
--- trunk/Source/WebKit2/Shared/WebConnection.h 2011-12-09 23:43:52 UTC (rev 102483)
+++ trunk/Source/WebKit2/Shared/WebConnection.h 2011-12-09 23:45:49 UTC (rev 102484)
@@ -46,6 +46,8 @@
protected:
virtual Type type() const { return APIType; }
+ void forwardDidReceiveMessageToClient(const String&, APIObject*);
+
WebConnectionClient m_client;
};
Modified: trunk/Source/WebKit2/UIProcess/WebConnectionToWebProcess.cpp (102483 => 102484)
--- trunk/Source/WebKit2/UIProcess/WebConnectionToWebProcess.cpp 2011-12-09 23:43:52 UTC (rev 102483)
+++ trunk/Source/WebKit2/UIProcess/WebConnectionToWebProcess.cpp 2011-12-09 23:45:49 UTC (rev 102484)
@@ -73,6 +73,22 @@
void WebConnectionToWebProcess::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments)
{
+ if (messageID.is<CoreIPC::MessageClassWebConnectionLegacy>()) {
+ switch (messageID.get<WebConnectionLegacyMessage::Kind>()) {
+ case WebConnectionLegacyMessage::PostMessage: {
+ String messageName;
+ RefPtr<APIObject> messageBody;
+ WebContextUserMessageDecoder messageDecoder(messageBody, m_process->context());
+ if (!arguments->decode(CoreIPC::Out(messageName, messageDecoder)))
+ return;
+
+ forwardDidReceiveMessageToClient(messageName, messageBody.get());
+ return;
+ }
+ }
+ return;
+ }
+
m_process->didReceiveMessage(connection, messageID, arguments);
}
Modified: trunk/Source/WebKit2/UIProcess/WebContext.cpp (102483 => 102484)
--- trunk/Source/WebKit2/UIProcess/WebContext.cpp 2011-12-09 23:43:52 UTC (rev 102483)
+++ trunk/Source/WebKit2/UIProcess/WebContext.cpp 2011-12-09 23:45:49 UTC (rev 102484)
@@ -351,6 +351,8 @@
m_process->send(Messages::WebProcess::StartMemorySampler(sampleLogSandboxHandle, sampleLogFilePath, m_memorySamplerInterval), 0);
}
+
+ m_connectionClient.didCreateConnection(this, process->webConnection());
}
void WebContext::disconnectProcess(WebProcessProxy* process)
Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundle.cpp (102483 => 102484)
--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundle.cpp 2011-12-09 23:43:52 UTC (rev 102483)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundle.cpp 2011-12-09 23:45:49 UTC (rev 102484)
@@ -56,6 +56,11 @@
*returnDataRef = toAPI(returnData.release().leakRef());
}
+WKConnectionRef WKBundleGetApplicationConnection(WKBundleRef bundleRef)
+{
+ return toAPI(toImpl(bundleRef)->webConnectionToUIProcess());
+}
+
void WKBundleSetShouldTrackVisitedLinks(WKBundleRef bundleRef, bool shouldTrackVisitedLinks)
{
toImpl(bundleRef)->setShouldTrackVisitedLinks(shouldTrackVisitedLinks);
Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundle.h (102483 => 102484)
--- trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundle.h 2011-12-09 23:43:52 UTC (rev 102483)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/API/c/WKBundle.h 2011-12-09 23:45:49 UTC (rev 102484)
@@ -58,6 +58,8 @@
WK_EXPORT void WKBundlePostMessage(WKBundleRef bundle, WKStringRef messageName, WKTypeRef messageBody);
WK_EXPORT void WKBundlePostSynchronousMessage(WKBundleRef bundle, WKStringRef messageName, WKTypeRef messageBody, WKTypeRef* returnData);
+WK_EXPORT WKConnectionRef WKBundleGetApplicationConnection(WKBundleRef bundle);
+
WK_EXPORT void WKBundleReportException(JSContextRef, JSValueRef exception);
#ifdef __cplusplus
Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp (102483 => 102484)
--- trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp 2011-12-09 23:43:52 UTC (rev 102483)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp 2011-12-09 23:45:49 UTC (rev 102484)
@@ -98,6 +98,11 @@
returnData = returnDataTmp;
}
+WebConnection* InjectedBundle::webConnectionToUIProcess() const
+{
+ return WebProcess::shared().webConnectionToUIProcess();
+}
+
void InjectedBundle::setShouldTrackVisitedLinks(bool shouldTrackVisitedLinks)
{
PageGroup::setShouldTrackVisitedLinks(shouldTrackVisitedLinks);
Modified: trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.h (102483 => 102484)
--- trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.h 2011-12-09 23:43:52 UTC (rev 102483)
+++ trunk/Source/WebKit2/WebProcess/InjectedBundle/InjectedBundle.h 2011-12-09 23:45:49 UTC (rev 102484)
@@ -64,6 +64,7 @@
class ImmutableArray;
class InjectedBundleScriptWorld;
class WebCertificateInfo;
+class WebConnection;
class WebFrame;
class WebPage;
class WebPageGroupProxy;
@@ -90,6 +91,8 @@
void setClientCertificate(const String& host, const String& certificateSystemStoreName, const WebCertificateInfo*);
#endif
+ WebConnection* webConnectionToUIProcess() const;
+
// TestRunner only SPI
void setShouldTrackVisitedLinks(bool);
void removeAllVisitedLinks();
Modified: trunk/Source/WebKit2/WebProcess/WebConnectionToUIProcess.cpp (102483 => 102484)
--- trunk/Source/WebKit2/WebProcess/WebConnectionToUIProcess.cpp 2011-12-09 23:43:52 UTC (rev 102483)
+++ trunk/Source/WebKit2/WebProcess/WebConnectionToUIProcess.cpp 2011-12-09 23:45:49 UTC (rev 102484)
@@ -71,6 +71,22 @@
void WebConnectionToUIProcess::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments)
{
+ if (messageID.is<CoreIPC::MessageClassWebConnectionLegacy>()) {
+ switch (messageID.get<WebConnectionLegacyMessage::Kind>()) {
+ case WebConnectionLegacyMessage::PostMessage: {
+ String messageName;
+ RefPtr<APIObject> messageBody;
+ InjectedBundleUserMessageDecoder messageDecoder(messageBody);
+ if (!arguments->decode(CoreIPC::Out(messageName, messageDecoder)))
+ return;
+
+ forwardDidReceiveMessageToClient(messageName, messageBody.get());
+ return;
+ }
+ }
+ return;
+ }
+
m_process->didReceiveMessage(connection, messageID, arguments);
}
Modified: trunk/Source/WebKit2/WebProcess/WebProcess.h (102483 => 102484)
--- trunk/Source/WebKit2/WebProcess/WebProcess.h 2011-12-09 23:43:52 UTC (rev 102483)
+++ trunk/Source/WebKit2/WebProcess/WebProcess.h 2011-12-09 23:45:49 UTC (rev 102484)
@@ -81,6 +81,8 @@
CoreIPC::Connection* connection() const { return m_connection->connection(); }
RunLoop* runLoop() const { return m_runLoop; }
+ WebConnectionToUIProcess* webConnectionToUIProcess() const { return m_connection.get(); }
+
WebPage* webPage(uint64_t pageID) const;
void createWebPage(uint64_t pageID, const WebPageCreationParameters&);
void removeWebPage(uint64_t pageID);
Modified: trunk/Tools/ChangeLog (102483 => 102484)
--- trunk/Tools/ChangeLog 2011-12-09 23:43:52 UTC (rev 102483)
+++ trunk/Tools/ChangeLog 2011-12-09 23:45:49 UTC (rev 102484)
@@ -1,3 +1,23 @@
+2011-12-09 Sam Weinig <s...@webkit.org>
+
+ Expose a WKConnectionRef which represents the connection to/from the WebProcess/UIProcess
+ https://bugs.webkit.org/show_bug.cgi?id=74218
+
+ Reviewed by Anders Carlsson.
+
+ Add a test of the WKConnectionRef API.
+
+ * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj:
+ * TestWebKitAPI/Tests/WebKit2/WKConnection.cpp: Added.
+ (TestWebKitAPI::didCreateConnection):
+ (TestWebKitAPI::connectionDidReceiveMessage):
+ (TestWebKitAPI::connectionDidClose):
+ (TestWebKitAPI::TEST):
+ * TestWebKitAPI/Tests/WebKit2/WKConnection_Bundle.cpp: Added.
+ (TestWebKitAPI::connectionDidReceiveMessage):
+ (TestWebKitAPI::WKConnectionTest::WKConnectionTest):
+ (TestWebKitAPI::WKConnectionTest::initialize):
+
2011-12-09 David Levin <le...@chromium.org>
Hash* iterators should allow comparison between const and const versions.
Modified: trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj (102483 => 102484)
--- trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2011-12-09 23:43:52 UTC (rev 102483)
+++ trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj 2011-12-09 23:45:49 UTC (rev 102484)
@@ -62,6 +62,8 @@
BC575BD9126F58E2006F0F12 /* PlatformUtilities.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC575BBF126F5752006F0F12 /* PlatformUtilities.cpp */; };
BC575BE0126F590D006F0F12 /* PlatformUtilitiesMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC131884117114B600B69727 /* PlatformUtilitiesMac.mm */; };
BC7B61AA129A038700D174A4 /* WKPreferences.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC7B619A1299FE9E00D174A4 /* WKPreferences.cpp */; };
+ BC901E241492ADCE0074A667 /* WKConnection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC901E221492ADCE0074A667 /* WKConnection.cpp */; };
+ BC901E331492AF390074A667 /* WKConnection_Bundle.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC901E311492AF390074A667 /* WKConnection_Bundle.cpp */; };
BC90955D125548AA00083756 /* PlatformWebViewMac.mm in Sources */ = {isa = PBXBuildFile; fileRef = BC90955C125548AA00083756 /* PlatformWebViewMac.mm */; };
BC90964C125561BF00083756 /* VectorBasic.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BC90964B125561BF00083756 /* VectorBasic.cpp */; };
BC90964E1255620C00083756 /* _javascript_Core.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC90964D1255620C00083756 /* _javascript_Core.framework */; };
@@ -207,6 +209,8 @@
BC575AE2126E88B1006F0F12 /* InjectedBundle.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = InjectedBundle.xcconfig; sourceTree = "<group>"; };
BC575BBF126F5752006F0F12 /* PlatformUtilities.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformUtilities.cpp; sourceTree = "<group>"; };
BC7B619A1299FE9E00D174A4 /* WKPreferences.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKPreferences.cpp; sourceTree = "<group>"; };
+ BC901E221492ADCE0074A667 /* WKConnection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKConnection.cpp; sourceTree = "<group>"; };
+ BC901E311492AF390074A667 /* WKConnection_Bundle.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WKConnection_Bundle.cpp; sourceTree = "<group>"; };
BC90951B125533D700083756 /* PlatformWebView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformWebView.h; sourceTree = "<group>"; };
BC90955C125548AA00083756 /* PlatformWebViewMac.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PlatformWebViewMac.mm; sourceTree = "<group>"; };
BC90957E12554CF900083756 /* Base.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Base.xcconfig; sourceTree = "<group>"; };
@@ -387,8 +391,8 @@
C0C5D3BB14598B6F00A802A6 /* mac */,
BC90977B125571AE00083756 /* Resources */,
BC246D8C132F115A00B56D7C /* AboutBlankLoad.cpp */,
+ BC246D98132F1FE100B56D7C /* CanHandleRequest.cpp */,
BC246D97132F1FE100B56D7C /* CanHandleRequest_Bundle.cpp */,
- BC246D98132F1FE100B56D7C /* CanHandleRequest.cpp */,
F6F3F29013342FEB00A6BF19 /* CookieManager.cpp */,
BCB6803F126FBFE100642A61 /* DocumentStartUserScriptAlertCrash.cpp */,
BCB68041126FBFF100642A61 /* DocumentStartUserScriptAlertCrash_Bundle.cpp */,
@@ -416,11 +420,13 @@
C0BD669E131D3CFF00E18F2A /* ResponsivenessTimerDoesntFireEarly_Bundle.cpp */,
C0ADBE8212FCA6AA00D2C129 /* RestoreSessionStateContainingFormData.cpp */,
C02B77F1126612140026BF0F /* SpacebarScrolling.cpp */,
+ 520BCF4B141EB09E00937EA8 /* WebArchive.cpp */,
+ 520BCF4A141EB09E00937EA8 /* WebArchive_Bundle.cpp */,
+ BC901E221492ADCE0074A667 /* WKConnection.cpp */,
+ BC901E311492AF390074A667 /* WKConnection_Bundle.cpp */,
BC7B619A1299FE9E00D174A4 /* WKPreferences.cpp */,
BC90995D12567BC100083756 /* WKString.cpp */,
BC9099931256ACF100083756 /* WKStringJSString.cpp */,
- 520BCF4A141EB09E00937EA8 /* WebArchive_Bundle.cpp */,
- 520BCF4B141EB09E00937EA8 /* WebArchive.cpp */,
);
path = WebKit2;
sourceTree = "<group>";
@@ -688,6 +694,7 @@
37A6895F148A9B50005100FA /* SubresourceErrorCrash.mm in Sources */,
BC029B181486AD6400817DA9 /* RetainPtr.cpp in Sources */,
BC029B1C1486B25900817DA9 /* RetainPtr.mm in Sources */,
+ BC901E241492ADCE0074A667 /* WKConnection.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -709,6 +716,7 @@
33DC89141419579F00747EF7 /* LoadCanceledNoServerRedirectCallback_Bundle.cpp in Sources */,
520BCF4C141EB09E00937EA8 /* WebArchive_Bundle.cpp in Sources */,
C0C5D3C61459912900A802A6 /* GetBackingScaleFactor_Bundle.mm in Sources */,
+ BC901E331492AF390074A667 /* WKConnection_Bundle.cpp in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/WKConnection.cpp (0 => 102484)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/WKConnection.cpp (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/WKConnection.cpp 2011-12-09 23:45:49 UTC (rev 102484)
@@ -0,0 +1,116 @@
+/*
+ * 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 "config.h"
+#include "PlatformUtilities.h"
+#include "PlatformWebView.h"
+#include "Test.h"
+
+namespace TestWebKitAPI {
+
+// State for part 1 - setting up the connection.
+static bool connectionEstablished;
+static WKConnectionRef connectionToBundle;
+
+// State for part 2 - send/recieving messages.
+static bool messageReceived;
+
+// State for part 3 - tearing down the connection.
+static bool connectionTornDown;
+
+
+/* WKContextConnectionClient */
+static void didCreateConnection(WKContextRef context, WKConnectionRef connection, const void* clientInfo)
+{
+ connectionEstablished = true;
+
+ // Store off the conneciton to use.
+ connectionToBundle = (WKConnectionRef)WKRetain(connection);
+}
+
+/* WKConnectionClient */
+static void connectionDidReceiveMessage(WKConnectionRef connection, WKStringRef messageName, WKTypeRef messageBody, const void *clientInfo)
+{
+ // We only expect to get the "Pong" message.
+ EXPECT_WK_STREQ(messageName, "PongMessageName");
+ EXPECT_WK_STREQ((WKStringRef)messageBody, "PongMessageBody");
+
+ messageReceived = true;
+}
+
+static void connectionDidClose(WKConnectionRef connection, const void* clientInfo)
+{
+ connectionTornDown = true;
+}
+
+TEST(WebKit2, WKConnectionTest)
+{
+ WKRetainPtr<WKContextRef> context(AdoptWK, Util::createContextForInjectedBundleTest("WKConnectionTest"));
+
+ // Set up the context's connection client so that we can access the connection when
+ // it is created.
+ WKContextConnectionClient contextConnectionClient;
+ memset(&contextConnectionClient, 0, sizeof(contextConnectionClient));
+ contextConnectionClient.version = kWKContextConnectionClientCurrentVersion;
+ contextConnectionClient.clientInfo = 0;
+ contextConnectionClient.didCreateConnection = didCreateConnection;
+ WKContextSetConnectionClient(context.get(), &contextConnectionClient);
+
+ // Load a simple page to start the WebProcess and establish a connection.
+ PlatformWebView webView(context.get());
+ WKRetainPtr<WKURLRef> url(AdoptWK, Util::createURLForResource("simple", "html"));
+ WKPageLoadURL(webView.page(), url.get());
+
+ // Wait until the connection is established.
+ Util::run(&connectionEstablished);
+ ASSERT_NOT_NULL(connectionToBundle);
+
+ // Setup a client on the connection so we can listen for messages and
+ // tear down notifications.
+ WKConnectionClient connectionClient;
+ memset(&connectionClient, 0, sizeof(connectionClient));
+ connectionClient.version = WKConnectionClientCurrentVersion;
+ connectionClient.clientInfo = 0;
+ connectionClient.didReceiveMessage = connectionDidReceiveMessage;
+ connectionClient.didClose = connectionDidClose;
+ WKConnectionSetConnectionClient(connectionToBundle, &connectionClient);
+
+ // Post a simple message to the bundle via the connection.
+ WKConnectionPostMessage(connectionToBundle, Util::toWK("PingMessageName").get(), Util::toWK("PingMessageBody").get());
+
+ // Wait for the reply.
+ Util::run(&messageReceived);
+
+ // Terminate the page to force the connection closed.
+ WKPageTerminate(webView.page());
+
+ // Wait for the connection to close.
+ Util::run(&connectionTornDown);
+
+ // This release is to balance the retain in didCreateConnection.
+ WKRelease(connectionToBundle);
+}
+
+} // namespace TestWebKitAPI
Added: trunk/Tools/TestWebKitAPI/Tests/WebKit2/WKConnection_Bundle.cpp (0 => 102484)
--- trunk/Tools/TestWebKitAPI/Tests/WebKit2/WKConnection_Bundle.cpp (rev 0)
+++ trunk/Tools/TestWebKitAPI/Tests/WebKit2/WKConnection_Bundle.cpp 2011-12-09 23:45:49 UTC (rev 102484)
@@ -0,0 +1,60 @@
+/*
+ * 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 "config.h"
+#include "InjectedBundleTest.h"
+#include "PlatformUtilities.h"
+#include <WebKit2/WKRetainPtr.h>
+
+namespace TestWebKitAPI {
+
+/* WKConnectionClient */
+static void connectionDidReceiveMessage(WKConnectionRef connection, WKStringRef messageName, WKTypeRef messageBody, const void *clientInfo)
+{
+ // Post a simple message to the back to the application layer.
+ WKConnectionPostMessage(connection, Util::toWK("PongMessageName").get(), Util::toWK("PongMessageBody").get());
+}
+
+class WKConnectionTest : public InjectedBundleTest {
+public:
+ WKConnectionTest(const std::string& identifier)
+ : InjectedBundleTest(identifier)
+ {
+ }
+
+ virtual void initialize(WKBundleRef bundle, WKTypeRef)
+ {
+ WKConnectionClient connectionClient;
+ memset(&connectionClient, 0, sizeof(connectionClient));
+ connectionClient.version = WKConnectionClientCurrentVersion;
+ connectionClient.clientInfo = 0;
+ connectionClient.didReceiveMessage = connectionDidReceiveMessage;
+ WKConnectionSetConnectionClient(WKBundleGetApplicationConnection(bundle), &connectionClient);
+ }
+};
+
+static InjectedBundleTest::Register<WKConnectionTest> registrar("WKConnectionTest");
+
+} // namespace TestWebKitAPI