| OLD | NEW |
| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 } | 211 } |
| 212 | 212 |
| 213 void WebWorkerImpl::workerObjectDestroyed() { | 213 void WebWorkerImpl::workerObjectDestroyed() { |
| 214 // Worker object in the renderer was destroyed, perhaps a result of GC. | 214 // Worker object in the renderer was destroyed, perhaps a result of GC. |
| 215 // For us, it's a signal to start terminating the WorkerContext too. | 215 // For us, it's a signal to start terminating the WorkerContext too. |
| 216 // TODO(dimich): when 'kill a worker' html5 spec algorithm is implemented, it | 216 // TODO(dimich): when 'kill a worker' html5 spec algorithm is implemented, it |
| 217 // should be used here instead of 'terminate a worker'. | 217 // should be used here instead of 'terminate a worker'. |
| 218 terminateWorkerContext(); | 218 terminateWorkerContext(); |
| 219 } | 219 } |
| 220 | 220 |
| 221 void WebWorkerImpl::clientDestroyed() { |
| 222 client_ = NULL; |
| 223 } |
| 224 |
| 221 void WebWorkerImpl::DispatchTaskToMainThread( | 225 void WebWorkerImpl::DispatchTaskToMainThread( |
| 222 PassRefPtr<WebCore::ScriptExecutionContext::Task> task) { | 226 PassRefPtr<WebCore::ScriptExecutionContext::Task> task) { |
| 223 return WTF::callOnMainThread(InvokeTaskMethod, task.releaseRef()); | 227 return WTF::callOnMainThread(InvokeTaskMethod, task.releaseRef()); |
| 224 } | 228 } |
| 225 | 229 |
| 226 void WebWorkerImpl::InvokeTaskMethod(void* param) { | 230 void WebWorkerImpl::InvokeTaskMethod(void* param) { |
| 227 WebCore::ScriptExecutionContext::Task* task = | 231 WebCore::ScriptExecutionContext::Task* task = |
| 228 static_cast<WebCore::ScriptExecutionContext::Task*>(param); | 232 static_cast<WebCore::ScriptExecutionContext::Task*>(param); |
| 229 task->performTask(NULL); | 233 task->performTask(NULL); |
| 230 task->deref(); | 234 task->deref(); |
| 231 } | 235 } |
| 232 | 236 |
| 233 // WorkerObjectProxy ----------------------------------------------------------- | 237 // WorkerObjectProxy ----------------------------------------------------------- |
| 234 | 238 |
| 235 void WebWorkerImpl::postMessageToWorkerObject( | 239 void WebWorkerImpl::postMessageToWorkerObject( |
| 236 WTF::PassRefPtr<WebCore::SerializedScriptValue> message, | 240 WTF::PassRefPtr<WebCore::SerializedScriptValue> message, |
| 237 WTF::PassOwnPtr<WebCore::MessagePortChannelArray> channels) { | 241 WTF::PassOwnPtr<WebCore::MessagePortChannelArray> channels) { |
| 238 DispatchTaskToMainThread(WebCore::createCallbackTask( | 242 DispatchTaskToMainThread(WebCore::createCallbackTask( |
| 239 &PostMessageTask, | 243 &PostMessageTask, |
| 240 this, | 244 this, |
| 241 message->toString(), | 245 message->toString(), |
| 242 channels)); | 246 channels)); |
| 243 } | 247 } |
| 244 | 248 |
| 245 void WebWorkerImpl::PostMessageTask( | 249 void WebWorkerImpl::PostMessageTask( |
| 246 WebCore::ScriptExecutionContext* context, | 250 WebCore::ScriptExecutionContext* context, |
| 247 WebWorkerImpl* this_ptr, | 251 WebWorkerImpl* this_ptr, |
| 248 WebCore::String message, | 252 WebCore::String message, |
| 249 WTF::PassOwnPtr<WebCore::MessagePortChannelArray> channels) { | 253 WTF::PassOwnPtr<WebCore::MessagePortChannelArray> channels) { |
| 254 if (!this_ptr->client_) |
| 255 return; |
| 256 |
| 250 WebMessagePortChannelArray web_channels( | 257 WebMessagePortChannelArray web_channels( |
| 251 channels.get() ? channels->size() : 0); | 258 channels.get() ? channels->size() : 0); |
| 252 for (size_t i = 0; i < web_channels.size(); ++i) { | 259 for (size_t i = 0; i < web_channels.size(); ++i) { |
| 253 web_channels[i] = (*channels)[i]->channel()->webChannelRelease(); | 260 web_channels[i] = (*channels)[i]->channel()->webChannelRelease(); |
| 254 web_channels[i]->setClient(0); | 261 web_channels[i]->setClient(0); |
| 255 } | 262 } |
| 256 | 263 |
| 257 this_ptr->client_->postMessageToWorkerObject( | 264 this_ptr->client_->postMessageToWorkerObject( |
| 258 webkit_glue::StringToWebString(message), web_channels); | 265 webkit_glue::StringToWebString(message), web_channels); |
| 259 } | 266 } |
| 260 | 267 |
| 261 void WebWorkerImpl::postExceptionToWorkerObject( | 268 void WebWorkerImpl::postExceptionToWorkerObject( |
| 262 const WebCore::String& error_message, | 269 const WebCore::String& error_message, |
| 263 int line_number, | 270 int line_number, |
| 264 const WebCore::String& source_url) { | 271 const WebCore::String& source_url) { |
| 265 DispatchTaskToMainThread(WebCore::createCallbackTask( | 272 DispatchTaskToMainThread(WebCore::createCallbackTask( |
| 266 &PostExceptionTask, | 273 &PostExceptionTask, |
| 267 this, | 274 this, |
| 268 error_message, | 275 error_message, |
| 269 line_number, | 276 line_number, |
| 270 source_url)); | 277 source_url)); |
| 271 } | 278 } |
| 272 | 279 |
| 273 void WebWorkerImpl::PostExceptionTask( | 280 void WebWorkerImpl::PostExceptionTask( |
| 274 WebCore::ScriptExecutionContext* context, | 281 WebCore::ScriptExecutionContext* context, |
| 275 WebWorkerImpl* this_ptr, | 282 WebWorkerImpl* this_ptr, |
| 276 const WebCore::String& error_message, | 283 const WebCore::String& error_message, |
| 277 int line_number, | 284 int line_number, |
| 278 const WebCore::String& source_url) { | 285 const WebCore::String& source_url) { |
| 286 if (!this_ptr->client_) |
| 287 return; |
| 288 |
| 279 this_ptr->client_->postExceptionToWorkerObject( | 289 this_ptr->client_->postExceptionToWorkerObject( |
| 280 webkit_glue::StringToWebString(error_message), | 290 webkit_glue::StringToWebString(error_message), |
| 281 line_number, | 291 line_number, |
| 282 webkit_glue::StringToWebString(source_url)); | 292 webkit_glue::StringToWebString(source_url)); |
| 283 } | 293 } |
| 284 | 294 |
| 285 void WebWorkerImpl::postConsoleMessageToWorkerObject( | 295 void WebWorkerImpl::postConsoleMessageToWorkerObject( |
| 286 WebCore::MessageDestination destination, | 296 WebCore::MessageDestination destination, |
| 287 WebCore::MessageSource source, | 297 WebCore::MessageSource source, |
| 288 WebCore::MessageType type, | 298 WebCore::MessageType type, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 305 void WebWorkerImpl::PostConsoleMessageTask( | 315 void WebWorkerImpl::PostConsoleMessageTask( |
| 306 WebCore::ScriptExecutionContext* context, | 316 WebCore::ScriptExecutionContext* context, |
| 307 WebWorkerImpl* this_ptr, | 317 WebWorkerImpl* this_ptr, |
| 308 int destination, | 318 int destination, |
| 309 int source, | 319 int source, |
| 310 int type, | 320 int type, |
| 311 int level, | 321 int level, |
| 312 const WebCore::String& message, | 322 const WebCore::String& message, |
| 313 int line_number, | 323 int line_number, |
| 314 const WebCore::String& source_url) { | 324 const WebCore::String& source_url) { |
| 325 if (!this_ptr->client_) |
| 326 return; |
| 327 |
| 315 this_ptr->client_->postConsoleMessageToWorkerObject( | 328 this_ptr->client_->postConsoleMessageToWorkerObject( |
| 316 destination, | 329 destination, |
| 317 source, | 330 source, |
| 318 type, | 331 type, |
| 319 level, | 332 level, |
| 320 webkit_glue::StringToWebString(message), | 333 webkit_glue::StringToWebString(message), |
| 321 line_number, | 334 line_number, |
| 322 webkit_glue::StringToWebString(source_url)); | 335 webkit_glue::StringToWebString(source_url)); |
| 323 } | 336 } |
| 324 | 337 |
| 325 void WebWorkerImpl::confirmMessageFromWorkerObject(bool has_pending_activity) { | 338 void WebWorkerImpl::confirmMessageFromWorkerObject(bool has_pending_activity) { |
| 326 DispatchTaskToMainThread(WebCore::createCallbackTask( | 339 DispatchTaskToMainThread(WebCore::createCallbackTask( |
| 327 &ConfirmMessageTask, | 340 &ConfirmMessageTask, |
| 328 this, | 341 this, |
| 329 has_pending_activity)); | 342 has_pending_activity)); |
| 330 } | 343 } |
| 331 | 344 |
| 332 void WebWorkerImpl::ConfirmMessageTask( | 345 void WebWorkerImpl::ConfirmMessageTask( |
| 333 WebCore::ScriptExecutionContext* context, | 346 WebCore::ScriptExecutionContext* context, |
| 334 WebWorkerImpl* this_ptr, | 347 WebWorkerImpl* this_ptr, |
| 335 bool has_pending_activity) { | 348 bool has_pending_activity) { |
| 349 if (!this_ptr->client_) |
| 350 return; |
| 351 |
| 336 this_ptr->client_->confirmMessageFromWorkerObject(has_pending_activity); | 352 this_ptr->client_->confirmMessageFromWorkerObject(has_pending_activity); |
| 337 } | 353 } |
| 338 | 354 |
| 339 void WebWorkerImpl::reportPendingActivity(bool has_pending_activity) { | 355 void WebWorkerImpl::reportPendingActivity(bool has_pending_activity) { |
| 340 DispatchTaskToMainThread(WebCore::createCallbackTask( | 356 DispatchTaskToMainThread(WebCore::createCallbackTask( |
| 341 &ReportPendingActivityTask, | 357 &ReportPendingActivityTask, |
| 342 this, | 358 this, |
| 343 has_pending_activity)); | 359 has_pending_activity)); |
| 344 } | 360 } |
| 345 | 361 |
| 346 void WebWorkerImpl::ReportPendingActivityTask( | 362 void WebWorkerImpl::ReportPendingActivityTask( |
| 347 WebCore::ScriptExecutionContext* context, | 363 WebCore::ScriptExecutionContext* context, |
| 348 WebWorkerImpl* this_ptr, | 364 WebWorkerImpl* this_ptr, |
| 349 bool has_pending_activity) { | 365 bool has_pending_activity) { |
| 366 if (!this_ptr->client_) |
| 367 return; |
| 368 |
| 350 this_ptr->client_->reportPendingActivity(has_pending_activity); | 369 this_ptr->client_->reportPendingActivity(has_pending_activity); |
| 351 } | 370 } |
| 352 | 371 |
| 353 void WebWorkerImpl::workerContextDestroyed() { | 372 void WebWorkerImpl::workerContextDestroyed() { |
| 354 DispatchTaskToMainThread(WebCore::createCallbackTask( | 373 DispatchTaskToMainThread(WebCore::createCallbackTask( |
| 355 &WorkerContextDestroyedTask, | 374 &WorkerContextDestroyedTask, |
| 356 this)); | 375 this)); |
| 357 } | 376 } |
| 358 | 377 |
| 359 // WorkerLoaderProxy ----------------------------------------------------------- | 378 // WorkerLoaderProxy ----------------------------------------------------------- |
| 360 | 379 |
| 361 void WebWorkerImpl::postTaskToLoader( | 380 void WebWorkerImpl::postTaskToLoader( |
| 362 PassRefPtr<WebCore::ScriptExecutionContext::Task> task) { | 381 PassRefPtr<WebCore::ScriptExecutionContext::Task> task) { |
| 363 ASSERT(loading_document_->isDocument()); | 382 ASSERT(loading_document_->isDocument()); |
| 364 loading_document_->postTask(task); | 383 loading_document_->postTask(task); |
| 365 } | 384 } |
| 366 | 385 |
| 367 void WebWorkerImpl::postTaskForModeToWorkerContext( | 386 void WebWorkerImpl::postTaskForModeToWorkerContext( |
| 368 PassRefPtr<WebCore::ScriptExecutionContext::Task> task, | 387 PassRefPtr<WebCore::ScriptExecutionContext::Task> task, |
| 369 const WebCore::String& mode) { | 388 const WebCore::String& mode) { |
| 370 worker_thread_->runLoop().postTaskForMode(task, mode); | 389 worker_thread_->runLoop().postTaskForMode(task, mode); |
| 371 } | 390 } |
| 372 | 391 |
| 373 void WebWorkerImpl::WorkerContextDestroyedTask( | 392 void WebWorkerImpl::WorkerContextDestroyedTask( |
| 374 WebCore::ScriptExecutionContext* context, | 393 WebCore::ScriptExecutionContext* context, |
| 375 WebWorkerImpl* this_ptr) { | 394 WebWorkerImpl* this_ptr) { |
| 376 this_ptr->client_->workerContextDestroyed(); | 395 if (this_ptr->client_) |
| 396 this_ptr->client_->workerContextDestroyed(); |
| 377 | 397 |
| 378 // The lifetime of this proxy is controlled by the worker context. | 398 // The lifetime of this proxy is controlled by the worker context. |
| 379 delete this_ptr; | 399 delete this_ptr; |
| 380 } | 400 } |
| 381 | 401 |
| 382 #else | 402 #else |
| 383 | 403 |
| 384 namespace WebKit { | 404 namespace WebKit { |
| 385 | 405 |
| 386 WebWorker* WebWorker::create(WebWorkerClient* client) { | 406 WebWorker* WebWorker::create(WebWorkerClient* client) { |
| 387 return NULL; | 407 return NULL; |
| 388 } | 408 } |
| 389 | 409 |
| 390 } | 410 } |
| 391 | 411 |
| 392 #endif | 412 #endif |
| OLD | NEW |