| 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/devtools/render_view_devtools_agent_host.h" | 5 #include "content/browser/devtools/render_view_devtools_agent_host.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "content/browser/child_process_security_policy_impl.h" | 9 #include "content/browser/child_process_security_policy_impl.h" |
| 10 #include "content/browser/devtools/devtools_manager_impl.h" | 10 #include "content/browser/devtools/devtools_manager_impl.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 | 85 |
| 86 // static | 86 // static |
| 87 bool DevToolsAgentHost::HasFor(RenderViewHost* rvh) { | 87 bool DevToolsAgentHost::HasFor(RenderViewHost* rvh) { |
| 88 return FindAgentHost(rvh) != NULL; | 88 return FindAgentHost(rvh) != NULL; |
| 89 } | 89 } |
| 90 | 90 |
| 91 // static | 91 // static |
| 92 bool DevToolsAgentHost::IsDebuggerAttached(WebContents* web_contents) { | 92 bool DevToolsAgentHost::IsDebuggerAttached(WebContents* web_contents) { |
| 93 if (g_instances == NULL) | 93 if (g_instances == NULL) |
| 94 return false; | 94 return false; |
| 95 DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); | |
| 96 if (!devtools_manager) | |
| 97 return false; | |
| 98 RenderViewHostDelegate* delegate = | 95 RenderViewHostDelegate* delegate = |
| 99 static_cast<WebContentsImpl*>(web_contents); | 96 static_cast<WebContentsImpl*>(web_contents); |
| 100 for (Instances::iterator it = g_instances.Get().begin(); | 97 for (Instances::iterator it = g_instances.Get().begin(); |
| 101 it != g_instances.Get().end(); ++it) { | 98 it != g_instances.Get().end(); ++it) { |
| 102 RenderViewHost* rvh = (*it)->render_view_host_; | 99 RenderViewHost* rvh = (*it)->render_view_host_; |
| 103 if (rvh && rvh->GetDelegate() != delegate) | 100 if (rvh && rvh->GetDelegate() != delegate) |
| 104 continue; | 101 continue; |
| 105 if ((*it)->IsAttached()) | 102 if ((*it)->IsAttached()) |
| 106 return true; | 103 return true; |
| 107 } | 104 } |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 } | 225 } |
| 229 | 226 |
| 230 void RenderViewDevToolsAgentHost::OnClientAttached() { | 227 void RenderViewDevToolsAgentHost::OnClientAttached() { |
| 231 if (!render_view_host_) | 228 if (!render_view_host_) |
| 232 return; | 229 return; |
| 233 | 230 |
| 234 InnerOnClientAttached(); | 231 InnerOnClientAttached(); |
| 235 | 232 |
| 236 // TODO(kaznacheev): Move this call back to DevToolsManagerImpl when | 233 // TODO(kaznacheev): Move this call back to DevToolsManagerImpl when |
| 237 // extensions::ProcessManager no longer relies on this notification. | 234 // extensions::ProcessManager no longer relies on this notification. |
| 238 if (!reattaching_) | |
| 239 DevToolsManagerImpl::GetInstance()->NotifyObservers(this, true); | |
| 240 } | 235 } |
| 241 | 236 |
| 242 void RenderViewDevToolsAgentHost::InnerOnClientAttached() { | 237 void RenderViewDevToolsAgentHost::InnerOnClientAttached() { |
| 243 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadRawCookies( | 238 ChildProcessSecurityPolicyImpl::GetInstance()->GrantReadRawCookies( |
| 244 render_view_host_->GetProcess()->GetID()); | 239 render_view_host_->GetProcess()->GetID()); |
| 245 | 240 |
| 246 #if defined(OS_ANDROID) | 241 #if defined(OS_ANDROID) |
| 247 power_save_blocker_.reset( | 242 power_save_blocker_.reset( |
| 248 static_cast<PowerSaveBlockerImpl*>( | 243 static_cast<PowerSaveBlockerImpl*>( |
| 249 PowerSaveBlocker::Create( | 244 PowerSaveBlocker::Create( |
| (...skipping 17 matching lines...) Expand all Loading... |
| 267 } | 262 } |
| 268 | 263 |
| 269 void RenderViewDevToolsAgentHost::ClientDetachedFromRenderer() { | 264 void RenderViewDevToolsAgentHost::ClientDetachedFromRenderer() { |
| 270 if (!render_view_host_) | 265 if (!render_view_host_) |
| 271 return; | 266 return; |
| 272 | 267 |
| 273 InnerClientDetachedFromRenderer(); | 268 InnerClientDetachedFromRenderer(); |
| 274 | 269 |
| 275 // TODO(kaznacheev): Move this call back to DevToolsManagerImpl when | 270 // TODO(kaznacheev): Move this call back to DevToolsManagerImpl when |
| 276 // extensions::ProcessManager no longer relies on this notification. | 271 // extensions::ProcessManager no longer relies on this notification. |
| 277 if (!reattaching_) | |
| 278 DevToolsManagerImpl::GetInstance()->NotifyObservers(this, false); | |
| 279 } | 272 } |
| 280 | 273 |
| 281 void RenderViewDevToolsAgentHost::InnerClientDetachedFromRenderer() { | 274 void RenderViewDevToolsAgentHost::InnerClientDetachedFromRenderer() { |
| 282 bool process_has_agents = false; | 275 bool process_has_agents = false; |
| 283 RenderProcessHost* render_process_host = render_view_host_->GetProcess(); | 276 RenderProcessHost* render_process_host = render_view_host_->GetProcess(); |
| 284 for (Instances::iterator it = g_instances.Get().begin(); | 277 for (Instances::iterator it = g_instances.Get().begin(); |
| 285 it != g_instances.Get().end(); ++it) { | 278 it != g_instances.Get().end(); ++it) { |
| 286 if (*it == this || !(*it)->IsAttached()) | 279 if (*it == this || !(*it)->IsAttached()) |
| 287 continue; | 280 continue; |
| 288 RenderViewHost* rvh = (*it)->render_view_host(); | 281 RenderViewHost* rvh = (*it)->render_view_host(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 ConnectRenderViewHost(rvh); | 328 ConnectRenderViewHost(rvh); |
| 336 reattaching_ = false; | 329 reattaching_ = false; |
| 337 } | 330 } |
| 338 | 331 |
| 339 void RenderViewDevToolsAgentHost::RenderViewDeleted(RenderViewHost* rvh) { | 332 void RenderViewDevToolsAgentHost::RenderViewDeleted(RenderViewHost* rvh) { |
| 340 if (rvh != render_view_host_) | 333 if (rvh != render_view_host_) |
| 341 return; | 334 return; |
| 342 | 335 |
| 343 DCHECK(render_view_host_); | 336 DCHECK(render_view_host_); |
| 344 scoped_refptr<RenderViewDevToolsAgentHost> protect(this); | 337 scoped_refptr<RenderViewDevToolsAgentHost> protect(this); |
| 345 NotifyCloseListener(); | 338 HostClosed(); |
| 346 ClearRenderViewHost(); | 339 ClearRenderViewHost(); |
| 347 Release(); | 340 Release(); |
| 348 } | 341 } |
| 349 | 342 |
| 350 void RenderViewDevToolsAgentHost::RenderProcessGone( | 343 void RenderViewDevToolsAgentHost::RenderProcessGone( |
| 351 base::TerminationStatus status) { | 344 base::TerminationStatus status) { |
| 352 switch(status) { | 345 switch(status) { |
| 353 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: | 346 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: |
| 354 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: | 347 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
| 355 case base::TERMINATION_STATUS_PROCESS_CRASHED: | 348 case base::TERMINATION_STATUS_PROCESS_CRASHED: |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 415 | 408 |
| 416 void RenderViewDevToolsAgentHost::DisconnectRenderViewHost() { | 409 void RenderViewDevToolsAgentHost::DisconnectRenderViewHost() { |
| 417 ClientDetachedFromRenderer(); | 410 ClientDetachedFromRenderer(); |
| 418 ClearRenderViewHost(); | 411 ClearRenderViewHost(); |
| 419 } | 412 } |
| 420 | 413 |
| 421 void RenderViewDevToolsAgentHost::RenderViewCrashed() { | 414 void RenderViewDevToolsAgentHost::RenderViewCrashed() { |
| 422 scoped_refptr<DevToolsProtocol::Notification> notification = | 415 scoped_refptr<DevToolsProtocol::Notification> notification = |
| 423 DevToolsProtocol::CreateNotification( | 416 DevToolsProtocol::CreateNotification( |
| 424 devtools::Inspector::targetCrashed::kName, NULL); | 417 devtools::Inspector::targetCrashed::kName, NULL); |
| 425 DevToolsManagerImpl::GetInstance()-> | 418 SendMessageToClient(notification->Serialize()); |
| 426 DispatchOnInspectorFrontend(this, notification->Serialize()); | |
| 427 } | 419 } |
| 428 | 420 |
| 429 bool RenderViewDevToolsAgentHost::DispatchIPCMessage( | 421 bool RenderViewDevToolsAgentHost::DispatchIPCMessage( |
| 430 const IPC::Message& msg) { | 422 const IPC::Message& msg) { |
| 431 if (!render_view_host_) | 423 if (!render_view_host_) |
| 432 return false; | 424 return false; |
| 433 | 425 |
| 434 bool handled = true; | 426 bool handled = true; |
| 435 IPC_BEGIN_MESSAGE_MAP(RenderViewDevToolsAgentHost, msg) | 427 IPC_BEGIN_MESSAGE_MAP(RenderViewDevToolsAgentHost, msg) |
| 436 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, | 428 IPC_MESSAGE_HANDLER(DevToolsClientMsg_DispatchOnInspectorFrontend, |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 const std::string& message) { | 469 const std::string& message) { |
| 478 if (!render_view_host_) | 470 if (!render_view_host_) |
| 479 return; | 471 return; |
| 480 | 472 |
| 481 scoped_refptr<DevToolsProtocol::Notification> notification = | 473 scoped_refptr<DevToolsProtocol::Notification> notification = |
| 482 DevToolsProtocol::ParseNotification(message); | 474 DevToolsProtocol::ParseNotification(message); |
| 483 | 475 |
| 484 if (notification) { | 476 if (notification) { |
| 485 tracing_handler_->HandleNotification(notification); | 477 tracing_handler_->HandleNotification(notification); |
| 486 } | 478 } |
| 487 DevToolsManagerImpl::GetInstance()->DispatchOnInspectorFrontend( | 479 SendMessageToClient(message); |
| 488 this, message); | |
| 489 } | 480 } |
| 490 | 481 |
| 491 } // namespace content | 482 } // namespace content |
| OLD | NEW |