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_manager.h" | 5 #include "content/browser/debugger/devtools_manager.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/io_thread.h" | 12 #include "chrome/browser/io_thread.h" |
13 #include "chrome/browser/prefs/pref_service.h" | 13 #include "chrome/browser/prefs/pref_service.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
15 #include "chrome/browser/profiles/profile_manager.h" | |
Jói
2011/07/05 18:00:45
Please don't add a new dependency on ProfileManage
pfeldman
2011/07/06 08:29:39
Do you have an estimate on when migration is compl
jam
2011/07/06 13:47:40
if a method is added to ContentBrowserClient to re
yurys
2011/07/06 14:03:52
My understanding is that DevToolsWindow is a Chrom
| |
15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
16 #include "chrome/common/pref_names.h" | 17 #include "chrome/common/pref_names.h" |
17 #include "content/browser/browsing_instance.h" | 18 #include "content/browser/browsing_instance.h" |
18 #include "content/browser/child_process_security_policy.h" | 19 #include "content/browser/child_process_security_policy.h" |
19 #include "content/browser/debugger/devtools_client_host.h" | 20 #include "content/browser/debugger/devtools_client_host.h" |
20 #include "content/browser/debugger/devtools_netlog_observer.h" | 21 #include "content/browser/debugger/devtools_netlog_observer.h" |
21 #include "content/browser/debugger/devtools_window.h" | 22 #include "content/browser/debugger/devtools_window.h" |
23 #include "content/browser/debugger/worker_devtools_manager.h" | |
22 #include "content/browser/renderer_host/render_view_host.h" | 24 #include "content/browser/renderer_host/render_view_host.h" |
23 #include "content/browser/site_instance.h" | 25 #include "content/browser/site_instance.h" |
24 #include "content/common/devtools_messages.h" | 26 #include "content/common/devtools_messages.h" |
25 #include "content/common/notification_service.h" | 27 #include "content/common/notification_service.h" |
26 #include "googleurl/src/gurl.h" | 28 #include "googleurl/src/gurl.h" |
27 | 29 |
28 // static | 30 // static |
29 DevToolsManager* DevToolsManager::GetInstance() { | 31 DevToolsManager* DevToolsManager::GetInstance() { |
30 // http://crbug.com/47806 this method may be called when BrowserProcess | 32 // http://crbug.com/47806 this method may be called when BrowserProcess |
31 // has already been destroyed. | 33 // has already been destroyed. |
(...skipping 16 matching lines...) Expand all Loading... | |
48 registrar_.Add(this, NotificationType::RENDER_VIEW_HOST_DELETED, | 50 registrar_.Add(this, NotificationType::RENDER_VIEW_HOST_DELETED, |
49 NotificationService::AllSources()); | 51 NotificationService::AllSources()); |
50 } | 52 } |
51 | 53 |
52 DevToolsManager::~DevToolsManager() { | 54 DevToolsManager::~DevToolsManager() { |
53 DCHECK(inspected_rvh_to_client_host_.empty()); | 55 DCHECK(inspected_rvh_to_client_host_.empty()); |
54 DCHECK(client_host_to_inspected_rvh_.empty()); | 56 DCHECK(client_host_to_inspected_rvh_.empty()); |
55 // By the time we destroy devtools manager, all orphan client hosts should | 57 // By the time we destroy devtools manager, all orphan client hosts should |
56 // have been delelted, no need to notify them upon tab closing. | 58 // have been delelted, no need to notify them upon tab closing. |
57 DCHECK(orphan_client_hosts_.empty()); | 59 DCHECK(orphan_client_hosts_.empty()); |
60 DCHECK(worker_id_to_client_host_.empty()); | |
58 } | 61 } |
59 | 62 |
60 DevToolsClientHost* DevToolsManager::GetDevToolsClientHostFor( | 63 DevToolsClientHost* DevToolsManager::GetDevToolsClientHostFor( |
61 RenderViewHost* inspected_rvh) { | 64 RenderViewHost* inspected_rvh) { |
62 InspectedRvhToClientHostMap::iterator it = | 65 InspectedRvhToClientHostMap::iterator it = |
63 inspected_rvh_to_client_host_.find(inspected_rvh); | 66 inspected_rvh_to_client_host_.find(inspected_rvh); |
64 if (it != inspected_rvh_to_client_host_.end()) | 67 if (it != inspected_rvh_to_client_host_.end()) |
65 return it->second; | 68 return it->second; |
66 return NULL; | 69 return NULL; |
67 } | 70 } |
68 | 71 |
69 void DevToolsManager::RegisterDevToolsClientHostFor( | 72 void DevToolsManager::RegisterDevToolsClientHostFor( |
70 RenderViewHost* inspected_rvh, | 73 RenderViewHost* inspected_rvh, |
71 DevToolsClientHost* client_host) { | 74 DevToolsClientHost* client_host) { |
72 DCHECK(!GetDevToolsClientHostFor(inspected_rvh)); | 75 DCHECK(!GetDevToolsClientHostFor(inspected_rvh)); |
73 | 76 |
74 DevToolsRuntimeProperties initial_properties; | 77 DevToolsRuntimeProperties initial_properties; |
75 BindClientHost(inspected_rvh, client_host, initial_properties); | 78 BindClientHost(inspected_rvh, client_host, initial_properties); |
76 client_host->set_close_listener(this); | 79 client_host->set_close_listener(this); |
77 SendAttachToAgent(inspected_rvh); | 80 SendAttachToAgent(inspected_rvh); |
78 } | 81 } |
79 | 82 |
80 void DevToolsManager::ForwardToDevToolsAgent( | 83 void DevToolsManager::ForwardToDevToolsAgent( |
81 RenderViewHost* client_rvh, | 84 RenderViewHost* client_rvh, |
82 const IPC::Message& message) { | 85 const IPC::Message& message) { |
83 DevToolsClientHost* client_host = FindOwnerDevToolsClientHost(client_rvh); | 86 DevToolsClientHost* client_host = FindOwnerDevToolsClientHost(client_rvh); |
84 if (client_host) | 87 if (client_host) { |
85 ForwardToDevToolsAgent(client_host, message); | 88 ForwardToDevToolsAgent(client_host, message); |
89 return; | |
90 } | |
91 ForwardToWorkerDevToolsAgent(client_rvh, message); | |
86 } | 92 } |
87 | 93 |
88 void DevToolsManager::ForwardToDevToolsAgent(DevToolsClientHost* from, | 94 void DevToolsManager::ForwardToDevToolsAgent(DevToolsClientHost* from, |
89 const IPC::Message& message) { | 95 const IPC::Message& message) { |
90 RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(from); | 96 RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(from); |
91 if (!inspected_rvh) { | 97 if (!inspected_rvh) { |
92 // TODO(yurys): notify client that the agent is no longer available | 98 // TODO(yurys): notify client that the agent is no longer available |
93 NOTREACHED(); | 99 NOTREACHED(); |
94 return; | 100 return; |
95 } | 101 } |
96 | 102 |
97 IPC::Message* m = new IPC::Message(message); | 103 IPC::Message* m = new IPC::Message(message); |
98 m->set_routing_id(inspected_rvh->routing_id()); | 104 m->set_routing_id(inspected_rvh->routing_id()); |
99 inspected_rvh->Send(m); | 105 inspected_rvh->Send(m); |
100 } | 106 } |
101 | 107 |
102 void DevToolsManager::ForwardToDevToolsClient(RenderViewHost* inspected_rvh, | 108 void DevToolsManager::ForwardToDevToolsClient(RenderViewHost* inspected_rvh, |
103 const IPC::Message& message) { | 109 const IPC::Message& message) { |
104 DevToolsClientHost* client_host = GetDevToolsClientHostFor(inspected_rvh); | 110 DevToolsClientHost* client_host = GetDevToolsClientHostFor(inspected_rvh); |
105 if (!client_host) { | 111 if (!client_host) { |
106 // Client window was closed while there were messages | 112 // Client window was closed while there were messages |
107 // being sent to it. | 113 // being sent to it. |
108 return; | 114 return; |
109 } | 115 } |
110 client_host->SendMessageToClient(message); | 116 client_host->SendMessageToClient(message); |
111 } | 117 } |
112 | 118 |
119 void DevToolsManager::OpenDevToolsForWorker(int worker_devtools_id) { | |
120 Profile* profile = ProfileManager::GetDefaultProfile(); | |
121 if (!profile) | |
122 return; | |
123 DevToolsWindow* window = new DevToolsWindow(profile, NULL, false); | |
124 window->set_close_listener(this); | |
125 window->Show(DEVTOOLS_TOGGLE_ACTION_NONE); | |
126 worker_id_to_client_host_[worker_devtools_id] = window; | |
127 } | |
128 | |
129 void DevToolsManager::ForwardToWorkerDevToolsClient( | |
130 int worker_devtools_id, | |
131 const IPC::Message& message) { | |
132 WorkerIdToClientHostMap::iterator it = | |
133 worker_id_to_client_host_.find(worker_devtools_id); | |
134 if (it == worker_id_to_client_host_.end()) | |
135 return; | |
136 it->second->SendMessageToClient(message); | |
137 } | |
138 | |
139 static void ForwardToWorkerDevToolsAgentOnIOThread( | |
140 int worker_devtools_id, | |
141 const IPC::Message& message) { | |
142 WorkerDevToolsManager::GetInstance()->ForwardToWorkerDevToolsAgent( | |
143 worker_devtools_id, message); | |
144 } | |
145 | |
146 void DevToolsManager::ForwardToWorkerDevToolsAgent( | |
147 RenderViewHost* client_rvh, | |
148 const IPC::Message& message) { | |
149 int worker_devtools_id = FindWorkerDevToolsId(client_rvh); | |
150 if (worker_devtools_id == -1) | |
151 return; | |
152 BrowserThread::PostTask( | |
153 BrowserThread::IO, FROM_HERE, | |
154 NewRunnableFunction( | |
155 ForwardToWorkerDevToolsAgentOnIOThread, | |
156 worker_devtools_id, | |
157 IPC::Message(message))); | |
158 } | |
159 | |
160 int DevToolsManager::FindWorkerDevToolsId(RenderViewHost* client_rvh) { | |
161 for (WorkerIdToClientHostMap::const_iterator it = | |
162 worker_id_to_client_host_.begin(); | |
163 it != worker_id_to_client_host_.end(); ++it) { | |
164 DevToolsWindow* window = it->second->AsDevToolsWindow(); | |
165 if (!window) | |
166 continue; | |
167 if (window->GetRenderViewHost() != client_rvh) | |
168 continue; | |
169 return it->first; | |
170 } | |
171 return -1; | |
172 } | |
173 | |
174 static void NotifyWorkerDevToolsClientClosingOnIOThread( | |
175 int worker_devtools_id) { | |
176 WorkerDevToolsManager::GetInstance()->WorkerDevToolsClientClosing( | |
177 worker_devtools_id); | |
178 } | |
179 | |
180 void DevToolsManager::MaybeWorkerDevToolsClientHostClosing( | |
181 DevToolsClientHost* host) { | |
182 WorkerIdToClientHostMap::iterator it = worker_id_to_client_host_.begin(); | |
183 for (; it != worker_id_to_client_host_.end(); ++it) { | |
184 if (it->second == host) { | |
185 BrowserThread::PostTask( | |
186 BrowserThread::IO, FROM_HERE, | |
187 NewRunnableFunction(NotifyWorkerDevToolsClientClosingOnIOThread, | |
188 it->first)); | |
189 worker_id_to_client_host_.erase(it); | |
190 return; | |
191 } | |
192 } | |
193 } | |
194 | |
113 void DevToolsManager::ActivateWindow(RenderViewHost* client_rvh) { | 195 void DevToolsManager::ActivateWindow(RenderViewHost* client_rvh) { |
114 DevToolsClientHost* client_host = FindOwnerDevToolsClientHost(client_rvh); | 196 DevToolsClientHost* client_host = FindOwnerDevToolsClientHost(client_rvh); |
115 if (!client_host) | 197 if (!client_host) |
116 return; | 198 return; |
117 | 199 |
118 DevToolsWindow* window = client_host->AsDevToolsWindow(); | 200 DevToolsWindow* window = client_host->AsDevToolsWindow(); |
119 DCHECK(window); | 201 DCHECK(window); |
120 window->Activate(); | 202 window->Activate(); |
121 } | 203 } |
122 | 204 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(host); | 261 RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(host); |
180 if (!inspected_rvh) { | 262 if (!inspected_rvh) { |
181 // It might be in the list of orphan client hosts, remove it from there. | 263 // It might be in the list of orphan client hosts, remove it from there. |
182 for (OrphanClientHosts::iterator it = orphan_client_hosts_.begin(); | 264 for (OrphanClientHosts::iterator it = orphan_client_hosts_.begin(); |
183 it != orphan_client_hosts_.end(); ++it) { | 265 it != orphan_client_hosts_.end(); ++it) { |
184 if (it->second.first == host) { | 266 if (it->second.first == host) { |
185 orphan_client_hosts_.erase(it->first); | 267 orphan_client_hosts_.erase(it->first); |
186 return; | 268 return; |
187 } | 269 } |
188 } | 270 } |
271 | |
272 // Worker DevTools clients don't have inspected RVHs. Check if one of them | |
273 // is closing. | |
274 MaybeWorkerDevToolsClientHostClosing(host); | |
189 return; | 275 return; |
190 } | 276 } |
191 | 277 |
192 NotificationService::current()->Notify( | 278 NotificationService::current()->Notify( |
193 NotificationType::DEVTOOLS_WINDOW_CLOSING, | 279 NotificationType::DEVTOOLS_WINDOW_CLOSING, |
194 Source<Profile>(inspected_rvh->site_instance()->GetProcess()->profile()), | 280 Source<Profile>(inspected_rvh->site_instance()->GetProcess()->profile()), |
195 Details<RenderViewHost>(inspected_rvh)); | 281 Details<RenderViewHost>(inspected_rvh)); |
196 | 282 |
197 UnbindClientHost(inspected_rvh, host); | 283 UnbindClientHost(inspected_rvh, host); |
198 } | 284 } |
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
457 for (InspectedRvhToClientHostMap::iterator it = | 543 for (InspectedRvhToClientHostMap::iterator it = |
458 inspected_rvh_to_client_host_.begin(); | 544 inspected_rvh_to_client_host_.begin(); |
459 it != inspected_rvh_to_client_host_.end(); ++it) { | 545 it != inspected_rvh_to_client_host_.end(); ++it) { |
460 rhvs.push_back(it->first); | 546 rhvs.push_back(it->first); |
461 } | 547 } |
462 for (std::vector<RenderViewHost*>::iterator it = rhvs.begin(); | 548 for (std::vector<RenderViewHost*>::iterator it = rhvs.begin(); |
463 it != rhvs.end(); ++it) { | 549 it != rhvs.end(); ++it) { |
464 UnregisterDevToolsClientHostFor(*it); | 550 UnregisterDevToolsClientHostFor(*it); |
465 } | 551 } |
466 } | 552 } |
OLD | NEW |