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" | |
caseq
2016/12/23 00:38:41
These should hopefully no longer be necessary :-)
dgozman
2016/12/27 20:01:52
Done.
| |
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), | |
21 dispatcher_(new protocol::UberDispatcher(this)) { | 30 dispatcher_(new protocol::UberDispatcher(this)) { |
22 } | 31 } |
23 | 32 |
24 DevToolsSession::~DevToolsSession() {} | 33 DevToolsSession::~DevToolsSession() { |
34 dispatcher_.reset(); | |
35 for (auto& pair : handlers_) | |
36 pair.second->Disable(); | |
37 handlers_.clear(); | |
38 } | |
25 | 39 |
26 void DevToolsSession::ResetDispatcher() { | 40 void DevToolsSession::AddHandler( |
27 dispatcher_.reset(); | 41 std::unique_ptr<protocol::DevToolsDomainHandler> handler) { |
42 handler->Wire(dispatcher_.get()); | |
43 handler->SetRenderFrameHost(host_); | |
44 handlers_[handler->name()] = std::move(handler); | |
45 } | |
46 | |
47 void DevToolsSession::SetRenderFrameHost(RenderFrameHostImpl* host) { | |
48 host_ = host; | |
49 for (auto& pair : handlers_) | |
50 pair.second->SetRenderFrameHost(host_); | |
51 } | |
52 | |
53 void DevToolsSession::SetFallThroughForNotFound(bool value) { | |
54 dispatcher_->setFallThroughForNotFound(value); | |
28 } | 55 } |
29 | 56 |
30 protocol::Response::Status DevToolsSession::Dispatch( | 57 protocol::Response::Status DevToolsSession::Dispatch( |
31 const std::string& message, | 58 const std::string& message, |
59 bool offer_to_delegate, | |
32 int* call_id, | 60 int* call_id, |
33 std::string* method) { | 61 std::string* method) { |
34 std::unique_ptr<base::Value> value = base::JSONReader::Read(message); | 62 std::unique_ptr<base::Value> value = base::JSONReader::Read(message); |
35 | 63 |
36 DevToolsManagerDelegate* delegate = | 64 DevToolsManagerDelegate* delegate = offer_to_delegate ? |
37 DevToolsManager::GetInstance()->delegate(); | 65 DevToolsManager::GetInstance()->delegate() : nullptr; |
38 if (value && value->IsType(base::Value::Type::DICTIONARY) && delegate) { | 66 if (value && value->IsType(base::Value::Type::DICTIONARY) && delegate) { |
39 std::unique_ptr<base::DictionaryValue> response(delegate->HandleCommand( | 67 std::unique_ptr<base::DictionaryValue> response(delegate->HandleCommand( |
40 agent_host_, | 68 agent_host_, |
41 static_cast<base::DictionaryValue*>(value.get()))); | 69 static_cast<base::DictionaryValue*>(value.get()))); |
42 if (response) { | 70 if (response) { |
43 std::string json; | 71 std::string json; |
44 base::JSONWriter::Write(*response.get(), &json); | 72 base::JSONWriter::Write(*response.get(), &json); |
45 agent_host_->SendMessageToClient(session_id_, json); | 73 agent_host_->SendMessageToClient(session_id_, json); |
46 return protocol::Response::kSuccess; | 74 return protocol::Response::kSuccess; |
47 } | 75 } |
(...skipping 10 matching lines...) Expand all Loading... | |
58 } | 86 } |
59 | 87 |
60 void DevToolsSession::sendProtocolNotification( | 88 void DevToolsSession::sendProtocolNotification( |
61 std::unique_ptr<protocol::Serializable> message) { | 89 std::unique_ptr<protocol::Serializable> message) { |
62 agent_host_->SendMessageToClient(session_id_, message->serialize()); | 90 agent_host_->SendMessageToClient(session_id_, message->serialize()); |
63 } | 91 } |
64 | 92 |
65 void DevToolsSession::flushProtocolNotifications() { | 93 void DevToolsSession::flushProtocolNotifications() { |
66 } | 94 } |
67 | 95 |
96 protocol::DevToolsDomainHandler* DevToolsSession::GetHandlerByName( | |
97 const std::string& name) { | |
98 auto it = handlers_.find(name); | |
99 if (it == handlers_.end()) | |
100 return nullptr; | |
101 return it->second.get(); | |
102 } | |
103 | |
68 } // namespace content | 104 } // namespace content |
OLD | NEW |