blob: 236ab137f382384c8ae71078d8daa04cdc6f7b50 [file] [log] [blame]
danakjc492bf82020-09-09 20:02:441// 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.
4
5#ifndef CONTENT_BROWSER_RENDERER_HOST_FRAME_TREE_NODE_H_
6#define CONTENT_BROWSER_RENDERER_HOST_FRAME_TREE_NODE_H_
7
8#include <stddef.h>
9
10#include <memory>
11#include <string>
12#include <vector>
13
14#include "base/gtest_prod_util.h"
15#include "base/macros.h"
16#include "base/memory/ref_counted.h"
17#include "content/browser/renderer_host/frame_tree.h"
18#include "content/browser/renderer_host/frame_tree_node_blame_context.h"
19#include "content/browser/renderer_host/navigator.h"
20#include "content/browser/renderer_host/render_frame_host_impl.h"
21#include "content/browser/renderer_host/render_frame_host_manager.h"
22#include "content/common/content_export.h"
danakjc492bf82020-09-09 20:02:4423#include "services/network/public/mojom/content_security_policy.mojom-forward.h"
24#include "third_party/blink/public/common/frame/frame_policy.h"
25#include "third_party/blink/public/common/frame/user_activation_state.h"
26#include "third_party/blink/public/mojom/frame/frame_owner_element_type.mojom.h"
27#include "third_party/blink/public/mojom/frame/frame_owner_properties.mojom.h"
Gyuyoung Kimc16e52e92021-03-19 02:45:3728#include "third_party/blink/public/mojom/frame/frame_replication_state.mojom-forward.h"
danakjc492bf82020-09-09 20:02:4429#include "third_party/blink/public/mojom/frame/user_activation_update_types.mojom.h"
30#include "third_party/blink/public/mojom/security_context/insecure_request_policy.mojom-forward.h"
31
32#include "url/gurl.h"
33#include "url/origin.h"
34
35namespace content {
36
37class NavigationRequest;
38class RenderFrameHostImpl;
39class NavigationEntryImpl;
40
41// When a page contains iframes, its renderer process maintains a tree structure
42// of those frames. We are mirroring this tree in the browser process. This
43// class represents a node in this tree and is a wrapper for all objects that
44// are frame-specific (as opposed to page-specific).
45//
46// Each FrameTreeNode has a current RenderFrameHost, which can change over
47// time as the frame is navigated. Any immediate subframes of the current
48// document are tracked using FrameTreeNodes owned by the current
49// RenderFrameHost, rather than as children of FrameTreeNode itself. This
50// allows subframe FrameTreeNodes to stay alive while a RenderFrameHost is
51// still alive - for example while pending deletion, after a new current
52// RenderFrameHost has replaced it.
53class CONTENT_EXPORT FrameTreeNode {
54 public:
55 class Observer {
56 public:
57 // Invoked when a FrameTreeNode is being destroyed.
58 virtual void OnFrameTreeNodeDestroyed(FrameTreeNode* node) {}
59
60 // Invoked when a FrameTreeNode becomes focused.
61 virtual void OnFrameTreeNodeFocused(FrameTreeNode* node) {}
62
Fergal Dalya1d569972021-03-16 03:24:5363 virtual ~Observer() = default;
danakjc492bf82020-09-09 20:02:4464 };
65
66 static const int kFrameTreeNodeInvalidId;
67
68 // Returns the FrameTreeNode with the given global |frame_tree_node_id|,
69 // regardless of which FrameTree it is in.
70 static FrameTreeNode* GloballyFindByID(int frame_tree_node_id);
71
72 // Returns the FrameTreeNode for the given |rfh|. Same as
73 // rfh->frame_tree_node(), but also supports nullptrs.
74 static FrameTreeNode* From(RenderFrameHost* rfh);
75
76 // Callers are are expected to initialize sandbox flags separately after
77 // calling the constructor.
78 FrameTreeNode(
79 FrameTree* frame_tree,
80 RenderFrameHostImpl* parent,
81 blink::mojom::TreeScopeType scope,
82 const std::string& name,
83 const std::string& unique_name,
84 bool is_created_by_script,
85 const base::UnguessableToken& devtools_frame_token,
86 const blink::mojom::FrameOwnerProperties& frame_owner_properties,
87 blink::mojom::FrameOwnerElementType owner_type);
88
89 ~FrameTreeNode();
90
91 void AddObserver(Observer* observer);
92 void RemoveObserver(Observer* observer);
93
94 bool IsMainFrame() const;
95
arthursonzogni76098e52020-11-25 14:18:4596 // Clears any state in this node which was set by the document itself (CSP &
97 // UserActivationState) and notifies proxies as appropriate. Invoked after
98 // committing navigation to a new document (since the new document comes with
99 // a fresh set of CSP).
100 // TODO(arthursonzogni): Remove this function. The frame/document must not be
101 // left temporarily with lax state.
Hiroki Nakagawaab309622021-05-19 16:38:13102 void ResetForNavigation();
danakjc492bf82020-09-09 20:02:44103
104 FrameTree* frame_tree() const { return frame_tree_; }
105 Navigator& navigator() { return frame_tree()->navigator(); }
106
107 RenderFrameHostManager* render_manager() { return &render_manager_; }
108 int frame_tree_node_id() const { return frame_tree_node_id_; }
Antonio Sartori90f41212021-01-22 10:08:34109 const std::string& frame_name() const { return replication_state_->name; }
danakjc492bf82020-09-09 20:02:44110
111 const std::string& unique_name() const {
Antonio Sartori90f41212021-01-22 10:08:34112 return replication_state_->unique_name;
danakjc492bf82020-09-09 20:02:44113 }
114
115 // See comment on the member declaration.
116 const base::UnguessableToken& devtools_frame_token() const {
117 return devtools_frame_token_;
118 }
119
120 size_t child_count() const { return current_frame_host()->child_count(); }
121
122 unsigned int depth() const { return depth_; }
123
124 RenderFrameHostImpl* parent() const { return parent_; }
125
126 FrameTreeNode* opener() const { return opener_; }
127
128 FrameTreeNode* original_opener() const { return original_opener_; }
129
Anton Bikineevf62d1bf2021-05-15 17:56:07130 const absl::optional<base::UnguessableToken>& opener_devtools_frame_token() {
Wolfgang Beyerd8809db2020-09-30 15:29:39131 return opener_devtools_frame_token_;
132 }
133
danakjc492bf82020-09-09 20:02:44134 // Gets the total number of descendants to this FrameTreeNode in addition to
135 // this node.
136 size_t GetFrameTreeSize() const;
137
138 // Assigns a new opener for this node and, if |opener| is non-null, registers
139 // an observer that will clear this node's opener if |opener| is ever
140 // destroyed.
141 void SetOpener(FrameTreeNode* opener);
142
143 // Assigns the initial opener for this node, and if |opener| is non-null,
144 // registers an observer that will clear this node's opener if |opener| is
145 // ever destroyed. The value set here is the root of the tree.
146 //
147 // It is not possible to change the opener once it was set.
148 void SetOriginalOpener(FrameTreeNode* opener);
149
Wolfgang Beyerd8809db2020-09-30 15:29:39150 // Assigns an opener frame id for this node. This string id is only set once
151 // and cannot be changed. It persists, even if the |opener| is destroyed. It
152 // is used for attribution in the DevTools frontend.
153 void SetOpenerDevtoolsFrameToken(
154 base::UnguessableToken opener_devtools_frame_token);
155
danakjc492bf82020-09-09 20:02:44156 FrameTreeNode* child_at(size_t index) const {
157 return current_frame_host()->child_at(index);
158 }
159
160 // Returns the URL of the last committed page in the current frame.
161 const GURL& current_url() const {
162 return current_frame_host()->GetLastCommittedURL();
163 }
164
165 // Sets the last committed URL for this frame and updates
166 // has_committed_real_load accordingly.
167 void SetCurrentURL(const GURL& url);
168
169 // Returns true iff SetCurrentURL has been called with a non-blank URL.
170 bool has_committed_real_load() const { return has_committed_real_load_; }
171
172 // Returns whether the frame's owner element in the parent document is
173 // collapsed, that is, removed from the layout as if it did not exist, as per
174 // request by the embedder (of the content/ layer).
175 bool is_collapsed() const { return is_collapsed_; }
176
177 // Sets whether to collapse the frame's owner element in the parent document,
178 // that is, to remove it from the layout as if it did not exist, as per
179 // request by the embedder (of the content/ layer). Cannot be called for main
180 // frames.
181 //
182 // This only has an effect for <iframe> owner elements, and is a no-op when
183 // called on sub-frames hosted in <frame>, <object>, and <embed> elements.
184 void SetCollapsed(bool collapsed);
185
186 // Returns the origin of the last committed page in this frame.
187 // WARNING: To get the last committed origin for a particular
188 // RenderFrameHost, use RenderFrameHost::GetLastCommittedOrigin() instead,
189 // which will behave correctly even when the RenderFrameHost is not the
190 // current one for this frame (such as when it's pending deletion).
191 const url::Origin& current_origin() const {
Antonio Sartori90f41212021-01-22 10:08:34192 return replication_state_->origin;
danakjc492bf82020-09-09 20:02:44193 }
194
195 // Set the current origin and notify proxies about the update.
196 void SetCurrentOrigin(const url::Origin& origin,
197 bool is_potentially_trustworthy_unique_origin);
198
199 // Set the current name and notify proxies about the update.
200 void SetFrameName(const std::string& name, const std::string& unique_name);
201
danakjc492bf82020-09-09 20:02:44202 // Sets the current insecure request policy, and notifies proxies about the
203 // update.
204 void SetInsecureRequestPolicy(blink::mojom::InsecureRequestPolicy policy);
205
206 // Sets the current set of insecure urls to upgrade, and notifies proxies
207 // about the update.
208 void SetInsecureNavigationsSet(
209 const std::vector<uint32_t>& insecure_navigations_set);
210
211 // Returns the latest frame policy (sandbox flags and container policy) for
212 // this frame. This includes flags inherited from parent frames and the latest
213 // flags from the <iframe> element hosting this frame. The returned policies
214 // may not yet have taken effect, since "sandbox" and "allow" attribute
215 // updates in an <iframe> element take effect on next navigation. To retrieve
216 // the currently active policy for this frame, use effective_frame_policy().
217 const blink::FramePolicy& pending_frame_policy() const {
218 return pending_frame_policy_;
219 }
220
221 // Update this frame's sandbox flags and container policy. This is called
222 // when a parent frame updates the "sandbox" attribute in the <iframe> element
223 // for this frame, or any of the attributes which affect the container policy
224 // ("allowfullscreen", "allowpaymentrequest", "allow", and "src".)
225 // These policies won't take effect until next navigation. If this frame's
226 // parent is itself sandboxed, the parent's sandbox flags are combined with
227 // those in |frame_policy|.
228 // Attempting to change the container policy on the main frame will have no
229 // effect.
230 void SetPendingFramePolicy(blink::FramePolicy frame_policy);
231
232 // Returns the currently active frame policy for this frame, including the
233 // sandbox flags which were present at the time the document was loaded, and
Charlie Hu5130d25e2021-03-05 21:53:39234 // the permissions policy container policy, which is set by the iframe's
danakjc492bf82020-09-09 20:02:44235 // allowfullscreen, allowpaymentrequest, and allow attributes, along with the
236 // origin of the iframe's src attribute (which may be different from the URL
237 // of the document currently loaded into the frame). This does not include
238 // policy changes that have been made by updating the containing iframe
239 // element attributes since the frame was last navigated; use
240 // pending_frame_policy() for those.
241 const blink::FramePolicy& effective_frame_policy() const {
Antonio Sartori90f41212021-01-22 10:08:34242 return replication_state_->frame_policy;
danakjc492bf82020-09-09 20:02:44243 }
244
245 // Set the frame_policy provided in function parameter as active frame policy,
246 // while leaving pending_frame_policy_ untouched.
247 bool CommitFramePolicy(const blink::FramePolicy& frame_policy);
248
249 const blink::mojom::FrameOwnerProperties& frame_owner_properties() {
250 return frame_owner_properties_;
251 }
252
253 void set_frame_owner_properties(
254 const blink::mojom::FrameOwnerProperties& frame_owner_properties) {
255 frame_owner_properties_ = frame_owner_properties;
256 }
257
258 const network::mojom::ContentSecurityPolicy* csp_attribute() {
259 return csp_attribute_.get();
260 }
261
262 void set_csp_attribute(
263 network::mojom::ContentSecurityPolicyPtr parsed_csp_attribute) {
264 csp_attribute_ = std::move(parsed_csp_attribute);
265 }
266
267 bool HasSameOrigin(const FrameTreeNode& node) const {
Antonio Sartori90f41212021-01-22 10:08:34268 return replication_state_->origin.IsSameOriginWith(
269 node.replication_state_->origin);
danakjc492bf82020-09-09 20:02:44270 }
271
Gyuyoung Kimc16e52e92021-03-19 02:45:37272 const blink::mojom::FrameReplicationState& current_replication_state() const {
Antonio Sartori90f41212021-01-22 10:08:34273 return *replication_state_;
danakjc492bf82020-09-09 20:02:44274 }
275
276 RenderFrameHostImpl* current_frame_host() const {
277 return render_manager_.current_frame_host();
278 }
279
280 // Return the node immediately preceding this node in its parent's children,
281 // or nullptr if there is no such node.
282 FrameTreeNode* PreviousSibling() const;
283
284 // Return the node immediately following this node in its parent's children,
285 // or nullptr if there is no such node.
286 FrameTreeNode* NextSibling() const;
287
288 // Returns true if this node is in a loading state.
289 bool IsLoading() const;
290
Alex Moshchuk9b0fd822020-10-26 23:08:15291 // Returns true if this node has a cross-document navigation in progress.
292 bool HasPendingCrossDocumentNavigation() const;
293
danakjc492bf82020-09-09 20:02:44294 NavigationRequest* navigation_request() { return navigation_request_.get(); }
295
296 // Transfers the ownership of the NavigationRequest to |render_frame_host|.
297 // From ReadyToCommit to DidCommit, the NavigationRequest is owned by the
298 // RenderFrameHost that is committing the navigation.
299 void TransferNavigationRequestOwnership(
300 RenderFrameHostImpl* render_frame_host);
301
302 // Takes ownership of |navigation_request| and makes it the current
303 // NavigationRequest of this frame. This corresponds to the start of a new
304 // navigation. If there was an ongoing navigation request before calling this
305 // function, it is canceled. |navigation_request| should not be null.
306 void CreatedNavigationRequest(
307 std::unique_ptr<NavigationRequest> navigation_request);
308
309 // Resets the current navigation request. If |keep_state| is true, any state
310 // created by the NavigationRequest (e.g. speculative RenderFrameHost,
311 // loading state) will not be reset by the function.
312 void ResetNavigationRequest(bool keep_state);
313
314 // A RenderFrameHost in this node started loading.
315 // |to_different_document| will be true unless the load is a fragment
316 // navigation, or triggered by history.pushState/replaceState.
317 // |was_previously_loading| is false if the FrameTree was not loading before.
318 // The caller is required to provide this boolean as the delegate should only
319 // be notified if the FrameTree went from non-loading to loading state.
320 // However, when it is called, the FrameTree should be in a loading state.
321 void DidStartLoading(bool to_different_document, bool was_previously_loading);
322
323 // A RenderFrameHost in this node stopped loading.
324 void DidStopLoading();
325
326 // The load progress for a RenderFrameHost in this node was updated to
327 // |load_progress|. This will notify the FrameTree which will in turn notify
328 // the WebContents.
329 void DidChangeLoadProgress(double load_progress);
330
331 // Called when the user directed the page to stop loading. Stops all loads
332 // happening in the FrameTreeNode. This method should be used with
333 // FrameTree::ForEach to stop all loads in the entire FrameTree.
334 bool StopLoading();
335
336 // Returns the time this frame was last focused.
337 base::TimeTicks last_focus_time() const { return last_focus_time_; }
338
339 // Called when this node becomes focused. Updates the node's last focused
340 // time and notifies observers.
341 void DidFocus();
342
343 // Called when the user closed the modal dialogue for BeforeUnload and
344 // cancelled the navigation. This should stop any load happening in the
345 // FrameTreeNode.
346 void BeforeUnloadCanceled();
347
348 // Returns the BlameContext associated with this node.
349 FrameTreeNodeBlameContext& blame_context() { return blame_context_; }
350
351 // Updates the user activation state in the browser frame tree and in the
352 // frame trees in all renderer processes except the renderer for this node
353 // (which initiated the update). Returns |false| if the update tries to
354 // consume an already consumed/expired transient state, |true| otherwise. See
355 // the comment on user_activation_state_ below.
356 //
357 // The |notification_type| parameter is used for histograms, only for the case
358 // |update_state == kNotifyActivation|.
359 bool UpdateUserActivationState(
360 blink::mojom::UserActivationUpdateType update_type,
361 blink::mojom::UserActivationNotificationType notification_type);
362
363 void OnSetHadStickyUserActivationBeforeNavigation(bool value);
364
365 // Returns the sandbox flags currently in effect for this frame. This includes
366 // flags inherited from parent frames, the currently active flags from the
367 // <iframe> element hosting this frame, as well as any flags set from a
368 // Content-Security-Policy HTTP header. This does not include flags that have
369 // have been updated in an <iframe> element but have not taken effect yet; use
370 // pending_frame_policy() for those. To see the flags which will take effect
371 // on navigation (which does not include the CSP-set flags), use
372 // effective_frame_policy().
373 network::mojom::WebSandboxFlags active_sandbox_flags() const {
Antonio Sartori90f41212021-01-22 10:08:34374 return replication_state_->active_sandbox_flags;
danakjc492bf82020-09-09 20:02:44375 }
376
377 // Updates the active sandbox flags in this frame, in response to a
378 // Content-Security-Policy header adding additional flags, in addition to
379 // those given to this frame by its parent, or in response to the
Charlie Hu5130d25e2021-03-05 21:53:39380 // Permissions-Policy header being set. Note that on navigation, these updates
danakjc492bf82020-09-09 20:02:44381 // will be cleared, and the flags in the pending frame policy will be applied
382 // to the frame.
Alexander Timin45b716c2020-11-06 01:40:31383 // Returns true iff this operation has changed state of either sandbox flags
Charlie Hu5130d25e2021-03-05 21:53:39384 // or permissions policy.
Alexander Timin45b716c2020-11-06 01:40:31385 bool UpdateFramePolicyHeaders(
danakjc492bf82020-09-09 20:02:44386 network::mojom::WebSandboxFlags sandbox_flags,
Charlie Hue24f04832021-03-04 21:07:06387 const blink::ParsedPermissionsPolicy& parsed_header);
danakjc492bf82020-09-09 20:02:44388
389 // Returns whether the frame received a user gesture on a previous navigation
390 // on the same eTLD+1.
391 bool has_received_user_gesture_before_nav() const {
Antonio Sartori90f41212021-01-22 10:08:34392 return replication_state_->has_received_user_gesture_before_nav;
danakjc492bf82020-09-09 20:02:44393 }
394
395 // When a tab is discarded, WebContents sets was_discarded on its
396 // root FrameTreeNode.
397 // In addition, when a child frame is created, this bit is passed on from
398 // parent to child.
399 // When a navigation request is created, was_discarded is passed on to the
400 // request and reset to false in FrameTreeNode.
401 void set_was_discarded() { was_discarded_ = true; }
402 bool was_discarded() const { return was_discarded_; }
403
404 // Returns the sticky bit of the User Activation v2 state of the
405 // |FrameTreeNode|.
406 bool HasStickyUserActivation() const {
407 return user_activation_state_.HasBeenActive();
408 }
409
410 // Returns the transient bit of the User Activation v2 state of the
411 // |FrameTreeNode|.
412 bool HasTransientUserActivation() {
413 return user_activation_state_.IsActive();
414 }
415
416 // Remove history entries for all frames created by script in this frame's
417 // subtree. If a frame created by a script is removed, then its history entry
418 // will never be reused - this saves memory.
419 void PruneChildFrameNavigationEntries(NavigationEntryImpl* entry);
420
421 blink::mojom::FrameOwnerElementType frame_owner_element_type() const {
Daniel Cheng9bd90f92021-04-23 20:49:45422 return frame_owner_element_type_;
danakjc492bf82020-09-09 20:02:44423 }
danakjc492bf82020-09-09 20:02:44424
425 void SetAdFrameType(blink::mojom::AdFrameType ad_frame_type);
426
arthursonzogni034bb9c2020-10-01 08:29:56427 // The initial popup URL for new window opened using:
428 // `window.open(initial_popup_url)`.
429 // An empty GURL otherwise.
430 //
431 // [WARNING] There is no guarantee the FrameTreeNode will ever host a
432 // document served from this URL. The FrameTreeNode always starts hosting the
433 // initial empty document and attempts a navigation toward this URL. However
434 // the navigation might be delayed, redirected and even cancelled.
435 void SetInitialPopupURL(const GURL& initial_popup_url);
436 const GURL& initial_popup_url() const { return initial_popup_url_; }
437
438 // The origin of the document that used window.open() to create this frame.
439 // Otherwise, an opaque Origin with a nonce different from all previously
440 // existing Origins.
441 void SetPopupCreatorOrigin(const url::Origin& popup_creator_origin);
442 const url::Origin& popup_creator_origin() const {
443 return popup_creator_origin_;
444 }
445
Harkiran Bolaria59290d62021-03-17 01:53:01446 // Sets the associated FrameTree for this node. The node can change FrameTrees
447 // when blink::features::Prerender2 is enabled, which allows a page loaded in
448 // the prerendered FrameTree to be used for a navigation in the primary frame
449 // tree.
450 void SetFrameTree(FrameTree& frame_tree);
451
Alexander Timinf785f342021-03-18 00:00:56452 // Write a representation of this object into a trace.
Alexander Timinbebb2002021-04-20 15:42:24453 void WriteIntoTrace(perfetto::TracedValue context) const;
Alexander Timinf785f342021-03-18 00:00:56454
Carlos Caballero76711352021-03-24 17:38:21455 // Returns true the node is navigating, i.e. it has an associated
456 // NavigationRequest.
457 bool HasNavigation();
458
danakjc492bf82020-09-09 20:02:44459 private:
Charlie Hubb5943d2021-03-09 19:46:12460 FRIEND_TEST_ALL_PREFIXES(SitePerProcessPermissionsPolicyBrowserTest,
danakjc492bf82020-09-09 20:02:44461 ContainerPolicyDynamic);
Charlie Hubb5943d2021-03-09 19:46:12462 FRIEND_TEST_ALL_PREFIXES(SitePerProcessPermissionsPolicyBrowserTest,
danakjc492bf82020-09-09 20:02:44463 ContainerPolicySandboxDynamic);
464
465 class OpenerDestroyedObserver;
466
467 FrameTreeNode* GetSibling(int relative_offset) const;
468
469 // The |notification_type| parameter is used for histograms only.
470 bool NotifyUserActivation(
471 blink::mojom::UserActivationNotificationType notification_type);
472
473 bool ConsumeTransientUserActivation();
474
475 bool ClearUserActivation();
476
477 // Verify that the renderer process is allowed to set user activation on this
478 // frame by checking whether this frame's RenderWidgetHost had previously seen
479 // an input event that might lead to user activation. If user activation
480 // should be allowed, this returns true and also clears corresponding pending
481 // user activation state in the widget. Otherwise, this returns false.
482 bool VerifyUserActivation();
483
484 // The next available browser-global FrameTreeNode ID.
485 static int next_frame_tree_node_id_;
486
487 // The FrameTree that owns us.
488 FrameTree* frame_tree_; // not owned.
489
danakjc492bf82020-09-09 20:02:44490 // A browser-global identifier for the frame in the page, which stays stable
491 // even if the frame does a cross-process navigation.
492 const int frame_tree_node_id_;
493
494 // The RenderFrameHost owning this FrameTreeNode, which cannot change for the
495 // life of this FrameTreeNode. |nullptr| if this node is the root.
496 RenderFrameHostImpl* const parent_;
497
498 // Number of edges from this node to the root. 0 if this is the root.
499 const unsigned int depth_;
500
501 // The frame that opened this frame, if any. Will be set to null if the
502 // opener is closed, or if this frame disowns its opener by setting its
503 // window.opener to null.
arthursonzogni9816b9192021-03-29 16:09:19504 FrameTreeNode* opener_ = nullptr;
danakjc492bf82020-09-09 20:02:44505
506 // An observer that clears this node's |opener_| if the opener is destroyed.
507 // This observer is added to the |opener_|'s observer list when the |opener_|
508 // is set to a non-null node, and it is removed from that list when |opener_|
509 // changes or when this node is destroyed. It is also cleared if |opener_|
510 // is disowned.
511 std::unique_ptr<OpenerDestroyedObserver> opener_observer_;
512
513 // The frame that opened this frame, if any. Contrary to opener_, this
514 // cannot be changed unless the original opener is destroyed.
arthursonzogni9816b9192021-03-29 16:09:19515 FrameTreeNode* original_opener_ = nullptr;
danakjc492bf82020-09-09 20:02:44516
Wolfgang Beyerd8809db2020-09-30 15:29:39517 // The devtools frame token of the frame which opened this frame. This is
518 // not cleared even if the opener is destroyed or disowns the frame.
Anton Bikineevf62d1bf2021-05-15 17:56:07519 absl::optional<base::UnguessableToken> opener_devtools_frame_token_;
Wolfgang Beyerd8809db2020-09-30 15:29:39520
danakjc492bf82020-09-09 20:02:44521 // An observer that clears this node's |original_opener_| if the opener is
522 // destroyed.
523 std::unique_ptr<OpenerDestroyedObserver> original_opener_observer_;
524
arthursonzogni034bb9c2020-10-01 08:29:56525 // When created by an opener, the URL specified in window.open(url)
526 // Please refer to {Get,Set}InitialPopupURL() documentation.
527 GURL initial_popup_url_;
528
529 // When created using window.open, the origin of the creator.
530 // Please refer to {Get,Set}PopupCreatorOrigin() documentation.
531 url::Origin popup_creator_origin_;
532
danakjc492bf82020-09-09 20:02:44533 // Whether this frame has committed any real load, replacing its initial
534 // about:blank page.
arthursonzogni9816b9192021-03-29 16:09:19535 bool has_committed_real_load_ = false;
danakjc492bf82020-09-09 20:02:44536
537 // Whether the frame's owner element in the parent document is collapsed.
arthursonzogni9816b9192021-03-29 16:09:19538 bool is_collapsed_ = false;
danakjc492bf82020-09-09 20:02:44539
Daniel Cheng9bd90f92021-04-23 20:49:45540 // The type of frame owner for this frame, if any.
541 const blink::mojom::FrameOwnerElementType frame_owner_element_type_ =
542 blink::mojom::FrameOwnerElementType::kNone;
543
danakjc492bf82020-09-09 20:02:44544 // Track information that needs to be replicated to processes that have
545 // proxies for this frame.
Gyuyoung Kimc16e52e92021-03-19 02:45:37546 blink::mojom::FrameReplicationStatePtr replication_state_;
danakjc492bf82020-09-09 20:02:44547
548 // Track the pending sandbox flags and container policy for this frame. When a
549 // parent frame dynamically updates 'sandbox', 'allow', 'allowfullscreen',
550 // 'allowpaymentrequest' or 'src' attributes, the updated policy for the frame
Antonio Sartori90f41212021-01-22 10:08:34551 // is stored here, and transferred into replication_state_->frame_policy when
danakjc492bf82020-09-09 20:02:44552 // they take effect on the next frame navigation.
553 blink::FramePolicy pending_frame_policy_;
554
555 // Whether the frame was created by javascript. This is useful to prune
556 // history entries when the frame is removed (because frames created by
557 // scripts are never recreated with the same unique name - see
558 // https://crbug.com/500260).
arthursonzogni9816b9192021-03-29 16:09:19559 const bool is_created_by_script_;
danakjc492bf82020-09-09 20:02:44560
561 // Used for devtools instrumentation and trace-ability. The token is
562 // propagated to Blink's LocalFrame and both Blink and content/
563 // can tag calls and requests with this token in order to attribute them
564 // to the context frame.
565 // |devtools_frame_token_| is only defined by the browser process and is never
566 // sent back from the renderer in the control calls. It should be never used
567 // to look up the FrameTreeNode instance.
arthursonzogni9816b9192021-03-29 16:09:19568 const base::UnguessableToken devtools_frame_token_;
danakjc492bf82020-09-09 20:02:44569
570 // Tracks the scrolling and margin properties for this frame. These
571 // properties affect the child renderer but are stored on its parent's
572 // frame element. When this frame's parent dynamically updates these
573 // properties, we update them here too.
574 //
575 // Note that dynamic updates only take effect on the next frame navigation.
576 blink::mojom::FrameOwnerProperties frame_owner_properties_;
577
578 // Contains the current parsed value of the 'csp' attribute of this frame.
579 network::mojom::ContentSecurityPolicyPtr csp_attribute_;
580
581 // Owns an ongoing NavigationRequest until it is ready to commit. It will then
582 // be reset and a RenderFrameHost will be responsible for the navigation.
583 std::unique_ptr<NavigationRequest> navigation_request_;
584
585 // List of objects observing this FrameTreeNode.
586 base::ObserverList<Observer>::Unchecked observers_;
587
588 base::TimeTicks last_focus_time_;
589
arthursonzogni9816b9192021-03-29 16:09:19590 bool was_discarded_ = false;
danakjc492bf82020-09-09 20:02:44591
592 // The user activation state of the current frame. See |UserActivationState|
593 // for details on how this state is maintained.
594 blink::UserActivationState user_activation_state_;
595
596 // A helper for tracing the snapshots of this FrameTreeNode and attributing
597 // browser process activities to this node (when possible). It is unrelated
598 // to the core logic of FrameTreeNode.
599 FrameTreeNodeBlameContext blame_context_;
600
Lukasz Anforowicz147141962020-12-16 18:03:24601 // Manages creation and swapping of RenderFrameHosts for this frame.
602 //
603 // This field needs to be declared last, because destruction of
604 // RenderFrameHostManager may call arbitrary callbacks (e.g. via
605 // WebContentsObserver::DidFinishNavigation fired after RenderFrameHostManager
606 // destructs a RenderFrameHostImpl and its NavigationRequest). Such callbacks
607 // may try to use FrameTreeNode's fields above - this would be an undefined
608 // behavior if the fields (even trivially-destructible ones) were destructed
609 // before the RenderFrameHostManager's destructor runs. See also
610 // https://crbug.com/1157988.
611 RenderFrameHostManager render_manager_;
612
danakjc492bf82020-09-09 20:02:44613 DISALLOW_COPY_AND_ASSIGN(FrameTreeNode);
614};
615
616} // namespace content
617
618#endif // CONTENT_BROWSER_RENDERER_HOST_FRAME_TREE_NODE_H_