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"
17 #include "content/common/frame_replication_state.h"
19 #include "url/origin.h"
25 class RenderFrameHostImpl
;
27 // When a page contains iframes, its renderer process maintains a tree structure
28 // of those frames. We are mirroring this tree in the browser process. This
29 // class represents a node in this tree and is a wrapper for all objects that
30 // are frame-specific (as opposed to page-specific).
31 class CONTENT_EXPORT FrameTreeNode
{
34 FrameTreeNode(FrameTree
* frame_tree
,
36 RenderFrameHostDelegate
* render_frame_delegate
,
37 RenderViewHostDelegate
* render_view_delegate
,
38 RenderWidgetHostDelegate
* render_widget_delegate
,
39 RenderFrameHostManager::Delegate
* manager_delegate
,
40 const std::string
& name
);
44 bool IsMainFrame() const;
46 void AddChild(scoped_ptr
<FrameTreeNode
> child
,
48 int frame_routing_id
);
49 void RemoveChild(FrameTreeNode
* child
);
51 // Clears process specific-state in this node to prepare for a new process.
52 void ResetForNewProcess();
54 FrameTree
* frame_tree() const {
58 Navigator
* navigator() {
59 return navigator_
.get();
62 RenderFrameHostManager
* render_manager() {
63 return &render_manager_
;
66 int64
frame_tree_node_id() const {
67 return frame_tree_node_id_
;
70 const std::string
& frame_name() const {
71 return replication_state_
.name
;
74 size_t child_count() const {
75 return children_
.size();
78 FrameTreeNode
* parent() const { return parent_
; }
80 FrameTreeNode
* child_at(size_t index
) const {
81 return children_
[index
];
84 const GURL
& current_url() const {
88 void set_current_url(const GURL
& url
) {
92 void set_current_origin(const url::Origin
& origin
) {
93 replication_state_
.origin
= origin
;
96 void set_sandbox_flags(SandboxFlags sandbox_flags
) {
97 replication_state_
.sandbox_flags
= sandbox_flags
;
100 bool HasSameOrigin(const FrameTreeNode
& node
) const {
101 return replication_state_
.origin
.IsSameAs(node
.replication_state_
.origin
);
104 const FrameReplicationState
& current_replication_state() const {
105 return replication_state_
;
108 void set_is_loading(bool is_loading
) {
109 is_loading_
= is_loading
;
111 bool is_loading() const {
115 RenderFrameHostImpl
* current_frame_host() const {
116 return render_manager_
.current_frame_host();
119 bool IsDescendantOf(FrameTreeNode
* other
) const;
122 void set_parent(FrameTreeNode
* parent
) { parent_
= parent
; }
124 // The next available browser-global FrameTreeNode ID.
125 static int64 next_frame_tree_node_id_
;
127 // The FrameTree that owns us.
128 FrameTree
* frame_tree_
; // not owned.
130 // The Navigator object responsible for managing navigations at this node
131 // of the frame tree.
132 scoped_refptr
<Navigator
> navigator_
;
134 // Manages creation and swapping of RenderFrameHosts for this frame. This
135 // must be declared before |children_| so that it gets deleted after them.
136 // That's currently necessary so that RenderFrameHostImpl's destructor can
138 RenderFrameHostManager render_manager_
;
140 // A browser-global identifier for the frame in the page, which stays stable
141 // even if the frame does a cross-process navigation.
142 const int64 frame_tree_node_id_
;
144 // The parent node of this frame. NULL if this node is the root or if it has
145 // not yet been attached to the frame tree.
146 FrameTreeNode
* parent_
;
148 // The immediate children of this specific frame.
149 ScopedVector
<FrameTreeNode
> children_
;
151 // Track the current frame's last committed URL, so we can estimate the
152 // process impact of out-of-process iframes.
153 // TODO(creis): Remove this when we can store subframe URLs in the
154 // NavigationController.
157 // Track information that needs to be replicated to processes that have
158 // proxies for this frame.
159 FrameReplicationState replication_state_
;
161 // Boolean value indicating whether the frame is in the process of loading
162 // a document or not. In cross-process transfer navigation the DidStartLoading
163 // message is received from both existing RenderFrame and from the pending
164 // RenderFrame. However, there will be only one DidStopLoading message sent by
165 // the pending-which-becomes-current RenderFrame. Since both renderers belong
166 // to the FrameTreeNode, it is better to ask it about the loading status than
167 // RenderFrameHost or using a counter to balance the events out.
170 DISALLOW_COPY_AND_ASSIGN(FrameTreeNode
);
173 } // namespace content
175 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_