| 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" | |
| 21 #include "content/browser/debugger/devtools_manager.h" | |
| 22 #include "content/browser/tab_contents/tab_contents.h" | 20 #include "content/browser/tab_contents/tab_contents.h" |
| 23 #include "content/browser/tab_contents/tab_contents_observer.h" | 21 #include "content/browser/tab_contents/tab_contents_observer.h" |
| 24 #include "content/common/devtools_messages.h" | 22 #include "content/common/devtools_messages.h" |
| 25 #include "content/public/browser/browser_thread.h" | 23 #include "content/public/browser/browser_thread.h" |
| 24 #include "content/public/browser/devtools/devtools_agent_host_registry.h" |
| 25 #include "content/public/browser/devtools/devtools_client_host.h" |
| 26 #include "content/public/browser/devtools/devtools_manager.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::DevToolsAgentHost; |
| 35 using content::DevToolsAgentHostRegistry; |
| 36 using content::DevToolsClientHost; |
| 37 using content::DevToolsManager; |
| 33 | 38 |
| 34 const int kBufferSize = 16 * 1024; | 39 const int kBufferSize = 16 * 1024; |
| 35 | 40 |
| 36 namespace { | 41 namespace { |
| 37 | 42 |
| 38 // An internal implementation of DevToolsClientHost that delegates | 43 // An internal implementation of DevToolsClientHost that delegates |
| 39 // messages sent for DevToolsClient to a DebuggerShell instance. | 44 // messages sent for DevToolsClient to a DebuggerShell instance. |
| 40 class DevToolsClientHostImpl : public DevToolsClientHost { | 45 class DevToolsClientHostImpl : public DevToolsClientHost { |
| 41 public: | 46 public: |
| 42 DevToolsClientHostImpl( | 47 DevToolsClientHostImpl( |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 for (Tabs::iterator it = inspectable_tabs.begin(); | 295 for (Tabs::iterator it = inspectable_tabs.begin(); |
| 291 it != inspectable_tabs.end(); ++it) { | 296 it != inspectable_tabs.end(); ++it) { |
| 292 | 297 |
| 293 TabContents* tab_contents = *it; | 298 TabContents* tab_contents = *it; |
| 294 NavigationController& controller = tab_contents->controller(); | 299 NavigationController& controller = tab_contents->controller(); |
| 295 | 300 |
| 296 NavigationEntry* entry = controller.GetActiveEntry(); | 301 NavigationEntry* entry = controller.GetActiveEntry(); |
| 297 if (entry == NULL || !entry->url().is_valid()) | 302 if (entry == NULL || !entry->url().is_valid()) |
| 298 continue; | 303 continue; |
| 299 | 304 |
| 305 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 306 tab_contents->render_view_host()); |
| 300 DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> | 307 DevToolsClientHost* client_host = DevToolsManager::GetInstance()-> |
| 301 GetDevToolsClientHostFor(tab_contents->render_view_host()); | 308 GetDevToolsClientHostFor(agent); |
| 302 PageInfo page_info; | 309 PageInfo page_info; |
| 303 page_info.id = TabContentsIDHelper::GetID(tab_contents); | 310 page_info.id = TabContentsIDHelper::GetID(tab_contents); |
| 304 page_info.attached = client_host != NULL; | 311 page_info.attached = client_host != NULL; |
| 305 page_info.url = entry->url().spec(); | 312 page_info.url = entry->url().spec(); |
| 306 page_info.title = UTF16ToUTF8(net::EscapeForHTML(entry->title())); | 313 page_info.title = UTF16ToUTF8(net::EscapeForHTML(entry->title())); |
| 307 page_info.thumbnail_url = "/thumb/" + entry->url().spec(); | 314 page_info.thumbnail_url = "/thumb/" + entry->url().spec(); |
| 308 page_info.favicon_url = entry->favicon().url().spec(); | 315 page_info.favicon_url = entry->favicon().url().spec(); |
| 309 page_list.push_back(page_info); | 316 page_list.push_back(page_info); |
| 310 } | 317 } |
| 311 return page_list; | 318 return page_list; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 return; | 368 return; |
| 362 } | 369 } |
| 363 | 370 |
| 364 TabContents* tab_contents = TabContentsIDHelper::GetTabContents(id); | 371 TabContents* tab_contents = TabContentsIDHelper::GetTabContents(id); |
| 365 if (tab_contents == NULL) { | 372 if (tab_contents == NULL) { |
| 366 Send500(connection_id, "No such page id: " + page_id); | 373 Send500(connection_id, "No such page id: " + page_id); |
| 367 return; | 374 return; |
| 368 } | 375 } |
| 369 | 376 |
| 370 DevToolsManager* manager = DevToolsManager::GetInstance(); | 377 DevToolsManager* manager = DevToolsManager::GetInstance(); |
| 371 if (manager->GetDevToolsClientHostFor(tab_contents->render_view_host())) { | 378 DevToolsAgentHost* agent = DevToolsAgentHostRegistry::GetDevToolsAgentHost( |
| 379 tab_contents->render_view_host()); |
| 380 if (manager->GetDevToolsClientHostFor(agent)) { |
| 372 Send500(connection_id, "Page with given id is being inspected: " + page_id); | 381 Send500(connection_id, "Page with given id is being inspected: " + page_id); |
| 373 return; | 382 return; |
| 374 } | 383 } |
| 375 | 384 |
| 376 DevToolsClientHostImpl* client_host = | 385 DevToolsClientHostImpl* client_host = |
| 377 new DevToolsClientHostImpl(server_, connection_id); | 386 new DevToolsClientHostImpl(server_, connection_id); |
| 378 connection_to_client_host_ui_[connection_id] = client_host; | 387 connection_to_client_host_ui_[connection_id] = client_host; |
| 379 | 388 |
| 380 manager->RegisterDevToolsClientHostFor( | 389 manager->RegisterDevToolsClientHostFor(agent, client_host); |
| 381 tab_contents->render_view_host(), | |
| 382 client_host); | |
| 383 manager->ForwardToDevToolsAgent( | 390 manager->ForwardToDevToolsAgent( |
| 384 client_host, | 391 client_host, |
| 385 DevToolsAgentMsg_FrontendLoaded(MSG_ROUTING_NONE)); | 392 DevToolsAgentMsg_FrontendLoaded(MSG_ROUTING_NONE)); |
| 386 | 393 |
| 387 AcceptWebSocket(connection_id, request); | 394 AcceptWebSocket(connection_id, request); |
| 388 } | 395 } |
| 389 | 396 |
| 390 void DevToolsHttpProtocolHandler::OnWebSocketMessageUI( | 397 void DevToolsHttpProtocolHandler::OnWebSocketMessageUI( |
| 391 int connection_id, | 398 int connection_id, |
| 392 const std::string& data) { | 399 const std::string& data) { |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 } | 556 } |
| 550 | 557 |
| 551 void DevToolsHttpProtocolHandler::AcceptWebSocket( | 558 void DevToolsHttpProtocolHandler::AcceptWebSocket( |
| 552 int connection_id, | 559 int connection_id, |
| 553 const net::HttpServerRequestInfo& request) { | 560 const net::HttpServerRequestInfo& request) { |
| 554 BrowserThread::PostTask( | 561 BrowserThread::PostTask( |
| 555 BrowserThread::IO, FROM_HERE, | 562 BrowserThread::IO, FROM_HERE, |
| 556 base::Bind(&net::HttpServer::AcceptWebSocket, server_.get(), | 563 base::Bind(&net::HttpServer::AcceptWebSocket, server_.get(), |
| 557 connection_id, request)); | 564 connection_id, request)); |
| 558 } | 565 } |
| OLD | NEW |