| 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 "content/browser/devtools/devtools_session.h" | 5 #include "content/browser/devtools/devtools_session.h" |
| 6 | 6 |
| 7 #include "base/json/json_reader.h" |
| 8 #include "base/json/json_writer.h" |
| 7 #include "content/browser/devtools/devtools_agent_host_impl.h" | 9 #include "content/browser/devtools/devtools_agent_host_impl.h" |
| 10 #include "content/browser/devtools/devtools_manager.h" |
| 8 #include "content/browser/devtools/protocol/protocol.h" | 11 #include "content/browser/devtools/protocol/protocol.h" |
| 12 #include "content/public/browser/devtools_manager_delegate.h" |
| 9 | 13 |
| 10 namespace content { | 14 namespace content { |
| 11 | 15 |
| 12 DevToolsSession::DevToolsSession( | 16 DevToolsSession::DevToolsSession( |
| 13 DevToolsAgentHostImpl* agent_host, | 17 DevToolsAgentHostImpl* agent_host, |
| 14 int session_id) | 18 int session_id) |
| 15 : agent_host_(agent_host), | 19 : agent_host_(agent_host), |
| 16 session_id_(session_id), | 20 session_id_(session_id), |
| 17 dispatcher_(new protocol::UberDispatcher(this)) { | 21 dispatcher_(new protocol::UberDispatcher(this)) { |
| 18 } | 22 } |
| 19 | 23 |
| 20 DevToolsSession::~DevToolsSession() {} | 24 DevToolsSession::~DevToolsSession() {} |
| 21 | 25 |
| 22 void DevToolsSession::ResetDispatcher() { | 26 void DevToolsSession::ResetDispatcher() { |
| 23 dispatcher_.reset(); | 27 dispatcher_.reset(); |
| 24 } | 28 } |
| 25 | 29 |
| 30 protocol::Response::Status DevToolsSession::Dispatch( |
| 31 const std::string& message, |
| 32 int* call_id, |
| 33 std::string* method) { |
| 34 std::unique_ptr<base::Value> value = base::JSONReader::Read(message); |
| 35 |
| 36 DevToolsManagerDelegate* delegate = |
| 37 DevToolsManager::GetInstance()->delegate(); |
| 38 if (value && value->IsType(base::Value::Type::DICTIONARY) && delegate) { |
| 39 std::unique_ptr<base::DictionaryValue> response(delegate->HandleCommand( |
| 40 agent_host_, |
| 41 static_cast<base::DictionaryValue*>(value.get()))); |
| 42 if (response) { |
| 43 std::string json; |
| 44 base::JSONWriter::Write(*response.get(), &json); |
| 45 agent_host_->SendMessageToClient(session_id_, json); |
| 46 return protocol::Response::kSuccess; |
| 47 } |
| 48 } |
| 49 |
| 50 return dispatcher_->dispatch(protocol::toProtocolValue(value.get(), 1000), |
| 51 call_id, method); |
| 52 } |
| 53 |
| 26 void DevToolsSession::sendProtocolResponse( | 54 void DevToolsSession::sendProtocolResponse( |
| 27 int call_id, | 55 int call_id, |
| 28 std::unique_ptr<protocol::Serializable> message) { | 56 std::unique_ptr<protocol::Serializable> message) { |
| 29 agent_host_->SendMessageToClient(session_id_, message->serialize()); | 57 agent_host_->SendMessageToClient(session_id_, message->serialize()); |
| 30 } | 58 } |
| 31 | 59 |
| 32 void DevToolsSession::sendProtocolNotification( | 60 void DevToolsSession::sendProtocolNotification( |
| 33 std::unique_ptr<protocol::Serializable> message) { | 61 std::unique_ptr<protocol::Serializable> message) { |
| 34 agent_host_->SendMessageToClient(session_id_, message->serialize()); | 62 agent_host_->SendMessageToClient(session_id_, message->serialize()); |
| 35 } | 63 } |
| 36 | 64 |
| 37 void DevToolsSession::flushProtocolNotifications() { | 65 void DevToolsSession::flushProtocolNotifications() { |
| 38 } | 66 } |
| 39 | 67 |
| 40 } // namespace content | 68 } // namespace content |
| OLD | NEW |