| 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" |
| 31 #include "content/public/browser/render_process_host.h" | 33 #include "content/public/browser/render_process_host.h" |
| 32 #include "content/public/browser/render_view_host.h" | 34 #include "content/public/browser/render_view_host.h" |
| 33 #include "content/public/browser/render_widget_host.h" | 35 #include "content/public/browser/render_widget_host.h" |
| 34 #include "content/public/common/content_client.h" | 36 #include "content/public/common/content_client.h" |
| 35 #include "content/public/common/url_constants.h" | 37 #include "content/public/common/url_constants.h" |
| 36 #include "googleurl/src/gurl.h" | 38 #include "googleurl/src/gurl.h" |
| 37 #include "grit/devtools_resources_map.h" | 39 #include "grit/devtools_resources_map.h" |
| 38 #include "net/base/escape.h" | 40 #include "net/base/escape.h" |
| 39 #include "net/base/io_buffer.h" | 41 #include "net/base/io_buffer.h" |
| 40 #include "net/base/ip_endpoint.h" | 42 #include "net/base/ip_endpoint.h" |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 // An internal implementation of DevToolsClientHost that delegates | 88 // An internal implementation of DevToolsClientHost that delegates |
| 87 // messages sent for DevToolsClient to a DebuggerShell instance. | 89 // messages sent for DevToolsClient to a DebuggerShell instance. |
| 88 class DevToolsClientHostImpl : public DevToolsClientHost { | 90 class DevToolsClientHostImpl : public DevToolsClientHost { |
| 89 public: | 91 public: |
| 90 DevToolsClientHostImpl( | 92 DevToolsClientHostImpl( |
| 91 MessageLoop* message_loop, | 93 MessageLoop* message_loop, |
| 92 net::HttpServer* server, | 94 net::HttpServer* server, |
| 93 int connection_id) | 95 int connection_id) |
| 94 : message_loop_(message_loop), | 96 : message_loop_(message_loop), |
| 95 server_(server), | 97 server_(server), |
| 96 connection_id_(connection_id) { | 98 connection_id_(connection_id), |
| 99 is_closed_(false) { |
| 97 } | 100 } |
| 101 |
| 98 ~DevToolsClientHostImpl() {} | 102 ~DevToolsClientHostImpl() {} |
| 99 | 103 |
| 100 // DevToolsClientHost interface | 104 // DevToolsClientHost interface |
| 101 virtual void InspectedContentsClosing() { | 105 virtual void InspectedContentsClosing() { |
| 106 if (is_closed_) |
| 107 return; |
| 108 is_closed_ = true; |
| 102 message_loop_->PostTask( | 109 message_loop_->PostTask( |
| 103 FROM_HERE, | 110 FROM_HERE, |
| 104 base::Bind(&net::HttpServer::Close, server_, connection_id_)); | 111 base::Bind(&net::HttpServer::Close, server_, connection_id_)); |
| 105 } | 112 } |
| 106 | 113 |
| 107 virtual void DispatchOnInspectorFrontend(const std::string& data) { | 114 virtual void DispatchOnInspectorFrontend(const std::string& data) { |
| 108 message_loop_->PostTask( | 115 message_loop_->PostTask( |
| 109 FROM_HERE, | 116 FROM_HERE, |
| 110 base::Bind(&net::HttpServer::SendOverWebSocket, | 117 base::Bind(&net::HttpServer::SendOverWebSocket, |
| 111 server_, | 118 server_, |
| 112 connection_id_, | 119 connection_id_, |
| 113 data)); | 120 data)); |
| 114 } | 121 } |
| 115 | 122 |
| 116 virtual void ContentsReplaced(WebContents* new_contents) { | 123 virtual void ContentsReplaced(WebContents* new_contents) { |
| 117 } | 124 } |
| 118 | 125 |
| 119 private: | 126 private: |
| 120 virtual void FrameNavigating(const std::string& url) {} | 127 virtual void FrameNavigating(const std::string& url) {} |
| 121 MessageLoop* message_loop_; | 128 MessageLoop* message_loop_; |
| 122 net::HttpServer* server_; | 129 net::HttpServer* server_; |
| 123 int connection_id_; | 130 int connection_id_; |
| 131 bool is_closed_; |
| 124 }; | 132 }; |
| 125 | 133 |
| 126 } // namespace | 134 } // namespace |
| 127 | 135 |
| 128 // static | 136 // static |
| 129 int DevToolsHttpHandler::GetFrontendResourceId(const std::string& name) { | 137 int DevToolsHttpHandler::GetFrontendResourceId(const std::string& name) { |
| 130 for (size_t i = 0; i < kDevtoolsResourcesSize; ++i) { | 138 for (size_t i = 0; i < kDevtoolsResourcesSize; ++i) { |
| 131 if (name == kDevtoolsResources[i].name) | 139 if (name == kDevtoolsResources[i].name) |
| 132 return kDevtoolsResources[i].value; | 140 return kDevtoolsResources[i].value; |
| 133 } | 141 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 return "application/javascript"; | 220 return "application/javascript"; |
| 213 } else if (EndsWith(filename, ".png", false)) { | 221 } else if (EndsWith(filename, ".png", false)) { |
| 214 return "image/png"; | 222 return "image/png"; |
| 215 } else if (EndsWith(filename, ".gif", false)) { | 223 } else if (EndsWith(filename, ".gif", false)) { |
| 216 return "image/gif"; | 224 return "image/gif"; |
| 217 } | 225 } |
| 218 NOTREACHED(); | 226 NOTREACHED(); |
| 219 return "text/plain"; | 227 return "text/plain"; |
| 220 } | 228 } |
| 221 | 229 |
| 230 void DevToolsHttpHandlerImpl::Observe(int type, |
| 231 const NotificationSource& source, |
| 232 const NotificationDetails& details) { |
| 233 RenderProcessHost* process = Source<RenderProcessHost>(source).ptr(); |
| 234 DevToolsManager* manager = DevToolsManager::GetInstance(); |
| 235 for (ConnectionToClientHostMap::iterator it = |
| 236 connection_to_client_host_ui_.begin(); |
| 237 it != connection_to_client_host_ui_.end(); ++it) { |
| 238 DevToolsAgentHost* agent = manager->GetDevToolsAgentHostFor(it->second); |
| 239 if (!agent) |
| 240 continue; |
| 241 RenderViewHost* rvh = DevToolsAgentHostRegistry::GetRenderViewHost(agent); |
| 242 if (rvh && rvh->GetProcess() == process) |
| 243 it->second->InspectedContentsClosing(); |
| 244 } |
| 245 } |
| 246 |
| 222 void DevToolsHttpHandlerImpl::OnHttpRequest( | 247 void DevToolsHttpHandlerImpl::OnHttpRequest( |
| 223 int connection_id, | 248 int connection_id, |
| 224 const net::HttpServerRequestInfo& info) { | 249 const net::HttpServerRequestInfo& info) { |
| 225 if (info.path.find("/json/version") == 0) { | 250 if (info.path.find("/json/version") == 0) { |
| 226 // New page request. | 251 // New page request. |
| 227 BrowserThread::PostTask( | 252 BrowserThread::PostTask( |
| 228 BrowserThread::UI, | 253 BrowserThread::UI, |
| 229 FROM_HERE, | 254 FROM_HERE, |
| 230 base::Bind(&DevToolsHttpHandlerImpl::OnVersionRequestUI, | 255 base::Bind(&DevToolsHttpHandlerImpl::OnVersionRequestUI, |
| 231 this, | 256 this, |
| (...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 553 DevToolsHttpHandlerDelegate* delegate) | 578 DevToolsHttpHandlerDelegate* delegate) |
| 554 : overridden_frontend_url_(frontend_url), | 579 : overridden_frontend_url_(frontend_url), |
| 555 socket_factory_(socket_factory), | 580 socket_factory_(socket_factory), |
| 556 delegate_(delegate) { | 581 delegate_(delegate) { |
| 557 if (overridden_frontend_url_.empty()) | 582 if (overridden_frontend_url_.empty()) |
| 558 overridden_frontend_url_ = "/devtools/devtools.html"; | 583 overridden_frontend_url_ = "/devtools/devtools.html"; |
| 559 | 584 |
| 560 default_binding_.reset(new DevToolsDefaultBindingHandler); | 585 default_binding_.reset(new DevToolsDefaultBindingHandler); |
| 561 binding_ = default_binding_.get(); | 586 binding_ = default_binding_.get(); |
| 562 | 587 |
| 588 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_TERMINATED, |
| 589 content::NotificationService::AllBrowserContextsAndSources()); |
| 590 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED, |
| 591 content::NotificationService::AllBrowserContextsAndSources()); |
| 563 AddRef(); | 592 AddRef(); |
| 564 } | 593 } |
| 565 | 594 |
| 566 void DevToolsHttpHandlerImpl::Init() { | 595 void DevToolsHttpHandlerImpl::Init() { |
| 567 server_ = new net::HttpServer(*socket_factory_.get(), this); | 596 server_ = new net::HttpServer(*socket_factory_.get(), this); |
| 568 } | 597 } |
| 569 | 598 |
| 570 // Run on the handler thread | 599 // Run on the handler thread |
| 571 void DevToolsHttpHandlerImpl::TeardownAndRelease() { | 600 void DevToolsHttpHandlerImpl::TeardownAndRelease() { |
| 572 server_ = NULL; | 601 server_ = NULL; |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 674 page_info.id.c_str())); | 703 page_info.id.c_str())); |
| 675 std::string devtools_frontend_url = GetFrontendURLInternal( | 704 std::string devtools_frontend_url = GetFrontendURLInternal( |
| 676 page_info.id.c_str(), | 705 page_info.id.c_str(), |
| 677 host); | 706 host); |
| 678 dictionary->SetString("devtoolsFrontendUrl", devtools_frontend_url); | 707 dictionary->SetString("devtoolsFrontendUrl", devtools_frontend_url); |
| 679 } | 708 } |
| 680 return dictionary; | 709 return dictionary; |
| 681 } | 710 } |
| 682 | 711 |
| 683 } // namespace content | 712 } // namespace content |
| OLD | NEW |