summaryrefslogtreecommitdiffstats
path: root/webkit/glue
diff options
context:
space:
mode:
authorlevin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-30 18:11:15 +0000
committerlevin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-30 18:11:15 +0000
commitc8dfb0a3a2bec575024c195a325cc2ebb6b1ed23 (patch)
tree4d2faa6b3c9dce3cf98cb11acbd4b4a733b4f32e /webkit/glue
parent3e7612f0abcaeeaeb0aad3e0c7e0bbf6a9e6fd2d (diff)
downloadchromium_src-c8dfb0a3a2bec575024c195a325cc2ebb6b1ed23.zip
chromium_src-c8dfb0a3a2bec575024c195a325cc2ebb6b1ed23.tar.gz
chromium_src-c8dfb0a3a2bec575024c195a325cc2ebb6b1ed23.tar.bz2
Chromium implementation of new WebKit postMessageToWorkerObject/Context APIs
that accept MessagePortChannels as an optional parameter. For now, we just ignore passed-in MessagePortChannels (they are automatically freed) but we'll add support for them once the Chromium implementation of cross-process MessagePorts is in place. This is the chromium-side change for https://bugs.webkit.org/show_bug.cgi?id=25435 and should not be landed until that change lands in the WebKit tree. BUG=15426 TEST=none (WebKit change contains LayoutTests) R=levin@chromium.org Review URL: http://codereview.chromium.org/147189 Review URL: http://codereview.chromium.org/151090 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19608 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue')
-rw-r--r--webkit/glue/webworker_impl.cc29
-rw-r--r--webkit/glue/webworker_impl.h12
-rw-r--r--webkit/glue/webworkerclient_impl.cc38
-rw-r--r--webkit/glue/webworkerclient_impl.h12
4 files changed, 70 insertions, 21 deletions
diff --git a/webkit/glue/webworker_impl.cc b/webkit/glue/webworker_impl.cc
index b648cf1..65131d5 100644
--- a/webkit/glue/webworker_impl.cc
+++ b/webkit/glue/webworker_impl.cc
@@ -8,6 +8,8 @@
#include "GenericWorkerTask.h"
#include "KURL.h"
+#include "MessagePort.h"
+#include "MessagePortChannel.h"
#include "ScriptExecutionContext.h"
#include "SecurityOrigin.h"
#include "SubstituteData.h"
@@ -128,11 +130,18 @@ WebWorkerImpl::~WebWorkerImpl() {
void WebWorkerImpl::PostMessageToWorkerContextTask(
WebCore::ScriptExecutionContext* context,
WebWorkerImpl* this_ptr,
- const WebCore::String& message) {
+ const WebCore::String& message,
+ WTF::PassOwnPtr<WebCore::MessagePortChannel> channel) {
DCHECK(context->isWorkerContext());
WebCore::WorkerContext* worker_context =
static_cast<WebCore::WorkerContext*>(context);
- worker_context->dispatchMessage(message);
+
+ WTF::RefPtr<WebCore::MessagePort> port;
+ if (channel) {
+ port = WebCore::MessagePort::create(*context);
+ port->entangle(channel.release());
+ }
+ worker_context->dispatchMessage(message, port.release());
this_ptr->confirmMessageFromWorkerObject(
worker_context->hasPendingActivity());
@@ -189,10 +198,12 @@ void WebWorkerImpl::terminateWorkerContext() {
}
void WebWorkerImpl::postMessageToWorkerContext(const WebString& message) {
+ // TODO(jam): Need to update these APIs to accept MessagePorts.
worker_thread_->runLoop().postTask(WebCore::createCallbackTask(
&PostMessageToWorkerContextTask,
this,
- webkit_glue::WebStringToString(message)));
+ webkit_glue::WebStringToString(message),
+ WTF::PassOwnPtr<WebCore::MessagePortChannel>(0)));
}
void WebWorkerImpl::workerObjectDestroyed() {
@@ -212,17 +223,23 @@ void WebWorkerImpl::InvokeTaskMethod(void* param) {
// WorkerObjectProxy -----------------------------------------------------------
-void WebWorkerImpl::postMessageToWorkerObject(const WebCore::String& message) {
+void WebWorkerImpl::postMessageToWorkerObject(
+ const WebCore::String& message,
+ WTF::PassOwnPtr<WebCore::MessagePortChannel> channel) {
DispatchTaskToMainThread(WebCore::createCallbackTask(
&PostMessageTask,
this,
- message));
+ message,
+ channel));
}
void WebWorkerImpl::PostMessageTask(
WebCore::ScriptExecutionContext* context,
WebWorkerImpl* this_ptr,
- WebCore::String message) {
+ WebCore::String message,
+ WTF::PassOwnPtr<WebCore::MessagePortChannel> channel) {
+ // TODO(jam): Update to pass a MessagePortChannel or
+ // PlatformMessagePortChannel when we add MessagePort support to Chrome.
this_ptr->client_->postMessageToWorkerObject(
webkit_glue::StringToWebString(message));
}
diff --git a/webkit/glue/webworker_impl.h b/webkit/glue/webworker_impl.h
index db12c09..6f083b6 100644
--- a/webkit/glue/webworker_impl.h
+++ b/webkit/glue/webworker_impl.h
@@ -12,10 +12,12 @@
#include "ScriptExecutionContext.h"
#include "WorkerLoaderProxy.h"
#include "WorkerObjectProxy.h"
+#include <wtf/PassOwnPtr.h>
#include <wtf/RefPtr.h>
namespace WebCore {
class Strng;
+class MessagePortChannel;
class WorkerThread;
};
@@ -33,7 +35,9 @@ class WebWorkerImpl: public WebCore::WorkerObjectProxy,
explicit WebWorkerImpl(WebKit::WebWorkerClient* client);
// WebCore::WorkerObjectProxy methods:
- virtual void postMessageToWorkerObject(const WebCore::String& message);
+ virtual void postMessageToWorkerObject(
+ const WebCore::String& message,
+ WTF::PassOwnPtr<WebCore::MessagePortChannel> channel);
virtual void postExceptionToWorkerObject(
const WebCore::String& error_message,
int line_number,
@@ -77,7 +81,8 @@ class WebWorkerImpl: public WebCore::WorkerObjectProxy,
static void PostMessageToWorkerContextTask(
WebCore::ScriptExecutionContext* context,
WebWorkerImpl* this_ptr,
- const WebCore::String& message);
+ const WebCore::String& message,
+ WTF::PassOwnPtr<WebCore::MessagePortChannel> channel);
// Function used to invoke tasks on the main thread.
static void InvokeTaskMethod(void* param);
@@ -86,7 +91,8 @@ class WebWorkerImpl: public WebCore::WorkerObjectProxy,
static void PostMessageTask(
WebCore::ScriptExecutionContext* context,
WebWorkerImpl* this_ptr,
- WebCore::String message);
+ WebCore::String message,
+ WTF::PassOwnPtr<WebCore::MessagePortChannel> channel);
static void PostExceptionTask(
WebCore::ScriptExecutionContext* context,
WebWorkerImpl* this_ptr,
diff --git a/webkit/glue/webworkerclient_impl.cc b/webkit/glue/webworkerclient_impl.cc
index b0db8a0..d915ca7 100644
--- a/webkit/glue/webworkerclient_impl.cc
+++ b/webkit/glue/webworkerclient_impl.cc
@@ -11,6 +11,8 @@
#include "Frame.h"
#include "FrameLoaderClient.h"
#include "GenericWorkerTask.h"
+#include "MessagePort.h"
+#include "MessagePortChannel.h"
#include "ScriptExecutionContext.h"
#include "WorkerContextExecutionProxy.h"
#include "WorkerMessagingProxy.h"
@@ -145,7 +147,8 @@ void WebWorkerClientImpl::terminateWorkerContext() {
}
void WebWorkerClientImpl::postMessageToWorkerContext(
- const WebCore::String& message) {
+ const WebCore::String& message,
+ WTF::PassOwnPtr<WebCore::MessagePortChannel> port) {
// Worker.terminate() could be called from JS before the context is started.
if (asked_to_terminate_)
return;
@@ -154,11 +157,13 @@ void WebWorkerClientImpl::postMessageToWorkerContext(
if (!WTF::isMainThread()) {
WebWorkerImpl::DispatchTaskToMainThread(
- WebCore::createCallbackTask(&PostMessageToWorkerContextTask, this,
- message));
+ WebCore::createCallbackTask(
+ &PostMessageToWorkerContextTask, this, message, port));
return;
}
+ // TODO(jam): Update to pass a MessagePortChannel or
+ // PlatformMessagePortChannel when we add MessagePort support to Chrome.
webworker_->postMessageToWorkerContext(
webkit_glue::StringToWebString(message));
}
@@ -181,14 +186,17 @@ void WebWorkerClientImpl::workerObjectDestroyed() {
}
void WebWorkerClientImpl::postMessageToWorkerObject(const WebString& message) {
+ // TODO(jam): Add support for passing MessagePorts when they are supported
+ // in Chrome.
if (WTF::currentThread() != worker_thread_id_) {
script_execution_context_->postTask(
WebCore::createCallbackTask(&PostMessageToWorkerObjectTask, this,
- webkit_glue::WebStringToString(message)));
+ webkit_glue::WebStringToString(message),
+ WTF::PassOwnPtr<WebCore::MessagePortChannel>(0)));
return;
}
- worker_->dispatchMessage(webkit_glue::WebStringToString(message));
+ worker_->dispatchMessage(webkit_glue::WebStringToString(message), 0);
}
void WebWorkerClientImpl::postExceptionToWorkerObject(
@@ -276,7 +284,10 @@ void WebWorkerClientImpl::TerminateWorkerContextTask(
void WebWorkerClientImpl::PostMessageToWorkerContextTask(
WebCore::ScriptExecutionContext* context,
WebWorkerClientImpl* this_ptr,
- const WebCore::String& message) {
+ const WebCore::String& message,
+ WTF::PassOwnPtr<WebCore::MessagePortChannel> channel) {
+ // TODO(jam): Update to pass a MessagePortChannel or
+ // PlatformMessagePortChannel when we add MessagePort support to Chrome.
this_ptr->webworker_->postMessageToWorkerContext(
webkit_glue::StringToWebString(message));
}
@@ -292,9 +303,18 @@ void WebWorkerClientImpl::WorkerObjectDestroyedTask(
void WebWorkerClientImpl::PostMessageToWorkerObjectTask(
WebCore::ScriptExecutionContext* context,
WebWorkerClientImpl* this_ptr,
- const WebCore::String& message) {
- if (this_ptr->worker_)
- this_ptr->worker_->dispatchMessage(message);
+ const WebCore::String& message,
+ WTF::PassOwnPtr<WebCore::MessagePortChannel> channel) {
+
+ if (this_ptr->worker_) {
+ WTF::RefPtr<WebCore::MessagePort> port;
+ if (channel) {
+ port = WebCore::MessagePort::create(*context);
+ port->entangle(channel.release());
+ }
+
+ this_ptr->worker_->dispatchMessage(message, port.release());
+ }
}
void WebWorkerClientImpl::PostExceptionToWorkerObjectTask(
diff --git a/webkit/glue/webworkerclient_impl.h b/webkit/glue/webworkerclient_impl.h
index f76ed5e..b5f1aac 100644
--- a/webkit/glue/webworkerclient_impl.h
+++ b/webkit/glue/webworkerclient_impl.h
@@ -10,9 +10,11 @@
#include "webkit/api/public/WebWorkerClient.h"
#include "WorkerContextProxy.h"
+#include <wtf/PassOwnPtr.h>
#include <wtf/RefPtr.h>
namespace WebCore {
+class MessagePortChannel;
class ScriptExecutionContext;
}
namespace WebKit {
@@ -38,7 +40,9 @@ class WebWorkerClientImpl : public WebCore::WorkerContextProxy,
const WebCore::String& user_agent,
const WebCore::String& source_code);
virtual void terminateWorkerContext();
- virtual void postMessageToWorkerContext(const WebCore::String& message);
+ virtual void postMessageToWorkerContext(
+ const WebCore::String& message,
+ WTF::PassOwnPtr<WebCore::MessagePortChannel> channel);
virtual bool hasPendingActivity() const;
virtual void workerObjectDestroyed();
@@ -81,7 +85,8 @@ class WebWorkerClientImpl : public WebCore::WorkerContextProxy,
static void PostMessageToWorkerContextTask(
WebCore::ScriptExecutionContext* context,
WebWorkerClientImpl* this_ptr,
- const WebCore::String& message);
+ const WebCore::String& message,
+ WTF::PassOwnPtr<WebCore::MessagePortChannel> channel);
static void WorkerObjectDestroyedTask(
WebCore::ScriptExecutionContext* context,
WebWorkerClientImpl* this_ptr);
@@ -92,7 +97,8 @@ class WebWorkerClientImpl : public WebCore::WorkerContextProxy,
static void PostMessageToWorkerObjectTask(
WebCore::ScriptExecutionContext* context,
WebWorkerClientImpl* this_ptr,
- const WebCore::String& message);
+ const WebCore::String& message,
+ WTF::PassOwnPtr<WebCore::MessagePortChannel> channel);
static void PostExceptionToWorkerObjectTask(
WebCore::ScriptExecutionContext* context,
WebWorkerClientImpl* this_ptr,