| 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, |
| 95 RenderFrameHost* host) { |
| 96 RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>(host); |
| 97 if (!rfh->IsRenderFrameLive()) |
| 98 return; |
| 99 if (rfh->IsCrossProcessSubframe() || !rfh->GetParent()) |
| 100 result->push_back(RenderFrameDevToolsAgentHost::GetOrCreateFor(rfh)); |
| 101 } |
| 102 |
| 103 // static |
| 84 bool DevToolsAgentHost::HasFor(WebContents* web_contents) { | 104 bool DevToolsAgentHost::HasFor(WebContents* web_contents) { |
| 85 return FindAgentHost(web_contents) != NULL; | 105 return FindAgentHost(web_contents) != NULL; |
| 86 } | 106 } |
| 87 | 107 |
| 88 // static | 108 // static |
| 89 bool DevToolsAgentHost::IsDebuggerAttached(WebContents* web_contents) { | 109 bool DevToolsAgentHost::IsDebuggerAttached(WebContents* web_contents) { |
| 90 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(web_contents); | 110 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(web_contents); |
| 91 return agent_host && agent_host->IsAttached(); | 111 return agent_host && agent_host->IsAttached(); |
| 92 } | 112 } |
| 93 | 113 |
| 94 //static | 114 //static |
| 95 std::vector<WebContents*> DevToolsAgentHostImpl::GetInspectableWebContents() { | 115 void RenderFrameDevToolsAgentHost::AddAllAgentHosts( |
| 96 std::set<WebContents*> set; | 116 DevToolsAgentHost::List* result) { |
| 97 scoped_ptr<RenderWidgetHostIterator> widgets( | 117 base::Callback<void(RenderFrameHost*)> callback = base::Bind( |
| 98 RenderWidgetHost::GetRenderWidgetHosts()); | 118 RenderFrameDevToolsAgentHost::AppendAgentHostForFrameIfApplicable, |
| 99 while (RenderWidgetHost* widget = widgets->GetNextHost()) { | 119 base::Unretained(result)); |
| 100 // Ignore processes that don't have a connection, such as crashed contents. | 120 for (const auto& wc : WebContentsImpl::GetAllWebContents()) |
| 101 if (!widget->GetProcess()->HasConnection()) | 121 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 } | 122 } |
| 115 | 123 |
| 116 // static | 124 // static |
| 117 void RenderFrameDevToolsAgentHost::OnCancelPendingNavigation( | 125 void RenderFrameDevToolsAgentHost::OnCancelPendingNavigation( |
| 118 RenderFrameHost* pending, | 126 RenderFrameHost* pending, |
| 119 RenderFrameHost* current) { | 127 RenderFrameHost* current) { |
| 120 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(pending); | 128 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(pending); |
| 121 if (!agent_host) | 129 if (!agent_host) |
| 122 return; | 130 return; |
| 123 agent_host->DisconnectRenderFrameHost(); | 131 agent_host->DisconnectRenderFrameHost(); |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 402 const NotificationDetails& details) { | 410 const NotificationDetails& details) { |
| 403 if (type == content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED) { | 411 if (type == content::NOTIFICATION_RENDER_WIDGET_VISIBILITY_CHANGED) { |
| 404 bool visible = *Details<bool>(details).ptr(); | 412 bool visible = *Details<bool>(details).ptr(); |
| 405 page_handler_->OnVisibilityChanged(visible); | 413 page_handler_->OnVisibilityChanged(visible); |
| 406 } | 414 } |
| 407 } | 415 } |
| 408 | 416 |
| 409 void RenderFrameDevToolsAgentHost::SetRenderFrameHost(RenderFrameHost* rfh) { | 417 void RenderFrameDevToolsAgentHost::SetRenderFrameHost(RenderFrameHost* rfh) { |
| 410 DCHECK(!render_frame_host_); | 418 DCHECK(!render_frame_host_); |
| 411 render_frame_host_ = static_cast<RenderFrameHostImpl*>(rfh); | 419 render_frame_host_ = static_cast<RenderFrameHostImpl*>(rfh); |
| 420 // TODO(dgozman): here we should DCHECK that frame host is either root or |
| 421 // cross process subframe, but this requires handling cross-process |
| 422 // navigation. See http://crbug.com/464993. |
| 412 | 423 |
| 413 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(rfh)); | 424 WebContentsObserver::Observe(WebContents::FromRenderFrameHost(rfh)); |
| 414 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( | 425 RenderViewHostImpl* rvh = static_cast<RenderViewHostImpl*>( |
| 415 rfh->GetRenderViewHost()); | 426 rfh->GetRenderViewHost()); |
| 416 dom_handler_->SetRenderViewHost(rvh); | 427 dom_handler_->SetRenderViewHost(rvh); |
| 417 input_handler_->SetRenderViewHost(rvh); | 428 input_handler_->SetRenderViewHost(rvh); |
| 418 network_handler_->SetRenderViewHost(rvh); | 429 network_handler_->SetRenderViewHost(rvh); |
| 419 page_handler_->SetRenderViewHost(rvh); | 430 page_handler_->SetRenderViewHost(rvh); |
| 420 | 431 |
| 421 registrar_.Add( | 432 registrar_.Add( |
| (...skipping 19 matching lines...) Expand all Loading... |
| 441 | 452 |
| 442 void RenderFrameDevToolsAgentHost::DisconnectWebContents() { | 453 void RenderFrameDevToolsAgentHost::DisconnectWebContents() { |
| 443 DisconnectRenderFrameHost(); | 454 DisconnectRenderFrameHost(); |
| 444 } | 455 } |
| 445 | 456 |
| 446 void RenderFrameDevToolsAgentHost::ConnectWebContents(WebContents* wc) { | 457 void RenderFrameDevToolsAgentHost::ConnectWebContents(WebContents* wc) { |
| 447 ConnectRenderFrameHost(wc->GetMainFrame()); | 458 ConnectRenderFrameHost(wc->GetMainFrame()); |
| 448 } | 459 } |
| 449 | 460 |
| 450 DevToolsAgentHost::Type RenderFrameDevToolsAgentHost::GetType() { | 461 DevToolsAgentHost::Type RenderFrameDevToolsAgentHost::GetType() { |
| 451 return TYPE_WEB_CONTENTS; | 462 return IsChildFrame() ? TYPE_FRAME : TYPE_WEB_CONTENTS; |
| 452 } | 463 } |
| 453 | 464 |
| 454 std::string RenderFrameDevToolsAgentHost::GetTitle() { | 465 std::string RenderFrameDevToolsAgentHost::GetTitle() { |
| 466 if (IsChildFrame()) |
| 467 return GetURL().spec(); |
| 455 if (WebContents* web_contents = GetWebContents()) | 468 if (WebContents* web_contents = GetWebContents()) |
| 456 return base::UTF16ToUTF8(web_contents->GetTitle()); | 469 return base::UTF16ToUTF8(web_contents->GetTitle()); |
| 457 return ""; | 470 return ""; |
| 458 } | 471 } |
| 459 | 472 |
| 460 GURL RenderFrameDevToolsAgentHost::GetURL() { | 473 GURL RenderFrameDevToolsAgentHost::GetURL() { |
| 461 if (WebContents* web_contents = GetWebContents()) | 474 WebContents* web_contents = GetWebContents(); |
| 475 if (web_contents && !IsChildFrame()) |
| 462 return web_contents->GetVisibleURL(); | 476 return web_contents->GetVisibleURL(); |
| 463 return render_frame_host_ ? | 477 return render_frame_host_ ? |
| 464 render_frame_host_->GetLastCommittedURL() : GURL(); | 478 render_frame_host_->GetLastCommittedURL() : GURL(); |
| 465 } | 479 } |
| 466 | 480 |
| 467 bool RenderFrameDevToolsAgentHost::Activate() { | 481 bool RenderFrameDevToolsAgentHost::Activate() { |
| 468 if (render_frame_host_) { | 482 if (render_frame_host_) { |
| 469 render_frame_host_->GetRenderViewHost()->GetDelegate()->Activate(); | 483 render_frame_host_->GetRenderViewHost()->GetDelegate()->Activate(); |
| 470 return true; | 484 return true; |
| 471 } | 485 } |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 ProcessChunkedMessageFromAgent(message); | 541 ProcessChunkedMessageFromAgent(message); |
| 528 } | 542 } |
| 529 | 543 |
| 530 void RenderFrameDevToolsAgentHost::DispatchOnInspectorFrontend( | 544 void RenderFrameDevToolsAgentHost::DispatchOnInspectorFrontend( |
| 531 const std::string& message) { | 545 const std::string& message) { |
| 532 if (!IsAttached() || !render_frame_host_) | 546 if (!IsAttached() || !render_frame_host_) |
| 533 return; | 547 return; |
| 534 SendMessageToClient(message); | 548 SendMessageToClient(message); |
| 535 } | 549 } |
| 536 | 550 |
| 551 bool RenderFrameDevToolsAgentHost::IsChildFrame() { |
| 552 return render_frame_host_ && render_frame_host_->GetParent(); |
| 553 } |
| 554 |
| 537 } // namespace content | 555 } // namespace content |
| OLD | NEW |