Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: chrome/renderer/webworker_proxy.cc

Issue 173193: Updating Worker.postMessage(), DOMWindow.postMessage(), and... (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/webworker_proxy.h ('k') | chrome/worker/nativewebworker_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/webworker_proxy.h" 5 #include "chrome/renderer/webworker_proxy.h"
6 6
7 #include "chrome/common/child_thread.h" 7 #include "chrome/common/child_thread.h"
8 #include "chrome/common/render_messages.h" 8 #include "chrome/common/render_messages.h"
9 #include "chrome/common/webmessageportchannel_impl.h" 9 #include "chrome/common/webmessageportchannel_impl.h"
10 #include "chrome/common/worker_messages.h" 10 #include "chrome/common/worker_messages.h"
11 #include "webkit/api/public/WebURL.h" 11 #include "webkit/api/public/WebURL.h"
12 #include "webkit/api/public/WebWorkerClient.h" 12 #include "webkit/api/public/WebWorkerClient.h"
13 13
14 using WebKit::WebMessagePortChannel; 14 using WebKit::WebMessagePortChannel;
15 using WebKit::WebMessagePortChannelArray;
15 using WebKit::WebString; 16 using WebKit::WebString;
16 using WebKit::WebURL; 17 using WebKit::WebURL;
17 using WebKit::WebWorkerClient; 18 using WebKit::WebWorkerClient;
18 19
19 WebWorkerProxy::WebWorkerProxy( 20 WebWorkerProxy::WebWorkerProxy(
20 WebWorkerClient* client, 21 WebWorkerClient* client,
21 ChildThread* child_thread, 22 ChildThread* child_thread,
22 int render_view_route_id) 23 int render_view_route_id)
23 : route_id_(MSG_ROUTING_NONE), 24 : route_id_(MSG_ROUTING_NONE),
24 child_thread_(child_thread), 25 child_thread_(child_thread),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 } 69 }
69 70
70 void WebWorkerProxy::terminateWorkerContext() { 71 void WebWorkerProxy::terminateWorkerContext() {
71 if (route_id_ != MSG_ROUTING_NONE) { 72 if (route_id_ != MSG_ROUTING_NONE) {
72 Send(new WorkerMsg_TerminateWorkerContext(route_id_)); 73 Send(new WorkerMsg_TerminateWorkerContext(route_id_));
73 Disconnect(); 74 Disconnect();
74 } 75 }
75 } 76 }
76 77
77 void WebWorkerProxy::postMessageToWorkerContext( 78 void WebWorkerProxy::postMessageToWorkerContext(
78 const WebString& message, WebMessagePortChannel* channel) { 79 const WebString& message, const WebMessagePortChannelArray& channels) {
79 int message_port_id = MSG_ROUTING_NONE; 80 std::vector<int> message_port_ids(channels.size());
80 if (channel) { 81 std::vector<int> routing_ids(channels.size());
82 for (size_t i = 0; i < channels.size(); ++i) {
81 WebMessagePortChannelImpl* webchannel = 83 WebMessagePortChannelImpl* webchannel =
82 static_cast<WebMessagePortChannelImpl*>(channel); 84 static_cast<WebMessagePortChannelImpl*>(channels[i]);
83 message_port_id = webchannel->message_port_id(); 85 message_port_ids[i] = webchannel->message_port_id();
84 webchannel->QueueMessages(); 86 webchannel->QueueMessages();
85 DCHECK(message_port_id != MSG_ROUTING_NONE); 87 routing_ids[i] = MSG_ROUTING_NONE;
88 DCHECK(message_port_ids[i] != MSG_ROUTING_NONE);
86 } 89 }
87 90
88 Send(new WorkerMsg_PostMessage( 91 Send(new WorkerMsg_PostMessage(
89 route_id_, message, message_port_id, MSG_ROUTING_NONE)); 92 route_id_, message, message_port_ids, routing_ids));
90 } 93 }
91 94
92 void WebWorkerProxy::workerObjectDestroyed() { 95 void WebWorkerProxy::workerObjectDestroyed() {
93 Send(new WorkerMsg_WorkerObjectDestroyed(route_id_)); 96 Send(new WorkerMsg_WorkerObjectDestroyed(route_id_));
94 delete this; 97 delete this;
95 } 98 }
96 99
97 bool WebWorkerProxy::Send(IPC::Message* message) { 100 bool WebWorkerProxy::Send(IPC::Message* message) {
98 // It's possible that postMessage is called before the worker is created, in 101 // It's possible that postMessage is called before the worker is created, in
99 // which case route_id_ will be none. Or the worker object can be interacted 102 // which case route_id_ will be none. Or the worker object can be interacted
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 void WebWorkerProxy::OnDedicatedWorkerCreated() { 143 void WebWorkerProxy::OnDedicatedWorkerCreated() {
141 DCHECK(queued_messages_.size()); 144 DCHECK(queued_messages_.size());
142 std::vector<IPC::Message*> queued_messages = queued_messages_; 145 std::vector<IPC::Message*> queued_messages = queued_messages_;
143 queued_messages_.clear(); 146 queued_messages_.clear();
144 for (size_t i = 0; i < queued_messages.size(); ++i) { 147 for (size_t i = 0; i < queued_messages.size(); ++i) {
145 queued_messages[i]->set_routing_id(route_id_); 148 queued_messages[i]->set_routing_id(route_id_);
146 Send(queued_messages[i]); 149 Send(queued_messages[i]);
147 } 150 }
148 } 151 }
149 152
150 void WebWorkerProxy::OnPostMessage(const string16& message, 153 void WebWorkerProxy::OnPostMessage(
151 int sent_message_port_id, 154 const string16& message,
152 int new_routing_id) { 155 const std::vector<int>& sent_message_port_ids,
153 WebMessagePortChannel* channel = NULL; 156 const std::vector<int>& new_routing_ids) {
154 if (sent_message_port_id != MSG_ROUTING_NONE) { 157 DCHECK(new_routing_ids.size() == sent_message_port_ids.size());
155 channel = new WebMessagePortChannelImpl( 158 WebMessagePortChannelArray channels(sent_message_port_ids.size());
156 new_routing_id, sent_message_port_id); 159 for (size_t i = 0; i < sent_message_port_ids.size(); ++i) {
160 channels[i] = new WebMessagePortChannelImpl(
161 new_routing_ids[i], sent_message_port_ids[i]);
157 } 162 }
158 163
159 client_->postMessageToWorkerObject(message, channel); 164 client_->postMessageToWorkerObject(message, channels);
160 } 165 }
161 166
162 void WebWorkerProxy::OnPostConsoleMessageToWorkerObject( 167 void WebWorkerProxy::OnPostConsoleMessageToWorkerObject(
163 const WorkerHostMsg_PostConsoleMessageToWorkerObject_Params& params) { 168 const WorkerHostMsg_PostConsoleMessageToWorkerObject_Params& params) {
164 client_->postConsoleMessageToWorkerObject(params.destination_identifier, 169 client_->postConsoleMessageToWorkerObject(params.destination_identifier,
165 params.source_identifier, params.message_type, params.message_level, 170 params.source_identifier, params.message_type, params.message_level,
166 params.message, params.line_number, params.source_url); 171 params.message, params.line_number, params.source_url);
167 } 172 }
168 173
OLDNEW
« no previous file with comments | « chrome/renderer/webworker_proxy.h ('k') | chrome/worker/nativewebworker_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698