Chromium Code Reviews| 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/json/json_writer.h" | 8 #include "base/json/json_writer.h" |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 | 74 |
| 75 scoped_refptr<DevToolsAgentHost> | 75 scoped_refptr<DevToolsAgentHost> |
| 76 DevToolsAgentHost::GetOrCreateFor(WebContents* web_contents) { | 76 DevToolsAgentHost::GetOrCreateFor(WebContents* web_contents) { |
| 77 RenderFrameDevToolsAgentHost* result = FindAgentHost(web_contents); | 77 RenderFrameDevToolsAgentHost* result = FindAgentHost(web_contents); |
| 78 if (!result) | 78 if (!result) |
| 79 result = new RenderFrameDevToolsAgentHost(web_contents->GetMainFrame()); | 79 result = new RenderFrameDevToolsAgentHost(web_contents->GetMainFrame()); |
| 80 return result; | 80 return result; |
| 81 } | 81 } |
| 82 | 82 |
| 83 // static | 83 // static |
| 84 scoped_refptr<DevToolsAgentHost> RenderFrameDevToolsAgentHost::GetOrCreateFor( | |
| 85 RenderFrameHost* host) { | |
| 86 RenderFrameDevToolsAgentHost* result = FindAgentHost(host); | |
| 87 if (!result) | |
| 88 result = new RenderFrameDevToolsAgentHost(host); | |
| 89 return result; | |
| 90 } | |
| 91 | |
| 92 // static | |
| 93 void RenderFrameDevToolsAgentHost::AppendAgentHostForFrameIfApplicable( | |
| 94 DevToolsAgentHost::List* result, RenderFrameHost* host) { | |
|
Charlie Reis
2015/03/06 21:33:50
Style nit: Each parameter on its own line if the m
dgozman
2015/03/07 14:13:01
Done.
| |
| 95 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(host); | |
| 96 if (!rfh->IsRenderFrameLive()) | |
| 97 return; | |
| 98 if (rfh->IsCrossProcessSubframe() || !rfh->GetParent()) | |
| 99 result->push_back(RenderFrameDevToolsAgentHost::GetOrCreateFor(rfh)); | |
| 100 } | |
| 101 | |
| 102 // static | |
| 84 bool DevToolsAgentHost::HasFor(WebContents* web_contents) { | 103 bool DevToolsAgentHost::HasFor(WebContents* web_contents) { |
| 85 return FindAgentHost(web_contents) != NULL; | 104 return FindAgentHost(web_contents) != NULL; |
| 86 } | 105 } |
| 87 | 106 |
| 88 // static | 107 // static |
| 89 bool DevToolsAgentHost::IsDebuggerAttached(WebContents* web_contents) { | 108 bool DevToolsAgentHost::IsDebuggerAttached(WebContents* web_contents) { |
| 90 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(web_contents); | 109 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(web_contents); |
| 91 return agent_host && agent_host->IsAttached(); | 110 return agent_host && agent_host->IsAttached(); |
| 92 } | 111 } |
| 93 | 112 |
| 94 //static | 113 //static |
| 95 std::vector<WebContents*> DevToolsAgentHostImpl::GetInspectableWebContents() { | 114 void RenderFrameDevToolsAgentHost::AddAllAgentHosts( |
| 96 std::set<WebContents*> set; | 115 DevToolsAgentHost::List* result) { |
| 97 scoped_ptr<RenderWidgetHostIterator> widgets( | 116 base::Callback<void(RenderFrameHost*)> callback = base::Bind( |
| 98 RenderWidgetHost::GetRenderWidgetHosts()); | 117 RenderFrameDevToolsAgentHost::AppendAgentHostForFrameIfApplicable, |
| 99 while (RenderWidgetHost* widget = widgets->GetNextHost()) { | 118 base::Unretained(result)); |
| 100 // Ignore processes that don't have a connection, such as crashed contents. | 119 for (const auto& wc : WebContentsImpl::GetAllWebContents()) |
| 101 if (!widget->GetProcess()->HasConnection()) | 120 wc->ForEachFrame(callback); |
| 102 continue; | |
| 103 if (!widget->IsRenderView()) | |
| 104 continue; | |
| 105 | |
| 106 RenderViewHost* rvh = RenderViewHost::From(widget); | |
| 107 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); | |
| 108 if (web_contents) | |
| 109 set.insert(web_contents); | |
| 110 } | |
| 111 std::vector<WebContents*> result(set.size()); | |
| 112 std::copy(set.begin(), set.end(), result.begin()); | |
| 113 return result; | |
| 114 } | 121 } |
| 115 | 122 |
| 116 // static | 123 // static |
| 117 void RenderFrameDevToolsAgentHost::OnCancelPendingNavigation( | 124 void RenderFrameDevToolsAgentHost::OnCancelPendingNavigation( |
| 118 RenderFrameHost* pending, | 125 RenderFrameHost* pending, |
| 119 RenderFrameHost* current) { | 126 RenderFrameHost* current) { |
| 120 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(pending); | 127 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(pending); |
| 121 if (!agent_host) | 128 if (!agent_host) |
| 122 return; | 129 return; |
| 123 agent_host->DisconnectRenderFrameHost(); | 130 agent_host->DisconnectRenderFrameHost(); |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 402 const NotificationDetails& details) { | 409 const NotificationDetails& details) { |
| 403 if (type == content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED) { | 410 if (type == content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED) { |
| 404 bool visible = *Details<bool>(details).ptr(); | 411 bool visible = *Details<bool>(details).ptr(); |
| 405 page_handler_->OnVisibilityChanged(visible); | 412 page_handler_->OnVisibilityChanged(visible); |
| 406 } | 413 } |
| 407 } | 414 } |
| 408 | 415 |
| 409 void RenderFrameDevToolsAgentHost::SetRenderFrameHost(RenderFrameHost* rfh) { | 416 void RenderFrameDevToolsAgentHost::SetRenderFrameHost(RenderFrameHost* rfh) { |
| 410 DCHECK(!render_frame_host_); | 417 DCHECK(!render_frame_host_); |
| 411 render_frame_host_ = static_cast<RenderFrameHostImpl*>(rfh); | 418 render_frame_host_ = static_cast<RenderFrameHostImpl*>(rfh); |
| 419 // TODO(dgozman): here we should DCHECK that frame host is either root or | |
| 420 // cross process subframe, but this requires handling cross-process | |
| 421 // navigation. | |
|
Charlie Reis
2015/03/06 21:33:50
Is there a bug number we can cite here?
dgozman
2015/03/07 14:13:01
Done.
| |
| 412 | 422 |
| 413 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(rfh)); | 423 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(rfh)); |
| 414 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 424 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 415 rfh->GetRenderViewHost()); | 425 rfh->GetRenderViewHost()); |
| 416 dom_handler_->SetRenderViewHost(rvh); | 426 dom_handler_->SetRenderViewHost(rvh); |
| 417 input_handler_->SetRenderViewHost(rvh); | 427 input_handler_->SetRenderViewHost(rvh); |
| 418 network_handler_->SetRenderViewHost(rvh); | 428 network_handler_->SetRenderViewHost(rvh); |
| 419 page_handler_->SetRenderViewHost(rvh); | 429 page_handler_->SetRenderViewHost(rvh); |
| 420 | 430 |
| 421 registrar_.Add( | 431 registrar_.Add( |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 441 | 451 |
| 442 void RenderFrameDevToolsAgentHost::DisconnectWebContents() { | 452 void RenderFrameDevToolsAgentHost::DisconnectWebContents() { |
| 443 DisconnectRenderFrameHost(); | 453 DisconnectRenderFrameHost(); |
| 444 } | 454 } |
| 445 | 455 |
| 446 void RenderFrameDevToolsAgentHost::ConnectWebContents(WebContents* wc) { | 456 void RenderFrameDevToolsAgentHost::ConnectWebContents(WebContents* wc) { |
| 447 ConnectRenderFrameHost(wc->GetMainFrame()); | 457 ConnectRenderFrameHost(wc->GetMainFrame()); |
| 448 } | 458 } |
| 449 | 459 |
| 450 DevToolsAgentHost::Type RenderFrameDevToolsAgentHost::GetType() { | 460 DevToolsAgentHost::Type RenderFrameDevToolsAgentHost::GetType() { |
| 451 return TYPE_WEB_CONTENTS; | 461 return IsChildFrame() ? TYPE_FRAME : TYPE_WEB_CONTENTS; |
| 452 } | 462 } |
| 453 | 463 |
| 454 std::string RenderFrameDevToolsAgentHost::GetTitle() { | 464 std::string RenderFrameDevToolsAgentHost::GetTitle() { |
| 465 if (IsChildFrame()) | |
| 466 return GetURL().spec(); | |
| 455 if (WebContents* web_contents = GetWebContents()) | 467 if (WebContents* web_contents = GetWebContents()) |
| 456 return base::UTF16ToUTF8(web_contents->GetTitle()); | 468 return base::UTF16ToUTF8(web_contents->GetTitle()); |
| 457 return ""; | 469 return ""; |
| 458 } | 470 } |
| 459 | 471 |
| 460 GURL RenderFrameDevToolsAgentHost::GetURL() { | 472 GURL RenderFrameDevToolsAgentHost::GetURL() { |
| 461 if (WebContents* web_contents = GetWebContents()) | |
| 462 return web_contents->GetVisibleURL(); | |
| 463 return render_frame_host_ ? | 473 return render_frame_host_ ? |
| 464 render_frame_host_->GetLastCommittedURL() : GURL(); | 474 render_frame_host_->GetLastCommittedURL() : GURL(); |
| 465 } | 475 } |
| 466 | 476 |
| 467 bool RenderFrameDevToolsAgentHost::Activate() { | 477 bool RenderFrameDevToolsAgentHost::Activate() { |
| 468 if (render_frame_host_) { | 478 if (render_frame_host_) { |
| 469 render_frame_host_->GetRenderViewHost()->GetDelegate()->Activate(); | 479 render_frame_host_->GetRenderViewHost()->GetDelegate()->Activate(); |
| 470 return true; | 480 return true; |
| 471 } | 481 } |
| 472 return false; | 482 return false; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 527 ProcessChunkedMessageFromAgent(message); | 537 ProcessChunkedMessageFromAgent(message); |
| 528 } | 538 } |
| 529 | 539 |
| 530 void RenderFrameDevToolsAgentHost::DispatchOnInspectorFrontend( | 540 void RenderFrameDevToolsAgentHost::DispatchOnInspectorFrontend( |
| 531 const std::string& message) { | 541 const std::string& message) { |
| 532 if (!IsAttached() || !render_frame_host_) | 542 if (!IsAttached() || !render_frame_host_) |
| 533 return; | 543 return; |
| 534 SendMessageToClient(message); | 544 SendMessageToClient(message); |
| 535 } | 545 } |
| 536 | 546 |
| 547 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | |
| 548 return render_frame_host_ && render_frame_host_->GetParent(); | |
| 549 } | |
| 550 | |
| 537 } // namespace content | 551 } // namespace content |
| OLD | NEW |