Chromium Code Reviews| Index: content/browser/debugger/devtools_http_handler_impl.cc |
| diff --git a/content/browser/debugger/devtools_http_handler_impl.cc b/content/browser/debugger/devtools_http_handler_impl.cc |
| index 377ec1c164bb0714f4e2194ae7ca6f7f813f4818..afa172f3167252ca7416a3496852083c737ea1b8 100644 |
| --- a/content/browser/debugger/devtools_http_handler_impl.cc |
| +++ b/content/browser/debugger/devtools_http_handler_impl.cc |
| @@ -19,6 +19,8 @@ |
| #include "base/threading/thread.h" |
| #include "base/utf_string_conversions.h" |
| #include "base/values.h" |
| +#include "content/browser/debugger/devtools_browser_target.h" |
| +#include "content/browser/debugger/devtools_tracing_handler.h" |
| #include "content/browser/web_contents/web_contents_impl.h" |
| #include "content/common/devtools_messages.h" |
| #include "content/public/browser/browser_thread.h" |
| @@ -588,15 +590,27 @@ void DevToolsHttpHandlerImpl::OnWebSocketRequestUI( |
| const net::HttpServerRequestInfo& request) { |
| if (!thread_.get()) |
| return; |
| + std::string browser_prefix = "/devtools/browser"; |
| + size_t browser_pos = request.path.find(browser_prefix); |
| + if (browser_pos == 0) { |
| + if (browser_target_) { |
| + Send500(connection_id, "Browser already registered"); |
|
pfeldman
2012/12/14 18:35:05
"Another client is already attached"?
bulach
2012/12/14 19:53:39
Done.
|
| + return; |
| + } |
| + browser_target_.reset(new DevToolsBrowserTarget(connection_id)); |
| + browser_target_->RegisterHandler("Tracing", new DevToolsTracingHandler()); |
|
pfeldman
2012/12/14 18:35:05
nit: Handler could have a ::protocol() method and
bulach
2012/12/14 19:53:39
I got confused on what is "protocol", sorry.
I cre
pfeldman
2012/12/14 20:15:14
Yes, domain(), sorry
|
| + AcceptWebSocket(connection_id, request); |
| + return; |
| + } |
| - std::string prefix = "/devtools/page/"; |
| - size_t pos = request.path.find(prefix); |
| + std::string page_prefix = "/devtools/page/"; |
| + size_t pos = request.path.find(page_prefix); |
| if (pos != 0) { |
| Send404(connection_id); |
| return; |
| } |
| - std::string page_id = request.path.substr(prefix.length()); |
| + std::string page_id = request.path.substr(page_prefix.length()); |
| RenderViewHost* rvh = binding_->ForIdentifier(page_id); |
| if (!rvh) { |
| Send500(connection_id, "No such target id: " + page_id); |
| @@ -626,6 +640,18 @@ void DevToolsHttpHandlerImpl::OnWebSocketRequestUI( |
| void DevToolsHttpHandlerImpl::OnWebSocketMessageUI( |
| int connection_id, |
| const std::string& data) { |
| + if (browser_target_ && connection_id == browser_target_->connection_id()) { |
| + std::string json_response = browser_target_->HandleMessage(data); |
| + |
| + thread_->message_loop()->PostTask( |
| + FROM_HERE, |
| + base::Bind(&net::HttpServer::SendOverWebSocket, |
| + server_.get(), |
| + connection_id, |
| + json_response)); |
| + return; |
| + } |
| + |
| ConnectionToClientHostMap::iterator it = |
| connection_to_client_host_ui_.find(connection_id); |
| if (it == connection_to_client_host_ui_.end()) |
| @@ -645,6 +671,10 @@ void DevToolsHttpHandlerImpl::OnCloseUI(int connection_id) { |
| delete client_host; |
| connection_to_client_host_ui_.erase(connection_id); |
| } |
| + if (browser_target_ && browser_target_->connection_id() == connection_id) { |
| + browser_target_.reset(); |
| + return; |
| + } |
| } |
| DevToolsHttpHandlerImpl::DevToolsHttpHandlerImpl( |