Index: Source/core/workers/WorkerMessagingProxy.cpp |
diff --git a/Source/core/workers/WorkerMessagingProxy.cpp b/Source/core/workers/WorkerMessagingProxy.cpp |
index 46d09cffd0fab2db4b6f4f50a8110a102e3255d4..79c2e829e836ecb8d22527821a66efedce1300f1 100644 |
--- a/Source/core/workers/WorkerMessagingProxy.cpp |
+++ b/Source/core/workers/WorkerMessagingProxy.cpp |
@@ -33,7 +33,10 @@ |
#include "core/dom/Document.h" |
#include "core/events/ErrorEvent.h" |
#include "core/events/MessageEvent.h" |
+#include "core/frame/Console.h" |
+#include "core/frame/FrameConsole.h" |
#include "core/frame/LocalDOMWindow.h" |
+#include "core/frame/LocalFrame.h" |
#include "core/frame/csp/ContentSecurityPolicy.h" |
#include "core/inspector/InspectorInstrumentation.h" |
#include "core/inspector/ScriptCallStack.h" |
@@ -177,7 +180,16 @@ void WorkerMessagingProxy::reportConsoleMessage(MessageSource source, MessageLev |
{ |
if (m_askedToTerminate) |
return; |
- m_executionContext->addConsoleMessage(ConsoleMessage::create(source, level, message, sourceURL, lineNumber)); |
+ // FIXME: In case of nested workers, this should go directly to the root Document context. |
+ ASSERT(m_executionContext->isDocument()); |
+ Document* document = toDocument(m_executionContext.get()); |
+ LocalFrame* frame = document->frame(); |
+ if (!frame) |
+ return; |
+ |
+ RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(source, level, message, sourceURL, lineNumber); |
+ consoleMessage->setWorkerId(this); |
+ frame->console().addMessage(consoleMessage.release()); |
} |
void WorkerMessagingProxy::workerThreadCreated(PassRefPtr<DedicatedWorkerThread> workerThread) |
@@ -276,9 +288,7 @@ void WorkerMessagingProxy::workerGlobalScopeDestroyed() |
// in either side any more. However, the Worker object may still exist, and it assumes that the proxy exists, too. |
m_askedToTerminate = true; |
m_workerThread = nullptr; |
- |
- InspectorInstrumentation::workerGlobalScopeTerminated(m_executionContext.get(), this); |
- |
+ terminateInternally(); |
if (m_mayBeDestroyed) |
delete this; |
} |
@@ -292,7 +302,7 @@ void WorkerMessagingProxy::terminateWorkerGlobalScope() |
if (m_workerThread) |
m_workerThread->stop(); |
- InspectorInstrumentation::workerGlobalScopeTerminated(m_executionContext.get(), this); |
+ terminateInternally(); |
} |
void WorkerMessagingProxy::postMessageToPageInspector(const String& message) |
@@ -320,4 +330,16 @@ bool WorkerMessagingProxy::hasPendingActivity() const |
return (m_unconfirmedMessageCount || m_workerThreadHadPendingActivity) && !m_askedToTerminate; |
} |
+void WorkerMessagingProxy::terminateInternally() |
+{ |
+ InspectorInstrumentation::workerGlobalScopeTerminated(m_executionContext.get(), this); |
+ |
+ // FIXME: This need to be revisited when we support nested worker one day |
+ ASSERT(m_executionContext->isDocument()); |
+ Document* document = toDocument(m_executionContext.get()); |
+ LocalFrame* frame = document->frame(); |
+ if (frame) |
+ frame->console().adoptWorkerConsoleMessages(this); |
+} |
+ |
} // namespace blink |