OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/browser/debugger/devtools_manager.h" | 5 #include "chrome/browser/debugger/devtools_manager.h" |
6 | 6 |
| 7 #include <vector> |
| 8 |
7 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
8 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/browsing_instance.h" | 11 #include "chrome/browser/browsing_instance.h" |
10 #include "chrome/browser/child_process_security_policy.h" | 12 #include "chrome/browser/child_process_security_policy.h" |
11 #include "chrome/browser/debugger/devtools_window.h" | 13 #include "chrome/browser/debugger/devtools_window.h" |
12 #include "chrome/browser/debugger/devtools_client_host.h" | 14 #include "chrome/browser/debugger/devtools_client_host.h" |
13 #include "chrome/browser/profile.h" | 15 #include "chrome/browser/profile.h" |
14 #include "chrome/browser/renderer_host/render_view_host.h" | 16 #include "chrome/browser/renderer_host/render_view_host.h" |
15 #include "chrome/browser/renderer_host/site_instance.h" | 17 #include "chrome/browser/renderer_host/site_instance.h" |
16 #include "chrome/browser/tab_contents/tab_contents.h" | 18 #include "chrome/browser/tab_contents/tab_contents.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 | 52 |
51 void DevToolsManager::RegisterDevToolsClientHostFor( | 53 void DevToolsManager::RegisterDevToolsClientHostFor( |
52 RenderViewHost* inspected_rvh, | 54 RenderViewHost* inspected_rvh, |
53 DevToolsClientHost* client_host) { | 55 DevToolsClientHost* client_host) { |
54 DCHECK(!GetDevToolsClientHostFor(inspected_rvh)); | 56 DCHECK(!GetDevToolsClientHostFor(inspected_rvh)); |
55 | 57 |
56 inspected_rvh_to_client_host_[inspected_rvh] = client_host; | 58 inspected_rvh_to_client_host_[inspected_rvh] = client_host; |
57 client_host_to_inspected_rvh_[client_host] = inspected_rvh; | 59 client_host_to_inspected_rvh_[client_host] = inspected_rvh; |
58 client_host->set_close_listener(this); | 60 client_host->set_close_listener(this); |
59 | 61 |
60 SendAttachToAgent(inspected_rvh); | 62 SendAttachToAgent(inspected_rvh, std::set<std::string>()); |
61 } | 63 } |
62 | 64 |
63 void DevToolsManager::ForwardToDevToolsAgent( | 65 void DevToolsManager::ForwardToDevToolsAgent( |
64 RenderViewHost* client_rvh, | 66 RenderViewHost* client_rvh, |
65 const IPC::Message& message) { | 67 const IPC::Message& message) { |
66 DevToolsClientHost* client_host = FindOnwerDevToolsClientHost(client_rvh); | 68 DevToolsClientHost* client_host = FindOnwerDevToolsClientHost(client_rvh); |
67 if (client_host) | 69 if (client_host) |
68 ForwardToDevToolsAgent(client_host, message); | 70 ForwardToDevToolsAgent(client_host, message); |
69 } | 71 } |
70 | 72 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 } | 129 } |
128 | 130 |
129 void DevToolsManager::OpenDevToolsWindow(RenderViewHost* inspected_rvh) { | 131 void DevToolsManager::OpenDevToolsWindow(RenderViewHost* inspected_rvh) { |
130 ToggleDevToolsWindow(inspected_rvh, true); | 132 ToggleDevToolsWindow(inspected_rvh, true); |
131 } | 133 } |
132 | 134 |
133 void DevToolsManager::ToggleDevToolsWindow(RenderViewHost* inspected_rvh) { | 135 void DevToolsManager::ToggleDevToolsWindow(RenderViewHost* inspected_rvh) { |
134 ToggleDevToolsWindow(inspected_rvh, false); | 136 ToggleDevToolsWindow(inspected_rvh, false); |
135 } | 137 } |
136 | 138 |
| 139 void DevToolsManager::RuntimeFeatureStateChanged(RenderViewHost* inspected_rvh, |
| 140 const std::string& feature, |
| 141 bool enabled) { |
| 142 RuntimeFeaturesMap::iterator it = runtime_features_.find(inspected_rvh); |
| 143 if (it == runtime_features_.end()) { |
| 144 std::pair<RenderViewHost*, std::set<std::string> > value( |
| 145 inspected_rvh, |
| 146 std::set<std::string>()); |
| 147 it = runtime_features_.insert(value).first; |
| 148 } |
| 149 if (enabled) |
| 150 it->second.insert(feature); |
| 151 else |
| 152 it->second.erase(feature); |
| 153 } |
| 154 |
137 void DevToolsManager::InspectElement(RenderViewHost* inspected_rvh, | 155 void DevToolsManager::InspectElement(RenderViewHost* inspected_rvh, |
138 int x, | 156 int x, |
139 int y) { | 157 int y) { |
140 OpenDevToolsWindow(inspected_rvh); | 158 OpenDevToolsWindow(inspected_rvh); |
141 IPC::Message* m = new DevToolsAgentMsg_InspectElement(x, y); | 159 IPC::Message* m = new DevToolsAgentMsg_InspectElement(x, y); |
142 m->set_routing_id(inspected_rvh->routing_id()); | 160 m->set_routing_id(inspected_rvh->routing_id()); |
143 inspected_rvh->Send(m); | 161 inspected_rvh->Send(m); |
144 } | 162 } |
145 | 163 |
146 void DevToolsManager::ClientHostClosing(DevToolsClientHost* host) { | 164 void DevToolsManager::ClientHostClosing(DevToolsClientHost* host) { |
147 RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(host); | 165 RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(host); |
148 if (!inspected_rvh) | 166 if (!inspected_rvh) |
149 return; | 167 return; |
150 SendDetachToAgent(inspected_rvh); | 168 SendDetachToAgent(inspected_rvh); |
151 | 169 |
152 inspected_rvh_to_client_host_.erase(inspected_rvh); | 170 inspected_rvh_to_client_host_.erase(inspected_rvh); |
| 171 runtime_features_.erase(inspected_rvh); |
153 client_host_to_inspected_rvh_.erase(host); | 172 client_host_to_inspected_rvh_.erase(host); |
154 } | 173 } |
155 | 174 |
156 RenderViewHost* DevToolsManager::GetInspectedRenderViewHost( | 175 RenderViewHost* DevToolsManager::GetInspectedRenderViewHost( |
157 DevToolsClientHost* client_host) { | 176 DevToolsClientHost* client_host) { |
158 ClientHostToInspectedRvhMap::iterator it = | 177 ClientHostToInspectedRvhMap::iterator it = |
159 client_host_to_inspected_rvh_.find(client_host); | 178 client_host_to_inspected_rvh_.find(client_host); |
160 if (it != client_host_to_inspected_rvh_.end()) | 179 if (it != client_host_to_inspected_rvh_.end()) |
161 return it->second; | 180 return it->second; |
162 return NULL; | 181 return NULL; |
163 } | 182 } |
164 | 183 |
165 void DevToolsManager::UnregisterDevToolsClientHostFor( | 184 void DevToolsManager::UnregisterDevToolsClientHostFor( |
166 RenderViewHost* inspected_rvh) { | 185 RenderViewHost* inspected_rvh) { |
167 DevToolsClientHost* host = GetDevToolsClientHostFor(inspected_rvh); | 186 DevToolsClientHost* host = GetDevToolsClientHostFor(inspected_rvh); |
168 if (!host) | 187 if (!host) |
169 return; | 188 return; |
170 inspected_rvh_to_client_host_.erase(inspected_rvh); | 189 inspected_rvh_to_client_host_.erase(inspected_rvh); |
| 190 runtime_features_.erase(inspected_rvh); |
| 191 |
171 client_host_to_inspected_rvh_.erase(host); | 192 client_host_to_inspected_rvh_.erase(host); |
172 if (inspected_rvh_for_reopen_ == inspected_rvh) | 193 if (inspected_rvh_for_reopen_ == inspected_rvh) |
173 inspected_rvh_for_reopen_ = NULL; | 194 inspected_rvh_for_reopen_ = NULL; |
174 | 195 |
175 // Issue tab closing event post unbound. | 196 // Issue tab closing event post unbound. |
176 host->InspectedTabClosing(); | 197 host->InspectedTabClosing(); |
177 | 198 |
178 int process_id = inspected_rvh->process()->id(); | 199 int process_id = inspected_rvh->process()->id(); |
179 for (InspectedRvhToClientHostMap::iterator it = | 200 for (InspectedRvhToClientHostMap::iterator it = |
180 inspected_rvh_to_client_host_.begin(); | 201 inspected_rvh_to_client_host_.begin(); |
(...skipping 10 matching lines...) Expand all Loading... |
191 RenderViewHost* dest_rvh, | 212 RenderViewHost* dest_rvh, |
192 const GURL& gurl) { | 213 const GURL& gurl) { |
193 if (in_initial_show_) { | 214 if (in_initial_show_) { |
194 // Mute this even in case it is caused by the initial show routines. | 215 // Mute this even in case it is caused by the initial show routines. |
195 return; | 216 return; |
196 } | 217 } |
197 DevToolsClientHost* client_host = | 218 DevToolsClientHost* client_host = |
198 GetDevToolsClientHostFor(rvh); | 219 GetDevToolsClientHostFor(rvh); |
199 if (client_host) { | 220 if (client_host) { |
200 // Navigating to URL in the inspected window. | 221 // Navigating to URL in the inspected window. |
| 222 std::set<std::string> runtime_features = runtime_features_[rvh]; |
201 inspected_rvh_to_client_host_.erase(rvh); | 223 inspected_rvh_to_client_host_.erase(rvh); |
| 224 runtime_features_.erase(rvh); |
202 inspected_rvh_to_client_host_[dest_rvh] = client_host; | 225 inspected_rvh_to_client_host_[dest_rvh] = client_host; |
203 client_host_to_inspected_rvh_[client_host] = dest_rvh; | 226 client_host_to_inspected_rvh_[client_host] = dest_rvh; |
204 SendAttachToAgent(dest_rvh); | 227 SendAttachToAgent(dest_rvh, runtime_features); |
205 return; | 228 return; |
206 } | 229 } |
207 | 230 |
208 // Iterate over client hosts and if there is one that has render view host | 231 // Iterate over client hosts and if there is one that has render view host |
209 // changing, reopen entire client window (this must be caused by the user | 232 // changing, reopen entire client window (this must be caused by the user |
210 // manually refreshing its content). | 233 // manually refreshing its content). |
211 for (ClientHostToInspectedRvhMap::iterator it = | 234 for (ClientHostToInspectedRvhMap::iterator it = |
212 client_host_to_inspected_rvh_.begin(); | 235 client_host_to_inspected_rvh_.begin(); |
213 it != client_host_to_inspected_rvh_.end(); ++it) { | 236 it != client_host_to_inspected_rvh_.end(); ++it) { |
214 DevToolsWindow* window = it->first->AsDevToolsWindow(); | 237 DevToolsWindow* window = it->first->AsDevToolsWindow(); |
215 if (window && window->GetRenderViewHost() == rvh) { | 238 if (window && window->GetRenderViewHost() == rvh) { |
216 inspected_rvh_for_reopen_ = it->second; | 239 inspected_rvh_for_reopen_ = it->second; |
217 MessageLoop::current()->PostTask(FROM_HERE, | 240 MessageLoop::current()->PostTask(FROM_HERE, |
218 NewRunnableMethod(this, | 241 NewRunnableMethod(this, |
219 &DevToolsManager::ForceReopenWindow)); | 242 &DevToolsManager::ForceReopenWindow)); |
220 return; | 243 return; |
221 } | 244 } |
222 } | 245 } |
223 } | 246 } |
224 | 247 |
225 void DevToolsManager::SendAttachToAgent(RenderViewHost* inspected_rvh) { | 248 void DevToolsManager::SendAttachToAgent( |
| 249 RenderViewHost* inspected_rvh, |
| 250 const std::set<std::string>& runtime_features) { |
226 if (inspected_rvh) { | 251 if (inspected_rvh) { |
227 ChildProcessSecurityPolicy::GetInstance()->GrantReadRawCookies( | 252 ChildProcessSecurityPolicy::GetInstance()->GrantReadRawCookies( |
228 inspected_rvh->process()->id()); | 253 inspected_rvh->process()->id()); |
229 IPC::Message* m = new DevToolsAgentMsg_Attach(); | 254 std::vector<std::string> features(runtime_features.begin(), |
| 255 runtime_features.end()); |
| 256 IPC::Message* m = new DevToolsAgentMsg_Attach(features); |
230 m->set_routing_id(inspected_rvh->routing_id()); | 257 m->set_routing_id(inspected_rvh->routing_id()); |
231 inspected_rvh->Send(m); | 258 inspected_rvh->Send(m); |
232 } | 259 } |
233 } | 260 } |
234 | 261 |
235 void DevToolsManager::SendDetachToAgent(RenderViewHost* inspected_rvh) { | 262 void DevToolsManager::SendDetachToAgent(RenderViewHost* inspected_rvh) { |
236 if (inspected_rvh) { | 263 if (inspected_rvh) { |
237 IPC::Message* m = new DevToolsAgentMsg_Detach(); | 264 IPC::Message* m = new DevToolsAgentMsg_Detach(); |
238 m->set_routing_id(inspected_rvh->routing_id()); | 265 m->set_routing_id(inspected_rvh->routing_id()); |
239 inspected_rvh->Send(m); | 266 inspected_rvh->Send(m); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 } | 339 } |
313 } | 340 } |
314 | 341 |
315 void DevToolsManager::CloseWindow(DevToolsClientHost* client_host) { | 342 void DevToolsManager::CloseWindow(DevToolsClientHost* client_host) { |
316 RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(client_host); | 343 RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(client_host); |
317 DCHECK(inspected_rvh); | 344 DCHECK(inspected_rvh); |
318 SendDetachToAgent(inspected_rvh); | 345 SendDetachToAgent(inspected_rvh); |
319 | 346 |
320 UnregisterDevToolsClientHostFor(inspected_rvh); | 347 UnregisterDevToolsClientHostFor(inspected_rvh); |
321 } | 348 } |
OLD | NEW |