Commit ac6817b7 authored by sergeyv@chromium.org's avatar sergeyv@chromium.org

DevTools: Do not push to frontend messages from worker while it is alive

BUG=

Review URL: https://codereview.chromium.org/466753002

git-svn-id: svn://svn.chromium.org/blink/trunk@180165 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 36e1c1dd
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "core/page/Chrome.h" #include "core/page/Chrome.h"
#include "core/page/ChromeClient.h" #include "core/page/ChromeClient.h"
#include "core/page/Page.h" #include "core/page/Page.h"
#include "core/workers/WorkerGlobalScopeProxy.h"
#include "wtf/text/StringBuilder.h" #include "wtf/text/StringBuilder.h"
namespace blink { namespace blink {
...@@ -111,4 +112,9 @@ void FrameConsole::unmute() ...@@ -111,4 +112,9 @@ void FrameConsole::unmute()
muteCount--; muteCount--;
} }
void FrameConsole::adoptWorkerConsoleMessages(WorkerGlobalScopeProxy* proxy)
{
InspectorInstrumentation::adoptWorkerConsoleMessages(m_frame.document(), proxy);
}
} // namespace blink } // namespace blink
...@@ -40,6 +40,7 @@ namespace blink { ...@@ -40,6 +40,7 @@ namespace blink {
class ConsoleMessage; class ConsoleMessage;
class FrameHost; class FrameHost;
class ScriptCallStack; class ScriptCallStack;
class WorkerGlobalScopeProxy;
// FrameConsole takes per-frame console messages and routes them up through the FrameHost to the ChromeClient and Inspector. // FrameConsole takes per-frame console messages and routes them up through the FrameHost to the ChromeClient and Inspector.
// It's meant as an abstraction around ChromeClient calls and the way that Blink core/ can add messages to the console. // It's meant as an abstraction around ChromeClient calls and the way that Blink core/ can add messages to the console.
...@@ -48,6 +49,8 @@ public: ...@@ -48,6 +49,8 @@ public:
static PassOwnPtr<FrameConsole> create(LocalFrame& frame) { return adoptPtr(new FrameConsole(frame)); } static PassOwnPtr<FrameConsole> create(LocalFrame& frame) { return adoptPtr(new FrameConsole(frame)); }
void addMessage(PassRefPtrWillBeRawPtr<ConsoleMessage>); void addMessage(PassRefPtrWillBeRawPtr<ConsoleMessage>);
void adoptWorkerConsoleMessages(WorkerGlobalScopeProxy*);
static String formatStackTraceString(const String& originalMessage, PassRefPtrWillBeRawPtr<ScriptCallStack>); static String formatStackTraceString(const String& originalMessage, PassRefPtrWillBeRawPtr<ScriptCallStack>);
static void mute(); static void mute();
......
...@@ -14,6 +14,7 @@ ConsoleMessage::ConsoleMessage() ...@@ -14,6 +14,7 @@ ConsoleMessage::ConsoleMessage()
, m_columnNumber(0) , m_columnNumber(0)
, m_scriptState(nullptr) , m_scriptState(nullptr)
, m_requestIdentifier(0) , m_requestIdentifier(0)
, m_workerProxy(nullptr)
{ {
} }
...@@ -31,6 +32,7 @@ ConsoleMessage::ConsoleMessage(MessageSource source, ...@@ -31,6 +32,7 @@ ConsoleMessage::ConsoleMessage(MessageSource source,
, m_columnNumber(columnNumber) , m_columnNumber(columnNumber)
, m_scriptState(nullptr) , m_scriptState(nullptr)
, m_requestIdentifier(0) , m_requestIdentifier(0)
, m_workerProxy(nullptr)
{ {
} }
......
...@@ -18,6 +18,7 @@ namespace blink { ...@@ -18,6 +18,7 @@ namespace blink {
class ScriptCallStack; class ScriptCallStack;
class ScriptState; class ScriptState;
class WorkerGlobalScopeProxy;
class ConsoleMessage FINAL: public RefCountedWillBeGarbageCollectedFinalized<ConsoleMessage> { class ConsoleMessage FINAL: public RefCountedWillBeGarbageCollectedFinalized<ConsoleMessage> {
public: public:
...@@ -43,6 +44,8 @@ public: ...@@ -43,6 +44,8 @@ public:
MessageLevel level() const; MessageLevel level() const;
const String& message() const; const String& message() const;
unsigned columnNumber() const; unsigned columnNumber() const;
void setWorkerId(WorkerGlobalScopeProxy* proxy) { m_workerProxy = proxy; }
WorkerGlobalScopeProxy* workerId() { return m_workerProxy; }
void trace(Visitor*); void trace(Visitor*);
...@@ -59,6 +62,7 @@ private: ...@@ -59,6 +62,7 @@ private:
RefPtrWillBeMember<ScriptCallStack> m_callStack; RefPtrWillBeMember<ScriptCallStack> m_callStack;
ScriptState* m_scriptState; ScriptState* m_scriptState;
unsigned long m_requestIdentifier; unsigned long m_requestIdentifier;
WorkerGlobalScopeProxy* m_workerProxy;
}; };
} // namespace WebCore } // namespace WebCore
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#include "core/inspector/ScriptCallStack.h" #include "core/inspector/ScriptCallStack.h"
#include "core/loader/DocumentLoader.h" #include "core/loader/DocumentLoader.h"
#include "core/page/Page.h" #include "core/page/Page.h"
#include "core/workers/WorkerGlobalScopeProxy.h"
#include "platform/network/ResourceError.h" #include "platform/network/ResourceError.h"
#include "platform/network/ResourceResponse.h" #include "platform/network/ResourceResponse.h"
#include "wtf/CurrentTime.h" #include "wtf/CurrentTime.h"
...@@ -169,11 +170,22 @@ void InspectorConsoleAgent::clearFrontend() ...@@ -169,11 +170,22 @@ void InspectorConsoleAgent::clearFrontend()
void InspectorConsoleAgent::addMessageToConsole(ConsoleMessage* consoleMessage) void InspectorConsoleAgent::addMessageToConsole(ConsoleMessage* consoleMessage)
{ {
InspectorConsoleMessage* message;
if (consoleMessage->callStack()) { if (consoleMessage->callStack()) {
addConsoleMessage(adoptPtr(new InspectorConsoleMessage(consoleMessage->source(), LogMessageType, consoleMessage->level(), consoleMessage->message(), consoleMessage->callStack(), consoleMessage->requestIdentifier()))); message = new InspectorConsoleMessage(consoleMessage->source(), LogMessageType, consoleMessage->level(), consoleMessage->message(), consoleMessage->callStack(), consoleMessage->requestIdentifier());
} else { } else {
bool shouldGenerateCallStack = m_frontend; bool shouldGenerateCallStack = m_frontend;
addConsoleMessage(adoptPtr(new InspectorConsoleMessage(shouldGenerateCallStack, consoleMessage->source(), LogMessageType, consoleMessage->level(), consoleMessage->message(), consoleMessage->url(), consoleMessage->lineNumber(), consoleMessage->columnNumber(), consoleMessage->scriptState(), consoleMessage->requestIdentifier()))); message = new InspectorConsoleMessage(shouldGenerateCallStack, consoleMessage->source(), LogMessageType, consoleMessage->level(), consoleMessage->message(), consoleMessage->url(), consoleMessage->lineNumber(), consoleMessage->columnNumber(), consoleMessage->scriptState(), consoleMessage->requestIdentifier());
}
message->setWorkerGlobalScopeProxy(consoleMessage->workerId());
addConsoleMessage(adoptPtr(message));
}
void InspectorConsoleAgent::adoptWorkerConsoleMessages(WorkerGlobalScopeProxy* proxy)
{
for (size_t i = 0; i < m_consoleMessages.size(); i++) {
if (m_consoleMessages[i]->workerGlobalScopeProxy() == proxy)
m_consoleMessages[i]->setWorkerGlobalScopeProxy(nullptr);
} }
} }
......
...@@ -57,6 +57,7 @@ class ScriptArguments; ...@@ -57,6 +57,7 @@ class ScriptArguments;
class ScriptCallStack; class ScriptCallStack;
class ScriptProfile; class ScriptProfile;
class ThreadableLoaderClient; class ThreadableLoaderClient;
class WorkerGlobalScopeProxy;
class XMLHttpRequest; class XMLHttpRequest;
typedef String ErrorString; typedef String ErrorString;
...@@ -81,7 +82,7 @@ public: ...@@ -81,7 +82,7 @@ public:
void addConsoleAPIMessageToConsole(MessageType, MessageLevel, const String& message, ScriptState*, PassRefPtrWillBeRawPtr<ScriptArguments>, unsigned long requestIdentifier = 0); void addConsoleAPIMessageToConsole(MessageType, MessageLevel, const String& message, ScriptState*, PassRefPtrWillBeRawPtr<ScriptArguments>, unsigned long requestIdentifier = 0);
void addMessageToConsole(ConsoleMessage*); void addMessageToConsole(ConsoleMessage*);
void adoptWorkerConsoleMessages(WorkerGlobalScopeProxy*);
Vector<unsigned> consoleMessageArgumentCounts(); Vector<unsigned> consoleMessageArgumentCounts();
void consoleTime(ExecutionContext*, const String& title); void consoleTime(ExecutionContext*, const String& title);
......
...@@ -56,6 +56,7 @@ InspectorConsoleMessage::InspectorConsoleMessage(MessageSource source, MessageTy ...@@ -56,6 +56,7 @@ InspectorConsoleMessage::InspectorConsoleMessage(MessageSource source, MessageTy
, m_column(0) , m_column(0)
, m_requestId(IdentifiersFactory::requestId(0)) , m_requestId(IdentifiersFactory::requestId(0))
, m_timestamp(WTF::currentTime()) , m_timestamp(WTF::currentTime())
, m_workerProxy(nullptr)
{ {
autogenerateMetadata(); autogenerateMetadata();
} }
...@@ -71,6 +72,7 @@ InspectorConsoleMessage::InspectorConsoleMessage(bool shouldGenerateCallStack, M ...@@ -71,6 +72,7 @@ InspectorConsoleMessage::InspectorConsoleMessage(bool shouldGenerateCallStack, M
, m_column(column) , m_column(column)
, m_requestId(IdentifiersFactory::requestId(requestIdentifier)) , m_requestId(IdentifiersFactory::requestId(requestIdentifier))
, m_timestamp(WTF::currentTime()) , m_timestamp(WTF::currentTime())
, m_workerProxy(nullptr)
{ {
autogenerateMetadata(shouldGenerateCallStack); autogenerateMetadata(shouldGenerateCallStack);
} }
...@@ -87,6 +89,7 @@ InspectorConsoleMessage::InspectorConsoleMessage(MessageSource source, MessageTy ...@@ -87,6 +89,7 @@ InspectorConsoleMessage::InspectorConsoleMessage(MessageSource source, MessageTy
, m_column(0) , m_column(0)
, m_requestId(IdentifiersFactory::requestId(requestIdentifier)) , m_requestId(IdentifiersFactory::requestId(requestIdentifier))
, m_timestamp(WTF::currentTime()) , m_timestamp(WTF::currentTime())
, m_workerProxy(nullptr)
{ {
autogenerateMetadata(false); autogenerateMetadata(false);
} }
...@@ -103,6 +106,7 @@ InspectorConsoleMessage::InspectorConsoleMessage(MessageSource source, MessageTy ...@@ -103,6 +106,7 @@ InspectorConsoleMessage::InspectorConsoleMessage(MessageSource source, MessageTy
, m_column(0) , m_column(0)
, m_requestId(IdentifiersFactory::requestId(requestIdentifier)) , m_requestId(IdentifiersFactory::requestId(requestIdentifier))
, m_timestamp(WTF::currentTime()) , m_timestamp(WTF::currentTime())
, m_workerProxy(nullptr)
{ {
autogenerateMetadata(); autogenerateMetadata();
} }
...@@ -179,6 +183,9 @@ static TypeBuilder::Console::ConsoleMessage::Level::Enum messageLevelValue(Messa ...@@ -179,6 +183,9 @@ static TypeBuilder::Console::ConsoleMessage::Level::Enum messageLevelValue(Messa
void InspectorConsoleMessage::addToFrontend(InspectorFrontend::Console* frontend, InjectedScriptManager* injectedScriptManager, bool generatePreview) void InspectorConsoleMessage::addToFrontend(InspectorFrontend::Console* frontend, InjectedScriptManager* injectedScriptManager, bool generatePreview)
{ {
if (m_workerProxy)
return;
RefPtr<TypeBuilder::Console::ConsoleMessage> jsonObj = TypeBuilder::Console::ConsoleMessage::create() RefPtr<TypeBuilder::Console::ConsoleMessage> jsonObj = TypeBuilder::Console::ConsoleMessage::create()
.setSource(messageSourceValue(m_source)) .setSource(messageSourceValue(m_source))
.setLevel(messageLevelValue(m_level)) .setLevel(messageLevelValue(m_level))
......
...@@ -46,6 +46,7 @@ class ScriptArguments; ...@@ -46,6 +46,7 @@ class ScriptArguments;
class ScriptCallFrame; class ScriptCallFrame;
class ScriptCallStack; class ScriptCallStack;
class ScriptValue; class ScriptValue;
class WorkerGlobalScopeProxy;
class InspectorConsoleMessage { class InspectorConsoleMessage {
WTF_MAKE_NONCOPYABLE(InspectorConsoleMessage); WTF_MAKE_FAST_ALLOCATED; WTF_MAKE_NONCOPYABLE(InspectorConsoleMessage); WTF_MAKE_FAST_ALLOCATED;
...@@ -58,6 +59,8 @@ public: ...@@ -58,6 +59,8 @@ public:
void addToFrontend(InspectorFrontend::Console*, InjectedScriptManager*, bool generatePreview); void addToFrontend(InspectorFrontend::Console*, InjectedScriptManager*, bool generatePreview);
void setTimestamp(double timestamp) { m_timestamp = timestamp; } void setTimestamp(double timestamp) { m_timestamp = timestamp; }
void setWorkerGlobalScopeProxy(WorkerGlobalScopeProxy* proxy) { m_workerProxy = proxy; }
WorkerGlobalScopeProxy* workerGlobalScopeProxy() { return m_workerProxy; }
MessageType type() const { return m_type; } MessageType type() const { return m_type; }
...@@ -80,6 +83,7 @@ private: ...@@ -80,6 +83,7 @@ private:
unsigned m_column; unsigned m_column;
String m_requestId; String m_requestId;
double m_timestamp; double m_timestamp;
WorkerGlobalScopeProxy* m_workerProxy;
}; };
} // namespace blink } // namespace blink
......
...@@ -510,6 +510,10 @@ class ConsoleMessage; ...@@ -510,6 +510,10 @@ class ConsoleMessage;
[Profiler, Inline=FastReturn] [Profiler, Inline=FastReturn]
void consoleProfileEnd(ExecutionContext* context, const String& title); void consoleProfileEnd(ExecutionContext* context, const String& title);
//FIXME: remove when we move console message storage from InspectorConsoleAgent to FrameConsole
[Console]
void adoptWorkerConsoleMessages(ExecutionContext* context, WorkerGlobalScopeProxy* proxy);
} }
interface InspectorOverrides { interface InspectorOverrides {
......
...@@ -33,7 +33,10 @@ ...@@ -33,7 +33,10 @@
#include "core/dom/Document.h" #include "core/dom/Document.h"
#include "core/events/ErrorEvent.h" #include "core/events/ErrorEvent.h"
#include "core/events/MessageEvent.h" #include "core/events/MessageEvent.h"
#include "core/frame/Console.h"
#include "core/frame/FrameConsole.h"
#include "core/frame/LocalDOMWindow.h" #include "core/frame/LocalDOMWindow.h"
#include "core/frame/LocalFrame.h"
#include "core/frame/csp/ContentSecurityPolicy.h" #include "core/frame/csp/ContentSecurityPolicy.h"
#include "core/inspector/InspectorInstrumentation.h" #include "core/inspector/InspectorInstrumentation.h"
#include "core/inspector/ScriptCallStack.h" #include "core/inspector/ScriptCallStack.h"
...@@ -177,7 +180,16 @@ void WorkerMessagingProxy::reportConsoleMessage(MessageSource source, MessageLev ...@@ -177,7 +180,16 @@ void WorkerMessagingProxy::reportConsoleMessage(MessageSource source, MessageLev
{ {
if (m_askedToTerminate) if (m_askedToTerminate)
return; 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) void WorkerMessagingProxy::workerThreadCreated(PassRefPtr<DedicatedWorkerThread> workerThread)
...@@ -276,9 +288,7 @@ void WorkerMessagingProxy::workerGlobalScopeDestroyed() ...@@ -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. // in either side any more. However, the Worker object may still exist, and it assumes that the proxy exists, too.
m_askedToTerminate = true; m_askedToTerminate = true;
m_workerThread = nullptr; m_workerThread = nullptr;
terminateInternally();
InspectorInstrumentation::workerGlobalScopeTerminated(m_executionContext.get(), this);
if (m_mayBeDestroyed) if (m_mayBeDestroyed)
delete this; delete this;
} }
...@@ -292,7 +302,7 @@ void WorkerMessagingProxy::terminateWorkerGlobalScope() ...@@ -292,7 +302,7 @@ void WorkerMessagingProxy::terminateWorkerGlobalScope()
if (m_workerThread) if (m_workerThread)
m_workerThread->stop(); m_workerThread->stop();
InspectorInstrumentation::workerGlobalScopeTerminated(m_executionContext.get(), this); terminateInternally();
} }
void WorkerMessagingProxy::postMessageToPageInspector(const String& message) void WorkerMessagingProxy::postMessageToPageInspector(const String& message)
...@@ -320,4 +330,16 @@ bool WorkerMessagingProxy::hasPendingActivity() const ...@@ -320,4 +330,16 @@ bool WorkerMessagingProxy::hasPendingActivity() const
return (m_unconfirmedMessageCount || m_workerThreadHadPendingActivity) && !m_askedToTerminate; 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 } // namespace blink
...@@ -86,6 +86,7 @@ protected: ...@@ -86,6 +86,7 @@ protected:
private: private:
static void workerObjectDestroyedInternal(ExecutionContext*, WorkerMessagingProxy*); static void workerObjectDestroyedInternal(ExecutionContext*, WorkerMessagingProxy*);
void terminateInternally();
RefPtrWillBePersistent<ExecutionContext> m_executionContext; RefPtrWillBePersistent<ExecutionContext> m_executionContext;
OwnPtr<WorkerObjectProxy> m_workerObjectProxy; OwnPtr<WorkerObjectProxy> m_workerObjectProxy;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment