| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/frame_host/frame_tree.h" | 5 #include "content/browser/frame_host/frame_tree.h" |
| 6 | 6 |
| 7 #include <queue> | 7 #include <queue> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "content/browser/frame_host/frame_tree_node.h" | 13 #include "content/browser/frame_host/frame_tree_node.h" |
| 14 #include "content/browser/frame_host/navigator.h" | 14 #include "content/browser/frame_host/navigator.h" |
| 15 #include "content/browser/frame_host/render_frame_host_factory.h" | 15 #include "content/browser/frame_host/render_frame_host_factory.h" |
| 16 #include "content/browser/frame_host/render_frame_host_impl.h" | 16 #include "content/browser/frame_host/render_frame_host_impl.h" |
| 17 #include "content/browser/frame_host/render_frame_proxy_host.h" | 17 #include "content/browser/frame_host/render_frame_proxy_host.h" |
| 18 #include "content/browser/renderer_host/render_view_host_factory.h" | 18 #include "content/browser/renderer_host/render_view_host_factory.h" |
| 19 #include "content/browser/renderer_host/render_view_host_impl.h" | 19 #include "content/browser/renderer_host/render_view_host_impl.h" |
| 20 | 20 |
| 21 namespace content { | 21 namespace content { |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // Used with FrameTree::ForEach() to search for the FrameTreeNode | 25 // Used with FrameTree::ForEach() to search for the FrameTreeNode |
| 26 // corresponding to |frame_tree_node_id| whithin a specific FrameTree. | 26 // corresponding to |frame_tree_node_id| within a specific FrameTree. |
| 27 bool FrameTreeNodeForId(int64 frame_tree_node_id, | 27 bool FrameTreeNodeForId(int64 frame_tree_node_id, |
| 28 FrameTreeNode** out_node, | 28 FrameTreeNode** out_node, |
| 29 FrameTreeNode* node) { | 29 FrameTreeNode* node) { |
| 30 if (node->frame_tree_node_id() == frame_tree_node_id) { | 30 if (node->frame_tree_node_id() == frame_tree_node_id) { |
| 31 *out_node = node; | 31 *out_node = node; |
| 32 // Terminate iteration once the node has been found. | 32 // Terminate iteration once the node has been found. |
| 33 return false; | 33 return false; |
| 34 } | 34 } |
| 35 return true; | 35 return true; |
| 36 } | 36 } |
| 37 | 37 |
| 38 // Used with FrameTree::ForEach() to search for the FrameTreeNode with the given |
| 39 // |name| within a specific FrameTree. |
| 40 bool FrameTreeNodeForName(const std::string& name, |
| 41 FrameTreeNode** out_node, |
| 42 FrameTreeNode* node) { |
| 43 if (node->frame_name() == name) { |
| 44 *out_node = node; |
| 45 // Terminate iteration once the node has been found. |
| 46 return false; |
| 47 } |
| 48 return true; |
| 49 } |
| 50 |
| 38 bool CreateProxyForSiteInstance(const scoped_refptr<SiteInstance>& instance, | 51 bool CreateProxyForSiteInstance(const scoped_refptr<SiteInstance>& instance, |
| 39 FrameTreeNode* node) { | 52 FrameTreeNode* node) { |
| 40 // If a new frame is created in the current SiteInstance, other frames in | 53 // If a new frame is created in the current SiteInstance, other frames in |
| 41 // that SiteInstance don't need a proxy for the new frame. | 54 // that SiteInstance don't need a proxy for the new frame. |
| 42 SiteInstance* current_instance = | 55 SiteInstance* current_instance = |
| 43 node->render_manager()->current_frame_host()->GetSiteInstance(); | 56 node->render_manager()->current_frame_host()->GetSiteInstance(); |
| 44 if (current_instance != instance.get()) | 57 if (current_instance != instance.get()) |
| 45 node->render_manager()->CreateRenderFrameProxy(instance.get()); | 58 node->render_manager()->CreateRenderFrameProxy(instance.get()); |
| 46 return true; | 59 return true; |
| 47 } | 60 } |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 manager_delegate, | 110 manager_delegate, |
| 98 std::string())), | 111 std::string())), |
| 99 focused_frame_tree_node_id_(-1), | 112 focused_frame_tree_node_id_(-1), |
| 100 load_progress_(0.0) { | 113 load_progress_(0.0) { |
| 101 } | 114 } |
| 102 | 115 |
| 103 FrameTree::~FrameTree() { | 116 FrameTree::~FrameTree() { |
| 104 } | 117 } |
| 105 | 118 |
| 106 FrameTreeNode* FrameTree::FindByID(int64 frame_tree_node_id) { | 119 FrameTreeNode* FrameTree::FindByID(int64 frame_tree_node_id) { |
| 107 FrameTreeNode* node = NULL; | 120 FrameTreeNode* node = nullptr; |
| 108 ForEach(base::Bind(&FrameTreeNodeForId, frame_tree_node_id, &node)); | 121 ForEach(base::Bind(&FrameTreeNodeForId, frame_tree_node_id, &node)); |
| 109 return node; | 122 return node; |
| 110 } | 123 } |
| 111 | 124 |
| 112 FrameTreeNode* FrameTree::FindByRoutingID(int process_id, int routing_id) { | 125 FrameTreeNode* FrameTree::FindByRoutingID(int process_id, int routing_id) { |
| 113 RenderFrameHostImpl* render_frame_host = | 126 RenderFrameHostImpl* render_frame_host = |
| 114 RenderFrameHostImpl::FromID(process_id, routing_id); | 127 RenderFrameHostImpl::FromID(process_id, routing_id); |
| 115 if (render_frame_host) { | 128 if (render_frame_host) { |
| 116 FrameTreeNode* result = render_frame_host->frame_tree_node(); | 129 FrameTreeNode* result = render_frame_host->frame_tree_node(); |
| 117 if (this == result->frame_tree()) | 130 if (this == result->frame_tree()) |
| 118 return result; | 131 return result; |
| 119 } | 132 } |
| 120 | 133 |
| 121 RenderFrameProxyHost* render_frame_proxy_host = | 134 RenderFrameProxyHost* render_frame_proxy_host = |
| 122 RenderFrameProxyHost::FromID(process_id, routing_id); | 135 RenderFrameProxyHost::FromID(process_id, routing_id); |
| 123 if (render_frame_proxy_host) { | 136 if (render_frame_proxy_host) { |
| 124 FrameTreeNode* result = render_frame_proxy_host->frame_tree_node(); | 137 FrameTreeNode* result = render_frame_proxy_host->frame_tree_node(); |
| 125 if (this == result->frame_tree()) | 138 if (this == result->frame_tree()) |
| 126 return result; | 139 return result; |
| 127 } | 140 } |
| 128 | 141 |
| 129 return NULL; | 142 return nullptr; |
| 143 } |
| 144 |
| 145 FrameTreeNode* FrameTree::FindByName(const std::string& name) { |
| 146 if (name.empty()) |
| 147 return root_.get(); |
| 148 |
| 149 FrameTreeNode* node = nullptr; |
| 150 ForEach(base::Bind(&FrameTreeNodeForName, name, &node)); |
| 151 return node; |
| 130 } | 152 } |
| 131 | 153 |
| 132 void FrameTree::ForEach( | 154 void FrameTree::ForEach( |
| 133 const base::Callback<bool(FrameTreeNode*)>& on_node) const { | 155 const base::Callback<bool(FrameTreeNode*)>& on_node) const { |
| 134 ForEach(on_node, NULL); | 156 ForEach(on_node, nullptr); |
| 135 } | 157 } |
| 136 | 158 |
| 137 void FrameTree::ForEach( | 159 void FrameTree::ForEach( |
| 138 const base::Callback<bool(FrameTreeNode*)>& on_node, | 160 const base::Callback<bool(FrameTreeNode*)>& on_node, |
| 139 FrameTreeNode* skip_this_subtree) const { | 161 FrameTreeNode* skip_this_subtree) const { |
| 140 std::queue<FrameTreeNode*> queue; | 162 std::queue<FrameTreeNode*> queue; |
| 141 queue.push(root_.get()); | 163 queue.push(root_.get()); |
| 142 | 164 |
| 143 while (!queue.empty()) { | 165 while (!queue.empty()) { |
| 144 FrameTreeNode* node = queue.front(); | 166 FrameTreeNode* node = queue.front(); |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 | 292 |
| 271 render_view_host_map_[site_instance->GetId()] = rvh; | 293 render_view_host_map_[site_instance->GetId()] = rvh; |
| 272 return rvh; | 294 return rvh; |
| 273 } | 295 } |
| 274 | 296 |
| 275 RenderViewHostImpl* FrameTree::GetRenderViewHost(SiteInstance* site_instance) { | 297 RenderViewHostImpl* FrameTree::GetRenderViewHost(SiteInstance* site_instance) { |
| 276 RenderViewHostMap::iterator iter = | 298 RenderViewHostMap::iterator iter = |
| 277 render_view_host_map_.find(site_instance->GetId()); | 299 render_view_host_map_.find(site_instance->GetId()); |
| 278 // TODO(creis): Mirror the frame tree so this check can't fail. | 300 // TODO(creis): Mirror the frame tree so this check can't fail. |
| 279 if (iter == render_view_host_map_.end()) | 301 if (iter == render_view_host_map_.end()) |
| 280 return NULL; | 302 return nullptr; |
| 281 return iter->second; | 303 return iter->second; |
| 282 } | 304 } |
| 283 | 305 |
| 284 void FrameTree::RegisterRenderFrameHost( | 306 void FrameTree::RegisterRenderFrameHost( |
| 285 RenderFrameHostImpl* render_frame_host) { | 307 RenderFrameHostImpl* render_frame_host) { |
| 286 SiteInstance* site_instance = render_frame_host->GetSiteInstance(); | 308 SiteInstance* site_instance = render_frame_host->GetSiteInstance(); |
| 287 RenderViewHostMap::iterator iter = | 309 RenderViewHostMap::iterator iter = |
| 288 render_view_host_map_.find(site_instance->GetId()); | 310 render_view_host_map_.find(site_instance->GetId()); |
| 289 CHECK(iter != render_view_host_map_.end()); | 311 CHECK(iter != render_view_host_map_.end()); |
| 290 | 312 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 load_progress_ = 0.0; | 390 load_progress_ = 0.0; |
| 369 } | 391 } |
| 370 | 392 |
| 371 bool FrameTree::IsLoading() { | 393 bool FrameTree::IsLoading() { |
| 372 bool is_loading = false; | 394 bool is_loading = false; |
| 373 ForEach(base::Bind(&IsNodeLoading, &is_loading)); | 395 ForEach(base::Bind(&IsNodeLoading, &is_loading)); |
| 374 return is_loading; | 396 return is_loading; |
| 375 } | 397 } |
| 376 | 398 |
| 377 } // namespace content | 399 } // namespace content |
| OLD | NEW |