| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/inspector/InspectorSession.h" | 5 #include "core/inspector/InspectorSession.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/ScriptController.h" | 7 #include "bindings/core/v8/ScriptController.h" |
| 8 #include "core/frame/LocalFrame.h" | 8 #include "core/frame/LocalFrame.h" |
| 9 #include "core/frame/UseCounter.h" | 9 #include "core/frame/UseCounter.h" |
| 10 #include "core/inspector/InspectedFrames.h" | 10 #include "core/inspector/InspectedFrames.h" |
| 11 #include "core/inspector/InspectorBaseAgent.h" | 11 #include "core/inspector/InspectorBaseAgent.h" |
| 12 #include "core/inspector/InspectorInstrumentation.h" | 12 #include "core/inspector/InspectorInstrumentation.h" |
| 13 #include "platform/inspector_protocol/Backend.h" | |
| 14 #include "platform/inspector_protocol/Parser.h" | 13 #include "platform/inspector_protocol/Parser.h" |
| 15 #include "platform/inspector_protocol/TypeBuilder.h" | 14 #include "platform/inspector_protocol/TypeBuilder.h" |
| 16 #include "platform/v8_inspector/public/V8Debugger.h" | 15 #include "platform/v8_inspector/public/V8Debugger.h" |
| 17 #include "platform/v8_inspector/public/V8InspectorSession.h" | 16 #include "platform/v8_inspector/public/V8InspectorSession.h" |
| 18 | 17 |
| 19 namespace blink { | 18 namespace blink { |
| 20 | 19 |
| 21 namespace { | 20 namespace { |
| 22 const char kV8StateKey[] = "v8"; | 21 const char kV8StateKey[] = "v8"; |
| 23 } | 22 } |
| 24 | 23 |
| 25 InspectorSession::InspectorSession(Client* client, InspectedFrames* inspectedFra
mes, InstrumentingAgents* instrumentingAgents, int sessionId, bool autoFlush, V8
Debugger* debugger, int contextGroupId, const String* savedState) | 24 InspectorSession::InspectorSession(Client* client, InspectedFrames* inspectedFra
mes, InstrumentingAgents* instrumentingAgents, int sessionId, bool autoFlush, V8
Debugger* debugger, int contextGroupId, const String* savedState) |
| 26 : m_client(client) | 25 : m_client(client) |
| 27 , m_v8Session(nullptr) | 26 , m_v8Session(nullptr) |
| 28 , m_sessionId(sessionId) | 27 , m_sessionId(sessionId) |
| 29 , m_autoFlush(autoFlush) | 28 , m_autoFlush(autoFlush) |
| 30 , m_disposed(false) | 29 , m_disposed(false) |
| 31 , m_inspectedFrames(inspectedFrames) | 30 , m_inspectedFrames(inspectedFrames) |
| 32 , m_instrumentingAgents(instrumentingAgents) | 31 , m_instrumentingAgents(instrumentingAgents) |
| 33 , m_inspectorFrontend(new protocol::Frontend(this)) | 32 , m_inspectorBackendDispatcher(new protocol::UberDispatcher(this)) |
| 34 , m_inspectorBackendDispatcher(protocol::Dispatcher::create(this)) | |
| 35 { | 33 { |
| 36 InspectorInstrumentation::frontendCreated(); | 34 InspectorInstrumentation::frontendCreated(); |
| 37 | 35 |
| 38 if (savedState) { | 36 if (savedState) { |
| 39 std::unique_ptr<protocol::Value> state = protocol::parseJSON(*savedState
); | 37 std::unique_ptr<protocol::Value> state = protocol::parseJSON(*savedState
); |
| 40 if (state) | 38 if (state) |
| 41 m_state = protocol::DictionaryValue::cast(std::move(state)); | 39 m_state = protocol::DictionaryValue::cast(std::move(state)); |
| 42 if (!m_state) | 40 if (!m_state) |
| 43 m_state = protocol::DictionaryValue::create(); | 41 m_state = protocol::DictionaryValue::create(); |
| 44 } else { | 42 } else { |
| 45 m_state = protocol::DictionaryValue::create(); | 43 m_state = protocol::DictionaryValue::create(); |
| 46 } | 44 } |
| 47 | 45 |
| 48 String16 v8State; | 46 String16 v8State; |
| 49 m_state->getString(kV8StateKey, &v8State); | 47 m_state->getString(kV8StateKey, &v8State); |
| 50 m_v8Session = debugger->connect(contextGroupId, this, savedState ? &v8State
: nullptr); | 48 m_v8Session = debugger->connect(contextGroupId, this, savedState ? &v8State
: nullptr); |
| 51 } | 49 } |
| 52 | 50 |
| 53 InspectorSession::~InspectorSession() | 51 InspectorSession::~InspectorSession() |
| 54 { | 52 { |
| 55 DCHECK(m_disposed); | 53 DCHECK(m_disposed); |
| 56 } | 54 } |
| 57 | 55 |
| 58 void InspectorSession::append(InspectorAgent* agent) | 56 void InspectorSession::append(InspectorAgent* agent) |
| 59 { | 57 { |
| 60 m_agents.append(agent); | 58 m_agents.append(agent); |
| 61 agent->init(m_instrumentingAgents.get(), m_inspectorFrontend.get(), m_inspec
torBackendDispatcher.get(), m_state.get()); | 59 agent->init(m_instrumentingAgents.get(), m_inspectorBackendDispatcher.get(),
m_state.get()); |
| 62 } | 60 } |
| 63 | 61 |
| 64 void InspectorSession::restore() | 62 void InspectorSession::restore() |
| 65 { | 63 { |
| 66 DCHECK(!m_disposed); | 64 DCHECK(!m_disposed); |
| 67 for (size_t i = 0; i < m_agents.size(); i++) | 65 for (size_t i = 0; i < m_agents.size(); i++) |
| 68 m_agents[i]->restore(); | 66 m_agents[i]->restore(); |
| 69 } | 67 } |
| 70 | 68 |
| 71 void InspectorSession::dispose() | 69 void InspectorSession::dispose() |
| 72 { | 70 { |
| 73 DCHECK(!m_disposed); | 71 DCHECK(!m_disposed); |
| 74 m_disposed = true; | 72 m_disposed = true; |
| 75 m_inspectorBackendDispatcher->clearFrontend(); | |
| 76 m_inspectorBackendDispatcher.reset(); | 73 m_inspectorBackendDispatcher.reset(); |
| 77 for (size_t i = m_agents.size(); i > 0; i--) | 74 for (size_t i = m_agents.size(); i > 0; i--) |
| 78 m_agents[i - 1]->dispose(); | 75 m_agents[i - 1]->dispose(); |
| 79 m_inspectorFrontend.reset(); | |
| 80 m_agents.clear(); | 76 m_agents.clear(); |
| 81 m_v8Session.reset(); | 77 m_v8Session.reset(); |
| 82 DCHECK(!isInstrumenting()); | 78 DCHECK(!isInstrumenting()); |
| 83 InspectorInstrumentation::frontendDeleted(); | 79 InspectorInstrumentation::frontendDeleted(); |
| 84 } | 80 } |
| 85 | 81 |
| 86 void InspectorSession::dispatchProtocolMessage(const String& method, const Strin
g& message) | 82 void InspectorSession::dispatchProtocolMessage(const String& method, const Strin
g& message) |
| 87 { | 83 { |
| 88 DCHECK(!m_disposed); | 84 DCHECK(!m_disposed); |
| 89 if (V8InspectorSession::isV8ProtocolMethod(method)) | 85 if (V8InspectorSession::isV8ProtocolMethod(method)) |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 | 236 |
| 241 DEFINE_TRACE(InspectorSession) | 237 DEFINE_TRACE(InspectorSession) |
| 242 { | 238 { |
| 243 visitor->trace(m_instrumentingAgents); | 239 visitor->trace(m_instrumentingAgents); |
| 244 visitor->trace(m_inspectedFrames); | 240 visitor->trace(m_inspectedFrames); |
| 245 visitor->trace(m_agents); | 241 visitor->trace(m_agents); |
| 246 } | 242 } |
| 247 | 243 |
| 248 } // namespace blink | 244 } // namespace blink |
| 249 | 245 |
| OLD | NEW |