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 <tuple> | 7 #include <tuple> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/guid.h" | 10 #include "base/guid.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 static RenderFrameDevToolsAgentHost* FindAgentHost(WebContents* web_contents) { | 85 static RenderFrameDevToolsAgentHost* FindAgentHost(WebContents* web_contents) { |
| 86 if (!web_contents->GetMainFrame()) | 86 if (!web_contents->GetMainFrame()) |
| 87 return nullptr; | 87 return nullptr; |
| 88 return FindAgentHost(web_contents->GetMainFrame()); | 88 return FindAgentHost(web_contents->GetMainFrame()); |
| 89 } | 89 } |
| 90 | 90 |
| 91 bool ShouldCreateDevToolsFor(RenderFrameHost* rfh) { | 91 bool ShouldCreateDevToolsFor(RenderFrameHost* rfh) { |
| 92 return rfh->IsCrossProcessSubframe() || !rfh->GetParent(); | 92 return rfh->IsCrossProcessSubframe() || !rfh->GetParent(); |
| 93 } | 93 } |
| 94 | 94 |
| 95 bool ShouldCreateDevToolsForNode(FrameTreeNode* ftn) { | |
| 96 return ShouldCreateDevToolsFor(ftn->current_frame_host()); | |
|
clamy
2017/01/11 13:47:29
I'm not sure if we should check for the Speculativ
dgozman
2017/01/11 18:24:31
Good question. Let's not for now - I hope PlzNavig
| |
| 97 } | |
| 98 | |
| 99 static RenderFrameDevToolsAgentHost* GetAgentHostFor(FrameTreeNode* ftn) { | |
| 100 while (ftn && !ShouldCreateDevToolsForNode(ftn)) | |
| 101 ftn = ftn->parent(); | |
| 102 return FindAgentHost(ftn); | |
| 103 } | |
| 104 | |
| 95 } // namespace | 105 } // namespace |
| 96 | 106 |
| 97 // RenderFrameDevToolsAgentHost::FrameHostHolder ------------------------------- | 107 // RenderFrameDevToolsAgentHost::FrameHostHolder ------------------------------- |
| 98 | 108 |
| 99 class RenderFrameDevToolsAgentHost::FrameHostHolder { | 109 class RenderFrameDevToolsAgentHost::FrameHostHolder { |
| 100 public: | 110 public: |
| 101 FrameHostHolder( | 111 FrameHostHolder( |
| 102 RenderFrameDevToolsAgentHost* agent, RenderFrameHostImpl* host); | 112 RenderFrameDevToolsAgentHost* agent, RenderFrameHostImpl* host); |
| 103 ~FrameHostHolder(); | 113 ~FrameHostHolder(); |
| 104 | 114 |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 388 protocol::PageHandler* page_handler = | 398 protocol::PageHandler* page_handler = |
| 389 protocol::PageHandler::FromSession(agent_host->session()); | 399 protocol::PageHandler::FromSession(agent_host->session()); |
| 390 if (!page_handler) | 400 if (!page_handler) |
| 391 return nullptr; | 401 return nullptr; |
| 392 return page_handler->CreateThrottleForNavigation(navigation_handle); | 402 return page_handler->CreateThrottleForNavigation(navigation_handle); |
| 393 } | 403 } |
| 394 | 404 |
| 395 // static | 405 // static |
| 396 bool RenderFrameDevToolsAgentHost::IsNetworkHandlerEnabled( | 406 bool RenderFrameDevToolsAgentHost::IsNetworkHandlerEnabled( |
| 397 FrameTreeNode* frame_tree_node) { | 407 FrameTreeNode* frame_tree_node) { |
| 398 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node); | 408 RenderFrameDevToolsAgentHost* agent_host = GetAgentHostFor(frame_tree_node); |
| 399 if (!agent_host || !agent_host->session()) | 409 if (!agent_host || !agent_host->session()) |
| 400 return false; | 410 return false; |
| 401 return protocol::NetworkHandler::FromSession(agent_host->session()) | 411 return protocol::NetworkHandler::FromSession(agent_host->session()) |
| 402 ->enabled(); | 412 ->enabled(); |
| 403 } | 413 } |
| 404 | 414 |
| 405 // static | 415 // static |
| 406 std::string RenderFrameDevToolsAgentHost::UserAgentOverride( | 416 std::string RenderFrameDevToolsAgentHost::UserAgentOverride( |
| 407 FrameTreeNode* frame_tree_node) { | 417 FrameTreeNode* frame_tree_node) { |
| 408 RenderFrameDevToolsAgentHost* agent_host = FindAgentHost(frame_tree_node); | 418 RenderFrameDevToolsAgentHost* agent_host = GetAgentHostFor(frame_tree_node); |
| 409 if (!agent_host || !agent_host->session()) | 419 if (!agent_host || !agent_host->session()) |
| 410 return std::string(); | 420 return std::string(); |
| 411 return protocol::NetworkHandler::FromSession(agent_host->session()) | 421 return protocol::NetworkHandler::FromSession(agent_host->session()) |
| 412 ->UserAgentOverride(); | 422 ->UserAgentOverride(); |
| 413 } | 423 } |
| 414 | 424 |
| 415 // static | 425 // static |
| 416 void RenderFrameDevToolsAgentHost::WebContentsCreated( | 426 void RenderFrameDevToolsAgentHost::WebContentsCreated( |
| 417 WebContents* web_contents) { | 427 WebContents* web_contents) { |
| 418 if (ShouldForceCreation()) { | 428 if (ShouldForceCreation()) { |
| (...skipping 733 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1152 RenderFrameHost* host) { | 1162 RenderFrameHost* host) { |
| 1153 return (current_ && current_->host() == host) || | 1163 return (current_ && current_->host() == host) || |
| 1154 (pending_ && pending_->host() == host); | 1164 (pending_ && pending_->host() == host); |
| 1155 } | 1165 } |
| 1156 | 1166 |
| 1157 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | 1167 bool RenderFrameDevToolsAgentHost::IsChildFrame() { |
| 1158 return current_ && current_->host()->GetParent(); | 1168 return current_ && current_->host()->GetParent(); |
| 1159 } | 1169 } |
| 1160 | 1170 |
| 1161 } // namespace content | 1171 } // namespace content |
| OLD | NEW |