| 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/V8InspectorString.h" | 12 #include "core/inspector/V8InspectorString.h" |
| 13 #include "core/inspector/protocol/Protocol.h" |
| 13 #include "platform/v8_inspector/public/V8Inspector.h" | 14 #include "platform/v8_inspector/public/V8Inspector.h" |
| 14 #include "platform/v8_inspector/public/V8InspectorSession.h" | 15 #include "platform/v8_inspector/public/V8InspectorSession.h" |
| 15 | 16 |
| 16 namespace blink { | 17 namespace blink { |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 const char kV8StateKey[] = "v8"; | 20 const char kV8StateKey[] = "v8"; |
| 20 } | 21 } |
| 21 | 22 |
| 22 InspectorSession::InspectorSession(Client* client, InstrumentingAgents* instrume
ntingAgents, int sessionId, v8_inspector::V8Inspector* inspector, int contextGro
upId, const String* savedState) | 23 InspectorSession::InspectorSession(Client* client, InstrumentingAgents* instrume
ntingAgents, int sessionId, v8_inspector::V8Inspector* inspector, int contextGro
upId, const String* savedState) |
| 23 : m_client(client) | 24 : m_client(client) |
| 24 , m_v8Session(nullptr) | 25 , m_v8Session(nullptr) |
| 25 , m_sessionId(sessionId) | 26 , m_sessionId(sessionId) |
| 26 , m_disposed(false) | 27 , m_disposed(false) |
| 27 , m_instrumentingAgents(instrumentingAgents) | 28 , m_instrumentingAgents(instrumentingAgents) |
| 28 , m_inspectorBackendDispatcher(new protocol::UberDispatcher(this)) | 29 , m_inspectorBackendDispatcher(new protocol::UberDispatcher(this)) |
| 29 { | 30 { |
| 30 if (savedState) { | 31 if (savedState) { |
| 31 std::unique_ptr<protocol::Value> state = protocol::parseJSON(*savedState
); | 32 std::unique_ptr<protocol::Value> state = protocol::parseJSON(*savedState
); |
| 32 if (state) | 33 if (state) |
| 33 m_state = protocol::DictionaryValue::cast(std::move(state)); | 34 m_state = protocol::DictionaryValue::cast(std::move(state)); |
| 34 if (!m_state) | 35 if (!m_state) |
| 35 m_state = protocol::DictionaryValue::create(); | 36 m_state = protocol::DictionaryValue::create(); |
| 36 } else { | 37 } else { |
| 37 m_state = protocol::DictionaryValue::create(); | 38 m_state = protocol::DictionaryValue::create(); |
| 38 } | 39 } |
| 39 | 40 |
| 40 String16 v8State; | 41 String v8State; |
| 41 if (savedState) | 42 if (savedState) |
| 42 m_state->getString(kV8StateKey, &v8State); | 43 m_state->getString(kV8StateKey, &v8State); |
| 43 m_v8Session = inspector->connect(contextGroupId, this, toV8InspectorStringVi
ew(String(v8State))); | 44 m_v8Session = inspector->connect(contextGroupId, this, toV8InspectorStringVi
ew(v8State)); |
| 44 } | 45 } |
| 45 | 46 |
| 46 InspectorSession::~InspectorSession() | 47 InspectorSession::~InspectorSession() |
| 47 { | 48 { |
| 48 DCHECK(m_disposed); | 49 DCHECK(m_disposed); |
| 49 } | 50 } |
| 50 | 51 |
| 51 void InspectorSession::append(InspectorAgent* agent) | 52 void InspectorSession::append(InspectorAgent* agent) |
| 52 { | 53 { |
| 53 m_agents.append(agent); | 54 m_agents.append(agent); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 80 else | 81 else |
| 81 m_inspectorBackendDispatcher->dispatch(protocol::parseJSON(message)); | 82 m_inspectorBackendDispatcher->dispatch(protocol::parseJSON(message)); |
| 82 } | 83 } |
| 83 | 84 |
| 84 void InspectorSession::didCommitLoadForLocalFrame(LocalFrame* frame) | 85 void InspectorSession::didCommitLoadForLocalFrame(LocalFrame* frame) |
| 85 { | 86 { |
| 86 for (size_t i = 0; i < m_agents.size(); i++) | 87 for (size_t i = 0; i < m_agents.size(); i++) |
| 87 m_agents[i]->didCommitLoadForLocalFrame(frame); | 88 m_agents[i]->didCommitLoadForLocalFrame(frame); |
| 88 } | 89 } |
| 89 | 90 |
| 90 void InspectorSession::sendProtocolResponse(int callId, const protocol::String16
& message) | 91 void InspectorSession::sendProtocolResponse(int callId, const String& message) |
| 91 { | 92 { |
| 92 if (m_disposed) | 93 if (m_disposed) |
| 93 return; | 94 return; |
| 94 flushProtocolNotifications(); | 95 flushProtocolNotifications(); |
| 95 m_state->setString(kV8StateKey, toCoreString(m_v8Session->stateJSON())); | 96 m_state->setString(kV8StateKey, toCoreString(m_v8Session->stateJSON())); |
| 96 String stateToSend = m_state->toJSONString(); | 97 String stateToSend = m_state->toJSONString(); |
| 97 if (stateToSend == m_lastSentState) | 98 if (stateToSend == m_lastSentState) |
| 98 stateToSend = String(); | 99 stateToSend = String(); |
| 99 else | 100 else |
| 100 m_lastSentState = stateToSend; | 101 m_lastSentState = stateToSend; |
| 101 m_client->sendProtocolMessage(m_sessionId, callId, message, stateToSend); | 102 m_client->sendProtocolMessage(m_sessionId, callId, message, stateToSend); |
| 102 } | 103 } |
| 103 | 104 |
| 104 void InspectorSession::sendProtocolNotification(const protocol::String16& messag
e) | 105 void InspectorSession::sendProtocolResponse(int callId, const v8_inspector::Stri
ngView& message) |
| 106 { |
| 107 // We can potentially avoid copies if WebString would convert to utf8 right
from StringView, |
| 108 // but it uses StringImpl itself, so we don't create any extra copies here. |
| 109 sendProtocolResponse(callId, toCoreString(message)); |
| 110 } |
| 111 |
| 112 void InspectorSession::sendProtocolNotification(const String& message) |
| 105 { | 113 { |
| 106 if (m_disposed) | 114 if (m_disposed) |
| 107 return; | 115 return; |
| 108 m_notificationQueue.append(message); | 116 m_notificationQueue.append(message); |
| 109 } | 117 } |
| 110 | 118 |
| 119 void InspectorSession::sendProtocolNotification(const v8_inspector::StringView&
message) |
| 120 { |
| 121 sendProtocolNotification(toCoreString(message)); |
| 122 } |
| 123 |
| 111 void InspectorSession::flushProtocolNotifications() | 124 void InspectorSession::flushProtocolNotifications() |
| 112 { | 125 { |
| 113 if (m_disposed) | 126 if (m_disposed) |
| 114 return; | 127 return; |
| 115 for (size_t i = 0; i < m_agents.size(); i++) | 128 for (size_t i = 0; i < m_agents.size(); i++) |
| 116 m_agents[i]->flushPendingProtocolNotifications(); | 129 m_agents[i]->flushPendingProtocolNotifications(); |
| 117 for (size_t i = 0; i < m_notificationQueue.size(); ++i) | 130 for (size_t i = 0; i < m_notificationQueue.size(); ++i) |
| 118 m_client->sendProtocolMessage(m_sessionId, 0, m_notificationQueue[i], St
ring()); | 131 m_client->sendProtocolMessage(m_sessionId, 0, m_notificationQueue[i], St
ring()); |
| 119 m_notificationQueue.clear(); | 132 m_notificationQueue.clear(); |
| 120 } | 133 } |
| 121 | 134 |
| 122 DEFINE_TRACE(InspectorSession) | 135 DEFINE_TRACE(InspectorSession) |
| 123 { | 136 { |
| 124 visitor->trace(m_instrumentingAgents); | 137 visitor->trace(m_instrumentingAgents); |
| 125 visitor->trace(m_agents); | 138 visitor->trace(m_agents); |
| 126 } | 139 } |
| 127 | 140 |
| 128 } // namespace blink | 141 } // namespace blink |
| 129 | 142 |
| OLD | NEW |