| 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/InspectorBaseAgent.h" | 10 #include "core/inspector/InspectorBaseAgent.h" |
| 11 #include "core/inspector/InspectorInstrumentation.h" | 11 #include "core/inspector/InspectorInstrumentation.h" |
| 12 #include "core/inspector/V8InspectorStringView.h" |
| 12 #include "platform/v8_inspector/public/V8Inspector.h" | 13 #include "platform/v8_inspector/public/V8Inspector.h" |
| 13 #include "platform/v8_inspector/public/V8InspectorSession.h" | 14 #include "platform/v8_inspector/public/V8InspectorSession.h" |
| 14 | 15 |
| 15 namespace blink { | 16 namespace blink { |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 const char kV8StateKey[] = "v8"; | 19 const char kV8StateKey[] = "v8"; |
| 19 } | 20 } |
| 20 | 21 |
| 21 InspectorSession::InspectorSession(Client* client, InstrumentingAgents* instrume
ntingAgents, int sessionId, v8_inspector::V8Inspector* inspector, int contextGro
upId, const String* savedState) | 22 InspectorSession::InspectorSession(Client* client, InstrumentingAgents* instrume
ntingAgents, int sessionId, v8_inspector::V8Inspector* inspector, int contextGro
upId, const String* savedState) |
| 22 : m_client(client) | 23 : m_client(client) |
| 23 , m_v8Session(nullptr) | 24 , m_v8Session(nullptr) |
| 24 , m_sessionId(sessionId) | 25 , m_sessionId(sessionId) |
| 25 , m_disposed(false) | 26 , m_disposed(false) |
| 26 , m_instrumentingAgents(instrumentingAgents) | 27 , m_instrumentingAgents(instrumentingAgents) |
| 27 , m_inspectorBackendDispatcher(new protocol::UberDispatcher(this)) | 28 , m_inspectorBackendDispatcher(new protocol::UberDispatcher(this)) |
| 28 { | 29 { |
| 29 if (savedState) { | 30 if (savedState) { |
| 30 std::unique_ptr<protocol::Value> state = protocol::parseJSON(*savedState
); | 31 std::unique_ptr<protocol::Value> state = protocol::parseJSON(*savedState
); |
| 31 if (state) | 32 if (state) |
| 32 m_state = protocol::DictionaryValue::cast(std::move(state)); | 33 m_state = protocol::DictionaryValue::cast(std::move(state)); |
| 33 if (!m_state) | 34 if (!m_state) |
| 34 m_state = protocol::DictionaryValue::create(); | 35 m_state = protocol::DictionaryValue::create(); |
| 35 } else { | 36 } else { |
| 36 m_state = protocol::DictionaryValue::create(); | 37 m_state = protocol::DictionaryValue::create(); |
| 37 } | 38 } |
| 38 | 39 |
| 39 String16 v8State; | 40 String16 v8State; |
| 40 m_state->getString(kV8StateKey, &v8State); | 41 if (savedState) |
| 41 m_v8Session = inspector->connect(contextGroupId, this, savedState ? &v8State
: nullptr); | 42 m_state->getString(kV8StateKey, &v8State); |
| 43 m_v8Session = inspector->connect(contextGroupId, this, toV8InspectorStringVi
ew(v8State)); |
| 42 } | 44 } |
| 43 | 45 |
| 44 InspectorSession::~InspectorSession() | 46 InspectorSession::~InspectorSession() |
| 45 { | 47 { |
| 46 DCHECK(m_disposed); | 48 DCHECK(m_disposed); |
| 47 } | 49 } |
| 48 | 50 |
| 49 void InspectorSession::append(InspectorAgent* agent) | 51 void InspectorSession::append(InspectorAgent* agent) |
| 50 { | 52 { |
| 51 m_agents.append(agent); | 53 m_agents.append(agent); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 66 m_inspectorBackendDispatcher.reset(); | 68 m_inspectorBackendDispatcher.reset(); |
| 67 for (size_t i = m_agents.size(); i > 0; i--) | 69 for (size_t i = m_agents.size(); i > 0; i--) |
| 68 m_agents[i - 1]->dispose(); | 70 m_agents[i - 1]->dispose(); |
| 69 m_agents.clear(); | 71 m_agents.clear(); |
| 70 m_v8Session.reset(); | 72 m_v8Session.reset(); |
| 71 } | 73 } |
| 72 | 74 |
| 73 void InspectorSession::dispatchProtocolMessage(const String& method, const Strin
g& message) | 75 void InspectorSession::dispatchProtocolMessage(const String& method, const Strin
g& message) |
| 74 { | 76 { |
| 75 DCHECK(!m_disposed); | 77 DCHECK(!m_disposed); |
| 76 if (v8_inspector::V8InspectorSession::canDispatchMethod(method)) | 78 if (v8_inspector::V8InspectorSession::canDispatchMethod(toV8InspectorStringV
iew(method))) |
| 77 m_v8Session->dispatchProtocolMessage(message); | 79 m_v8Session->dispatchProtocolMessage(toV8InspectorStringView(message)); |
| 78 else | 80 else |
| 79 m_inspectorBackendDispatcher->dispatch(message); | 81 m_inspectorBackendDispatcher->dispatch(protocol::parseJSON(message)); |
| 80 } | 82 } |
| 81 | 83 |
| 82 void InspectorSession::didCommitLoadForLocalFrame(LocalFrame* frame) | 84 void InspectorSession::didCommitLoadForLocalFrame(LocalFrame* frame) |
| 83 { | 85 { |
| 84 for (size_t i = 0; i < m_agents.size(); i++) | 86 for (size_t i = 0; i < m_agents.size(); i++) |
| 85 m_agents[i]->didCommitLoadForLocalFrame(frame); | 87 m_agents[i]->didCommitLoadForLocalFrame(frame); |
| 86 } | 88 } |
| 87 | 89 |
| 88 void InspectorSession::sendProtocolResponse(int callId, const protocol::String16
& message) | 90 void InspectorSession::sendProtocolResponse(int callId, const protocol::String16
& message) |
| 89 { | 91 { |
| 90 if (m_disposed) | 92 if (m_disposed) |
| 91 return; | 93 return; |
| 92 flushProtocolNotifications(); | 94 flushProtocolNotifications(); |
| 93 m_state->setString(kV8StateKey, m_v8Session->stateJSON()); | 95 m_state->setString(kV8StateKey, toCoreString(m_v8Session->stateJSON())); |
| 94 String stateToSend = m_state->toJSONString(); | 96 String stateToSend = m_state->toJSONString(); |
| 95 if (stateToSend == m_lastSentState) | 97 if (stateToSend == m_lastSentState) |
| 96 stateToSend = String(); | 98 stateToSend = String(); |
| 97 else | 99 else |
| 98 m_lastSentState = stateToSend; | 100 m_lastSentState = stateToSend; |
| 99 m_client->sendProtocolMessage(m_sessionId, callId, message, stateToSend); | 101 m_client->sendProtocolMessage(m_sessionId, callId, message, stateToSend); |
| 100 } | 102 } |
| 101 | 103 |
| 102 void InspectorSession::sendProtocolNotification(const protocol::String16& messag
e) | 104 void InspectorSession::sendProtocolNotification(const protocol::String16& messag
e) |
| 103 { | 105 { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 118 } | 120 } |
| 119 | 121 |
| 120 DEFINE_TRACE(InspectorSession) | 122 DEFINE_TRACE(InspectorSession) |
| 121 { | 123 { |
| 122 visitor->trace(m_instrumentingAgents); | 124 visitor->trace(m_instrumentingAgents); |
| 123 visitor->trace(m_agents); | 125 visitor->trace(m_agents); |
| 124 } | 126 } |
| 125 | 127 |
| 126 } // namespace blink | 128 } // namespace blink |
| 127 | 129 |
| OLD | NEW |