OLD | NEW |
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 <algorithm> | 5 #include <algorithm> |
6 #include <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/message_loop/message_loop_proxy.h" | 13 #include "base/message_loop/message_loop_proxy.h" |
14 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 #include "base/threading/thread.h" | 16 #include "base/threading/thread.h" |
17 #include "base/values.h" | 17 #include "base/values.h" |
18 #include "content/browser/devtools/devtools_manager.h" | 18 #include "content/browser/devtools/devtools_manager.h" |
19 #include "content/browser/devtools/devtools_protocol.h" | 19 #include "content/browser/devtools/devtools_protocol.h" |
20 #include "content/browser/devtools/devtools_protocol_constants.h" | 20 #include "content/browser/devtools/devtools_protocol_constants.h" |
21 #include "content/browser/devtools/devtools_system_info_handler.h" | |
22 #include "content/browser/devtools/protocol/devtools_protocol_handler_impl.h" | 21 #include "content/browser/devtools/protocol/devtools_protocol_handler_impl.h" |
| 22 #include "content/browser/devtools/protocol/system_info_handler.h" |
23 #include "content/browser/devtools/protocol/tethering_handler.h" | 23 #include "content/browser/devtools/protocol/tethering_handler.h" |
24 #include "content/browser/devtools/protocol/tracing_handler.h" | 24 #include "content/browser/devtools/protocol/tracing_handler.h" |
25 #include "content/common/devtools_messages.h" | 25 #include "content/common/devtools_messages.h" |
26 #include "content/public/browser/browser_thread.h" | 26 #include "content/public/browser/browser_thread.h" |
27 #include "content/public/browser/devtools_agent_host.h" | 27 #include "content/public/browser/devtools_agent_host.h" |
28 #include "content/public/browser/devtools_http_handler.h" | 28 #include "content/public/browser/devtools_http_handler.h" |
29 #include "content/public/browser/devtools_http_handler_delegate.h" | 29 #include "content/public/browser/devtools_http_handler_delegate.h" |
30 #include "content/public/browser/devtools_target.h" | 30 #include "content/public/browser/devtools_target.h" |
31 #include "content/public/common/content_client.h" | 31 #include "content/public/common/content_client.h" |
32 #include "content/public/common/url_constants.h" | 32 #include "content/public/common/url_constants.h" |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 | 406 |
407 class BrowserTarget { | 407 class BrowserTarget { |
408 public: | 408 public: |
409 BrowserTarget(base::MessageLoop* message_loop, | 409 BrowserTarget(base::MessageLoop* message_loop, |
410 ServerWrapper* server_wrapper, | 410 ServerWrapper* server_wrapper, |
411 DevToolsHttpHandlerDelegate* delegate, | 411 DevToolsHttpHandlerDelegate* delegate, |
412 int connection_id) | 412 int connection_id) |
413 : message_loop_(message_loop), | 413 : message_loop_(message_loop), |
414 server_wrapper_(server_wrapper), | 414 server_wrapper_(server_wrapper), |
415 connection_id_(connection_id), | 415 connection_id_(connection_id), |
| 416 system_info_handler_(new devtools::system_info::SystemInfoHandler()), |
416 tethering_handler_(new devtools::tethering::TetheringHandler( | 417 tethering_handler_(new devtools::tethering::TetheringHandler( |
417 delegate, message_loop->message_loop_proxy())), | 418 delegate, message_loop->message_loop_proxy())), |
418 tracing_handler_(new devtools::tracing::TracingHandler( | 419 tracing_handler_(new devtools::tracing::TracingHandler( |
419 devtools::tracing::TracingHandler::Browser)), | 420 devtools::tracing::TracingHandler::Browser)), |
420 protocol_handler_(new DevToolsProtocolHandlerImpl()) { | 421 protocol_handler_(new DevToolsProtocolHandlerImpl()) { |
421 protocol_handler_->SetNotifier( | 422 protocol_handler_->SetNotifier( |
422 base::Bind(&BrowserTarget::Respond, base::Unretained(this))); | 423 base::Bind(&BrowserTarget::Respond, base::Unretained(this))); |
| 424 protocol_handler_->SetSystemInfoHandler(system_info_handler_.get()); |
423 protocol_handler_->SetTetheringHandler(tethering_handler_.get()); | 425 protocol_handler_->SetTetheringHandler(tethering_handler_.get()); |
424 protocol_handler_->SetTracingHandler(tracing_handler_.get()); | 426 protocol_handler_->SetTracingHandler(tracing_handler_.get()); |
425 } | 427 } |
426 | 428 |
427 ~BrowserTarget() { | |
428 STLDeleteElements(&handlers_); | |
429 } | |
430 | |
431 // Takes ownership. | |
432 void RegisterHandler(DevToolsProtocol::Handler* handler) { | |
433 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
434 handler->SetNotifier( | |
435 base::Bind(&BrowserTarget::Respond, base::Unretained(this))); | |
436 handlers_.push_back(handler); | |
437 } | |
438 | |
439 void HandleMessage(const std::string& message) { | 429 void HandleMessage(const std::string& message) { |
440 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 430 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
441 std::string error_response; | 431 std::string error_response; |
442 scoped_refptr<DevToolsProtocol::Command> command = | 432 scoped_refptr<DevToolsProtocol::Command> command = |
443 DevToolsProtocol::ParseCommand(message, &error_response); | 433 DevToolsProtocol::ParseCommand(message, &error_response); |
444 if (!command.get()) { | 434 if (!command.get()) { |
445 Respond(error_response); | 435 Respond(error_response); |
446 return; | 436 return; |
447 } | 437 } |
448 | 438 |
449 scoped_refptr<DevToolsProtocol::Response> response = | 439 scoped_refptr<DevToolsProtocol::Response> response = |
450 protocol_handler_->HandleCommand(command); | 440 protocol_handler_->HandleCommand(command); |
451 for (const auto& handler : handlers_) { | |
452 if (response.get()) | |
453 break; | |
454 response = handler->HandleCommand(command); | |
455 } | |
456 | 441 |
457 if (response.get()) { | 442 if (response.get()) { |
458 if (!response->is_async_promise()) | 443 if (!response->is_async_promise()) |
459 Respond(response->Serialize()); | 444 Respond(response->Serialize()); |
460 } else { | 445 } else { |
461 Respond(command->NoSuchMethodErrorResponse()->Serialize()); | 446 Respond(command->NoSuchMethodErrorResponse()->Serialize()); |
462 } | 447 } |
463 } | 448 } |
464 | 449 |
465 void Respond(const std::string& message) { | 450 void Respond(const std::string& message) { |
466 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 451 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
467 message_loop_->PostTask( | 452 message_loop_->PostTask( |
468 FROM_HERE, | 453 FROM_HERE, |
469 base::Bind(&ServerWrapper::SendOverWebSocket, | 454 base::Bind(&ServerWrapper::SendOverWebSocket, |
470 base::Unretained(server_wrapper_), | 455 base::Unretained(server_wrapper_), |
471 connection_id_, | 456 connection_id_, |
472 message)); | 457 message)); |
473 } | 458 } |
474 | 459 |
475 private: | 460 private: |
476 base::MessageLoop* const message_loop_; | 461 base::MessageLoop* const message_loop_; |
477 ServerWrapper* const server_wrapper_; | 462 ServerWrapper* const server_wrapper_; |
478 const int connection_id_; | 463 const int connection_id_; |
| 464 scoped_ptr<devtools::system_info::SystemInfoHandler> system_info_handler_; |
479 scoped_ptr<devtools::tethering::TetheringHandler> tethering_handler_; | 465 scoped_ptr<devtools::tethering::TetheringHandler> tethering_handler_; |
480 scoped_ptr<devtools::tracing::TracingHandler> tracing_handler_; | 466 scoped_ptr<devtools::tracing::TracingHandler> tracing_handler_; |
481 scoped_ptr<DevToolsProtocolHandlerImpl> protocol_handler_; | 467 scoped_ptr<DevToolsProtocolHandlerImpl> protocol_handler_; |
482 std::vector<DevToolsProtocol::Handler*> handlers_; | |
483 }; | 468 }; |
484 | 469 |
485 } // namespace | 470 } // namespace |
486 | 471 |
487 // DevToolsHttpHandler ------------------------------------------------------- | 472 // DevToolsHttpHandler ------------------------------------------------------- |
488 | 473 |
489 // static | 474 // static |
490 bool DevToolsHttpHandler::IsSupportedProtocolVersion( | 475 bool DevToolsHttpHandler::IsSupportedProtocolVersion( |
491 const std::string& version) { | 476 const std::string& version) { |
492 return devtools::IsSupportedProtocolVersion(version); | 477 return devtools::IsSupportedProtocolVersion(version); |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 | 894 |
910 void DevToolsHttpHandlerImpl::OnWebSocketRequest( | 895 void DevToolsHttpHandlerImpl::OnWebSocketRequest( |
911 int connection_id, | 896 int connection_id, |
912 const net::HttpServerRequestInfo& request) { | 897 const net::HttpServerRequestInfo& request) { |
913 if (!thread_) | 898 if (!thread_) |
914 return; | 899 return; |
915 | 900 |
916 std::string browser_prefix = "/devtools/browser"; | 901 std::string browser_prefix = "/devtools/browser"; |
917 size_t browser_pos = request.path.find(browser_prefix); | 902 size_t browser_pos = request.path.find(browser_prefix); |
918 if (browser_pos == 0) { | 903 if (browser_pos == 0) { |
919 BrowserTarget* browser_target = new BrowserTarget(thread_->message_loop(), | 904 browser_targets_[connection_id] = new BrowserTarget(thread_->message_loop(), |
920 server_wrapper_, | 905 server_wrapper_, |
921 delegate_.get(), | 906 delegate_.get(), |
922 connection_id); | 907 connection_id); |
923 browser_target->RegisterHandler( | |
924 new DevToolsSystemInfoHandler()); | |
925 browser_targets_[connection_id] = browser_target; | |
926 AcceptWebSocket(connection_id, request); | 908 AcceptWebSocket(connection_id, request); |
927 return; | 909 return; |
928 } | 910 } |
929 | 911 |
930 size_t pos = request.path.find(kPageUrlPrefix); | 912 size_t pos = request.path.find(kPageUrlPrefix); |
931 if (pos != 0) { | 913 if (pos != 0) { |
932 Send404(connection_id); | 914 Send404(connection_id); |
933 return; | 915 return; |
934 } | 916 } |
935 | 917 |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1155 id.c_str(), | 1137 id.c_str(), |
1156 host); | 1138 host); |
1157 dictionary->SetString( | 1139 dictionary->SetString( |
1158 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); | 1140 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); |
1159 } | 1141 } |
1160 | 1142 |
1161 return dictionary; | 1143 return dictionary; |
1162 } | 1144 } |
1163 | 1145 |
1164 } // namespace content | 1146 } // namespace content |
OLD | NEW |