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
3 // found in the LICENSE file.
5 #include "content/browser/frame_host/frame_tree_node.h"
9 #include "base/stl_util.h"
10 #include "content/browser/frame_host/frame_tree.h"
11 #include "content/browser/frame_host/navigator.h"
12 #include "content/browser/frame_host/render_frame_host_impl.h"
13 #include "content/browser/renderer_host/render_view_host_impl.h"
17 int64
FrameTreeNode::next_frame_tree_node_id_
= 1;
19 FrameTreeNode::FrameTreeNode(FrameTree
* frame_tree
,
21 RenderFrameHostDelegate
* render_frame_delegate
,
22 RenderViewHostDelegate
* render_view_delegate
,
23 RenderWidgetHostDelegate
* render_widget_delegate
,
24 RenderFrameHostManager::Delegate
* manager_delegate
,
25 const std::string
& name
)
26 : frame_tree_(frame_tree
),
27 navigator_(navigator
),
29 render_frame_delegate
,
31 render_widget_delegate
,
33 frame_tree_node_id_(next_frame_tree_node_id_
++),
37 FrameTreeNode::~FrameTreeNode() {
40 bool FrameTreeNode::IsMainFrame() const {
41 return frame_tree_
->root() == this;
44 void FrameTreeNode::AddChild(scoped_ptr
<FrameTreeNode
> child
,
45 int frame_routing_id
) {
46 // Initialize the RenderFrameHost for the new node. We always create child
47 // frames in the same SiteInstance as the current frame, and they can swap to
48 // a different one if they navigate away.
49 child
->render_manager()->Init(
50 render_manager_
.current_host()->GetSiteInstance()->GetBrowserContext(),
51 render_manager_
.current_host()->GetSiteInstance(),
52 render_manager_
.current_host()->GetRoutingID(),
54 child
->set_parent(this);
55 children_
.push_back(child
.release());
58 void FrameTreeNode::RemoveChild(FrameTreeNode
* child
) {
59 std::vector
<FrameTreeNode
*>::iterator iter
;
61 for (iter
= children_
.begin(); iter
!= children_
.end(); ++iter
) {
66 if (iter
!= children_
.end()) {
67 // Subtle: we need to make sure the node is gone from the tree before
68 // observers are notified of its deletion.
69 scoped_ptr
<FrameTreeNode
> node_to_delete(*iter
);
70 children_
.weak_erase(iter
);
71 node_to_delete
->set_parent(NULL
);
72 node_to_delete
.reset();
76 void FrameTreeNode::ResetForNewProcess() {
77 current_url_
= GURL();
79 // The children may not have been cleared if a cross-process navigation
80 // commits before the old process cleans everything up. Make sure the child
81 // nodes get deleted before swapping to a new process.
82 ScopedVector
<FrameTreeNode
> old_children
= children_
.Pass();
83 old_children
.clear(); // May notify observers.
86 } // namespace content