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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
265 | 287 |
266 render_view_host_map_[site_instance->GetId()] = rvh; | 288 render_view_host_map_[site_instance->GetId()] = rvh; |
267 return rvh; | 289 return rvh; |
268 } | 290 } |
269 | 291 |
270 RenderViewHostImpl* FrameTree::GetRenderViewHost(SiteInstance* site_instance) { | 292 RenderViewHostImpl* FrameTree::GetRenderViewHost(SiteInstance* site_instance) { |
271 RenderViewHostMap::iterator iter = | 293 RenderViewHostMap::iterator iter = |
272 render_view_host_map_.find(site_instance->GetId()); | 294 render_view_host_map_.find(site_instance->GetId()); |
273 // TODO(creis): Mirror the frame tree so this check can't fail. | 295 // TODO(creis): Mirror the frame tree so this check can't fail. |
274 if (iter == render_view_host_map_.end()) | 296 if (iter == render_view_host_map_.end()) |
275 return NULL; | 297 return nullptr; |
276 return iter->second; | 298 return iter->second; |
277 } | 299 } |
278 | 300 |
279 void FrameTree::RegisterRenderFrameHost( | 301 void FrameTree::RegisterRenderFrameHost( |
280 RenderFrameHostImpl* render_frame_host) { | 302 RenderFrameHostImpl* render_frame_host) { |
281 SiteInstance* site_instance = render_frame_host->GetSiteInstance(); | 303 SiteInstance* site_instance = render_frame_host->GetSiteInstance(); |
282 RenderViewHostMap::iterator iter = | 304 RenderViewHostMap::iterator iter = |
283 render_view_host_map_.find(site_instance->GetId()); | 305 render_view_host_map_.find(site_instance->GetId()); |
284 CHECK(iter != render_view_host_map_.end()); | 306 CHECK(iter != render_view_host_map_.end()); |
285 | 307 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 load_progress_ = 0.0; | 388 load_progress_ = 0.0; |
367 } | 389 } |
368 | 390 |
369 bool FrameTree::IsLoading() { | 391 bool FrameTree::IsLoading() { |
370 bool is_loading = false; | 392 bool is_loading = false; |
371 ForEach(base::Bind(&IsNodeLoading, &is_loading)); | 393 ForEach(base::Bind(&IsNodeLoading, &is_loading)); |
372 return is_loading; | 394 return is_loading; |
373 } | 395 } |
374 | 396 |
375 } // namespace content | 397 } // namespace content |
OLD | NEW |