Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / content / browser / frame_host / frame_tree_node.h
blob7e1add1231f694ef0e37f29fb9f34bafd24ee55b
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 NavigationRequest;
25 class Navigator;
26 class RenderFrameHostImpl;
28 // When a page contains iframes, its renderer process maintains a tree structure
29 // of those frames. We are mirroring this tree in the browser process. This
30 // class represents a node in this tree and is a wrapper for all objects that
31 // are frame-specific (as opposed to page-specific).
32 class CONTENT_EXPORT FrameTreeNode {
33 public:
34 // Returns the FrameTreeNode with the given global |frame_tree_node_id|,
35 // regardless of which FrameTree it is in.
36 static FrameTreeNode* GloballyFindByID(int64 frame_tree_node_id);
38 FrameTreeNode(FrameTree* frame_tree,
39 Navigator* navigator,
40 RenderFrameHostDelegate* render_frame_delegate,
41 RenderViewHostDelegate* render_view_delegate,
42 RenderWidgetHostDelegate* render_widget_delegate,
43 RenderFrameHostManager::Delegate* manager_delegate,
44 const std::string& name);
46 ~FrameTreeNode();
48 bool IsMainFrame() const;
50 void AddChild(scoped_ptr<FrameTreeNode> child,
51 int process_id,
52 int frame_routing_id);
53 void RemoveChild(FrameTreeNode* child);
55 // Clears process specific-state in this node to prepare for a new process.
56 void ResetForNewProcess();
58 FrameTree* frame_tree() const {
59 return frame_tree_;
62 Navigator* navigator() {
63 return navigator_.get();
66 RenderFrameHostManager* render_manager() {
67 return &render_manager_;
70 int64 frame_tree_node_id() const {
71 return frame_tree_node_id_;
74 const std::string& frame_name() const {
75 return replication_state_.name;
78 size_t child_count() const {
79 return children_.size();
82 FrameTreeNode* parent() const { return parent_; }
84 FrameTreeNode* child_at(size_t index) const {
85 return children_[index];
88 const GURL& current_url() const {
89 return current_url_;
92 void set_current_url(const GURL& url) {
93 current_url_ = url;
96 void set_current_origin(const url::Origin& origin) {
97 replication_state_.origin = origin;
100 void SetFrameName(const std::string& name);
102 SandboxFlags effective_sandbox_flags() { return effective_sandbox_flags_; }
104 void set_sandbox_flags(SandboxFlags sandbox_flags) {
105 replication_state_.sandbox_flags = sandbox_flags;
108 // Transfer any pending sandbox flags into |effective_sandbox_flags_|, and
109 // return true if the sandbox flags were changed.
110 bool CommitPendingSandboxFlags();
112 bool HasSameOrigin(const FrameTreeNode& node) const {
113 return replication_state_.origin.IsSameAs(node.replication_state_.origin);
116 const FrameReplicationState& current_replication_state() const {
117 return replication_state_;
120 RenderFrameHostImpl* current_frame_host() const {
121 return render_manager_.current_frame_host();
124 bool IsDescendantOf(FrameTreeNode* other) const;
126 // Returns true if this node is in a loading state.
127 bool IsLoading() const;
129 // Returns this node's loading progress.
130 double loading_progress() const { return loading_progress_; }
132 NavigationRequest* navigation_request() { return navigation_request_.get(); }
134 // PlzNavigate
135 // Takes ownership of |navigation_request| and makes it the current
136 // NavigationRequest of this frame. This corresponds to the start of a new
137 // navigation. If there was an ongoing navigation request before calling this
138 // function, it is canceled. |navigation_request| should not be null.
139 void SetNavigationRequest(scoped_ptr<NavigationRequest> navigation_request);
141 // PlzNavigate
142 // Resets the current navigation request. |is_commit| is true if the reset is
143 // due to the commit of the navigation.
144 void ResetNavigationRequest(bool is_commit);
146 // Returns true if this node is in a state where the loading progress is being
147 // tracked.
148 bool has_started_loading() const;
150 // Resets this node's loading progress.
151 void reset_loading_progress();
153 // A RenderFrameHost in this node started loading.
154 // |to_different_document| will be true unless the load is a fragment
155 // navigation, or triggered by history.pushState/replaceState.
156 void DidStartLoading(bool to_different_document);
158 // A RenderFrameHost in this node stopped loading.
159 void DidStopLoading();
161 // The load progress for a RenderFrameHost in this node was updated to
162 // |load_progress|. This will notify the FrameTree which will in turn notify
163 // the WebContents.
164 void DidChangeLoadProgress(double load_progress);
166 private:
167 void set_parent(FrameTreeNode* parent) { parent_ = parent; }
169 // The next available browser-global FrameTreeNode ID.
170 static int64 next_frame_tree_node_id_;
172 // The FrameTree that owns us.
173 FrameTree* frame_tree_; // not owned.
175 // The Navigator object responsible for managing navigations at this node
176 // of the frame tree.
177 scoped_refptr<Navigator> navigator_;
179 // Manages creation and swapping of RenderFrameHosts for this frame. This
180 // must be declared before |children_| so that it gets deleted after them.
181 // That's currently necessary so that RenderFrameHostImpl's destructor can
182 // call GetProcess.
183 RenderFrameHostManager render_manager_;
185 // A browser-global identifier for the frame in the page, which stays stable
186 // even if the frame does a cross-process navigation.
187 const int64 frame_tree_node_id_;
189 // The parent node of this frame. NULL if this node is the root or if it has
190 // not yet been attached to the frame tree.
191 FrameTreeNode* parent_;
193 // The immediate children of this specific frame.
194 ScopedVector<FrameTreeNode> children_;
196 // Track the current frame's last committed URL, so we can estimate the
197 // process impact of out-of-process iframes.
198 // TODO(creis): Remove this when we can store subframe URLs in the
199 // NavigationController.
200 GURL current_url_;
202 // Track information that needs to be replicated to processes that have
203 // proxies for this frame.
204 FrameReplicationState replication_state_;
206 // Track the effective sandbox flags for this frame. When a parent frame
207 // dynamically updates sandbox flags for a child frame, the child's updated
208 // sandbox flags are stored in replication_state_.sandbox_flags. However, the
209 // update only takes effect on the next frame navigation, so the effective
210 // sandbox flags are tracked separately here. When enforcing sandbox flags
211 // directives in the browser process, |effective_sandbox_flags_| should be
212 // used. |effective_sandbox_flags_| is updated with any pending sandbox
213 // flags when a navigation for this frame commits.
214 SandboxFlags effective_sandbox_flags_;
216 // Used to track this node's loading progress (from 0 to 1).
217 double loading_progress_;
219 // PlzNavigate
220 // Owns an ongoing NavigationRequest until it is ready to commit. It will then
221 // be reset and a RenderFrameHost will be responsible for the navigation.
222 scoped_ptr<NavigationRequest> navigation_request_;
224 DISALLOW_COPY_AND_ASSIGN(FrameTreeNode);
227 } // namespace content
229 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_