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

Side by Side Diff: webkit/glue/webworkerclient_impl.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
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 "config.h" 5 #include "config.h"
6 6
7 #if ENABLE(WORKERS) 7 #if ENABLE(WORKERS)
8 8
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 10
(...skipping 23 matching lines...) Expand all
34 #include "webkit/api/public/WebWorker.h" 34 #include "webkit/api/public/WebWorker.h"
35 #include "webkit/api/src/PlatformMessagePortChannel.h" 35 #include "webkit/api/src/PlatformMessagePortChannel.h"
36 #include "webkit/glue/glue_util.h" 36 #include "webkit/glue/glue_util.h"
37 #include "webkit/glue/webframeloaderclient_impl.h" 37 #include "webkit/glue/webframeloaderclient_impl.h"
38 #include "webkit/glue/webframe_impl.h" 38 #include "webkit/glue/webframe_impl.h"
39 #include "webkit/glue/webview_delegate.h" 39 #include "webkit/glue/webview_delegate.h"
40 #include "webkit/glue/webview_impl.h" 40 #include "webkit/glue/webview_impl.h"
41 #include "webkit/glue/webworker_impl.h" 41 #include "webkit/glue/webworker_impl.h"
42 42
43 using WebKit::WebMessagePortChannel; 43 using WebKit::WebMessagePortChannel;
44 using WebKit::WebMessagePortChannelArray;
44 using WebKit::WebString; 45 using WebKit::WebString;
45 using WebKit::WebWorker; 46 using WebKit::WebWorker;
46 using WebKit::WebWorkerClient; 47 using WebKit::WebWorkerClient;
47 48
48 // When WebKit creates a WorkerContextProxy object, we check if we're in the 49 // When WebKit creates a WorkerContextProxy object, we check if we're in the
49 // renderer or worker process. If the latter, then we just use 50 // renderer or worker process. If the latter, then we just use
50 // WebCore::WorkerMessagingProxy. 51 // WebCore::WorkerMessagingProxy.
51 // 52 //
52 // If we're in the renderer process, then we need use the glue provided 53 // If we're in the renderer process, then we need use the glue provided
53 // WebWorker object to talk to the worker process over IPC. The worker process 54 // WebWorker object to talk to the worker process over IPC. The worker process
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 WebWorkerImpl::DispatchTaskToMainThread( 148 WebWorkerImpl::DispatchTaskToMainThread(
148 WebCore::createCallbackTask(&TerminateWorkerContextTask, this)); 149 WebCore::createCallbackTask(&TerminateWorkerContextTask, this));
149 return; 150 return;
150 } 151 }
151 152
152 webworker_->terminateWorkerContext(); 153 webworker_->terminateWorkerContext();
153 } 154 }
154 155
155 void WebWorkerClientImpl::postMessageToWorkerContext( 156 void WebWorkerClientImpl::postMessageToWorkerContext(
156 const WebCore::String& message, 157 const WebCore::String& message,
157 WTF::PassOwnPtr<WebCore::MessagePortChannel> channel) { 158 WTF::PassOwnPtr<WebCore::MessagePortChannelArray> channels) {
158 // Worker.terminate() could be called from JS before the context is started. 159 // Worker.terminate() could be called from JS before the context is started.
159 if (asked_to_terminate_) 160 if (asked_to_terminate_)
160 return; 161 return;
161 162
162 ++unconfirmed_message_count_; 163 ++unconfirmed_message_count_;
163 164
164 if (!WTF::isMainThread()) { 165 if (!WTF::isMainThread()) {
165 WebWorkerImpl::DispatchTaskToMainThread( 166 WebWorkerImpl::DispatchTaskToMainThread(
166 WebCore::createCallbackTask( 167 WebCore::createCallbackTask(
167 &PostMessageToWorkerContextTask, this, message, channel)); 168 &PostMessageToWorkerContextTask, this, message, channels));
168 return; 169 return;
169 } 170 }
170 171
171 WebMessagePortChannel* webchannel = NULL; 172 WebMessagePortChannelArray webchannels(channels.get() ? channels->size() : 0);
172 if (channel.get()) { 173
173 webchannel = channel->channel()->webChannelRelease(); 174 for (size_t i = 0; i < webchannels.size(); ++i) {
175 WebMessagePortChannel* webchannel =
176 (*channels)[i]->channel()->webChannelRelease();
174 webchannel->setClient(0); 177 webchannel->setClient(0);
178 webchannels[i] = webchannel;
175 } 179 }
176 180
177 webworker_->postMessageToWorkerContext( 181 webworker_->postMessageToWorkerContext(
178 webkit_glue::StringToWebString(message), webchannel); 182 webkit_glue::StringToWebString(message), webchannels);
179 } 183 }
180 184
181 bool WebWorkerClientImpl::hasPendingActivity() const { 185 bool WebWorkerClientImpl::hasPendingActivity() const {
182 return !asked_to_terminate_ && 186 return !asked_to_terminate_ &&
183 (unconfirmed_message_count_ || worker_context_had_pending_activity_); 187 (unconfirmed_message_count_ || worker_context_had_pending_activity_);
184 } 188 }
185 189
186 void WebWorkerClientImpl::workerObjectDestroyed() { 190 void WebWorkerClientImpl::workerObjectDestroyed() {
187 if (WTF::isMainThread()) { 191 if (WTF::isMainThread()) {
188 webworker_->workerObjectDestroyed(); 192 webworker_->workerObjectDestroyed();
189 worker_ = NULL; 193 worker_ = NULL;
190 } 194 }
191 195
192 // Even if this is called on the main thread, there could be a queued task for 196 // Even if this is called on the main thread, there could be a queued task for
193 // this object, so don't delete it right away. 197 // this object, so don't delete it right away.
194 WebWorkerImpl::DispatchTaskToMainThread( 198 WebWorkerImpl::DispatchTaskToMainThread(
195 WebCore::createCallbackTask(&WorkerObjectDestroyedTask, this)); 199 WebCore::createCallbackTask(&WorkerObjectDestroyedTask, this));
196 } 200 }
197 201
198 void WebWorkerClientImpl::postMessageToWorkerObject( 202 void WebWorkerClientImpl::postMessageToWorkerObject(
199 const WebString& message, 203 const WebString& message,
200 WebMessagePortChannel* channel) { 204 const WebMessagePortChannelArray& channels) {
201 WebCore::String message2 = webkit_glue::WebStringToString(message); 205 WebCore::String message2 = webkit_glue::WebStringToString(message);
202 OwnPtr<WebCore::MessagePortChannel> channel2; 206 OwnPtr<WebCore::MessagePortChannelArray> channels2;
203 if (channel) { 207 if (channels.size()) {
204 RefPtr<WebCore::PlatformMessagePortChannel> platform_channel = 208 channels2 = new WebCore::MessagePortChannelArray(channels.size());
205 WebCore::PlatformMessagePortChannel::create(channel); 209 for (size_t i = 0; i < channels.size(); ++i) {
206 channel->setClient(platform_channel.get()); 210 RefPtr<WebCore::PlatformMessagePortChannel> platform_channel =
207 channel2 = WebCore::MessagePortChannel::create(platform_channel); 211 WebCore::PlatformMessagePortChannel::create(channels[i]);
212 channels[i]->setClient(platform_channel.get());
213 (*channels2)[i] = WebCore::MessagePortChannel::create(platform_channel);
214 }
208 } 215 }
209 216
210 if (WTF::currentThread() != worker_thread_id_) { 217 if (WTF::currentThread() != worker_thread_id_) {
211 script_execution_context_->postTask( 218 script_execution_context_->postTask(
212 WebCore::createCallbackTask(&PostMessageToWorkerObjectTask, this, 219 WebCore::createCallbackTask(&PostMessageToWorkerObjectTask, this,
213 message2, channel2.release())); 220 message2, channels2.release()));
214 return; 221 return;
215 } 222 }
216 223
217 PostMessageToWorkerObjectTask( 224 PostMessageToWorkerObjectTask(
218 script_execution_context_.get(), this, message2, channel2.release()); 225 script_execution_context_.get(), this, message2, channels2.release());
219 } 226 }
220 227
221 void WebWorkerClientImpl::postExceptionToWorkerObject( 228 void WebWorkerClientImpl::postExceptionToWorkerObject(
222 const WebString& error_message, 229 const WebString& error_message,
223 int line_number, 230 int line_number,
224 const WebString& source_url) { 231 const WebString& source_url) {
225 if (WTF::currentThread() != worker_thread_id_) { 232 if (WTF::currentThread() != worker_thread_id_) {
226 script_execution_context_->postTask( 233 script_execution_context_->postTask(
227 WebCore::createCallbackTask(&PostExceptionToWorkerObjectTask, this, 234 WebCore::createCallbackTask(&PostExceptionToWorkerObjectTask, this,
228 webkit_glue::WebStringToString(error_message), 235 webkit_glue::WebStringToString(error_message),
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 void WebWorkerClientImpl::TerminateWorkerContextTask( 313 void WebWorkerClientImpl::TerminateWorkerContextTask(
307 WebCore::ScriptExecutionContext* context, 314 WebCore::ScriptExecutionContext* context,
308 WebWorkerClientImpl* this_ptr) { 315 WebWorkerClientImpl* this_ptr) {
309 this_ptr->webworker_->terminateWorkerContext(); 316 this_ptr->webworker_->terminateWorkerContext();
310 } 317 }
311 318
312 void WebWorkerClientImpl::PostMessageToWorkerContextTask( 319 void WebWorkerClientImpl::PostMessageToWorkerContextTask(
313 WebCore::ScriptExecutionContext* context, 320 WebCore::ScriptExecutionContext* context,
314 WebWorkerClientImpl* this_ptr, 321 WebWorkerClientImpl* this_ptr,
315 const WebCore::String& message, 322 const WebCore::String& message,
316 WTF::PassOwnPtr<WebCore::MessagePortChannel> channel) { 323 WTF::PassOwnPtr<WebCore::MessagePortChannelArray> channels) {
317 WebMessagePortChannel* webChannel = NULL; 324 WebMessagePortChannelArray web_channels(channels.get() ? channels->size() : 0) ;
318 if (channel.get()) { 325
319 webChannel = channel->channel()->webChannelRelease(); 326 for (size_t i = 0; i < web_channels.size(); ++i) {
320 webChannel->setClient(0); 327 web_channels[i] = (*channels)[i]->channel()->webChannelRelease();
328 web_channels[i]->setClient(0);
321 } 329 }
322 330
323 this_ptr->webworker_->postMessageToWorkerContext( 331 this_ptr->webworker_->postMessageToWorkerContext(
324 webkit_glue::StringToWebString(message), webChannel); 332 webkit_glue::StringToWebString(message), web_channels);
325 } 333 }
326 334
327 void WebWorkerClientImpl::WorkerObjectDestroyedTask( 335 void WebWorkerClientImpl::WorkerObjectDestroyedTask(
328 WebCore::ScriptExecutionContext* context, 336 WebCore::ScriptExecutionContext* context,
329 WebWorkerClientImpl* this_ptr) { 337 WebWorkerClientImpl* this_ptr) {
330 if (this_ptr->worker_) // Check we haven't alread called this. 338 if (this_ptr->worker_) // Check we haven't alread called this.
331 this_ptr->webworker_->workerObjectDestroyed(); 339 this_ptr->webworker_->workerObjectDestroyed();
332 delete this_ptr; 340 delete this_ptr;
333 } 341 }
334 342
335 void WebWorkerClientImpl::PostMessageToWorkerObjectTask( 343 void WebWorkerClientImpl::PostMessageToWorkerObjectTask(
336 WebCore::ScriptExecutionContext* context, 344 WebCore::ScriptExecutionContext* context,
337 WebWorkerClientImpl* this_ptr, 345 WebWorkerClientImpl* this_ptr,
338 const WebCore::String& message, 346 const WebCore::String& message,
339 WTF::PassOwnPtr<WebCore::MessagePortChannel> channel) { 347 WTF::PassOwnPtr<WebCore::MessagePortChannelArray> channels) {
340 348
341 if (this_ptr->worker_) { 349 if (this_ptr->worker_) {
342 WTF::RefPtr<WebCore::MessagePort> port; 350 WTF::OwnPtr<WebCore::MessagePortArray> ports =
343 if (channel) { 351 WebCore::MessagePort::entanglePorts(*context, channels.release());
344 port = WebCore::MessagePort::create(*context); 352 this_ptr->worker_->dispatchMessage(message, ports.release());
345 port->entangle(channel.release());
346 }
347
348 this_ptr->worker_->dispatchMessage(message, port.release());
349 } 353 }
350 } 354 }
351 355
352 void WebWorkerClientImpl::PostExceptionToWorkerObjectTask( 356 void WebWorkerClientImpl::PostExceptionToWorkerObjectTask(
353 WebCore::ScriptExecutionContext* context, 357 WebCore::ScriptExecutionContext* context,
354 WebWorkerClientImpl* this_ptr, 358 WebWorkerClientImpl* this_ptr,
355 const WebCore::String& error_message, 359 const WebCore::String& error_message,
356 int line_number, 360 int line_number,
357 const WebCore::String& source_url) { 361 const WebCore::String& source_url) {
358 bool handled = false; 362 bool handled = false;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
391 } 395 }
392 396
393 void WebWorkerClientImpl::ReportPendingActivityTask( 397 void WebWorkerClientImpl::ReportPendingActivityTask(
394 WebCore::ScriptExecutionContext* context, 398 WebCore::ScriptExecutionContext* context,
395 WebWorkerClientImpl* this_ptr, 399 WebWorkerClientImpl* this_ptr,
396 bool has_pending_activity) { 400 bool has_pending_activity) {
397 this_ptr->worker_context_had_pending_activity_ = has_pending_activity; 401 this_ptr->worker_context_had_pending_activity_ = has_pending_activity;
398 } 402 }
399 403
400 #endif 404 #endif
OLDNEW
« no previous file with comments | « webkit/glue/webworkerclient_impl.h ('k') | webkit/tools/test_shell/test_worker/test_webworker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698