| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * Copyright (C) 2009 Google Inc. All Rights Reserved. | 3 * Copyright (C) 2009 Google Inc. All Rights Reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 223 |
| 224 private: | 224 private: |
| 225 PostMessageToPageInspectorTask(WorkerMessagingProxy* messagingProxy, const S
tring& message) | 225 PostMessageToPageInspectorTask(WorkerMessagingProxy* messagingProxy, const S
tring& message) |
| 226 : m_messagingProxy(messagingProxy) | 226 : m_messagingProxy(messagingProxy) |
| 227 , m_message(message.isolatedCopy()) | 227 , m_message(message.isolatedCopy()) |
| 228 { | 228 { |
| 229 } | 229 } |
| 230 | 230 |
| 231 virtual void performTask(ScriptExecutionContext*) | 231 virtual void performTask(ScriptExecutionContext*) |
| 232 { | 232 { |
| 233 #if ENABLE(INSPECTOR) | |
| 234 if (WorkerContextProxy::PageInspector* pageInspector = m_messagingProxy-
>m_pageInspector) | 233 if (WorkerContextProxy::PageInspector* pageInspector = m_messagingProxy-
>m_pageInspector) |
| 235 pageInspector->dispatchMessageFromWorker(m_message); | 234 pageInspector->dispatchMessageFromWorker(m_message); |
| 236 #endif | |
| 237 } | 235 } |
| 238 | 236 |
| 239 WorkerMessagingProxy* m_messagingProxy; | 237 WorkerMessagingProxy* m_messagingProxy; |
| 240 String m_message; | 238 String m_message; |
| 241 }; | 239 }; |
| 242 | 240 |
| 243 | 241 |
| 244 #if !PLATFORM(CHROMIUM) | 242 #if !PLATFORM(CHROMIUM) |
| 245 WorkerContextProxy* WorkerContextProxy::create(Worker* worker) | 243 WorkerContextProxy* WorkerContextProxy::create(Worker* worker) |
| 246 { | 244 { |
| 247 return new WorkerMessagingProxy(worker); | 245 return new WorkerMessagingProxy(worker); |
| 248 } | 246 } |
| 249 #endif | 247 #endif |
| 250 | 248 |
| 251 WorkerMessagingProxy::WorkerMessagingProxy(Worker* workerObject) | 249 WorkerMessagingProxy::WorkerMessagingProxy(Worker* workerObject) |
| 252 : m_scriptExecutionContext(workerObject->scriptExecutionContext()) | 250 : m_scriptExecutionContext(workerObject->scriptExecutionContext()) |
| 253 , m_workerObject(workerObject) | 251 , m_workerObject(workerObject) |
| 254 , m_mayBeDestroyed(false) | 252 , m_mayBeDestroyed(false) |
| 255 , m_unconfirmedMessageCount(0) | 253 , m_unconfirmedMessageCount(0) |
| 256 , m_workerThreadHadPendingActivity(false) | 254 , m_workerThreadHadPendingActivity(false) |
| 257 , m_askedToTerminate(false) | 255 , m_askedToTerminate(false) |
| 258 #if ENABLE(INSPECTOR) | |
| 259 , m_pageInspector(0) | 256 , m_pageInspector(0) |
| 260 #endif | |
| 261 { | 257 { |
| 262 ASSERT(m_workerObject); | 258 ASSERT(m_workerObject); |
| 263 ASSERT((m_scriptExecutionContext->isDocument() && isMainThread()) | 259 ASSERT((m_scriptExecutionContext->isDocument() && isMainThread()) |
| 264 || (m_scriptExecutionContext->isWorkerContext() && currentThread() ==
static_cast<WorkerContext*>(m_scriptExecutionContext.get())->thread()->threadID
())); | 260 || (m_scriptExecutionContext->isWorkerContext() && currentThread() ==
static_cast<WorkerContext*>(m_scriptExecutionContext.get())->thread()->threadID
())); |
| 265 } | 261 } |
| 266 | 262 |
| 267 WorkerMessagingProxy::~WorkerMessagingProxy() | 263 WorkerMessagingProxy::~WorkerMessagingProxy() |
| 268 { | 264 { |
| 269 ASSERT(!m_workerObject); | 265 ASSERT(!m_workerObject); |
| 270 ASSERT((m_scriptExecutionContext->isDocument() && isMainThread()) | 266 ASSERT((m_scriptExecutionContext->isDocument() && isMainThread()) |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 | 359 |
| 364 void WorkerMessagingProxy::workerObjectDestroyedInternal(ScriptExecutionContext*
, WorkerMessagingProxy* proxy) | 360 void WorkerMessagingProxy::workerObjectDestroyedInternal(ScriptExecutionContext*
, WorkerMessagingProxy* proxy) |
| 365 { | 361 { |
| 366 proxy->m_mayBeDestroyed = true; | 362 proxy->m_mayBeDestroyed = true; |
| 367 if (proxy->m_workerThread) | 363 if (proxy->m_workerThread) |
| 368 proxy->terminateWorkerContext(); | 364 proxy->terminateWorkerContext(); |
| 369 else | 365 else |
| 370 proxy->workerContextDestroyedInternal(); | 366 proxy->workerContextDestroyedInternal(); |
| 371 } | 367 } |
| 372 | 368 |
| 373 #if ENABLE(INSPECTOR) | |
| 374 #if ENABLE(JAVASCRIPT_DEBUGGER) | |
| 375 static void connectToWorkerContextInspectorTask(ScriptExecutionContext* context,
bool) | 369 static void connectToWorkerContextInspectorTask(ScriptExecutionContext* context,
bool) |
| 376 { | 370 { |
| 377 ASSERT_WITH_SECURITY_IMPLICATION(context->isWorkerContext()); | 371 ASSERT_WITH_SECURITY_IMPLICATION(context->isWorkerContext()); |
| 378 static_cast<WorkerContext*>(context)->workerInspectorController()->connectFr
ontend(); | 372 static_cast<WorkerContext*>(context)->workerInspectorController()->connectFr
ontend(); |
| 379 } | 373 } |
| 380 #endif | |
| 381 | 374 |
| 382 void WorkerMessagingProxy::connectToInspector(WorkerContextProxy::PageInspector*
pageInspector) | 375 void WorkerMessagingProxy::connectToInspector(WorkerContextProxy::PageInspector*
pageInspector) |
| 383 { | 376 { |
| 384 if (m_askedToTerminate) | 377 if (m_askedToTerminate) |
| 385 return; | 378 return; |
| 386 ASSERT(!m_pageInspector); | 379 ASSERT(!m_pageInspector); |
| 387 m_pageInspector = pageInspector; | 380 m_pageInspector = pageInspector; |
| 388 #if ENABLE(JAVASCRIPT_DEBUGGER) | |
| 389 m_workerThread->runLoop().postTaskForMode(createCallbackTask(connectToWorker
ContextInspectorTask, true), WorkerDebuggerAgent::debuggerTaskMode); | 381 m_workerThread->runLoop().postTaskForMode(createCallbackTask(connectToWorker
ContextInspectorTask, true), WorkerDebuggerAgent::debuggerTaskMode); |
| 390 #endif | |
| 391 } | 382 } |
| 392 | 383 |
| 393 #if ENABLE(JAVASCRIPT_DEBUGGER) | |
| 394 static void disconnectFromWorkerContextInspectorTask(ScriptExecutionContext* con
text, bool) | 384 static void disconnectFromWorkerContextInspectorTask(ScriptExecutionContext* con
text, bool) |
| 395 { | 385 { |
| 396 ASSERT_WITH_SECURITY_IMPLICATION(context->isWorkerContext()); | 386 ASSERT_WITH_SECURITY_IMPLICATION(context->isWorkerContext()); |
| 397 static_cast<WorkerContext*>(context)->workerInspectorController()->disconnec
tFrontend(); | 387 static_cast<WorkerContext*>(context)->workerInspectorController()->disconnec
tFrontend(); |
| 398 } | 388 } |
| 399 #endif | |
| 400 | 389 |
| 401 void WorkerMessagingProxy::disconnectFromInspector() | 390 void WorkerMessagingProxy::disconnectFromInspector() |
| 402 { | 391 { |
| 403 m_pageInspector = 0; | 392 m_pageInspector = 0; |
| 404 if (m_askedToTerminate) | 393 if (m_askedToTerminate) |
| 405 return; | 394 return; |
| 406 #if ENABLE(JAVASCRIPT_DEBUGGER) | |
| 407 m_workerThread->runLoop().postTaskForMode(createCallbackTask(disconnectFromW
orkerContextInspectorTask, true), WorkerDebuggerAgent::debuggerTaskMode); | 395 m_workerThread->runLoop().postTaskForMode(createCallbackTask(disconnectFromW
orkerContextInspectorTask, true), WorkerDebuggerAgent::debuggerTaskMode); |
| 408 #endif | |
| 409 } | 396 } |
| 410 | 397 |
| 411 #if ENABLE(JAVASCRIPT_DEBUGGER) | |
| 412 static void dispatchOnInspectorBackendTask(ScriptExecutionContext* context, cons
t String& message) | 398 static void dispatchOnInspectorBackendTask(ScriptExecutionContext* context, cons
t String& message) |
| 413 { | 399 { |
| 414 ASSERT_WITH_SECURITY_IMPLICATION(context->isWorkerContext()); | 400 ASSERT_WITH_SECURITY_IMPLICATION(context->isWorkerContext()); |
| 415 static_cast<WorkerContext*>(context)->workerInspectorController()->dispatchM
essageFromFrontend(message); | 401 static_cast<WorkerContext*>(context)->workerInspectorController()->dispatchM
essageFromFrontend(message); |
| 416 } | 402 } |
| 417 #endif | |
| 418 | 403 |
| 419 void WorkerMessagingProxy::sendMessageToInspector(const String& message) | 404 void WorkerMessagingProxy::sendMessageToInspector(const String& message) |
| 420 { | 405 { |
| 421 if (m_askedToTerminate) | 406 if (m_askedToTerminate) |
| 422 return; | 407 return; |
| 423 #if ENABLE(JAVASCRIPT_DEBUGGER) | |
| 424 m_workerThread->runLoop().postTaskForMode(createCallbackTask(dispatchOnInspe
ctorBackendTask, String(message)), WorkerDebuggerAgent::debuggerTaskMode); | 408 m_workerThread->runLoop().postTaskForMode(createCallbackTask(dispatchOnInspe
ctorBackendTask, String(message)), WorkerDebuggerAgent::debuggerTaskMode); |
| 425 WorkerDebuggerAgent::interruptAndDispatchInspectorCommands(m_workerThread.ge
t()); | 409 WorkerDebuggerAgent::interruptAndDispatchInspectorCommands(m_workerThread.ge
t()); |
| 426 #endif | |
| 427 } | 410 } |
| 428 #endif | |
| 429 | 411 |
| 430 void WorkerMessagingProxy::workerContextDestroyed() | 412 void WorkerMessagingProxy::workerContextDestroyed() |
| 431 { | 413 { |
| 432 m_scriptExecutionContext->postTask(WorkerContextDestroyedTask::create(this))
; | 414 m_scriptExecutionContext->postTask(WorkerContextDestroyedTask::create(this))
; |
| 433 // Will execute workerContextDestroyedInternal() on context's thread. | 415 // Will execute workerContextDestroyedInternal() on context's thread. |
| 434 } | 416 } |
| 435 | 417 |
| 436 void WorkerMessagingProxy::workerContextClosed() | 418 void WorkerMessagingProxy::workerContextClosed() |
| 437 { | 419 { |
| 438 // Executes terminateWorkerContext() on parent context's thread. | 420 // Executes terminateWorkerContext() on parent context's thread. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 457 if (m_askedToTerminate) | 439 if (m_askedToTerminate) |
| 458 return; | 440 return; |
| 459 m_askedToTerminate = true; | 441 m_askedToTerminate = true; |
| 460 | 442 |
| 461 if (m_workerThread) | 443 if (m_workerThread) |
| 462 m_workerThread->stop(); | 444 m_workerThread->stop(); |
| 463 | 445 |
| 464 InspectorInstrumentation::workerContextTerminated(m_scriptExecutionContext.g
et(), this); | 446 InspectorInstrumentation::workerContextTerminated(m_scriptExecutionContext.g
et(), this); |
| 465 } | 447 } |
| 466 | 448 |
| 467 #if ENABLE(INSPECTOR) | |
| 468 void WorkerMessagingProxy::postMessageToPageInspector(const String& message) | 449 void WorkerMessagingProxy::postMessageToPageInspector(const String& message) |
| 469 { | 450 { |
| 470 m_scriptExecutionContext->postTask(PostMessageToPageInspectorTask::create(th
is, message)); | 451 m_scriptExecutionContext->postTask(PostMessageToPageInspectorTask::create(th
is, message)); |
| 471 } | 452 } |
| 472 | 453 |
| 473 void WorkerMessagingProxy::updateInspectorStateCookie(const String&) | 454 void WorkerMessagingProxy::updateInspectorStateCookie(const String&) |
| 474 { | 455 { |
| 475 notImplemented(); | 456 notImplemented(); |
| 476 } | 457 } |
| 477 #endif | |
| 478 | 458 |
| 479 void WorkerMessagingProxy::confirmMessageFromWorkerObject(bool hasPendingActivit
y) | 459 void WorkerMessagingProxy::confirmMessageFromWorkerObject(bool hasPendingActivit
y) |
| 480 { | 460 { |
| 481 m_scriptExecutionContext->postTask(WorkerThreadActivityReportTask::create(th
is, true, hasPendingActivity)); | 461 m_scriptExecutionContext->postTask(WorkerThreadActivityReportTask::create(th
is, true, hasPendingActivity)); |
| 482 // Will execute reportPendingActivityInternal() on context's thread. | 462 // Will execute reportPendingActivityInternal() on context's thread. |
| 483 } | 463 } |
| 484 | 464 |
| 485 void WorkerMessagingProxy::reportPendingActivity(bool hasPendingActivity) | 465 void WorkerMessagingProxy::reportPendingActivity(bool hasPendingActivity) |
| 486 { | 466 { |
| 487 m_scriptExecutionContext->postTask(WorkerThreadActivityReportTask::create(th
is, false, hasPendingActivity)); | 467 m_scriptExecutionContext->postTask(WorkerThreadActivityReportTask::create(th
is, false, hasPendingActivity)); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 499 } | 479 } |
| 500 | 480 |
| 501 bool WorkerMessagingProxy::hasPendingActivity() const | 481 bool WorkerMessagingProxy::hasPendingActivity() const |
| 502 { | 482 { |
| 503 return (m_unconfirmedMessageCount || m_workerThreadHadPendingActivity) && !m
_askedToTerminate; | 483 return (m_unconfirmedMessageCount || m_workerThreadHadPendingActivity) && !m
_askedToTerminate; |
| 504 } | 484 } |
| 505 | 485 |
| 506 } // namespace WebCore | 486 } // namespace WebCore |
| 507 | 487 |
| 508 #endif // ENABLE(WORKERS) | 488 #endif // ENABLE(WORKERS) |
| OLD | NEW |