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/input_handler.h" |
| 12 #include "content/browser/devtools/protocol/inspector_handler.h" |
| 13 #include "content/browser/devtools/protocol/network_handler.h" |
| 14 #include "content/browser/devtools/protocol/page_handler.h" |
11 #include "content/browser/devtools/protocol/protocol.h" | 15 #include "content/browser/devtools/protocol/protocol.h" |
| 16 #include "content/browser/devtools/protocol/target_handler.h" |
| 17 #include "content/browser/devtools/protocol/tracing_handler.h" |
12 #include "content/public/browser/devtools_manager_delegate.h" | 18 #include "content/public/browser/devtools_manager_delegate.h" |
13 | 19 |
14 namespace content { | 20 namespace content { |
15 | 21 |
16 DevToolsSession::DevToolsSession( | 22 DevToolsSession::DevToolsSession( |
17 DevToolsAgentHostImpl* agent_host, | 23 DevToolsAgentHostImpl* agent_host, |
| 24 DevToolsAgentHostClient* client, |
18 int session_id) | 25 int session_id) |
19 : agent_host_(agent_host), | 26 : agent_host_(agent_host), |
| 27 client_(client), |
20 session_id_(session_id), | 28 session_id_(session_id), |
| 29 host_(nullptr), |
| 30 attached_(false), |
21 dispatcher_(new protocol::UberDispatcher(this)) { | 31 dispatcher_(new protocol::UberDispatcher(this)) { |
22 } | 32 } |
23 | 33 |
24 DevToolsSession::~DevToolsSession() {} | 34 DevToolsSession::~DevToolsSession() {} |
25 | 35 |
26 void DevToolsSession::ResetDispatcher() { | 36 void DevToolsSession::AddHandler( |
| 37 std::unique_ptr<protocol::DevToolsDomainHandler> handler) { |
| 38 handlers_[handler->name()] = std::move(handler); |
| 39 } |
| 40 |
| 41 void DevToolsSession::SetRenderFrameHost(RenderFrameHostImpl* host) { |
| 42 host_ = host; |
| 43 if (!attached_) |
| 44 return; |
| 45 for (auto& pair : handlers_) |
| 46 pair.second->SetRenderFrameHost(host_); |
| 47 } |
| 48 |
| 49 void DevToolsSession::SetFallThroughForNotFound(bool value) { |
| 50 dispatcher_->setFallThroughForNotFound(value); |
| 51 } |
| 52 |
| 53 void DevToolsSession::Attach() { |
| 54 for (auto& pair : handlers_) { |
| 55 pair.second->Wire(dispatcher_.get()); |
| 56 pair.second->SetRenderFrameHost(host_); |
| 57 } |
| 58 attached_ = true; |
| 59 } |
| 60 |
| 61 void DevToolsSession::Detach() { |
| 62 attached_ = false; |
27 dispatcher_.reset(); | 63 dispatcher_.reset(); |
| 64 for (auto& pair : handlers_) |
| 65 pair.second->Disable(); |
| 66 handlers_.clear(); |
28 } | 67 } |
29 | 68 |
30 protocol::Response::Status DevToolsSession::Dispatch( | 69 protocol::Response::Status DevToolsSession::Dispatch( |
31 const std::string& message, | 70 const std::string& message, |
| 71 bool offer_to_delegate, |
32 int* call_id, | 72 int* call_id, |
33 std::string* method) { | 73 std::string* method) { |
34 std::unique_ptr<base::Value> value = base::JSONReader::Read(message); | 74 std::unique_ptr<base::Value> value = base::JSONReader::Read(message); |
35 | 75 |
36 DevToolsManagerDelegate* delegate = | 76 DevToolsManagerDelegate* delegate = |
37 DevToolsManager::GetInstance()->delegate(); | 77 DevToolsManager::GetInstance()->delegate(); |
38 if (value && value->IsType(base::Value::Type::DICTIONARY) && delegate) { | 78 if (value && value->IsType(base::Value::Type::DICTIONARY) && delegate) { |
39 std::unique_ptr<base::DictionaryValue> response(delegate->HandleCommand( | 79 std::unique_ptr<base::DictionaryValue> response(delegate->HandleCommand( |
40 agent_host_, | 80 agent_host_, |
41 static_cast<base::DictionaryValue*>(value.get()))); | 81 static_cast<base::DictionaryValue*>(value.get()))); |
(...skipping 16 matching lines...) Expand all Loading... |
58 } | 98 } |
59 | 99 |
60 void DevToolsSession::sendProtocolNotification( | 100 void DevToolsSession::sendProtocolNotification( |
61 std::unique_ptr<protocol::Serializable> message) { | 101 std::unique_ptr<protocol::Serializable> message) { |
62 agent_host_->SendMessageToClient(session_id_, message->serialize()); | 102 agent_host_->SendMessageToClient(session_id_, message->serialize()); |
63 } | 103 } |
64 | 104 |
65 void DevToolsSession::flushProtocolNotifications() { | 105 void DevToolsSession::flushProtocolNotifications() { |
66 } | 106 } |
67 | 107 |
| 108 protocol::DevToolsDomainHandler* DevToolsSession::GetHandlerByName( |
| 109 const std::string& name) { |
| 110 auto it = handlers_.find(name); |
| 111 if (it == handlers_.end()) |
| 112 return nullptr; |
| 113 return it->second.get(); |
| 114 } |
| 115 |
| 116 protocol::InputHandler* DevToolsSession::GetInputHandler() { |
| 117 return static_cast<protocol::InputHandler*>( |
| 118 GetHandlerByName(protocol::Input::Metainfo::domainName)); |
| 119 } |
| 120 |
| 121 protocol::InspectorHandler* DevToolsSession::GetInspectorHandler() { |
| 122 return static_cast<protocol::InspectorHandler*>( |
| 123 GetHandlerByName(protocol::Inspector::Metainfo::domainName)); |
| 124 } |
| 125 |
| 126 protocol::NetworkHandler* DevToolsSession::GetNetworkHandler() { |
| 127 return static_cast<protocol::NetworkHandler*>( |
| 128 GetHandlerByName(protocol::Network::Metainfo::domainName)); |
| 129 } |
| 130 |
| 131 protocol::PageHandler* DevToolsSession::GetPageHandler() { |
| 132 return static_cast<protocol::PageHandler*>( |
| 133 GetHandlerByName(protocol::Page::Metainfo::domainName)); |
| 134 } |
| 135 |
| 136 protocol::TargetHandler* DevToolsSession::GetTargetHandler() { |
| 137 return static_cast<protocol::TargetHandler*>( |
| 138 GetHandlerByName(protocol::Target::Metainfo::domainName)); |
| 139 } |
| 140 |
| 141 protocol::TracingHandler* DevToolsSession::GetTracingHandler() { |
| 142 return static_cast<protocol::TracingHandler*>( |
| 143 GetHandlerByName(protocol::Tracing::Metainfo::domainName)); |
| 144 } |
| 145 |
68 } // namespace content | 146 } // namespace content |
OLD | NEW |