| 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 "base/message_loop.h" | 7 #include "base/message_loop.h" |
| 8 #include "chrome/browser/browser_process.h" | 8 #include "chrome/browser/browser_process.h" |
| 9 #include "chrome/browser/browsing_instance.h" | 9 #include "chrome/browser/browsing_instance.h" |
| 10 #include "chrome/browser/child_process_security_policy.h" |
| 10 #include "chrome/browser/debugger/devtools_window.h" | 11 #include "chrome/browser/debugger/devtools_window.h" |
| 11 #include "chrome/browser/debugger/devtools_client_host.h" | 12 #include "chrome/browser/debugger/devtools_client_host.h" |
| 12 #include "chrome/browser/profile.h" | 13 #include "chrome/browser/profile.h" |
| 13 #include "chrome/browser/renderer_host/render_view_host.h" | 14 #include "chrome/browser/renderer_host/render_view_host.h" |
| 14 #include "chrome/browser/renderer_host/site_instance.h" | 15 #include "chrome/browser/renderer_host/site_instance.h" |
| 15 #include "chrome/browser/tab_contents/tab_contents.h" | 16 #include "chrome/browser/tab_contents/tab_contents.h" |
| 16 #include "chrome/common/devtools_messages.h" | 17 #include "chrome/common/devtools_messages.h" |
| 17 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
| 18 #include "chrome/common/pref_service.h" | 19 #include "chrome/common/pref_service.h" |
| 19 #include "googleurl/src/gurl.h" | 20 #include "googleurl/src/gurl.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 35 | 36 |
| 36 DevToolsManager::~DevToolsManager() { | 37 DevToolsManager::~DevToolsManager() { |
| 37 DCHECK(inspected_rvh_to_client_host_.empty()); | 38 DCHECK(inspected_rvh_to_client_host_.empty()); |
| 38 DCHECK(client_host_to_inspected_rvh_.empty()); | 39 DCHECK(client_host_to_inspected_rvh_.empty()); |
| 39 } | 40 } |
| 40 | 41 |
| 41 DevToolsClientHost* DevToolsManager::GetDevToolsClientHostFor( | 42 DevToolsClientHost* DevToolsManager::GetDevToolsClientHostFor( |
| 42 RenderViewHost* inspected_rvh) { | 43 RenderViewHost* inspected_rvh) { |
| 43 InspectedRvhToClientHostMap::iterator it = | 44 InspectedRvhToClientHostMap::iterator it = |
| 44 inspected_rvh_to_client_host_.find(inspected_rvh); | 45 inspected_rvh_to_client_host_.find(inspected_rvh); |
| 45 if (it != inspected_rvh_to_client_host_.end()) { | 46 if (it != inspected_rvh_to_client_host_.end()) |
| 46 return it->second; | 47 return it->second; |
| 47 } | |
| 48 return NULL; | 48 return NULL; |
| 49 } | 49 } |
| 50 | 50 |
| 51 void DevToolsManager::RegisterDevToolsClientHostFor( | 51 void DevToolsManager::RegisterDevToolsClientHostFor( |
| 52 RenderViewHost* inspected_rvh, | 52 RenderViewHost* inspected_rvh, |
| 53 DevToolsClientHost* client_host) { | 53 DevToolsClientHost* client_host) { |
| 54 DCHECK(!GetDevToolsClientHostFor(inspected_rvh)); | 54 DCHECK(!GetDevToolsClientHostFor(inspected_rvh)); |
| 55 | 55 |
| 56 inspected_rvh_to_client_host_[inspected_rvh] = client_host; | 56 inspected_rvh_to_client_host_[inspected_rvh] = client_host; |
| 57 client_host_to_inspected_rvh_[client_host] = inspected_rvh; | 57 client_host_to_inspected_rvh_[client_host] = inspected_rvh; |
| 58 client_host->set_close_listener(this); | 58 client_host->set_close_listener(this); |
| 59 | 59 |
| 60 SendAttachToAgent(inspected_rvh); | 60 SendAttachToAgent(inspected_rvh); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void DevToolsManager::ForwardToDevToolsAgent( | 63 void DevToolsManager::ForwardToDevToolsAgent( |
| 64 RenderViewHost* client_rvh, | 64 RenderViewHost* client_rvh, |
| 65 const IPC::Message& message) { | 65 const IPC::Message& message) { |
| 66 DevToolsClientHost* client_host = FindOnwerDevToolsClientHost(client_rvh); | 66 DevToolsClientHost* client_host = FindOnwerDevToolsClientHost(client_rvh); |
| 67 if (client_host) { | 67 if (client_host) |
| 68 ForwardToDevToolsAgent(client_host, message); | 68 ForwardToDevToolsAgent(client_host, message); |
| 69 } | |
| 70 } | 69 } |
| 71 | 70 |
| 72 void DevToolsManager::ForwardToDevToolsAgent(DevToolsClientHost* from, | 71 void DevToolsManager::ForwardToDevToolsAgent(DevToolsClientHost* from, |
| 73 const IPC::Message& message) { | 72 const IPC::Message& message) { |
| 74 RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(from); | 73 RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(from); |
| 75 if (!inspected_rvh) { | 74 if (!inspected_rvh) { |
| 76 // TODO(yurys): notify client that the agent is no longer available | 75 // TODO(yurys): notify client that the agent is no longer available |
| 77 NOTREACHED(); | 76 NOTREACHED(); |
| 78 return; | 77 return; |
| 79 } | 78 } |
| 80 | 79 |
| 81 IPC::Message* m = new IPC::Message(message); | 80 IPC::Message* m = new IPC::Message(message); |
| 82 m->set_routing_id(inspected_rvh->routing_id()); | 81 m->set_routing_id(inspected_rvh->routing_id()); |
| 83 inspected_rvh->Send(m); | 82 inspected_rvh->Send(m); |
| 84 } | 83 } |
| 85 | 84 |
| 86 void DevToolsManager::ForwardToDevToolsClient(RenderViewHost* inspected_rvh, | 85 void DevToolsManager::ForwardToDevToolsClient(RenderViewHost* inspected_rvh, |
| 87 const IPC::Message& message) { | 86 const IPC::Message& message) { |
| 88 DevToolsClientHost* client_host = GetDevToolsClientHostFor(inspected_rvh); | 87 DevToolsClientHost* client_host = GetDevToolsClientHostFor(inspected_rvh); |
| 89 if (!client_host) { | 88 if (!client_host) { |
| 90 // Client window was closed while there were messages | 89 // Client window was closed while there were messages |
| 91 // being sent to it. | 90 // being sent to it. |
| 92 return; | 91 return; |
| 93 } | 92 } |
| 94 client_host->SendMessageToClient(message); | 93 client_host->SendMessageToClient(message); |
| 95 } | 94 } |
| 96 | 95 |
| 97 void DevToolsManager::ActivateWindow(RenderViewHost* client_rvh) { | 96 void DevToolsManager::ActivateWindow(RenderViewHost* client_rvh) { |
| 98 DevToolsClientHost* client_host = FindOnwerDevToolsClientHost(client_rvh); | 97 DevToolsClientHost* client_host = FindOnwerDevToolsClientHost(client_rvh); |
| 99 if (!client_host) { | 98 if (!client_host) |
| 100 return; | 99 return; |
| 101 } | 100 |
| 102 DevToolsWindow* window = client_host->AsDevToolsWindow(); | 101 DevToolsWindow* window = client_host->AsDevToolsWindow(); |
| 103 DCHECK(window); | 102 DCHECK(window); |
| 104 window->Activate(); | 103 window->Activate(); |
| 105 } | 104 } |
| 106 | 105 |
| 107 void DevToolsManager::CloseWindow(RenderViewHost* client_rvh) { | 106 void DevToolsManager::CloseWindow(RenderViewHost* client_rvh) { |
| 108 DevToolsClientHost* client_host = FindOnwerDevToolsClientHost(client_rvh); | 107 DevToolsClientHost* client_host = FindOnwerDevToolsClientHost(client_rvh); |
| 109 if (client_host) { | 108 if (client_host) |
| 110 CloseWindow(client_host); | 109 CloseWindow(client_host); |
| 111 } | |
| 112 } | 110 } |
| 113 | 111 |
| 114 void DevToolsManager::DockWindow(RenderViewHost* client_rvh) { | 112 void DevToolsManager::DockWindow(RenderViewHost* client_rvh) { |
| 115 ReopenWindow(client_rvh, true); | 113 ReopenWindow(client_rvh, true); |
| 116 } | 114 } |
| 117 | 115 |
| 118 void DevToolsManager::UndockWindow(RenderViewHost* client_rvh) { | 116 void DevToolsManager::UndockWindow(RenderViewHost* client_rvh) { |
| 119 ReopenWindow(client_rvh, false); | 117 ReopenWindow(client_rvh, false); |
| 120 } | 118 } |
| 121 | 119 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 140 int x, | 138 int x, |
| 141 int y) { | 139 int y) { |
| 142 OpenDevToolsWindow(inspected_rvh); | 140 OpenDevToolsWindow(inspected_rvh); |
| 143 IPC::Message* m = new DevToolsAgentMsg_InspectElement(x, y); | 141 IPC::Message* m = new DevToolsAgentMsg_InspectElement(x, y); |
| 144 m->set_routing_id(inspected_rvh->routing_id()); | 142 m->set_routing_id(inspected_rvh->routing_id()); |
| 145 inspected_rvh->Send(m); | 143 inspected_rvh->Send(m); |
| 146 } | 144 } |
| 147 | 145 |
| 148 void DevToolsManager::ClientHostClosing(DevToolsClientHost* host) { | 146 void DevToolsManager::ClientHostClosing(DevToolsClientHost* host) { |
| 149 RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(host); | 147 RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(host); |
| 150 if (!inspected_rvh) { | 148 if (!inspected_rvh) |
| 151 return; | 149 return; |
| 152 } | |
| 153 SendDetachToAgent(inspected_rvh); | 150 SendDetachToAgent(inspected_rvh); |
| 154 | 151 |
| 155 inspected_rvh_to_client_host_.erase(inspected_rvh); | 152 inspected_rvh_to_client_host_.erase(inspected_rvh); |
| 156 client_host_to_inspected_rvh_.erase(host); | 153 client_host_to_inspected_rvh_.erase(host); |
| 157 } | 154 } |
| 158 | 155 |
| 159 RenderViewHost* DevToolsManager::GetInspectedRenderViewHost( | 156 RenderViewHost* DevToolsManager::GetInspectedRenderViewHost( |
| 160 DevToolsClientHost* client_host) { | 157 DevToolsClientHost* client_host) { |
| 161 ClientHostToInspectedRvhMap::iterator it = | 158 ClientHostToInspectedRvhMap::iterator it = |
| 162 client_host_to_inspected_rvh_.find(client_host); | 159 client_host_to_inspected_rvh_.find(client_host); |
| 163 if (it != client_host_to_inspected_rvh_.end()) { | 160 if (it != client_host_to_inspected_rvh_.end()) |
| 164 return it->second; | 161 return it->second; |
| 165 } | |
| 166 return NULL; | 162 return NULL; |
| 167 } | 163 } |
| 168 | 164 |
| 169 void DevToolsManager::UnregisterDevToolsClientHostFor( | 165 void DevToolsManager::UnregisterDevToolsClientHostFor( |
| 170 RenderViewHost* inspected_rvh) { | 166 RenderViewHost* inspected_rvh) { |
| 171 DevToolsClientHost* host = GetDevToolsClientHostFor(inspected_rvh); | 167 DevToolsClientHost* host = GetDevToolsClientHostFor(inspected_rvh); |
| 172 if (!host) { | 168 if (!host) |
| 173 return; | 169 return; |
| 174 } | |
| 175 inspected_rvh_to_client_host_.erase(inspected_rvh); | 170 inspected_rvh_to_client_host_.erase(inspected_rvh); |
| 176 client_host_to_inspected_rvh_.erase(host); | 171 client_host_to_inspected_rvh_.erase(host); |
| 177 if (inspected_rvh_for_reopen_ == inspected_rvh) { | 172 if (inspected_rvh_for_reopen_ == inspected_rvh) |
| 178 inspected_rvh_for_reopen_ = NULL; | 173 inspected_rvh_for_reopen_ = NULL; |
| 179 } | |
| 180 | 174 |
| 181 // Issue tab closing event post unbound. | 175 // Issue tab closing event post unbound. |
| 182 host->InspectedTabClosing(); | 176 host->InspectedTabClosing(); |
| 177 |
| 178 int process_id = inspected_rvh->process()->id(); |
| 179 for (InspectedRvhToClientHostMap::iterator it = |
| 180 inspected_rvh_to_client_host_.begin(); |
| 181 it != inspected_rvh_to_client_host_.end(); |
| 182 ++it) { |
| 183 if (it->first->process()->id() == process_id) |
| 184 return; |
| 185 } |
| 186 // We've disconnected from the last renderer -> revoke cookie permissions. |
| 187 ChildProcessSecurityPolicy::GetInstance()->RevokeReadRawCookies(process_id); |
| 183 } | 188 } |
| 184 | 189 |
| 185 void DevToolsManager::OnNavigatingToPendingEntry(RenderViewHost* rvh, | 190 void DevToolsManager::OnNavigatingToPendingEntry(RenderViewHost* rvh, |
| 186 RenderViewHost* dest_rvh, | 191 RenderViewHost* dest_rvh, |
| 187 const GURL& gurl) { | 192 const GURL& gurl) { |
| 188 if (in_initial_show_) { | 193 if (in_initial_show_) { |
| 189 // Mute this even in case it is caused by the initial show routines. | 194 // Mute this even in case it is caused by the initial show routines. |
| 190 return; | 195 return; |
| 191 } | 196 } |
| 192 DevToolsClientHost* client_host = | 197 DevToolsClientHost* client_host = |
| (...skipping 19 matching lines...) Expand all Loading... |
| 212 MessageLoop::current()->PostTask(FROM_HERE, | 217 MessageLoop::current()->PostTask(FROM_HERE, |
| 213 NewRunnableMethod(this, | 218 NewRunnableMethod(this, |
| 214 &DevToolsManager::ForceReopenWindow)); | 219 &DevToolsManager::ForceReopenWindow)); |
| 215 return; | 220 return; |
| 216 } | 221 } |
| 217 } | 222 } |
| 218 } | 223 } |
| 219 | 224 |
| 220 void DevToolsManager::SendAttachToAgent(RenderViewHost* inspected_rvh) { | 225 void DevToolsManager::SendAttachToAgent(RenderViewHost* inspected_rvh) { |
| 221 if (inspected_rvh) { | 226 if (inspected_rvh) { |
| 227 ChildProcessSecurityPolicy::GetInstance()->GrantReadRawCookies( |
| 228 inspected_rvh->process()->id()); |
| 222 IPC::Message* m = new DevToolsAgentMsg_Attach(); | 229 IPC::Message* m = new DevToolsAgentMsg_Attach(); |
| 223 m->set_routing_id(inspected_rvh->routing_id()); | 230 m->set_routing_id(inspected_rvh->routing_id()); |
| 224 inspected_rvh->Send(m); | 231 inspected_rvh->Send(m); |
| 225 } | 232 } |
| 226 } | 233 } |
| 227 | 234 |
| 228 void DevToolsManager::SendDetachToAgent(RenderViewHost* inspected_rvh) { | 235 void DevToolsManager::SendDetachToAgent(RenderViewHost* inspected_rvh) { |
| 229 if (inspected_rvh) { | 236 if (inspected_rvh) { |
| 230 IPC::Message* m = new DevToolsAgentMsg_Detach(); | 237 IPC::Message* m = new DevToolsAgentMsg_Detach(); |
| 231 m->set_routing_id(inspected_rvh->routing_id()); | 238 m->set_routing_id(inspected_rvh->routing_id()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 242 } | 249 } |
| 243 } | 250 } |
| 244 | 251 |
| 245 DevToolsClientHost* DevToolsManager::FindOnwerDevToolsClientHost( | 252 DevToolsClientHost* DevToolsManager::FindOnwerDevToolsClientHost( |
| 246 RenderViewHost* client_rvh) { | 253 RenderViewHost* client_rvh) { |
| 247 for (InspectedRvhToClientHostMap::iterator it = | 254 for (InspectedRvhToClientHostMap::iterator it = |
| 248 inspected_rvh_to_client_host_.begin(); | 255 inspected_rvh_to_client_host_.begin(); |
| 249 it != inspected_rvh_to_client_host_.end(); | 256 it != inspected_rvh_to_client_host_.end(); |
| 250 ++it) { | 257 ++it) { |
| 251 DevToolsWindow* win = it->second->AsDevToolsWindow(); | 258 DevToolsWindow* win = it->second->AsDevToolsWindow(); |
| 252 if (!win) { | 259 if (!win) |
| 253 continue; | 260 continue; |
| 254 } | 261 if (client_rvh == win->GetRenderViewHost()) |
| 255 if (client_rvh == win->GetRenderViewHost()) { | |
| 256 return it->second; | 262 return it->second; |
| 257 } | |
| 258 } | 263 } |
| 259 return NULL; | 264 return NULL; |
| 260 } | 265 } |
| 261 | 266 |
| 262 void DevToolsManager::ReopenWindow(RenderViewHost* client_rvh, bool docked) { | 267 void DevToolsManager::ReopenWindow(RenderViewHost* client_rvh, bool docked) { |
| 263 DevToolsClientHost* client_host = FindOnwerDevToolsClientHost(client_rvh); | 268 DevToolsClientHost* client_host = FindOnwerDevToolsClientHost(client_rvh); |
| 264 if (!client_host) { | 269 if (!client_host) |
| 265 return; | 270 return; |
| 266 } | |
| 267 RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(client_host); | 271 RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(client_host); |
| 268 DCHECK(inspected_rvh); | 272 DCHECK(inspected_rvh); |
| 269 inspected_rvh->process()->profile()->GetPrefs()->SetBoolean( | 273 inspected_rvh->process()->profile()->GetPrefs()->SetBoolean( |
| 270 prefs::kDevToolsOpenDocked, docked); | 274 prefs::kDevToolsOpenDocked, docked); |
| 271 | 275 |
| 272 DevToolsWindow* window = client_host->AsDevToolsWindow(); | 276 DevToolsWindow* window = client_host->AsDevToolsWindow(); |
| 273 DCHECK(window); | 277 DCHECK(window); |
| 274 window->SetDocked(docked); | 278 window->SetDocked(docked); |
| 275 } | 279 } |
| 276 | 280 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 287 GetBoolean(prefs::kDevToolsOpenDocked); | 291 GetBoolean(prefs::kDevToolsOpenDocked); |
| 288 #endif | 292 #endif |
| 289 host = new DevToolsWindow( | 293 host = new DevToolsWindow( |
| 290 inspected_rvh->site_instance()->browsing_instance()->profile(), | 294 inspected_rvh->site_instance()->browsing_instance()->profile(), |
| 291 inspected_rvh, | 295 inspected_rvh, |
| 292 docked); | 296 docked); |
| 293 RegisterDevToolsClientHostFor(inspected_rvh, host); | 297 RegisterDevToolsClientHostFor(inspected_rvh, host); |
| 294 do_open = true; | 298 do_open = true; |
| 295 } | 299 } |
| 296 DevToolsWindow* window = host->AsDevToolsWindow(); | 300 DevToolsWindow* window = host->AsDevToolsWindow(); |
| 297 if (!window) { | 301 if (!window) |
| 298 return; | 302 return; |
| 299 } | |
| 300 | 303 |
| 301 // If window is docked and visible, we hide it on toggle. If window is | 304 // If window is docked and visible, we hide it on toggle. If window is |
| 302 // undocked, we show (activate) it. | 305 // undocked, we show (activate) it. |
| 303 if (!window->is_docked() || do_open) { | 306 if (!window->is_docked() || do_open) { |
| 304 in_initial_show_ = true; | 307 in_initial_show_ = true; |
| 305 window->Show(); | 308 window->Show(); |
| 306 in_initial_show_ = false; | 309 in_initial_show_ = false; |
| 307 } else { | 310 } else { |
| 308 CloseWindow(host); | 311 CloseWindow(host); |
| 309 } | 312 } |
| 310 } | 313 } |
| 311 | 314 |
| 312 void DevToolsManager::CloseWindow(DevToolsClientHost* client_host) { | 315 void DevToolsManager::CloseWindow(DevToolsClientHost* client_host) { |
| 313 RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(client_host); | 316 RenderViewHost* inspected_rvh = GetInspectedRenderViewHost(client_host); |
| 314 DCHECK(inspected_rvh); | 317 DCHECK(inspected_rvh); |
| 315 SendDetachToAgent(inspected_rvh); | 318 SendDetachToAgent(inspected_rvh); |
| 316 | 319 |
| 317 UnregisterDevToolsClientHostFor(inspected_rvh); | 320 UnregisterDevToolsClientHostFor(inspected_rvh); |
| 318 } | 321 } |
| OLD | NEW |