| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/debugger/devtools_http_protocol_handler.h" | 5 #include "content/browser/debugger/devtools_http_protocol_handler.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/message_loop_proxy.h" | 14 #include "base/message_loop_proxy.h" |
| 15 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
| 16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
| 17 #include "base/threading/thread.h" | 17 #include "base/threading/thread.h" |
| 18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
| 19 #include "base/values.h" | 19 #include "base/values.h" |
| 20 #include "content/browser/debugger/devtools_client_host.h" | 20 #include "content/browser/debugger/devtools_client_host.h" |
| 21 #include "content/browser/debugger/devtools_manager.h" | 21 #include "content/browser/debugger/devtools_manager.h" |
| 22 #include "content/browser/tab_contents/tab_contents.h" | 22 #include "content/browser/tab_contents/tab_contents.h" |
| 23 #include "content/browser/tab_contents/tab_contents_observer.h" | 23 #include "content/browser/tab_contents/tab_contents_observer.h" |
| 24 #include "content/common/devtools_messages.h" | 24 #include "content/common/devtools_messages.h" |
| 25 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
| 26 #include "content/public/browser/devtools/devtools_agent_host_registry.h" |
| 26 #include "googleurl/src/gurl.h" | 27 #include "googleurl/src/gurl.h" |
| 27 #include "net/base/escape.h" | 28 #include "net/base/escape.h" |
| 28 #include "net/base/io_buffer.h" | 29 #include "net/base/io_buffer.h" |
| 29 #include "net/server/http_server_request_info.h" | 30 #include "net/server/http_server_request_info.h" |
| 30 #include "net/url_request/url_request_context.h" | 31 #include "net/url_request/url_request_context.h" |
| 31 | 32 |
| 32 using content::BrowserThread; | 33 using content::BrowserThread; |
| 34 using content::DevToolsAgentHostRegistry; |
| 33 | 35 |
| 34 const int kBufferSize = 16 * 1024; | 36 const int kBufferSize = 16 * 1024; |
| 35 | 37 |
| 36 namespace { | 38 namespace { |
| 37 | 39 |
| 38 // An internal implementation of DevToolsClientHost that delegates | 40 // An internal implementation of DevToolsClientHost that delegates |
| 39 // messages sent for DevToolsClient to a DebuggerShell instance. | 41 // messages sent for DevToolsClient to a DebuggerShell instance. |
| 40 class DevToolsClientHostImpl : public DevToolsClientHost { | 42 class DevToolsClientHostImpl : public DevToolsClientHost { |
| 41 public: | 43 public: |
| 42 DevToolsClientHostImpl( | 44 DevToolsClientHostImpl( |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 DevToolsManager* manager = DevToolsManager::GetInstance(); | 372 DevToolsManager* manager = DevToolsManager::GetInstance(); |
| 371 if (manager->GetDevToolsClientHostFor(tab_contents->render_view_host())) { | 373 if (manager->GetDevToolsClientHostFor(tab_contents->render_view_host())) { |
| 372 Send500(connection_id, "Page with given id is being inspected: " + page_id); | 374 Send500(connection_id, "Page with given id is being inspected: " + page_id); |
| 373 return; | 375 return; |
| 374 } | 376 } |
| 375 | 377 |
| 376 DevToolsClientHostImpl* client_host = | 378 DevToolsClientHostImpl* client_host = |
| 377 new DevToolsClientHostImpl(server_, connection_id); | 379 new DevToolsClientHostImpl(server_, connection_id); |
| 378 connection_to_client_host_ui_[connection_id] = client_host; | 380 connection_to_client_host_ui_[connection_id] = client_host; |
| 379 | 381 |
| 380 manager->RegisterDevToolsClientHostFor( | 382 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 381 tab_contents->render_view_host(), | 383 tab_contents->render_view_host()); |
| 382 client_host); | 384 manager->RegisterDevToolsClientHostFor(agent, client_host); |
| 383 manager->ForwardToDevToolsAgent( | 385 manager->ForwardToDevToolsAgent( |
| 384 client_host, | 386 client_host, |
| 385 DevToolsAgentMsg_FrontendLoaded(MSG_ROUTING_NONE)); | 387 DevToolsAgentMsg_FrontendLoaded(MSG_ROUTING_NONE)); |
| 386 | 388 |
| 387 AcceptWebSocket(connection_id, request); | 389 AcceptWebSocket(connection_id, request); |
| 388 } | 390 } |
| 389 | 391 |
| 390 void DevToolsHttpProtocolHandler::OnWebSocketMessageUI( | 392 void DevToolsHttpProtocolHandler::OnWebSocketMessageUI( |
| 391 int connection_id, | 393 int connection_id, |
| 392 const std::string& data) { | 394 const std::string& data) { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 } | 551 } |
| 550 | 552 |
| 551 void DevToolsHttpProtocolHandler::AcceptWebSocket( | 553 void DevToolsHttpProtocolHandler::AcceptWebSocket( |
| 552 int connection_id, | 554 int connection_id, |
| 553 const net::HttpServerRequestInfo& request) { | 555 const net::HttpServerRequestInfo& request) { |
| 554 BrowserThread::PostTask( | 556 BrowserThread::PostTask( |
| 555 BrowserThread::IO, FROM_HERE, | 557 BrowserThread::IO, FROM_HERE, |
| 556 base::Bind(&net::HttpServer::AcceptWebSocket, server_.get(), | 558 base::Bind(&net::HttpServer::AcceptWebSocket, server_.get(), |
| 557 connection_id, request)); | 559 connection_id, request)); |
| 558 } | 560 } |
| OLD | NEW |