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

Side by Side Diff: webkit/glue/webworker_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, 3 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 | « webkit/glue/webworker_impl.h ('k') | webkit/glue/webworkerclient_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 "config.h" 5 #include "config.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 8
9 #include "DedicatedWorkerContext.h" 9 #include "DedicatedWorkerContext.h"
10 #include "DedicatedWorkerThread.h" 10 #include "DedicatedWorkerThread.h"
(...skipping 20 matching lines...) Expand all
31 #include "webkit/glue/webdatasource_impl.h" 31 #include "webkit/glue/webdatasource_impl.h"
32 #include "webkit/glue/webframe_impl.h" 32 #include "webkit/glue/webframe_impl.h"
33 #include "webkit/glue/webpreferences.h" 33 #include "webkit/glue/webpreferences.h"
34 #include "webkit/glue/webview.h" 34 #include "webkit/glue/webview.h"
35 #include "webkit/glue/webview_delegate.h" 35 #include "webkit/glue/webview_delegate.h"
36 #include "webkit/glue/webworker_impl.h" 36 #include "webkit/glue/webworker_impl.h"
37 37
38 using WebKit::WebCursorInfo; 38 using WebKit::WebCursorInfo;
39 using WebKit::WebFrame; 39 using WebKit::WebFrame;
40 using WebKit::WebMessagePortChannel; 40 using WebKit::WebMessagePortChannel;
41 using WebKit::WebMessagePortChannelArray;
41 using WebKit::WebNavigationPolicy; 42 using WebKit::WebNavigationPolicy;
42 using WebKit::WebRect; 43 using WebKit::WebRect;
43 using WebKit::WebScreenInfo; 44 using WebKit::WebScreenInfo;
44 using WebKit::WebString; 45 using WebKit::WebString;
45 using WebKit::WebURL; 46 using WebKit::WebURL;
46 using WebKit::WebWorker; 47 using WebKit::WebWorker;
47 using WebKit::WebWorkerClient; 48 using WebKit::WebWorkerClient;
48 49
49 #if ENABLE(WORKERS) 50 #if ENABLE(WORKERS)
50 51
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 } 118 }
118 119
119 WebWorkerImpl::~WebWorkerImpl() { 120 WebWorkerImpl::~WebWorkerImpl() {
120 web_view_->close(); 121 web_view_->close();
121 } 122 }
122 123
123 void WebWorkerImpl::PostMessageToWorkerContextTask( 124 void WebWorkerImpl::PostMessageToWorkerContextTask(
124 WebCore::ScriptExecutionContext* context, 125 WebCore::ScriptExecutionContext* context,
125 WebWorkerImpl* this_ptr, 126 WebWorkerImpl* this_ptr,
126 const WebCore::String& message, 127 const WebCore::String& message,
127 WTF::PassOwnPtr<WebCore::MessagePortChannel> channel) { 128 WTF::PassOwnPtr<WebCore::MessagePortChannelArray> channels) {
128 DCHECK(context->isWorkerContext()); 129 DCHECK(context->isWorkerContext());
129 WebCore::DedicatedWorkerContext* worker_context = 130 WebCore::DedicatedWorkerContext* worker_context =
130 static_cast<WebCore::DedicatedWorkerContext*>(context); 131 static_cast<WebCore::DedicatedWorkerContext*>(context);
131 132
132 WTF::RefPtr<WebCore::MessagePort> port; 133 WTF::OwnPtr<WebCore::MessagePortArray> ports =
133 if (channel) { 134 WebCore::MessagePort::entanglePorts(*context, channels.release());
134 port = WebCore::MessagePort::create(*context); 135 worker_context->dispatchMessage(message, ports.release());
135 port->entangle(channel.release());
136 }
137 worker_context->dispatchMessage(message, port.release());
138 136
139 this_ptr->confirmMessageFromWorkerObject( 137 this_ptr->confirmMessageFromWorkerObject(
140 worker_context->hasPendingActivity()); 138 worker_context->hasPendingActivity());
141 } 139 }
142 140
143 // WebWorker ------------------------------------------------------------------- 141 // WebWorker -------------------------------------------------------------------
144 142
145 void WebWorkerImpl::startWorkerContext(const WebURL& script_url, 143 void WebWorkerImpl::startWorkerContext(const WebURL& script_url,
146 const WebString& user_agent, 144 const WebString& user_agent,
147 const WebString& source_code) { 145 const WebString& source_code) {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 if (asked_to_terminate_) 188 if (asked_to_terminate_)
191 return; 189 return;
192 asked_to_terminate_ = true; 190 asked_to_terminate_ = true;
193 191
194 if (worker_thread_) 192 if (worker_thread_)
195 worker_thread_->stop(); 193 worker_thread_->stop();
196 } 194 }
197 195
198 void WebWorkerImpl::postMessageToWorkerContext( 196 void WebWorkerImpl::postMessageToWorkerContext(
199 const WebString& message, 197 const WebString& message,
200 WebMessagePortChannel* webchannel) { 198 const WebMessagePortChannelArray& webchannels) {
201 199
202 OwnPtr<WebCore::MessagePortChannel> channel; 200 WTF::OwnPtr<WebCore::MessagePortChannelArray> channels;
203 if (webchannel) { 201 if (webchannels.size()) {
204 RefPtr<WebCore::PlatformMessagePortChannel> platform_channel = 202 channels = new WebCore::MessagePortChannelArray(webchannels.size());
205 WebCore::PlatformMessagePortChannel::create(webchannel); 203 for (size_t i = 0; i < webchannels.size(); ++i) {
206 webchannel->setClient(platform_channel.get()); 204 RefPtr<WebCore::PlatformMessagePortChannel> platform_channel =
207 channel = WebCore::MessagePortChannel::create(platform_channel); 205 WebCore::PlatformMessagePortChannel::create(webchannels[i]);
206 webchannels[i]->setClient(platform_channel.get());
207 (*channels)[i] = WebCore::MessagePortChannel::create(platform_channel);
208 }
208 } 209 }
209 210
210 worker_thread_->runLoop().postTask(WebCore::createCallbackTask( 211 worker_thread_->runLoop().postTask(WebCore::createCallbackTask(
211 &PostMessageToWorkerContextTask, 212 &PostMessageToWorkerContextTask,
212 this, 213 this,
213 webkit_glue::WebStringToString(message), 214 webkit_glue::WebStringToString(message),
214 channel.release())); 215 channels.release()));
215 } 216 }
216 217
217 void WebWorkerImpl::workerObjectDestroyed() { 218 void WebWorkerImpl::workerObjectDestroyed() {
218 // Worker object in the renderer was destroyed, perhaps a result of GC. 219 // Worker object in the renderer was destroyed, perhaps a result of GC.
219 // For us, it's a signal to start terminating the WorkerContext too. 220 // For us, it's a signal to start terminating the WorkerContext too.
220 // TODO(dimich): when 'kill a worker' html5 spec algorithm is implemented, it 221 // TODO(dimich): when 'kill a worker' html5 spec algorithm is implemented, it
221 // should be used here instead of 'terminate a worker'. 222 // should be used here instead of 'terminate a worker'.
222 terminateWorkerContext(); 223 terminateWorkerContext();
223 } 224 }
224 225
225 void WebWorkerImpl::DispatchTaskToMainThread( 226 void WebWorkerImpl::DispatchTaskToMainThread(
226 PassRefPtr<WebCore::ScriptExecutionContext::Task> task) { 227 PassRefPtr<WebCore::ScriptExecutionContext::Task> task) {
227 return WTF::callOnMainThread(InvokeTaskMethod, task.releaseRef()); 228 return WTF::callOnMainThread(InvokeTaskMethod, task.releaseRef());
228 } 229 }
229 230
230 void WebWorkerImpl::InvokeTaskMethod(void* param) { 231 void WebWorkerImpl::InvokeTaskMethod(void* param) {
231 WebCore::ScriptExecutionContext::Task* task = 232 WebCore::ScriptExecutionContext::Task* task =
232 static_cast<WebCore::ScriptExecutionContext::Task*>(param); 233 static_cast<WebCore::ScriptExecutionContext::Task*>(param);
233 task->performTask(NULL); 234 task->performTask(NULL);
234 task->deref(); 235 task->deref();
235 } 236 }
236 237
237 // WorkerObjectProxy ----------------------------------------------------------- 238 // WorkerObjectProxy -----------------------------------------------------------
238 239
239 void WebWorkerImpl::postMessageToWorkerObject( 240 void WebWorkerImpl::postMessageToWorkerObject(
240 const WebCore::String& message, 241 const WebCore::String& message,
241 WTF::PassOwnPtr<WebCore::MessagePortChannel> channel) { 242 WTF::PassOwnPtr<WebCore::MessagePortChannelArray> channels) {
242 DispatchTaskToMainThread(WebCore::createCallbackTask( 243 DispatchTaskToMainThread(WebCore::createCallbackTask(
243 &PostMessageTask, 244 &PostMessageTask,
244 this, 245 this,
245 message, 246 message,
246 channel)); 247 channels));
247 } 248 }
248 249
249 void WebWorkerImpl::PostMessageTask( 250 void WebWorkerImpl::PostMessageTask(
250 WebCore::ScriptExecutionContext* context, 251 WebCore::ScriptExecutionContext* context,
251 WebWorkerImpl* this_ptr, 252 WebWorkerImpl* this_ptr,
252 WebCore::String message, 253 WebCore::String message,
253 WTF::PassOwnPtr<WebCore::MessagePortChannel> channel) { 254 WTF::PassOwnPtr<WebCore::MessagePortChannelArray> channels) {
254 WebMessagePortChannel* webChannel = NULL; 255 WebMessagePortChannelArray web_channels(
255 if (channel.get()) { 256 channels.get() ? channels->size() : 0);
256 webChannel = channel->channel()->webChannelRelease(); 257 for (size_t i = 0; i < web_channels.size(); ++i) {
257 webChannel->setClient(0); 258 web_channels[i] = (*channels)[i]->channel()->webChannelRelease();
259 web_channels[i]->setClient(0);
258 } 260 }
259 261
260 this_ptr->client_->postMessageToWorkerObject( 262 this_ptr->client_->postMessageToWorkerObject(
261 webkit_glue::StringToWebString(message), webChannel); 263 webkit_glue::StringToWebString(message), web_channels);
262 } 264 }
263 265
264 void WebWorkerImpl::postExceptionToWorkerObject( 266 void WebWorkerImpl::postExceptionToWorkerObject(
265 const WebCore::String& error_message, 267 const WebCore::String& error_message,
266 int line_number, 268 int line_number,
267 const WebCore::String& source_url) { 269 const WebCore::String& source_url) {
268 DispatchTaskToMainThread(WebCore::createCallbackTask( 270 DispatchTaskToMainThread(WebCore::createCallbackTask(
269 &PostExceptionTask, 271 &PostExceptionTask,
270 this, 272 this,
271 error_message, 273 error_message,
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 388
387 namespace WebKit { 389 namespace WebKit {
388 390
389 WebWorker* WebWorker::create(WebWorkerClient* client) { 391 WebWorker* WebWorker::create(WebWorkerClient* client) {
390 return NULL; 392 return NULL;
391 } 393 }
392 394
393 } 395 }
394 396
395 #endif 397 #endif
OLDNEW
« no previous file with comments | « webkit/glue/webworker_impl.h ('k') | webkit/glue/webworkerclient_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698