Commit 8d00b5cf authored by dgozman's avatar dgozman Committed by Commit bot

[DevTools] Introduce InspectorSession.

Session manages agents list, does bookkeeping and handles messages.
Session only exists while client is attached.
There will be one session per client in multi-client scenario.

Simplified InspectorAgent interface along the way.

BUG=590878

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

Cr-Commit-Position: refs/heads/master@{#388569}
parent f6f80667
...@@ -1814,7 +1814,7 @@ ...@@ -1814,7 +1814,7 @@
'inspector/InspectorAnimationAgent.h', 'inspector/InspectorAnimationAgent.h',
'inspector/InspectorApplicationCacheAgent.cpp', 'inspector/InspectorApplicationCacheAgent.cpp',
'inspector/InspectorApplicationCacheAgent.h', 'inspector/InspectorApplicationCacheAgent.h',
'inspector/InspectorBaseAgent.cpp', 'inspector/InspectorBaseAgent.h',
'inspector/InspectorCSSAgent.cpp', 'inspector/InspectorCSSAgent.cpp',
'inspector/InspectorCSSAgent.h', 'inspector/InspectorCSSAgent.h',
'inspector/InspectorConsoleAgent.cpp', 'inspector/InspectorConsoleAgent.cpp',
...@@ -1854,6 +1854,8 @@ ...@@ -1854,6 +1854,8 @@
'inspector/InspectorResourceContentLoader.h', 'inspector/InspectorResourceContentLoader.h',
'inspector/InspectorRuntimeAgent.cpp', 'inspector/InspectorRuntimeAgent.cpp',
'inspector/InspectorRuntimeAgent.h', 'inspector/InspectorRuntimeAgent.h',
'inspector/InspectorSession.cpp',
'inspector/InspectorSession.h',
'inspector/InspectorStyleSheet.cpp', 'inspector/InspectorStyleSheet.cpp',
'inspector/InspectorStyleSheet.h', 'inspector/InspectorStyleSheet.h',
'inspector/InspectorTaskRunner.cpp', 'inspector/InspectorTaskRunner.cpp',
......
/*
* Copyright (C) 2011 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "core/inspector/InspectorBaseAgent.h"
#include "platform/inspector_protocol/Parser.h"
#include "wtf/PassOwnPtr.h"
namespace blink {
InspectorAgent::InspectorAgent(const String& name)
: m_name(name)
{
}
InspectorAgent::~InspectorAgent()
{
}
DEFINE_TRACE(InspectorAgent)
{
visitor->trace(m_instrumentingAgents);
}
void InspectorAgent::appended(InstrumentingAgents* instrumentingAgents)
{
m_instrumentingAgents = instrumentingAgents;
init();
}
void InspectorAgent::setState(protocol::DictionaryValue* state)
{
m_state = state;
}
InspectorAgentRegistry::InspectorAgentRegistry(InstrumentingAgents* instrumentingAgents)
: m_instrumentingAgents(instrumentingAgents)
, m_state(protocol::DictionaryValue::create())
{
}
void InspectorAgentRegistry::append(InspectorAgent* agent)
{
ASSERT(!m_state->get(agent->name()));
OwnPtr<protocol::DictionaryValue> agentState = protocol::DictionaryValue::create();
agent->setState(agentState.get());
m_state->setObject(agent->name(), agentState.release());
agent->appended(m_instrumentingAgents);
m_agents.append(agent);
}
void InspectorAgentRegistry::setFrontend(protocol::Frontend* frontend)
{
for (size_t i = 0; i < m_agents.size(); i++)
m_agents[i]->setFrontend(frontend);
}
void InspectorAgentRegistry::clearFrontend()
{
for (size_t i = 0; i < m_agents.size(); i++)
m_agents[i]->clearFrontend();
}
void InspectorAgentRegistry::restore(const String& savedState)
{
OwnPtr<protocol::Value> state = protocol::parseJSON(savedState);
if (state)
m_state = protocol::DictionaryValue::cast(state.release());
if (!m_state)
m_state = protocol::DictionaryValue::create();
for (size_t i = 0; i < m_agents.size(); i++) {
protocol::DictionaryValue* agentState = m_state->getObject(m_agents[i]->name());
if (!agentState) {
OwnPtr<protocol::DictionaryValue> newState = protocol::DictionaryValue::create();
agentState = newState.get();
m_state->setObject(m_agents[i]->name(), newState.release());
}
m_agents[i]->setState(agentState);
}
for (size_t i = 0; i < m_agents.size(); i++)
m_agents[i]->restore();
}
String InspectorAgentRegistry::state()
{
return m_state->toJSONString();
}
void InspectorAgentRegistry::registerInDispatcher(protocol::Dispatcher* dispatcher)
{
for (size_t i = 0; i < m_agents.size(); i++)
m_agents[i]->registerInDispatcher(dispatcher);
}
void InspectorAgentRegistry::discardAgents()
{
for (size_t i = m_agents.size(); i > 0; i--)
m_agents[i - 1]->discardAgent();
m_agents.clear();
m_state = protocol::DictionaryValue::create();
}
void InspectorAgentRegistry::flushPendingProtocolNotifications()
{
for (size_t i = 0; i < m_agents.size(); i++)
m_agents[i]->flushPendingProtocolNotifications();
}
DEFINE_TRACE(InspectorAgentRegistry)
{
visitor->trace(m_instrumentingAgents);
visitor->trace(m_agents);
}
void InspectorAgentRegistry::didCommitLoadForLocalFrame(LocalFrame* frame)
{
for (size_t i = 0; i < m_agents.size(); i++)
m_agents[i]->didCommitLoadForLocalFrame(frame);
}
} // namespace blink
...@@ -40,67 +40,28 @@ ...@@ -40,67 +40,28 @@
#include "platform/inspector_protocol/TypeBuilder.h" #include "platform/inspector_protocol/TypeBuilder.h"
#include "platform/inspector_protocol/Values.h" #include "platform/inspector_protocol/Values.h"
#include "wtf/Forward.h" #include "wtf/Forward.h"
#include "wtf/Vector.h"
#include "wtf/text/WTFString.h" #include "wtf/text/WTFString.h"
namespace blink { namespace blink {
class Frontend;
class InstrumentingAgents;
class LocalFrame; class LocalFrame;
using protocol::Maybe; using protocol::Maybe;
class CORE_EXPORT InspectorAgent : public GarbageCollectedFinalized<InspectorAgent> { class CORE_EXPORT InspectorAgent : public GarbageCollectedFinalized<InspectorAgent> {
public: public:
explicit InspectorAgent(const String&); InspectorAgent() { }
virtual ~InspectorAgent(); virtual ~InspectorAgent() { }
DECLARE_VIRTUAL_TRACE(); DEFINE_INLINE_VIRTUAL_TRACE() { }
virtual void init() { }
virtual void setFrontend(protocol::Frontend*) = 0;
virtual void clearFrontend() = 0;
virtual void disable(ErrorString*) { } virtual void disable(ErrorString*) { }
virtual void restore() { } virtual void restore() { }
virtual void registerInDispatcher(protocol::Dispatcher*) = 0;
virtual void discardAgent() { } virtual void discardAgent() { }
virtual void didCommitLoadForLocalFrame(LocalFrame*) { } virtual void didCommitLoadForLocalFrame(LocalFrame*) { }
virtual void flushPendingProtocolNotifications() { } virtual void flushPendingProtocolNotifications() { }
virtual void setState(protocol::DictionaryValue*);
String name() const { return m_name; } virtual void init(InstrumentingAgents*, protocol::Frontend*, protocol::Dispatcher*, protocol::DictionaryValue*) = 0;
void appended(InstrumentingAgents*); virtual void dispose() = 0;
protected:
Member<InstrumentingAgents> m_instrumentingAgents;
protocol::DictionaryValue* m_state;
private:
String m_name;
};
class CORE_EXPORT InspectorAgentRegistry final {
DISALLOW_NEW();
WTF_MAKE_NONCOPYABLE(InspectorAgentRegistry);
public:
explicit InspectorAgentRegistry(InstrumentingAgents*);
void append(InspectorAgent*);
void setFrontend(protocol::Frontend*);
void clearFrontend();
void restore(const String& savedState);
void registerInDispatcher(protocol::Dispatcher*);
void discardAgents();
void flushPendingProtocolNotifications();
void didCommitLoadForLocalFrame(LocalFrame*);
String state();
DECLARE_TRACE();
private:
Member<InstrumentingAgents> m_instrumentingAgents;
OwnPtr<protocol::DictionaryValue> m_state;
HeapVector<Member<InspectorAgent>> m_agents;
}; };
template<typename AgentClass, typename FrontendClass> template<typename AgentClass, typename FrontendClass>
...@@ -108,43 +69,53 @@ class InspectorBaseAgent : public InspectorAgent { ...@@ -108,43 +69,53 @@ class InspectorBaseAgent : public InspectorAgent {
public: public:
~InspectorBaseAgent() override { } ~InspectorBaseAgent() override { }
void setFrontend(protocol::Frontend* frontend) override void init(InstrumentingAgents* instrumentingAgents, protocol::Frontend* frontend, protocol::Dispatcher* dispatcher, protocol::DictionaryValue* state) override
{ {
ASSERT(!m_frontend); m_instrumentingAgents = instrumentingAgents;
m_frontend = FrontendClass::from(frontend); m_frontend = FrontendClass::from(frontend);
dispatcher->registerAgent(static_cast<AgentClass*>(this));
m_state = state->getObject(m_name);
if (!m_state) {
OwnPtr<protocol::DictionaryValue> newState = protocol::DictionaryValue::create();
m_state = newState.get();
state->setObject(m_name, newState.release());
}
} }
void clearFrontend() override void dispose() override
{ {
ErrorString error; ErrorString error;
disable(&error); disable(&error);
ASSERT(m_frontend);
m_frontend = nullptr; m_frontend = nullptr;
m_state = nullptr;
m_instrumentingAgents = nullptr;
discardAgent();
} }
void registerInDispatcher(protocol::Dispatcher* dispatcher) final DEFINE_INLINE_VIRTUAL_TRACE()
{ {
dispatcher->registerAgent(static_cast<AgentClass*>(this)); visitor->trace(m_instrumentingAgents);
InspectorAgent::trace(visitor);
} }
protected: protected:
explicit InspectorBaseAgent(const String& name) explicit InspectorBaseAgent(const String& name)
: InspectorAgent(name) : InspectorAgent()
, m_name(name)
, m_frontend(nullptr) , m_frontend(nullptr)
{ {
} }
FrontendClass* frontend() const { return m_frontend; } FrontendClass* frontend() const { return m_frontend; }
Member<InstrumentingAgents> m_instrumentingAgents;
protocol::DictionaryValue* m_state;
private: private:
String m_name;
FrontendClass* m_frontend; FrontendClass* m_frontend;
}; };
inline bool asBool(const bool* const b)
{
return b ? *b : false;
}
} // namespace blink } // namespace blink
#endif // !defined(InspectorBaseAgent_h) #endif // !defined(InspectorBaseAgent_h)
...@@ -304,22 +304,17 @@ void InspectorDebuggerAgent::asyncTaskFinished(void* task) ...@@ -304,22 +304,17 @@ void InspectorDebuggerAgent::asyncTaskFinished(void* task)
} }
// InspectorBaseAgent overrides. // InspectorBaseAgent overrides.
void InspectorDebuggerAgent::setState(protocol::DictionaryValue* state) void InspectorDebuggerAgent::init(InstrumentingAgents* instrumentingAgents, protocol::Frontend* baseFrontend, protocol::Dispatcher* dispatcher, protocol::DictionaryValue* state)
{ {
InspectorBaseAgent::setState(state); InspectorBaseAgent::init(instrumentingAgents, baseFrontend, dispatcher, state);
m_v8DebuggerAgent->setInspectorState(m_state); m_v8DebuggerAgent->setInspectorState(m_state);
m_v8DebuggerAgent->setFrontend(frontend());
} }
void InspectorDebuggerAgent::setFrontend(protocol::Frontend* frontend) void InspectorDebuggerAgent::dispose()
{
InspectorBaseAgent::setFrontend(frontend);
m_v8DebuggerAgent->setFrontend(protocol::Frontend::Debugger::from(frontend));
}
void InspectorDebuggerAgent::clearFrontend()
{ {
m_v8DebuggerAgent->clearFrontend(); m_v8DebuggerAgent->clearFrontend();
InspectorBaseAgent::clearFrontend(); InspectorBaseAgent::dispose();
} }
void InspectorDebuggerAgent::restore() void InspectorDebuggerAgent::restore()
......
...@@ -90,9 +90,8 @@ public: ...@@ -90,9 +90,8 @@ public:
void asyncTaskFinished(void* task); void asyncTaskFinished(void* task);
// InspectorBaseAgent overrides. // InspectorBaseAgent overrides.
void setState(protocol::DictionaryValue*) override; void init(InstrumentingAgents*, protocol::Frontend*, protocol::Dispatcher*, protocol::DictionaryValue*) override;
void setFrontend(protocol::Frontend*) override; void dispose() override;
void clearFrontend() override;
void restore() override; void restore() override;
V8DebuggerAgent* v8Agent() const { return m_v8DebuggerAgent; } V8DebuggerAgent* v8Agent() const { return m_v8DebuggerAgent; }
......
...@@ -89,22 +89,17 @@ InspectorHeapProfilerAgent::~InspectorHeapProfilerAgent() ...@@ -89,22 +89,17 @@ InspectorHeapProfilerAgent::~InspectorHeapProfilerAgent()
} }
// InspectorBaseAgent overrides. // InspectorBaseAgent overrides.
void InspectorHeapProfilerAgent::setState(protocol::DictionaryValue* state) void InspectorHeapProfilerAgent::init(InstrumentingAgents* instrumentingAgents, protocol::Frontend* baseFrontend, protocol::Dispatcher* dispatcher, protocol::DictionaryValue* state)
{ {
InspectorBaseAgent::setState(state); InspectorBaseAgent::init(instrumentingAgents, baseFrontend, dispatcher, state);
m_v8HeapProfilerAgent->setInspectorState(m_state); m_v8HeapProfilerAgent->setInspectorState(m_state);
m_v8HeapProfilerAgent->setFrontend(frontend());
} }
void InspectorHeapProfilerAgent::setFrontend(protocol::Frontend* frontend) void InspectorHeapProfilerAgent::dispose()
{
InspectorBaseAgent::setFrontend(frontend);
m_v8HeapProfilerAgent->setFrontend(protocol::Frontend::HeapProfiler::from(frontend));
}
void InspectorHeapProfilerAgent::clearFrontend()
{ {
m_v8HeapProfilerAgent->clearFrontend(); m_v8HeapProfilerAgent->clearFrontend();
InspectorBaseAgent::clearFrontend(); InspectorBaseAgent::dispose();
} }
void InspectorHeapProfilerAgent::restore() void InspectorHeapProfilerAgent::restore()
......
...@@ -53,9 +53,8 @@ public: ...@@ -53,9 +53,8 @@ public:
~InspectorHeapProfilerAgent() override; ~InspectorHeapProfilerAgent() override;
// InspectorBaseAgent overrides. // InspectorBaseAgent overrides.
void setState(protocol::DictionaryValue*) override; void init(InstrumentingAgents*, protocol::Frontend*, protocol::Dispatcher*, protocol::DictionaryValue*) override;
void setFrontend(protocol::Frontend*) override; void dispose() override;
void clearFrontend() override;
void restore() override; void restore() override;
void enable(ErrorString*) override; void enable(ErrorString*) override;
......
...@@ -58,22 +58,17 @@ InspectorProfilerAgent::~InspectorProfilerAgent() ...@@ -58,22 +58,17 @@ InspectorProfilerAgent::~InspectorProfilerAgent()
} }
// InspectorBaseAgent overrides. // InspectorBaseAgent overrides.
void InspectorProfilerAgent::setState(protocol::DictionaryValue* state) void InspectorProfilerAgent::init(InstrumentingAgents* instrumentingAgents, protocol::Frontend* baseFrontend, protocol::Dispatcher* dispatcher, protocol::DictionaryValue* state)
{ {
InspectorBaseAgent::setState(state); InspectorBaseAgent::init(instrumentingAgents, baseFrontend, dispatcher, state);
m_v8ProfilerAgent->setInspectorState(m_state); m_v8ProfilerAgent->setInspectorState(m_state);
m_v8ProfilerAgent->setFrontend(frontend());
} }
void InspectorProfilerAgent::setFrontend(protocol::Frontend* frontend) void InspectorProfilerAgent::dispose()
{
InspectorBaseAgent::setFrontend(frontend);
m_v8ProfilerAgent->setFrontend(protocol::Frontend::Profiler::from(frontend));
}
void InspectorProfilerAgent::clearFrontend()
{ {
m_v8ProfilerAgent->clearFrontend(); m_v8ProfilerAgent->clearFrontend();
InspectorBaseAgent::clearFrontend(); InspectorBaseAgent::dispose();
} }
void InspectorProfilerAgent::restore() void InspectorProfilerAgent::restore()
......
...@@ -58,9 +58,8 @@ public: ...@@ -58,9 +58,8 @@ public:
DECLARE_VIRTUAL_TRACE(); DECLARE_VIRTUAL_TRACE();
// InspectorBaseAgent overrides. // InspectorBaseAgent overrides.
void setState(protocol::DictionaryValue*) override; void init(InstrumentingAgents*, protocol::Frontend*, protocol::Dispatcher*, protocol::DictionaryValue*) override;
void setFrontend(protocol::Frontend*) override; void dispose() override;
void clearFrontend() override;
void restore() override; void restore() override;
void consoleProfile(ExecutionContext*, const String16& title); void consoleProfile(ExecutionContext*, const String16& title);
......
...@@ -57,22 +57,17 @@ InspectorRuntimeAgent::~InspectorRuntimeAgent() ...@@ -57,22 +57,17 @@ InspectorRuntimeAgent::~InspectorRuntimeAgent()
} }
// InspectorBaseAgent overrides. // InspectorBaseAgent overrides.
void InspectorRuntimeAgent::setState(protocol::DictionaryValue* state) void InspectorRuntimeAgent::init(InstrumentingAgents* instrumentingAgents, protocol::Frontend* baseFrontend, protocol::Dispatcher* dispatcher, protocol::DictionaryValue* state)
{ {
InspectorBaseAgent::setState(state); InspectorBaseAgent::init(instrumentingAgents, baseFrontend, dispatcher, state);
m_v8RuntimeAgent->setInspectorState(m_state); m_v8RuntimeAgent->setInspectorState(m_state);
m_v8RuntimeAgent->setFrontend(frontend());
} }
void InspectorRuntimeAgent::setFrontend(protocol::Frontend* frontend) void InspectorRuntimeAgent::dispose()
{
InspectorBaseAgent::setFrontend(frontend);
m_v8RuntimeAgent->setFrontend(protocol::Frontend::Runtime::from(frontend));
}
void InspectorRuntimeAgent::clearFrontend()
{ {
m_v8RuntimeAgent->clearFrontend(); m_v8RuntimeAgent->clearFrontend();
InspectorBaseAgent::clearFrontend(); InspectorBaseAgent::dispose();
} }
void InspectorRuntimeAgent::restore() void InspectorRuntimeAgent::restore()
......
...@@ -64,9 +64,8 @@ public: ...@@ -64,9 +64,8 @@ public:
~InspectorRuntimeAgent() override; ~InspectorRuntimeAgent() override;
// InspectorBaseAgent overrides. // InspectorBaseAgent overrides.
void setState(protocol::DictionaryValue*) override; void init(InstrumentingAgents*, protocol::Frontend*, protocol::Dispatcher*, protocol::DictionaryValue*) override;
void setFrontend(protocol::Frontend*) override; void dispose() override;
void clearFrontend() override;
void restore() override; void restore() override;
// Part of the protocol. // Part of the protocol.
......
// 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.
#include "core/inspector/InspectorSession.h"
#include "core/inspector/InspectorBaseAgent.h"
#include "core/inspector/InspectorInstrumentation.h"
#include "platform/inspector_protocol/Backend.h"
#include "platform/inspector_protocol/Dispatcher.h"
#include "platform/inspector_protocol/Frontend.h"
#include "platform/inspector_protocol/Parser.h"
#include "platform/inspector_protocol/TypeBuilder.h"
namespace blink {
InspectorSession::InspectorSession(Client* client, int sessionId, InstrumentingAgents* instrumentingAgents, bool autoFlush)
: m_client(client)
, m_sessionId(sessionId)
, m_autoFlush(autoFlush)
, m_attached(false)
, m_instrumentingAgents(instrumentingAgents)
, m_inspectorFrontend(adoptPtr(new protocol::Frontend(this)))
, m_inspectorBackendDispatcher(protocol::Dispatcher::create(this))
{
}
void InspectorSession::append(InspectorAgent* agent)
{
m_agents.append(agent);
}
void InspectorSession::attach(const String* savedState)
{
ASSERT(!m_attached);
m_attached = true;
InspectorInstrumentation::frontendCreated();
bool restore = savedState;
if (restore) {
OwnPtr<protocol::Value> state = protocol::parseJSON(*savedState);
if (state)
m_state = protocol::DictionaryValue::cast(state.release());
if (!m_state)
m_state = protocol::DictionaryValue::create();
} else {
m_state = protocol::DictionaryValue::create();
}
for (size_t i = 0; i < m_agents.size(); i++)
m_agents[i]->init(m_instrumentingAgents.get(), m_inspectorFrontend.get(), m_inspectorBackendDispatcher.get(), m_state.get());
if (restore) {
for (size_t i = 0; i < m_agents.size(); i++)
m_agents[i]->restore();
}
}
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_instrumentingAgents->reset();
InspectorInstrumentation::frontendDeleted();
}
void InspectorSession::dispatchProtocolMessage(const String& message)
{
ASSERT(m_attached);
m_inspectorBackendDispatcher->dispatch(m_sessionId, message);
}
void InspectorSession::didCommitLoadForLocalFrame(LocalFrame* frame)
{
for (size_t i = 0; i < m_agents.size(); i++)
m_agents[i]->didCommitLoadForLocalFrame(frame);
}
void InspectorSession::sendProtocolResponse(int sessionId, int callId, PassOwnPtr<protocol::DictionaryValue> message)
{
if (!m_attached)
return;
flush();
String stateToSend = m_state->toJSONString();
if (stateToSend == m_lastSentState)
stateToSend = String();
else
m_lastSentState = stateToSend;
m_client->sendProtocolMessage(m_sessionId, callId, message->toJSONString(), stateToSend);
}
void InspectorSession::sendProtocolNotification(PassOwnPtr<protocol::DictionaryValue> message)
{
if (!m_attached)
return;
if (m_autoFlush)
m_client->sendProtocolMessage(m_sessionId, 0, message->toJSONString(), String());
else
m_notificationQueue.append(message);
}
void InspectorSession::flush()
{
flushPendingProtocolNotifications();
}
void InspectorSession::flushPendingProtocolNotifications()
{
if (m_attached) {
for (size_t i = 0; i < m_agents.size(); i++)
m_agents[i]->flushPendingProtocolNotifications();
for (size_t i = 0; i < m_notificationQueue.size(); ++i)
m_client->sendProtocolMessage(m_sessionId, 0, m_notificationQueue[i]->toJSONString(), String());
}
m_notificationQueue.clear();
}
DEFINE_TRACE(InspectorSession)
{
visitor->trace(m_instrumentingAgents);
visitor->trace(m_agents);
}
} // namespace blink
// 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 InspectorSession_h
#define InspectorSession_h
#include "core/CoreExport.h"
#include "platform/heap/Handle.h"
#include "platform/inspector_protocol/FrontendChannel.h"
#include "platform/inspector_protocol/Values.h"
#include "wtf/Forward.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/Vector.h"
#include "wtf/text/WTFString.h"
namespace blink {
class InspectorAgent;
class InstrumentingAgents;
class LocalFrame;
namespace protocol {
class Dispatcher;
class Frontend;
}
class CORE_EXPORT InspectorSession
: public GarbageCollectedFinalized<InspectorSession>
, WTF_NON_EXPORTED_BASE(public protocol::FrontendChannel) {
WTF_MAKE_NONCOPYABLE(InspectorSession);
public:
class Client {
public:
virtual void sendProtocolMessage(int sessionId, int callId, const String& response, const String& state) = 0;
virtual ~Client() {}
};
InspectorSession(Client*, int sessionId, InstrumentingAgents*, bool autoFlush);
int sessionId() { return m_sessionId; }
void append(InspectorAgent*);
void attach(const String* savedState);
void detach();
void didCommitLoadForLocalFrame(LocalFrame*);
void dispatchProtocolMessage(const String& message);
void flushPendingProtocolNotifications();
DECLARE_TRACE();
private:
// protocol::FrontendChannel implementation.
void sendProtocolResponse(int sessionId, int callId, PassOwnPtr<protocol::DictionaryValue> message) override;
void sendProtocolNotification(PassOwnPtr<protocol::DictionaryValue> message) override;
void flush();
Client* m_client;
int m_sessionId;
bool m_autoFlush;
bool m_attached;
Member<InstrumentingAgents> m_instrumentingAgents;
OwnPtr<protocol::Frontend> m_inspectorFrontend;
OwnPtr<protocol::Dispatcher> m_inspectorBackendDispatcher;
OwnPtr<protocol::DictionaryValue> m_state;
HeapVector<Member<InspectorAgent>> m_agents;
Vector<OwnPtr<protocol::DictionaryValue>> m_notificationQueue;
String m_lastSentState;
};
} // namespace blink
#endif // !defined(InspectorSession_h)
...@@ -62,7 +62,6 @@ WorkerInspectorController::WorkerInspectorController(WorkerGlobalScope* workerGl ...@@ -62,7 +62,6 @@ WorkerInspectorController::WorkerInspectorController(WorkerGlobalScope* workerGl
: m_debugger(debugger) : m_debugger(debugger)
, m_workerGlobalScope(workerGlobalScope) , m_workerGlobalScope(workerGlobalScope)
, m_instrumentingAgents(InstrumentingAgents::create()) , m_instrumentingAgents(InstrumentingAgents::create())
, m_agents(m_instrumentingAgents.get())
{ {
} }
...@@ -70,55 +69,40 @@ WorkerInspectorController::~WorkerInspectorController() ...@@ -70,55 +69,40 @@ WorkerInspectorController::~WorkerInspectorController()
{ {
} }
void WorkerInspectorController::initializeAgents() void WorkerInspectorController::connectFrontend()
{ {
if (m_session)
return;
// sessionId will be overwritten by WebDevToolsAgent::sendProtocolNotifications call.
m_session = new InspectorSession(this, 0, m_instrumentingAgents.get(), true /* autoFlush */);
m_v8Session = m_debugger->debugger()->connect(m_debugger->contextGroupId()); m_v8Session = m_debugger->debugger()->connect(m_debugger->contextGroupId());
m_agents.append(WorkerRuntimeAgent::create(m_v8Session->runtimeAgent(), m_workerGlobalScope, this));
m_agents.append(WorkerDebuggerAgent::create(m_v8Session->debuggerAgent(), m_workerGlobalScope)); m_session->append(WorkerRuntimeAgent::create(m_v8Session->runtimeAgent(), m_workerGlobalScope, this));
m_agents.append(InspectorProfilerAgent::create(m_v8Session->profilerAgent(), nullptr)); m_session->append(WorkerDebuggerAgent::create(m_v8Session->debuggerAgent(), m_workerGlobalScope));
m_agents.append(InspectorHeapProfilerAgent::create(m_workerGlobalScope->thread()->isolate(), m_v8Session->heapProfilerAgent())); m_session->append(InspectorProfilerAgent::create(m_v8Session->profilerAgent(), nullptr));
m_session->append(InspectorHeapProfilerAgent::create(m_workerGlobalScope->thread()->isolate(), m_v8Session->heapProfilerAgent()));
WorkerConsoleAgent* workerConsoleAgent = WorkerConsoleAgent::create(m_v8Session->runtimeAgent(), m_v8Session->debuggerAgent(), m_workerGlobalScope); WorkerConsoleAgent* workerConsoleAgent = WorkerConsoleAgent::create(m_v8Session->runtimeAgent(), m_v8Session->debuggerAgent(), m_workerGlobalScope);
m_agents.append(workerConsoleAgent); m_session->append(workerConsoleAgent);
m_v8Session->runtimeAgent()->setClearConsoleCallback(bind<>(&InspectorConsoleAgent::clearAllMessages, workerConsoleAgent)); m_v8Session->runtimeAgent()->setClearConsoleCallback(bind<>(&InspectorConsoleAgent::clearAllMessages, workerConsoleAgent));
}
void WorkerInspectorController::destroyAgents()
{
m_agents.discardAgents();
m_instrumentingAgents->reset();
m_v8Session.clear();
}
void WorkerInspectorController::connectFrontend() m_session->attach(nullptr);
{
initializeAgents();
ASSERT(!m_frontend);
m_frontend = adoptPtr(new protocol::Frontend(this));
m_backendDispatcher = protocol::Dispatcher::create(this);
m_agents.registerInDispatcher(m_backendDispatcher.get());
m_agents.setFrontend(m_frontend.get());
InspectorInstrumentation::frontendCreated();
} }
void WorkerInspectorController::disconnectFrontend() void WorkerInspectorController::disconnectFrontend()
{ {
if (!m_frontend) if (!m_session)
return; return;
m_backendDispatcher->clearFrontend(); m_session->detach();
m_backendDispatcher.clear(); m_v8Session.clear();
m_agents.clearFrontend(); m_session.clear();
m_frontend.clear();
destroyAgents();
InspectorInstrumentation::frontendDeleted();
} }
void WorkerInspectorController::dispatchMessageFromFrontend(const String& message) void WorkerInspectorController::dispatchMessageFromFrontend(const String& message)
{ {
if (m_backendDispatcher) { if (m_session)
// sessionId will be overwritten by WebDevToolsAgent::sendProtocolNotifications call. m_session->dispatchProtocolMessage(message);
m_backendDispatcher->dispatch(0, message);
}
} }
void WorkerInspectorController::dispose() void WorkerInspectorController::dispose()
...@@ -131,26 +115,17 @@ void WorkerInspectorController::resumeStartup() ...@@ -131,26 +115,17 @@ void WorkerInspectorController::resumeStartup()
m_workerGlobalScope->thread()->stopRunningDebuggerTasksOnPause(); m_workerGlobalScope->thread()->stopRunningDebuggerTasksOnPause();
} }
void WorkerInspectorController::sendProtocolResponse(int sessionId, int callId, PassOwnPtr<protocol::DictionaryValue> message) void WorkerInspectorController::sendProtocolMessage(int sessionId, int callId, const String& response, const String& state)
{
// Worker messages are wrapped, no need to handle callId.
m_workerGlobalScope->thread()->workerReportingProxy().postMessageToPageInspector(message->toJSONString());
}
void WorkerInspectorController::sendProtocolNotification(PassOwnPtr<protocol::DictionaryValue> message)
{
m_workerGlobalScope->thread()->workerReportingProxy().postMessageToPageInspector(message->toJSONString());
}
void WorkerInspectorController::flush()
{ {
// Worker messages are wrapped, no need to handle callId or state.
m_workerGlobalScope->thread()->workerReportingProxy().postMessageToPageInspector(response);
} }
DEFINE_TRACE(WorkerInspectorController) DEFINE_TRACE(WorkerInspectorController)
{ {
visitor->trace(m_workerGlobalScope); visitor->trace(m_workerGlobalScope);
visitor->trace(m_instrumentingAgents); visitor->trace(m_instrumentingAgents);
visitor->trace(m_agents); visitor->trace(m_session);
} }
} // namespace blink } // namespace blink
...@@ -31,10 +31,9 @@ ...@@ -31,10 +31,9 @@
#ifndef WorkerInspectorController_h #ifndef WorkerInspectorController_h
#define WorkerInspectorController_h #define WorkerInspectorController_h
#include "core/inspector/InspectorBaseAgent.h"
#include "core/inspector/InspectorRuntimeAgent.h" #include "core/inspector/InspectorRuntimeAgent.h"
#include "core/inspector/InspectorSession.h"
#include "core/inspector/InspectorTaskRunner.h" #include "core/inspector/InspectorTaskRunner.h"
#include "platform/inspector_protocol/FrontendChannel.h"
#include "wtf/Allocator.h" #include "wtf/Allocator.h"
#include "wtf/Forward.h" #include "wtf/Forward.h"
#include "wtf/Noncopyable.h" #include "wtf/Noncopyable.h"
...@@ -55,7 +54,7 @@ class Frontend; ...@@ -55,7 +54,7 @@ class Frontend;
class FrontendChannel; class FrontendChannel;
} }
class WorkerInspectorController final : public GarbageCollectedFinalized<WorkerInspectorController>, public InspectorRuntimeAgent::Client, public protocol::FrontendChannel { class WorkerInspectorController final : public GarbageCollectedFinalized<WorkerInspectorController>, public InspectorRuntimeAgent::Client, public InspectorSession::Client {
WTF_MAKE_NONCOPYABLE(WorkerInspectorController); WTF_MAKE_NONCOPYABLE(WorkerInspectorController);
public: public:
static WorkerInspectorController* create(WorkerGlobalScope*); static WorkerInspectorController* create(WorkerGlobalScope*);
...@@ -72,24 +71,17 @@ public: ...@@ -72,24 +71,17 @@ public:
private: private:
WorkerInspectorController(WorkerGlobalScope*, WorkerThreadDebugger*); WorkerInspectorController(WorkerGlobalScope*, WorkerThreadDebugger*);
void initializeAgents();
void destroyAgents();
// InspectorRuntimeAgent::Client implementation. // InspectorRuntimeAgent::Client implementation.
void resumeStartup() override; void resumeStartup() override;
// protocol::FrontendChannel implementation. // InspectorSession::Client implementation.
void sendProtocolResponse(int sessionId, int callId, PassOwnPtr<protocol::DictionaryValue> message) override; void sendProtocolMessage(int sessionId, int callId, const String& response, const String& state) override;
void sendProtocolNotification(PassOwnPtr<protocol::DictionaryValue> message) override;
void flush() override;
WorkerThreadDebugger* m_debugger; WorkerThreadDebugger* m_debugger;
Member<WorkerGlobalScope> m_workerGlobalScope; Member<WorkerGlobalScope> m_workerGlobalScope;
Member<InstrumentingAgents> m_instrumentingAgents; Member<InstrumentingAgents> m_instrumentingAgents;
InspectorAgentRegistry m_agents;
OwnPtr<V8InspectorSession> m_v8Session; OwnPtr<V8InspectorSession> m_v8Session;
OwnPtr<protocol::Frontend> m_frontend; Member<InspectorSession> m_session;
OwnPtr<protocol::Dispatcher> m_backendDispatcher;
}; };
} // namespace blink } // namespace blink
......
...@@ -33,9 +33,9 @@ ...@@ -33,9 +33,9 @@
#include "core/inspector/InspectorPageAgent.h" #include "core/inspector/InspectorPageAgent.h"
#include "core/inspector/InspectorRuntimeAgent.h" #include "core/inspector/InspectorRuntimeAgent.h"
#include "core/inspector/InspectorSession.h"
#include "core/inspector/InspectorTracingAgent.h" #include "core/inspector/InspectorTracingAgent.h"
#include "platform/heap/Handle.h" #include "platform/heap/Handle.h"
#include "platform/inspector_protocol/FrontendChannel.h"
#include "public/platform/WebSize.h" #include "public/platform/WebSize.h"
#include "public/platform/WebThread.h" #include "public/platform/WebThread.h"
#include "public/web/WebDevToolsAgent.h" #include "public/web/WebDevToolsAgent.h"
...@@ -77,7 +77,7 @@ class WebDevToolsAgentImpl final ...@@ -77,7 +77,7 @@ class WebDevToolsAgentImpl final
, public InspectorTracingAgent::Client , public InspectorTracingAgent::Client
, public InspectorPageAgent::Client , public InspectorPageAgent::Client
, public InspectorRuntimeAgent::Client , public InspectorRuntimeAgent::Client
, public protocol::FrontendChannel , public InspectorSession::Client
, private WebThread::TaskObserver { , private WebThread::TaskObserver {
public: public:
static WebDevToolsAgentImpl* create(WebLocalFrameImpl*, WebDevToolsAgentClient*); static WebDevToolsAgentImpl* create(WebLocalFrameImpl*, WebDevToolsAgentClient*);
...@@ -128,24 +128,23 @@ private: ...@@ -128,24 +128,23 @@ private:
void setPausedInDebuggerMessage(const String&) override; void setPausedInDebuggerMessage(const String&) override;
void waitForCreateWindow(LocalFrame*) override; void waitForCreateWindow(LocalFrame*) override;
// protocol::FrontendChannel implementation. // InspectorSession::Client implementation.
void sendProtocolResponse(int sessionId, int callId, PassOwnPtr<protocol::DictionaryValue> message) override; void sendProtocolMessage(int sessionId, int callId, const String& response, const String& state) override;
void sendProtocolNotification(PassOwnPtr<protocol::DictionaryValue> message) override;
void flush() override;
// WebThread::TaskObserver implementation. // WebThread::TaskObserver implementation.
void willProcessTask() override; void willProcessTask() override;
void didProcessTask() override; void didProcessTask() override;
void initializeAgents(); void initializeSession(int sessionId, const String& hostId);
void destroyAgents(); void destroySession();
friend class WebDevToolsAgent; friend class WebDevToolsAgent;
static void runDebuggerTask(int sessionId, PassOwnPtr<WebDevToolsAgent::MessageDescriptor>); static void runDebuggerTask(int sessionId, PassOwnPtr<WebDevToolsAgent::MessageDescriptor>);
bool attached() const { return m_session.get(); }
WebDevToolsAgentClient* m_client; WebDevToolsAgentClient* m_client;
Member<WebLocalFrameImpl> m_webLocalFrameImpl; Member<WebLocalFrameImpl> m_webLocalFrameImpl;
bool m_attached;
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
bool m_hasBeenDisposed; bool m_hasBeenDisposed;
#endif #endif
...@@ -163,16 +162,8 @@ private: ...@@ -163,16 +162,8 @@ private:
Member<InspectorLayerTreeAgent> m_layerTreeAgent; Member<InspectorLayerTreeAgent> m_layerTreeAgent;
Member<InspectorTracingAgent> m_tracingAgent; Member<InspectorTracingAgent> m_tracingAgent;
OwnPtr<protocol::Dispatcher> m_inspectorBackendDispatcher; Member<InspectorSession> m_session;
OwnPtr<protocol::Frontend> m_inspectorFrontend;
InspectorAgentRegistry m_agents;
bool m_includeViewAgents; bool m_includeViewAgents;
typedef Vector<std::pair<int, OwnPtr<protocol::Value>>> NotificationQueue;
NotificationQueue m_notificationQueue;
int m_sessionId;
String m_stateCookie;
bool m_stateMuted;
int m_layerTreeId; int m_layerTreeId;
}; };
......
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