Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: content/browser/debugger/devtools_http_handler_impl.cc

Issue 11141024: DevTools: [remote debugging] terminate web socket connection upon renderer disconnect. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Removed extra file Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 "googleurl/src/gurl.h" 37 #include "googleurl/src/gurl.h"
36 #include "grit/devtools_resources_map.h" 38 #include "grit/devtools_resources_map.h"
37 #include "net/base/escape.h" 39 #include "net/base/escape.h"
38 #include "net/base/io_buffer.h" 40 #include "net/base/io_buffer.h"
39 #include "net/base/ip_endpoint.h" 41 #include "net/base/ip_endpoint.h"
40 #include "net/server/http_server_request_info.h" 42 #include "net/server/http_server_request_info.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 if (!base::StringToInt(identifier.substr(pos+1), &routing_id)) 76 if (!base::StringToInt(identifier.substr(pos+1), &routing_id))
75 return NULL; 77 return NULL;
76 78
77 return RenderViewHost::FromID(process_id, routing_id); 79 return RenderViewHost::FromID(process_id, routing_id);
78 } 80 }
79 }; 81 };
80 82
81 83
82 // An internal implementation of DevToolsClientHost that delegates 84 // An internal implementation of DevToolsClientHost that delegates
83 // messages sent for DevToolsClient to a DebuggerShell instance. 85 // messages sent for DevToolsClient to a DebuggerShell instance.
84 class DevToolsClientHostImpl : public DevToolsClientHost { 86 class DevToolsClientHostImpl : public DevToolsClientHost,
87 public NotificationObserver {
85 public: 88 public:
86 DevToolsClientHostImpl( 89 DevToolsClientHostImpl(
87 MessageLoop* message_loop, 90 MessageLoop* message_loop,
88 net::HttpServer* server, 91 net::HttpServer* server,
89 int connection_id) 92 int connection_id,
93 RenderProcessHost* process_host)
90 : message_loop_(message_loop), 94 : message_loop_(message_loop),
91 server_(server), 95 server_(server),
92 connection_id_(connection_id) { 96 connection_id_(connection_id),
97 is_closed_(false) {
98 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_TERMINATED,
99 Source<RenderProcessHost>(process_host));
100 registrar_.Add(this, NOTIFICATION_RENDERER_PROCESS_CLOSED,
yurys 2012/10/16 06:18:20 We listen to the termination of the render process
pfeldman 2012/10/16 08:35:28 We maintain WebSocket connection (And DevToolsClie
101 Source<RenderProcessHost>(process_host));
93 } 102 }
103
94 ~DevToolsClientHostImpl() {} 104 ~DevToolsClientHostImpl() {}
95 105
96 // DevToolsClientHost interface 106 // DevToolsClientHost interface
97 virtual void InspectedContentsClosing() { 107 virtual void InspectedContentsClosing() {
108 if (is_closed_)
109 return;
110 is_closed_ = true;
98 message_loop_->PostTask( 111 message_loop_->PostTask(
99 FROM_HERE, 112 FROM_HERE,
100 base::Bind(&net::HttpServer::Close, server_, connection_id_)); 113 base::Bind(&net::HttpServer::Close, server_, connection_id_));
101 } 114 }
102 115
103 virtual void DispatchOnInspectorFrontend(const std::string& data) { 116 virtual void DispatchOnInspectorFrontend(const std::string& data) {
104 message_loop_->PostTask( 117 message_loop_->PostTask(
105 FROM_HERE, 118 FROM_HERE,
106 base::Bind(&net::HttpServer::SendOverWebSocket, 119 base::Bind(&net::HttpServer::SendOverWebSocket,
107 server_, 120 server_,
108 connection_id_, 121 connection_id_,
109 data)); 122 data));
110 } 123 }
111 124
112 virtual void ContentsReplaced(WebContents* new_contents) { 125 virtual void ContentsReplaced(WebContents* new_contents) {
113 } 126 }
114 127
115 private: 128 private:
129 virtual void Observe(int type,
130 const NotificationSource& source,
131 const NotificationDetails& details) {
132 InspectedContentsClosing();
133 }
134
116 virtual void FrameNavigating(const std::string& url) {} 135 virtual void FrameNavigating(const std::string& url) {}
117 MessageLoop* message_loop_; 136 MessageLoop* message_loop_;
118 net::HttpServer* server_; 137 net::HttpServer* server_;
119 int connection_id_; 138 int connection_id_;
139 bool is_closed_;
140 NotificationRegistrar registrar_;
120 }; 141 };
121 142
122 } // namespace 143 } // namespace
123 144
124 // static 145 // static
125 int DevToolsHttpHandler::GetFrontendResourceId(const std::string& name) { 146 int DevToolsHttpHandler::GetFrontendResourceId(const std::string& name) {
126 for (size_t i = 0; i < kDevtoolsResourcesSize; ++i) { 147 for (size_t i = 0; i < kDevtoolsResourcesSize; ++i) {
127 if (name == kDevtoolsResources[i].name) 148 if (name == kDevtoolsResources[i].name)
128 return kDevtoolsResources[i].value; 149 return kDevtoolsResources[i].value;
129 } 150 }
(...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 rvh); 500 rvh);
480 if (manager->GetDevToolsClientHostFor(agent)) { 501 if (manager->GetDevToolsClientHostFor(agent)) {
481 Send500(connection_id, "Target with given id is being inspected: " + 502 Send500(connection_id, "Target with given id is being inspected: " +
482 page_id); 503 page_id);
483 return; 504 return;
484 } 505 }
485 506
486 DevToolsClientHostImpl* client_host = 507 DevToolsClientHostImpl* client_host =
487 new DevToolsClientHostImpl(thread_->message_loop(), 508 new DevToolsClientHostImpl(thread_->message_loop(),
488 server_, 509 server_,
489 connection_id); 510 connection_id,
511 rvh->GetProcess());
yurys 2012/10/16 06:18:20 This will not work for clients attached to instanc
pfeldman 2012/10/16 08:35:28 Allowing workers will require a major rewrite of d
490 connection_to_client_host_ui_[connection_id] = client_host; 512 connection_to_client_host_ui_[connection_id] = client_host;
491 513
492 manager->RegisterDevToolsClientHostFor(agent, client_host); 514 manager->RegisterDevToolsClientHostFor(agent, client_host);
493 515
494 AcceptWebSocket(connection_id, request); 516 AcceptWebSocket(connection_id, request);
495 } 517 }
496 518
497 void DevToolsHttpHandlerImpl::OnWebSocketMessageUI( 519 void DevToolsHttpHandlerImpl::OnWebSocketMessageUI(
498 int connection_id, 520 int connection_id,
499 const std::string& data) { 521 const std::string& data) {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 page_info.id.c_str())); 667 page_info.id.c_str()));
646 std::string devtools_frontend_url = GetFrontendURLInternal( 668 std::string devtools_frontend_url = GetFrontendURLInternal(
647 page_info.id.c_str(), 669 page_info.id.c_str(),
648 host); 670 host);
649 dictionary->SetString("devtoolsFrontendUrl", devtools_frontend_url); 671 dictionary->SetString("devtoolsFrontendUrl", devtools_frontend_url);
650 } 672 }
651 return dictionary; 673 return dictionary;
652 } 674 }
653 675
654 } // namespace content 676 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698