Chromium Code Reviews| 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" |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 84 m_inspectorBackendDispatcher->dispatch( | 84 m_inspectorBackendDispatcher->dispatch( |
| 85 protocol::StringUtil::parseJSON(message)); | 85 protocol::StringUtil::parseJSON(message)); |
| 86 } | 86 } |
| 87 } | 87 } |
| 88 | 88 |
| 89 void InspectorSession::didCommitLoadForLocalFrame(LocalFrame* frame) { | 89 void InspectorSession::didCommitLoadForLocalFrame(LocalFrame* frame) { |
| 90 for (size_t i = 0; i < m_agents.size(); i++) | 90 for (size_t i = 0; i < m_agents.size(); i++) |
| 91 m_agents[i]->didCommitLoadForLocalFrame(frame); | 91 m_agents[i]->didCommitLoadForLocalFrame(frame); |
| 92 } | 92 } |
| 93 | 93 |
| 94 void InspectorSession::sendProtocolResponse( | |
| 95 int callId, | |
| 96 std::unique_ptr<protocol::Serializable> message) { | |
| 97 sendProtocolResponse(callId, message->serializeValue()->toJSONString()); | |
| 98 } | |
| 99 | |
| 100 void InspectorSession::sendProtocolResponse( | |
| 101 int callId, | |
| 102 const v8_inspector::StringView& message) { | |
| 103 // We can potentially avoid copies if WebString would convert to utf8 right | |
| 104 // from StringView, but it uses StringImpl itself, so we don't create any | |
| 105 // extra copies here. | |
| 106 sendProtocolResponse(callId, toCoreString(message)); | |
| 107 } | |
| 108 | |
| 94 void InspectorSession::sendProtocolResponse(int callId, const String& message) { | 109 void InspectorSession::sendProtocolResponse(int callId, const String& message) { |
| 95 if (m_disposed) | 110 if (m_disposed) |
| 96 return; | 111 return; |
| 97 flushProtocolNotifications(); | 112 flushProtocolNotifications(); |
| 98 m_state->setString(kV8StateKey, toCoreString(m_v8Session->stateJSON())); | 113 m_state->setString(kV8StateKey, toCoreString(m_v8Session->stateJSON())); |
| 99 String stateToSend = m_state->toJSONString(); | 114 String stateToSend = m_state->toJSONString(); |
| 100 if (stateToSend == m_lastSentState) | 115 if (stateToSend == m_lastSentState) |
| 101 stateToSend = String(); | 116 stateToSend = String(); |
| 102 else | 117 else |
| 103 m_lastSentState = stateToSend; | 118 m_lastSentState = stateToSend; |
| 104 m_client->sendProtocolMessage(m_sessionId, callId, message, stateToSend); | 119 m_client->sendProtocolMessage(m_sessionId, callId, message, stateToSend); |
| 105 } | 120 } |
| 106 | 121 |
| 107 void InspectorSession::sendProtocolResponse( | 122 class InspectorSession::Notification { |
| 108 int callId, | 123 public: |
| 109 const v8_inspector::StringView& message) { | 124 static std::unique_ptr<Notification> createForBlink( |
| 110 // We can potentially avoid copies if WebString would convert to utf8 right | 125 std::unique_ptr<protocol::Serializable> notification) { |
| 111 // from StringView, but it uses StringImpl itself, so we don't create any | 126 return std::unique_ptr<Notification>( |
| 112 // extra copies here. | 127 new Notification(std::move(notification))); |
| 113 sendProtocolResponse(callId, toCoreString(message)); | 128 } |
| 114 } | |
| 115 | 129 |
| 116 void InspectorSession::sendProtocolNotification(const String& message) { | 130 static std::unique_ptr<Notification> createForV8( |
| 131 const v8_inspector::StringView& notification) { | |
| 132 return std::unique_ptr<Notification>(new Notification(notification)); | |
| 133 } | |
| 134 | |
| 135 String string() { | |
| 136 if (m_notification) | |
| 137 return m_notification->serializeValue()->toJSONString(); | |
|
dgozman
2016/11/21 22:29:16
Let's clear m_notification here to not store extra
kozy
2016/11/22 01:25:38
Done.
| |
| 138 return m_rawNotification; | |
| 139 } | |
| 140 | |
| 141 private: | |
| 142 explicit Notification(std::unique_ptr<protocol::Serializable> notification) | |
| 143 : m_notification(std::move(notification)) {} | |
| 144 | |
| 145 explicit Notification(const v8_inspector::StringView& notification) | |
| 146 : m_rawNotification(toCoreString(notification)) {} | |
| 147 | |
| 148 std::unique_ptr<protocol::Serializable> m_notification; | |
| 149 String m_rawNotification; | |
| 150 }; | |
| 151 | |
| 152 void InspectorSession::sendProtocolNotification( | |
| 153 std::unique_ptr<protocol::Serializable> notification) { | |
| 117 if (m_disposed) | 154 if (m_disposed) |
| 118 return; | 155 return; |
| 119 m_notificationQueue.append(message); | 156 m_notificationQueue.append( |
| 157 Notification::createForBlink(std::move(notification))); | |
| 120 } | 158 } |
| 121 | 159 |
| 122 void InspectorSession::sendProtocolNotification( | 160 void InspectorSession::sendProtocolNotification( |
| 123 const v8_inspector::StringView& message) { | 161 const v8_inspector::StringView& notification) { |
| 124 sendProtocolNotification(toCoreString(message)); | 162 if (m_disposed) |
| 163 return; | |
| 164 m_notificationQueue.append(Notification::createForV8(notification)); | |
| 125 } | 165 } |
| 126 | 166 |
| 127 void InspectorSession::flushProtocolNotifications() { | 167 void InspectorSession::flushProtocolNotifications() { |
| 128 if (m_disposed) | 168 if (m_disposed) |
| 129 return; | 169 return; |
| 130 for (size_t i = 0; i < m_agents.size(); i++) | 170 for (size_t i = 0; i < m_agents.size(); i++) |
| 131 m_agents[i]->flushPendingProtocolNotifications(); | 171 m_agents[i]->flushPendingProtocolNotifications(); |
| 132 for (size_t i = 0; i < m_notificationQueue.size(); ++i) | 172 for (size_t i = 0; i < m_notificationQueue.size(); ++i) { |
| 133 m_client->sendProtocolMessage(m_sessionId, 0, m_notificationQueue[i], | 173 m_client->sendProtocolMessage(m_sessionId, 0, |
| 134 String()); | 174 m_notificationQueue[i]->string(), String()); |
| 175 } | |
| 135 m_notificationQueue.clear(); | 176 m_notificationQueue.clear(); |
| 136 } | 177 } |
| 137 | 178 |
| 138 DEFINE_TRACE(InspectorSession) { | 179 DEFINE_TRACE(InspectorSession) { |
| 139 visitor->trace(m_instrumentingAgents); | 180 visitor->trace(m_instrumentingAgents); |
| 140 visitor->trace(m_agents); | 181 visitor->trace(m_agents); |
| 141 } | 182 } |
| 142 | 183 |
| 143 } // namespace blink | 184 } // namespace blink |
| OLD | NEW |