Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(365)

Side by Side Diff: third_party/WebKit/Source/core/inspector/InspectorSession.cpp

Issue 2522583002: Roll third_party/inspector_protocol to 4ad35c45aca9834b67ec2cb152c816ea1b7ceb48 (Closed)
Patch Set: addressed comments Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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::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 serialize() {
136 if (m_notification) {
137 m_rawNotification = m_notification->serialize();
138 m_notification.reset();
139 }
140 return m_rawNotification;
141 }
142
143 private:
144 explicit Notification(std::unique_ptr<protocol::Serializable> notification)
145 : m_notification(std::move(notification)) {}
146
147 explicit Notification(const v8_inspector::StringView& notification)
148 : m_rawNotification(toCoreString(notification)) {}
149
150 std::unique_ptr<protocol::Serializable> m_notification;
151 String m_rawNotification;
152 };
153
154 void InspectorSession::sendProtocolNotification(
155 std::unique_ptr<protocol::Serializable> notification) {
117 if (m_disposed) 156 if (m_disposed)
118 return; 157 return;
119 m_notificationQueue.append(message); 158 m_notificationQueue.append(
159 Notification::createForBlink(std::move(notification)));
120 } 160 }
121 161
122 void InspectorSession::sendProtocolNotification( 162 void InspectorSession::sendProtocolNotification(
123 const v8_inspector::StringView& message) { 163 const v8_inspector::StringView& notification) {
124 sendProtocolNotification(toCoreString(message)); 164 if (m_disposed)
165 return;
166 m_notificationQueue.append(Notification::createForV8(notification));
125 } 167 }
126 168
127 void InspectorSession::flushProtocolNotifications() { 169 void InspectorSession::flushProtocolNotifications() {
128 if (m_disposed) 170 if (m_disposed)
129 return; 171 return;
130 for (size_t i = 0; i < m_agents.size(); i++) 172 for (size_t i = 0; i < m_agents.size(); i++)
131 m_agents[i]->flushPendingProtocolNotifications(); 173 m_agents[i]->flushPendingProtocolNotifications();
132 for (size_t i = 0; i < m_notificationQueue.size(); ++i) 174 for (size_t i = 0; i < m_notificationQueue.size(); ++i) {
133 m_client->sendProtocolMessage(m_sessionId, 0, m_notificationQueue[i], 175 m_client->sendProtocolMessage(
134 String()); 176 m_sessionId, 0, m_notificationQueue[i]->serialize(), String());
177 }
135 m_notificationQueue.clear(); 178 m_notificationQueue.clear();
136 } 179 }
137 180
138 DEFINE_TRACE(InspectorSession) { 181 DEFINE_TRACE(InspectorSession) {
139 visitor->trace(m_instrumentingAgents); 182 visitor->trace(m_instrumentingAgents);
140 visitor->trace(m_agents); 183 visitor->trace(m_agents);
141 } 184 }
142 185
143 } // namespace blink 186 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698