Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / browser / frame_host / frame_tree_node.h
blob30843d8f2723c8663f30370e980322f67fa3724d
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_
8 #include <string>
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"
18 #include "url/gurl.h"
19 #include "url/origin.h"
21 namespace content {
23 class FrameTree;
24 class Navigator;
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 {
32 public:
33 // These values indicate the loading progress status. The minimum progress
34 // value matches what Blink's ProgressTracker has traditionally used for a
35 // minimum progress value.
36 // TODO(fdegans): Move these values to the implementation when the relevant
37 // IPCs are moved from WebContentsImpl to RenderFrameHost.
38 static const double kLoadingProgressNotStarted;
39 static const double kLoadingProgressMinimum;
40 static const double kLoadingProgressDone;
42 // Returns the FrameTreeNode with the given global |frame_tree_node_id|,
43 // regardless of which FrameTree it is in.
44 static FrameTreeNode* GloballyFindByID(int64 frame_tree_node_id);
46 FrameTreeNode(FrameTree* frame_tree,
47 Navigator* navigator,
48 RenderFrameHostDelegate* render_frame_delegate,
49 RenderViewHostDelegate* render_view_delegate,
50 RenderWidgetHostDelegate* render_widget_delegate,
51 RenderFrameHostManager::Delegate* manager_delegate,
52 const std::string& name);
54 ~FrameTreeNode();
56 bool IsMainFrame() const;
58 void AddChild(scoped_ptr<FrameTreeNode> child,
59 int process_id,
60 int frame_routing_id);
61 void RemoveChild(FrameTreeNode* child);
63 // Clears process specific-state in this node to prepare for a new process.
64 void ResetForNewProcess();
66 FrameTree* frame_tree() const {
67 return frame_tree_;
70 Navigator* navigator() {
71 return navigator_.get();
74 RenderFrameHostManager* render_manager() {
75 return &render_manager_;
78 int64 frame_tree_node_id() const {
79 return frame_tree_node_id_;
82 const std::string& frame_name() const {
83 return replication_state_.name;
86 size_t child_count() const {
87 return children_.size();
90 FrameTreeNode* parent() const { return parent_; }
92 FrameTreeNode* child_at(size_t index) const {
93 return children_[index];
96 const GURL& current_url() const {
97 return current_url_;
100 void set_current_url(const GURL& url) {
101 current_url_ = url;
104 void set_current_origin(const url::Origin& origin) {
105 replication_state_.origin = origin;
108 void SetFrameName(const std::string& name);
110 SandboxFlags effective_sandbox_flags() { return effective_sandbox_flags_; }
112 void set_sandbox_flags(SandboxFlags sandbox_flags) {
113 replication_state_.sandbox_flags = sandbox_flags;
116 // Transfer any pending sandbox flags into |effective_sandbox_flags_|, and
117 // return true if the sandbox flags were changed.
118 bool CommitPendingSandboxFlags();
120 bool HasSameOrigin(const FrameTreeNode& node) const {
121 return replication_state_.origin.IsSameAs(node.replication_state_.origin);
124 const FrameReplicationState& current_replication_state() const {
125 return replication_state_;
128 RenderFrameHostImpl* current_frame_host() const {
129 return render_manager_.current_frame_host();
132 bool IsDescendantOf(FrameTreeNode* other) const;
134 // Returns true if this node is in a loading state.
135 bool IsLoading() const;
137 // Sets this node's loading progress (from 0 to 1).
138 void set_loading_progress(double loading_progress) {
139 loading_progress_ = loading_progress;
142 // Returns this node's loading progress.
143 double loading_progress() const { return loading_progress_; }
145 private:
146 void set_parent(FrameTreeNode* parent) { parent_ = parent; }
148 // The next available browser-global FrameTreeNode ID.
149 static int64 next_frame_tree_node_id_;
151 // The FrameTree that owns us.
152 FrameTree* frame_tree_; // not owned.
154 // The Navigator object responsible for managing navigations at this node
155 // of the frame tree.
156 scoped_refptr<Navigator> navigator_;
158 // Manages creation and swapping of RenderFrameHosts for this frame. This
159 // must be declared before |children_| so that it gets deleted after them.
160 // That's currently necessary so that RenderFrameHostImpl's destructor can
161 // call GetProcess.
162 RenderFrameHostManager render_manager_;
164 // A browser-global identifier for the frame in the page, which stays stable
165 // even if the frame does a cross-process navigation.
166 const int64 frame_tree_node_id_;
168 // The parent node of this frame. NULL if this node is the root or if it has
169 // not yet been attached to the frame tree.
170 FrameTreeNode* parent_;
172 // The immediate children of this specific frame.
173 ScopedVector<FrameTreeNode> children_;
175 // Track the current frame's last committed URL, so we can estimate the
176 // process impact of out-of-process iframes.
177 // TODO(creis): Remove this when we can store subframe URLs in the
178 // NavigationController.
179 GURL current_url_;
181 // Track information that needs to be replicated to processes that have
182 // proxies for this frame.
183 FrameReplicationState replication_state_;
185 // Track the effective sandbox flags for this frame. When a parent frame
186 // dynamically updates sandbox flags for a child frame, the child's updated
187 // sandbox flags are stored in replication_state_.sandbox_flags. However, the
188 // update only takes effect on the next frame navigation, so the effective
189 // sandbox flags are tracked separately here. When enforcing sandbox flags
190 // directives in the browser process, |effective_sandbox_flags_| should be
191 // used. |effective_sandbox_flags_| is updated with any pending sandbox
192 // flags when a navigation for this frame commits.
193 SandboxFlags effective_sandbox_flags_;
195 // Used to track this node's loading progress (from 0 to 1).
196 double loading_progress_;
198 DISALLOW_COPY_AND_ASSIGN(FrameTreeNode);
201 } // namespace content
203 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_