blob: e264437f66c423e85fa79bdf651bfcfb43641679 [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>
Arthur Sonzognic686e8f2024-01-11 08:36:3711#include <optional>
danakjc492bf82020-09-09 20:02:4412#include <string>
David Sanders2c1194d92022-04-19 23:32:3213#include <utility>
danakjc492bf82020-09-09 20:02:4414
15#include "base/gtest_prod_util.h"
Keishi Hattori0e45c022021-11-27 09:25:5216#include "base/memory/raw_ptr.h"
Christian Biesingere1865c57c2023-10-20 15:19:2917#include "base/memory/safe_ref.h"
David Sanders2c1194d92022-04-19 23:32:3218#include "base/memory/scoped_refptr.h"
David Sandersd4bf5eb2022-03-17 07:12:0519#include "base/observer_list.h"
Mingyu Lei7956b8b2023-07-24 08:24:0820#include "base/task/cancelable_task_tracker.h"
Arthur Sonzognic686e8f2024-01-11 08:36:3721#include "base/time/time.h"
danakjc492bf82020-09-09 20:02:4422#include "content/browser/renderer_host/navigator.h"
23#include "content/browser/renderer_host/render_frame_host_impl.h"
24#include "content/browser/renderer_host/render_frame_host_manager.h"
Miyoung Shin7cf88b42022-11-07 13:22:3025#include "content/browser/renderer_host/render_frame_host_owner.h"
danakjc492bf82020-09-09 20:02:4426#include "content/common/content_export.h"
Julie Jeongeun Kimf38c1eca2021-12-14 07:46:5527#include "content/public/browser/frame_type.h"
Rakina Zata Amni58681c62024-06-25 06:32:1328#include "content/public/browser/navigation_discard_reason.h"
danakjc492bf82020-09-09 20:02:4429#include "services/network/public/mojom/content_security_policy.mojom-forward.h"
Julie Jeongeun Kim0e242242022-11-30 10:45:0930#include "services/network/public/mojom/referrer_policy.mojom-forward.h"
Kevin McNee43fe8292021-10-04 22:59:4131#include "third_party/blink/public/common/frame/frame_owner_element_type.h"
danakjc492bf82020-09-09 20:02:4432#include "third_party/blink/public/common/frame/frame_policy.h"
danakjc492bf82020-09-09 20:02:4433#include "third_party/blink/public/mojom/frame/frame_owner_properties.mojom.h"
Gyuyoung Kimc16e52e92021-03-19 02:45:3734#include "third_party/blink/public/mojom/frame/frame_replication_state.mojom-forward.h"
Daniel Cheng6ac128172021-05-25 18:49:0135#include "third_party/blink/public/mojom/frame/tree_scope_type.mojom.h"
David Sanders2c1194d92022-04-19 23:32:3236#include "third_party/blink/public/mojom/frame/user_activation_update_types.mojom-forward.h"
Miyoung Shinaf9a34362023-01-31 02:46:5137#include "third_party/blink/public/mojom/webauthn/virtual_authenticator.mojom-forward.h"
danakjc492bf82020-09-09 20:02:4438#include "url/gurl.h"
39#include "url/origin.h"
40
41namespace content {
42
43class NavigationRequest;
danakjc492bf82020-09-09 20:02:4444class NavigationEntryImpl;
Paul Semel3e241042022-10-11 12:57:3145class FrameTree;
danakjc492bf82020-09-09 20:02:4446
47// When a page contains iframes, its renderer process maintains a tree structure
48// of those frames. We are mirroring this tree in the browser process. This
49// class represents a node in this tree and is a wrapper for all objects that
50// are frame-specific (as opposed to page-specific).
51//
52// Each FrameTreeNode has a current RenderFrameHost, which can change over
53// time as the frame is navigated. Any immediate subframes of the current
54// document are tracked using FrameTreeNodes owned by the current
55// RenderFrameHost, rather than as children of FrameTreeNode itself. This
56// allows subframe FrameTreeNodes to stay alive while a RenderFrameHost is
57// still alive - for example while pending deletion, after a new current
58// RenderFrameHost has replaced it.
Miyoung Shin7cf88b42022-11-07 13:22:3059class CONTENT_EXPORT FrameTreeNode : public RenderFrameHostOwner {
danakjc492bf82020-09-09 20:02:4460 public:
61 class Observer {
62 public:
63 // Invoked when a FrameTreeNode is being destroyed.
64 virtual void OnFrameTreeNodeDestroyed(FrameTreeNode* node) {}
65
66 // Invoked when a FrameTreeNode becomes focused.
67 virtual void OnFrameTreeNodeFocused(FrameTreeNode* node) {}
68
Arthur Hemerye4659282022-03-28 08:36:1569 // Invoked when a FrameTreeNode moves to a different BrowsingInstance and
70 // the popups it opened should be disowned.
71 virtual void OnFrameTreeNodeDisownedOpenee(FrameTreeNode* node) {}
72
Fergal Dalya1d569972021-03-16 03:24:5373 virtual ~Observer() = default;
danakjc492bf82020-09-09 20:02:4474 };
75
danakjc492bf82020-09-09 20:02:4476 // Returns the FrameTreeNode with the given global |frame_tree_node_id|,
77 // regardless of which FrameTree it is in.
Avi Drissmanbd153642024-09-03 18:58:0578 static FrameTreeNode* GloballyFindByID(FrameTreeNodeId frame_tree_node_id);
danakjc492bf82020-09-09 20:02:4479
80 // Returns the FrameTreeNode for the given |rfh|. Same as
81 // rfh->frame_tree_node(), but also supports nullptrs.
82 static FrameTreeNode* From(RenderFrameHost* rfh);
83
84 // Callers are are expected to initialize sandbox flags separately after
85 // calling the constructor.
86 FrameTreeNode(
Arthur Sonzognif6785ec2022-12-05 10:11:5087 FrameTree& frame_tree,
danakjc492bf82020-09-09 20:02:4488 RenderFrameHostImpl* parent,
Daniel Cheng6ac128172021-05-25 18:49:0189 blink::mojom::TreeScopeType tree_scope_type,
danakjc492bf82020-09-09 20:02:4490 bool is_created_by_script,
danakjc492bf82020-09-09 20:02:4491 const blink::mojom::FrameOwnerProperties& frame_owner_properties,
Kevin McNee43fe8292021-10-04 22:59:4192 blink::FrameOwnerElementType owner_type,
Dominic Farolino08662c82021-06-11 07:36:3493 const blink::FramePolicy& frame_owner);
danakjc492bf82020-09-09 20:02:4494
Peter Boström828b9022021-09-21 02:28:4395 FrameTreeNode(const FrameTreeNode&) = delete;
96 FrameTreeNode& operator=(const FrameTreeNode&) = delete;
97
Miyoung Shin7cf88b42022-11-07 13:22:3098 ~FrameTreeNode() override;
danakjc492bf82020-09-09 20:02:4499
100 void AddObserver(Observer* observer);
101 void RemoveObserver(Observer* observer);
102
Ian Vollick25a9d032022-04-12 23:20:17103 // Frame trees may be nested so it can be the case that IsMainFrame() is true,
104 // but is not the outermost main frame. In particular, !IsMainFrame() cannot
105 // be used to check if the frame is an embedded frame -- use
106 // !IsOutermostMainFrame() instead. NB: this does not escape guest views;
107 // IsOutermostMainFrame will be true for the outermost main frame in an inner
108 // guest view.
danakjc492bf82020-09-09 20:02:44109 bool IsMainFrame() const;
Arthur Hemerya06697f2023-03-14 09:20:57110 bool IsOutermostMainFrame() const;
danakjc492bf82020-09-09 20:02:44111
Arthur Sonzognif6785ec2022-12-05 10:11:50112 FrameTree& frame_tree() const { return frame_tree_.get(); }
Paul Semel3e241042022-10-11 12:57:31113 Navigator& navigator();
danakjc492bf82020-09-09 20:02:44114
115 RenderFrameHostManager* render_manager() { return &render_manager_; }
Alexander Timin33e2e2c12022-03-03 04:21:33116 const RenderFrameHostManager* render_manager() const {
117 return &render_manager_;
118 }
Avi Drissmanbd153642024-09-03 18:58:05119 FrameTreeNodeId frame_tree_node_id() const { return frame_tree_node_id_; }
Yuzu Saijo03dbf9b2022-07-22 04:29:45120 // This reflects window.name, which is initially set to the the "name"
121 // attribute. But this won't reflect changes of 'name' attribute and instead
122 // reflect changes to the Window object's name property.
123 // This is different from IframeAttributes' name in that this will not get
124 // updated when 'name' attribute gets updated.
Harkiran Bolaria4eacb3a2021-12-13 20:03:47125 const std::string& frame_name() const {
126 return render_manager_.current_replication_state().name;
127 }
danakjc492bf82020-09-09 20:02:44128
129 const std::string& unique_name() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47130 return render_manager_.current_replication_state().unique_name;
danakjc492bf82020-09-09 20:02:44131 }
132
danakjc492bf82020-09-09 20:02:44133 size_t child_count() const { return current_frame_host()->child_count(); }
134
danakjc492bf82020-09-09 20:02:44135 RenderFrameHostImpl* parent() const { return parent_; }
136
Dave Tapuskac8de3b02021-12-03 21:51:01137 // See `RenderFrameHost::GetParentOrOuterDocument()` for
138 // documentation.
Arthur Hemerya06697f2023-03-14 09:20:57139 RenderFrameHostImpl* GetParentOrOuterDocument() const;
Dave Tapuskac8de3b02021-12-03 21:51:01140
141 // See `RenderFrameHostImpl::GetParentOrOuterDocumentOrEmbedder()` for
142 // documentation.
143 RenderFrameHostImpl* GetParentOrOuterDocumentOrEmbedder();
144
danakjc492bf82020-09-09 20:02:44145 FrameTreeNode* opener() const { return opener_; }
146
Rakina Zata Amni3a48ae42022-05-05 03:39:56147 FrameTreeNode* first_live_main_frame_in_original_opener_chain() const {
148 return first_live_main_frame_in_original_opener_chain_;
149 }
danakjc492bf82020-09-09 20:02:44150
Arthur Sonzognic686e8f2024-01-11 08:36:37151 const std::optional<base::UnguessableToken>& opener_devtools_frame_token() {
Wolfgang Beyerd8809db2020-09-30 15:29:39152 return opener_devtools_frame_token_;
153 }
154
Julie Jeongeun Kimf38c1eca2021-12-14 07:46:55155 // Returns the type of the frame. Refer to frame_type.h for the details.
156 FrameType GetFrameType() const;
157
danakjc492bf82020-09-09 20:02:44158 // Assigns a new opener for this node and, if |opener| is non-null, registers
159 // an observer that will clear this node's opener if |opener| is ever
160 // destroyed.
161 void SetOpener(FrameTreeNode* opener);
162
163 // Assigns the initial opener for this node, and if |opener| is non-null,
164 // registers an observer that will clear this node's opener if |opener| is
165 // ever destroyed. The value set here is the root of the tree.
166 //
167 // It is not possible to change the opener once it was set.
168 void SetOriginalOpener(FrameTreeNode* opener);
169
Wolfgang Beyerd8809db2020-09-30 15:29:39170 // Assigns an opener frame id for this node. This string id is only set once
171 // and cannot be changed. It persists, even if the |opener| is destroyed. It
172 // is used for attribution in the DevTools frontend.
173 void SetOpenerDevtoolsFrameToken(
174 base::UnguessableToken opener_devtools_frame_token);
175
danakjc492bf82020-09-09 20:02:44176 FrameTreeNode* child_at(size_t index) const {
177 return current_frame_host()->child_at(index);
178 }
179
180 // Returns the URL of the last committed page in the current frame.
181 const GURL& current_url() const {
182 return current_frame_host()->GetLastCommittedURL();
183 }
184
Charlie Reis734db662024-01-11 18:20:03185 // Moves this frame out of the initial empty document state, which is a
186 // one-way change for FrameTreeNode (i.e., it cannot go back into the initial
187 // empty document state).
188 void set_not_on_initial_empty_document() {
189 is_on_initial_empty_document_ = false;
190 }
191
192 // Returns false if the frame has committed a document that is not the initial
193 // empty document, or if the current document's input stream has been opened
194 // with document.open(), causing the document to lose its "initial empty
195 // document" status. For more details, see the definition of
196 // `is_on_initial_empty_document_`.
Rakina Zata Amni86c88fa2021-11-01 01:27:30197 bool is_on_initial_empty_document() const {
Charlie Reis734db662024-01-11 18:20:03198 return is_on_initial_empty_document_;
Rakina Zata Amnifc4cc3d42021-06-10 09:03:56199 }
200
danakjc492bf82020-09-09 20:02:44201 // Returns whether the frame's owner element in the parent document is
202 // collapsed, that is, removed from the layout as if it did not exist, as per
203 // request by the embedder (of the content/ layer).
204 bool is_collapsed() const { return is_collapsed_; }
205
206 // Sets whether to collapse the frame's owner element in the parent document,
207 // that is, to remove it from the layout as if it did not exist, as per
208 // request by the embedder (of the content/ layer). Cannot be called for main
209 // frames.
210 //
211 // This only has an effect for <iframe> owner elements, and is a no-op when
212 // called on sub-frames hosted in <frame>, <object>, and <embed> elements.
213 void SetCollapsed(bool collapsed);
214
215 // Returns the origin of the last committed page in this frame.
216 // WARNING: To get the last committed origin for a particular
217 // RenderFrameHost, use RenderFrameHost::GetLastCommittedOrigin() instead,
218 // which will behave correctly even when the RenderFrameHost is not the
219 // current one for this frame (such as when it's pending deletion).
220 const url::Origin& current_origin() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47221 return render_manager_.current_replication_state().origin;
danakjc492bf82020-09-09 20:02:44222 }
223
danakjc492bf82020-09-09 20:02:44224 // Returns the latest frame policy (sandbox flags and container policy) for
225 // this frame. This includes flags inherited from parent frames and the latest
226 // flags from the <iframe> element hosting this frame. The returned policies
227 // may not yet have taken effect, since "sandbox" and "allow" attribute
Liam Brady25a14162022-12-02 15:25:57228 // updates in an <iframe> element take effect on next navigation. For
229 // <fencedframe> elements, not everything in the frame policy might actually
230 // take effect after the navigation. To retrieve the currently active policy
231 // for this frame, use effective_frame_policy().
danakjc492bf82020-09-09 20:02:44232 const blink::FramePolicy& pending_frame_policy() const {
233 return pending_frame_policy_;
234 }
235
236 // Update this frame's sandbox flags and container policy. This is called
237 // when a parent frame updates the "sandbox" attribute in the <iframe> element
238 // for this frame, or any of the attributes which affect the container policy
239 // ("allowfullscreen", "allowpaymentrequest", "allow", and "src".)
240 // These policies won't take effect until next navigation. If this frame's
241 // parent is itself sandboxed, the parent's sandbox flags are combined with
242 // those in |frame_policy|.
243 // Attempting to change the container policy on the main frame will have no
244 // effect.
245 void SetPendingFramePolicy(blink::FramePolicy frame_policy);
246
247 // Returns the currently active frame policy for this frame, including the
248 // sandbox flags which were present at the time the document was loaded, and
Charlie Hu5130d25e2021-03-05 21:53:39249 // the permissions policy container policy, which is set by the iframe's
danakjc492bf82020-09-09 20:02:44250 // allowfullscreen, allowpaymentrequest, and allow attributes, along with the
251 // origin of the iframe's src attribute (which may be different from the URL
252 // of the document currently loaded into the frame). This does not include
253 // policy changes that have been made by updating the containing iframe
254 // element attributes since the frame was last navigated; use
255 // pending_frame_policy() for those.
256 const blink::FramePolicy& effective_frame_policy() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47257 return render_manager_.current_replication_state().frame_policy;
danakjc492bf82020-09-09 20:02:44258 }
259
danakjc492bf82020-09-09 20:02:44260 const blink::mojom::FrameOwnerProperties& frame_owner_properties() {
261 return frame_owner_properties_;
262 }
263
264 void set_frame_owner_properties(
265 const blink::mojom::FrameOwnerProperties& frame_owner_properties) {
266 frame_owner_properties_ = frame_owner_properties;
267 }
268
Yuzu Saijo03dbf9b2022-07-22 04:29:45269 // Reflects the attributes of the corresponding iframe html element, such
Arthur Sonzogni64457592022-11-22 11:08:59270 // as 'credentialless', 'id', 'name' and 'src'. These values should not be
Yuzu Saijo03dbf9b2022-07-22 04:29:45271 // exposed to cross-origin renderers.
272 const network::mojom::ContentSecurityPolicy* csp_attribute() const {
273 return attributes_->parsed_csp_attribute.get();
danakjc492bf82020-09-09 20:02:44274 }
Yao Xiao9c54b3e2023-03-14 04:25:04275 // Tracks iframe's 'browsingtopics' attribute, indicating whether the
276 // navigation requests on this frame should calculate and send the
277 // `Sec-Browsing-Topics` header.
278 bool browsing_topics() const { return attributes_->browsing_topics; }
Camillia Smith Barnes6d2966c82023-08-23 21:16:18279
Orr Bernsteina0cc6792023-11-14 22:12:35280 // Tracks iframe's 'adauctionheaders' attribute, indicating whether the
281 // navigation request on this frame should calculate and send the
282 // 'Sec-Ad-Auction-Fetch` header.
283 bool ad_auction_headers() const { return attributes_->ad_auction_headers; }
284
Camillia Smith Barnes6d2966c82023-08-23 21:16:18285 // Tracks iframe's 'sharedstoragewritable' attribute, indicating what value
Camillia Smith Barnesc267be62023-11-01 20:01:02286 // the the corresponding
287 // `network::ResourceRequest::shared_storage_writable_eligible` should take
288 // for the navigation(s) on this frame, pending a permissions policy check. If
289 // true, and if the permissions policy check returns "enabled", the network
Camillia Smith Barnes6d2966c82023-08-23 21:16:18290 // service will send the `Shared-Storage-Write` request header.
Camillia Smith Barnesc267be62023-11-01 20:01:02291 bool shared_storage_writable_opted_in() const {
292 return attributes_->shared_storage_writable_opted_in;
Camillia Smith Barnes6d2966c82023-08-23 21:16:18293 }
Arthur Sonzognic686e8f2024-01-11 08:36:37294 const std::optional<std::string> html_id() const { return attributes_->id; }
Yuzu Saijo03dbf9b2022-07-22 04:29:45295 // This tracks iframe's 'name' attribute instead of window.name, which is
296 // tracked in FrameReplicationState. See the comment for frame_name() for
297 // more details.
Arthur Sonzognic686e8f2024-01-11 08:36:37298 const std::optional<std::string> html_name() const {
Yuzu Saijodc870f92023-01-20 03:39:11299 return attributes_->name;
300 }
Arthur Sonzognic686e8f2024-01-11 08:36:37301 const std::optional<std::string> html_src() const { return attributes_->src; }
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).
Rakina Zata Amni58681c62024-06-25 06:32:13350 void ResetNavigationRequestButKeepState(NavigationDiscardReason reason);
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
murakinonoka97a8f042024-01-10 09:17:07464 // Returns true if there are any navigations happening in FrameTreeNode that
465 // is pending commit (i.e. between ReadyToCommit and DidCommit). Note that
466 // those navigations won't live in the FrameTreeNode itself, as they will
467 // already be owned by the committing RenderFrameHost (either the current
468 // RenderFrameHost or the speculative RenderFrameHost).
469 bool HasPendingCommitNavigation();
470
shivanigithubf3ddff52021-07-03 22:06:30471 // Fenced frames (meta-bug crbug.com/1111084):
shivanigithub4cd016a2021-09-20 21:10:30472 // Note that these two functions cannot be invoked from a FrameTree's or
473 // its root node's constructor since they require the frame tree and the
474 // root node to be completely constructed.
475 //
shivanigithubf3ddff52021-07-03 22:06:30476 // Returns false if fenced frames are disabled. Returns true if the feature is
477 // enabled and if |this| is a fenced frame. Returns false for
478 // iframes embedded in a fenced frame. To clarify: for the MPArch
479 // implementation this only returns true if |this| is the actual
480 // root node of the inner FrameTree and not the proxy FrameTreeNode in the
481 // outer FrameTree.
Dominic Farolino4bc10ee2021-08-31 00:37:36482 bool IsFencedFrameRoot() const;
shivanigithubf3ddff52021-07-03 22:06:30483
484 // Returns false if fenced frames are disabled. Returns true if the
485 // feature is enabled and if |this| or any of its ancestor nodes is a
486 // fenced frame.
487 bool IsInFencedFrameTree() const;
488
shivanigithub4cd016a2021-09-20 21:10:30489 // Returns a valid nonce if `IsInFencedFrameTree()` returns true for `this`.
Garrett Tanzer34cb92fe2022-09-28 17:50:54490 // Returns nullopt otherwise.
491 //
492 // Nonce used in the net::IsolationInfo and blink::StorageKey for a fenced
493 // frame and any iframes nested within it. Not set if this frame is not in a
494 // fenced frame's FrameTree. Note that this could be a field in FrameTree for
495 // the MPArch version but for the shadow DOM version we need to keep it here
496 // since the fenced frame root is not a main frame for the latter. The value
497 // of the nonce will be the same for all of the the iframes inside a fenced
498 // frame tree. If there is a nested fenced frame it will have a different
499 // nonce than its parent fenced frame. The nonce will stay the same across
500 // navigations initiated from the fenced frame tree because it is always used
501 // in conjunction with other fields of the keys and would be good to access
502 // the same storage across same-origin navigations. If the navigation is
503 // same-origin/site then the same network stack partition/storage will be
504 // reused and if it's cross-origin/site then other parts of the key will
505 // change and so, even with the same nonce, another partition will be used.
506 // But if the navigation is initiated from the embedder, the nonce will be
507 // reinitialized irrespective of same or cross origin such that there is no
508 // privacy leak via storage shared between two embedder initiated navigations.
509 // Note that this reinitialization is implemented for all embedder-initiated
510 // navigations in MPArch, but only urn:uuid navigations in ShadowDOM.
Arthur Sonzognic686e8f2024-01-11 08:36:37511 std::optional<base::UnguessableToken> GetFencedFrameNonce();
shivanigithub4cd016a2021-09-20 21:10:30512
Garrett Tanzer34cb92fe2022-09-28 17:50:54513 // If applicable, initialize the default fenced frame properties. Right now,
514 // this means setting a new fenced frame nonce. See comment on
shivanigithub4cd016a2021-09-20 21:10:30515 // fenced_frame_nonce() for when it is set to a non-null value. Invoked
516 // by FrameTree::Init() or FrameTree::AddFrame().
Garrett Tanzer34cb92fe2022-09-28 17:50:54517 void SetFencedFramePropertiesIfNeeded();
shivanigithub4cd016a2021-09-20 21:10:30518
Garrett Tanzer291a2d52023-03-20 22:41:57519 // Set the current FencedFrameProperties to have "opaque ads mode".
520 // This should only be used during tests, when the proper embedder-initiated
521 // fenced frame root urn/config navigation flow isn't available.
Alison Gale770f3fc2024-04-27 00:39:58522 // TODO(crbug.com/40233168): Refactor and expand use of test utils so there is
Garrett Tanzer291a2d52023-03-20 22:41:57523 // a consistent way to do this properly everywhere. Consider removing
524 // arbitrary restrictions in "default mode" so that using opaque ads mode is
525 // less necessary.
526 void SetFencedFramePropertiesOpaqueAdsModeForTesting() {
527 if (fenced_frame_properties_.has_value()) {
Garrett Tanzer06980702023-12-12 19:48:20528 fenced_frame_properties_
529 ->SetFencedFramePropertiesOpaqueAdsModeForTesting();
Garrett Tanzer291a2d52023-03-20 22:41:57530 }
531 }
532
533 // Returns the mode attribute from the `FencedFrameProperties` if this frame
534 // is in a fenced frame tree, otherwise returns `kDefault`.
535 blink::FencedFrame::DeprecatedFencedFrameMode GetDeprecatedFencedFrameMode();
Nan Lin171fe9a2022-02-17 16:42:16536
Dave Tapuskac8de3b02021-12-03 21:51:01537 // Helper for GetParentOrOuterDocument/GetParentOrOuterDocumentOrEmbedder.
538 // Do not use directly.
Kevin McNee86e64ee2023-02-17 16:35:50539 // `escape_guest_view` determines whether to iterate out of guest views and is
540 // the behaviour distinction between GetParentOrOuterDocument and
541 // GetParentOrOuterDocumentOrEmbedder. See the comment on
542 // GetParentOrOuterDocumentOrEmbedder for details.
543 // `include_prospective` includes embedders which own our frame tree, but have
544 // not yet attached it to the outer frame tree.
Arthur Hemerya06697f2023-03-14 09:20:57545 RenderFrameHostImpl* GetParentOrOuterDocumentHelper(
546 bool escape_guest_view,
547 bool include_prospective) const;
Dave Tapuskac8de3b02021-12-03 21:51:01548
Harkiran Bolariab4437fd2021-08-11 17:51:22549 // Sets the unique_name and name fields on replication_state_. To be used in
550 // prerender activation to make sure the FrameTreeNode replication state is
551 // correct after the RenderFrameHost is moved between FrameTreeNodes. The
552 // renderers should already have the correct value, so unlike
553 // FrameTreeNode::SetFrameName, we do not notify them here.
Alison Gale770f3fc2024-04-27 00:39:58554 // TODO(crbug.com/40192974): Remove this once the BrowsingContextState
Harkiran Bolaria4eacb3a2021-12-13 20:03:47555 // is implemented to utilize the new path.
Harkiran Bolariab4437fd2021-08-11 17:51:22556 void set_frame_name_for_activation(const std::string& unique_name,
557 const std::string& name) {
Harkiran Bolaria0b3bdef02022-03-10 13:04:40558 current_frame_host()->browsing_context_state()->set_frame_name(unique_name,
559 name);
Harkiran Bolariab4437fd2021-08-11 17:51:22560 }
561
Nan Linaaf84f72021-12-02 22:31:56562 // Returns true if error page isolation is enabled.
563 bool IsErrorPageIsolationEnabled() const;
564
W. James MacLean81b8d01f2022-01-25 20:50:59565 // Functions to store and retrieve a frame's srcdoc value on this
566 // FrameTreeNode.
567 void SetSrcdocValue(const std::string& srcdoc_value);
568 const std::string& srcdoc_value() const { return srcdoc_value_; }
569
Garrett Tanzerc69f4642022-08-15 22:15:14570 void set_fenced_frame_properties(
Arthur Sonzognic686e8f2024-01-11 08:36:37571 const std::optional<FencedFrameProperties>& fenced_frame_properties) {
Alison Gale770f3fc2024-04-27 00:39:58572 // TODO(crbug.com/40202462): Reenable this DCHECK once ShadowDOM and
Garrett Tanzer2975eeac2022-08-22 16:34:01573 // loading urns in iframes (for FLEDGE OT) are gone.
574 // DCHECK_EQ(fenced_frame_status_,
575 // RenderFrameHostImpl::FencedFrameStatus::kFencedFrameRoot);
Garrett Tanzerc69f4642022-08-15 22:15:14576 fenced_frame_properties_ = fenced_frame_properties;
577 }
578
Xiaochen Zhou86f2e712023-09-13 19:55:04579 // This function returns the fenced frame properties associated with the given
580 // source.
581 // - If `source_node` is set to `kClosestAncestor`, the fenced frame
582 // properties are obtained by a bottom-up traversal from this node.
583 // - If `source_node` is set tp `kFrameTreeRoot`, the fenced frame properties
584 // from the fenced frame tree root are returned.
585 // For example, for an urn iframe that is nested inside a fenced frame.
586 // Calling this function from the nested urn iframe with `source_node` set to:
587 // - `kClosestAncestor`: returns the fenced frame properties from the urn
588 // iframe.
589 // - `kFrameTreeRoot`: returns the fenced frame properties from the fenced
590 // frame.
591 // Clients should decide which one to use depending on how the application of
592 // the fenced frame properties interact with urn iframes.
Alison Gale770f3fc2024-04-27 00:39:58593 // TODO(crbug.com/40060657): Once navigation support for urn::uuid in iframes
Xiaochen Zhou86f2e712023-09-13 19:55:04594 // is deprecated, remove the parameter `node_source`.
Arthur Sonzognic686e8f2024-01-11 08:36:37595 std::optional<FencedFrameProperties>& GetFencedFrameProperties(
Xiaochen Zhou86f2e712023-09-13 19:55:04596 FencedFramePropertiesNodeSource node_source =
597 FencedFramePropertiesNodeSource::kClosestAncestor);
Garrett Tanzerc69f4642022-08-15 22:15:14598
Liam Brady27da6a22024-06-05 16:35:34599 // Helper function for getting the FrameTreeNode that houses the relevant
600 // FencedFrameProperties when GetFencedFrameProperties() is called with
601 // kClosestAncestor.
602 FrameTreeNode* GetClosestAncestorWithFencedFrameProperties();
603
Liam Brady86ca0482023-12-06 19:49:25604 bool HasFencedFrameProperties() const {
605 return fenced_frame_properties_.has_value();
606 }
607
Yao Xiaof9ae90a2023-03-01 20:52:44608 // Returns the number of fenced frame boundaries above this frame. The
Yao Xiaoa2337ad2022-10-12 20:59:29609 // outermost main frame's frame tree has fenced frame depth 0, a topmost
610 // fenced frame tree embedded in the outermost main frame has fenced frame
611 // depth 1, etc.
Yao Xiaof9ae90a2023-03-01 20:52:44612 //
613 // Also, sets `shared_storage_fenced_frame_root_count` to the
614 // number of fenced frame boundaries (roots) above this frame that originate
615 // from shared storage. This is used to check whether a fenced frame
616 // originates from shared storage only (i.e. not from FLEDGE).
Alison Gale770f3fc2024-04-27 00:39:58617 // TODO(crbug.com/40233168): Remove this check once we put permissions inside
Yao Xiaof9ae90a2023-03-01 20:52:44618 // FencedFrameConfig.
619 size_t GetFencedFrameDepth(size_t& shared_storage_fenced_frame_root_count);
Yao Xiaoa2337ad2022-10-12 20:59:29620
621 // Traverse up from this node. Return all valid
622 // `node->fenced_frame_properties_->shared_storage_budget_metadata` (i.e. this
623 // node is subjected to the shared storage budgeting associated with those
624 // metadata). Every node that originates from sharedStorage.selectURL() will
625 // have an associated metadata. This indicates that the metadata can only
626 // possibly be associated with a fenced frame root, unless when
627 // `kAllowURNsInIframes` is enabled in which case they could be be associated
628 // with any node.
Garrett Tanzer29de7112022-12-06 21:26:32629 std::vector<const SharedStorageBudgetMetadata*>
Yao Xiao1ac702d2022-06-08 17:20:49630 FindSharedStorageBudgetMetadata();
631
Camillia Smith Barnes7218518c2023-03-06 19:02:17632 // Returns any shared storage context string that was written to a
633 // `blink::FencedFrameConfig` before navigation via
634 // `setSharedStorageContext()`, as long as the request is for a same-origin
635 // frame within the config's fenced frame tree (or a same-origin descendant of
636 // a URN iframe).
Arthur Sonzognic686e8f2024-01-11 08:36:37637 std::optional<std::u16string> GetEmbedderSharedStorageContextIfAllowed();
Camillia Smith Barnes7218518c2023-03-06 19:02:17638
Harkiran Bolariaebbe7702022-02-22 19:19:03639 // Accessor to BrowsingContextState for subframes only. Only main frame
640 // navigations can change BrowsingInstances and BrowsingContextStates,
641 // therefore for subframes associated BrowsingContextState never changes. This
642 // helper method makes this more explicit and guards against calling this on
643 // main frames (there an appropriate BrowsingContextState should be obtained
644 // from RenderFrameHost or from RenderFrameProxyHost as e.g. during
645 // cross-BrowsingInstance navigations multiple BrowsingContextStates exist in
646 // the same frame).
647 const scoped_refptr<BrowsingContextState>&
648 GetBrowsingContextStateForSubframe() const;
649
Arthur Hemerye4659282022-03-28 08:36:15650 // Clears the opener property of popups referencing this FrameTreeNode as
651 // their opener.
652 void ClearOpenerReferences();
653
Liam Brady95d36d12023-03-13 21:13:06654 // Calculates whether one of the ancestor frames or this frame has a CSPEE in
655 // place. This is eventually sent over to LocalFrame in the renderer where it
656 // will be used by NavigatorAuction::canLoadAdAuctionFencedFrame for
657 // information it can't get on its own.
Liam Bradyd2a41e152022-07-19 13:58:48658 bool AncestorOrSelfHasCSPEE() const;
659
Arthur Sonzogni8e8eb1f2023-01-10 14:51:01660 // Reset every navigation in this frame, and its descendants. This is called
661 // after the <iframe> element has been removed, or after the document owning
662 // this frame has been navigated away.
663 //
664 // This takes into account:
665 // - Non-pending commit NavigationRequest owned by the FrameTreeNode
666 // - Pending commit NavigationRequest owned by the current RenderFrameHost
667 // - Speculative RenderFrameHost and its pending commit NavigationRequests.
668 void ResetAllNavigationsForFrameDetach();
669
Miyoung Shin7cf88b42022-11-07 13:22:30670 // RenderFrameHostOwner implementation:
Nate Chapin470dbc62023-04-25 16:34:38671 void DidStartLoading(LoadingState previous_frame_tree_loading_state) override;
Julie Jeongeun Kim07c077bd2022-12-05 08:40:31672 void DidStopLoading() override;
Miyoung Shin7cf88b42022-11-07 13:22:30673 void RestartNavigationAsCrossDocument(
674 std::unique_ptr<NavigationRequest> navigation_request) override;
Miyoung Shin1504eb712022-12-07 10:32:18675 bool Reload() override;
Julie Jeongeun Kimc1b07c32022-11-11 10:26:32676 Navigator& GetCurrentNavigator() override;
Miyoung Shine16cd2262022-11-30 05:52:16677 RenderFrameHostManager& GetRenderFrameHostManager() override;
Miyoung Shin64fd1bea2023-01-04 04:22:08678 FrameTreeNode* GetOpener() const override;
Julie Jeongeun Kim2132b37f82022-11-23 08:30:46679 void SetFocusedFrame(SiteInstanceGroup* source) override;
Julie Jeongeun Kim0e242242022-11-30 10:45:09680 void DidChangeReferrerPolicy(
681 network::mojom::ReferrerPolicy referrer_policy) override;
Miyoung Shin8a66ec022022-11-28 23:50:09682 // Updates the user activation state in the browser frame tree and in the
683 // frame trees in all renderer processes except the renderer for this node
684 // (which initiated the update). Returns |false| if the update tries to
685 // consume an already consumed/expired transient state, |true| otherwise. See
686 // the comment on `user_activation_state_` in RenderFrameHostImpl.
687 //
688 // The |notification_type| parameter is used for histograms, only for the case
689 // |update_state == kNotifyActivation|.
690 bool UpdateUserActivationState(
691 blink::mojom::UserActivationUpdateType update_type,
692 blink::mojom::UserActivationNotificationType notification_type) override;
Nate Chapin47276a62023-02-16 16:53:44693 void DidConsumeHistoryUserActivation() override;
Charlie Reis734db662024-01-11 18:20:03694 void DidOpenDocumentInputStream() override;
Miyoung Shinff13ed22022-11-30 09:21:47695 std::unique_ptr<NavigationRequest>
696 CreateNavigationRequestForSynchronousRendererCommit(
697 RenderFrameHostImpl* render_frame_host,
698 bool is_same_document,
699 const GURL& url,
700 const url::Origin& origin,
Arthur Sonzognic686e8f2024-01-11 08:36:37701 const std::optional<GURL>& initiator_base_url,
Miyoung Shinff13ed22022-11-30 09:21:47702 const net::IsolationInfo& isolation_info_for_subresources,
703 blink::mojom::ReferrerPtr referrer,
704 const ui::PageTransition& transition,
705 bool should_replace_current_entry,
706 const std::string& method,
707 bool has_transient_activation,
708 bool is_overriding_user_agent,
709 const std::vector<GURL>& redirects,
710 const GURL& original_url,
711 std::unique_ptr<CrossOriginEmbedderPolicyReporter> coep_reporter,
Miyoung Shinff13ed22022-11-30 09:21:47712 int http_response_code) override;
Rakina Zata Amni58681c62024-06-25 06:32:13713 void CancelNavigation(NavigationDiscardReason reason) override;
Thomas Lukaszewicz1b672fe2024-09-17 08:35:03714 void ResetNavigationsForDiscard() override;
Miyoung Shinc9ff4812023-01-05 08:58:05715 bool Credentialless() const override;
Miyoung Shinaf9a34362023-01-31 02:46:51716#if !BUILDFLAG(IS_ANDROID)
717 void GetVirtualAuthenticatorManager(
718 mojo::PendingReceiver<blink::test::mojom::VirtualAuthenticatorManager>
719 receiver) override;
720#endif
Kevin McNeef1b0f0b2024-09-17 21:49:41721 FrameType GetCurrentFrameType() const override;
Miyoung Shinff13ed22022-11-30 09:21:47722
Mingyu Lei7956b8b2023-07-24 08:24:08723 // Restart the navigation restoring the page from the back-forward cache
724 // as a regular non-BFCached history navigation.
725 //
726 // The restart itself is asynchronous as it's dangerous to restart navigation
727 // with arbitrary state on the stack (another navigation might be starting),
728 // so this function only posts the actual task to do all the work (See
729 // `RestartBackForwardCachedNavigationImpl()`).
730 void RestartBackForwardCachedNavigationAsync(int nav_entry_id);
731
732 // Cancel the asynchronous task that would restart the BFCache navigation.
733 // This should be called whenever a FrameTreeNode's NavigationRequest would
734 // normally get cancelled, including when another NavigationRequest starts.
735 // This preserves the previous behavior where a restarting BFCache
736 // NavigationRequest is kept around until the task to create the new
737 // navigation is run, or until that NavigationRequest gets deleted (which
738 // cancels the task).
739 void CancelRestartingBackForwardCacheNavigation();
740
Christian Biesingere1865c57c2023-10-20 15:19:29741 base::SafeRef<FrameTreeNode> GetSafeRef() {
742 return weak_factory_.GetSafeRef();
743 }
744
danakjc492bf82020-09-09 20:02:44745 private:
Yuzu Saijo03dbf9b2022-07-22 04:29:45746 friend class CSPEmbeddedEnforcementUnitTest;
Charlie Hubb5943d2021-03-09 19:46:12747 FRIEND_TEST_ALL_PREFIXES(SitePerProcessPermissionsPolicyBrowserTest,
danakjc492bf82020-09-09 20:02:44748 ContainerPolicyDynamic);
Charlie Hubb5943d2021-03-09 19:46:12749 FRIEND_TEST_ALL_PREFIXES(SitePerProcessPermissionsPolicyBrowserTest,
danakjc492bf82020-09-09 20:02:44750 ContainerPolicySandboxDynamic);
Yuzu Saijo03dbf9b2022-07-22 04:29:45751 FRIEND_TEST_ALL_PREFIXES(NavigationRequestTest, StorageKeyToCommit);
Arthur Sonzogni64457592022-11-22 11:08:59752 FRIEND_TEST_ALL_PREFIXES(
753 NavigationRequestTest,
754 NavigationToCredentiallessDocumentNetworkIsolationInfo);
Yuzu Saijo03dbf9b2022-07-22 04:29:45755 FRIEND_TEST_ALL_PREFIXES(RenderFrameHostImplTest,
Arthur Sonzogni64457592022-11-22 11:08:59756 ChildOfCredentiallessIsCredentialless);
Yifan Luo86a79f42022-08-16 18:38:27757 FRIEND_TEST_ALL_PREFIXES(ContentPasswordManagerDriverTest,
Arthur Sonzogni64457592022-11-22 11:08:59758 PasswordAutofillDisabledOnCredentiallessIframe);
danakjc492bf82020-09-09 20:02:44759
Dominic Farolino8a2187b2021-12-24 20:44:21760 // Called by the destructor. When `this` is an outer dummy FrameTreeNode
761 // representing an inner FrameTree, this method destroys said inner FrameTree.
762 void DestroyInnerFrameTreeIfExists();
763
danakjc492bf82020-09-09 20:02:44764 class OpenerDestroyedObserver;
765
danakjc492bf82020-09-09 20:02:44766 // The |notification_type| parameter is used for histograms only.
Liam Brady38b84562024-03-07 22:11:26767 // |sticky_only| is set to true when propagating sticky user activation during
768 // cross-document navigations. The transient state remains unchanged.
danakjc492bf82020-09-09 20:02:44769 bool NotifyUserActivation(
Liam Brady38b84562024-03-07 22:11:26770 blink::mojom::UserActivationNotificationType notification_type,
771 bool sticky_only = false);
772
773 bool NotifyUserActivationStickyOnly();
danakjc492bf82020-09-09 20:02:44774
775 bool ConsumeTransientUserActivation();
776
777 bool ClearUserActivation();
778
779 // Verify that the renderer process is allowed to set user activation on this
780 // frame by checking whether this frame's RenderWidgetHost had previously seen
781 // an input event that might lead to user activation. If user activation
782 // should be allowed, this returns true and also clears corresponding pending
783 // user activation state in the widget. Otherwise, this returns false.
784 bool VerifyUserActivation();
785
Mingyu Lei7956b8b2023-07-24 08:24:08786 // See `RestartBackForwardCachedNavigationAsync()`.
787 void RestartBackForwardCachedNavigationImpl(int nav_entry_id);
788
Avi Drissmanbd153642024-09-03 18:58:05789 // The browser-global FrameTreeNodeId generator.
790 static FrameTreeNodeId::Generator frame_tree_node_id_generator_;
danakjc492bf82020-09-09 20:02:44791
Arthur Sonzognif6785ec2022-12-05 10:11:50792 // The FrameTree owning |this|. It can change with Prerender2 during
793 // activation.
794 raw_ref<FrameTree> frame_tree_;
danakjc492bf82020-09-09 20:02:44795
danakjc492bf82020-09-09 20:02:44796 // A browser-global identifier for the frame in the page, which stays stable
797 // even if the frame does a cross-process navigation.
Avi Drissmanbd153642024-09-03 18:58:05798 const FrameTreeNodeId frame_tree_node_id_;
danakjc492bf82020-09-09 20:02:44799
800 // The RenderFrameHost owning this FrameTreeNode, which cannot change for the
801 // life of this FrameTreeNode. |nullptr| if this node is the root.
Keishi Hattori0e45c022021-11-27 09:25:52802 const raw_ptr<RenderFrameHostImpl> parent_;
danakjc492bf82020-09-09 20:02:44803
danakjc492bf82020-09-09 20:02:44804 // The frame that opened this frame, if any. Will be set to null if the
805 // opener is closed, or if this frame disowns its opener by setting its
806 // window.opener to null.
Keishi Hattori0e45c022021-11-27 09:25:52807 raw_ptr<FrameTreeNode> opener_ = nullptr;
danakjc492bf82020-09-09 20:02:44808
809 // An observer that clears this node's |opener_| if the opener is destroyed.
810 // This observer is added to the |opener_|'s observer list when the |opener_|
811 // is set to a non-null node, and it is removed from that list when |opener_|
812 // changes or when this node is destroyed. It is also cleared if |opener_|
813 // is disowned.
814 std::unique_ptr<OpenerDestroyedObserver> opener_observer_;
815
Rakina Zata Amni3a48ae42022-05-05 03:39:56816 // Unlike `opener_`, the "original opener chain" doesn't reflect
817 // window.opener, which can be suppressed or updated. The "original opener"
818 // is the main frame of the actual opener of this frame. This traces the all
819 // the way back, so if the original opener was closed (deleted or severed due
820 // to COOP), but _it_ had an original opener, this will return the original
821 // opener's original opener, etc. So this value will always be set as long as
822 // there is at least one live frame in the chain whose connection is not
823 // severed due to COOP.
824 raw_ptr<FrameTreeNode> first_live_main_frame_in_original_opener_chain_ =
825 nullptr;
danakjc492bf82020-09-09 20:02:44826
Wolfgang Beyerd8809db2020-09-30 15:29:39827 // The devtools frame token of the frame which opened this frame. This is
828 // not cleared even if the opener is destroyed or disowns the frame.
Arthur Sonzognic686e8f2024-01-11 08:36:37829 std::optional<base::UnguessableToken> opener_devtools_frame_token_;
Wolfgang Beyerd8809db2020-09-30 15:29:39830
Rakina Zata Amni3a48ae42022-05-05 03:39:56831 // An observer that updates this node's
832 // |first_live_main_frame_in_original_opener_chain_| to the next original
833 // opener in the chain if the original opener is destroyed.
danakjc492bf82020-09-09 20:02:44834 std::unique_ptr<OpenerDestroyedObserver> original_opener_observer_;
835
arthursonzogni034bb9c2020-10-01 08:29:56836 // When created by an opener, the URL specified in window.open(url)
837 // Please refer to {Get,Set}InitialPopupURL() documentation.
838 GURL initial_popup_url_;
839
840 // When created using window.open, the origin of the creator.
841 // Please refer to {Get,Set}PopupCreatorOrigin() documentation.
842 url::Origin popup_creator_origin_;
843
W. James MacLean81b8d01f2022-01-25 20:50:59844 // If the url from the the last BeginNavigation is about:srcdoc, this value
845 // stores the srcdoc_attribute's value for re-use in history navigations.
846 std::string srcdoc_value_;
847
Charlie Reis734db662024-01-11 18:20:03848 // Whether this frame is still on the initial about:blank document or the
849 // synchronously committed about:blank document committed at frame creation,
850 // and its "initial empty document"-ness is still true.
851 // This will be false if either of these has happened:
852 // - The current RenderFrameHost commits a cross-document navigation that is
853 // not the synchronously committed about:blank document per:
854 // https://html.spec.whatwg.org/multipage/browsers.html#creating-browsing-contexts:is-initial-about:blank
855 // - The document's input stream has been opened with document.open(), per
856 // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#opening-the-input-stream:is-initial-about:blank
857 // NOTE: we treat both the "initial about:blank document" and the
858 // "synchronously committed about:blank document" as the initial empty
859 // document. In the future, we plan to remove the synchronous about:blank
860 // commit so that this state will only be true if the frame is on the
861 // "initial about:blank document". See also:
862 // - https://github.com/whatwg/html/issues/6863
863 // - https://crbug.com/1215096
864 //
865 // Note that cross-document navigations update this state at
866 // DidCommitNavigation() time. Thus, this is still true when a cross-document
867 // navigation from an initial empty document is in the pending-commit window,
868 // after sending the CommitNavigation IPC but before receiving
869 // DidCommitNavigation(). This is in contrast to
870 // has_committed_any_navigation(), which is updated in CommitNavigation().
871 // TODO(alexmos): Consider updating this at CommitNavigation() time as well to
872 // match the has_committed_any_navigation() behavior.
873 bool is_on_initial_empty_document_ = true;
874
danakjc492bf82020-09-09 20:02:44875 // Whether the frame's owner element in the parent document is collapsed.
arthursonzogni9816b9192021-03-29 16:09:19876 bool is_collapsed_ = false;
danakjc492bf82020-09-09 20:02:44877
Daniel Cheng6ac128172021-05-25 18:49:01878 // The type of frame owner for this frame. This is only relevant for non-main
879 // frames.
Kevin McNee43fe8292021-10-04 22:59:41880 const blink::FrameOwnerElementType frame_owner_element_type_ =
881 blink::FrameOwnerElementType::kNone;
Daniel Cheng9bd90f92021-04-23 20:49:45882
Daniel Cheng6ac128172021-05-25 18:49:01883 // The tree scope type of frame owner element, i.e. whether the element is in
884 // the document tree (https://dom.spec.whatwg.org/#document-trees) or the
885 // shadow tree (https://dom.spec.whatwg.org/#shadow-trees). This is only
886 // relevant for non-main frames.
887 const blink::mojom::TreeScopeType tree_scope_type_ =
888 blink::mojom::TreeScopeType::kDocument;
889
danakjc492bf82020-09-09 20:02:44890 // Track the pending sandbox flags and container policy for this frame. When a
891 // parent frame dynamically updates 'sandbox', 'allow', 'allowfullscreen',
892 // 'allowpaymentrequest' or 'src' attributes, the updated policy for the frame
Harkiran Bolaria4eacb3a2021-12-13 20:03:47893 // is stored here, and transferred into
894 // render_manager_.current_replication_state().frame_policy when they take
895 // effect on the next frame navigation.
danakjc492bf82020-09-09 20:02:44896 blink::FramePolicy pending_frame_policy_;
897
898 // Whether the frame was created by javascript. This is useful to prune
899 // history entries when the frame is removed (because frames created by
900 // scripts are never recreated with the same unique name - see
901 // https://crbug.com/500260).
arthursonzogni9816b9192021-03-29 16:09:19902 const bool is_created_by_script_;
danakjc492bf82020-09-09 20:02:44903
danakjc492bf82020-09-09 20:02:44904 // Tracks the scrolling and margin properties for this frame. These
905 // properties affect the child renderer but are stored on its parent's
906 // frame element. When this frame's parent dynamically updates these
907 // properties, we update them here too.
908 //
909 // Note that dynamic updates only take effect on the next frame navigation.
910 blink::mojom::FrameOwnerProperties frame_owner_properties_;
911
Yuzu Saijo03dbf9b2022-07-22 04:29:45912 // Contains the tracked HTML attributes of the corresponding iframe element,
913 // such as 'id' and 'src'.
914 blink::mojom::IframeAttributesPtr attributes_;
Antonio Sartori5abc8de2021-07-13 08:42:47915
danakjc492bf82020-09-09 20:02:44916 // Owns an ongoing NavigationRequest until it is ready to commit. It will then
917 // be reset and a RenderFrameHost will be responsible for the navigation.
918 std::unique_ptr<NavigationRequest> navigation_request_;
919
920 // List of objects observing this FrameTreeNode.
921 base::ObserverList<Observer>::Unchecked observers_;
922
923 base::TimeTicks last_focus_time_;
924
arthursonzogni9816b9192021-03-29 16:09:19925 bool was_discarded_ = false;
danakjc492bf82020-09-09 20:02:44926
Abhijeet Kandalkar3f29bc42022-09-23 12:39:58927 const FencedFrameStatus fenced_frame_status_ =
928 FencedFrameStatus::kNotNestedInFencedFrame;
Harkiran Bolaria16f2c48d2022-04-22 12:39:57929
Garrett Tanzerc69f4642022-08-15 22:15:14930 // If this is a fenced frame resulting from a urn:uuid navigation, this
931 // contains all the metadata specifying the resulting context.
Alison Gale770f3fc2024-04-27 00:39:58932 // TODO(crbug.com/40202462): Move this into the FrameTree once ShadowDOM
Garrett Tanzer34cb92fe2022-09-28 17:50:54933 // and urn iframes are gone.
Arthur Sonzognic686e8f2024-01-11 08:36:37934 std::optional<FencedFrameProperties> fenced_frame_properties_;
Garrett Tanzerc69f4642022-08-15 22:15:14935
Mingyu Lei7956b8b2023-07-24 08:24:08936 // The tracker of the task that restarts the BFCache navigation. It might be
937 // used to cancel the task.
938 // See `CancelRestartingBackForwardCacheNavigation()`.
939 base::CancelableTaskTracker restart_back_forward_cached_navigation_tracker_;
940
Lukasz Anforowicz147141962020-12-16 18:03:24941 // Manages creation and swapping of RenderFrameHosts for this frame.
942 //
943 // This field needs to be declared last, because destruction of
944 // RenderFrameHostManager may call arbitrary callbacks (e.g. via
945 // WebContentsObserver::DidFinishNavigation fired after RenderFrameHostManager
946 // destructs a RenderFrameHostImpl and its NavigationRequest). Such callbacks
947 // may try to use FrameTreeNode's fields above - this would be an undefined
948 // behavior if the fields (even trivially-destructible ones) were destructed
949 // before the RenderFrameHostManager's destructor runs. See also
950 // https://crbug.com/1157988.
951 RenderFrameHostManager render_manager_;
Mingyu Lei7956b8b2023-07-24 08:24:08952
953 base::WeakPtrFactory<FrameTreeNode> weak_factory_{this};
danakjc492bf82020-09-09 20:02:44954};
955
956} // namespace content
957
958#endif // CONTENT_BROWSER_RENDERER_HOST_FRAME_TREE_NODE_H_