blob: a27f6365bc83e0c68c048b102c23e016790f90c1 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2013 The Chromium Authors
danakjc492bf82020-09-09 20:02:442// 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>
David Sanders2c1194d92022-04-19 23:32:3212#include <utility>
danakjc492bf82020-09-09 20:02:4413
14#include "base/gtest_prod_util.h"
Keishi Hattori0e45c022021-11-27 09:25:5215#include "base/memory/raw_ptr.h"
David Sanders2c1194d92022-04-19 23:32:3216#include "base/memory/scoped_refptr.h"
David Sandersd4bf5eb2022-03-17 07:12:0517#include "base/observer_list.h"
Mingyu Lei7956b8b2023-07-24 08:24:0818#include "base/task/cancelable_task_tracker.h"
Daniel Cheng390e2a72022-09-28 06:07:5319#include "content/browser/renderer_host/navigation_discard_reason.h"
danakjc492bf82020-09-09 20:02:4420#include "content/browser/renderer_host/navigator.h"
21#include "content/browser/renderer_host/render_frame_host_impl.h"
22#include "content/browser/renderer_host/render_frame_host_manager.h"
Miyoung Shin7cf88b42022-11-07 13:22:3023#include "content/browser/renderer_host/render_frame_host_owner.h"
danakjc492bf82020-09-09 20:02:4424#include "content/common/content_export.h"
Julie Jeongeun Kimf38c1eca2021-12-14 07:46:5525#include "content/public/browser/frame_type.h"
danakjc492bf82020-09-09 20:02:4426#include "services/network/public/mojom/content_security_policy.mojom-forward.h"
Julie Jeongeun Kim0e242242022-11-30 10:45:0927#include "services/network/public/mojom/referrer_policy.mojom-forward.h"
Lei Zhang698df03c2021-05-21 04:23:3428#include "third_party/abseil-cpp/absl/types/optional.h"
Kevin McNee43fe8292021-10-04 22:59:4129#include "third_party/blink/public/common/frame/frame_owner_element_type.h"
danakjc492bf82020-09-09 20:02:4430#include "third_party/blink/public/common/frame/frame_policy.h"
danakjc492bf82020-09-09 20:02:4431#include "third_party/blink/public/mojom/frame/frame_owner_properties.mojom.h"
Gyuyoung Kimc16e52e92021-03-19 02:45:3732#include "third_party/blink/public/mojom/frame/frame_replication_state.mojom-forward.h"
Daniel Cheng6ac128172021-05-25 18:49:0133#include "third_party/blink/public/mojom/frame/tree_scope_type.mojom.h"
David Sanders2c1194d92022-04-19 23:32:3234#include "third_party/blink/public/mojom/frame/user_activation_update_types.mojom-forward.h"
Miyoung Shinaf9a34362023-01-31 02:46:5135#include "third_party/blink/public/mojom/webauthn/virtual_authenticator.mojom-forward.h"
danakjc492bf82020-09-09 20:02:4436
Gabriel Charetted87f10f2022-03-31 00:44:2237#include "base/time/time.h"
danakjc492bf82020-09-09 20:02:4438#include "url/gurl.h"
39#include "url/origin.h"
40
41namespace content {
42
43class NavigationRequest;
44class RenderFrameHostImpl;
45class NavigationEntryImpl;
Paul Semel3e241042022-10-11 12:57:3146class FrameTree;
danakjc492bf82020-09-09 20:02:4447
48// When a page contains iframes, its renderer process maintains a tree structure
49// of those frames. We are mirroring this tree in the browser process. This
50// class represents a node in this tree and is a wrapper for all objects that
51// are frame-specific (as opposed to page-specific).
52//
53// Each FrameTreeNode has a current RenderFrameHost, which can change over
54// time as the frame is navigated. Any immediate subframes of the current
55// document are tracked using FrameTreeNodes owned by the current
56// RenderFrameHost, rather than as children of FrameTreeNode itself. This
57// allows subframe FrameTreeNodes to stay alive while a RenderFrameHost is
58// still alive - for example while pending deletion, after a new current
59// RenderFrameHost has replaced it.
Miyoung Shin7cf88b42022-11-07 13:22:3060class CONTENT_EXPORT FrameTreeNode : public RenderFrameHostOwner {
danakjc492bf82020-09-09 20:02:4461 public:
62 class Observer {
63 public:
64 // Invoked when a FrameTreeNode is being destroyed.
65 virtual void OnFrameTreeNodeDestroyed(FrameTreeNode* node) {}
66
67 // Invoked when a FrameTreeNode becomes focused.
68 virtual void OnFrameTreeNodeFocused(FrameTreeNode* node) {}
69
Arthur Hemerye4659282022-03-28 08:36:1570 // Invoked when a FrameTreeNode moves to a different BrowsingInstance and
71 // the popups it opened should be disowned.
72 virtual void OnFrameTreeNodeDisownedOpenee(FrameTreeNode* node) {}
73
Fergal Dalya1d569972021-03-16 03:24:5374 virtual ~Observer() = default;
danakjc492bf82020-09-09 20:02:4475 };
76
77 static const int kFrameTreeNodeInvalidId;
78
79 // Returns the FrameTreeNode with the given global |frame_tree_node_id|,
80 // regardless of which FrameTree it is in.
81 static FrameTreeNode* GloballyFindByID(int frame_tree_node_id);
82
83 // Returns the FrameTreeNode for the given |rfh|. Same as
84 // rfh->frame_tree_node(), but also supports nullptrs.
85 static FrameTreeNode* From(RenderFrameHost* rfh);
86
87 // Callers are are expected to initialize sandbox flags separately after
88 // calling the constructor.
89 FrameTreeNode(
Arthur Sonzognif6785ec2022-12-05 10:11:5090 FrameTree& frame_tree,
danakjc492bf82020-09-09 20:02:4491 RenderFrameHostImpl* parent,
Daniel Cheng6ac128172021-05-25 18:49:0192 blink::mojom::TreeScopeType tree_scope_type,
danakjc492bf82020-09-09 20:02:4493 bool is_created_by_script,
danakjc492bf82020-09-09 20:02:4494 const blink::mojom::FrameOwnerProperties& frame_owner_properties,
Kevin McNee43fe8292021-10-04 22:59:4195 blink::FrameOwnerElementType owner_type,
Dominic Farolino08662c82021-06-11 07:36:3496 const blink::FramePolicy& frame_owner);
danakjc492bf82020-09-09 20:02:4497
Peter Boström828b9022021-09-21 02:28:4398 FrameTreeNode(const FrameTreeNode&) = delete;
99 FrameTreeNode& operator=(const FrameTreeNode&) = delete;
100
Miyoung Shin7cf88b42022-11-07 13:22:30101 ~FrameTreeNode() override;
danakjc492bf82020-09-09 20:02:44102
103 void AddObserver(Observer* observer);
104 void RemoveObserver(Observer* observer);
105
Ian Vollick25a9d032022-04-12 23:20:17106 // Frame trees may be nested so it can be the case that IsMainFrame() is true,
107 // but is not the outermost main frame. In particular, !IsMainFrame() cannot
108 // be used to check if the frame is an embedded frame -- use
109 // !IsOutermostMainFrame() instead. NB: this does not escape guest views;
110 // IsOutermostMainFrame will be true for the outermost main frame in an inner
111 // guest view.
danakjc492bf82020-09-09 20:02:44112 bool IsMainFrame() const;
Arthur Hemerya06697f2023-03-14 09:20:57113 bool IsOutermostMainFrame() const;
danakjc492bf82020-09-09 20:02:44114
arthursonzogni76098e52020-11-25 14:18:45115 // Clears any state in this node which was set by the document itself (CSP &
116 // UserActivationState) and notifies proxies as appropriate. Invoked after
117 // committing navigation to a new document (since the new document comes with
118 // a fresh set of CSP).
119 // TODO(arthursonzogni): Remove this function. The frame/document must not be
120 // left temporarily with lax state.
Hiroki Nakagawaab309622021-05-19 16:38:13121 void ResetForNavigation();
danakjc492bf82020-09-09 20:02:44122
Arthur Sonzognif6785ec2022-12-05 10:11:50123 FrameTree& frame_tree() const { return frame_tree_.get(); }
Paul Semel3e241042022-10-11 12:57:31124 Navigator& navigator();
danakjc492bf82020-09-09 20:02:44125
126 RenderFrameHostManager* render_manager() { return &render_manager_; }
Alexander Timin33e2e2c12022-03-03 04:21:33127 const RenderFrameHostManager* render_manager() const {
128 return &render_manager_;
129 }
danakjc492bf82020-09-09 20:02:44130 int frame_tree_node_id() const { return frame_tree_node_id_; }
Yuzu Saijo03dbf9b2022-07-22 04:29:45131 // This reflects window.name, which is initially set to the the "name"
132 // attribute. But this won't reflect changes of 'name' attribute and instead
133 // reflect changes to the Window object's name property.
134 // This is different from IframeAttributes' name in that this will not get
135 // updated when 'name' attribute gets updated.
Harkiran Bolaria4eacb3a2021-12-13 20:03:47136 const std::string& frame_name() const {
137 return render_manager_.current_replication_state().name;
138 }
danakjc492bf82020-09-09 20:02:44139
140 const std::string& unique_name() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47141 return render_manager_.current_replication_state().unique_name;
danakjc492bf82020-09-09 20:02:44142 }
143
danakjc492bf82020-09-09 20:02:44144 size_t child_count() const { return current_frame_host()->child_count(); }
145
danakjc492bf82020-09-09 20:02:44146 RenderFrameHostImpl* parent() const { return parent_; }
147
Dave Tapuskac8de3b02021-12-03 21:51:01148 // See `RenderFrameHost::GetParentOrOuterDocument()` for
149 // documentation.
Arthur Hemerya06697f2023-03-14 09:20:57150 RenderFrameHostImpl* GetParentOrOuterDocument() const;
Dave Tapuskac8de3b02021-12-03 21:51:01151
152 // See `RenderFrameHostImpl::GetParentOrOuterDocumentOrEmbedder()` for
153 // documentation.
154 RenderFrameHostImpl* GetParentOrOuterDocumentOrEmbedder();
155
danakjc492bf82020-09-09 20:02:44156 FrameTreeNode* opener() const { return opener_; }
157
Rakina Zata Amni3a48ae42022-05-05 03:39:56158 FrameTreeNode* first_live_main_frame_in_original_opener_chain() const {
159 return first_live_main_frame_in_original_opener_chain_;
160 }
danakjc492bf82020-09-09 20:02:44161
Anton Bikineevf62d1bf2021-05-15 17:56:07162 const absl::optional<base::UnguessableToken>& opener_devtools_frame_token() {
Wolfgang Beyerd8809db2020-09-30 15:29:39163 return opener_devtools_frame_token_;
164 }
165
Julie Jeongeun Kimf38c1eca2021-12-14 07:46:55166 // Returns the type of the frame. Refer to frame_type.h for the details.
167 FrameType GetFrameType() const;
168
danakjc492bf82020-09-09 20:02:44169 // Assigns a new opener for this node and, if |opener| is non-null, registers
170 // an observer that will clear this node's opener if |opener| is ever
171 // destroyed.
172 void SetOpener(FrameTreeNode* opener);
173
174 // Assigns the initial opener for this node, and if |opener| is non-null,
175 // registers an observer that will clear this node's opener if |opener| is
176 // ever destroyed. The value set here is the root of the tree.
177 //
178 // It is not possible to change the opener once it was set.
179 void SetOriginalOpener(FrameTreeNode* opener);
180
Wolfgang Beyerd8809db2020-09-30 15:29:39181 // Assigns an opener frame id for this node. This string id is only set once
182 // and cannot be changed. It persists, even if the |opener| is destroyed. It
183 // is used for attribution in the DevTools frontend.
184 void SetOpenerDevtoolsFrameToken(
185 base::UnguessableToken opener_devtools_frame_token);
186
danakjc492bf82020-09-09 20:02:44187 FrameTreeNode* child_at(size_t index) const {
188 return current_frame_host()->child_at(index);
189 }
190
191 // Returns the URL of the last committed page in the current frame.
192 const GURL& current_url() const {
193 return current_frame_host()->GetLastCommittedURL();
194 }
195
Abhijeet Kandalkarb86993b2022-11-22 05:17:40196 // Note that the current RenderFrameHost might not exist yet when calling this
197 // during FrameTreeNode initialization. In this case the FrameTreeNode must be
198 // on the initial empty document. Refer RFHI::is_initial_empty_document for a
199 // more details.
Rakina Zata Amni86c88fa2021-11-01 01:27:30200 bool is_on_initial_empty_document() const {
Abhijeet Kandalkarb86993b2022-11-22 05:17:40201 return current_frame_host()
202 ? current_frame_host()->is_initial_empty_document()
203 : true;
Rakina Zata Amnifc4cc3d42021-06-10 09:03:56204 }
205
danakjc492bf82020-09-09 20:02:44206 // Returns whether the frame's owner element in the parent document is
207 // collapsed, that is, removed from the layout as if it did not exist, as per
208 // request by the embedder (of the content/ layer).
209 bool is_collapsed() const { return is_collapsed_; }
210
211 // Sets whether to collapse the frame's owner element in the parent document,
212 // that is, to remove it from the layout as if it did not exist, as per
213 // request by the embedder (of the content/ layer). Cannot be called for main
214 // frames.
215 //
216 // This only has an effect for <iframe> owner elements, and is a no-op when
217 // called on sub-frames hosted in <frame>, <object>, and <embed> elements.
218 void SetCollapsed(bool collapsed);
219
220 // Returns the origin of the last committed page in this frame.
221 // WARNING: To get the last committed origin for a particular
222 // RenderFrameHost, use RenderFrameHost::GetLastCommittedOrigin() instead,
223 // which will behave correctly even when the RenderFrameHost is not the
224 // current one for this frame (such as when it's pending deletion).
225 const url::Origin& current_origin() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47226 return render_manager_.current_replication_state().origin;
danakjc492bf82020-09-09 20:02:44227 }
228
danakjc492bf82020-09-09 20:02:44229 // Returns the latest frame policy (sandbox flags and container policy) for
230 // this frame. This includes flags inherited from parent frames and the latest
231 // flags from the <iframe> element hosting this frame. The returned policies
232 // may not yet have taken effect, since "sandbox" and "allow" attribute
Liam Brady25a14162022-12-02 15:25:57233 // updates in an <iframe> element take effect on next navigation. For
234 // <fencedframe> elements, not everything in the frame policy might actually
235 // take effect after the navigation. To retrieve the currently active policy
236 // for this frame, use effective_frame_policy().
danakjc492bf82020-09-09 20:02:44237 const blink::FramePolicy& pending_frame_policy() const {
238 return pending_frame_policy_;
239 }
240
241 // Update this frame's sandbox flags and container policy. This is called
242 // when a parent frame updates the "sandbox" attribute in the <iframe> element
243 // for this frame, or any of the attributes which affect the container policy
244 // ("allowfullscreen", "allowpaymentrequest", "allow", and "src".)
245 // These policies won't take effect until next navigation. If this frame's
246 // parent is itself sandboxed, the parent's sandbox flags are combined with
247 // those in |frame_policy|.
248 // Attempting to change the container policy on the main frame will have no
249 // effect.
250 void SetPendingFramePolicy(blink::FramePolicy frame_policy);
251
252 // Returns the currently active frame policy for this frame, including the
253 // sandbox flags which were present at the time the document was loaded, and
Charlie Hu5130d25e2021-03-05 21:53:39254 // the permissions policy container policy, which is set by the iframe's
danakjc492bf82020-09-09 20:02:44255 // allowfullscreen, allowpaymentrequest, and allow attributes, along with the
256 // origin of the iframe's src attribute (which may be different from the URL
257 // of the document currently loaded into the frame). This does not include
258 // policy changes that have been made by updating the containing iframe
259 // element attributes since the frame was last navigated; use
260 // pending_frame_policy() for those.
261 const blink::FramePolicy& effective_frame_policy() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47262 return render_manager_.current_replication_state().frame_policy;
danakjc492bf82020-09-09 20:02:44263 }
264
danakjc492bf82020-09-09 20:02:44265 const blink::mojom::FrameOwnerProperties& frame_owner_properties() {
266 return frame_owner_properties_;
267 }
268
269 void set_frame_owner_properties(
270 const blink::mojom::FrameOwnerProperties& frame_owner_properties) {
271 frame_owner_properties_ = frame_owner_properties;
272 }
273
Yuzu Saijo03dbf9b2022-07-22 04:29:45274 // Reflects the attributes of the corresponding iframe html element, such
Arthur Sonzogni64457592022-11-22 11:08:59275 // as 'credentialless', 'id', 'name' and 'src'. These values should not be
Yuzu Saijo03dbf9b2022-07-22 04:29:45276 // exposed to cross-origin renderers.
277 const network::mojom::ContentSecurityPolicy* csp_attribute() const {
278 return attributes_->parsed_csp_attribute.get();
danakjc492bf82020-09-09 20:02:44279 }
Yao Xiao9c54b3e2023-03-14 04:25:04280 // Tracks iframe's 'browsingtopics' attribute, indicating whether the
281 // navigation requests on this frame should calculate and send the
282 // `Sec-Browsing-Topics` header.
283 bool browsing_topics() const { return attributes_->browsing_topics; }
Camillia Smith Barnes6d2966c82023-08-23 21:16:18284
285 // Tracks iframe's 'sharedstoragewritable' attribute, indicating what value
286 // the the corresponding `network::ResourceRequest::shared_storage_writable`
287 // should take for the navigation(s) on this frame. If true, the network
288 // service will send the `Shared-Storage-Write` request header.
289 bool shared_storage_writable() const {
290 return attributes_->shared_storage_writable;
291 }
Yuzu Saijodc870f92023-01-20 03:39:11292 const absl::optional<std::string> html_id() const { return attributes_->id; }
Yuzu Saijo03dbf9b2022-07-22 04:29:45293 // This tracks iframe's 'name' attribute instead of window.name, which is
294 // tracked in FrameReplicationState. See the comment for frame_name() for
295 // more details.
Yuzu Saijodc870f92023-01-20 03:39:11296 const absl::optional<std::string> html_name() const {
297 return attributes_->name;
298 }
299 const absl::optional<std::string> html_src() const {
300 return attributes_->src;
301 }
danakjc492bf82020-09-09 20:02:44302
Yuzu Saijo03dbf9b2022-07-22 04:29:45303 void SetAttributes(blink::mojom::IframeAttributesPtr attributes);
Antonio Sartori5abc8de2021-07-13 08:42:47304
danakjc492bf82020-09-09 20:02:44305 bool HasSameOrigin(const FrameTreeNode& node) const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47306 return render_manager_.current_replication_state().origin.IsSameOriginWith(
307 node.current_replication_state().origin);
danakjc492bf82020-09-09 20:02:44308 }
309
Gyuyoung Kimc16e52e92021-03-19 02:45:37310 const blink::mojom::FrameReplicationState& current_replication_state() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47311 return render_manager_.current_replication_state();
danakjc492bf82020-09-09 20:02:44312 }
313
314 RenderFrameHostImpl* current_frame_host() const {
315 return render_manager_.current_frame_host();
316 }
317
danakjc492bf82020-09-09 20:02:44318 // Returns true if this node is in a loading state.
319 bool IsLoading() const;
Nate Chapin470dbc62023-04-25 16:34:38320 LoadingState GetLoadingState() const;
danakjc492bf82020-09-09 20:02:44321
Alex Moshchuk9b0fd822020-10-26 23:08:15322 // Returns true if this node has a cross-document navigation in progress.
323 bool HasPendingCrossDocumentNavigation() const;
324
danakjc492bf82020-09-09 20:02:44325 NavigationRequest* navigation_request() { return navigation_request_.get(); }
326
327 // Transfers the ownership of the NavigationRequest to |render_frame_host|.
328 // From ReadyToCommit to DidCommit, the NavigationRequest is owned by the
329 // RenderFrameHost that is committing the navigation.
330 void TransferNavigationRequestOwnership(
331 RenderFrameHostImpl* render_frame_host);
332
333 // Takes ownership of |navigation_request| and makes it the current
334 // NavigationRequest of this frame. This corresponds to the start of a new
335 // navigation. If there was an ongoing navigation request before calling this
336 // function, it is canceled. |navigation_request| should not be null.
Charlie Reis09952ee2022-12-08 16:35:07337 void TakeNavigationRequest(
danakjc492bf82020-09-09 20:02:44338 std::unique_ptr<NavigationRequest> navigation_request);
339
Rakina Zata Amnif8f2bb62022-11-23 05:54:32340 // Resets the navigation request owned by `this` (which shouldn't have reached
341 // the "pending commit" stage yet) and any state created by it, including the
Rakina Zata Amni33175cb92022-11-24 02:46:03342 // speculative RenderFrameHost (if there are no other navigations associated
343 // with it). Note that this does not affect navigations that have reached the
344 // "pending commit" stage, which are owned by their corresponding
345 // RenderFrameHosts instead.
Daniel Cheng390e2a72022-09-28 06:07:53346 void ResetNavigationRequest(NavigationDiscardReason reason);
347
Rakina Zata Amnif8f2bb62022-11-23 05:54:32348 // Similar to `ResetNavigationRequest()`, but keeps the state created by the
Daniel Cheng390e2a72022-09-28 06:07:53349 // NavigationRequest (e.g. speculative RenderFrameHost, loading state).
350 void ResetNavigationRequestButKeepState();
danakjc492bf82020-09-09 20:02:44351
danakjc492bf82020-09-09 20:02:44352 // The load progress for a RenderFrameHost in this node was updated to
353 // |load_progress|. This will notify the FrameTree which will in turn notify
354 // the WebContents.
355 void DidChangeLoadProgress(double load_progress);
356
357 // Called when the user directed the page to stop loading. Stops all loads
358 // happening in the FrameTreeNode. This method should be used with
359 // FrameTree::ForEach to stop all loads in the entire FrameTree.
360 bool StopLoading();
361
362 // Returns the time this frame was last focused.
363 base::TimeTicks last_focus_time() const { return last_focus_time_; }
364
365 // Called when this node becomes focused. Updates the node's last focused
366 // time and notifies observers.
367 void DidFocus();
368
369 // Called when the user closed the modal dialogue for BeforeUnload and
370 // cancelled the navigation. This should stop any load happening in the
371 // FrameTreeNode.
372 void BeforeUnloadCanceled();
373
danakjc492bf82020-09-09 20:02:44374 // Returns the sandbox flags currently in effect for this frame. This includes
375 // flags inherited from parent frames, the currently active flags from the
376 // <iframe> element hosting this frame, as well as any flags set from a
377 // Content-Security-Policy HTTP header. This does not include flags that have
378 // have been updated in an <iframe> element but have not taken effect yet; use
379 // pending_frame_policy() for those. To see the flags which will take effect
380 // on navigation (which does not include the CSP-set flags), use
381 // effective_frame_policy().
382 network::mojom::WebSandboxFlags active_sandbox_flags() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47383 return render_manager_.current_replication_state().active_sandbox_flags;
danakjc492bf82020-09-09 20:02:44384 }
385
danakjc492bf82020-09-09 20:02:44386 // Returns whether the frame received a user gesture on a previous navigation
387 // on the same eTLD+1.
388 bool has_received_user_gesture_before_nav() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47389 return render_manager_.current_replication_state()
390 .has_received_user_gesture_before_nav;
danakjc492bf82020-09-09 20:02:44391 }
392
393 // When a tab is discarded, WebContents sets was_discarded on its
394 // root FrameTreeNode.
395 // In addition, when a child frame is created, this bit is passed on from
396 // parent to child.
397 // When a navigation request is created, was_discarded is passed on to the
398 // request and reset to false in FrameTreeNode.
399 void set_was_discarded() { was_discarded_ = true; }
400 bool was_discarded() const { return was_discarded_; }
401
Miyoung Shin8a66ec022022-11-28 23:50:09402 // Deprecated. Use directly HasStickyUserActivation in RFHI.
danakjc492bf82020-09-09 20:02:44403 // Returns the sticky bit of the User Activation v2 state of the
404 // |FrameTreeNode|.
405 bool HasStickyUserActivation() const {
Miyoung Shin8a66ec022022-11-28 23:50:09406 return current_frame_host()->HasStickyUserActivation();
danakjc492bf82020-09-09 20:02:44407 }
408
Miyoung Shin8a66ec022022-11-28 23:50:09409 // Deprecated. Use directly HasStickyUserActivation in RFHI.
danakjc492bf82020-09-09 20:02:44410 // Returns the transient bit of the User Activation v2 state of the
411 // |FrameTreeNode|.
412 bool HasTransientUserActivation() {
Miyoung Shin8a66ec022022-11-28 23:50:09413 return current_frame_host()->HasTransientUserActivation();
danakjc492bf82020-09-09 20:02:44414 }
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
Abhijeet Kandalkarb43affa72022-09-27 16:48:01421 using FencedFrameStatus = RenderFrameHostImpl::FencedFrameStatus;
Abhijeet Kandalkar3f29bc42022-09-23 12:39:58422 FencedFrameStatus fenced_frame_status() const { return fenced_frame_status_; }
423
Kevin McNee43fe8292021-10-04 22:59:41424 blink::FrameOwnerElementType frame_owner_element_type() const {
Daniel Cheng9bd90f92021-04-23 20:49:45425 return frame_owner_element_type_;
danakjc492bf82020-09-09 20:02:44426 }
danakjc492bf82020-09-09 20:02:44427
Daniel Cheng6ac128172021-05-25 18:49:01428 blink::mojom::TreeScopeType tree_scope_type() const {
429 return tree_scope_type_;
430 }
431
arthursonzogni034bb9c2020-10-01 08:29:56432 // The initial popup URL for new window opened using:
433 // `window.open(initial_popup_url)`.
434 // An empty GURL otherwise.
435 //
436 // [WARNING] There is no guarantee the FrameTreeNode will ever host a
437 // document served from this URL. The FrameTreeNode always starts hosting the
438 // initial empty document and attempts a navigation toward this URL. However
439 // the navigation might be delayed, redirected and even cancelled.
440 void SetInitialPopupURL(const GURL& initial_popup_url);
441 const GURL& initial_popup_url() const { return initial_popup_url_; }
442
443 // The origin of the document that used window.open() to create this frame.
444 // Otherwise, an opaque Origin with a nonce different from all previously
445 // existing Origins.
446 void SetPopupCreatorOrigin(const url::Origin& popup_creator_origin);
447 const url::Origin& popup_creator_origin() const {
448 return popup_creator_origin_;
449 }
450
Harkiran Bolaria59290d62021-03-17 01:53:01451 // Sets the associated FrameTree for this node. The node can change FrameTrees
Domenic Denicola7767a9c2023-07-13 15:36:39452 // as part of prerendering, which allows a page loaded in the prerendered
453 // FrameTree to be used for a navigation in the primary frame tree.
Harkiran Bolaria59290d62021-03-17 01:53:01454 void SetFrameTree(FrameTree& frame_tree);
455
Alexander Timin074cd182022-03-23 18:11:22456 using TraceProto = perfetto::protos::pbzero::FrameTreeNodeInfo;
Alexander Timinf785f342021-03-18 00:00:56457 // Write a representation of this object into a trace.
Alexander Timin074cd182022-03-23 18:11:22458 void WriteIntoTrace(perfetto::TracedProto<TraceProto> proto) const;
Alexander Timinf785f342021-03-18 00:00:56459
Carlos Caballero76711352021-03-24 17:38:21460 // Returns true the node is navigating, i.e. it has an associated
461 // NavigationRequest.
462 bool HasNavigation();
463
shivanigithubf3ddff52021-07-03 22:06:30464 // Fenced frames (meta-bug crbug.com/1111084):
shivanigithub4cd016a2021-09-20 21:10:30465 // Note that these two functions cannot be invoked from a FrameTree's or
466 // its root node's constructor since they require the frame tree and the
467 // root node to be completely constructed.
468 //
shivanigithubf3ddff52021-07-03 22:06:30469 // Returns false if fenced frames are disabled. Returns true if the feature is
470 // enabled and if |this| is a fenced frame. Returns false for
471 // iframes embedded in a fenced frame. To clarify: for the MPArch
472 // implementation this only returns true if |this| is the actual
473 // root node of the inner FrameTree and not the proxy FrameTreeNode in the
474 // outer FrameTree.
Dominic Farolino4bc10ee2021-08-31 00:37:36475 bool IsFencedFrameRoot() const;
shivanigithubf3ddff52021-07-03 22:06:30476
477 // Returns false if fenced frames are disabled. Returns true if the
478 // feature is enabled and if |this| or any of its ancestor nodes is a
479 // fenced frame.
480 bool IsInFencedFrameTree() const;
481
shivanigithub4cd016a2021-09-20 21:10:30482 // Returns a valid nonce if `IsInFencedFrameTree()` returns true for `this`.
Garrett Tanzer34cb92fe2022-09-28 17:50:54483 // Returns nullopt otherwise.
484 //
485 // Nonce used in the net::IsolationInfo and blink::StorageKey for a fenced
486 // frame and any iframes nested within it. Not set if this frame is not in a
487 // fenced frame's FrameTree. Note that this could be a field in FrameTree for
488 // the MPArch version but for the shadow DOM version we need to keep it here
489 // since the fenced frame root is not a main frame for the latter. The value
490 // of the nonce will be the same for all of the the iframes inside a fenced
491 // frame tree. If there is a nested fenced frame it will have a different
492 // nonce than its parent fenced frame. The nonce will stay the same across
493 // navigations initiated from the fenced frame tree because it is always used
494 // in conjunction with other fields of the keys and would be good to access
495 // the same storage across same-origin navigations. If the navigation is
496 // same-origin/site then the same network stack partition/storage will be
497 // reused and if it's cross-origin/site then other parts of the key will
498 // change and so, even with the same nonce, another partition will be used.
499 // But if the navigation is initiated from the embedder, the nonce will be
500 // reinitialized irrespective of same or cross origin such that there is no
501 // privacy leak via storage shared between two embedder initiated navigations.
502 // Note that this reinitialization is implemented for all embedder-initiated
503 // navigations in MPArch, but only urn:uuid navigations in ShadowDOM.
504 absl::optional<base::UnguessableToken> GetFencedFrameNonce();
shivanigithub4cd016a2021-09-20 21:10:30505
Garrett Tanzer34cb92fe2022-09-28 17:50:54506 // If applicable, initialize the default fenced frame properties. Right now,
507 // this means setting a new fenced frame nonce. See comment on
shivanigithub4cd016a2021-09-20 21:10:30508 // fenced_frame_nonce() for when it is set to a non-null value. Invoked
509 // by FrameTree::Init() or FrameTree::AddFrame().
Garrett Tanzer34cb92fe2022-09-28 17:50:54510 void SetFencedFramePropertiesIfNeeded();
shivanigithub4cd016a2021-09-20 21:10:30511
Garrett Tanzer291a2d52023-03-20 22:41:57512 // Set the current FencedFrameProperties to have "opaque ads mode".
513 // This should only be used during tests, when the proper embedder-initiated
514 // fenced frame root urn/config navigation flow isn't available.
515 // TODO(crbug.com/1347953): Refactor and expand use of test utils so there is
516 // a consistent way to do this properly everywhere. Consider removing
517 // arbitrary restrictions in "default mode" so that using opaque ads mode is
518 // less necessary.
519 void SetFencedFramePropertiesOpaqueAdsModeForTesting() {
520 if (fenced_frame_properties_.has_value()) {
521 fenced_frame_properties_->mode_ =
522 blink::FencedFrame::DeprecatedFencedFrameMode::kOpaqueAds;
523 }
524 }
525
526 // Returns the mode attribute from the `FencedFrameProperties` if this frame
527 // is in a fenced frame tree, otherwise returns `kDefault`.
528 blink::FencedFrame::DeprecatedFencedFrameMode GetDeprecatedFencedFrameMode();
Nan Lin171fe9a2022-02-17 16:42:16529
Dave Tapuskac8de3b02021-12-03 21:51:01530 // Helper for GetParentOrOuterDocument/GetParentOrOuterDocumentOrEmbedder.
531 // Do not use directly.
Kevin McNee86e64ee2023-02-17 16:35:50532 // `escape_guest_view` determines whether to iterate out of guest views and is
533 // the behaviour distinction between GetParentOrOuterDocument and
534 // GetParentOrOuterDocumentOrEmbedder. See the comment on
535 // GetParentOrOuterDocumentOrEmbedder for details.
536 // `include_prospective` includes embedders which own our frame tree, but have
537 // not yet attached it to the outer frame tree.
Arthur Hemerya06697f2023-03-14 09:20:57538 RenderFrameHostImpl* GetParentOrOuterDocumentHelper(
539 bool escape_guest_view,
540 bool include_prospective) const;
Dave Tapuskac8de3b02021-12-03 21:51:01541
Harkiran Bolariab4437fd2021-08-11 17:51:22542 // Sets the unique_name and name fields on replication_state_. To be used in
543 // prerender activation to make sure the FrameTreeNode replication state is
544 // correct after the RenderFrameHost is moved between FrameTreeNodes. The
545 // renderers should already have the correct value, so unlike
546 // FrameTreeNode::SetFrameName, we do not notify them here.
Harkiran Bolaria4eacb3a2021-12-13 20:03:47547 // TODO(https://crbug.com/1237091): Remove this once the BrowsingContextState
548 // is implemented to utilize the new path.
Harkiran Bolariab4437fd2021-08-11 17:51:22549 void set_frame_name_for_activation(const std::string& unique_name,
550 const std::string& name) {
Harkiran Bolaria0b3bdef02022-03-10 13:04:40551 current_frame_host()->browsing_context_state()->set_frame_name(unique_name,
552 name);
Harkiran Bolariab4437fd2021-08-11 17:51:22553 }
554
Nan Linaaf84f72021-12-02 22:31:56555 // Returns true if error page isolation is enabled.
556 bool IsErrorPageIsolationEnabled() const;
557
W. James MacLean81b8d01f2022-01-25 20:50:59558 // Functions to store and retrieve a frame's srcdoc value on this
559 // FrameTreeNode.
560 void SetSrcdocValue(const std::string& srcdoc_value);
561 const std::string& srcdoc_value() const { return srcdoc_value_; }
562
Garrett Tanzerc69f4642022-08-15 22:15:14563 void set_fenced_frame_properties(
Garrett Tanzer29de7112022-12-06 21:26:32564 const absl::optional<FencedFrameProperties>& fenced_frame_properties) {
Garrett Tanzer2975eeac2022-08-22 16:34:01565 // TODO(crbug.com/1262022): Reenable this DCHECK once ShadowDOM and
566 // loading urns in iframes (for FLEDGE OT) are gone.
567 // DCHECK_EQ(fenced_frame_status_,
568 // RenderFrameHostImpl::FencedFrameStatus::kFencedFrameRoot);
Garrett Tanzerc69f4642022-08-15 22:15:14569 fenced_frame_properties_ = fenced_frame_properties;
570 }
571
Xiaochen Zhou90858e82023-05-31 15:47:37572 // By default, this function checks the fenced frame root's properties if one
573 // exists, and then otherwise traverses the frame tree to find urn iframe
574 // roots. This doesn't work correctly for urn iframes nested inside of fenced
575 // frames. Enable `force_tree_traversal` to skip the fenced frame root short
576 // circuit and always traverse the tree.
577 // TODO(crbug.com/1355857): This function has the correct semantics when
578 // `force_tree_traversal` is set to true. It is set to false for urn iframes
579 // nested in fenced frames to work correctly in some cases. For example,
580 // storage partitioning. Once those issues are resolved, remove this parameter
581 // entirely.
582 const absl::optional<FencedFrameProperties>& GetFencedFrameProperties(
583 bool force_tree_traversal = false);
Garrett Tanzerc69f4642022-08-15 22:15:14584
Liam Brady6da2cc9e2023-01-30 17:09:43585 // Called from the currently active document via the
586 // `Fence.setReportEventDataForAutomaticBeacons` JS API.
587 void SetFencedFrameAutomaticBeaconReportEventData(
588 const std::string& event_data,
Nan Lindbce6e32023-05-10 22:42:55589 const std::vector<blink::FencedFrame::ReportingDestination>& destinations,
590 network::AttributionReportingRuntimeFeatures
Liam Bradybe6621d12023-07-20 19:43:40591 attribution_reporting_runtime_features,
592 bool once) override;
593
594 // Helper function to clear out automatic beacon data after one automatic
595 // beacon if `once` was set to true when calling
596 // `setReportEventDataForAutomaticBeacons()`.
597 void MaybeResetFencedFrameAutomaticBeaconReportEventData();
Liam Brady6da2cc9e2023-01-30 17:09:43598
Yao Xiaof9ae90a2023-03-01 20:52:44599 // Returns the number of fenced frame boundaries above this frame. The
Yao Xiaoa2337ad2022-10-12 20:59:29600 // outermost main frame's frame tree has fenced frame depth 0, a topmost
601 // fenced frame tree embedded in the outermost main frame has fenced frame
602 // depth 1, etc.
Yao Xiaof9ae90a2023-03-01 20:52:44603 //
604 // Also, sets `shared_storage_fenced_frame_root_count` to the
605 // number of fenced frame boundaries (roots) above this frame that originate
606 // from shared storage. This is used to check whether a fenced frame
607 // originates from shared storage only (i.e. not from FLEDGE).
608 // TODO(crbug.com/1347953): Remove this check once we put permissions inside
609 // FencedFrameConfig.
610 size_t GetFencedFrameDepth(size_t& shared_storage_fenced_frame_root_count);
Yao Xiaoa2337ad2022-10-12 20:59:29611
612 // Traverse up from this node. Return all valid
613 // `node->fenced_frame_properties_->shared_storage_budget_metadata` (i.e. this
614 // node is subjected to the shared storage budgeting associated with those
615 // metadata). Every node that originates from sharedStorage.selectURL() will
616 // have an associated metadata. This indicates that the metadata can only
617 // possibly be associated with a fenced frame root, unless when
618 // `kAllowURNsInIframes` is enabled in which case they could be be associated
619 // with any node.
Garrett Tanzer29de7112022-12-06 21:26:32620 std::vector<const SharedStorageBudgetMetadata*>
Yao Xiao1ac702d2022-06-08 17:20:49621 FindSharedStorageBudgetMetadata();
622
Camillia Smith Barnes7218518c2023-03-06 19:02:17623 // Returns any shared storage context string that was written to a
624 // `blink::FencedFrameConfig` before navigation via
625 // `setSharedStorageContext()`, as long as the request is for a same-origin
626 // frame within the config's fenced frame tree (or a same-origin descendant of
627 // a URN iframe).
628 absl::optional<std::u16string> GetEmbedderSharedStorageContextIfAllowed();
629
Harkiran Bolariaebbe7702022-02-22 19:19:03630 // Accessor to BrowsingContextState for subframes only. Only main frame
631 // navigations can change BrowsingInstances and BrowsingContextStates,
632 // therefore for subframes associated BrowsingContextState never changes. This
633 // helper method makes this more explicit and guards against calling this on
634 // main frames (there an appropriate BrowsingContextState should be obtained
635 // from RenderFrameHost or from RenderFrameProxyHost as e.g. during
636 // cross-BrowsingInstance navigations multiple BrowsingContextStates exist in
637 // the same frame).
638 const scoped_refptr<BrowsingContextState>&
639 GetBrowsingContextStateForSubframe() const;
640
Arthur Hemerye4659282022-03-28 08:36:15641 // Clears the opener property of popups referencing this FrameTreeNode as
642 // their opener.
643 void ClearOpenerReferences();
644
Liam Brady95d36d12023-03-13 21:13:06645 // Calculates whether one of the ancestor frames or this frame has a CSPEE in
646 // place. This is eventually sent over to LocalFrame in the renderer where it
647 // will be used by NavigatorAuction::canLoadAdAuctionFencedFrame for
648 // information it can't get on its own.
Liam Bradyd2a41e152022-07-19 13:58:48649 bool AncestorOrSelfHasCSPEE() const;
650
Arthur Sonzogni8e8eb1f2023-01-10 14:51:01651 // Reset every navigation in this frame, and its descendants. This is called
652 // after the <iframe> element has been removed, or after the document owning
653 // this frame has been navigated away.
654 //
655 // This takes into account:
656 // - Non-pending commit NavigationRequest owned by the FrameTreeNode
657 // - Pending commit NavigationRequest owned by the current RenderFrameHost
658 // - Speculative RenderFrameHost and its pending commit NavigationRequests.
659 void ResetAllNavigationsForFrameDetach();
660
Miyoung Shin7cf88b42022-11-07 13:22:30661 // RenderFrameHostOwner implementation:
Nate Chapin470dbc62023-04-25 16:34:38662 void DidStartLoading(LoadingState previous_frame_tree_loading_state) override;
Julie Jeongeun Kim07c077bd2022-12-05 08:40:31663 void DidStopLoading() override;
Miyoung Shin7cf88b42022-11-07 13:22:30664 void RestartNavigationAsCrossDocument(
665 std::unique_ptr<NavigationRequest> navigation_request) override;
Miyoung Shin1504eb712022-12-07 10:32:18666 bool Reload() override;
Julie Jeongeun Kimc1b07c32022-11-11 10:26:32667 Navigator& GetCurrentNavigator() override;
Miyoung Shine16cd2262022-11-30 05:52:16668 RenderFrameHostManager& GetRenderFrameHostManager() override;
Miyoung Shin64fd1bea2023-01-04 04:22:08669 FrameTreeNode* GetOpener() const override;
Julie Jeongeun Kim2132b37f82022-11-23 08:30:46670 void SetFocusedFrame(SiteInstanceGroup* source) override;
Julie Jeongeun Kim0e242242022-11-30 10:45:09671 void DidChangeReferrerPolicy(
672 network::mojom::ReferrerPolicy referrer_policy) override;
Miyoung Shin7cf88b42022-11-07 13:22:30673
Miyoung Shin8a66ec022022-11-28 23:50:09674 // Updates the user activation state in the browser frame tree and in the
675 // frame trees in all renderer processes except the renderer for this node
676 // (which initiated the update). Returns |false| if the update tries to
677 // consume an already consumed/expired transient state, |true| otherwise. See
678 // the comment on `user_activation_state_` in RenderFrameHostImpl.
679 //
680 // The |notification_type| parameter is used for histograms, only for the case
681 // |update_state == kNotifyActivation|.
682 bool UpdateUserActivationState(
683 blink::mojom::UserActivationUpdateType update_type,
684 blink::mojom::UserActivationNotificationType notification_type) override;
685
Nate Chapin47276a62023-02-16 16:53:44686 void DidConsumeHistoryUserActivation() override;
687
Miyoung Shinff13ed22022-11-30 09:21:47688 std::unique_ptr<NavigationRequest>
689 CreateNavigationRequestForSynchronousRendererCommit(
690 RenderFrameHostImpl* render_frame_host,
691 bool is_same_document,
692 const GURL& url,
693 const url::Origin& origin,
W. James MacLean23e90a12022-12-21 04:38:21694 const absl::optional<GURL>& initiator_base_url,
Miyoung Shinff13ed22022-11-30 09:21:47695 const net::IsolationInfo& isolation_info_for_subresources,
696 blink::mojom::ReferrerPtr referrer,
697 const ui::PageTransition& transition,
698 bool should_replace_current_entry,
699 const std::string& method,
700 bool has_transient_activation,
701 bool is_overriding_user_agent,
702 const std::vector<GURL>& redirects,
703 const GURL& original_url,
704 std::unique_ptr<CrossOriginEmbedderPolicyReporter> coep_reporter,
Miyoung Shinff13ed22022-11-30 09:21:47705 int http_response_code) override;
Miyoung Shinb5561802022-12-01 08:21:35706 void CancelNavigation() override;
Miyoung Shinc9ff4812023-01-05 08:58:05707 bool Credentialless() const override;
Miyoung Shinaf9a34362023-01-31 02:46:51708#if !BUILDFLAG(IS_ANDROID)
709 void GetVirtualAuthenticatorManager(
710 mojo::PendingReceiver<blink::test::mojom::VirtualAuthenticatorManager>
711 receiver) override;
712#endif
Miyoung Shinff13ed22022-11-30 09:21:47713
Mingyu Lei7956b8b2023-07-24 08:24:08714 // Restart the navigation restoring the page from the back-forward cache
715 // as a regular non-BFCached history navigation.
716 //
717 // The restart itself is asynchronous as it's dangerous to restart navigation
718 // with arbitrary state on the stack (another navigation might be starting),
719 // so this function only posts the actual task to do all the work (See
720 // `RestartBackForwardCachedNavigationImpl()`).
721 void RestartBackForwardCachedNavigationAsync(int nav_entry_id);
722
723 // Cancel the asynchronous task that would restart the BFCache navigation.
724 // This should be called whenever a FrameTreeNode's NavigationRequest would
725 // normally get cancelled, including when another NavigationRequest starts.
726 // This preserves the previous behavior where a restarting BFCache
727 // NavigationRequest is kept around until the task to create the new
728 // navigation is run, or until that NavigationRequest gets deleted (which
729 // cancels the task).
730 void CancelRestartingBackForwardCacheNavigation();
731
danakjc492bf82020-09-09 20:02:44732 private:
Yuzu Saijo03dbf9b2022-07-22 04:29:45733 friend class CSPEmbeddedEnforcementUnitTest;
Charlie Hubb5943d2021-03-09 19:46:12734 FRIEND_TEST_ALL_PREFIXES(SitePerProcessPermissionsPolicyBrowserTest,
danakjc492bf82020-09-09 20:02:44735 ContainerPolicyDynamic);
Charlie Hubb5943d2021-03-09 19:46:12736 FRIEND_TEST_ALL_PREFIXES(SitePerProcessPermissionsPolicyBrowserTest,
danakjc492bf82020-09-09 20:02:44737 ContainerPolicySandboxDynamic);
Yuzu Saijo03dbf9b2022-07-22 04:29:45738 FRIEND_TEST_ALL_PREFIXES(NavigationRequestTest, StorageKeyToCommit);
Arthur Sonzogni64457592022-11-22 11:08:59739 FRIEND_TEST_ALL_PREFIXES(
740 NavigationRequestTest,
741 NavigationToCredentiallessDocumentNetworkIsolationInfo);
Yuzu Saijo03dbf9b2022-07-22 04:29:45742 FRIEND_TEST_ALL_PREFIXES(RenderFrameHostImplTest,
Arthur Sonzogni64457592022-11-22 11:08:59743 ChildOfCredentiallessIsCredentialless);
Yifan Luo86a79f42022-08-16 18:38:27744 FRIEND_TEST_ALL_PREFIXES(ContentPasswordManagerDriverTest,
Arthur Sonzogni64457592022-11-22 11:08:59745 PasswordAutofillDisabledOnCredentiallessIframe);
danakjc492bf82020-09-09 20:02:44746
Dominic Farolino8a2187b2021-12-24 20:44:21747 // Called by the destructor. When `this` is an outer dummy FrameTreeNode
748 // representing an inner FrameTree, this method destroys said inner FrameTree.
749 void DestroyInnerFrameTreeIfExists();
750
danakjc492bf82020-09-09 20:02:44751 class OpenerDestroyedObserver;
752
danakjc492bf82020-09-09 20:02:44753 // The |notification_type| parameter is used for histograms only.
754 bool NotifyUserActivation(
755 blink::mojom::UserActivationNotificationType notification_type);
756
757 bool ConsumeTransientUserActivation();
758
759 bool ClearUserActivation();
760
761 // Verify that the renderer process is allowed to set user activation on this
762 // frame by checking whether this frame's RenderWidgetHost had previously seen
763 // an input event that might lead to user activation. If user activation
764 // should be allowed, this returns true and also clears corresponding pending
765 // user activation state in the widget. Otherwise, this returns false.
766 bool VerifyUserActivation();
767
Xiaochen Zhou90858e82023-05-31 15:47:37768 // See comments for `GetFencedFrameProperties()`.
769 absl::optional<FencedFrameProperties>& GetFencedFramePropertiesForEditing(
770 bool force_tree_traversal = false);
Liam Brady6da2cc9e2023-01-30 17:09:43771
Mingyu Lei7956b8b2023-07-24 08:24:08772 // See `RestartBackForwardCachedNavigationAsync()`.
773 void RestartBackForwardCachedNavigationImpl(int nav_entry_id);
774
danakjc492bf82020-09-09 20:02:44775 // The next available browser-global FrameTreeNode ID.
776 static int next_frame_tree_node_id_;
777
Arthur Sonzognif6785ec2022-12-05 10:11:50778 // The FrameTree owning |this|. It can change with Prerender2 during
779 // activation.
780 raw_ref<FrameTree> frame_tree_;
danakjc492bf82020-09-09 20:02:44781
danakjc492bf82020-09-09 20:02:44782 // A browser-global identifier for the frame in the page, which stays stable
783 // even if the frame does a cross-process navigation.
784 const int frame_tree_node_id_;
785
786 // The RenderFrameHost owning this FrameTreeNode, which cannot change for the
787 // life of this FrameTreeNode. |nullptr| if this node is the root.
Keishi Hattori0e45c022021-11-27 09:25:52788 const raw_ptr<RenderFrameHostImpl> parent_;
danakjc492bf82020-09-09 20:02:44789
danakjc492bf82020-09-09 20:02:44790 // The frame that opened this frame, if any. Will be set to null if the
791 // opener is closed, or if this frame disowns its opener by setting its
792 // window.opener to null.
Keishi Hattori0e45c022021-11-27 09:25:52793 raw_ptr<FrameTreeNode> opener_ = nullptr;
danakjc492bf82020-09-09 20:02:44794
795 // An observer that clears this node's |opener_| if the opener is destroyed.
796 // This observer is added to the |opener_|'s observer list when the |opener_|
797 // is set to a non-null node, and it is removed from that list when |opener_|
798 // changes or when this node is destroyed. It is also cleared if |opener_|
799 // is disowned.
800 std::unique_ptr<OpenerDestroyedObserver> opener_observer_;
801
Rakina Zata Amni3a48ae42022-05-05 03:39:56802 // Unlike `opener_`, the "original opener chain" doesn't reflect
803 // window.opener, which can be suppressed or updated. The "original opener"
804 // is the main frame of the actual opener of this frame. This traces the all
805 // the way back, so if the original opener was closed (deleted or severed due
806 // to COOP), but _it_ had an original opener, this will return the original
807 // opener's original opener, etc. So this value will always be set as long as
808 // there is at least one live frame in the chain whose connection is not
809 // severed due to COOP.
810 raw_ptr<FrameTreeNode> first_live_main_frame_in_original_opener_chain_ =
811 nullptr;
danakjc492bf82020-09-09 20:02:44812
Wolfgang Beyerd8809db2020-09-30 15:29:39813 // The devtools frame token of the frame which opened this frame. This is
814 // not cleared even if the opener is destroyed or disowns the frame.
Anton Bikineevf62d1bf2021-05-15 17:56:07815 absl::optional<base::UnguessableToken> opener_devtools_frame_token_;
Wolfgang Beyerd8809db2020-09-30 15:29:39816
Rakina Zata Amni3a48ae42022-05-05 03:39:56817 // An observer that updates this node's
818 // |first_live_main_frame_in_original_opener_chain_| to the next original
819 // opener in the chain if the original opener is destroyed.
danakjc492bf82020-09-09 20:02:44820 std::unique_ptr<OpenerDestroyedObserver> original_opener_observer_;
821
arthursonzogni034bb9c2020-10-01 08:29:56822 // When created by an opener, the URL specified in window.open(url)
823 // Please refer to {Get,Set}InitialPopupURL() documentation.
824 GURL initial_popup_url_;
825
826 // When created using window.open, the origin of the creator.
827 // Please refer to {Get,Set}PopupCreatorOrigin() documentation.
828 url::Origin popup_creator_origin_;
829
W. James MacLean81b8d01f2022-01-25 20:50:59830 // If the url from the the last BeginNavigation is about:srcdoc, this value
831 // stores the srcdoc_attribute's value for re-use in history navigations.
832 std::string srcdoc_value_;
833
danakjc492bf82020-09-09 20:02:44834 // Whether the frame's owner element in the parent document is collapsed.
arthursonzogni9816b9192021-03-29 16:09:19835 bool is_collapsed_ = false;
danakjc492bf82020-09-09 20:02:44836
Daniel Cheng6ac128172021-05-25 18:49:01837 // The type of frame owner for this frame. This is only relevant for non-main
838 // frames.
Kevin McNee43fe8292021-10-04 22:59:41839 const blink::FrameOwnerElementType frame_owner_element_type_ =
840 blink::FrameOwnerElementType::kNone;
Daniel Cheng9bd90f92021-04-23 20:49:45841
Daniel Cheng6ac128172021-05-25 18:49:01842 // The tree scope type of frame owner element, i.e. whether the element is in
843 // the document tree (https://dom.spec.whatwg.org/#document-trees) or the
844 // shadow tree (https://dom.spec.whatwg.org/#shadow-trees). This is only
845 // relevant for non-main frames.
846 const blink::mojom::TreeScopeType tree_scope_type_ =
847 blink::mojom::TreeScopeType::kDocument;
848
danakjc492bf82020-09-09 20:02:44849 // Track the pending sandbox flags and container policy for this frame. When a
850 // parent frame dynamically updates 'sandbox', 'allow', 'allowfullscreen',
851 // 'allowpaymentrequest' or 'src' attributes, the updated policy for the frame
Harkiran Bolaria4eacb3a2021-12-13 20:03:47852 // is stored here, and transferred into
853 // render_manager_.current_replication_state().frame_policy when they take
854 // effect on the next frame navigation.
danakjc492bf82020-09-09 20:02:44855 blink::FramePolicy pending_frame_policy_;
856
857 // Whether the frame was created by javascript. This is useful to prune
858 // history entries when the frame is removed (because frames created by
859 // scripts are never recreated with the same unique name - see
860 // https://crbug.com/500260).
arthursonzogni9816b9192021-03-29 16:09:19861 const bool is_created_by_script_;
danakjc492bf82020-09-09 20:02:44862
danakjc492bf82020-09-09 20:02:44863 // Tracks the scrolling and margin properties for this frame. These
864 // properties affect the child renderer but are stored on its parent's
865 // frame element. When this frame's parent dynamically updates these
866 // properties, we update them here too.
867 //
868 // Note that dynamic updates only take effect on the next frame navigation.
869 blink::mojom::FrameOwnerProperties frame_owner_properties_;
870
Yuzu Saijo03dbf9b2022-07-22 04:29:45871 // Contains the tracked HTML attributes of the corresponding iframe element,
872 // such as 'id' and 'src'.
873 blink::mojom::IframeAttributesPtr attributes_;
Antonio Sartori5abc8de2021-07-13 08:42:47874
danakjc492bf82020-09-09 20:02:44875 // Owns an ongoing NavigationRequest until it is ready to commit. It will then
876 // be reset and a RenderFrameHost will be responsible for the navigation.
877 std::unique_ptr<NavigationRequest> navigation_request_;
878
879 // List of objects observing this FrameTreeNode.
880 base::ObserverList<Observer>::Unchecked observers_;
881
882 base::TimeTicks last_focus_time_;
883
arthursonzogni9816b9192021-03-29 16:09:19884 bool was_discarded_ = false;
danakjc492bf82020-09-09 20:02:44885
Abhijeet Kandalkar3f29bc42022-09-23 12:39:58886 const FencedFrameStatus fenced_frame_status_ =
887 FencedFrameStatus::kNotNestedInFencedFrame;
Harkiran Bolaria16f2c48d2022-04-22 12:39:57888
Garrett Tanzerc69f4642022-08-15 22:15:14889 // If this is a fenced frame resulting from a urn:uuid navigation, this
890 // contains all the metadata specifying the resulting context.
Garrett Tanzer34cb92fe2022-09-28 17:50:54891 // TODO(crbug.com/1262022): Move this into the FrameTree once ShadowDOM
892 // and urn iframes are gone.
Garrett Tanzer29de7112022-12-06 21:26:32893 absl::optional<FencedFrameProperties> fenced_frame_properties_;
Garrett Tanzerc69f4642022-08-15 22:15:14894
Mingyu Lei7956b8b2023-07-24 08:24:08895 // The tracker of the task that restarts the BFCache navigation. It might be
896 // used to cancel the task.
897 // See `CancelRestartingBackForwardCacheNavigation()`.
898 base::CancelableTaskTracker restart_back_forward_cached_navigation_tracker_;
899
Lukasz Anforowicz147141962020-12-16 18:03:24900 // Manages creation and swapping of RenderFrameHosts for this frame.
901 //
902 // This field needs to be declared last, because destruction of
903 // RenderFrameHostManager may call arbitrary callbacks (e.g. via
904 // WebContentsObserver::DidFinishNavigation fired after RenderFrameHostManager
905 // destructs a RenderFrameHostImpl and its NavigationRequest). Such callbacks
906 // may try to use FrameTreeNode's fields above - this would be an undefined
907 // behavior if the fields (even trivially-destructible ones) were destructed
908 // before the RenderFrameHostManager's destructor runs. See also
909 // https://crbug.com/1157988.
910 RenderFrameHostManager render_manager_;
Mingyu Lei7956b8b2023-07-24 08:24:08911
912 base::WeakPtrFactory<FrameTreeNode> weak_factory_{this};
danakjc492bf82020-09-09 20:02:44913};
914
915} // namespace content
916
917#endif // CONTENT_BROWSER_RENDERER_HOST_FRAME_TREE_NODE_H_