From 821ac29a26b665d65f674d6ccf88590ad91c5806 Mon Sep 17 00:00:00 2001 From: dgozman Date: Mon, 25 Apr 2016 13:42:10 -0700 Subject: [PATCH] [DevTools] Move v8-related instrumentation from agents to InspectorSession. Added V8InspectorSessionClient which gets notified when instrumentation should start and stop. BUG=590878,580337 Review URL: https://codereview.chromium.org/1907663005 Cr-Commit-Position: refs/heads/master@{#389556} --- .../inspector/CodeGeneratorInstrumentation.py | 2 + .../core/inspector/InspectorDebuggerAgent.cpp | 39 ----- .../core/inspector/InspectorDebuggerAgent.h | 11 -- .../inspector/InspectorInstrumentation.cpp | 8 +- .../inspector/InspectorInstrumentation.idl | 36 +++-- .../core/inspector/InspectorProfilerAgent.cpp | 23 --- .../core/inspector/InspectorProfilerAgent.h | 5 - .../core/inspector/InspectorSession.cpp | 134 +++++++++++++++++- .../Source/core/inspector/InspectorSession.h | 37 ++++- .../core/inspector/PageDebuggerAgent.cpp | 10 -- .../Source/core/inspector/PageDebuggerAgent.h | 2 - .../core/inspector/PageRuntimeAgent.cpp | 12 -- .../Source/core/inspector/PageRuntimeAgent.h | 2 - .../inspector/WorkerInspectorController.cpp | 4 +- .../Source/platform/blink_platform.gypi | 1 + .../v8_inspector/V8DebuggerAgentImpl.cpp | 2 + .../v8_inspector/V8InspectorSessionImpl.cpp | 17 +++ .../v8_inspector/V8InspectorSessionImpl.h | 6 + .../v8_inspector/V8ProfilerAgentImpl.cpp | 24 +++- .../v8_inspector/V8ProfilerAgentImpl.h | 3 +- .../v8_inspector/V8RuntimeAgentImpl.cpp | 4 + .../v8_inspector/public/V8InspectorSession.h | 3 + .../public/V8InspectorSessionClient.h | 24 ++++ .../Source/web/WebDevToolsAgentImpl.cpp | 16 +-- 24 files changed, 275 insertions(+), 150 deletions(-) create mode 100644 third_party/WebKit/Source/platform/v8_inspector/public/V8InspectorSessionClient.h diff --git a/third_party/WebKit/Source/core/inspector/CodeGeneratorInstrumentation.py b/third_party/WebKit/Source/core/inspector/CodeGeneratorInstrumentation.py index 57162f19b82564..3b10ff2d705793 100755 --- a/third_party/WebKit/Source/core/inspector/CodeGeneratorInstrumentation.py +++ b/third_party/WebKit/Source/core/inspector/CodeGeneratorInstrumentation.py @@ -353,6 +353,8 @@ def generate_param_name(param_type): def agent_class_name(agent): + if agent == "V8": + return "InspectorSession" custom_agent_names = ["PageDebugger", "PageRuntime", "WorkerRuntime", "PageConsole"] if agent in custom_agent_names: return "%sAgent" % agent diff --git a/third_party/WebKit/Source/core/inspector/InspectorDebuggerAgent.cpp b/third_party/WebKit/Source/core/inspector/InspectorDebuggerAgent.cpp index 0087ef7095e68b..3df7e846701aa5 100644 --- a/third_party/WebKit/Source/core/inspector/InspectorDebuggerAgent.cpp +++ b/third_party/WebKit/Source/core/inspector/InspectorDebuggerAgent.cpp @@ -60,14 +60,12 @@ DEFINE_TRACE(InspectorDebuggerAgent) void InspectorDebuggerAgent::enable(ErrorString* errorString) { m_v8DebuggerAgent->enable(errorString); - m_instrumentingAgents->setInspectorDebuggerAgent(this); m_state->setBoolean(DebuggerAgentState::debuggerEnabled, true); } void InspectorDebuggerAgent::disable(ErrorString* errorString) { m_state->setBoolean(DebuggerAgentState::debuggerEnabled, false); - m_instrumentingAgents->setInspectorDebuggerAgent(nullptr); m_v8DebuggerAgent->disable(errorString); } @@ -257,43 +255,6 @@ void InspectorDebuggerAgent::setBlackboxedRanges( m_v8DebuggerAgent->setBlackboxedRanges(errorString, inScriptId, std::move(inPositions)); } -void InspectorDebuggerAgent::scriptExecutionBlockedByCSP(const String& directiveText) -{ - OwnPtr directive = protocol::DictionaryValue::create(); - directive->setString("directiveText", directiveText); - m_v8DebuggerAgent->breakProgramOnException(protocol::Debugger::Paused::ReasonEnum::CSPViolation, directive.release()); -} - -void InspectorDebuggerAgent::asyncTaskScheduled(const String& taskName, void* task) -{ - m_v8DebuggerAgent->asyncTaskScheduled(taskName, task, false); -} - -void InspectorDebuggerAgent::asyncTaskScheduled(const String& operationName, void* task, bool recurring) -{ - m_v8DebuggerAgent->asyncTaskScheduled(operationName, task, recurring); -} - -void InspectorDebuggerAgent::asyncTaskCanceled(void* task) -{ - m_v8DebuggerAgent->asyncTaskCanceled(task); -} - -void InspectorDebuggerAgent::allAsyncTasksCanceled() -{ - m_v8DebuggerAgent->allAsyncTasksCanceled(); -} - -void InspectorDebuggerAgent::asyncTaskStarted(void* task) -{ - m_v8DebuggerAgent->asyncTaskStarted(task); -} - -void InspectorDebuggerAgent::asyncTaskFinished(void* task) -{ - m_v8DebuggerAgent->asyncTaskFinished(task); -} - // InspectorBaseAgent overrides. void InspectorDebuggerAgent::init(InstrumentingAgents* instrumentingAgents, protocol::Frontend* baseFrontend, protocol::Dispatcher* dispatcher, protocol::DictionaryValue* state) { diff --git a/third_party/WebKit/Source/core/inspector/InspectorDebuggerAgent.h b/third_party/WebKit/Source/core/inspector/InspectorDebuggerAgent.h index afcdf782851531..e9ab64169db53b 100644 --- a/third_party/WebKit/Source/core/inspector/InspectorDebuggerAgent.h +++ b/third_party/WebKit/Source/core/inspector/InspectorDebuggerAgent.h @@ -76,17 +76,6 @@ class CORE_EXPORT InspectorDebuggerAgent void setBlackboxPatterns(ErrorString*, PassOwnPtr> patterns) override; void setBlackboxedRanges(ErrorString*, const String16& scriptId, PassOwnPtr> positions) override; - // Called by InspectorInstrumentation. - void scriptExecutionBlockedByCSP(const String& directiveText); - - // Async stack implementation. - void asyncTaskScheduled(const String& taskName, void* task); - void asyncTaskScheduled(const String& taskName, void* task, bool recurring); - void asyncTaskCanceled(void* task); - void allAsyncTasksCanceled(); - void asyncTaskStarted(void* task); - void asyncTaskFinished(void* task); - // InspectorBaseAgent overrides. void init(InstrumentingAgents*, protocol::Frontend*, protocol::Dispatcher*, protocol::DictionaryValue*) override; void dispose() override; diff --git a/third_party/WebKit/Source/core/inspector/InspectorInstrumentation.cpp b/third_party/WebKit/Source/core/inspector/InspectorInstrumentation.cpp index 9a1c4a0d4203db..6f816743ec75d1 100644 --- a/third_party/WebKit/Source/core/inspector/InspectorInstrumentation.cpp +++ b/third_party/WebKit/Source/core/inspector/InspectorInstrumentation.cpp @@ -73,8 +73,8 @@ AsyncTask::AsyncTask(ExecutionContext* context, void* task, bool enabled) if (!m_instrumentingSessions || m_instrumentingSessions->isEmpty()) return; for (InspectorSession* session : *m_instrumentingSessions) { - if (session->instrumentingAgents()->inspectorDebuggerAgent()) - session->instrumentingAgents()->inspectorDebuggerAgent()->asyncTaskStarted(m_task); + if (session->instrumentingAgents()->inspectorSession()) + session->instrumentingAgents()->inspectorSession()->asyncTaskStarted(m_task); } } @@ -83,8 +83,8 @@ AsyncTask::~AsyncTask() if (!m_instrumentingSessions || m_instrumentingSessions->isEmpty()) return; for (InspectorSession* session : *m_instrumentingSessions) { - if (session->instrumentingAgents()->inspectorDebuggerAgent()) - session->instrumentingAgents()->inspectorDebuggerAgent()->asyncTaskFinished(m_task); + if (session->instrumentingAgents()->inspectorSession()) + session->instrumentingAgents()->inspectorSession()->asyncTaskFinished(m_task); } } diff --git a/third_party/WebKit/Source/core/inspector/InspectorInstrumentation.idl b/third_party/WebKit/Source/core/inspector/InspectorInstrumentation.idl index 4d4f1fde0ebe6a..431b22293cdfd9 100644 --- a/third_party/WebKit/Source/core/inspector/InspectorInstrumentation.idl +++ b/third_party/WebKit/Source/core/inspector/InspectorInstrumentation.idl @@ -71,7 +71,7 @@ class WorkerInspectorProxy; class XMLHttpRequest; // We should call PageDebuggerAgent method first otherwise this method resets script cache and removes scripts executed by other agents. - [PageRuntime, Page, Animation] + [V8, Page, Animation] void didClearDocumentOfWindowObject([Keep] LocalFrame*); [DOMDebugger] @@ -206,13 +206,13 @@ class XMLHttpRequest; [Resource] void scriptImported(ExecutionContext*, unsigned long identifier, const String& sourceString); - [Debugger] + [V8] void scriptExecutionBlockedByCSP(ExecutionContext*, const String& directiveText); [Resource] void didReceiveScriptResponse(ExecutionContext*, unsigned long identifier); - [PageDebugger] + [V8] void didStartProvisionalLoad([Keep] LocalFrame*); [DOM, Page] @@ -257,17 +257,23 @@ class XMLHttpRequest; [Worker, PageConsole] void workerTerminated(ExecutionContext*, WorkerInspectorProxy* proxy); - [Profiler] - void willProcessTask(WorkerGlobalScope* context); + [V8] + void willProcessTask(WorkerGlobalScope*); - [Profiler] - void didProcessTask(WorkerGlobalScope* context); + [V8] + void didProcessTask(WorkerGlobalScope*); - [Profiler] - void willEnterNestedRunLoop(WorkerGlobalScope* context); + [V8] + void willProcessTask(LocalFrame*); - [Profiler] - void didLeaveNestedRunLoop(WorkerGlobalScope* context); + [V8] + void didProcessTask(LocalFrame*); + + [V8] + void willEnterNestedRunLoop(WorkerGlobalScope*); + + [V8] + void didLeaveNestedRunLoop(WorkerGlobalScope*); [Resource] void didCreateWebSocket([Keep] Document*, unsigned long identifier, const KURL& requestURL, const String& protocol); @@ -305,16 +311,16 @@ class XMLHttpRequest; [DOM] void pseudoElementDestroyed([Keep] PseudoElement*); - [Debugger] + [V8] void asyncTaskScheduled(ExecutionContext*, const String& name, void*); - [Debugger] + [V8] void asyncTaskScheduled(ExecutionContext*, const String& name, void*, bool recurring); - [Debugger] + [V8] void asyncTaskCanceled(ExecutionContext*, void*); - [Debugger] + [V8] void allAsyncTasksCanceled(ExecutionContext*); [Animation] diff --git a/third_party/WebKit/Source/core/inspector/InspectorProfilerAgent.cpp b/third_party/WebKit/Source/core/inspector/InspectorProfilerAgent.cpp index 18551341c1f04a..e3bd1a13555094 100644 --- a/third_party/WebKit/Source/core/inspector/InspectorProfilerAgent.cpp +++ b/third_party/WebKit/Source/core/inspector/InspectorProfilerAgent.cpp @@ -31,7 +31,6 @@ #include "bindings/core/v8/ScriptCallStack.h" #include "bindings/core/v8/V8Binding.h" -#include "core/frame/UseCounter.h" #include "platform/v8_inspector/public/V8ProfilerAgent.h" namespace blink { @@ -83,12 +82,10 @@ void InspectorProfilerAgent::enable(ErrorString* errorString) { m_v8ProfilerAgent->enable(errorString); m_state->setBoolean(ProfilerAgentState::profilerEnabled, true); - m_instrumentingAgents->setInspectorProfilerAgent(this); } void InspectorProfilerAgent::disable(ErrorString* errorString) { - m_instrumentingAgents->setInspectorProfilerAgent(nullptr); m_state->setBoolean(ProfilerAgentState::profilerEnabled, false); m_v8ProfilerAgent->disable(errorString); } @@ -112,26 +109,6 @@ void InspectorProfilerAgent::stop(ErrorString* errorString, OwnPtrstop(errorString, profile); } -void InspectorProfilerAgent::willProcessTask() -{ - m_v8ProfilerAgent->idleFinished(); -} - -void InspectorProfilerAgent::didProcessTask() -{ - m_v8ProfilerAgent->idleStarted(); -} - -void InspectorProfilerAgent::willEnterNestedRunLoop() -{ - m_v8ProfilerAgent->idleStarted(); -} - -void InspectorProfilerAgent::didLeaveNestedRunLoop() -{ - m_v8ProfilerAgent->idleFinished(); -} - DEFINE_TRACE(InspectorProfilerAgent) { InspectorBaseAgent::trace(visitor); diff --git a/third_party/WebKit/Source/core/inspector/InspectorProfilerAgent.h b/third_party/WebKit/Source/core/inspector/InspectorProfilerAgent.h index a364b9fb8804aa..f5cc784ce77d86 100644 --- a/third_party/WebKit/Source/core/inspector/InspectorProfilerAgent.h +++ b/third_party/WebKit/Source/core/inspector/InspectorProfilerAgent.h @@ -68,11 +68,6 @@ class CORE_EXPORT InspectorProfilerAgent final : public InspectorBaseAgent*) override; - void willProcessTask(); - void didProcessTask(); - void willEnterNestedRunLoop(); - void didLeaveNestedRunLoop(); - private: InspectorProfilerAgent(V8ProfilerAgent*, Client*); diff --git a/third_party/WebKit/Source/core/inspector/InspectorSession.cpp b/third_party/WebKit/Source/core/inspector/InspectorSession.cpp index 83d04455373570..762fa10641d9f4 100644 --- a/third_party/WebKit/Source/core/inspector/InspectorSession.cpp +++ b/third_party/WebKit/Source/core/inspector/InspectorSession.cpp @@ -4,20 +4,30 @@ #include "core/inspector/InspectorSession.h" +#include "bindings/core/v8/ScriptController.h" #include "core/InstrumentingAgents.h" +#include "core/frame/LocalFrame.h" +#include "core/frame/UseCounter.h" +#include "core/inspector/InspectedFrames.h" #include "core/inspector/InspectorBaseAgent.h" #include "core/inspector/InspectorInstrumentation.h" #include "platform/inspector_protocol/Backend.h" #include "platform/inspector_protocol/Parser.h" #include "platform/inspector_protocol/TypeBuilder.h" +#include "platform/v8_inspector/public/V8DebuggerAgent.h" +#include "platform/v8_inspector/public/V8InspectorSession.h" +#include "platform/v8_inspector/public/V8ProfilerAgent.h" +#include "platform/v8_inspector/public/V8RuntimeAgent.h" namespace blink { -InspectorSession::InspectorSession(Client* client, int sessionId, bool autoFlush) +InspectorSession::InspectorSession(Client* client, InspectedFrames* inspectedFrames, int sessionId, bool autoFlush) : m_client(client) + , m_v8Session(nullptr) , m_sessionId(sessionId) , m_autoFlush(autoFlush) , m_attached(false) + , m_inspectedFrames(inspectedFrames) , m_instrumentingAgents(new InstrumentingAgents()) , m_inspectorFrontend(adoptPtr(new protocol::Frontend(this))) , m_inspectorBackendDispatcher(protocol::Dispatcher::create(this)) @@ -29,10 +39,12 @@ void InspectorSession::append(InspectorAgent* agent) m_agents.append(agent); } -void InspectorSession::attach(const String* savedState) +void InspectorSession::attach(V8InspectorSession* v8Session, const String* savedState) { ASSERT(!m_attached); m_attached = true; + m_v8Session = v8Session; + m_v8Session->setClient(this); InspectorInstrumentation::frontendCreated(); bool restore = savedState; @@ -59,13 +71,15 @@ void InspectorSession::detach() { ASSERT(m_attached); m_attached = false; - m_inspectorBackendDispatcher->clearFrontend(); m_inspectorBackendDispatcher.clear(); for (size_t i = m_agents.size(); i > 0; i--) m_agents[i - 1]->dispose(); m_inspectorFrontend.clear(); m_agents.clear(); + m_v8Session->setClient(nullptr); + m_v8Session = nullptr; + ASSERT(!isInstrumenting()); InspectorInstrumentation::frontendDeleted(); } @@ -120,9 +134,123 @@ void InspectorSession::flushPendingProtocolNotifications() m_notificationQueue.clear(); } +void InspectorSession::scriptExecutionBlockedByCSP(const String& directiveText) +{ + ASSERT(isInstrumenting()); + OwnPtr directive = protocol::DictionaryValue::create(); + directive->setString("directiveText", directiveText); + m_v8Session->debuggerAgent()->breakProgramOnException(protocol::Debugger::Paused::ReasonEnum::CSPViolation, directive.release()); +} + +void InspectorSession::asyncTaskScheduled(const String& taskName, void* task) +{ + ASSERT(isInstrumenting()); + m_v8Session->debuggerAgent()->asyncTaskScheduled(taskName, task, false); +} + +void InspectorSession::asyncTaskScheduled(const String& operationName, void* task, bool recurring) +{ + ASSERT(isInstrumenting()); + m_v8Session->debuggerAgent()->asyncTaskScheduled(operationName, task, recurring); +} + +void InspectorSession::asyncTaskCanceled(void* task) +{ + ASSERT(isInstrumenting()); + m_v8Session->debuggerAgent()->asyncTaskCanceled(task); +} + +void InspectorSession::allAsyncTasksCanceled() +{ + ASSERT(isInstrumenting()); + m_v8Session->debuggerAgent()->allAsyncTasksCanceled(); +} + +void InspectorSession::asyncTaskStarted(void* task) +{ + ASSERT(isInstrumenting()); + m_v8Session->debuggerAgent()->asyncTaskStarted(task); +} + +void InspectorSession::asyncTaskFinished(void* task) +{ + ASSERT(isInstrumenting()); + m_v8Session->debuggerAgent()->asyncTaskFinished(task); +} + +void InspectorSession::didStartProvisionalLoad(LocalFrame* frame) +{ + ASSERT(isInstrumenting()); + if (m_inspectedFrames && m_inspectedFrames->root() == frame) { + ErrorString error; + m_v8Session->debuggerAgent()->resume(&error); + } +} + +void InspectorSession::didClearDocumentOfWindowObject(LocalFrame* frame) +{ + ASSERT(isInstrumenting()); + frame->script().initializeMainWorld(); +} + +void InspectorSession::willProcessTask() +{ + ASSERT(isInstrumenting()); + m_v8Session->profilerAgent()->idleFinished(); +} + +void InspectorSession::didProcessTask() +{ + ASSERT(isInstrumenting()); + m_v8Session->profilerAgent()->idleStarted(); +} + +void InspectorSession::willEnterNestedRunLoop() +{ + ASSERT(isInstrumenting()); + m_v8Session->profilerAgent()->idleStarted(); +} + +void InspectorSession::didLeaveNestedRunLoop() +{ + ASSERT(isInstrumenting()); + m_v8Session->profilerAgent()->idleFinished(); +} + +void InspectorSession::startInstrumenting() +{ + ASSERT(!isInstrumenting()); + m_instrumentingAgents->setInspectorSession(this); + forceContextsInAllFrames(); +} + +void InspectorSession::stopInstrumenting() +{ + ASSERT(isInstrumenting()); + m_instrumentingAgents->setInspectorSession(nullptr); +} + +void InspectorSession::forceContextsInAllFrames() +{ + if (!m_inspectedFrames) + return; + if (!m_inspectedFrames->root()->loader().stateMachine()->committedFirstRealDocumentLoad()) + return; + for (const LocalFrame* frame : *m_inspectedFrames) + frame->script().initializeMainWorld(); +} + +#if ENABLE(ASSERT) +bool InspectorSession::isInstrumenting() +{ + return m_instrumentingAgents->inspectorSession() == this; +} +#endif + DEFINE_TRACE(InspectorSession) { visitor->trace(m_instrumentingAgents); + visitor->trace(m_inspectedFrames); visitor->trace(m_agents); } diff --git a/third_party/WebKit/Source/core/inspector/InspectorSession.h b/third_party/WebKit/Source/core/inspector/InspectorSession.h index c76bc873d573f9..7688829ecbe84d 100644 --- a/third_party/WebKit/Source/core/inspector/InspectorSession.h +++ b/third_party/WebKit/Source/core/inspector/InspectorSession.h @@ -11,6 +11,7 @@ #include "platform/inspector_protocol/Frontend.h" #include "platform/inspector_protocol/FrontendChannel.h" #include "platform/inspector_protocol/Values.h" +#include "platform/v8_inspector/public/V8InspectorSessionClient.h" #include "wtf/Forward.h" #include "wtf/PassOwnPtr.h" #include "wtf/Vector.h" @@ -18,13 +19,17 @@ namespace blink { +class ExecutionContext; +class InspectedFrames; class InspectorAgent; class InstrumentingAgents; class LocalFrame; +class V8InspectorSession; class CORE_EXPORT InspectorSession : public GarbageCollectedFinalized - , WTF_NON_EXPORTED_BASE(public protocol::FrontendChannel) { + , WTF_NON_EXPORTED_BASE(public protocol::FrontendChannel) + , public V8InspectorSessionClient { WTF_MAKE_NONCOPYABLE(InspectorSession); public: class Client { @@ -33,17 +38,32 @@ class CORE_EXPORT InspectorSession virtual ~Client() {} }; - InspectorSession(Client*, int sessionId, bool autoFlush); + InspectorSession(Client*, InspectedFrames*, int sessionId, bool autoFlush); int sessionId() { return m_sessionId; } InstrumentingAgents* instrumentingAgents() { return m_instrumentingAgents.get(); } void append(InspectorAgent*); - void attach(const String* savedState); + void attach(V8InspectorSession*, const String* savedState); void detach(); void didCommitLoadForLocalFrame(LocalFrame*); void dispatchProtocolMessage(const String& message); void flushPendingProtocolNotifications(); + // Instrumentation methods marked by [V8] + void scriptExecutionBlockedByCSP(const String& directiveText); + void asyncTaskScheduled(const String& taskName, void* task); + void asyncTaskScheduled(const String& taskName, void* task, bool recurring); + void asyncTaskCanceled(void* task); + void allAsyncTasksCanceled(); + void asyncTaskStarted(void* task); + void asyncTaskFinished(void* task); + void didStartProvisionalLoad(LocalFrame*); + void didClearDocumentOfWindowObject(LocalFrame*); + void willProcessTask(); + void didProcessTask(); + void willEnterNestedRunLoop(); + void didLeaveNestedRunLoop(); + DECLARE_TRACE(); private: @@ -52,10 +72,21 @@ class CORE_EXPORT InspectorSession void sendProtocolNotification(PassOwnPtr message) override; void flush(); + // V8InspectorSessionClient implementation. + void startInstrumenting() override; + void stopInstrumenting() override; + + void forceContextsInAllFrames(); +#if ENABLE(ASSERT) + bool isInstrumenting(); +#endif + Client* m_client; + V8InspectorSession* m_v8Session; int m_sessionId; bool m_autoFlush; bool m_attached; + Member m_inspectedFrames; Member m_instrumentingAgents; OwnPtr m_inspectorFrontend; OwnPtr m_inspectorBackendDispatcher; diff --git a/third_party/WebKit/Source/core/inspector/PageDebuggerAgent.cpp b/third_party/WebKit/Source/core/inspector/PageDebuggerAgent.cpp index 38c083420e22a1..56e3fab731b6e4 100644 --- a/third_party/WebKit/Source/core/inspector/PageDebuggerAgent.cpp +++ b/third_party/WebKit/Source/core/inspector/PageDebuggerAgent.cpp @@ -79,12 +79,10 @@ void PageDebuggerAgent::enable(ErrorString* errorString) return; } InspectorDebuggerAgent::enable(errorString); - m_instrumentingAgents->setPageDebuggerAgent(this); } void PageDebuggerAgent::disable(ErrorString* errorString) { - m_instrumentingAgents->setPageDebuggerAgent(nullptr); m_compiledScriptURLs.clear(); InspectorDebuggerAgent::disable(errorString); } @@ -96,12 +94,4 @@ void PageDebuggerAgent::restore() } -void PageDebuggerAgent::didStartProvisionalLoad(LocalFrame* frame) -{ - if (frame == m_inspectedFrames->root()) { - ErrorString error; - resume(&error); - } -} - } // namespace blink diff --git a/third_party/WebKit/Source/core/inspector/PageDebuggerAgent.h b/third_party/WebKit/Source/core/inspector/PageDebuggerAgent.h index ba72504a83a45a..74af949a539d31 100644 --- a/third_party/WebKit/Source/core/inspector/PageDebuggerAgent.h +++ b/third_party/WebKit/Source/core/inspector/PageDebuggerAgent.h @@ -55,8 +55,6 @@ class CORE_EXPORT PageDebuggerAgent final void disable(ErrorString*) final; void restore() final; - void didStartProvisionalLoad(LocalFrame*); - private: PageDebuggerAgent(V8DebuggerAgent*, InspectedFrames*); diff --git a/third_party/WebKit/Source/core/inspector/PageRuntimeAgent.cpp b/third_party/WebKit/Source/core/inspector/PageRuntimeAgent.cpp index c6bb1d5ebc60fa..f7992d5dd2b20d 100644 --- a/third_party/WebKit/Source/core/inspector/PageRuntimeAgent.cpp +++ b/third_party/WebKit/Source/core/inspector/PageRuntimeAgent.cpp @@ -63,12 +63,6 @@ void PageRuntimeAgent::enable(ErrorString* errorString) { if (m_enabled) return; - - m_instrumentingAgents->setPageRuntimeAgent(this); - if (m_inspectedFrames->root()->loader().stateMachine()->committedFirstRealDocumentLoad()) { - for (const LocalFrame* frame : *m_inspectedFrames) - frame->script().initializeMainWorld(); - } InspectorRuntimeAgent::enable(errorString); } @@ -77,12 +71,6 @@ void PageRuntimeAgent::disable(ErrorString* errorString) if (!m_enabled) return; InspectorRuntimeAgent::disable(errorString); - m_instrumentingAgents->setPageRuntimeAgent(nullptr); -} - -void PageRuntimeAgent::didClearDocumentOfWindowObject(LocalFrame* frame) -{ - frame->script().initializeMainWorld(); } } // namespace blink diff --git a/third_party/WebKit/Source/core/inspector/PageRuntimeAgent.h b/third_party/WebKit/Source/core/inspector/PageRuntimeAgent.h index 034ffe00c4b7b2..17b55273a3f7d9 100644 --- a/third_party/WebKit/Source/core/inspector/PageRuntimeAgent.h +++ b/third_party/WebKit/Source/core/inspector/PageRuntimeAgent.h @@ -51,8 +51,6 @@ class CORE_EXPORT PageRuntimeAgent final : public InspectorRuntimeAgent { void enable(ErrorString*) override; void disable(ErrorString*) override; - void didClearDocumentOfWindowObject(LocalFrame*); - private: PageRuntimeAgent(Client*, V8RuntimeAgent*, InspectedFrames*); diff --git a/third_party/WebKit/Source/core/inspector/WorkerInspectorController.cpp b/third_party/WebKit/Source/core/inspector/WorkerInspectorController.cpp index bc0c434927a0ca..7f93c6e6a24e92 100644 --- a/third_party/WebKit/Source/core/inspector/WorkerInspectorController.cpp +++ b/third_party/WebKit/Source/core/inspector/WorkerInspectorController.cpp @@ -74,7 +74,7 @@ void WorkerInspectorController::connectFrontend() return; // sessionId will be overwritten by WebDevToolsAgent::sendProtocolNotifications call. - m_session = new InspectorSession(this, 0, true /* autoFlush */); + m_session = new InspectorSession(this, nullptr, 0, true /* autoFlush */); m_v8Session = m_debugger->debugger()->connect(m_debugger->contextGroupId()); m_session->append(WorkerRuntimeAgent::create(m_v8Session->runtimeAgent(), m_workerGlobalScope, this)); @@ -87,7 +87,7 @@ void WorkerInspectorController::connectFrontend() m_v8Session->runtimeAgent()->setClearConsoleCallback(bind<>(&InspectorConsoleAgent::clearAllMessages, workerConsoleAgent)); m_instrumentingSessions->add(m_session); - m_session->attach(nullptr); + m_session->attach(m_v8Session.get(), nullptr); } void WorkerInspectorController::disconnectFrontend() diff --git a/third_party/WebKit/Source/platform/blink_platform.gypi b/third_party/WebKit/Source/platform/blink_platform.gypi index 2b9c1ebf35e2a4..720025fb467789 100644 --- a/third_party/WebKit/Source/platform/blink_platform.gypi +++ b/third_party/WebKit/Source/platform/blink_platform.gypi @@ -1093,6 +1093,7 @@ 'v8_inspector/public/V8DebuggerClient.h', 'v8_inspector/public/V8HeapProfilerAgent.h', 'v8_inspector/public/V8InspectorSession.h', + 'v8_inspector/public/V8InspectorSessionClient.h', 'v8_inspector/public/V8ProfilerAgent.h', 'v8_inspector/public/V8RuntimeAgent.h', 'v8_inspector/public/V8StackTrace.h', diff --git a/third_party/WebKit/Source/platform/v8_inspector/V8DebuggerAgentImpl.cpp b/third_party/WebKit/Source/platform/v8_inspector/V8DebuggerAgentImpl.cpp index dcbbdfa534d5ed..3c1e254e715476 100644 --- a/third_party/WebKit/Source/platform/v8_inspector/V8DebuggerAgentImpl.cpp +++ b/third_party/WebKit/Source/platform/v8_inspector/V8DebuggerAgentImpl.cpp @@ -204,6 +204,7 @@ void V8DebuggerAgentImpl::enable() // FIXME(WK44513): breakpoints activated flag should be synchronized between all front-ends debugger().setBreakpointsActivated(true); + m_session->changeInstrumentationCounter(+1); } bool V8DebuggerAgentImpl::enabled() @@ -225,6 +226,7 @@ void V8DebuggerAgentImpl::disable(ErrorString*) { if (!enabled()) return; + m_session->changeInstrumentationCounter(-1); m_state->setObject(DebuggerAgentState::javaScriptBreakpoints, protocol::DictionaryValue::create()); m_state->setNumber(DebuggerAgentState::pauseOnExceptionsState, V8DebuggerImpl::DontPauseOnExceptions); diff --git a/third_party/WebKit/Source/platform/v8_inspector/V8InspectorSessionImpl.cpp b/third_party/WebKit/Source/platform/v8_inspector/V8InspectorSessionImpl.cpp index 8856807ec7da28..91217f4052d867 100644 --- a/third_party/WebKit/Source/platform/v8_inspector/V8InspectorSessionImpl.cpp +++ b/third_party/WebKit/Source/platform/v8_inspector/V8InspectorSessionImpl.cpp @@ -26,8 +26,10 @@ PassOwnPtr V8InspectorSessionImpl::create(V8DebuggerImpl V8InspectorSessionImpl::V8InspectorSessionImpl(V8DebuggerImpl* debugger, int contextGroupId) : m_contextGroupId(contextGroupId) , m_debugger(debugger) + , m_client(nullptr) , m_injectedScriptHost(InjectedScriptHost::create(debugger, this)) , m_customObjectFormatterEnabled(false) + , m_instrumentationCounter(0) , m_runtimeAgent(adoptPtr(new V8RuntimeAgentImpl(this))) , m_debuggerAgent(adoptPtr(new V8DebuggerAgentImpl(this))) , m_heapProfilerAgent(adoptPtr(new V8HeapProfilerAgentImpl(this))) @@ -62,6 +64,11 @@ V8RuntimeAgent* V8InspectorSessionImpl::runtimeAgent() return m_runtimeAgent.get(); } +void V8InspectorSessionImpl::setClient(V8InspectorSessionClient* client) +{ + m_client = client; +} + void V8InspectorSessionImpl::reset() { m_debuggerAgent->reset(); @@ -163,4 +170,14 @@ void V8InspectorSessionImpl::reportAllContexts(V8RuntimeAgentImpl* agent) agent->reportExecutionContextCreated(idContext.second); } +void V8InspectorSessionImpl::changeInstrumentationCounter(int delta) +{ + ASSERT(m_instrumentationCounter + delta >= 0); + if (!m_instrumentationCounter && m_client) + m_client->startInstrumenting(); + m_instrumentationCounter += delta; + if (!m_instrumentationCounter && m_client) + m_client->stopInstrumenting(); +} + } // namespace blink diff --git a/third_party/WebKit/Source/platform/v8_inspector/V8InspectorSessionImpl.h b/third_party/WebKit/Source/platform/v8_inspector/V8InspectorSessionImpl.h index e978afe983993d..ca06bc097c7301 100644 --- a/third_party/WebKit/Source/platform/v8_inspector/V8InspectorSessionImpl.h +++ b/third_party/WebKit/Source/platform/v8_inspector/V8InspectorSessionImpl.h @@ -10,6 +10,7 @@ #include "platform/inspector_protocol/String16.h" #include "platform/inspector_protocol/TypeBuilder.h" #include "platform/v8_inspector/public/V8InspectorSession.h" +#include "platform/v8_inspector/public/V8InspectorSessionClient.h" #include "platform/v8_inspector/public/V8RuntimeAgent.h" #include "wtf/PassOwnPtr.h" @@ -33,6 +34,7 @@ class V8InspectorSessionImpl : public V8InspectorSession { ~V8InspectorSessionImpl(); V8DebuggerImpl* debugger() const { return m_debugger; } + V8InspectorSessionClient* client() const { return m_client; } V8DebuggerAgentImpl* debuggerAgentImpl() { return m_debuggerAgent.get(); } V8ProfilerAgentImpl* profilerAgentImpl() { return m_profilerAgent.get(); } V8RuntimeAgentImpl* runtimeAgentImpl() { return m_runtimeAgent.get(); } @@ -46,8 +48,10 @@ class V8InspectorSessionImpl : public V8InspectorSession { void addInspectedObject(PassOwnPtr); void releaseObjectGroup(const String16& objectGroup); void setCustomObjectFormatterEnabled(bool); + void changeInstrumentationCounter(int delta); // V8InspectorSession implementation. + void setClient(V8InspectorSessionClient*) override; V8DebuggerAgent* debuggerAgent() override; V8HeapProfilerAgent* heapProfilerAgent() override; V8ProfilerAgent* profilerAgent() override; @@ -61,8 +65,10 @@ class V8InspectorSessionImpl : public V8InspectorSession { int m_contextGroupId; V8DebuggerImpl* m_debugger; + V8InspectorSessionClient* m_client; OwnPtr m_injectedScriptHost; bool m_customObjectFormatterEnabled; + int m_instrumentationCounter; OwnPtr m_runtimeAgent; OwnPtr m_debuggerAgent; diff --git a/third_party/WebKit/Source/platform/v8_inspector/V8ProfilerAgentImpl.cpp b/third_party/WebKit/Source/platform/v8_inspector/V8ProfilerAgentImpl.cpp index c1604f8fb8a85f..631d080844c2fc 100644 --- a/third_party/WebKit/Source/platform/v8_inspector/V8ProfilerAgentImpl.cpp +++ b/third_party/WebKit/Source/platform/v8_inspector/V8ProfilerAgentImpl.cpp @@ -121,8 +121,8 @@ class V8ProfilerAgentImpl::ProfileDescriptor { }; V8ProfilerAgentImpl::V8ProfilerAgentImpl(V8InspectorSessionImpl* session) - : m_debugger(session->debugger()) - , m_isolate(m_debugger->isolate()) + : m_session(session) + , m_isolate(m_session->debugger()->isolate()) , m_state(nullptr) , m_frontend(nullptr) , m_enabled(false) @@ -136,16 +136,20 @@ V8ProfilerAgentImpl::~V8ProfilerAgentImpl() void V8ProfilerAgentImpl::consoleProfile(const String16& title) { - ASSERT(m_frontend && m_enabled); + if (!m_enabled) + return; + ASSERT(m_frontend); String16 id = nextProfileId(); m_startedProfiles.append(ProfileDescriptor(id, title)); startProfiling(id); - m_frontend->consoleProfileStarted(id, currentDebugLocation(m_debugger), title); + m_frontend->consoleProfileStarted(id, currentDebugLocation(m_session->debugger()), title); } void V8ProfilerAgentImpl::consoleProfileEnd(const String16& title) { - ASSERT(m_frontend && m_enabled); + if (!m_enabled) + return; + ASSERT(m_frontend); String16 id; String16 resolvedTitle; // Take last started profile if no title was passed. @@ -170,17 +174,23 @@ void V8ProfilerAgentImpl::consoleProfileEnd(const String16& title) OwnPtr profile = stopProfiling(id, true); if (!profile) return; - OwnPtr location = currentDebugLocation(m_debugger); + OwnPtr location = currentDebugLocation(m_session->debugger()); m_frontend->consoleProfileFinished(id, location.release(), profile.release(), resolvedTitle); } void V8ProfilerAgentImpl::enable(ErrorString*) { + if (m_enabled) + return; m_enabled = true; + m_session->changeInstrumentationCounter(+1); } void V8ProfilerAgentImpl::disable(ErrorString* errorString) { + if (!m_enabled) + return; + m_session->changeInstrumentationCounter(-1); for (size_t i = m_startedProfiles.size(); i > 0; --i) stopProfiling(m_startedProfiles[i - 1].m_id, false); m_startedProfiles.clear(); @@ -208,7 +218,9 @@ void V8ProfilerAgentImpl::clearFrontend() void V8ProfilerAgentImpl::restore() { + ASSERT(!m_enabled); m_enabled = true; + m_session->changeInstrumentationCounter(+1); int interval = 0; m_state->getNumber(ProfilerAgentState::samplingInterval, &interval); if (interval) diff --git a/third_party/WebKit/Source/platform/v8_inspector/V8ProfilerAgentImpl.h b/third_party/WebKit/Source/platform/v8_inspector/V8ProfilerAgentImpl.h index 612621b08b6b9f..e5f98c486623bf 100644 --- a/third_party/WebKit/Source/platform/v8_inspector/V8ProfilerAgentImpl.h +++ b/third_party/WebKit/Source/platform/v8_inspector/V8ProfilerAgentImpl.h @@ -16,7 +16,6 @@ class Isolate; namespace blink { -class V8DebuggerImpl; class V8InspectorSessionImpl; class V8ProfilerAgentImpl : public V8ProfilerAgent { @@ -52,7 +51,7 @@ class V8ProfilerAgentImpl : public V8ProfilerAgent { bool isRecording() const; - V8DebuggerImpl* m_debugger; + V8InspectorSessionImpl* m_session; v8::Isolate* m_isolate; protocol::DictionaryValue* m_state; protocol::Frontend::Profiler* m_frontend; diff --git a/third_party/WebKit/Source/platform/v8_inspector/V8RuntimeAgentImpl.cpp b/third_party/WebKit/Source/platform/v8_inspector/V8RuntimeAgentImpl.cpp index fe244fa8d89aed..03d016f4f42daa 100644 --- a/third_party/WebKit/Source/platform/v8_inspector/V8RuntimeAgentImpl.cpp +++ b/third_party/WebKit/Source/platform/v8_inspector/V8RuntimeAgentImpl.cpp @@ -365,6 +365,9 @@ void V8RuntimeAgentImpl::restore() void V8RuntimeAgentImpl::enable(ErrorString* errorString) { + if (m_enabled) + return; + m_session->changeInstrumentationCounter(+1); m_enabled = true; v8::HandleScope handles(m_debugger->isolate()); m_session->reportAllContexts(this); @@ -377,6 +380,7 @@ void V8RuntimeAgentImpl::disable(ErrorString* errorString) m_enabled = false; m_session->discardInjectedScripts(); reset(); + m_session->changeInstrumentationCounter(-1); } void V8RuntimeAgentImpl::setClearConsoleCallback(PassOwnPtr callback) diff --git a/third_party/WebKit/Source/platform/v8_inspector/public/V8InspectorSession.h b/third_party/WebKit/Source/platform/v8_inspector/public/V8InspectorSession.h index d8befe1463d5a9..88fcab1c076ef4 100644 --- a/third_party/WebKit/Source/platform/v8_inspector/public/V8InspectorSession.h +++ b/third_party/WebKit/Source/platform/v8_inspector/public/V8InspectorSession.h @@ -12,6 +12,7 @@ namespace blink { class V8DebuggerAgent; class V8HeapProfilerAgent; +class V8InspectorSessionClient; class V8ProfilerAgent; class V8RuntimeAgent; @@ -19,6 +20,8 @@ class PLATFORM_EXPORT V8InspectorSession { public: virtual ~V8InspectorSession() { } + virtual void setClient(V8InspectorSessionClient*) = 0; + virtual V8DebuggerAgent* debuggerAgent() = 0; virtual V8HeapProfilerAgent* heapProfilerAgent() = 0; virtual V8ProfilerAgent* profilerAgent() = 0; diff --git a/third_party/WebKit/Source/platform/v8_inspector/public/V8InspectorSessionClient.h b/third_party/WebKit/Source/platform/v8_inspector/public/V8InspectorSessionClient.h new file mode 100644 index 00000000000000..bb5beec6096bc6 --- /dev/null +++ b/third_party/WebKit/Source/platform/v8_inspector/public/V8InspectorSessionClient.h @@ -0,0 +1,24 @@ +// Copyright 2016 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef V8InspectorSessionClient_h +#define V8InspectorSessionClient_h + +#include "platform/PlatformExport.h" + +#include + +namespace blink { + +class PLATFORM_EXPORT V8InspectorSessionClient { +public: + virtual ~V8InspectorSessionClient() { } + virtual void startInstrumenting() = 0; + virtual void stopInstrumenting() = 0; +}; + +} // namespace blink + + +#endif // V8InspectorSessionClient_h diff --git a/third_party/WebKit/Source/web/WebDevToolsAgentImpl.cpp b/third_party/WebKit/Source/web/WebDevToolsAgentImpl.cpp index 4883ec22f72c34..ed36971a126ca0 100644 --- a/third_party/WebKit/Source/web/WebDevToolsAgentImpl.cpp +++ b/third_party/WebKit/Source/web/WebDevToolsAgentImpl.cpp @@ -377,7 +377,7 @@ void WebDevToolsAgentImpl::willBeDestroyed() void WebDevToolsAgentImpl::initializeSession(int sessionId, const String& hostId) { - m_session = new InspectorSession(this, sessionId, false /* autoFlush */); + m_session = new InspectorSession(this, m_inspectedFrames.get(), sessionId, false /* autoFlush */); ClientMessageLoopAdapter::ensureMainThreadDebuggerCreated(m_client); MainThreadDebugger* mainThreadDebugger = MainThreadDebugger::instance(); @@ -488,7 +488,7 @@ void WebDevToolsAgentImpl::attach(const WebString& hostId, int sessionId) if (attached()) return; initializeSession(sessionId, hostId); - m_session->attach(nullptr); + m_session->attach(m_v8Session.get(), nullptr); } void WebDevToolsAgentImpl::reattach(const WebString& hostId, int sessionId, const WebString& savedState) @@ -497,7 +497,7 @@ void WebDevToolsAgentImpl::reattach(const WebString& hostId, int sessionId, cons return; initializeSession(sessionId, hostId); String state = savedState; - m_session->attach(&state); + m_session->attach(m_v8Session.get(), &state); } void WebDevToolsAgentImpl::detach() @@ -654,20 +654,14 @@ void WebDevToolsAgentImpl::willProcessTask() { if (!attached()) return; - for (InspectorSession* session : *m_instrumentingSessions) { - if (InspectorProfilerAgent* profilerAgent = session->instrumentingAgents()->inspectorProfilerAgent()) - profilerAgent->willProcessTask(); - } + InspectorInstrumentation::willProcessTask(m_inspectedFrames->root()); } void WebDevToolsAgentImpl::didProcessTask() { if (!attached()) return; - for (InspectorSession* session : *m_instrumentingSessions) { - if (InspectorProfilerAgent* profilerAgent = session->instrumentingAgents()->inspectorProfilerAgent()) - profilerAgent->didProcessTask(); - } + InspectorInstrumentation::didProcessTask(m_inspectedFrames->root()); flushPendingProtocolNotifications(); }