Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: content/browser/devtools/devtools_session.cc

Issue 2590293003: [DevTools] Rework DevToolsSession interaction with domain handlers. (Closed)
Patch Set: addressed comments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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),
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,
caseq 2016/12/21 23:17:27 remove this?
dgozman 2016/12/22 06:26:13 Ops, I meant to use it actually.
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 =
37 DevToolsManager::GetInstance()->delegate(); 65 DevToolsManager::GetInstance()->delegate();
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())));
(...skipping 16 matching lines...) Expand all
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
104 protocol::InputHandler* DevToolsSession::GetInputHandler() {
105 return static_cast<protocol::InputHandler*>(
106 GetHandlerByName(protocol::Input::Metainfo::domainName));
107 }
108
109 protocol::InspectorHandler* DevToolsSession::GetInspectorHandler() {
110 return static_cast<protocol::InspectorHandler*>(
111 GetHandlerByName(protocol::Inspector::Metainfo::domainName));
112 }
113
114 protocol::NetworkHandler* DevToolsSession::GetNetworkHandler() {
115 return static_cast<protocol::NetworkHandler*>(
116 GetHandlerByName(protocol::Network::Metainfo::domainName));
117 }
118
119 protocol::PageHandler* DevToolsSession::GetPageHandler() {
120 return static_cast<protocol::PageHandler*>(
121 GetHandlerByName(protocol::Page::Metainfo::domainName));
122 }
123
124 protocol::TargetHandler* DevToolsSession::GetTargetHandler() {
125 return static_cast<protocol::TargetHandler*>(
126 GetHandlerByName(protocol::Target::Metainfo::domainName));
127 }
128
129 protocol::TracingHandler* DevToolsSession::GetTracingHandler() {
130 return static_cast<protocol::TracingHandler*>(
131 GetHandlerByName(protocol::Tracing::Metainfo::domainName));
132 }
133
68 } // namespace content 134 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698