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 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 | 58 |
59 // Iterate over the FrameTree to reset any node affected by the loss of the | 59 // Iterate over the FrameTree to reset any node affected by the loss of the |
60 // given RenderViewHost's process. | 60 // given RenderViewHost's process. |
61 bool ResetNodesForNewProcess(RenderViewHost* render_view_host, | 61 bool ResetNodesForNewProcess(RenderViewHost* render_view_host, |
62 FrameTreeNode* node) { | 62 FrameTreeNode* node) { |
63 if (render_view_host == node->current_frame_host()->render_view_host()) | 63 if (render_view_host == node->current_frame_host()->render_view_host()) |
64 node->ResetForNewProcess(); | 64 node->ResetForNewProcess(); |
65 return true; | 65 return true; |
66 } | 66 } |
67 | 67 |
68 bool CreateProxyForSiteInstance(FrameTreeNode* source_node, | 68 bool CreateProxyForSiteInstance(const scoped_refptr<SiteInstance>& instance, |
69 const scoped_refptr<SiteInstance>& instance, | |
70 FrameTreeNode* node) { | 69 FrameTreeNode* node) { |
71 // Skip the node that initiated the creation. | |
72 if (source_node == node) | |
73 return true; | |
74 | |
75 node->render_manager()->CreateRenderFrameProxy(instance.get()); | 70 node->render_manager()->CreateRenderFrameProxy(instance.get()); |
76 return true; | 71 return true; |
77 } | 72 } |
78 | 73 |
79 } // namespace | 74 } // namespace |
80 | 75 |
81 FrameTree::FrameTree(Navigator* navigator, | 76 FrameTree::FrameTree(Navigator* navigator, |
82 RenderFrameHostDelegate* render_frame_delegate, | 77 RenderFrameHostDelegate* render_frame_delegate, |
83 RenderViewHostDelegate* render_view_delegate, | 78 RenderViewHostDelegate* render_view_delegate, |
84 RenderWidgetHostDelegate* render_widget_delegate, | 79 RenderWidgetHostDelegate* render_widget_delegate, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 | 116 |
122 FrameTreeNode* FrameTree::FindByRoutingID(int routing_id, int process_id) { | 117 FrameTreeNode* FrameTree::FindByRoutingID(int routing_id, int process_id) { |
123 FrameTreeNode* node = NULL; | 118 FrameTreeNode* node = NULL; |
124 ForEach( | 119 ForEach( |
125 base::Bind(&FrameTreeNodeForRoutingId, routing_id, process_id, &node)); | 120 base::Bind(&FrameTreeNodeForRoutingId, routing_id, process_id, &node)); |
126 return node; | 121 return node; |
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 |