| 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 "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" | 23 #include "content/browser/devtools/devtools_system_info_handler.h" |
| 24 #include "content/browser/devtools/protocol/devtools_protocol_handler_impl.h" | 24 #include "content/browser/devtools/protocol/devtools_protocol_handler_impl.h" |
| 25 #include "content/browser/devtools/protocol/tethering_handler.h" |
| 25 #include "content/browser/devtools/protocol/tracing_handler.h" | 26 #include "content/browser/devtools/protocol/tracing_handler.h" |
| 26 #include "content/browser/devtools/tethering_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" |
| 35 #include "grit/devtools_resources_map.h" | 35 #include "grit/devtools_resources_map.h" |
| 36 #include "net/base/escape.h" | 36 #include "net/base/escape.h" |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 } | 149 } |
| 150 | 150 |
| 151 } // namespace | 151 } // namespace |
| 152 | 152 |
| 153 // DevToolsHttpHandlerImpl::BrowserTarget ------------------------------------ | 153 // DevToolsHttpHandlerImpl::BrowserTarget ------------------------------------ |
| 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 int connection_id) | 160 int connection_id) |
| 160 : message_loop_(message_loop), | 161 : message_loop_(message_loop), |
| 161 server_(server), | 162 server_(server), |
| 162 connection_id_(connection_id), | 163 connection_id_(connection_id), |
| 164 tethering_handler_(new devtools::tethering::TetheringHandler( |
| 165 delegate, message_loop->message_loop_proxy())), |
| 163 tracing_handler_(new devtools::tracing::TracingHandler( | 166 tracing_handler_(new devtools::tracing::TracingHandler( |
| 164 devtools::tracing::TracingHandler::Browser)), | 167 devtools::tracing::TracingHandler::Browser)), |
| 165 protocol_handler_(new DevToolsProtocolHandlerImpl()) { | 168 protocol_handler_(new DevToolsProtocolHandlerImpl()) { |
| 166 protocol_handler_->SetNotifier( | 169 protocol_handler_->SetNotifier( |
| 167 base::Bind(&BrowserTarget::Respond, base::Unretained(this))); | 170 base::Bind(&BrowserTarget::Respond, base::Unretained(this))); |
| 171 protocol_handler_->SetTetheringHandler(tethering_handler_.get()); |
| 168 protocol_handler_->SetTracingHandler(tracing_handler_.get()); | 172 protocol_handler_->SetTracingHandler(tracing_handler_.get()); |
| 169 } | 173 } |
| 170 | 174 |
| 171 ~BrowserTarget() { | 175 ~BrowserTarget() { |
| 172 STLDeleteElements(&handlers_); | 176 STLDeleteElements(&handlers_); |
| 173 } | 177 } |
| 174 | 178 |
| 175 // Takes ownership. | 179 // Takes ownership. |
| 176 void RegisterHandler(DevToolsProtocol::Handler* handler) { | 180 void RegisterHandler(DevToolsProtocol::Handler* handler) { |
| 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 181 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 base::Bind(&net::HttpServer::SendOverWebSocket, | 217 base::Bind(&net::HttpServer::SendOverWebSocket, |
| 214 base::Unretained(server_), | 218 base::Unretained(server_), |
| 215 connection_id_, | 219 connection_id_, |
| 216 message)); | 220 message)); |
| 217 } | 221 } |
| 218 | 222 |
| 219 private: | 223 private: |
| 220 base::MessageLoop* const message_loop_; | 224 base::MessageLoop* const message_loop_; |
| 221 net::HttpServer* const server_; | 225 net::HttpServer* const server_; |
| 222 const int connection_id_; | 226 const int connection_id_; |
| 227 scoped_ptr<devtools::tethering::TetheringHandler> tethering_handler_; |
| 223 scoped_ptr<devtools::tracing::TracingHandler> tracing_handler_; | 228 scoped_ptr<devtools::tracing::TracingHandler> tracing_handler_; |
| 224 scoped_ptr<DevToolsProtocolHandlerImpl> protocol_handler_; | 229 scoped_ptr<DevToolsProtocolHandlerImpl> protocol_handler_; |
| 225 std::vector<DevToolsProtocol::Handler*> handlers_; | 230 std::vector<DevToolsProtocol::Handler*> handlers_; |
| 226 }; | 231 }; |
| 227 | 232 |
| 228 // DevToolsHttpHandler ------------------------------------------------------- | 233 // DevToolsHttpHandler ------------------------------------------------------- |
| 229 | 234 |
| 230 // static | 235 // static |
| 231 bool DevToolsHttpHandler::IsSupportedProtocolVersion( | 236 bool DevToolsHttpHandler::IsSupportedProtocolVersion( |
| 232 const std::string& version) { | 237 const std::string& version) { |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 void DevToolsHttpHandlerImpl::OnWebSocketRequestUI( | 699 void DevToolsHttpHandlerImpl::OnWebSocketRequestUI( |
| 695 int connection_id, | 700 int connection_id, |
| 696 const net::HttpServerRequestInfo& request) { | 701 const net::HttpServerRequestInfo& request) { |
| 697 if (!thread_) | 702 if (!thread_) |
| 698 return; | 703 return; |
| 699 | 704 |
| 700 std::string browser_prefix = "/devtools/browser"; | 705 std::string browser_prefix = "/devtools/browser"; |
| 701 size_t browser_pos = request.path.find(browser_prefix); | 706 size_t browser_pos = request.path.find(browser_prefix); |
| 702 if (browser_pos == 0) { | 707 if (browser_pos == 0) { |
| 703 BrowserTarget* browser_target = new BrowserTarget( | 708 BrowserTarget* browser_target = new BrowserTarget( |
| 704 thread_->message_loop(), server_.get(), connection_id); | 709 thread_->message_loop(), server_.get(), delegate_.get(), connection_id); |
| 705 browser_target->RegisterHandler( | |
| 706 new TetheringHandler(delegate_.get(), thread_->message_loop_proxy())); | |
| 707 browser_target->RegisterHandler( | 710 browser_target->RegisterHandler( |
| 708 new DevToolsSystemInfoHandler()); | 711 new DevToolsSystemInfoHandler()); |
| 709 browser_targets_[connection_id] = browser_target; | 712 browser_targets_[connection_id] = browser_target; |
| 710 AcceptWebSocket(connection_id, request); | 713 AcceptWebSocket(connection_id, request); |
| 711 return; | 714 return; |
| 712 } | 715 } |
| 713 | 716 |
| 714 size_t pos = request.path.find(kPageUrlPrefix); | 717 size_t pos = request.path.find(kPageUrlPrefix); |
| 715 if (pos != 0) { | 718 if (pos != 0) { |
| 716 Send404(connection_id); | 719 Send404(connection_id); |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 id.c_str(), | 983 id.c_str(), |
| 981 host); | 984 host); |
| 982 dictionary->SetString( | 985 dictionary->SetString( |
| 983 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); | 986 kTargetDevtoolsFrontendUrlField, devtools_frontend_url); |
| 984 } | 987 } |
| 985 | 988 |
| 986 return dictionary; | 989 return dictionary; |
| 987 } | 990 } |
| 988 | 991 |
| 989 } // namespace content | 992 } // namespace content |
| OLD | NEW |