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 #ifndef CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_
6 #define CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_
10 #include "base/basictypes.h"
11 #include "base/memory/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/scoped_vector.h"
14 #include "content/browser/frame_host/render_frame_host_impl.h"
15 #include "content/browser/frame_host/render_frame_host_manager.h"
16 #include "content/common/content_export.h"
23 class RenderFrameHostImpl
;
25 // When a page contains iframes, its renderer process maintains a tree structure
26 // of those frames. We are mirroring this tree in the browser process. This
27 // class represents a node in this tree and is a wrapper for all objects that
28 // are frame-specific (as opposed to page-specific).
29 class CONTENT_EXPORT FrameTreeNode
{
32 FrameTreeNode(FrameTree
* frame_tree
,
34 RenderFrameHostDelegate
* render_frame_delegate
,
35 RenderViewHostDelegate
* render_view_delegate
,
36 RenderWidgetHostDelegate
* render_widget_delegate
,
37 RenderFrameHostManager::Delegate
* manager_delegate
,
38 const std::string
& name
);
42 bool IsMainFrame() const;
44 void AddChild(scoped_ptr
<FrameTreeNode
> child
,
46 int frame_routing_id
);
47 void RemoveChild(FrameTreeNode
* child
);
49 // Clears process specific-state in this node to prepare for a new process.
50 void ResetForNewProcess();
52 FrameTree
* frame_tree() const {
56 Navigator
* navigator() {
57 return navigator_
.get();
60 RenderFrameHostManager
* render_manager() {
61 return &render_manager_
;
64 int64
frame_tree_node_id() const {
65 return frame_tree_node_id_
;
68 const std::string
& frame_name() const {
72 size_t child_count() const {
73 return children_
.size();
76 FrameTreeNode
* parent() const { return parent_
; }
78 FrameTreeNode
* child_at(size_t index
) const {
79 return children_
[index
];
82 const GURL
& current_url() const {
86 void set_current_url(const GURL
& url
) {
90 RenderFrameHostImpl
* current_frame_host() const {
91 return render_manager_
.current_frame_host();
95 void set_parent(FrameTreeNode
* parent
) { parent_
= parent
; }
97 // The next available browser-global FrameTreeNode ID.
98 static int64 next_frame_tree_node_id_
;
100 // The FrameTree that owns us.
101 FrameTree
* frame_tree_
; // not owned.
103 // The Navigator object responsible for managing navigations at this node
104 // of the frame tree.
105 scoped_refptr
<Navigator
> navigator_
;
107 // Manages creation and swapping of RenderFrameHosts for this frame. This
108 // must be declared before |children_| so that it gets deleted after them.
109 // That's currently necessary so that RenderFrameHostImpl's destructor can
111 RenderFrameHostManager render_manager_
;
113 // A browser-global identifier for the frame in the page, which stays stable
114 // even if the frame does a cross-process navigation.
115 const int64 frame_tree_node_id_
;
117 // The assigned name of the frame. This name can be empty, unlike the unique
118 // name generated internally in the DOM tree.
119 std::string frame_name_
;
121 // The parent node of this frame. NULL if this node is the root or if it has
122 // not yet been attached to the frame tree.
123 FrameTreeNode
* parent_
;
125 // The immediate children of this specific frame.
126 ScopedVector
<FrameTreeNode
> children_
;
128 // Track the current frame's last committed URL, so we can estimate the
129 // process impact of out-of-process iframes.
130 // TODO(creis): Remove this when we can store subframe URLs in the
131 // NavigationController.
134 DISALLOW_COPY_AND_ASSIGN(FrameTreeNode
);
137 } // namespace content
139 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_