| OLD | NEW |
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project 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 "src/inspector/v8-inspector-session-impl.h" | 5 #include "src/inspector/v8-inspector-session-impl.h" |
| 6 | 6 |
| 7 #include "src/inspector/injected-script.h" | 7 #include "src/inspector/injected-script.h" |
| 8 #include "src/inspector/inspected-context.h" | 8 #include "src/inspector/inspected-context.h" |
| 9 #include "src/inspector/protocol/Protocol.h" | 9 #include "src/inspector/protocol/Protocol.h" |
| 10 #include "src/inspector/remote-object-id.h" | 10 #include "src/inspector/remote-object-id.h" |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 protocol::DictionaryValue* state = m_state->getObject(name); | 119 protocol::DictionaryValue* state = m_state->getObject(name); |
| 120 if (!state) { | 120 if (!state) { |
| 121 std::unique_ptr<protocol::DictionaryValue> newState = | 121 std::unique_ptr<protocol::DictionaryValue> newState = |
| 122 protocol::DictionaryValue::create(); | 122 protocol::DictionaryValue::create(); |
| 123 state = newState.get(); | 123 state = newState.get(); |
| 124 m_state->setObject(name, std::move(newState)); | 124 m_state->setObject(name, std::move(newState)); |
| 125 } | 125 } |
| 126 return state; | 126 return state; |
| 127 } | 127 } |
| 128 | 128 |
| 129 void V8InspectorSessionImpl::sendProtocolResponse(int callId, | 129 namespace { |
| 130 const String16& message) { | 130 |
| 131 m_channel->sendProtocolResponse(callId, toStringView(message)); | 131 class MessageBuffer : public StringBuffer { |
| 132 public: |
| 133 static std::unique_ptr<MessageBuffer> create( |
| 134 std::unique_ptr<protocol::Serializable> message) { |
| 135 return std::unique_ptr<MessageBuffer>( |
| 136 new MessageBuffer(std::move(message))); |
| 137 } |
| 138 |
| 139 const StringView& string() override { |
| 140 if (!m_serialized) { |
| 141 m_serialized = StringBuffer::create(toStringView(m_message->serialize())); |
| 142 m_message.reset(nullptr); |
| 143 } |
| 144 return m_serialized->string(); |
| 145 } |
| 146 |
| 147 private: |
| 148 explicit MessageBuffer(std::unique_ptr<protocol::Serializable> message) |
| 149 : m_message(std::move(message)) {} |
| 150 |
| 151 std::unique_ptr<protocol::Serializable> m_message; |
| 152 std::unique_ptr<StringBuffer> m_serialized; |
| 153 }; |
| 154 |
| 155 } // namespace |
| 156 |
| 157 void V8InspectorSessionImpl::sendProtocolResponse( |
| 158 int callId, std::unique_ptr<protocol::Serializable> message) { |
| 159 m_channel->sendResponse(callId, MessageBuffer::create(std::move(message))); |
| 132 } | 160 } |
| 133 | 161 |
| 134 void V8InspectorSessionImpl::sendProtocolNotification(const String16& message) { | 162 void V8InspectorSessionImpl::sendProtocolNotification( |
| 135 m_channel->sendProtocolNotification(toStringView(message)); | 163 std::unique_ptr<protocol::Serializable> message) { |
| 164 m_channel->sendNotification(MessageBuffer::create(std::move(message))); |
| 136 } | 165 } |
| 137 | 166 |
| 138 void V8InspectorSessionImpl::flushProtocolNotifications() { | 167 void V8InspectorSessionImpl::flushProtocolNotifications() { |
| 139 m_channel->flushProtocolNotifications(); | 168 m_channel->flushProtocolNotifications(); |
| 140 } | 169 } |
| 141 | 170 |
| 142 void V8InspectorSessionImpl::reset() { | 171 void V8InspectorSessionImpl::reset() { |
| 143 m_debuggerAgent->reset(); | 172 m_debuggerAgent->reset(); |
| 144 m_runtimeAgent->reset(); | 173 m_runtimeAgent->reset(); |
| 145 discardInjectedScripts(); | 174 discardInjectedScripts(); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 for (auto& idContext : *contexts) | 331 for (auto& idContext : *contexts) |
| 303 agent->reportExecutionContextCreated(idContext.second.get()); | 332 agent->reportExecutionContextCreated(idContext.second.get()); |
| 304 } | 333 } |
| 305 | 334 |
| 306 void V8InspectorSessionImpl::dispatchProtocolMessage( | 335 void V8InspectorSessionImpl::dispatchProtocolMessage( |
| 307 const StringView& message) { | 336 const StringView& message) { |
| 308 m_dispatcher.dispatch(protocol::StringUtil::parseJSON(message)); | 337 m_dispatcher.dispatch(protocol::StringUtil::parseJSON(message)); |
| 309 } | 338 } |
| 310 | 339 |
| 311 std::unique_ptr<StringBuffer> V8InspectorSessionImpl::stateJSON() { | 340 std::unique_ptr<StringBuffer> V8InspectorSessionImpl::stateJSON() { |
| 312 String16 json = m_state->toJSONString(); | 341 String16 json = m_state->serialize(); |
| 313 return StringBufferImpl::adopt(json); | 342 return StringBufferImpl::adopt(json); |
| 314 } | 343 } |
| 315 | 344 |
| 316 std::vector<std::unique_ptr<protocol::Schema::API::Domain>> | 345 std::vector<std::unique_ptr<protocol::Schema::API::Domain>> |
| 317 V8InspectorSessionImpl::supportedDomains() { | 346 V8InspectorSessionImpl::supportedDomains() { |
| 318 std::vector<std::unique_ptr<protocol::Schema::Domain>> domains = | 347 std::vector<std::unique_ptr<protocol::Schema::Domain>> domains = |
| 319 supportedDomainsImpl(); | 348 supportedDomainsImpl(); |
| 320 std::vector<std::unique_ptr<protocol::Schema::API::Domain>> result; | 349 std::vector<std::unique_ptr<protocol::Schema::API::Domain>> result; |
| 321 for (size_t i = 0; i < domains.size(); ++i) | 350 for (size_t i = 0; i < domains.size(); ++i) |
| 322 result.push_back(std::move(domains[i])); | 351 result.push_back(std::move(domains[i])); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> matches = | 427 std::vector<std::unique_ptr<protocol::Debugger::SearchMatch>> matches = |
| 399 searchInTextByLinesImpl(this, toString16(text), toString16(query), | 428 searchInTextByLinesImpl(this, toString16(text), toString16(query), |
| 400 caseSensitive, isRegex); | 429 caseSensitive, isRegex); |
| 401 std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>> result; | 430 std::vector<std::unique_ptr<protocol::Debugger::API::SearchMatch>> result; |
| 402 for (size_t i = 0; i < matches.size(); ++i) | 431 for (size_t i = 0; i < matches.size(); ++i) |
| 403 result.push_back(std::move(matches[i])); | 432 result.push_back(std::move(matches[i])); |
| 404 return result; | 433 return result; |
| 405 } | 434 } |
| 406 | 435 |
| 407 } // namespace v8_inspector | 436 } // namespace v8_inspector |
| OLD | NEW |