| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 if (g_instances == NULL) | 64 if (g_instances == NULL) |
| 65 return NULL; | 65 return NULL; |
| 66 for (Instances::iterator it = g_instances.Get().begin(); | 66 for (Instances::iterator it = g_instances.Get().begin(); |
| 67 it != g_instances.Get().end(); ++it) { | 67 it != g_instances.Get().end(); ++it) { |
| 68 if ((*it)->frame_tree_node() == frame_tree_node) | 68 if ((*it)->frame_tree_node() == frame_tree_node) |
| 69 return *it; | 69 return *it; |
| 70 } | 70 } |
| 71 return NULL; | 71 return NULL; |
| 72 } | 72 } |
| 73 | 73 |
| 74 // Returns RenderFrameDevToolsAgentHost attached to any of RenderFrameHost | |
| 75 // instances associated with |web_contents| | |
| 76 static RenderFrameDevToolsAgentHost* FindAgentHost(WebContents* web_contents) { | 74 static RenderFrameDevToolsAgentHost* FindAgentHost(WebContents* web_contents) { |
| 77 if (g_instances == NULL) | 75 if (!web_contents->GetMainFrame()) |
| 78 return NULL; | 76 return nullptr; |
| 79 for (Instances::iterator it = g_instances.Get().begin(); | 77 return FindAgentHost(web_contents->GetMainFrame()); |
| 80 it != g_instances.Get().end(); ++it) { | |
| 81 if ((*it)->GetWebContents() == web_contents) | |
| 82 return *it; | |
| 83 } | |
| 84 return NULL; | |
| 85 } | 78 } |
| 86 | 79 |
| 87 bool ShouldCreateDevToolsFor(RenderFrameHost* rfh) { | 80 bool ShouldCreateDevToolsFor(RenderFrameHost* rfh) { |
| 88 return rfh->IsCrossProcessSubframe() || !rfh->GetParent(); | 81 return rfh->IsCrossProcessSubframe() || !rfh->GetParent(); |
| 89 } | 82 } |
| 90 | 83 |
| 91 } // namespace | 84 } // namespace |
| 92 | 85 |
| 93 // RenderFrameDevToolsAgentHost::FrameHostHolder ------------------------------- | 86 // RenderFrameDevToolsAgentHost::FrameHostHolder ------------------------------- |
| 94 | 87 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 if (!result) { | 251 if (!result) { |
| 259 result = new RenderFrameDevToolsAgentHost( | 252 result = new RenderFrameDevToolsAgentHost( |
| 260 static_cast<RenderFrameHostImpl*>(frame_host)); | 253 static_cast<RenderFrameHostImpl*>(frame_host)); |
| 261 } | 254 } |
| 262 return result; | 255 return result; |
| 263 } | 256 } |
| 264 | 257 |
| 265 // static | 258 // static |
| 266 scoped_refptr<DevToolsAgentHost> | 259 scoped_refptr<DevToolsAgentHost> |
| 267 DevToolsAgentHost::GetOrCreateFor(WebContents* web_contents) { | 260 DevToolsAgentHost::GetOrCreateFor(WebContents* web_contents) { |
| 268 RenderFrameDevToolsAgentHost* result = FindAgentHost(web_contents); | 261 // TODO(dgozman): this check should not be necessary. See |
| 269 if (!result) { | 262 // http://crbug.com/489664. |
| 270 // TODO(dgozman): this check should not be necessary. See | 263 if (!web_contents->GetMainFrame()) |
| 271 // http://crbug.com/489664. | 264 return nullptr; |
| 272 if (!web_contents->GetMainFrame()) | 265 return DevToolsAgentHost::GetOrCreateFor(web_contents->GetMainFrame()); |
| 273 return nullptr; | |
| 274 result = new RenderFrameDevToolsAgentHost( | |
| 275 static_cast<RenderFrameHostImpl*>(web_contents->GetMainFrame())); | |
| 276 } | |
| 277 return result; | |
| 278 } | 266 } |
| 279 | 267 |
| 280 // static | 268 // static |
| 281 scoped_refptr<DevToolsAgentHost> RenderFrameDevToolsAgentHost::GetOrCreateFor( | 269 scoped_refptr<DevToolsAgentHost> RenderFrameDevToolsAgentHost::GetOrCreateFor( |
| 282 RenderFrameHostImpl* host) { | 270 RenderFrameHostImpl* host) { |
| 283 RenderFrameDevToolsAgentHost* result = FindAgentHost(host); | 271 RenderFrameDevToolsAgentHost* result = FindAgentHost(host); |
| 284 if (!result) | 272 if (!result) |
| 285 result = new RenderFrameDevToolsAgentHost(host); | 273 result = new RenderFrameDevToolsAgentHost(host); |
| 286 return result; | 274 return result; |
| 287 } | 275 } |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 RenderFrameHost* host) { | 896 RenderFrameHost* host) { |
| 909 return (current_ && current_->host() == host) || | 897 return (current_ && current_->host() == host) || |
| 910 (pending_ && pending_->host() == host); | 898 (pending_ && pending_->host() == host); |
| 911 } | 899 } |
| 912 | 900 |
| 913 bool RenderFrameDevToolsAgentHost::IsChildFrame() { | 901 bool RenderFrameDevToolsAgentHost::IsChildFrame() { |
| 914 return current_ && current_->host()->GetParent(); | 902 return current_ && current_->host()->GetParent(); |
| 915 } | 903 } |
| 916 | 904 |
| 917 } // namespace content | 905 } // namespace content |
| OLD | NEW |