Patch for https://bugs.webkit.org/show_bug.cgi?id=40940
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 21 Jun 2010 21:36:44 +0000 (21:36 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 21 Jun 2010 21:36:44 +0000 (21:36 +0000)
Add message passing support to the WebKit2 API.

Reviewed by Anders Carlsson.

WebKit2:

Adds message passing for both InjectedBundle -> WebContext
and WebContext -> InjectedBundle.

* Shared/CoreIPCSupport/WebProcessMessageKinds.h:
(WebProcessMessage::):
* Shared/CoreIPCSupport/WebProcessProxyMessageKinds.h: Added.
(WebProcessProxyMessage::):
(CoreIPC::):
* UIProcess/API/C/WKContext.cpp:
(WKContextSetInjectedBundleClient):
(WKContextPostMessageToInjectedBundle):
* UIProcess/API/C/WKContext.h:
* UIProcess/WebContext.cpp:
(WebKit::WebContext::initializeInjectedBundleClient):
(WebKit::WebContext::forwardMessageToWebContext):
(WebKit::WebContext::postMessageToInjectedBundle):
* UIProcess/WebContext.h:
* UIProcess/WebContextInjectedBundleClient.cpp: Added.
(WebKit::WebContextInjectedBundleClient::WebContextInjectedBundleClient):
(WebKit::WebContextInjectedBundleClient::initialize):
(WebKit::WebContextInjectedBundleClient::didRecieveMessageFromInjectedBundle):
* UIProcess/WebContextInjectedBundleClient.h: Added.
* UIProcess/WebProcessManager.cpp:
(WebKit::WebProcessManager::processDidClose):
* UIProcess/WebProcessProxy.cpp:
(WebKit::WebProcessProxy::didReceiveInjectedBundleMessage):
(WebKit::WebProcessProxy::didReceiveMessage):
* UIProcess/WebProcessProxy.h:
* WebKit2.xcodeproj/project.pbxproj:
* WebProcess/InjectedBundle/API/c/WKBundle.cpp:
(WKBundlePostMessage):
* WebProcess/InjectedBundle/API/c/WKBundle.h:
* WebProcess/InjectedBundle/InjectedBundle.cpp:
(WebKit::InjectedBundle::postMessage):
(WebKit::InjectedBundle::didCreatePage):
(WebKit::InjectedBundle::didRecieveMessage):
* WebProcess/InjectedBundle/InjectedBundle.h:
* WebProcess/WebProcess.cpp:
(WebKit::WebProcess::loadInjectedBundle):
(WebKit::WebProcess::forwardMessageToInjectedBundle):
(WebKit::WebProcess::didReceiveMessage):
* WebProcess/WebProcess.h:
* mac/WebKit2.exp:
* win/WebKit2.vcproj:

WebKitTools:

- Add some test messages.

* MiniBrowser/mac/AppDelegate.m:
(_didRecieveMessageFromInjectedBundle):
(-[BrowserAppDelegate init]):
* MiniBrowser/mac/WebBundle/WebBundleMain.m:
(_didClearWindow):
(_didCreatePage):
(_didRecieveMessage):
(WKBundleInitialize):

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

24 files changed:
WebKit2/ChangeLog
WebKit2/Shared/CoreIPCSupport/WebProcessMessageKinds.h
WebKit2/Shared/CoreIPCSupport/WebProcessProxyMessageKinds.h [new file with mode: 0644]
WebKit2/UIProcess/API/C/WKContext.cpp
WebKit2/UIProcess/API/C/WKContext.h
WebKit2/UIProcess/WebContext.cpp
WebKit2/UIProcess/WebContext.h
WebKit2/UIProcess/WebContextInjectedBundleClient.cpp [new file with mode: 0644]
WebKit2/UIProcess/WebContextInjectedBundleClient.h [new file with mode: 0644]
WebKit2/UIProcess/WebProcessManager.cpp
WebKit2/UIProcess/WebProcessProxy.cpp
WebKit2/UIProcess/WebProcessProxy.h
WebKit2/WebKit2.xcodeproj/project.pbxproj
WebKit2/WebProcess/InjectedBundle/API/c/WKBundle.cpp
WebKit2/WebProcess/InjectedBundle/API/c/WKBundle.h
WebKit2/WebProcess/InjectedBundle/InjectedBundle.cpp
WebKit2/WebProcess/InjectedBundle/InjectedBundle.h
WebKit2/WebProcess/WebProcess.cpp
WebKit2/WebProcess/WebProcess.h
WebKit2/mac/WebKit2.exp
WebKit2/win/WebKit2.vcproj
WebKitTools/ChangeLog
WebKitTools/MiniBrowser/mac/AppDelegate.m
WebKitTools/MiniBrowser/mac/WebBundle/WebBundleMain.m

index b23c0a3c2cd8904b5e333221b23b195cd4595aae..4dfc7425f1bbb6c39ce7da567df314a267036c94 100644 (file)
@@ -1,3 +1,55 @@
+2010-06-21  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Anders Carlsson.
+
+        Patch for https://bugs.webkit.org/show_bug.cgi?id=40940
+        Add message passing support to the WebKit2 API.
+
+        Adds message passing for both InjectedBundle -> WebContext
+        and WebContext -> InjectedBundle.
+
+        * Shared/CoreIPCSupport/WebProcessMessageKinds.h:
+        (WebProcessMessage::):
+        * Shared/CoreIPCSupport/WebProcessProxyMessageKinds.h: Added.
+        (WebProcessProxyMessage::):
+        (CoreIPC::):
+        * UIProcess/API/C/WKContext.cpp:
+        (WKContextSetInjectedBundleClient):
+        (WKContextPostMessageToInjectedBundle):
+        * UIProcess/API/C/WKContext.h:
+        * UIProcess/WebContext.cpp:
+        (WebKit::WebContext::initializeInjectedBundleClient):
+        (WebKit::WebContext::forwardMessageToWebContext):
+        (WebKit::WebContext::postMessageToInjectedBundle):
+        * UIProcess/WebContext.h:
+        * UIProcess/WebContextInjectedBundleClient.cpp: Added.
+        (WebKit::WebContextInjectedBundleClient::WebContextInjectedBundleClient):
+        (WebKit::WebContextInjectedBundleClient::initialize):
+        (WebKit::WebContextInjectedBundleClient::didRecieveMessageFromInjectedBundle):
+        * UIProcess/WebContextInjectedBundleClient.h: Added.
+        * UIProcess/WebProcessManager.cpp:
+        (WebKit::WebProcessManager::processDidClose):
+        * UIProcess/WebProcessProxy.cpp:
+        (WebKit::WebProcessProxy::didReceiveInjectedBundleMessage):
+        (WebKit::WebProcessProxy::didReceiveMessage):
+        * UIProcess/WebProcessProxy.h:
+        * WebKit2.xcodeproj/project.pbxproj:
+        * WebProcess/InjectedBundle/API/c/WKBundle.cpp:
+        (WKBundlePostMessage):
+        * WebProcess/InjectedBundle/API/c/WKBundle.h:
+        * WebProcess/InjectedBundle/InjectedBundle.cpp:
+        (WebKit::InjectedBundle::postMessage):
+        (WebKit::InjectedBundle::didCreatePage):
+        (WebKit::InjectedBundle::didRecieveMessage):
+        * WebProcess/InjectedBundle/InjectedBundle.h:
+        * WebProcess/WebProcess.cpp:
+        (WebKit::WebProcess::loadInjectedBundle):
+        (WebKit::WebProcess::forwardMessageToInjectedBundle):
+        (WebKit::WebProcess::didReceiveMessage):
+        * WebProcess/WebProcess.h:
+        * mac/WebKit2.exp:
+        * win/WebKit2.vcproj:
+
 2010-06-21  Anders Carlsson  <andersca@apple.com>
 
         Reviewed by Sam Weinig.
index 1147dc4ad2c0c3f8ab61e0d9c80b9363745192eb..4d76610841909d75f925344590b45ebbe6ee8ec3 100644 (file)
@@ -34,7 +34,8 @@ namespace WebProcessMessage {
 
 enum Kind {
     LoadInjectedBundle,
-    Create
+    Create,
+    PostMessage
 };
 
 }
diff --git a/WebKit2/Shared/CoreIPCSupport/WebProcessProxyMessageKinds.h b/WebKit2/Shared/CoreIPCSupport/WebProcessProxyMessageKinds.h
new file mode 100644 (file)
index 0000000..86e40fe
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+#ifndef WebProcessProxyMessageKinds_h
+#define WebProcessProxyMessageKinds_h
+
+// Messages sent from the web process to the WebProcessProxy.
+
+#include "MessageID.h"
+
+namespace WebProcessProxyMessage {
+
+enum Kind {
+    PostMessage
+};
+
+}
+
+namespace CoreIPC {
+
+template<> struct MessageKindTraits<WebProcessProxyMessage::Kind> { 
+    static const MessageClass messageClass = MessageClassWebProcessProxy;
+};
+
+}
+
+#endif // WebProcessProxyMessageKinds_h
index f6bf4b6f14ed175ba7676e4f946f00ab2d0be461..7d7416a01f0e54d675b3ec18efc964b94496b8b8 100644 (file)
@@ -67,6 +67,17 @@ WKPreferencesRef WKContextGetPreferences(WKContextRef contextRef)
     return toRef(toWK(contextRef)->preferences());
 }
 
+void WKContextSetInjectedBundleClient(WKContextRef contextRef, WKContextInjectedBundleClient* wkClient)
+{
+    if (wkClient && !wkClient->version)
+        toWK(contextRef)->initializeInjectedBundleClient(wkClient);
+}
+
+void WKContextPostMessageToInjectedBundle(WKContextRef contextRef, WKStringRef messageRef)
+{
+    toWK(contextRef)->postMessageToInjectedBundle(toWK(messageRef));
+}
+
 void WKContextGetStatistics(WKContextRef contextRef, WKContextStatistics* statistics)
 {
     toWK(contextRef)->getStatistics(statistics);
index 89141f41dafcc99366568947a15345945072ba0b..e0f7d4b221cfbbdb1afe32a33e55ad5471f00cb2 100644 (file)
 extern "C" {
 #endif
 
+// Policy Client.
+typedef void (*WKContextDidRecieveMessageFromInjectedBundleCallback)(WKContextRef page, WKStringRef message, const void *clientInfo);
+
+struct WKContextInjectedBundleClient {
+    int                                                                 version;
+    const void *                                                        clientInfo;
+    WKContextDidRecieveMessageFromInjectedBundleCallback                didRecieveMessageFromInjectedBundle;
+};
+typedef struct WKContextInjectedBundleClient WKContextInjectedBundleClient;
+
 WK_EXPORT WKContextRef WKContextCreate();
 WK_EXPORT WKContextRef WKContextCreateWithInjectedBundlePath(WKStringRef path);
-
 WK_EXPORT WKContextRef WKContextGetSharedProcessContext();
 
 WK_EXPORT void WKContextSetPreferences(WKContextRef context, WKPreferencesRef preferences);
 WK_EXPORT WKPreferencesRef WKContextGetPreferences(WKContextRef context);
 
+WK_EXPORT void WKContextSetInjectedBundleClient(WKContextRef context, WKContextInjectedBundleClient * client);
+
+WK_EXPORT void WKContextPostMessageToInjectedBundle(WKContextRef context, WKStringRef message);
+
 WK_EXPORT WKContextRef WKContextRetain(WKContextRef context);
 WK_EXPORT void WKContextRelease(WKContextRef context);
 
index e450155f3815496dcba388846266a8519daab8fe..638083c2c3e4915c2c0106c4b4db927c388a446d 100644 (file)
 #include "WebContext.h"
 
 #include "RunLoop.h"
+#include "WebCoreTypeArgumentMarshalling.h"
 #include "WebPageNamespace.h"
 #include "WebPreferences.h"
 #include "WebProcessManager.h"
+#include "WebProcessMessageKinds.h"
 #include "WebProcessProxy.h"
 
 #include "WKContextPrivate.h"
@@ -81,6 +83,11 @@ WebContext::~WebContext()
 #endif
 }
 
+void WebContext::initializeInjectedBundleClient(WKContextInjectedBundleClient* client)
+{
+    m_injectedBundleClient.initialize(client);
+}
+
 void WebContext::ensureWebProcess()
 {
     if (m_process && m_process->isValid())
@@ -140,6 +147,21 @@ void WebContext::preferencesDidChange()
     }
 }
 
+// InjectedBundle client
+
+void WebContext::didRecieveMessageFromInjectedBundle(const WebCore::String& message)
+{
+    m_injectedBundleClient.didRecieveMessageFromInjectedBundle(this, message);
+}
+
+void WebContext::postMessageToInjectedBundle(WebCore::StringImpl* message)
+{
+    if (!m_process || !m_process->isValid())
+        return;
+
+    m_process->connection()->send(WebProcessMessage::PostMessage, 0, CoreIPC::In(String(message)));
+}
+
 void WebContext::getStatistics(WKContextStatistics* statistics)
 {
     memset(statistics, 0, sizeof(WKContextStatistics));
index cf381299eae5bfbc02c67d0a52376a168de5f542..54478eb15db1fb64dd31d561c8717936e40ad1e0 100644 (file)
@@ -27,6 +27,7 @@
 #define WebContext_h
 
 #include "ProcessModel.h"
+#include "WebContextInjectedBundleClient.h"
 #include <WebCore/PlatformString.h>
 #include <wtf/Forward.h>
 #include <wtf/HashSet.h>
@@ -55,6 +56,8 @@ public:
 
     ~WebContext();
 
+    void initializeInjectedBundleClient(WKContextInjectedBundleClient*);
+
     ProcessModel processModel() const { return m_processModel; }
     WebProcessProxy* process() const { return m_process.get(); }
 
@@ -71,6 +74,11 @@ public:
 
     const WebCore::String& injectedBundlePath() const { return m_injectedBundlePath; }
 
+    // InjectedBundle client
+    void didRecieveMessageFromInjectedBundle(const WebCore::String&);
+
+    void postMessageToInjectedBundle(WebCore::StringImpl*);
+
     void getStatistics(WKContextStatistics* statistics);
 
 private:
@@ -87,6 +95,7 @@ private:
     RefPtr<WebPreferences> m_preferences;
 
     WebCore::String m_injectedBundlePath;
+    WebContextInjectedBundleClient m_injectedBundleClient;
 };
 
 } // namespace WebKit
diff --git a/WebKit2/UIProcess/WebContextInjectedBundleClient.cpp b/WebKit2/UIProcess/WebContextInjectedBundleClient.cpp
new file mode 100644 (file)
index 0000000..5341b6e
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2010 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 "WebContextInjectedBundleClient.h"
+
+#include "WKAPICast.h"
+#include <WebCore/PlatformString.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+WebContextInjectedBundleClient::WebContextInjectedBundleClient()
+{
+    initialize(0);
+}
+
+void WebContextInjectedBundleClient::initialize(WKContextInjectedBundleClient* client)
+{
+    if (client && !client->version)
+        m_client = *client;
+    else 
+        memset(&m_client, 0, sizeof(m_client));
+}
+
+void WebContextInjectedBundleClient::didRecieveMessageFromInjectedBundle(WebContext* context, const String& message)
+{
+    if (!m_client.didRecieveMessageFromInjectedBundle)
+        return;
+
+    m_client.didRecieveMessageFromInjectedBundle(toRef(context), toRef(message.impl()), m_client.clientInfo);
+}
+
+} // namespace WebKit
diff --git a/WebKit2/UIProcess/WebContextInjectedBundleClient.h b/WebKit2/UIProcess/WebContextInjectedBundleClient.h
new file mode 100644 (file)
index 0000000..a118c6c
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2010 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.
+ */
+
+#ifndef WebContextInjectedBundleClient_h
+#define WebContextInjectedBundleClient_h
+
+#include "WKContext.h"
+
+namespace WebCore {
+    class String;
+}
+
+namespace WebKit {
+
+class WebContext;
+
+class WebContextInjectedBundleClient {
+public:
+    WebContextInjectedBundleClient();
+    void initialize(WKContextInjectedBundleClient*);
+
+    void didRecieveMessageFromInjectedBundle(WebContext*, const WebCore::String&);
+
+private:
+    WKContextInjectedBundleClient m_client;
+};
+
+} // namespace WebKit
+
+#endif // WebContextInjectedBundleClient_h
index 3f410cb6cb069b69365cad8101bf728e745d4ac0..ad78215f3266ea5776fdb83013eccf4d7fdcef1a 100644 (file)
@@ -80,6 +80,7 @@ void WebProcessManager::processDidClose(WebProcessProxy* process, WebContext* co
     if (it != m_processMap.end()) {
         ASSERT(it->second == process);
         m_processMap.remove(it);
+        return;
     }
 
     // The shared thread connection should never be closed.
index 466a4b92c67a0bf72db96d5b220c40e7c41f9683..840b500b5258b30708cc21a61d086e3e392a1045 100644 (file)
@@ -31,6 +31,7 @@
 #include "WebProcessLauncher.h"
 #include "WebProcessManager.h"
 #include "WebProcessMessageKinds.h"
+#include "WebProcessProxyMessageKinds.h"
 #include <WebCore/PlatformString.h>
 
 using namespace WebCore;
@@ -127,8 +128,26 @@ size_t WebProcessProxy::numberOfPages()
     return m_pageMap.size();
 }
 
+void WebProcessProxy::forwardMessageToWebContext(const WebCore::String& message)
+{
+    m_context->didRecieveMessageFromInjectedBundle(message);
+}
+
 void WebProcessProxy::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::MessageID messageID, CoreIPC::ArgumentDecoder* arguments)
 {
+    if (messageID.is<CoreIPC::MessageClassWebProcessProxy>()) {
+        switch (messageID.get<WebProcessProxyMessage::Kind>()) {
+            case WebProcessProxyMessage::PostMessage: {
+                WebCore::String message;
+                if (!arguments->decode(CoreIPC::Out(message)))
+                    return;
+
+                forwardMessageToWebContext(message);
+                return;
+            }
+        }
+    }
+
     uint64_t pageID = arguments->destinationID();
     if (!pageID)
         return;
index c6274db157e810edc60f3d0cac40654e270f6465..cafd426929ed5a86241bd6611d37805fa462666b 100644 (file)
@@ -76,6 +76,8 @@ private:
 
     void connect();
 
+    void forwardMessageToWebContext(const WebCore::String&);
+
     // CoreIPC::Connection::Client
     void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
     void didReceiveSyncMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*, CoreIPC::ArgumentEncoder*);
index bc3a521f4aa8c8809f2c03f4cb106e2d0c824c5d..25ec05eb487be31b0cc191a0d6784e4415a986fd 100644 (file)
                BC9E969A11457EDE00870E71 /* DrawingAreaProxyMessageKinds.h in Headers */ = {isa = PBXBuildFile; fileRef = BC9E969911457EDE00870E71 /* DrawingAreaProxyMessageKinds.h */; };
                BC9E969C11457F3F00870E71 /* DrawingAreaMessageKinds.h in Headers */ = {isa = PBXBuildFile; fileRef = BC9E969B11457F3F00870E71 /* DrawingAreaMessageKinds.h */; };
                BCB63478116BF10600603215 /* WebKit2.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB63477116BF10600603215 /* WebKit2.h */; settings = {ATTRIBUTES = (Public, ); }; };
+               BCB7346E11CEE3FF00EC5002 /* WebProcessProxyMessageKinds.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB7346D11CEE3FF00EC5002 /* WebProcessProxyMessageKinds.h */; };
                BCB9E2431120DACA00A137E0 /* WebContext.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB9E2411120DACA00A137E0 /* WebContext.h */; };
                BCB9E2441120DACA00A137E0 /* WebContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCB9E2421120DACA00A137E0 /* WebContext.cpp */; };
                BCB9E24B1120E15C00A137E0 /* WKContext.h in Headers */ = {isa = PBXBuildFile; fileRef = BCB9E2491120E15C00A137E0 /* WKContext.h */; settings = {ATTRIBUTES = (Public, ); }; };
                BCD59800112B57BE00EC8C23 /* WebPreferences.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCD597FE112B57BE00EC8C23 /* WebPreferences.cpp */; };
                BCD598AC112B7FDF00EC8C23 /* WebPreferencesStore.h in Headers */ = {isa = PBXBuildFile; fileRef = BCD598AA112B7FDF00EC8C23 /* WebPreferencesStore.h */; };
                BCD598AD112B7FDF00EC8C23 /* WebPreferencesStore.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCD598AB112B7FDF00EC8C23 /* WebPreferencesStore.cpp */; };
+               BCDE059B11CDA8AE00E41AF1 /* WebContextInjectedBundleClient.h in Headers */ = {isa = PBXBuildFile; fileRef = BCDE059911CDA8AE00E41AF1 /* WebContextInjectedBundleClient.h */; };
+               BCDE059C11CDA8AE00E41AF1 /* WebContextInjectedBundleClient.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCDE059A11CDA8AE00E41AF1 /* WebContextInjectedBundleClient.cpp */; };
                BCEE966C112FAF57006BCC24 /* Attachment.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCEE966A112FAF57006BCC24 /* Attachment.cpp */; };
                BCEE966D112FAF57006BCC24 /* Attachment.h in Headers */ = {isa = PBXBuildFile; fileRef = BCEE966B112FAF57006BCC24 /* Attachment.h */; };
                BCEE98C6113314D7006BCC24 /* WebPageNamespace.cpp in Sources */ = {isa = PBXBuildFile; fileRef = BCEE98C4113314D7006BCC24 /* WebPageNamespace.cpp */; };
                BC9E969911457EDE00870E71 /* DrawingAreaProxyMessageKinds.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DrawingAreaProxyMessageKinds.h; sourceTree = "<group>"; };
                BC9E969B11457F3F00870E71 /* DrawingAreaMessageKinds.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DrawingAreaMessageKinds.h; sourceTree = "<group>"; };
                BCB63477116BF10600603215 /* WebKit2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebKit2.h; sourceTree = "<group>"; };
+               BCB7346D11CEE3FF00EC5002 /* WebProcessProxyMessageKinds.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebProcessProxyMessageKinds.h; sourceTree = "<group>"; };
                BCB86F4B116AAACD00CE20B7 /* WebKit2.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = WebKit2.xcconfig; sourceTree = "<group>"; };
                BCB8D4E011AF78C1008F9103 /* WebKit2.exp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.exports; name = WebKit2.exp; path = mac/WebKit2.exp; sourceTree = "<group>"; };
                BCB9E2411120DACA00A137E0 /* WebContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebContext.h; sourceTree = "<group>"; };
                BCD597FE112B57BE00EC8C23 /* WebPreferences.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebPreferences.cpp; sourceTree = "<group>"; };
                BCD598AA112B7FDF00EC8C23 /* WebPreferencesStore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebPreferencesStore.h; sourceTree = "<group>"; };
                BCD598AB112B7FDF00EC8C23 /* WebPreferencesStore.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebPreferencesStore.cpp; sourceTree = "<group>"; };
+               BCDE059911CDA8AE00E41AF1 /* WebContextInjectedBundleClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebContextInjectedBundleClient.h; sourceTree = "<group>"; };
+               BCDE059A11CDA8AE00E41AF1 /* WebContextInjectedBundleClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebContextInjectedBundleClient.cpp; sourceTree = "<group>"; };
                BCEE966A112FAF57006BCC24 /* Attachment.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Attachment.cpp; sourceTree = "<group>"; };
                BCEE966B112FAF57006BCC24 /* Attachment.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Attachment.h; sourceTree = "<group>"; };
                BCEE98C4113314D7006BCC24 /* WebPageNamespace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebPageNamespace.cpp; sourceTree = "<group>"; };
                                1A30066C1110F4F70031937C /* ResponsivenessTimer.h */,
                                BCB9E2421120DACA00A137E0 /* WebContext.cpp */,
                                BCB9E2411120DACA00A137E0 /* WebContext.h */,
+                               BCDE059A11CDA8AE00E41AF1 /* WebContextInjectedBundleClient.cpp */,
+                               BCDE059911CDA8AE00E41AF1 /* WebContextInjectedBundleClient.h */,
                                BCB9F69F1123A84B00A137E0 /* WebFramePolicyListenerProxy.cpp */,
                                BCB9F69E1123A84B00A137E0 /* WebFramePolicyListenerProxy.h */,
                                BC111B0A112F5E4F00337BAB /* WebFrameProxy.cpp */,
                                BC111B60112F638300337BAB /* WebPageMessageKinds.h */,
                                BC111B61112F638300337BAB /* WebPageProxyMessageKinds.h */,
                                BC111B62112F638300337BAB /* WebProcessMessageKinds.h */,
+                               BCB7346D11CEE3FF00EC5002 /* WebProcessProxyMessageKinds.h */,
                        );
                        path = CoreIPCSupport;
                        sourceTree = "<group>";
                                BC20528111C94284008F3375 /* WKBundlePage.h in Headers */,
                                BC20528811C943A5008F3375 /* InjectedBundlePageClient.h in Headers */,
                                1A3E736111CC2659007BD539 /* WebPlatformStrategies.h in Headers */,
+                               BCDE059B11CDA8AE00E41AF1 /* WebContextInjectedBundleClient.h in Headers */,
+                               BCB7346E11CEE3FF00EC5002 /* WebProcessProxyMessageKinds.h in Headers */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
                                BC20528211C94284008F3375 /* WKBundlePage.cpp in Sources */,
                                BC20528911C943A5008F3375 /* InjectedBundlePageClient.cpp in Sources */,
                                1A3E736211CC2659007BD539 /* WebPlatformStrategies.cpp in Sources */,
+                               BCDE059C11CDA8AE00E41AF1 /* WebContextInjectedBundleClient.cpp in Sources */,
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                };
index bfb4b0e1235fa1bdde827402795be69d08b839bc..0e8db37617d54a335e78461ee427e81e28fdb174 100644 (file)
@@ -25,8 +25,9 @@
 
 #include "WKBundle.h"
 
-#include "WKBundleAPICast.h"
 #include "InjectedBundle.h"
+#include "WKAPICast.h"
+#include "WKBundleAPICast.h"
 
 using namespace WebKit;
 
@@ -35,3 +36,8 @@ void WKBundleSetClient(WKBundleRef bundleRef, WKBundleClient * wkClient)
     if (wkClient && !wkClient->version)
         toWK(bundleRef)->initializeClient(wkClient);
 }
+
+void WKBundlePostMessage(WKBundleRef bundleRef, WKStringRef messageRef)
+{
+    toWK(bundleRef)->postMessage(toWK(messageRef));
+}
index 3a1b1accfd831c8316cd9e59f0425040e7faefa9..be8062921012855983c352c939cd87f9e19cca60 100644 (file)
@@ -26,6 +26,7 @@
 #ifndef WKBundle_h
 #define WKBundle_h
 
+#include <WebKit2/WKBase.h>
 #include <WebKit2/WKBundleBase.h>
 
 #ifdef __cplusplus
@@ -33,17 +34,21 @@ extern "C" {
 #endif
 
 // Client
-typedef void (*WKBundleDidCreatePageCallback)(WKBundlePageRef page, const void *clientInfo);
+typedef void (*WKBundleDidCreatePageCallback)(WKBundleRef bundle, WKBundlePageRef page, const void *clientInfo);
+typedef void (*WKBundleDidRecieveMessageCallback)(WKBundleRef bundle, WKStringRef message, const void *clientInfo);
 
 struct WKBundleClient {
     int                                                                 version;
     const void *                                                        clientInfo;
     WKBundleDidCreatePageCallback                                       didCreatePage;
+    WKBundleDidRecieveMessageCallback                                   didRecieveMessage;
 };
 typedef struct WKBundleClient WKBundleClient;
 
 WK_EXPORT void WKBundleSetClient(WKBundleRef bundle, WKBundleClient * client);
 
+WK_EXPORT void WKBundlePostMessage(WKBundleRef bundle, WKStringRef message);
+
 #ifdef __cplusplus
 }
 #endif
index f801839643ecf00f46308d883482c8b6802ad3bc..1e7fc23203f5e605d44205d6719a92495915d17c 100644 (file)
 
 #include "InjectedBundle.h"
 
+#include "WKAPICast.h"
 #include "WKBundleAPICast.h"
+#include "WebCoreTypeArgumentMarshalling.h"
+#include "WebProcess.h"
+#include "WebProcessProxyMessageKinds.h"
+
+using namespace WebCore;
 
 namespace WebKit {
 
@@ -48,10 +54,21 @@ void InjectedBundle::initializeClient(WKBundleClient* client)
         memset(&m_client, 0, sizeof(m_client));
 }
 
+void InjectedBundle::postMessage(StringImpl* message)
+{
+    WebProcess::shared().connection()->send(WebProcessProxyMessage::PostMessage, 0, CoreIPC::In(String(message)));
+}
+
 void InjectedBundle::didCreatePage(WebPage* page)
 {
     if (m_client.didCreatePage)
-        m_client.didCreatePage(toRef(page), m_client.clientInfo);
+        m_client.didCreatePage(toRef(this), toRef(page), m_client.clientInfo);
+}
+
+void InjectedBundle::didRecieveMessage(const WebCore::String& message)
+{
+    if (m_client.didRecieveMessage)
+        m_client.didRecieveMessage(toRef(this), toRef(message.impl()), m_client.clientInfo);
 }
 
 } // namespace WebKit
index ce2fd3f6e362bb2b7fbc01c86a2b14d6b15a32f3..fd865a3c7c9cf8577f8ac37e0d42a66252aacd4f 100644 (file)
@@ -53,9 +53,11 @@ public:
 
     // API
     void initializeClient(WKBundleClient*);
+    void postMessage(WebCore::StringImpl*);
 
     // Callback hooks
     void didCreatePage(WebPage*);
+    void didRecieveMessage(const WebCore::String&);
 
 private:
     InjectedBundle(const WebCore::String&);
index 3431c1a12d3906ec3abd11908548887cee64a623..c9a8a8cf2b334dc4e50846aeb6414ee03071929d 100644 (file)
@@ -69,7 +69,7 @@ void WebProcess::initialize(CoreIPC::Connection::Identifier serverIdentifier, Ru
     m_runLoop = runLoop;
 }
 
-void WebProcess::loadInjectedBundle(const WebCore::String& path)
+void WebProcess::loadInjectedBundle(const String& path)
 {
     ASSERT(m_pageMap.isEmpty());
     ASSERT(!path.isEmpty());
@@ -81,6 +81,14 @@ void WebProcess::loadInjectedBundle(const WebCore::String& path)
     }
 }
 
+void WebProcess::forwardMessageToInjectedBundle(const String& message)
+{
+    if (!m_injectedBundle)
+        return;
+
+    m_injectedBundle->didRecieveMessage(message);
+}
+
 WebPage* WebProcess::webPage(uint64_t pageID) const
 {
     return m_pageMap.get(pageID).get();
@@ -138,7 +146,7 @@ void WebProcess::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::Mes
     if (messageID.is<CoreIPC::MessageClassWebProcess>()) {
         switch (messageID.get<WebProcessMessage::Kind>()) {
             case WebProcessMessage::LoadInjectedBundle: {
-                WebCore::String path;
+                String path;
                 if (!arguments->decode(CoreIPC::Out(path)))
                     return;
 
@@ -156,6 +164,14 @@ void WebProcess::didReceiveMessage(CoreIPC::Connection* connection, CoreIPC::Mes
                 createWebPage(pageID, viewSize, store, static_cast<DrawingArea::Type>(drawingAreaType));
                 return;
             }
+            case WebProcessMessage::PostMessage: {
+                String message;
+                if (!arguments->decode(CoreIPC::Out(message)))
+                    return;
+
+                forwardMessageToInjectedBundle(message);
+                return;
+            }
         }
     }
 
index cdd9ea3d060188708a9f19e48228a3db5aca5542..b9eb6a255c9aabd9fb0f88cb98ad36ebe1162965 100644 (file)
@@ -63,6 +63,7 @@ private:
     void shutdown();
 
     void loadInjectedBundle(const WebCore::String&);
+    void forwardMessageToInjectedBundle(const WebCore::String&);
 
     // CoreIPC::Connection::Client
     void didReceiveMessage(CoreIPC::Connection*, CoreIPC::MessageID, CoreIPC::ArgumentDecoder*);
index 0037762bb413252a7befc3e22bcdbf68b2c6a829..a24a6bb6c50e86373ae845f014537ae36027371e 100644 (file)
@@ -1,14 +1,17 @@
 .objc_class_name_WKView
 _WKBundlePageGetMainFrameURL
 _WKBundlePageSetClient
+_WKBundlePostMessage
 _WKBundleSetClient
 _WKContextCreate
 _WKContextCreateWithInjectedBundlePath
 _WKContextGetSharedProcessContext
 _WKContextGetSharedThreadContext
 _WKContextGetStatistics
+_WKContextPostMessageToInjectedBundle
 _WKContextRelease
 _WKContextRetain
+_WKContextSetInjectedBundleClient
 _WKFrameGetFrameLoadState
 _WKFrameGetPage
 _WKFrameGetProvisionalURL
index ba4081f5c9c62208041c02b4679d898a61bb957b..f5b7ea60e36d86659add18c6240d4105838745fb 100755 (executable)
                                        RelativePath="..\Shared\CoreIPCSupport\WebProcessMessageKinds.h"\r
                                        >\r
                                </File>\r
+                               <File\r
+                                       RelativePath="..\Shared\CoreIPCSupport\WebProcessProxyMessageKinds.h"\r
+                                       >\r
+                               </File>\r
                        </Filter>\r
                        <Filter\r
                                Name="win"\r
                                RelativePath="..\UIProcess\WebContext.h"\r
                                >\r
                        </File>\r
+                       <File\r
+                               RelativePath="..\UIProcess\WebContextInjectedBundleClient.cpp"\r
+                               >\r
+                       </File>\r
+                       <File\r
+                               RelativePath="..\UIProcess\WebContextInjectedBundleClient.h"\r
+                               >\r
+                       </File>\r
                        <File\r
                                RelativePath="..\UIProcess\WebFramePolicyListenerProxy.cpp"\r
                                >\r
index 9a888c6e90a557a47d02f5262095d8b3779820a5..1db806ff7808c9f550ecd4ce5100b5927fa2d6a2 100644 (file)
@@ -1,3 +1,21 @@
+2010-06-21  Sam Weinig  <sam@webkit.org>
+
+        Reviewed by Anders Carlsson.
+
+        Patch for https://bugs.webkit.org/show_bug.cgi?id=40940
+        Add message passing support to the WebKit2 API.
+
+        - Add some test messages.
+
+        * MiniBrowser/mac/AppDelegate.m:
+        (_didRecieveMessageFromInjectedBundle):
+        (-[BrowserAppDelegate init]):
+        * MiniBrowser/mac/WebBundle/WebBundleMain.m:
+        (_didClearWindow):
+        (_didCreatePage):
+        (_didRecieveMessage):
+        (WKBundleInitialize):
+
 2010-06-21  Drew Wilson  <atwilson@chromium.org>
 
         Unreviewed.
index 02ecb47f2f475194a3271daa26192d82f50f7ee0..6798bfc801930322cc4fd3b752741a6a7cd42803 100644 (file)
@@ -35,6 +35,17 @@ static NSString *defaultURL = @"http://webkit.org/";
 
 @implementation BrowserAppDelegate
 
+void _didRecieveMessageFromInjectedBundle(WKContextRef context, WKStringRef message, const void *clientInfo)
+{
+    CFStringRef cfMessage = WKStringCopyCFString(0, message);
+    NSLog(@"ContextInjectedBundleClient - didRecieveMessage - message: %@", cfMessage);
+    CFRelease(cfMessage);
+
+    WKStringRef newMessage = WKStringCreateWithCFString(CFSTR("Roger that!"));
+    WKContextPostMessageToInjectedBundle(context, newMessage);
+    WKStringRelease(newMessage);
+}
+
 - (id)init
 {
     self = [super init];
@@ -52,6 +63,14 @@ static NSString *defaultURL = @"http://webkit.org/";
         WKStringRef bundlePath = WKStringCreateWithCFString(bundlePathCF);
 
         WKContextRef processContext = WKContextCreateWithInjectedBundlePath(bundlePath);
+        
+        WKContextInjectedBundleClient bundleClient = {
+            0,      /* version */
+            0,      /* clientInfo */
+            _didRecieveMessageFromInjectedBundle
+        };
+        WKContextSetInjectedBundleClient(processContext, &bundleClient);
+        
         processPageNamespace = WKPageNamespaceCreate(processContext);
         WKContextRelease(processContext);
 
index 2234b700a37ba4c8bd5d4b5a36c51af018fbaa46..ad382dc946ab30f3c56608ebab32acbacde12d41 100644 (file)
  * THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <stdio.h>
 #include <Cocoa/Cocoa.h>
 #include <WebKit2/WKBundle.h>
-#include <WebKit2/WKBundlePage.h>
 #include <WebKit2/WKBundleInitialize.h>
+#include <WebKit2/WKBundlePage.h>
+#include <WebKit2/WKString.h>
+#include <WebKit2/WKStringCF.h>
 #include <WebKit2/WKURLCF.h>
+#include <stdio.h>
 
 static WKBundleRef globalBundle;
 
@@ -37,9 +39,13 @@ void _didClearWindow(WKBundlePageRef page, WKBundleFrameRef frame, JSContextRef
     CFURLRef cfURL = WKURLCopyCFURL(0, WKBundlePageGetMainFrameURL(page));
     NSLog(@"WKBundlePageClient - _didClearWindowForFrame %@", [(NSURL *)cfURL absoluteString]);
     CFRelease(cfURL);
+
+    WKStringRef message = WKStringCreateWithCFString(CFSTR("Window was cleared"));
+    WKBundlePostMessage(globalBundle, message);
+    WKStringRelease(message);
 }
 
-void _didCreatePage(WKBundlePageRef page, const void* clientInfo)
+void _didCreatePage(WKBundlePageRef bundle, WKBundlePageRef page, const void* clientInfo)
 {
     NSLog(@"WKBundleClient - didCreatePage\n");
 
@@ -51,6 +57,13 @@ void _didCreatePage(WKBundlePageRef page, const void* clientInfo)
     WKBundlePageSetClient(page, &client);
 }
 
+void _didRecieveMessage(WKBundleRef bundle, WKStringRef message, const void *clientInfo)
+{
+    CFStringRef cfMessage = WKStringCopyCFString(0, message);
+    NSLog(@"WKBundleClient - didRecieveMessage %@\n", cfMessage);
+    CFRelease(cfMessage);
+}
+
 void WKBundleInitialize(WKBundleRef bundle)
 {
     globalBundle = bundle;
@@ -58,7 +71,8 @@ void WKBundleInitialize(WKBundleRef bundle)
     WKBundleClient client = {
         0,
         0,
-        _didCreatePage
+        _didCreatePage,
+        _didRecieveMessage
     };
     WKBundleSetClient(bundle, &client);
 }