diff options
author | jorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-26 21:38:03 +0000 |
---|---|---|
committer | jorlow@chromium.org <jorlow@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-26 21:38:03 +0000 |
commit | c36a24cbfdc6cb945f104d65174ef2aaa59e5dd3 (patch) | |
tree | 6f77d943b793b1f6968660c2ce3fb32f432369ed /chrome/worker | |
parent | c28a6aac0d9687b43781bb21fdef3b6849c0d398 (diff) | |
download | chromium_src-c36a24cbfdc6cb945f104d65174ef2aaa59e5dd3.zip chromium_src-c36a24cbfdc6cb945f104d65174ef2aaa59e5dd3.tar.gz chromium_src-c36a24cbfdc6cb945f104d65174ef2aaa59e5dd3.tar.bz2 |
First half of updating Worker.postMessage(), DOMWindow.postMessage(), and
MessagePort.postMessage() to accept multiple MessagePorts.
Original review: http://codereview.chromium.org/173193
TBR=atwilson
TEST=None (new functionality not yet exposed via bindings, so existing tests suffice)
BUG=19948
Review URL: http://codereview.chromium.org/174566
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24536 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/worker')
-rw-r--r-- | chrome/worker/nativewebworker_impl.cc | 6 | ||||
-rw-r--r-- | chrome/worker/nativewebworker_impl.h | 5 | ||||
-rw-r--r-- | chrome/worker/webworkerclient_proxy.cc | 34 | ||||
-rw-r--r-- | chrome/worker/webworkerclient_proxy.h | 10 |
4 files changed, 32 insertions, 23 deletions
diff --git a/chrome/worker/nativewebworker_impl.cc b/chrome/worker/nativewebworker_impl.cc index 5fc3ddc..9dfd739 100644 --- a/chrome/worker/nativewebworker_impl.cc +++ b/chrome/worker/nativewebworker_impl.cc @@ -35,7 +35,8 @@ class PostMessageTask : public Task { } ~PostMessageTask() { } void Run() { - client_->postMessageToWorkerObject(message_string_, NULL); + WebKit::WebMessagePortChannelArray empty_array; + client_->postMessageToWorkerObject(message_string_, empty_array); } private: @@ -147,7 +148,8 @@ void NativeWebWorkerImpl::terminateWorkerContext() { } void NativeWebWorkerImpl::postMessageToWorkerContext( - const WebKit::WebString& message, WebKit::WebMessagePortChannel* channel) { + const WebKit::WebString& message, + const WebKit::WebMessagePortChannelArray& channel) { size_t len; char* bufp = WebStringToCharp(message, &len); // Send a message to NaCl object diff --git a/chrome/worker/nativewebworker_impl.h b/chrome/worker/nativewebworker_impl.h index 7d0944c..29d85c9 100644 --- a/chrome/worker/nativewebworker_impl.h +++ b/chrome/worker/nativewebworker_impl.h @@ -27,8 +27,9 @@ class NativeWebWorkerImpl : public WebKit::WebWorker { const WebKit::WebString& user_agent, const WebKit::WebString& source_code); void terminateWorkerContext(); - void postMessageToWorkerContext(const WebKit::WebString& message, - WebKit::WebMessagePortChannel* channel); + void postMessageToWorkerContext( + const WebKit::WebString& message, + const WebKit::WebMessagePortChannelArray& channels); void workerObjectDestroyed(); private: diff --git a/chrome/worker/webworkerclient_proxy.cc b/chrome/worker/webworkerclient_proxy.cc index fdbaf9a..f0c6571 100644 --- a/chrome/worker/webworkerclient_proxy.cc +++ b/chrome/worker/webworkerclient_proxy.cc @@ -18,6 +18,7 @@ #include "webkit/api/public/WebWorker.h" using WebKit::WebMessagePortChannel; +using WebKit::WebMessagePortChannelArray; using WebKit::WebString; using WebKit::WebWorker; using WebKit::WebWorkerClient; @@ -81,18 +82,20 @@ WebWorkerClientProxy::~WebWorkerClientProxy() { void WebWorkerClientProxy::postMessageToWorkerObject( const WebString& message, - WebMessagePortChannel* channel) { - int message_port_id = MSG_ROUTING_NONE; - if (channel) { + const WebMessagePortChannelArray& channels) { + std::vector<int> message_port_ids(channels.size()); + std::vector<int> routing_ids(channels.size()); + for (size_t i = 0; i < channels.size(); ++i) { WebMessagePortChannelImpl* webchannel = - static_cast<WebMessagePortChannelImpl*>(channel); - message_port_id = webchannel->message_port_id(); + static_cast<WebMessagePortChannelImpl*>(channels[i]); + message_port_ids[i] = webchannel->message_port_id(); webchannel->QueueMessages(); - DCHECK(message_port_id != MSG_ROUTING_NONE); + DCHECK(message_port_ids[i] != MSG_ROUTING_NONE); + routing_ids[i] = MSG_ROUTING_NONE; } Send(new WorkerMsg_PostMessage( - route_id_, message, message_port_id, MSG_ROUTING_NONE)); + route_id_, message, message_port_ids, routing_ids)); } void WebWorkerClientProxy::postExceptionToWorkerObject( @@ -179,14 +182,15 @@ void WebWorkerClientProxy::OnTerminateWorkerContext() { new KillProcessTask(this), kMaxTimeForRunawayWorkerMs); } -void WebWorkerClientProxy::OnPostMessage(const string16& message, - int sent_message_port_id, - int new_routing_id) { - WebMessagePortChannel* channel = NULL; - if (sent_message_port_id != MSG_ROUTING_NONE) { - channel = new WebMessagePortChannelImpl( - new_routing_id, sent_message_port_id); +void WebWorkerClientProxy::OnPostMessage( + const string16& message, + const std::vector<int>& sent_message_port_ids, + const std::vector<int>& new_routing_ids) { + WebMessagePortChannelArray channels(sent_message_port_ids.size()); + for (size_t i = 0; i < sent_message_port_ids.size(); i++) { + channels[i] = new WebMessagePortChannelImpl( + new_routing_ids[i], sent_message_port_ids[i]); } - impl_->postMessageToWorkerContext(message, channel); + impl_->postMessageToWorkerContext(message, channels); } diff --git a/chrome/worker/webworkerclient_proxy.h b/chrome/worker/webworkerclient_proxy.h index aadbe07..8807d63 100644 --- a/chrome/worker/webworkerclient_proxy.h +++ b/chrome/worker/webworkerclient_proxy.h @@ -5,6 +5,8 @@ #ifndef CHROME_WORKER_WEBWORKERCLIENT_PROXY_H_ #define CHROME_WORKER_WEBWORKERCLIENT_PROXY_H_ +#include <vector> + #include "base/basictypes.h" #include "googleurl/src/gurl.h" #include "ipc/ipc_channel.h" @@ -27,7 +29,7 @@ class WebWorkerClientProxy : public WebKit::WebWorkerClient, // WebWorkerClient implementation. virtual void postMessageToWorkerObject( const WebKit::WebString& message, - WebKit::WebMessagePortChannel* channel); + const WebKit::WebMessagePortChannelArray& channel); virtual void postExceptionToWorkerObject( const WebKit::WebString& error_message, int line_number, @@ -49,14 +51,14 @@ class WebWorkerClientProxy : public WebKit::WebWorkerClient, virtual void OnMessageReceived(const IPC::Message& message); private: - ~WebWorkerClientProxy (); + ~WebWorkerClientProxy(); bool Send(IPC::Message* message); void OnTerminateWorkerContext(); void OnPostMessage(const string16& message, - int sent_message_port_id, - int new_routing_id); + const std::vector<int>& sent_message_port_ids, + const std::vector<int>& new_routing_ids); // The source url for this worker. GURL url_; |