| 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_frame_devtools_agent_host.h" | 5 #include "content/browser/devtools/render_frame_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 "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "content/browser/child_process_security_policy_impl.h" | 10 #include "content/browser/child_process_security_policy_impl.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 if (g_instances == NULL) | 62 if (g_instances == NULL) |
| 63 return NULL; | 63 return NULL; |
| 64 for (Instances::iterator it = g_instances.Get().begin(); | 64 for (Instances::iterator it = g_instances.Get().begin(); |
| 65 it != g_instances.Get().end(); ++it) { | 65 it != g_instances.Get().end(); ++it) { |
| 66 if ((*it)->GetWebContents() == web_contents) | 66 if ((*it)->GetWebContents() == web_contents) |
| 67 return *it; | 67 return *it; |
| 68 } | 68 } |
| 69 return NULL; | 69 return NULL; |
| 70 } | 70 } |
| 71 | 71 |
| 72 bool ShouldCreateDevToolsFor(RenderFrameHost* rfh) { |
| 73 return rfh->IsCrossProcessSubframe() || !rfh->GetParent(); |
| 74 } |
| 75 |
| 72 } // namespace | 76 } // namespace |
| 73 | 77 |
| 74 scoped_refptr<DevToolsAgentHost> | 78 scoped_refptr<DevToolsAgentHost> |
| 75 DevToolsAgentHost::GetOrCreateFor(WebContents* web_contents) { | 79 DevToolsAgentHost::GetOrCreateFor(WebContents* web_contents) { |
| 76 RenderFrameDevToolsAgentHost* result = FindAgentHost(web_contents); | 80 RenderFrameDevToolsAgentHost* result = FindAgentHost(web_contents); |
| 77 if (!result) | 81 if (!result) |
| 78 result = new RenderFrameDevToolsAgentHost(web_contents->GetMainFrame()); | 82 result = new RenderFrameDevToolsAgentHost(web_contents->GetMainFrame()); |
| 79 return result; | 83 return result; |
| 80 } | 84 } |
| 81 | 85 |
| 82 // static | 86 // static |
| 83 scoped_refptr<DevToolsAgentHost> RenderFrameDevToolsAgentHost::GetOrCreateFor( | 87 scoped_refptr<DevToolsAgentHost> RenderFrameDevToolsAgentHost::GetOrCreateFor( |
| 84 RenderFrameHost* host) { | 88 RenderFrameHost* host) { |
| 85 RenderFrameDevToolsAgentHost* result = FindAgentHost(host); | 89 RenderFrameDevToolsAgentHost* result = FindAgentHost(host); |
| 86 if (!result) | 90 if (!result) |
| 87 result = new RenderFrameDevToolsAgentHost(host); | 91 result = new RenderFrameDevToolsAgentHost(host); |
| 88 return result; | 92 return result; |
| 89 } | 93 } |
| 90 | 94 |
| 91 // static | 95 // static |
| 92 void RenderFrameDevToolsAgentHost::AppendAgentHostForFrameIfApplicable( | 96 void RenderFrameDevToolsAgentHost::AppendAgentHostForFrameIfApplicable( |
| 93 DevToolsAgentHost::List* result, | 97 DevToolsAgentHost::List* result, |
| 94 RenderFrameHost* host) { | 98 RenderFrameHost* host) { |
| 95 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(host); | 99 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(host); |
| 96 if (!rfh->IsRenderFrameLive()) | 100 if (!rfh->IsRenderFrameLive()) |
| 97 return; | 101 return; |
| 98 if (rfh->IsCrossProcessSubframe() || !rfh->GetParent()) | 102 if (ShouldCreateDevToolsFor(rfh)) |
| 99 result->push_back(RenderFrameDevToolsAgentHost::GetOrCreateFor(rfh)); | 103 result->push_back(RenderFrameDevToolsAgentHost::GetOrCreateFor(rfh)); |
| 100 } | 104 } |
| 101 | 105 |
| 102 // static | 106 // static |
| 103 bool DevToolsAgentHost::HasFor(WebContents* web_contents) { | 107 bool DevToolsAgentHost::HasFor(WebContents* web_contents) { |
| 104 return FindAgentHost(web_contents) != NULL; | 108 return FindAgentHost(web_contents) != NULL; |
| 105 } | 109 } |
| 106 | 110 |
| 107 // static | 111 // static |
| 108 bool DevToolsAgentHost::IsDebuggerAttached(WebContents* web_contents) { | 112 bool DevToolsAgentHost::IsDebuggerAttached(WebContents* web_contents) { |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 RenderFrameHost* new_host) { | 288 RenderFrameHost* new_host) { |
| 285 if (old_host == render_frame_host_ && new_host != render_frame_host_) { | 289 if (old_host == render_frame_host_ && new_host != render_frame_host_) { |
| 286 // AboutToNavigateRenderFrame was not called for renderer-initiated | 290 // AboutToNavigateRenderFrame was not called for renderer-initiated |
| 287 // navigation. | 291 // navigation. |
| 288 ReattachToRenderFrameHost(new_host); | 292 ReattachToRenderFrameHost(new_host); |
| 289 } | 293 } |
| 290 } | 294 } |
| 291 | 295 |
| 292 void | 296 void |
| 293 RenderFrameDevToolsAgentHost::ReattachToRenderFrameHost(RenderFrameHost* rfh) { | 297 RenderFrameDevToolsAgentHost::ReattachToRenderFrameHost(RenderFrameHost* rfh) { |
| 298 if (!ShouldCreateDevToolsFor(rfh)) { |
| 299 DestroyOnRenderFrameGone(); |
| 300 // |this| may be deleted at this point. |
| 301 return; |
| 302 } |
| 303 |
| 294 DCHECK(!reattaching_); | 304 DCHECK(!reattaching_); |
| 295 reattaching_ = true; | 305 reattaching_ = true; |
| 296 DisconnectRenderFrameHost(); | 306 DisconnectRenderFrameHost(); |
| 297 ConnectRenderFrameHost(rfh); | 307 ConnectRenderFrameHost(rfh); |
| 298 reattaching_ = false; | 308 reattaching_ = false; |
| 299 } | 309 } |
| 300 | 310 |
| 301 void RenderFrameDevToolsAgentHost::FrameDeleted(RenderFrameHost* rfh) { | 311 void RenderFrameDevToolsAgentHost::FrameDeleted(RenderFrameHost* rfh) { |
| 302 if (rfh != render_frame_host_) | 312 if (rfh != render_frame_host_) |
| 303 return; | 313 return; |
| 314 DestroyOnRenderFrameGone(); |
| 315 // |this| may be deleted at this point. |
| 316 } |
| 304 | 317 |
| 318 void RenderFrameDevToolsAgentHost::DestroyOnRenderFrameGone() { |
| 305 DCHECK(render_frame_host_); | 319 DCHECK(render_frame_host_); |
| 306 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); | 320 scoped_refptr<RenderFrameDevToolsAgentHost> protect(this); |
| 307 HostClosed(); | 321 HostClosed(); |
| 308 ClearRenderFrameHost(); | 322 ClearRenderFrameHost(); |
| 309 DevToolsManager::GetInstance()->AgentHostChanged(this); | 323 DevToolsManager::GetInstance()->AgentHostChanged(this); |
| 310 Release(); | 324 Release(); |
| 311 } | 325 } |
| 312 | 326 |
| 313 void RenderFrameDevToolsAgentHost::RenderProcessGone( | 327 void RenderFrameDevToolsAgentHost::RenderProcessGone( |
| 314 base::TerminationStatus status) { | 328 base::TerminationStatus status) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 389 void RenderFrameDevToolsAgentHost::Observe(int type, | 403 void RenderFrameDevToolsAgentHost::Observe(int type, |
| 390 const NotificationSource& source, | 404 const NotificationSource& source, |
| 391 const NotificationDetails& details) { | 405 const NotificationDetails& details) { |
| 392 if (type == content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED) { | 406 if (type == content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED) { |
| 393 bool visible = *Details<bool>(details).ptr(); | 407 bool visible = *Details<bool>(details).ptr(); |
| 394 page_handler_->OnVisibilityChanged(visible); | 408 page_handler_->OnVisibilityChanged(visible); |
| 395 } | 409 } |
| 396 } | 410 } |
| 397 | 411 |
| 398 void RenderFrameDevToolsAgentHost::SetRenderFrameHost(RenderFrameHost* rfh) { | 412 void RenderFrameDevToolsAgentHost::SetRenderFrameHost(RenderFrameHost* rfh) { |
| 413 DCHECK(ShouldCreateDevToolsFor(rfh)); |
| 399 DCHECK(!render_frame_host_); | 414 DCHECK(!render_frame_host_); |
| 400 render_frame_host_ = static_cast<RenderFrameHostImpl*>(rfh); | 415 render_frame_host_ = static_cast<RenderFrameHostImpl*>(rfh); |
| 401 // TODO(dgozman): here we should DCHECK that frame host is either root or | |
| 402 // cross process subframe, but this requires handling cross-process | |
| 403 // navigation. See http://crbug.com/464993. | |
| 404 | 416 |
| 405 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(rfh)); | 417 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(rfh)); |
| 406 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 418 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 407 rfh->GetRenderViewHost()); | 419 rfh->GetRenderViewHost()); |
| 408 dom_handler_->SetRenderViewHost(rvh); | 420 dom_handler_->SetRenderViewHost(rvh); |
| 409 emulation_handler_->SetRenderViewHost(rvh); | 421 emulation_handler_->SetRenderViewHost(rvh); |
| 410 input_handler_->SetRenderViewHost(rvh); | 422 input_handler_->SetRenderViewHost(rvh); |
| 411 network_handler_->SetRenderViewHost(rvh); | 423 network_handler_->SetRenderViewHost(rvh); |
| 412 page_handler_->SetRenderViewHost(rvh); | 424 page_handler_->SetRenderViewHost(rvh); |
| 413 service_worker_handler_->SetRenderFrameHost(render_frame_host_); | 425 service_worker_handler_->SetRenderFrameHost(render_frame_host_); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 524 if (!IsAttached() || !render_frame_host_) | 536 if (!IsAttached() || !render_frame_host_) |
| 525 return; | 537 return; |
| 526 ProcessChunkedMessageFromAgent(message); | 538 ProcessChunkedMessageFromAgent(message); |
| 527 } | 539 } |
| 528 | 540 |
| 529 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | 541 bool RenderFrameDevToolsAgentHost::IsChildFrame() { |
| 530 return render_frame_host_ && render_frame_host_->GetParent(); | 542 return render_frame_host_ && render_frame_host_->GetParent(); |
| 531 } | 543 } |
| 532 | 544 |
| 533 } // namespace content | 545 } // namespace content |
| OLD | NEW |