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

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

Issue 665123002: [DevTools] Move SystemInfo domain to generated handler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@browserProtocol
Patch Set: Created 6 years, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_http_handler_impl.h" 5 #include "content/browser/devtools/devtools_http_handler_impl.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/compiler_specific.h" 11 #include "base/compiler_specific.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/json/json_writer.h" 13 #include "base/json/json_writer.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/message_loop/message_loop_proxy.h" 15 #include "base/message_loop/message_loop_proxy.h"
16 #include "base/stl_util.h" 16 #include "base/stl_util.h"
17 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
18 #include "base/threading/thread.h" 18 #include "base/threading/thread.h"
19 #include "base/values.h" 19 #include "base/values.h"
20 #include "content/browser/devtools/devtools_manager.h" 20 #include "content/browser/devtools/devtools_manager.h"
21 #include "content/browser/devtools/devtools_protocol.h" 21 #include "content/browser/devtools/devtools_protocol.h"
22 #include "content/browser/devtools/devtools_protocol_constants.h" 22 #include "content/browser/devtools/devtools_protocol_constants.h"
23 #include "content/browser/devtools/devtools_system_info_handler.h"
24 #include "content/browser/devtools/protocol/devtools_protocol_handler_impl.h" 23 #include "content/browser/devtools/protocol/devtools_protocol_handler_impl.h"
24 #include "content/browser/devtools/protocol/system_info_handler.h"
25 #include "content/browser/devtools/protocol/tethering_handler.h" 25 #include "content/browser/devtools/protocol/tethering_handler.h"
26 #include "content/browser/devtools/protocol/tracing_handler.h" 26 #include "content/browser/devtools/protocol/tracing_handler.h"
27 #include "content/common/devtools_messages.h" 27 #include "content/common/devtools_messages.h"
28 #include "content/public/browser/browser_thread.h" 28 #include "content/public/browser/browser_thread.h"
29 #include "content/public/browser/devtools_agent_host.h" 29 #include "content/public/browser/devtools_agent_host.h"
30 #include "content/public/browser/devtools_http_handler_delegate.h" 30 #include "content/public/browser/devtools_http_handler_delegate.h"
31 #include "content/public/browser/devtools_target.h" 31 #include "content/public/browser/devtools_target.h"
32 #include "content/public/common/content_client.h" 32 #include "content/public/common/content_client.h"
33 #include "content/public/common/url_constants.h" 33 #include "content/public/common/url_constants.h"
34 #include "content/public/common/user_agent.h" 34 #include "content/public/common/user_agent.h"
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 154
155 class DevToolsHttpHandlerImpl::BrowserTarget { 155 class DevToolsHttpHandlerImpl::BrowserTarget {
156 public: 156 public:
157 BrowserTarget(base::MessageLoop* message_loop, 157 BrowserTarget(base::MessageLoop* message_loop,
158 net::HttpServer* server, 158 net::HttpServer* server,
159 DevToolsHttpHandlerDelegate* delegate, 159 DevToolsHttpHandlerDelegate* delegate,
160 int connection_id) 160 int connection_id)
161 : message_loop_(message_loop), 161 : message_loop_(message_loop),
162 server_(server), 162 server_(server),
163 connection_id_(connection_id), 163 connection_id_(connection_id),
164 system_info_handler_(new devtools::system_info::SystemInfoHandler()),
164 tethering_handler_(new devtools::tethering::TetheringHandler( 165 tethering_handler_(new devtools::tethering::TetheringHandler(
165 delegate, message_loop->message_loop_proxy())), 166 delegate, message_loop->message_loop_proxy())),
166 tracing_handler_(new devtools::tracing::TracingHandler( 167 tracing_handler_(new devtools::tracing::TracingHandler(
167 devtools::tracing::TracingHandler::Browser)), 168 devtools::tracing::TracingHandler::Browser)),
168 protocol_handler_(new DevToolsProtocolHandlerImpl()) { 169 protocol_handler_(new DevToolsProtocolHandlerImpl()) {
169 protocol_handler_->SetNotifier( 170 protocol_handler_->SetNotifier(
170 base::Bind(&BrowserTarget::Respond, base::Unretained(this))); 171 base::Bind(&BrowserTarget::Respond, base::Unretained(this)));
172 protocol_handler_->SetSystemInfoHandler(system_info_handler_.get());
171 protocol_handler_->SetTetheringHandler(tethering_handler_.get()); 173 protocol_handler_->SetTetheringHandler(tethering_handler_.get());
172 protocol_handler_->SetTracingHandler(tracing_handler_.get()); 174 protocol_handler_->SetTracingHandler(tracing_handler_.get());
173 } 175 }
174 176
175 ~BrowserTarget() {
176 STLDeleteElements(&handlers_);
177 }
178
179 // Takes ownership. 177 // Takes ownership.
dgozman 2014/10/28 10:19:58 Obsolete comment.
vkuzkokov 2014/10/28 11:57:50 Done.
180 void RegisterHandler(DevToolsProtocol::Handler* handler) {
181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
182 handler->SetNotifier(
183 base::Bind(&BrowserTarget::Respond, base::Unretained(this)));
184 handlers_.push_back(handler);
185 }
186
187 void HandleMessage(const std::string& message) { 178 void HandleMessage(const std::string& message) {
188 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 179 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
189 std::string error_response; 180 std::string error_response;
190 scoped_refptr<DevToolsProtocol::Command> command = 181 scoped_refptr<DevToolsProtocol::Command> command =
191 DevToolsProtocol::ParseCommand(message, &error_response); 182 DevToolsProtocol::ParseCommand(message, &error_response);
192 if (!command.get()) { 183 if (!command.get()) {
193 Respond(error_response); 184 Respond(error_response);
194 return; 185 return;
195 } 186 }
196 187
197 scoped_refptr<DevToolsProtocol::Response> response = 188 scoped_refptr<DevToolsProtocol::Response> response =
198 protocol_handler_->HandleCommand(command); 189 protocol_handler_->HandleCommand(command);
199 for (const auto& handler : handlers_) {
200 if (response.get())
201 break;
202 response = handler->HandleCommand(command);
203 }
204 190
205 if (response.get()) { 191 if (response.get()) {
206 if (!response->is_async_promise()) 192 if (!response->is_async_promise())
207 Respond(response->Serialize()); 193 Respond(response->Serialize());
208 } else { 194 } else {
209 Respond(command->NoSuchMethodErrorResponse()->Serialize()); 195 Respond(command->NoSuchMethodErrorResponse()->Serialize());
210 } 196 }
211 } 197 }
212 198
213 void Respond(const std::string& message) { 199 void Respond(const std::string& message) {
214 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 200 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
215 message_loop_->PostTask( 201 message_loop_->PostTask(
216 FROM_HERE, 202 FROM_HERE,
217 base::Bind(&net::HttpServer::SendOverWebSocket, 203 base::Bind(&net::HttpServer::SendOverWebSocket,
218 base::Unretained(server_), 204 base::Unretained(server_),
219 connection_id_, 205 connection_id_,
220 message)); 206 message));
221 } 207 }
222 208
223 private: 209 private:
224 base::MessageLoop* const message_loop_; 210 base::MessageLoop* const message_loop_;
225 net::HttpServer* const server_; 211 net::HttpServer* const server_;
226 const int connection_id_; 212 const int connection_id_;
213 scoped_ptr<devtools::system_info::SystemInfoHandler> system_info_handler_;
227 scoped_ptr<devtools::tethering::TetheringHandler> tethering_handler_; 214 scoped_ptr<devtools::tethering::TetheringHandler> tethering_handler_;
228 scoped_ptr<devtools::tracing::TracingHandler> tracing_handler_; 215 scoped_ptr<devtools::tracing::TracingHandler> tracing_handler_;
229 scoped_ptr<DevToolsProtocolHandlerImpl> protocol_handler_; 216 scoped_ptr<DevToolsProtocolHandlerImpl> protocol_handler_;
230 std::vector<DevToolsProtocol::Handler*> handlers_;
231 }; 217 };
232 218
233 // DevToolsHttpHandler ------------------------------------------------------- 219 // DevToolsHttpHandler -------------------------------------------------------
234 220
235 // static 221 // static
236 bool DevToolsHttpHandler::IsSupportedProtocolVersion( 222 bool DevToolsHttpHandler::IsSupportedProtocolVersion(
237 const std::string& version) { 223 const std::string& version) {
238 return devtools::IsSupportedProtocolVersion(version); 224 return devtools::IsSupportedProtocolVersion(version);
239 } 225 }
240 226
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after
698 684
699 void DevToolsHttpHandlerImpl::OnWebSocketRequestUI( 685 void DevToolsHttpHandlerImpl::OnWebSocketRequestUI(
700 int connection_id, 686 int connection_id,
701 const net::HttpServerRequestInfo& request) { 687 const net::HttpServerRequestInfo& request) {
702 if (!thread_) 688 if (!thread_)
703 return; 689 return;
704 690
705 std::string browser_prefix = "/devtools/browser"; 691 std::string browser_prefix = "/devtools/browser";
706 size_t browser_pos = request.path.find(browser_prefix); 692 size_t browser_pos = request.path.find(browser_prefix);
707 if (browser_pos == 0) { 693 if (browser_pos == 0) {
708 BrowserTarget* browser_target = new BrowserTarget( 694 browser_targets_[connection_id] = new BrowserTarget(
709 thread_->message_loop(), server_.get(), delegate_.get(), connection_id); 695 thread_->message_loop(), server_.get(), delegate_.get(), connection_id);
710 browser_target->RegisterHandler(
711 new DevToolsSystemInfoHandler());
712 browser_targets_[connection_id] = browser_target;
713 AcceptWebSocket(connection_id, request); 696 AcceptWebSocket(connection_id, request);
714 return; 697 return;
715 } 698 }
716 699
717 size_t pos = request.path.find(kPageUrlPrefix); 700 size_t pos = request.path.find(kPageUrlPrefix);
718 if (pos != 0) { 701 if (pos != 0) {
719 Send404(connection_id); 702 Send404(connection_id);
720 return; 703 return;
721 } 704 }
722 705
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 id.c_str(), 955 id.c_str(),
973 host); 956 host);
974 dictionary->SetString( 957 dictionary->SetString(
975 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); 958 kTargetDevtoolsFrontendUrlField, devtools_frontend_url);
976 } 959 }
977 960
978 return dictionary; 961 return dictionary;
979 } 962 }
980 963
981 } // namespace content 964 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698