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->serialize()); |
| 98 } |
| 99 |
| 100 void InspectorSession::sendResponse( |
| 101 int callId, |
| 102 std::unique_ptr<v8_inspector::StringBuffer> 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->string())); |
| 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->serialize(); |
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 } |
| 129 |
| 130 static std::unique_ptr<Notification> createForV8( |
| 131 std::unique_ptr<v8_inspector::StringBuffer> notification) { |
| 132 return std::unique_ptr<Notification>( |
| 133 new Notification(std::move(notification))); |
| 134 } |
| 135 |
| 136 String serialize() { |
| 137 if (m_blinkNotification) { |
| 138 m_serialized = m_blinkNotification->serialize(); |
| 139 m_blinkNotification.reset(); |
| 140 } else if (m_v8Notification) { |
| 141 m_serialized = toCoreString(m_v8Notification->string()); |
| 142 m_v8Notification.reset(); |
| 143 } |
| 144 return m_serialized; |
| 145 } |
| 146 |
| 147 private: |
| 148 explicit Notification(std::unique_ptr<protocol::Serializable> notification) |
| 149 : m_blinkNotification(std::move(notification)) {} |
| 150 |
| 151 explicit Notification( |
| 152 std::unique_ptr<v8_inspector::StringBuffer> notification) |
| 153 : m_v8Notification(std::move(notification)) {} |
| 154 |
| 155 std::unique_ptr<protocol::Serializable> m_blinkNotification; |
| 156 std::unique_ptr<v8_inspector::StringBuffer> m_v8Notification; |
| 157 String m_serialized; |
| 158 }; |
| 159 |
| 160 void InspectorSession::sendProtocolNotification( |
| 161 std::unique_ptr<protocol::Serializable> notification) { |
| 162 if (m_disposed) |
| 163 return; |
| 164 m_notificationQueue.append( |
| 165 Notification::createForBlink(std::move(notification))); |
114 } | 166 } |
115 | 167 |
116 void InspectorSession::sendProtocolNotification(const String& message) { | 168 void InspectorSession::sendNotification( |
| 169 std::unique_ptr<v8_inspector::StringBuffer> notification) { |
117 if (m_disposed) | 170 if (m_disposed) |
118 return; | 171 return; |
119 m_notificationQueue.append(message); | 172 m_notificationQueue.append( |
120 } | 173 Notification::createForV8(std::move(notification))); |
121 | |
122 void InspectorSession::sendProtocolNotification( | |
123 const v8_inspector::StringView& message) { | |
124 sendProtocolNotification(toCoreString(message)); | |
125 } | 174 } |
126 | 175 |
127 void InspectorSession::flushProtocolNotifications() { | 176 void InspectorSession::flushProtocolNotifications() { |
128 if (m_disposed) | 177 if (m_disposed) |
129 return; | 178 return; |
130 for (size_t i = 0; i < m_agents.size(); i++) | 179 for (size_t i = 0; i < m_agents.size(); i++) |
131 m_agents[i]->flushPendingProtocolNotifications(); | 180 m_agents[i]->flushPendingProtocolNotifications(); |
132 for (size_t i = 0; i < m_notificationQueue.size(); ++i) | 181 for (size_t i = 0; i < m_notificationQueue.size(); ++i) { |
133 m_client->sendProtocolMessage(m_sessionId, 0, m_notificationQueue[i], | 182 m_client->sendProtocolMessage( |
134 String()); | 183 m_sessionId, 0, m_notificationQueue[i]->serialize(), String()); |
| 184 } |
135 m_notificationQueue.clear(); | 185 m_notificationQueue.clear(); |
136 } | 186 } |
137 | 187 |
138 DEFINE_TRACE(InspectorSession) { | 188 DEFINE_TRACE(InspectorSession) { |
139 visitor->trace(m_instrumentingAgents); | 189 visitor->trace(m_instrumentingAgents); |
140 visitor->trace(m_agents); | 190 visitor->trace(m_agents); |
141 } | 191 } |
142 | 192 |
143 } // namespace blink | 193 } // namespace blink |
OLD | NEW |