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" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 // Iterate over the FrameTree to reset any node affected by the loss of the | 46 // Iterate over the FrameTree to reset any node affected by the loss of the |
47 // given RenderViewHost's process. | 47 // given RenderViewHost's process. |
48 bool ResetNodesForNewProcess(RenderViewHost* render_view_host, | 48 bool ResetNodesForNewProcess(RenderViewHost* render_view_host, |
49 FrameTreeNode* node) { | 49 FrameTreeNode* node) { |
50 if (render_view_host == node->current_frame_host()->render_view_host()) | 50 if (render_view_host == node->current_frame_host()->render_view_host()) |
51 node->ResetForNewProcess(); | 51 node->ResetForNewProcess(); |
52 return true; | 52 return true; |
53 } | 53 } |
54 | 54 |
55 bool CreateProxyForSiteInstance(FrameTreeNode* source_node, | 55 bool CreateProxyForSiteInstance(const scoped_refptr<SiteInstance>& instance, |
56 const scoped_refptr<SiteInstance>& instance, | |
57 FrameTreeNode* node) { | 56 FrameTreeNode* node) { |
58 // Skip the node that initiated the creation. | |
59 if (source_node == node) | |
60 return true; | |
61 | |
62 node->render_manager()->CreateRenderFrameProxy(instance.get()); | 57 node->render_manager()->CreateRenderFrameProxy(instance.get()); |
63 return true; | 58 return true; |
64 } | 59 } |
65 | 60 |
66 } // namespace | 61 } // namespace |
67 | 62 |
68 FrameTree::FrameTree(Navigator* navigator, | 63 FrameTree::FrameTree(Navigator* navigator, |
69 RenderFrameHostDelegate* render_frame_delegate, | 64 RenderFrameHostDelegate* render_frame_delegate, |
70 RenderViewHostDelegate* render_view_delegate, | 65 RenderViewHostDelegate* render_view_delegate, |
71 RenderWidgetHostDelegate* render_widget_delegate, | 66 RenderWidgetHostDelegate* render_widget_delegate, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 FrameTreeNode* result = render_frame_proxy_host->frame_tree_node(); | 116 FrameTreeNode* result = render_frame_proxy_host->frame_tree_node(); |
122 if (this == result->frame_tree()) | 117 if (this == result->frame_tree()) |
123 return result; | 118 return result; |
124 } | 119 } |
125 | 120 |
126 return NULL; | 121 return NULL; |
127 } | 122 } |
128 | 123 |
129 void FrameTree::ForEach( | 124 void FrameTree::ForEach( |
130 const base::Callback<bool(FrameTreeNode*)>& on_node) const { | 125 const base::Callback<bool(FrameTreeNode*)>& on_node) const { |
| 126 ForEach(on_node, NULL); |
| 127 } |
| 128 |
| 129 void FrameTree::ForEach( |
| 130 const base::Callback<bool(FrameTreeNode*)>& on_node, |
| 131 FrameTreeNode* skip_this_subtree) const { |
131 std::queue<FrameTreeNode*> queue; | 132 std::queue<FrameTreeNode*> queue; |
132 queue.push(root_.get()); | 133 queue.push(root_.get()); |
133 | 134 |
134 while (!queue.empty()) { | 135 while (!queue.empty()) { |
135 FrameTreeNode* node = queue.front(); | 136 FrameTreeNode* node = queue.front(); |
136 queue.pop(); | 137 queue.pop(); |
| 138 if (skip_this_subtree == node) |
| 139 continue; |
| 140 |
137 if (!on_node.Run(node)) | 141 if (!on_node.Run(node)) |
138 break; | 142 break; |
139 | 143 |
140 for (size_t i = 0; i < node->child_count(); ++i) | 144 for (size_t i = 0; i < node->child_count(); ++i) |
141 queue.push(node->child_at(i)); | 145 queue.push(node->child_at(i)); |
142 } | 146 } |
143 } | 147 } |
144 | 148 |
145 RenderFrameHostImpl* FrameTree::AddFrame(FrameTreeNode* parent, | 149 RenderFrameHostImpl* FrameTree::AddFrame(FrameTreeNode* parent, |
146 int process_id, | 150 int process_id, |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 if (!render_view_host) { | 198 if (!render_view_host) { |
195 root()->render_manager()->CreateRenderFrame(site_instance, | 199 root()->render_manager()->CreateRenderFrame(site_instance, |
196 MSG_ROUTING_NONE, | 200 MSG_ROUTING_NONE, |
197 true, | 201 true, |
198 false, | 202 false, |
199 true); | 203 true); |
200 } | 204 } |
201 } | 205 } |
202 | 206 |
203 scoped_refptr<SiteInstance> instance(site_instance); | 207 scoped_refptr<SiteInstance> instance(site_instance); |
204 ForEach(base::Bind(&CreateProxyForSiteInstance, source, instance)); | 208 |
| 209 // Proxies are created in the FrameTree in response to a node navigating to a |
| 210 // new SiteInstance. Since |source|'s navigation will replace the currently |
| 211 // loaded document, the entire subtree under |source| will be removed. |
| 212 ForEach(base::Bind(&CreateProxyForSiteInstance, instance), source); |
205 } | 213 } |
206 | 214 |
207 void FrameTree::ResetForMainFrameSwap() { | 215 void FrameTree::ResetForMainFrameSwap() { |
208 root_->ResetForNewProcess(); | 216 root_->ResetForNewProcess(); |
209 focused_frame_tree_node_id_ = -1; | 217 focused_frame_tree_node_id_ = -1; |
210 } | 218 } |
211 | 219 |
212 void FrameTree::RenderProcessGone(RenderViewHost* render_view_host) { | 220 void FrameTree::RenderProcessGone(RenderViewHost* render_view_host) { |
213 // Walk the full tree looking for nodes that may be affected. Once a frame | 221 // Walk the full tree looking for nodes that may be affected. Once a frame |
214 // crashes, all of its child FrameTreeNodes go away. | 222 // crashes, all of its child FrameTreeNodes go away. |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 rvh->Shutdown(); | 340 rvh->Shutdown(); |
333 render_view_host_pending_shutdown_map_.erase(multi_iter); | 341 render_view_host_pending_shutdown_map_.erase(multi_iter); |
334 } | 342 } |
335 break; | 343 break; |
336 } | 344 } |
337 CHECK(render_view_host_found); | 345 CHECK(render_view_host_found); |
338 } | 346 } |
339 } | 347 } |
340 | 348 |
341 } // namespace content | 349 } // namespace content |
OLD | NEW |