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" | 7 #include "base/json/json_reader.h" |
8 #include "base/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
9 #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" | 10 #include "content/browser/devtools/devtools_manager.h" |
11 #include "content/browser/devtools/protocol/protocol.h" | 11 #include "content/browser/devtools/protocol/protocol.h" |
12 #include "content/public/browser/devtools_manager_delegate.h" | 12 #include "content/public/browser/devtools_manager_delegate.h" |
13 | 13 |
14 namespace content { | 14 namespace content { |
15 | 15 |
16 DevToolsSession::DevToolsSession( | 16 DevToolsSession::DevToolsSession( |
17 DevToolsAgentHostImpl* agent_host, | 17 DevToolsAgentHostImpl* agent_host, |
| 18 DevToolsAgentHostClient* client, |
18 int session_id) | 19 int session_id) |
19 : agent_host_(agent_host), | 20 : agent_host_(agent_host), |
| 21 client_(client), |
20 session_id_(session_id), | 22 session_id_(session_id), |
| 23 host_(nullptr), |
21 dispatcher_(new protocol::UberDispatcher(this)) { | 24 dispatcher_(new protocol::UberDispatcher(this)) { |
22 } | 25 } |
23 | 26 |
24 DevToolsSession::~DevToolsSession() {} | 27 DevToolsSession::~DevToolsSession() { |
| 28 dispatcher_.reset(); |
| 29 for (auto& pair : handlers_) |
| 30 pair.second->Disable(); |
| 31 handlers_.clear(); |
| 32 } |
25 | 33 |
26 void DevToolsSession::ResetDispatcher() { | 34 void DevToolsSession::AddHandler( |
27 dispatcher_.reset(); | 35 std::unique_ptr<protocol::DevToolsDomainHandler> handler) { |
| 36 handler->Wire(dispatcher_.get()); |
| 37 handler->SetRenderFrameHost(host_); |
| 38 handlers_[handler->name()] = std::move(handler); |
| 39 } |
| 40 |
| 41 void DevToolsSession::SetRenderFrameHost(RenderFrameHostImpl* host) { |
| 42 host_ = host; |
| 43 for (auto& pair : handlers_) |
| 44 pair.second->SetRenderFrameHost(host_); |
| 45 } |
| 46 |
| 47 void DevToolsSession::SetFallThroughForNotFound(bool value) { |
| 48 dispatcher_->setFallThroughForNotFound(value); |
28 } | 49 } |
29 | 50 |
30 protocol::Response::Status DevToolsSession::Dispatch( | 51 protocol::Response::Status DevToolsSession::Dispatch( |
31 const std::string& message, | 52 const std::string& message, |
| 53 bool offer_to_delegate, |
32 int* call_id, | 54 int* call_id, |
33 std::string* method) { | 55 std::string* method) { |
34 std::unique_ptr<base::Value> value = base::JSONReader::Read(message); | 56 std::unique_ptr<base::Value> value = base::JSONReader::Read(message); |
35 | 57 |
36 DevToolsManagerDelegate* delegate = | 58 DevToolsManagerDelegate* delegate = offer_to_delegate ? |
37 DevToolsManager::GetInstance()->delegate(); | 59 DevToolsManager::GetInstance()->delegate() : nullptr; |
38 if (value && value->IsType(base::Value::Type::DICTIONARY) && delegate) { | 60 if (value && value->IsType(base::Value::Type::DICTIONARY) && delegate) { |
39 std::unique_ptr<base::DictionaryValue> response(delegate->HandleCommand( | 61 std::unique_ptr<base::DictionaryValue> response(delegate->HandleCommand( |
40 agent_host_, | 62 agent_host_, |
41 static_cast<base::DictionaryValue*>(value.get()))); | 63 static_cast<base::DictionaryValue*>(value.get()))); |
42 if (response) { | 64 if (response) { |
43 std::string json; | 65 std::string json; |
44 base::JSONWriter::Write(*response.get(), &json); | 66 base::JSONWriter::Write(*response.get(), &json); |
45 agent_host_->SendMessageToClient(session_id_, json); | 67 agent_host_->SendMessageToClient(session_id_, json); |
46 return protocol::Response::kSuccess; | 68 return protocol::Response::kSuccess; |
47 } | 69 } |
(...skipping 10 matching lines...) Expand all Loading... |
58 } | 80 } |
59 | 81 |
60 void DevToolsSession::sendProtocolNotification( | 82 void DevToolsSession::sendProtocolNotification( |
61 std::unique_ptr<protocol::Serializable> message) { | 83 std::unique_ptr<protocol::Serializable> message) { |
62 agent_host_->SendMessageToClient(session_id_, message->serialize()); | 84 agent_host_->SendMessageToClient(session_id_, message->serialize()); |
63 } | 85 } |
64 | 86 |
65 void DevToolsSession::flushProtocolNotifications() { | 87 void DevToolsSession::flushProtocolNotifications() { |
66 } | 88 } |
67 | 89 |
| 90 protocol::DevToolsDomainHandler* DevToolsSession::GetHandlerByName( |
| 91 const std::string& name) { |
| 92 auto it = handlers_.find(name); |
| 93 if (it == handlers_.end()) |
| 94 return nullptr; |
| 95 return it->second.get(); |
| 96 } |
| 97 |
68 } // namespace content | 98 } // namespace content |
OLD | NEW |