| Index: third_party/WebKit/Source/core/inspector/InspectorSession.cpp
|
| diff --git a/third_party/WebKit/Source/core/inspector/InspectorSession.cpp b/third_party/WebKit/Source/core/inspector/InspectorSession.cpp
|
| index ab986577ca7ab0985ffaa2a56bc3662b77c938a8..d3b3281319f8bb564ea2aa2f1e33f6dcd0362d3c 100644
|
| --- a/third_party/WebKit/Source/core/inspector/InspectorSession.cpp
|
| +++ b/third_party/WebKit/Source/core/inspector/InspectorSession.cpp
|
| @@ -13,41 +13,29 @@
|
| #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/V8Debugger.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, InspectedFrames* inspectedFrames, InstrumentingAgents* instrumentingAgents, int sessionId, bool autoFlush)
|
| +namespace {
|
| +const char kV8StateKey[] = "v8";
|
| +}
|
| +
|
| +InspectorSession::InspectorSession(Client* client, InspectedFrames* inspectedFrames, InstrumentingAgents* instrumentingAgents, int sessionId, bool autoFlush, V8Debugger* debugger, int contextGroupId, const String* savedState)
|
| : m_client(client)
|
| , m_v8Session(nullptr)
|
| , m_sessionId(sessionId)
|
| , m_autoFlush(autoFlush)
|
| - , m_attached(false)
|
| + , m_disposed(false)
|
| , m_inspectedFrames(inspectedFrames)
|
| , 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(V8InspectorSession* v8Session, const String* savedState)
|
| -{
|
| - ASSERT(!m_attached);
|
| - m_attached = true;
|
| - m_v8Session = v8Session;
|
| - m_v8Session->setClient(this);
|
| InspectorInstrumentation::frontendCreated();
|
| - bool restore = savedState;
|
|
|
| - if (restore) {
|
| + if (savedState) {
|
| OwnPtr<protocol::Value> state = protocol::parseJSON(*savedState);
|
| if (state)
|
| m_state = protocol::DictionaryValue::cast(std::move(state));
|
| @@ -57,35 +45,51 @@ void InspectorSession::attach(V8InspectorSession* v8Session, const String* saved
|
| 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());
|
| + String16 v8State;
|
| + m_state->getString(kV8StateKey, &v8State);
|
| + m_v8Session = debugger->connect(contextGroupId, this, savedState ? &v8State : nullptr);
|
| +}
|
|
|
| - if (restore) {
|
| - for (size_t i = 0; i < m_agents.size(); i++)
|
| - m_agents[i]->restore();
|
| - }
|
| +InspectorSession::~InspectorSession()
|
| +{
|
| + DCHECK(m_disposed);
|
| }
|
|
|
| -void InspectorSession::detach()
|
| +void InspectorSession::append(InspectorAgent* agent)
|
| {
|
| - ASSERT(m_attached);
|
| - m_attached = false;
|
| + m_agents.append(agent);
|
| + agent->init(m_instrumentingAgents.get(), m_inspectorFrontend.get(), m_inspectorBackendDispatcher.get(), m_state.get());
|
| +}
|
| +
|
| +void InspectorSession::restore()
|
| +{
|
| + DCHECK(!m_disposed);
|
| + for (size_t i = 0; i < m_agents.size(); i++)
|
| + m_agents[i]->restore();
|
| +}
|
| +
|
| +void InspectorSession::dispose()
|
| +{
|
| + DCHECK(!m_disposed);
|
| + m_disposed = true;
|
| 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());
|
| + m_v8Session.clear();
|
| + DCHECK(!isInstrumenting());
|
| InspectorInstrumentation::frontendDeleted();
|
| }
|
|
|
| -void InspectorSession::dispatchProtocolMessage(const String& message)
|
| +void InspectorSession::dispatchProtocolMessage(const String& method, const String& message)
|
| {
|
| - ASSERT(m_attached);
|
| - m_inspectorBackendDispatcher->dispatch(m_sessionId, message);
|
| + DCHECK(!m_disposed);
|
| + if (V8InspectorSession::isV8ProtocolMethod(method))
|
| + m_v8Session->dispatchProtocolMessage(message);
|
| + else
|
| + m_inspectorBackendDispatcher->dispatch(message);
|
| }
|
|
|
| void InspectorSession::didCommitLoadForLocalFrame(LocalFrame* frame)
|
| @@ -94,48 +98,44 @@ void InspectorSession::didCommitLoadForLocalFrame(LocalFrame* frame)
|
| m_agents[i]->didCommitLoadForLocalFrame(frame);
|
| }
|
|
|
| -void InspectorSession::sendProtocolResponse(int sessionId, int callId, PassOwnPtr<protocol::DictionaryValue> message)
|
| +void InspectorSession::sendProtocolResponse(int callId, const protocol::String16& message)
|
| {
|
| - if (!m_attached)
|
| + if (m_disposed)
|
| return;
|
| - flush();
|
| + flushProtocolNotifications();
|
| + m_state->setString(kV8StateKey, m_v8Session->stateJSON());
|
| String stateToSend = m_state->toJSONString();
|
| if (stateToSend == m_lastSentState)
|
| stateToSend = String();
|
| else
|
| m_lastSentState = stateToSend;
|
| - m_client->sendProtocolMessage(m_sessionId, callId, message->toJSONString(), stateToSend);
|
| + m_client->sendProtocolMessage(m_sessionId, callId, message, stateToSend);
|
| }
|
|
|
| -void InspectorSession::sendProtocolNotification(PassOwnPtr<protocol::DictionaryValue> message)
|
| +void InspectorSession::sendProtocolNotification(const protocol::String16& message)
|
| {
|
| - if (!m_attached)
|
| + if (m_disposed)
|
| return;
|
| if (m_autoFlush)
|
| - m_client->sendProtocolMessage(m_sessionId, 0, message->toJSONString(), String());
|
| + m_client->sendProtocolMessage(m_sessionId, 0, message, String());
|
| else
|
| - m_notificationQueue.append(std::move(message));
|
| + m_notificationQueue.append(message);
|
| }
|
|
|
| -void InspectorSession::flush()
|
| +void InspectorSession::flushProtocolNotifications()
|
| {
|
| - 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());
|
| - }
|
| + if (m_disposed)
|
| + return;
|
| + 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], String());
|
| m_notificationQueue.clear();
|
| }
|
|
|
| void InspectorSession::scriptExecutionBlockedByCSP(const String& directiveText)
|
| {
|
| - ASSERT(isInstrumenting());
|
| + DCHECK(isInstrumenting());
|
| OwnPtr<protocol::DictionaryValue> directive = protocol::DictionaryValue::create();
|
| directive->setString("directiveText", directiveText);
|
| m_v8Session->breakProgramOnException(protocol::Debugger::Paused::ReasonEnum::CSPViolation, std::move(directive));
|
| @@ -143,65 +143,63 @@ void InspectorSession::scriptExecutionBlockedByCSP(const String& directiveText)
|
|
|
| void InspectorSession::asyncTaskScheduled(const String& taskName, void* task)
|
| {
|
| - ASSERT(isInstrumenting());
|
| + DCHECK(isInstrumenting());
|
| m_v8Session->asyncTaskScheduled(taskName, task, false);
|
| }
|
|
|
| void InspectorSession::asyncTaskScheduled(const String& operationName, void* task, bool recurring)
|
| {
|
| - ASSERT(isInstrumenting());
|
| + DCHECK(isInstrumenting());
|
| m_v8Session->asyncTaskScheduled(operationName, task, recurring);
|
| }
|
|
|
| void InspectorSession::asyncTaskCanceled(void* task)
|
| {
|
| - ASSERT(isInstrumenting());
|
| + DCHECK(isInstrumenting());
|
| m_v8Session->asyncTaskCanceled(task);
|
| }
|
|
|
| void InspectorSession::allAsyncTasksCanceled()
|
| {
|
| - ASSERT(isInstrumenting());
|
| + DCHECK(isInstrumenting());
|
| m_v8Session->allAsyncTasksCanceled();
|
| }
|
|
|
| void InspectorSession::asyncTaskStarted(void* task)
|
| {
|
| - ASSERT(isInstrumenting());
|
| + DCHECK(isInstrumenting());
|
| m_v8Session->asyncTaskStarted(task);
|
| }
|
|
|
| void InspectorSession::asyncTaskFinished(void* task)
|
| {
|
| - ASSERT(isInstrumenting());
|
| + DCHECK(isInstrumenting());
|
| m_v8Session->asyncTaskFinished(task);
|
| }
|
|
|
| void InspectorSession::didStartProvisionalLoad(LocalFrame* frame)
|
| {
|
| - ASSERT(isInstrumenting());
|
| - if (m_inspectedFrames && m_inspectedFrames->root() == frame) {
|
| - ErrorString error;
|
| - m_v8Session->debuggerAgent()->resume(&error);
|
| - }
|
| + DCHECK(isInstrumenting());
|
| + if (m_inspectedFrames && m_inspectedFrames->root() == frame)
|
| + m_v8Session->resume();
|
| }
|
|
|
| void InspectorSession::didClearDocumentOfWindowObject(LocalFrame* frame)
|
| {
|
| - ASSERT(isInstrumenting());
|
| + DCHECK(isInstrumenting());
|
| frame->script().initializeMainWorld();
|
| }
|
|
|
| void InspectorSession::startInstrumenting()
|
| {
|
| - ASSERT(!isInstrumenting());
|
| + DCHECK(!isInstrumenting());
|
| m_instrumentingAgents->addInspectorSession(this);
|
| forceContextsInAllFrames();
|
| }
|
|
|
| void InspectorSession::stopInstrumenting()
|
| {
|
| - ASSERT(isInstrumenting());
|
| + DCHECK(isInstrumenting());
|
| m_instrumentingAgents->removeInspectorSession(this);
|
| }
|
|
|
| @@ -235,12 +233,10 @@ void InspectorSession::forceContextsInAllFrames()
|
| frame->script().initializeMainWorld();
|
| }
|
|
|
| -#if ENABLE(ASSERT)
|
| bool InspectorSession::isInstrumenting()
|
| {
|
| return m_instrumentingAgents->inspectorSessions().contains(this);
|
| }
|
| -#endif
|
|
|
| DEFINE_TRACE(InspectorSession)
|
| {
|
|
|