| 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/debugger/devtools_http_handler_impl.h" | 5 #include "content/browser/debugger/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" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 #include "base/values.h" | 21 #include "base/values.h" |
| 22 #include "content/browser/web_contents/web_contents_impl.h" | 22 #include "content/browser/web_contents/web_contents_impl.h" |
| 23 #include "content/common/devtools_messages.h" | 23 #include "content/common/devtools_messages.h" |
| 24 #include "content/public/browser/browser_thread.h" | 24 #include "content/public/browser/browser_thread.h" |
| 25 #include "content/public/browser/devtools_agent_host_registry.h" | 25 #include "content/public/browser/devtools_agent_host_registry.h" |
| 26 #include "content/public/browser/devtools_client_host.h" | 26 #include "content/public/browser/devtools_client_host.h" |
| 27 #include "content/public/browser/devtools_http_handler_delegate.h" | 27 #include "content/public/browser/devtools_http_handler_delegate.h" |
| 28 #include "content/public/browser/devtools_manager.h" | 28 #include "content/public/browser/devtools_manager.h" |
| 29 #include "content/public/browser/favicon_status.h" | 29 #include "content/public/browser/favicon_status.h" |
| 30 #include "content/public/browser/navigation_entry.h" | 30 #include "content/public/browser/navigation_entry.h" |
| 31 #include "content/public/browser/notification_service.h" | |
| 32 #include "content/public/browser/notification_types.h" | |
| 33 #include "content/public/browser/render_process_host.h" | 31 #include "content/public/browser/render_process_host.h" |
| 34 #include "content/public/browser/render_view_host.h" | 32 #include "content/public/browser/render_view_host.h" |
| 35 #include "content/public/browser/render_widget_host.h" | 33 #include "content/public/browser/render_widget_host.h" |
| 36 #include "content/public/common/content_client.h" | 34 #include "content/public/common/content_client.h" |
| 37 #include "content/public/common/url_constants.h" | 35 #include "content/public/common/url_constants.h" |
| 38 #include "googleurl/src/gurl.h" | 36 #include "googleurl/src/gurl.h" |
| 39 #include "grit/devtools_resources_map.h" | 37 #include "grit/devtools_resources_map.h" |
| 40 #include "net/base/escape.h" | 38 #include "net/base/escape.h" |
| 41 #include "net/base/io_buffer.h" | 39 #include "net/base/io_buffer.h" |
| 42 #include "net/base/ip_endpoint.h" | 40 #include "net/base/ip_endpoint.h" |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 if (!base::StringToInt(identifier.substr(pos+1), &routing_id)) | 78 if (!base::StringToInt(identifier.substr(pos+1), &routing_id)) |
| 81 return NULL; | 79 return NULL; |
| 82 | 80 |
| 83 return RenderViewHost::FromID(process_id, routing_id); | 81 return RenderViewHost::FromID(process_id, routing_id); |
| 84 } | 82 } |
| 85 }; | 83 }; |
| 86 | 84 |
| 87 | 85 |
| 88 // An internal implementation of DevToolsClientHost that delegates | 86 // An internal implementation of DevToolsClientHost that delegates |
| 89 // messages sent for DevToolsClient to a DebuggerShell instance. | 87 // messages sent for DevToolsClient to a DebuggerShell instance. |
| 90 class DevToolsClientHostImpl : public DevToolsClientHost, | 88 class DevToolsClientHostImpl : public DevToolsClientHost { |
| 91 public NotificationObserver { | |
| 92 public: | 89 public: |
| 93 DevToolsClientHostImpl( | 90 DevToolsClientHostImpl( |
| 94 MessageLoop* message_loop, | 91 MessageLoop* message_loop, |
| 95 net::HttpServer* server, | 92 net::HttpServer* server, |
| 96 int connection_id, | 93 int connection_id) |
| 97 RenderProcessHost* process_host) | |
| 98 : message_loop_(message_loop), | 94 : message_loop_(message_loop), |
| 99 server_(server), | 95 server_(server), |
| 100 connection_id_(connection_id), | 96 connection_id_(connection_id) { |
| 101 is_closed_(false) { | |
| 102 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_TERMINATED, | |
| 103 Source<RenderProcessHost>(process_host)); | |
| 104 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED, | |
| 105 Source<RenderProcessHost>(process_host)); | |
| 106 } | 97 } |
| 107 | |
| 108 ~DevToolsClientHostImpl() {} | 98 ~DevToolsClientHostImpl() {} |
| 109 | 99 |
| 110 // DevToolsClientHost interface | 100 // DevToolsClientHost interface |
| 111 virtual void InspectedContentsClosing() { | 101 virtual void InspectedContentsClosing() { |
| 112 if (is_closed_) | |
| 113 return; | |
| 114 is_closed_ = true; | |
| 115 message_loop_->PostTask( | 102 message_loop_->PostTask( |
| 116 FROM_HERE, | 103 FROM_HERE, |
| 117 base::Bind(&net::HttpServer::Close, server_, connection_id_)); | 104 base::Bind(&net::HttpServer::Close, server_, connection_id_)); |
| 118 } | 105 } |
| 119 | 106 |
| 120 virtual void DispatchOnInspectorFrontend(const std::string& data) { | 107 virtual void DispatchOnInspectorFrontend(const std::string& data) { |
| 121 message_loop_->PostTask( | 108 message_loop_->PostTask( |
| 122 FROM_HERE, | 109 FROM_HERE, |
| 123 base::Bind(&net::HttpServer::SendOverWebSocket, | 110 base::Bind(&net::HttpServer::SendOverWebSocket, |
| 124 server_, | 111 server_, |
| 125 connection_id_, | 112 connection_id_, |
| 126 data)); | 113 data)); |
| 127 } | 114 } |
| 128 | 115 |
| 129 virtual void ContentsReplaced(WebContents* new_contents) { | 116 virtual void ContentsReplaced(WebContents* new_contents) { |
| 130 } | 117 } |
| 131 | 118 |
| 132 private: | 119 private: |
| 133 virtual void Observe(int type, | |
| 134 const NotificationSource& source, | |
| 135 const NotificationDetails& details) { | |
| 136 InspectedContentsClosing(); | |
| 137 } | |
| 138 | |
| 139 virtual void FrameNavigating(const std::string& url) {} | 120 virtual void FrameNavigating(const std::string& url) {} |
| 140 MessageLoop* message_loop_; | 121 MessageLoop* message_loop_; |
| 141 net::HttpServer* server_; | 122 net::HttpServer* server_; |
| 142 int connection_id_; | 123 int connection_id_; |
| 143 bool is_closed_; | |
| 144 NotificationRegistrar registrar_; | |
| 145 }; | 124 }; |
| 146 | 125 |
| 147 } // namespace | 126 } // namespace |
| 148 | 127 |
| 149 // static | 128 // static |
| 150 int DevToolsHttpHandler::GetFrontendResourceId(const std::string& name) { | 129 int DevToolsHttpHandler::GetFrontendResourceId(const std::string& name) { |
| 151 for (size_t i = 0; i < kDevtoolsResourcesSize; ++i) { | 130 for (size_t i = 0; i < kDevtoolsResourcesSize; ++i) { |
| 152 if (name == kDevtoolsResources[i].name) | 131 if (name == kDevtoolsResources[i].name) |
| 153 return kDevtoolsResources[i].value; | 132 return kDevtoolsResources[i].value; |
| 154 } | 133 } |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 rvh); | 508 rvh); |
| 530 if (manager->GetDevToolsClientHostFor(agent)) { | 509 if (manager->GetDevToolsClientHostFor(agent)) { |
| 531 Send500(connection_id, "Target with given id is being inspected: " + | 510 Send500(connection_id, "Target with given id is being inspected: " + |
| 532 page_id); | 511 page_id); |
| 533 return; | 512 return; |
| 534 } | 513 } |
| 535 | 514 |
| 536 DevToolsClientHostImpl* client_host = | 515 DevToolsClientHostImpl* client_host = |
| 537 new DevToolsClientHostImpl(thread_->message_loop(), | 516 new DevToolsClientHostImpl(thread_->message_loop(), |
| 538 server_, | 517 server_, |
| 539 connection_id, | 518 connection_id); |
| 540 rvh->GetProcess()); | |
| 541 connection_to_client_host_ui_[connection_id] = client_host; | 519 connection_to_client_host_ui_[connection_id] = client_host; |
| 542 | 520 |
| 543 manager->RegisterDevToolsClientHostFor(agent, client_host); | 521 manager->RegisterDevToolsClientHostFor(agent, client_host); |
| 544 | 522 |
| 545 AcceptWebSocket(connection_id, request); | 523 AcceptWebSocket(connection_id, request); |
| 546 } | 524 } |
| 547 | 525 |
| 548 void DevToolsHttpHandlerImpl::OnWebSocketMessageUI( | 526 void DevToolsHttpHandlerImpl::OnWebSocketMessageUI( |
| 549 int connection_id, | 527 int connection_id, |
| 550 const std::string& data) { | 528 const std::string& data) { |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 696 page_info.id.c_str())); | 674 page_info.id.c_str())); |
| 697 std::string devtools_frontend_url = GetFrontendURLInternal( | 675 std::string devtools_frontend_url = GetFrontendURLInternal( |
| 698 page_info.id.c_str(), | 676 page_info.id.c_str(), |
| 699 host); | 677 host); |
| 700 dictionary->SetString("devtoolsFrontendUrl", devtools_frontend_url); | 678 dictionary->SetString("devtoolsFrontendUrl", devtools_frontend_url); |
| 701 } | 679 } |
| 702 return dictionary; | 680 return dictionary; |
| 703 } | 681 } |
| 704 | 682 |
| 705 } // namespace content | 683 } // namespace content |
| OLD | NEW |