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 new_routing_id, | 150 int new_routing_id, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 if (!render_view_host) { | 190 if (!render_view_host) { |
187 root()->render_manager()->CreateRenderFrame(site_instance, | 191 root()->render_manager()->CreateRenderFrame(site_instance, |
188 MSG_ROUTING_NONE, | 192 MSG_ROUTING_NONE, |
189 true, | 193 true, |
190 false, | 194 false, |
191 true); | 195 true); |
192 } | 196 } |
193 } | 197 } |
194 | 198 |
195 scoped_refptr<SiteInstance> instance(site_instance); | 199 scoped_refptr<SiteInstance> instance(site_instance); |
196 ForEach(base::Bind(&CreateProxyForSiteInstance, source, instance)); | 200 |
| 201 // Proxies are created in the FrameTree in response to a node navigating to a |
| 202 // new SiteInstance. Since |source|'s navigation will replace the currently |
| 203 // loaded document, the entire subtree under |source| will be removed. |
| 204 ForEach(base::Bind(&CreateProxyForSiteInstance, instance), source); |
197 } | 205 } |
198 | 206 |
199 void FrameTree::ResetForMainFrameSwap() { | 207 void FrameTree::ResetForMainFrameSwap() { |
200 root_->ResetForNewProcess(); | 208 root_->ResetForNewProcess(); |
201 focused_frame_tree_node_id_ = -1; | 209 focused_frame_tree_node_id_ = -1; |
202 } | 210 } |
203 | 211 |
204 void FrameTree::RenderProcessGone(RenderViewHost* render_view_host) { | 212 void FrameTree::RenderProcessGone(RenderViewHost* render_view_host) { |
205 // Walk the full tree looking for nodes that may be affected. Once a frame | 213 // Walk the full tree looking for nodes that may be affected. Once a frame |
206 // crashes, all of its child FrameTreeNodes go away. | 214 // crashes, all of its child FrameTreeNodes go away. |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 rvh->Shutdown(); | 330 rvh->Shutdown(); |
323 render_view_host_pending_shutdown_map_.erase(multi_iter); | 331 render_view_host_pending_shutdown_map_.erase(multi_iter); |
324 } | 332 } |
325 break; | 333 break; |
326 } | 334 } |
327 CHECK(render_view_host_found); | 335 CHECK(render_view_host_found); |
328 } | 336 } |
329 } | 337 } |
330 | 338 |
331 } // namespace content | 339 } // namespace content |
OLD | NEW |