• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include "content/browser/frame_host/frame_tree_node.h"
6 
7 #include <queue>
8 
9 #include "base/stl_util.h"
10 #include "content/browser/frame_host/navigator.h"
11 #include "content/browser/frame_host/render_frame_host_impl.h"
12 
13 namespace content {
14 
15 const int64 FrameTreeNode::kInvalidFrameId = -1;
16 int64 FrameTreeNode::next_frame_tree_node_id_ = 1;
17 
FrameTreeNode(Navigator * navigator,RenderFrameHostDelegate * render_frame_delegate,RenderViewHostDelegate * render_view_delegate,RenderWidgetHostDelegate * render_widget_delegate,RenderFrameHostManager::Delegate * manager_delegate,int64 frame_id,const std::string & name)18 FrameTreeNode::FrameTreeNode(Navigator* navigator,
19                              RenderFrameHostDelegate* render_frame_delegate,
20                              RenderViewHostDelegate* render_view_delegate,
21                              RenderWidgetHostDelegate* render_widget_delegate,
22                              RenderFrameHostManager::Delegate* manager_delegate,
23                              int64 frame_id,
24                              const std::string& name)
25   : navigator_(navigator),
26     render_manager_(render_frame_delegate,
27                     render_view_delegate,
28                     render_widget_delegate,
29                     manager_delegate),
30     frame_tree_node_id_(next_frame_tree_node_id_++),
31     frame_id_(frame_id),
32     frame_name_(name),
33     owns_render_frame_host_(true),
34     render_frame_host_(NULL) {
35 }
36 
~FrameTreeNode()37 FrameTreeNode::~FrameTreeNode() {
38   if (owns_render_frame_host_)
39     delete render_frame_host_;
40 }
41 
AddChild(scoped_ptr<FrameTreeNode> child)42 void FrameTreeNode::AddChild(scoped_ptr<FrameTreeNode> child) {
43   children_.push_back(child.release());
44 }
45 
RemoveChild(FrameTreeNode * child)46 void FrameTreeNode::RemoveChild(FrameTreeNode* child) {
47   std::vector<FrameTreeNode*>::iterator iter;
48 
49   for (iter = children_.begin(); iter != children_.end(); ++iter) {
50     if ((*iter) == child)
51       break;
52   }
53 
54   if (iter != children_.end())
55     children_.erase(iter);
56 }
57 
ResetForMainFrame(RenderFrameHostImpl * new_render_frame_host)58 void FrameTreeNode::ResetForMainFrame(
59     RenderFrameHostImpl* new_render_frame_host) {
60   owns_render_frame_host_ = false;
61   frame_id_ = kInvalidFrameId;
62   current_url_ = GURL();
63 
64   // The children may not have been cleared if a cross-process navigation
65   // commits before the old process cleans everything up.  Make sure the child
66   // nodes get deleted.
67   children_.clear();
68 
69   render_frame_host_ = new_render_frame_host;
70 }
71 
72 }  // namespace content
73