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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 | 73 |
| 74 scoped_refptr<DevToolsAgentHost> | 74 scoped_refptr<DevToolsAgentHost> |
| 75 DevToolsAgentHost::GetOrCreateFor(WebContents* web_contents) { | 75 DevToolsAgentHost::GetOrCreateFor(WebContents* web_contents) { |
| 76 RenderFrameDevToolsAgentHost* result = FindAgentHost(web_contents); | 76 RenderFrameDevToolsAgentHost* result = FindAgentHost(web_contents); |
| 77 if (!result) | 77 if (!result) |
| 78 result = new RenderFrameDevToolsAgentHost(web_contents->GetMainFrame()); | 78 result = new RenderFrameDevToolsAgentHost(web_contents->GetMainFrame()); |
| 79 return result; | 79 return result; |
| 80 } | 80 } |
| 81 | 81 |
| 82 // static | 82 // static |
| 83 scoped_refptr<DevToolsAgentHost> RenderFrameDevToolsAgentHost::GetOrCreateFor( | |
| 84 RenderFrameHost* host) { | |
| 85 RenderFrameDevToolsAgentHost* result = FindAgentHost(host); | |
| 86 if (!result) | |
| 87 result = new RenderFrameDevToolsAgentHost(host); | |
| 88 return result; | |
| 89 } | |
| 90 | |
| 91 // static | |
| 92 void RenderFrameDevToolsAgentHost::AppendAgentHostForFrameIfApplicable( | |
| 93 std::vector<scoped_refptr<DevToolsAgentHost>>* result, | |
| 94 RenderFrameHost* host) { | |
| 95 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(host); | |
| 96 if (rfh->IsRenderFrameLive() && rfh->IsFrameGroupRoot()) | |
| 97 result->push_back(RenderFrameDevToolsAgentHost::GetOrCreateFor(rfh)); | |
| 98 } | |
| 99 | |
| 100 // static | |
| 83 bool DevToolsAgentHost::HasFor(WebContents* web_contents) { | 101 bool DevToolsAgentHost::HasFor(WebContents* web_contents) { |
| 84 return FindAgentHost(web_contents) != NULL; | 102 return FindAgentHost(web_contents) != NULL; |
| 85 } | 103 } |
| 86 | 104 |
| 87 // static | 105 // static |
| 88 bool DevToolsAgentHost::IsDebuggerAttached(WebContents* web_contents) { | 106 bool DevToolsAgentHost::IsDebuggerAttached(WebContents* web_contents) { |
| 89 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(web_contents); | 107 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(web_contents); |
| 90 return agent_host && agent_host->IsAttached(); | 108 return agent_host && agent_host->IsAttached(); |
| 91 } | 109 } |
| 92 | 110 |
| 93 //static | 111 //static |
| 94 std::vector<WebContents*> DevToolsAgentHostImpl::GetInspectableWebContents() { | 112 void RenderFrameDevToolsAgentHost::AddAllAgentHosts( |
| 95 std::set<WebContents*> set; | 113 std::vector<scoped_refptr<DevToolsAgentHost>>* result) { |
| 96 scoped_ptr<RenderWidgetHostIterator> widgets( | 114 base::Callback<void(RenderFrameHost*)> callback = base::Bind( |
| 97 RenderWidgetHost::GetRenderWidgetHosts()); | 115 RenderFrameDevToolsAgentHost::AppendAgentHostForFrameIfApplicable, |
| 98 while (RenderWidgetHost* widget = widgets->GetNextHost()) { | 116 base::Unretained(result)); |
| 99 // Ignore processes that don't have a connection, such as crashed contents. | 117 for (const auto& wc : WebContentsImpl::GetAllWebContents()) |
| 100 if (!widget->GetProcess()->HasConnection()) | 118 wc->ForEachFrame(callback); |
| 101 continue; | |
| 102 if (!widget->IsRenderView()) | |
| 103 continue; | |
| 104 | |
| 105 RenderViewHost* rvh = RenderViewHost::From(widget); | |
| 106 WebContents* web_contents = WebContents::FromRenderViewHost(rvh); | |
| 107 if (web_contents) | |
| 108 set.insert(web_contents); | |
| 109 } | |
| 110 std::vector<WebContents*> result(set.size()); | |
| 111 std::copy(set.begin(), set.end(), result.begin()); | |
| 112 return result; | |
| 113 } | 119 } |
| 114 | 120 |
| 115 // static | 121 // static |
| 116 void RenderFrameDevToolsAgentHost::OnCancelPendingNavigation( | 122 void RenderFrameDevToolsAgentHost::OnCancelPendingNavigation( |
| 117 RenderFrameHost* pending, | 123 RenderFrameHost* pending, |
| 118 RenderFrameHost* current) { | 124 RenderFrameHost* current) { |
| 119 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(pending); | 125 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(pending); |
| 120 if (!agent_host) | 126 if (!agent_host) |
| 121 return; | 127 return; |
| 122 agent_host->DisconnectRenderFrameHost(); | 128 agent_host->DisconnectRenderFrameHost(); |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 | 442 |
| 437 void RenderFrameDevToolsAgentHost::DisconnectWebContents() { | 443 void RenderFrameDevToolsAgentHost::DisconnectWebContents() { |
| 438 DisconnectRenderFrameHost(); | 444 DisconnectRenderFrameHost(); |
| 439 } | 445 } |
| 440 | 446 |
| 441 void RenderFrameDevToolsAgentHost::ConnectWebContents(WebContents* wc) { | 447 void RenderFrameDevToolsAgentHost::ConnectWebContents(WebContents* wc) { |
| 442 ConnectRenderFrameHost(wc->GetMainFrame()); | 448 ConnectRenderFrameHost(wc->GetMainFrame()); |
| 443 } | 449 } |
| 444 | 450 |
| 445 DevToolsAgentHost::Type RenderFrameDevToolsAgentHost::GetType() { | 451 DevToolsAgentHost::Type RenderFrameDevToolsAgentHost::GetType() { |
| 446 return TYPE_WEB_CONTENTS; | 452 return IsChildFrame() ? TYPE_FRAME : TYPE_WEB_CONTENTS; |
| 447 } | 453 } |
| 448 | 454 |
| 449 std::string RenderFrameDevToolsAgentHost::GetTitle() { | 455 std::string RenderFrameDevToolsAgentHost::GetTitle() { |
| 456 if (IsChildFrame()) | |
| 457 return GetURL().spec(); | |
| 450 if (WebContents* web_contents = GetWebContents()) | 458 if (WebContents* web_contents = GetWebContents()) |
| 451 return base::UTF16ToUTF8(web_contents->GetTitle()); | 459 return base::UTF16ToUTF8(web_contents->GetTitle()); |
| 452 return ""; | 460 return ""; |
| 453 } | 461 } |
| 454 | 462 |
| 455 GURL RenderFrameDevToolsAgentHost::GetURL() { | 463 GURL RenderFrameDevToolsAgentHost::GetURL() { |
| 464 if (IsChildFrame()) | |
| 465 return render_frame_host_->GetLastCommittedURL(); | |
|
nasko
2015/03/05 15:20:48
Why not return this in all cases?
dgozman
2015/03/06 16:14:14
Done.
| |
| 456 if (WebContents* web_contents = GetWebContents()) | 466 if (WebContents* web_contents = GetWebContents()) |
| 457 return web_contents->GetVisibleURL(); | 467 return web_contents->GetVisibleURL(); |
|
nasko
2015/03/05 15:20:48
This is a bit orthogonal, but why do you need the
dgozman
2015/03/06 16:14:14
You are right, using last committed url.
| |
| 458 return render_frame_host_ ? | 468 return render_frame_host_ ? |
| 459 render_frame_host_->GetLastCommittedURL() : GURL(); | 469 render_frame_host_->GetLastCommittedURL() : GURL(); |
| 460 } | 470 } |
| 461 | 471 |
| 462 bool RenderFrameDevToolsAgentHost::Activate() { | 472 bool RenderFrameDevToolsAgentHost::Activate() { |
| 463 if (render_frame_host_) { | 473 if (render_frame_host_) { |
| 464 render_frame_host_->GetRenderViewHost()->GetDelegate()->Activate(); | 474 render_frame_host_->GetRenderViewHost()->GetDelegate()->Activate(); |
| 465 return true; | 475 return true; |
| 466 } | 476 } |
| 467 return false; | 477 return false; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 522 ProcessChunkedMessageFromAgent(message); | 532 ProcessChunkedMessageFromAgent(message); |
| 523 } | 533 } |
| 524 | 534 |
| 525 void RenderFrameDevToolsAgentHost::DispatchOnInspectorFrontend( | 535 void RenderFrameDevToolsAgentHost::DispatchOnInspectorFrontend( |
| 526 const std::string& message) { | 536 const std::string& message) { |
| 527 if (!IsAttached() || !render_frame_host_) | 537 if (!IsAttached() || !render_frame_host_) |
| 528 return; | 538 return; |
| 529 SendMessageToClient(message); | 539 SendMessageToClient(message); |
| 530 } | 540 } |
| 531 | 541 |
| 542 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | |
| 543 return render_frame_host_ && render_frame_host_->GetParent(); | |
| 544 } | |
| 545 | |
| 532 } // namespace content | 546 } // namespace content |
| OLD | NEW |