Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: content/browser/frame_host/frame_tree_node.h

Issue 1086283002: Track frame openers in FrameTreeNodes instead of WebContents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address Charlie's comments Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_ 5 #ifndef CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_
6 #define CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_ 6 #define CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 13 matching lines...) Expand all
24 class NavigationRequest; 24 class NavigationRequest;
25 class Navigator; 25 class Navigator;
26 class RenderFrameHostImpl; 26 class RenderFrameHostImpl;
27 27
28 // When a page contains iframes, its renderer process maintains a tree structure 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 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 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). 31 // are frame-specific (as opposed to page-specific).
32 class CONTENT_EXPORT FrameTreeNode { 32 class CONTENT_EXPORT FrameTreeNode {
33 public: 33 public:
34 class Observer {
35 public:
36 // Invoked when a FrameTreeNode is being destroyed.
37 virtual void OnFrameTreeNodeDestroyed(FrameTreeNode* node) {}
38
39 virtual ~Observer() {}
40 };
41
34 // Returns the FrameTreeNode with the given global |frame_tree_node_id|, 42 // Returns the FrameTreeNode with the given global |frame_tree_node_id|,
35 // regardless of which FrameTree it is in. 43 // regardless of which FrameTree it is in.
36 static FrameTreeNode* GloballyFindByID(int frame_tree_node_id); 44 static FrameTreeNode* GloballyFindByID(int frame_tree_node_id);
37 45
38 FrameTreeNode(FrameTree* frame_tree, 46 FrameTreeNode(FrameTree* frame_tree,
39 Navigator* navigator, 47 Navigator* navigator,
40 RenderFrameHostDelegate* render_frame_delegate, 48 RenderFrameHostDelegate* render_frame_delegate,
41 RenderViewHostDelegate* render_view_delegate, 49 RenderViewHostDelegate* render_view_delegate,
42 RenderWidgetHostDelegate* render_widget_delegate, 50 RenderWidgetHostDelegate* render_widget_delegate,
43 RenderFrameHostManager::Delegate* manager_delegate, 51 RenderFrameHostManager::Delegate* manager_delegate,
44 blink::WebTreeScopeType scope, 52 blink::WebTreeScopeType scope,
45 const std::string& name, 53 const std::string& name,
46 blink::WebSandboxFlags sandbox_flags); 54 blink::WebSandboxFlags sandbox_flags);
47 55
48 ~FrameTreeNode(); 56 ~FrameTreeNode();
49 57
58 void AddObserver(Observer* observer);
59 void RemoveObserver(Observer* observer);
60
50 bool IsMainFrame() const; 61 bool IsMainFrame() const;
51 62
52 void AddChild(scoped_ptr<FrameTreeNode> child, 63 void AddChild(scoped_ptr<FrameTreeNode> child,
53 int process_id, 64 int process_id,
54 int frame_routing_id); 65 int frame_routing_id);
55 void RemoveChild(FrameTreeNode* child); 66 void RemoveChild(FrameTreeNode* child);
56 67
57 // Clears process specific-state in this node to prepare for a new process. 68 // Clears process specific-state in this node to prepare for a new process.
58 void ResetForNewProcess(); 69 void ResetForNewProcess();
59 70
(...skipping 16 matching lines...) Expand all
76 const std::string& frame_name() const { 87 const std::string& frame_name() const {
77 return replication_state_.name; 88 return replication_state_.name;
78 } 89 }
79 90
80 size_t child_count() const { 91 size_t child_count() const {
81 return children_.size(); 92 return children_.size();
82 } 93 }
83 94
84 FrameTreeNode* parent() const { return parent_; } 95 FrameTreeNode* parent() const { return parent_; }
85 96
97 FrameTreeNode* opener() const { return opener_; }
98
99 // Assigns a new opener for this node and, if |opener| is non-null, registers
100 // an observer that will clear this node's opener if |opener| is ever
101 // destroyed.
102 void SetOpener(FrameTreeNode* opener);
103
86 FrameTreeNode* child_at(size_t index) const { 104 FrameTreeNode* child_at(size_t index) const {
87 return children_[index]; 105 return children_[index];
88 } 106 }
89 107
90 const GURL& current_url() const { 108 const GURL& current_url() const {
91 return current_url_; 109 return current_url_;
92 } 110 }
93 111
94 void set_current_url(const GURL& url) { 112 void set_current_url(const GURL& url) {
95 current_url_ = url; 113 current_url_ = url;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 183
166 // A RenderFrameHost in this node stopped loading. 184 // A RenderFrameHost in this node stopped loading.
167 void DidStopLoading(); 185 void DidStopLoading();
168 186
169 // The load progress for a RenderFrameHost in this node was updated to 187 // The load progress for a RenderFrameHost in this node was updated to
170 // |load_progress|. This will notify the FrameTree which will in turn notify 188 // |load_progress|. This will notify the FrameTree which will in turn notify
171 // the WebContents. 189 // the WebContents.
172 void DidChangeLoadProgress(double load_progress); 190 void DidChangeLoadProgress(double load_progress);
173 191
174 private: 192 private:
193 class OpenerDestroyedObserver;
194
175 void set_parent(FrameTreeNode* parent) { parent_ = parent; } 195 void set_parent(FrameTreeNode* parent) { parent_ = parent; }
176 196
177 // The next available browser-global FrameTreeNode ID. 197 // The next available browser-global FrameTreeNode ID.
178 static int next_frame_tree_node_id_; 198 static int next_frame_tree_node_id_;
179 199
180 // The FrameTree that owns us. 200 // The FrameTree that owns us.
181 FrameTree* frame_tree_; // not owned. 201 FrameTree* frame_tree_; // not owned.
182 202
183 // The Navigator object responsible for managing navigations at this node 203 // The Navigator object responsible for managing navigations at this node
184 // of the frame tree. 204 // of the frame tree.
185 scoped_refptr<Navigator> navigator_; 205 scoped_refptr<Navigator> navigator_;
186 206
187 // Manages creation and swapping of RenderFrameHosts for this frame. This 207 // Manages creation and swapping of RenderFrameHosts for this frame. This
188 // must be declared before |children_| so that it gets deleted after them. 208 // must be declared before |children_| so that it gets deleted after them.
189 // That's currently necessary so that RenderFrameHostImpl's destructor can 209 // That's currently necessary so that RenderFrameHostImpl's destructor can
190 // call GetProcess. 210 // call GetProcess.
191 RenderFrameHostManager render_manager_; 211 RenderFrameHostManager render_manager_;
192 212
193 // A browser-global identifier for the frame in the page, which stays stable 213 // A browser-global identifier for the frame in the page, which stays stable
194 // even if the frame does a cross-process navigation. 214 // even if the frame does a cross-process navigation.
195 const int frame_tree_node_id_; 215 const int frame_tree_node_id_;
196 216
197 // The parent node of this frame. NULL if this node is the root or if it has 217 // The parent node of this frame. NULL if this node is the root or if it has
198 // not yet been attached to the frame tree. 218 // not yet been attached to the frame tree.
199 FrameTreeNode* parent_; 219 FrameTreeNode* parent_;
200 220
221 // The frame that opened this frame, if any. Will be set to null if the
222 // opener is closed, or if this frame disowns its opener by setting its
223 // window.opener to null.
224 FrameTreeNode* opener_;
225
226 // An observer that clears this node's |opener_| if the opener is destroyed.
227 // This observer is added to the |opener_|'s observer list when the |opener_|
228 // is set to a non-null node, and it is removed from that list when |opener_|
229 // changes or when this node is destroyed.
Charlie Reis 2015/06/09 04:38:38 Can you add something like this? It is also cleare
alexmos 2015/06/09 20:13:05 Done.
230 scoped_ptr<OpenerDestroyedObserver> opener_observer_;
231
201 // The immediate children of this specific frame. 232 // The immediate children of this specific frame.
202 ScopedVector<FrameTreeNode> children_; 233 ScopedVector<FrameTreeNode> children_;
203 234
204 // Track the current frame's last committed URL, so we can estimate the 235 // Track the current frame's last committed URL, so we can estimate the
205 // process impact of out-of-process iframes. 236 // process impact of out-of-process iframes.
206 // TODO(creis): Remove this when we can store subframe URLs in the 237 // TODO(creis): Remove this when we can store subframe URLs in the
207 // NavigationController. 238 // NavigationController.
208 GURL current_url_; 239 GURL current_url_;
209 240
210 // Track information that needs to be replicated to processes that have 241 // Track information that needs to be replicated to processes that have
(...skipping 11 matching lines...) Expand all
222 blink::WebSandboxFlags effective_sandbox_flags_; 253 blink::WebSandboxFlags effective_sandbox_flags_;
223 254
224 // Used to track this node's loading progress (from 0 to 1). 255 // Used to track this node's loading progress (from 0 to 1).
225 double loading_progress_; 256 double loading_progress_;
226 257
227 // PlzNavigate 258 // PlzNavigate
228 // Owns an ongoing NavigationRequest until it is ready to commit. It will then 259 // Owns an ongoing NavigationRequest until it is ready to commit. It will then
229 // be reset and a RenderFrameHost will be responsible for the navigation. 260 // be reset and a RenderFrameHost will be responsible for the navigation.
230 scoped_ptr<NavigationRequest> navigation_request_; 261 scoped_ptr<NavigationRequest> navigation_request_;
231 262
263 // List of objects observing this FrameTreeNode.
264 base::ObserverList<Observer> observers_;
265
232 DISALLOW_COPY_AND_ASSIGN(FrameTreeNode); 266 DISALLOW_COPY_AND_ASSIGN(FrameTreeNode);
233 }; 267 };
234 268
235 } // namespace content 269 } // namespace content
236 270
237 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_ 271 #endif // CONTENT_BROWSER_FRAME_HOST_FRAME_TREE_NODE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698