| 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" |
| 21 #include "content/browser/devtools/protocol/devtools_protocol_handler_impl.h" | 22 #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()), | |
| 417 tethering_handler_(new devtools::tethering::TetheringHandler( | 416 tethering_handler_(new devtools::tethering::TetheringHandler( |
| 418 delegate, message_loop->message_loop_proxy())), | 417 delegate, message_loop->message_loop_proxy())), |
| 419 tracing_handler_(new devtools::tracing::TracingHandler( | 418 tracing_handler_(new devtools::tracing::TracingHandler( |
| 420 devtools::tracing::TracingHandler::Browser)), | 419 devtools::tracing::TracingHandler::Browser)), |
| 421 protocol_handler_(new DevToolsProtocolHandlerImpl()) { | 420 protocol_handler_(new DevToolsProtocolHandlerImpl()) { |
| 422 protocol_handler_->SetNotifier( | 421 protocol_handler_->SetNotifier( |
| 423 base::Bind(&BrowserTarget::Respond, base::Unretained(this))); | 422 base::Bind(&BrowserTarget::Respond, base::Unretained(this))); |
| 424 protocol_handler_->SetSystemInfoHandler(system_info_handler_.get()); | |
| 425 protocol_handler_->SetTetheringHandler(tethering_handler_.get()); | 423 protocol_handler_->SetTetheringHandler(tethering_handler_.get()); |
| 426 protocol_handler_->SetTracingHandler(tracing_handler_.get()); | 424 protocol_handler_->SetTracingHandler(tracing_handler_.get()); |
| 427 } | 425 } |
| 428 | 426 |
| 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 |
| 429 void HandleMessage(const std::string& message) { | 439 void HandleMessage(const std::string& message) { |
| 430 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 440 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 431 std::string error_response; | 441 std::string error_response; |
| 432 scoped_refptr<DevToolsProtocol::Command> command = | 442 scoped_refptr<DevToolsProtocol::Command> command = |
| 433 DevToolsProtocol::ParseCommand(message, &error_response); | 443 DevToolsProtocol::ParseCommand(message, &error_response); |
| 434 if (!command.get()) { | 444 if (!command.get()) { |
| 435 Respond(error_response); | 445 Respond(error_response); |
| 436 return; | 446 return; |
| 437 } | 447 } |
| 438 | 448 |
| 439 scoped_refptr<DevToolsProtocol::Response> response = | 449 scoped_refptr<DevToolsProtocol::Response> response = |
| 440 protocol_handler_->HandleCommand(command); | 450 protocol_handler_->HandleCommand(command); |
| 451 for (const auto& handler : handlers_) { |
| 452 if (response.get()) |
| 453 break; |
| 454 response = handler->HandleCommand(command); |
| 455 } |
| 441 | 456 |
| 442 if (response.get()) { | 457 if (response.get()) { |
| 443 if (!response->is_async_promise()) | 458 if (!response->is_async_promise()) |
| 444 Respond(response->Serialize()); | 459 Respond(response->Serialize()); |
| 445 } else { | 460 } else { |
| 446 Respond(command->NoSuchMethodErrorResponse()->Serialize()); | 461 Respond(command->NoSuchMethodErrorResponse()->Serialize()); |
| 447 } | 462 } |
| 448 } | 463 } |
| 449 | 464 |
| 450 void Respond(const std::string& message) { | 465 void Respond(const std::string& message) { |
| 451 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 466 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 452 message_loop_->PostTask( | 467 message_loop_->PostTask( |
| 453 FROM_HERE, | 468 FROM_HERE, |
| 454 base::Bind(&ServerWrapper::SendOverWebSocket, | 469 base::Bind(&ServerWrapper::SendOverWebSocket, |
| 455 base::Unretained(server_wrapper_), | 470 base::Unretained(server_wrapper_), |
| 456 connection_id_, | 471 connection_id_, |
| 457 message)); | 472 message)); |
| 458 } | 473 } |
| 459 | 474 |
| 460 private: | 475 private: |
| 461 base::MessageLoop* const message_loop_; | 476 base::MessageLoop* const message_loop_; |
| 462 ServerWrapper* const server_wrapper_; | 477 ServerWrapper* const server_wrapper_; |
| 463 const int connection_id_; | 478 const int connection_id_; |
| 464 scoped_ptr<devtools::system_info::SystemInfoHandler> system_info_handler_; | |
| 465 scoped_ptr<devtools::tethering::TetheringHandler> tethering_handler_; | 479 scoped_ptr<devtools::tethering::TetheringHandler> tethering_handler_; |
| 466 scoped_ptr<devtools::tracing::TracingHandler> tracing_handler_; | 480 scoped_ptr<devtools::tracing::TracingHandler> tracing_handler_; |
| 467 scoped_ptr<DevToolsProtocolHandlerImpl> protocol_handler_; | 481 scoped_ptr<DevToolsProtocolHandlerImpl> protocol_handler_; |
| 482 std::vector<DevToolsProtocol::Handler*> handlers_; |
| 468 }; | 483 }; |
| 469 | 484 |
| 470 } // namespace | 485 } // namespace |
| 471 | 486 |
| 472 // DevToolsHttpHandler ------------------------------------------------------- | 487 // DevToolsHttpHandler ------------------------------------------------------- |
| 473 | 488 |
| 474 // static | 489 // static |
| 475 bool DevToolsHttpHandler::IsSupportedProtocolVersion( | 490 bool DevToolsHttpHandler::IsSupportedProtocolVersion( |
| 476 const std::string& version) { | 491 const std::string& version) { |
| 477 return devtools::IsSupportedProtocolVersion(version); | 492 return devtools::IsSupportedProtocolVersion(version); |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 894 | 909 |
| 895 void DevToolsHttpHandlerImpl::OnWebSocketRequest( | 910 void DevToolsHttpHandlerImpl::OnWebSocketRequest( |
| 896 int connection_id, | 911 int connection_id, |
| 897 const net::HttpServerRequestInfo& request) { | 912 const net::HttpServerRequestInfo& request) { |
| 898 if (!thread_) | 913 if (!thread_) |
| 899 return; | 914 return; |
| 900 | 915 |
| 901 std::string browser_prefix = "/devtools/browser"; | 916 std::string browser_prefix = "/devtools/browser"; |
| 902 size_t browser_pos = request.path.find(browser_prefix); | 917 size_t browser_pos = request.path.find(browser_prefix); |
| 903 if (browser_pos == 0) { | 918 if (browser_pos == 0) { |
| 904 browser_targets_[connection_id] = new BrowserTarget(thread_->message_loop(), | 919 BrowserTarget* browser_target = new BrowserTarget(thread_->message_loop(), |
| 905 server_wrapper_, | 920 server_wrapper_, |
| 906 delegate_.get(), | 921 delegate_.get(), |
| 907 connection_id); | 922 connection_id); |
| 923 browser_target->RegisterHandler( |
| 924 new DevToolsSystemInfoHandler()); |
| 925 browser_targets_[connection_id] = browser_target; |
| 908 AcceptWebSocket(connection_id, request); | 926 AcceptWebSocket(connection_id, request); |
| 909 return; | 927 return; |
| 910 } | 928 } |
| 911 | 929 |
| 912 size_t pos = request.path.find(kPageUrlPrefix); | 930 size_t pos = request.path.find(kPageUrlPrefix); |
| 913 if (pos != 0) { | 931 if (pos != 0) { |
| 914 Send404(connection_id); | 932 Send404(connection_id); |
| 915 return; | 933 return; |
| 916 } | 934 } |
| 917 | 935 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1137 id.c_str(), | 1155 id.c_str(), |
| 1138 host); | 1156 host); |
| 1139 dictionary->SetString( | 1157 dictionary->SetString( |
| 1140 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); | 1158 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); |
| 1141 } | 1159 } |
| 1142 | 1160 |
| 1143 return dictionary; | 1161 return dictionary; |
| 1144 } | 1162 } |
| 1145 | 1163 |
| 1146 } // namespace content | 1164 } // namespace content |
| OLD | NEW |