blob: d877843e4365d4e28368e25f26cb86fda5823930 [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"
danakjc492bf82020-09-09 20:02:4437#include "url/gurl.h"
38#include "url/origin.h"
39
40namespace content {
41
42class NavigationRequest;
danakjc492bf82020-09-09 20:02:4443class NavigationEntryImpl;
Paul Semel3e241042022-10-11 12:57:3144class FrameTree;
danakjc492bf82020-09-09 20:02:4445
46// When a page contains iframes, its renderer process maintains a tree structure
47// of those frames. We are mirroring this tree in the browser process. This
48// class represents a node in this tree and is a wrapper for all objects that
49// are frame-specific (as opposed to page-specific).
50//
51// Each FrameTreeNode has a current RenderFrameHost, which can change over
52// time as the frame is navigated. Any immediate subframes of the current
53// document are tracked using FrameTreeNodes owned by the current
54// RenderFrameHost, rather than as children of FrameTreeNode itself. This
55// allows subframe FrameTreeNodes to stay alive while a RenderFrameHost is
56// still alive - for example while pending deletion, after a new current
57// RenderFrameHost has replaced it.
Miyoung Shin7cf88b42022-11-07 13:22:3058class CONTENT_EXPORT FrameTreeNode : public RenderFrameHostOwner {
danakjc492bf82020-09-09 20:02:4459 public:
60 class Observer {
61 public:
62 // Invoked when a FrameTreeNode is being destroyed.
63 virtual void OnFrameTreeNodeDestroyed(FrameTreeNode* node) {}
64
65 // Invoked when a FrameTreeNode becomes focused.
66 virtual void OnFrameTreeNodeFocused(FrameTreeNode* node) {}
67
Arthur Hemerye4659282022-03-28 08:36:1568 // Invoked when a FrameTreeNode moves to a different BrowsingInstance and
69 // the popups it opened should be disowned.
70 virtual void OnFrameTreeNodeDisownedOpenee(FrameTreeNode* node) {}
71
Fergal Dalya1d569972021-03-16 03:24:5372 virtual ~Observer() = default;
danakjc492bf82020-09-09 20:02:4473 };
74
danakjc492bf82020-09-09 20:02:4475 // Returns the FrameTreeNode with the given global |frame_tree_node_id|,
76 // regardless of which FrameTree it is in.
Avi Drissmanbd153642024-09-03 18:58:0577 static FrameTreeNode* GloballyFindByID(FrameTreeNodeId frame_tree_node_id);
danakjc492bf82020-09-09 20:02:4478
79 // Returns the FrameTreeNode for the given |rfh|. Same as
80 // rfh->frame_tree_node(), but also supports nullptrs.
81 static FrameTreeNode* From(RenderFrameHost* rfh);
82
83 // Callers are are expected to initialize sandbox flags separately after
84 // calling the constructor.
85 FrameTreeNode(
Arthur Sonzognif6785ec2022-12-05 10:11:5086 FrameTree& frame_tree,
danakjc492bf82020-09-09 20:02:4487 RenderFrameHostImpl* parent,
Daniel Cheng6ac128172021-05-25 18:49:0188 blink::mojom::TreeScopeType tree_scope_type,
danakjc492bf82020-09-09 20:02:4489 bool is_created_by_script,
danakjc492bf82020-09-09 20:02:4490 const blink::mojom::FrameOwnerProperties& frame_owner_properties,
Kevin McNee43fe8292021-10-04 22:59:4191 blink::FrameOwnerElementType owner_type,
Dominic Farolino08662c82021-06-11 07:36:3492 const blink::FramePolicy& frame_owner);
danakjc492bf82020-09-09 20:02:4493
Peter Boström828b9022021-09-21 02:28:4394 FrameTreeNode(const FrameTreeNode&) = delete;
95 FrameTreeNode& operator=(const FrameTreeNode&) = delete;
96
Miyoung Shin7cf88b42022-11-07 13:22:3097 ~FrameTreeNode() override;
danakjc492bf82020-09-09 20:02:4498
99 void AddObserver(Observer* observer);
100 void RemoveObserver(Observer* observer);
101
Ian Vollick25a9d032022-04-12 23:20:17102 // Frame trees may be nested so it can be the case that IsMainFrame() is true,
103 // but is not the outermost main frame. In particular, !IsMainFrame() cannot
104 // be used to check if the frame is an embedded frame -- use
105 // !IsOutermostMainFrame() instead. NB: this does not escape guest views;
106 // IsOutermostMainFrame will be true for the outermost main frame in an inner
107 // guest view.
danakjc492bf82020-09-09 20:02:44108 bool IsMainFrame() const;
Arthur Hemerya06697f2023-03-14 09:20:57109 bool IsOutermostMainFrame() const;
danakjc492bf82020-09-09 20:02:44110
Arthur Sonzognif6785ec2022-12-05 10:11:50111 FrameTree& frame_tree() const { return frame_tree_.get(); }
Paul Semel3e241042022-10-11 12:57:31112 Navigator& navigator();
danakjc492bf82020-09-09 20:02:44113
114 RenderFrameHostManager* render_manager() { return &render_manager_; }
Alexander Timin33e2e2c12022-03-03 04:21:33115 const RenderFrameHostManager* render_manager() const {
116 return &render_manager_;
117 }
Avi Drissmanbd153642024-09-03 18:58:05118 FrameTreeNodeId frame_tree_node_id() const { return frame_tree_node_id_; }
Yuzu Saijo03dbf9b2022-07-22 04:29:45119 // This reflects window.name, which is initially set to the the "name"
120 // attribute. But this won't reflect changes of 'name' attribute and instead
121 // reflect changes to the Window object's name property.
122 // This is different from IframeAttributes' name in that this will not get
123 // updated when 'name' attribute gets updated.
Harkiran Bolaria4eacb3a2021-12-13 20:03:47124 const std::string& frame_name() const {
125 return render_manager_.current_replication_state().name;
126 }
danakjc492bf82020-09-09 20:02:44127
128 const std::string& unique_name() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47129 return render_manager_.current_replication_state().unique_name;
danakjc492bf82020-09-09 20:02:44130 }
131
danakjc492bf82020-09-09 20:02:44132 size_t child_count() const { return current_frame_host()->child_count(); }
133
danakjc492bf82020-09-09 20:02:44134 RenderFrameHostImpl* parent() const { return parent_; }
135
Dave Tapuskac8de3b02021-12-03 21:51:01136 // See `RenderFrameHost::GetParentOrOuterDocument()` for
137 // documentation.
Arthur Hemerya06697f2023-03-14 09:20:57138 RenderFrameHostImpl* GetParentOrOuterDocument() const;
Dave Tapuskac8de3b02021-12-03 21:51:01139
140 // See `RenderFrameHostImpl::GetParentOrOuterDocumentOrEmbedder()` for
141 // documentation.
142 RenderFrameHostImpl* GetParentOrOuterDocumentOrEmbedder();
143
danakjc492bf82020-09-09 20:02:44144 FrameTreeNode* opener() const { return opener_; }
145
Rakina Zata Amni3a48ae42022-05-05 03:39:56146 FrameTreeNode* first_live_main_frame_in_original_opener_chain() const {
147 return first_live_main_frame_in_original_opener_chain_;
148 }
danakjc492bf82020-09-09 20:02:44149
Arthur Sonzognic686e8f2024-01-11 08:36:37150 const std::optional<base::UnguessableToken>& opener_devtools_frame_token() {
Wolfgang Beyerd8809db2020-09-30 15:29:39151 return opener_devtools_frame_token_;
152 }
153
Julie Jeongeun Kimf38c1eca2021-12-14 07:46:55154 // Returns the type of the frame. Refer to frame_type.h for the details.
155 FrameType GetFrameType() const;
156
danakjc492bf82020-09-09 20:02:44157 // Assigns a new opener for this node and, if |opener| is non-null, registers
158 // an observer that will clear this node's opener if |opener| is ever
159 // destroyed.
160 void SetOpener(FrameTreeNode* opener);
161
162 // Assigns the initial opener for this node, and if |opener| is non-null,
163 // registers an observer that will clear this node's opener if |opener| is
164 // ever destroyed. The value set here is the root of the tree.
165 //
166 // It is not possible to change the opener once it was set.
167 void SetOriginalOpener(FrameTreeNode* opener);
168
Wolfgang Beyerd8809db2020-09-30 15:29:39169 // Assigns an opener frame id for this node. This string id is only set once
170 // and cannot be changed. It persists, even if the |opener| is destroyed. It
171 // is used for attribution in the DevTools frontend.
172 void SetOpenerDevtoolsFrameToken(
173 base::UnguessableToken opener_devtools_frame_token);
174
danakjc492bf82020-09-09 20:02:44175 FrameTreeNode* child_at(size_t index) const {
176 return current_frame_host()->child_at(index);
177 }
178
179 // Returns the URL of the last committed page in the current frame.
180 const GURL& current_url() const {
181 return current_frame_host()->GetLastCommittedURL();
182 }
183
Charlie Reis734db662024-01-11 18:20:03184 // Moves this frame out of the initial empty document state, which is a
185 // one-way change for FrameTreeNode (i.e., it cannot go back into the initial
186 // empty document state).
187 void set_not_on_initial_empty_document() {
188 is_on_initial_empty_document_ = false;
189 }
190
191 // Returns false if the frame has committed a document that is not the initial
192 // empty document, or if the current document's input stream has been opened
193 // with document.open(), causing the document to lose its "initial empty
194 // document" status. For more details, see the definition of
195 // `is_on_initial_empty_document_`.
Rakina Zata Amni86c88fa2021-11-01 01:27:30196 bool is_on_initial_empty_document() const {
Charlie Reis734db662024-01-11 18:20:03197 return is_on_initial_empty_document_;
Rakina Zata Amnifc4cc3d42021-06-10 09:03:56198 }
199
danakjc492bf82020-09-09 20:02:44200 // Returns whether the frame's owner element in the parent document is
201 // collapsed, that is, removed from the layout as if it did not exist, as per
202 // request by the embedder (of the content/ layer).
203 bool is_collapsed() const { return is_collapsed_; }
204
205 // Sets whether to collapse the frame's owner element in the parent document,
206 // that is, to remove it from the layout as if it did not exist, as per
207 // request by the embedder (of the content/ layer). Cannot be called for main
208 // frames.
209 //
210 // This only has an effect for <iframe> owner elements, and is a no-op when
211 // called on sub-frames hosted in <frame>, <object>, and <embed> elements.
212 void SetCollapsed(bool collapsed);
213
214 // Returns the origin of the last committed page in this frame.
215 // WARNING: To get the last committed origin for a particular
216 // RenderFrameHost, use RenderFrameHost::GetLastCommittedOrigin() instead,
217 // which will behave correctly even when the RenderFrameHost is not the
218 // current one for this frame (such as when it's pending deletion).
219 const url::Origin& current_origin() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47220 return render_manager_.current_replication_state().origin;
danakjc492bf82020-09-09 20:02:44221 }
222
danakjc492bf82020-09-09 20:02:44223 // Returns the latest frame policy (sandbox flags and container policy) for
224 // this frame. This includes flags inherited from parent frames and the latest
225 // flags from the <iframe> element hosting this frame. The returned policies
226 // may not yet have taken effect, since "sandbox" and "allow" attribute
Liam Brady25a14162022-12-02 15:25:57227 // updates in an <iframe> element take effect on next navigation. For
228 // <fencedframe> elements, not everything in the frame policy might actually
229 // take effect after the navigation. To retrieve the currently active policy
230 // for this frame, use effective_frame_policy().
danakjc492bf82020-09-09 20:02:44231 const blink::FramePolicy& pending_frame_policy() const {
232 return pending_frame_policy_;
233 }
234
235 // Update this frame's sandbox flags and container policy. This is called
236 // when a parent frame updates the "sandbox" attribute in the <iframe> element
237 // for this frame, or any of the attributes which affect the container policy
238 // ("allowfullscreen", "allowpaymentrequest", "allow", and "src".)
239 // These policies won't take effect until next navigation. If this frame's
240 // parent is itself sandboxed, the parent's sandbox flags are combined with
241 // those in |frame_policy|.
242 // Attempting to change the container policy on the main frame will have no
243 // effect.
244 void SetPendingFramePolicy(blink::FramePolicy frame_policy);
245
246 // Returns the currently active frame policy for this frame, including the
247 // sandbox flags which were present at the time the document was loaded, and
Charlie Hu5130d25e2021-03-05 21:53:39248 // the permissions policy container policy, which is set by the iframe's
danakjc492bf82020-09-09 20:02:44249 // allowfullscreen, allowpaymentrequest, and allow attributes, along with the
250 // origin of the iframe's src attribute (which may be different from the URL
251 // of the document currently loaded into the frame). This does not include
252 // policy changes that have been made by updating the containing iframe
253 // element attributes since the frame was last navigated; use
254 // pending_frame_policy() for those.
255 const blink::FramePolicy& effective_frame_policy() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47256 return render_manager_.current_replication_state().frame_policy;
danakjc492bf82020-09-09 20:02:44257 }
258
danakjc492bf82020-09-09 20:02:44259 const blink::mojom::FrameOwnerProperties& frame_owner_properties() {
260 return frame_owner_properties_;
261 }
262
263 void set_frame_owner_properties(
264 const blink::mojom::FrameOwnerProperties& frame_owner_properties) {
265 frame_owner_properties_ = frame_owner_properties;
266 }
267
Yuzu Saijo03dbf9b2022-07-22 04:29:45268 // Reflects the attributes of the corresponding iframe html element, such
Arthur Sonzogni64457592022-11-22 11:08:59269 // as 'credentialless', 'id', 'name' and 'src'. These values should not be
Yuzu Saijo03dbf9b2022-07-22 04:29:45270 // exposed to cross-origin renderers.
271 const network::mojom::ContentSecurityPolicy* csp_attribute() const {
272 return attributes_->parsed_csp_attribute.get();
danakjc492bf82020-09-09 20:02:44273 }
Yao Xiao9c54b3e2023-03-14 04:25:04274 // Tracks iframe's 'browsingtopics' attribute, indicating whether the
275 // navigation requests on this frame should calculate and send the
276 // `Sec-Browsing-Topics` header.
277 bool browsing_topics() const { return attributes_->browsing_topics; }
Camillia Smith Barnes6d2966c82023-08-23 21:16:18278
Orr Bernsteina0cc6792023-11-14 22:12:35279 // Tracks iframe's 'adauctionheaders' attribute, indicating whether the
280 // navigation request on this frame should calculate and send the
281 // 'Sec-Ad-Auction-Fetch` header.
282 bool ad_auction_headers() const { return attributes_->ad_auction_headers; }
283
Camillia Smith Barnes6d2966c82023-08-23 21:16:18284 // Tracks iframe's 'sharedstoragewritable' attribute, indicating what value
Camillia Smith Barnesc267be62023-11-01 20:01:02285 // the the corresponding
286 // `network::ResourceRequest::shared_storage_writable_eligible` should take
287 // for the navigation(s) on this frame, pending a permissions policy check. If
288 // true, and if the permissions policy check returns "enabled", the network
Camillia Smith Barnes6d2966c82023-08-23 21:16:18289 // service will send the `Shared-Storage-Write` request header.
Camillia Smith Barnesc267be62023-11-01 20:01:02290 bool shared_storage_writable_opted_in() const {
291 return attributes_->shared_storage_writable_opted_in;
Camillia Smith Barnes6d2966c82023-08-23 21:16:18292 }
Arthur Sonzognic686e8f2024-01-11 08:36:37293 const std::optional<std::string> html_id() const { return attributes_->id; }
Yuzu Saijo03dbf9b2022-07-22 04:29:45294 // This tracks iframe's 'name' attribute instead of window.name, which is
295 // tracked in FrameReplicationState. See the comment for frame_name() for
296 // more details.
Arthur Sonzognic686e8f2024-01-11 08:36:37297 const std::optional<std::string> html_name() const {
Yuzu Saijodc870f92023-01-20 03:39:11298 return attributes_->name;
299 }
Arthur Sonzognic686e8f2024-01-11 08:36:37300 const std::optional<std::string> html_src() const { return attributes_->src; }
danakjc492bf82020-09-09 20:02:44301
Yuzu Saijo03dbf9b2022-07-22 04:29:45302 void SetAttributes(blink::mojom::IframeAttributesPtr attributes);
Antonio Sartori5abc8de2021-07-13 08:42:47303
danakjc492bf82020-09-09 20:02:44304 bool HasSameOrigin(const FrameTreeNode& node) const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47305 return render_manager_.current_replication_state().origin.IsSameOriginWith(
306 node.current_replication_state().origin);
danakjc492bf82020-09-09 20:02:44307 }
308
Gyuyoung Kimc16e52e92021-03-19 02:45:37309 const blink::mojom::FrameReplicationState& current_replication_state() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47310 return render_manager_.current_replication_state();
danakjc492bf82020-09-09 20:02:44311 }
312
313 RenderFrameHostImpl* current_frame_host() const {
314 return render_manager_.current_frame_host();
315 }
316
danakjc492bf82020-09-09 20:02:44317 // Returns true if this node is in a loading state.
318 bool IsLoading() const;
Nate Chapin470dbc62023-04-25 16:34:38319 LoadingState GetLoadingState() const;
danakjc492bf82020-09-09 20:02:44320
Alex Moshchuk9b0fd822020-10-26 23:08:15321 // Returns true if this node has a cross-document navigation in progress.
322 bool HasPendingCrossDocumentNavigation() const;
323
danakjc492bf82020-09-09 20:02:44324 NavigationRequest* navigation_request() { return navigation_request_.get(); }
325
326 // Transfers the ownership of the NavigationRequest to |render_frame_host|.
327 // From ReadyToCommit to DidCommit, the NavigationRequest is owned by the
328 // RenderFrameHost that is committing the navigation.
329 void TransferNavigationRequestOwnership(
330 RenderFrameHostImpl* render_frame_host);
331
332 // Takes ownership of |navigation_request| and makes it the current
333 // NavigationRequest of this frame. This corresponds to the start of a new
334 // navigation. If there was an ongoing navigation request before calling this
335 // function, it is canceled. |navigation_request| should not be null.
Charlie Reis09952ee2022-12-08 16:35:07336 void TakeNavigationRequest(
danakjc492bf82020-09-09 20:02:44337 std::unique_ptr<NavigationRequest> navigation_request);
338
Rakina Zata Amnif8f2bb62022-11-23 05:54:32339 // Resets the navigation request owned by `this` (which shouldn't have reached
340 // the "pending commit" stage yet) and any state created by it, including the
Rakina Zata Amni33175cb92022-11-24 02:46:03341 // speculative RenderFrameHost (if there are no other navigations associated
342 // with it). Note that this does not affect navigations that have reached the
343 // "pending commit" stage, which are owned by their corresponding
344 // RenderFrameHosts instead.
Daniel Cheng390e2a72022-09-28 06:07:53345 void ResetNavigationRequest(NavigationDiscardReason reason);
346
Rakina Zata Amnif8f2bb62022-11-23 05:54:32347 // Similar to `ResetNavigationRequest()`, but keeps the state created by the
Daniel Cheng390e2a72022-09-28 06:07:53348 // NavigationRequest (e.g. speculative RenderFrameHost, loading state).
Rakina Zata Amni58681c62024-06-25 06:32:13349 void ResetNavigationRequestButKeepState(NavigationDiscardReason reason);
danakjc492bf82020-09-09 20:02:44350
danakjc492bf82020-09-09 20:02:44351 // The load progress for a RenderFrameHost in this node was updated to
352 // |load_progress|. This will notify the FrameTree which will in turn notify
353 // the WebContents.
354 void DidChangeLoadProgress(double load_progress);
355
356 // Called when the user directed the page to stop loading. Stops all loads
357 // happening in the FrameTreeNode. This method should be used with
358 // FrameTree::ForEach to stop all loads in the entire FrameTree.
359 bool StopLoading();
360
361 // Returns the time this frame was last focused.
362 base::TimeTicks last_focus_time() const { return last_focus_time_; }
363
364 // Called when this node becomes focused. Updates the node's last focused
365 // time and notifies observers.
366 void DidFocus();
367
368 // Called when the user closed the modal dialogue for BeforeUnload and
369 // cancelled the navigation. This should stop any load happening in the
370 // FrameTreeNode.
371 void BeforeUnloadCanceled();
372
danakjc492bf82020-09-09 20:02:44373 // Returns the sandbox flags currently in effect for this frame. This includes
374 // flags inherited from parent frames, the currently active flags from the
375 // <iframe> element hosting this frame, as well as any flags set from a
376 // Content-Security-Policy HTTP header. This does not include flags that have
377 // have been updated in an <iframe> element but have not taken effect yet; use
378 // pending_frame_policy() for those. To see the flags which will take effect
379 // on navigation (which does not include the CSP-set flags), use
380 // effective_frame_policy().
381 network::mojom::WebSandboxFlags active_sandbox_flags() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47382 return render_manager_.current_replication_state().active_sandbox_flags;
danakjc492bf82020-09-09 20:02:44383 }
384
danakjc492bf82020-09-09 20:02:44385 // Returns whether the frame received a user gesture on a previous navigation
386 // on the same eTLD+1.
387 bool has_received_user_gesture_before_nav() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47388 return render_manager_.current_replication_state()
389 .has_received_user_gesture_before_nav;
danakjc492bf82020-09-09 20:02:44390 }
391
392 // When a tab is discarded, WebContents sets was_discarded on its
393 // root FrameTreeNode.
394 // In addition, when a child frame is created, this bit is passed on from
395 // parent to child.
396 // When a navigation request is created, was_discarded is passed on to the
397 // request and reset to false in FrameTreeNode.
398 void set_was_discarded() { was_discarded_ = true; }
399 bool was_discarded() const { return was_discarded_; }
400
Miyoung Shin8a66ec022022-11-28 23:50:09401 // Deprecated. Use directly HasStickyUserActivation in RFHI.
danakjc492bf82020-09-09 20:02:44402 // Returns the sticky bit of the User Activation v2 state of the
403 // |FrameTreeNode|.
404 bool HasStickyUserActivation() const {
Miyoung Shin8a66ec022022-11-28 23:50:09405 return current_frame_host()->HasStickyUserActivation();
danakjc492bf82020-09-09 20:02:44406 }
407
Miyoung Shin8a66ec022022-11-28 23:50:09408 // Deprecated. Use directly HasStickyUserActivation in RFHI.
danakjc492bf82020-09-09 20:02:44409 // Returns the transient bit of the User Activation v2 state of the
410 // |FrameTreeNode|.
411 bool HasTransientUserActivation() {
Miyoung Shin8a66ec022022-11-28 23:50:09412 return current_frame_host()->HasTransientUserActivation();
danakjc492bf82020-09-09 20:02:44413 }
414
415 // Remove history entries for all frames created by script in this frame's
416 // subtree. If a frame created by a script is removed, then its history entry
417 // will never be reused - this saves memory.
418 void PruneChildFrameNavigationEntries(NavigationEntryImpl* entry);
419
Abhijeet Kandalkarb43affa72022-09-27 16:48:01420 using FencedFrameStatus = RenderFrameHostImpl::FencedFrameStatus;
Abhijeet Kandalkar3f29bc42022-09-23 12:39:58421 FencedFrameStatus fenced_frame_status() const { return fenced_frame_status_; }
422
Kevin McNee43fe8292021-10-04 22:59:41423 blink::FrameOwnerElementType frame_owner_element_type() const {
Daniel Cheng9bd90f92021-04-23 20:49:45424 return frame_owner_element_type_;
danakjc492bf82020-09-09 20:02:44425 }
danakjc492bf82020-09-09 20:02:44426
Daniel Cheng6ac128172021-05-25 18:49:01427 blink::mojom::TreeScopeType tree_scope_type() const {
428 return tree_scope_type_;
429 }
430
arthursonzogni034bb9c2020-10-01 08:29:56431 // The initial popup URL for new window opened using:
432 // `window.open(initial_popup_url)`.
433 // An empty GURL otherwise.
434 //
435 // [WARNING] There is no guarantee the FrameTreeNode will ever host a
436 // document served from this URL. The FrameTreeNode always starts hosting the
437 // initial empty document and attempts a navigation toward this URL. However
438 // the navigation might be delayed, redirected and even cancelled.
439 void SetInitialPopupURL(const GURL& initial_popup_url);
440 const GURL& initial_popup_url() const { return initial_popup_url_; }
441
442 // The origin of the document that used window.open() to create this frame.
443 // Otherwise, an opaque Origin with a nonce different from all previously
444 // existing Origins.
445 void SetPopupCreatorOrigin(const url::Origin& popup_creator_origin);
446 const url::Origin& popup_creator_origin() const {
447 return popup_creator_origin_;
448 }
449
Harkiran Bolaria59290d62021-03-17 01:53:01450 // Sets the associated FrameTree for this node. The node can change FrameTrees
Domenic Denicola7767a9c2023-07-13 15:36:39451 // as part of prerendering, which allows a page loaded in the prerendered
452 // FrameTree to be used for a navigation in the primary frame tree.
Harkiran Bolaria59290d62021-03-17 01:53:01453 void SetFrameTree(FrameTree& frame_tree);
454
Alexander Timin074cd182022-03-23 18:11:22455 using TraceProto = perfetto::protos::pbzero::FrameTreeNodeInfo;
Alexander Timinf785f342021-03-18 00:00:56456 // Write a representation of this object into a trace.
Alexander Timin074cd182022-03-23 18:11:22457 void WriteIntoTrace(perfetto::TracedProto<TraceProto> proto) const;
Alexander Timinf785f342021-03-18 00:00:56458
Carlos Caballero76711352021-03-24 17:38:21459 // Returns true the node is navigating, i.e. it has an associated
460 // NavigationRequest.
461 bool HasNavigation();
462
murakinonoka97a8f042024-01-10 09:17:07463 // Returns true if there are any navigations happening in FrameTreeNode that
464 // is pending commit (i.e. between ReadyToCommit and DidCommit). Note that
465 // those navigations won't live in the FrameTreeNode itself, as they will
466 // already be owned by the committing RenderFrameHost (either the current
467 // RenderFrameHost or the speculative RenderFrameHost).
468 bool HasPendingCommitNavigation();
469
shivanigithubf3ddff52021-07-03 22:06:30470 // Fenced frames (meta-bug crbug.com/1111084):
shivanigithub4cd016a2021-09-20 21:10:30471 // Note that these two functions cannot be invoked from a FrameTree's or
472 // its root node's constructor since they require the frame tree and the
473 // root node to be completely constructed.
474 //
shivanigithubf3ddff52021-07-03 22:06:30475 // Returns false if fenced frames are disabled. Returns true if the feature is
476 // enabled and if |this| is a fenced frame. Returns false for
477 // iframes embedded in a fenced frame. To clarify: for the MPArch
478 // implementation this only returns true if |this| is the actual
479 // root node of the inner FrameTree and not the proxy FrameTreeNode in the
480 // outer FrameTree.
Dominic Farolino4bc10ee2021-08-31 00:37:36481 bool IsFencedFrameRoot() const;
shivanigithubf3ddff52021-07-03 22:06:30482
483 // Returns false if fenced frames are disabled. Returns true if the
484 // feature is enabled and if |this| or any of its ancestor nodes is a
485 // fenced frame.
486 bool IsInFencedFrameTree() const;
487
shivanigithub4cd016a2021-09-20 21:10:30488 // Returns a valid nonce if `IsInFencedFrameTree()` returns true for `this`.
Garrett Tanzer34cb92fe2022-09-28 17:50:54489 // Returns nullopt otherwise.
490 //
491 // Nonce used in the net::IsolationInfo and blink::StorageKey for a fenced
492 // frame and any iframes nested within it. Not set if this frame is not in a
493 // fenced frame's FrameTree. Note that this could be a field in FrameTree for
494 // the MPArch version but for the shadow DOM version we need to keep it here
495 // since the fenced frame root is not a main frame for the latter. The value
496 // of the nonce will be the same for all of the the iframes inside a fenced
497 // frame tree. If there is a nested fenced frame it will have a different
498 // nonce than its parent fenced frame. The nonce will stay the same across
499 // navigations initiated from the fenced frame tree because it is always used
500 // in conjunction with other fields of the keys and would be good to access
501 // the same storage across same-origin navigations. If the navigation is
502 // same-origin/site then the same network stack partition/storage will be
503 // reused and if it's cross-origin/site then other parts of the key will
504 // change and so, even with the same nonce, another partition will be used.
505 // But if the navigation is initiated from the embedder, the nonce will be
506 // reinitialized irrespective of same or cross origin such that there is no
507 // privacy leak via storage shared between two embedder initiated navigations.
508 // Note that this reinitialization is implemented for all embedder-initiated
509 // navigations in MPArch, but only urn:uuid navigations in ShadowDOM.
Arthur Sonzognic686e8f2024-01-11 08:36:37510 std::optional<base::UnguessableToken> GetFencedFrameNonce();
shivanigithub4cd016a2021-09-20 21:10:30511
Garrett Tanzer34cb92fe2022-09-28 17:50:54512 // If applicable, initialize the default fenced frame properties. Right now,
513 // this means setting a new fenced frame nonce. See comment on
shivanigithub4cd016a2021-09-20 21:10:30514 // fenced_frame_nonce() for when it is set to a non-null value. Invoked
515 // by FrameTree::Init() or FrameTree::AddFrame().
Garrett Tanzer34cb92fe2022-09-28 17:50:54516 void SetFencedFramePropertiesIfNeeded();
shivanigithub4cd016a2021-09-20 21:10:30517
Garrett Tanzer291a2d52023-03-20 22:41:57518 // Set the current FencedFrameProperties to have "opaque ads mode".
519 // This should only be used during tests, when the proper embedder-initiated
520 // fenced frame root urn/config navigation flow isn't available.
Alison Gale770f3fc2024-04-27 00:39:58521 // TODO(crbug.com/40233168): Refactor and expand use of test utils so there is
Garrett Tanzer291a2d52023-03-20 22:41:57522 // a consistent way to do this properly everywhere. Consider removing
523 // arbitrary restrictions in "default mode" so that using opaque ads mode is
524 // less necessary.
525 void SetFencedFramePropertiesOpaqueAdsModeForTesting() {
526 if (fenced_frame_properties_.has_value()) {
Garrett Tanzer06980702023-12-12 19:48:20527 fenced_frame_properties_
528 ->SetFencedFramePropertiesOpaqueAdsModeForTesting();
Garrett Tanzer291a2d52023-03-20 22:41:57529 }
530 }
531
532 // Returns the mode attribute from the `FencedFrameProperties` if this frame
533 // is in a fenced frame tree, otherwise returns `kDefault`.
534 blink::FencedFrame::DeprecatedFencedFrameMode GetDeprecatedFencedFrameMode();
Nan Lin171fe9a2022-02-17 16:42:16535
Dave Tapuskac8de3b02021-12-03 21:51:01536 // Helper for GetParentOrOuterDocument/GetParentOrOuterDocumentOrEmbedder.
537 // Do not use directly.
Kevin McNee86e64ee2023-02-17 16:35:50538 // `escape_guest_view` determines whether to iterate out of guest views and is
539 // the behaviour distinction between GetParentOrOuterDocument and
540 // GetParentOrOuterDocumentOrEmbedder. See the comment on
541 // GetParentOrOuterDocumentOrEmbedder for details.
542 // `include_prospective` includes embedders which own our frame tree, but have
543 // not yet attached it to the outer frame tree.
Arthur Hemerya06697f2023-03-14 09:20:57544 RenderFrameHostImpl* GetParentOrOuterDocumentHelper(
545 bool escape_guest_view,
546 bool include_prospective) const;
Dave Tapuskac8de3b02021-12-03 21:51:01547
Harkiran Bolariab4437fd2021-08-11 17:51:22548 // Sets the unique_name and name fields on replication_state_. To be used in
549 // prerender activation to make sure the FrameTreeNode replication state is
550 // correct after the RenderFrameHost is moved between FrameTreeNodes. The
551 // renderers should already have the correct value, so unlike
552 // FrameTreeNode::SetFrameName, we do not notify them here.
Alison Gale770f3fc2024-04-27 00:39:58553 // TODO(crbug.com/40192974): Remove this once the BrowsingContextState
Harkiran Bolaria4eacb3a2021-12-13 20:03:47554 // is implemented to utilize the new path.
Harkiran Bolariab4437fd2021-08-11 17:51:22555 void set_frame_name_for_activation(const std::string& unique_name,
556 const std::string& name) {
Harkiran Bolaria0b3bdef02022-03-10 13:04:40557 current_frame_host()->browsing_context_state()->set_frame_name(unique_name,
558 name);
Harkiran Bolariab4437fd2021-08-11 17:51:22559 }
560
Nan Linaaf84f72021-12-02 22:31:56561 // Returns true if error page isolation is enabled.
562 bool IsErrorPageIsolationEnabled() const;
563
W. James MacLean81b8d01f2022-01-25 20:50:59564 // Functions to store and retrieve a frame's srcdoc value on this
565 // FrameTreeNode.
566 void SetSrcdocValue(const std::string& srcdoc_value);
567 const std::string& srcdoc_value() const { return srcdoc_value_; }
568
Garrett Tanzerc69f4642022-08-15 22:15:14569 void set_fenced_frame_properties(
Arthur Sonzognic686e8f2024-01-11 08:36:37570 const std::optional<FencedFrameProperties>& fenced_frame_properties) {
Alison Gale770f3fc2024-04-27 00:39:58571 // TODO(crbug.com/40202462): Reenable this DCHECK once ShadowDOM and
Garrett Tanzer2975eeac2022-08-22 16:34:01572 // loading urns in iframes (for FLEDGE OT) are gone.
573 // DCHECK_EQ(fenced_frame_status_,
574 // RenderFrameHostImpl::FencedFrameStatus::kFencedFrameRoot);
Garrett Tanzerc69f4642022-08-15 22:15:14575 fenced_frame_properties_ = fenced_frame_properties;
576 }
577
Xiaochen Zhou86f2e712023-09-13 19:55:04578 // This function returns the fenced frame properties associated with the given
579 // source.
580 // - If `source_node` is set to `kClosestAncestor`, the fenced frame
581 // properties are obtained by a bottom-up traversal from this node.
582 // - If `source_node` is set tp `kFrameTreeRoot`, the fenced frame properties
583 // from the fenced frame tree root are returned.
584 // For example, for an urn iframe that is nested inside a fenced frame.
585 // Calling this function from the nested urn iframe with `source_node` set to:
586 // - `kClosestAncestor`: returns the fenced frame properties from the urn
587 // iframe.
588 // - `kFrameTreeRoot`: returns the fenced frame properties from the fenced
589 // frame.
590 // Clients should decide which one to use depending on how the application of
591 // the fenced frame properties interact with urn iframes.
Alison Gale770f3fc2024-04-27 00:39:58592 // TODO(crbug.com/40060657): Once navigation support for urn::uuid in iframes
Xiaochen Zhou86f2e712023-09-13 19:55:04593 // is deprecated, remove the parameter `node_source`.
Arthur Sonzognic686e8f2024-01-11 08:36:37594 std::optional<FencedFrameProperties>& GetFencedFrameProperties(
Xiaochen Zhou86f2e712023-09-13 19:55:04595 FencedFramePropertiesNodeSource node_source =
596 FencedFramePropertiesNodeSource::kClosestAncestor);
Garrett Tanzerc69f4642022-08-15 22:15:14597
Liam Brady27da6a22024-06-05 16:35:34598 // Helper function for getting the FrameTreeNode that houses the relevant
599 // FencedFrameProperties when GetFencedFrameProperties() is called with
600 // kClosestAncestor.
601 FrameTreeNode* GetClosestAncestorWithFencedFrameProperties();
602
Liam Brady86ca0482023-12-06 19:49:25603 bool HasFencedFrameProperties() const {
604 return fenced_frame_properties_.has_value();
605 }
606
Yao Xiaof9ae90a2023-03-01 20:52:44607 // Returns the number of fenced frame boundaries above this frame. The
Yao Xiaoa2337ad2022-10-12 20:59:29608 // outermost main frame's frame tree has fenced frame depth 0, a topmost
609 // fenced frame tree embedded in the outermost main frame has fenced frame
610 // depth 1, etc.
Yao Xiaof9ae90a2023-03-01 20:52:44611 //
612 // Also, sets `shared_storage_fenced_frame_root_count` to the
613 // number of fenced frame boundaries (roots) above this frame that originate
614 // from shared storage. This is used to check whether a fenced frame
615 // originates from shared storage only (i.e. not from FLEDGE).
Alison Gale770f3fc2024-04-27 00:39:58616 // TODO(crbug.com/40233168): Remove this check once we put permissions inside
Yao Xiaof9ae90a2023-03-01 20:52:44617 // FencedFrameConfig.
618 size_t GetFencedFrameDepth(size_t& shared_storage_fenced_frame_root_count);
Yao Xiaoa2337ad2022-10-12 20:59:29619
620 // Traverse up from this node. Return all valid
621 // `node->fenced_frame_properties_->shared_storage_budget_metadata` (i.e. this
622 // node is subjected to the shared storage budgeting associated with those
623 // metadata). Every node that originates from sharedStorage.selectURL() will
624 // have an associated metadata. This indicates that the metadata can only
625 // possibly be associated with a fenced frame root, unless when
626 // `kAllowURNsInIframes` is enabled in which case they could be be associated
627 // with any node.
Garrett Tanzer29de7112022-12-06 21:26:32628 std::vector<const SharedStorageBudgetMetadata*>
Yao Xiao1ac702d2022-06-08 17:20:49629 FindSharedStorageBudgetMetadata();
630
Camillia Smith Barnes7218518c2023-03-06 19:02:17631 // Returns any shared storage context string that was written to a
632 // `blink::FencedFrameConfig` before navigation via
633 // `setSharedStorageContext()`, as long as the request is for a same-origin
634 // frame within the config's fenced frame tree (or a same-origin descendant of
635 // a URN iframe).
Arthur Sonzognic686e8f2024-01-11 08:36:37636 std::optional<std::u16string> GetEmbedderSharedStorageContextIfAllowed();
Camillia Smith Barnes7218518c2023-03-06 19:02:17637
Harkiran Bolariaebbe7702022-02-22 19:19:03638 // Accessor to BrowsingContextState for subframes only. Only main frame
639 // navigations can change BrowsingInstances and BrowsingContextStates,
640 // therefore for subframes associated BrowsingContextState never changes. This
641 // helper method makes this more explicit and guards against calling this on
642 // main frames (there an appropriate BrowsingContextState should be obtained
643 // from RenderFrameHost or from RenderFrameProxyHost as e.g. during
644 // cross-BrowsingInstance navigations multiple BrowsingContextStates exist in
645 // the same frame).
646 const scoped_refptr<BrowsingContextState>&
647 GetBrowsingContextStateForSubframe() const;
648
Arthur Hemerye4659282022-03-28 08:36:15649 // Clears the opener property of popups referencing this FrameTreeNode as
650 // their opener.
651 void ClearOpenerReferences();
652
Liam Brady95d36d12023-03-13 21:13:06653 // Calculates whether one of the ancestor frames or this frame has a CSPEE in
654 // place. This is eventually sent over to LocalFrame in the renderer where it
655 // will be used by NavigatorAuction::canLoadAdAuctionFencedFrame for
656 // information it can't get on its own.
Liam Bradyd2a41e152022-07-19 13:58:48657 bool AncestorOrSelfHasCSPEE() const;
658
Arthur Sonzogni8e8eb1f2023-01-10 14:51:01659 // Reset every navigation in this frame, and its descendants. This is called
660 // after the <iframe> element has been removed, or after the document owning
661 // this frame has been navigated away.
662 //
663 // This takes into account:
664 // - Non-pending commit NavigationRequest owned by the FrameTreeNode
665 // - Pending commit NavigationRequest owned by the current RenderFrameHost
666 // - Speculative RenderFrameHost and its pending commit NavigationRequests.
667 void ResetAllNavigationsForFrameDetach();
668
Miyoung Shin7cf88b42022-11-07 13:22:30669 // RenderFrameHostOwner implementation:
Nate Chapin470dbc62023-04-25 16:34:38670 void DidStartLoading(LoadingState previous_frame_tree_loading_state) override;
Julie Jeongeun Kim07c077bd2022-12-05 08:40:31671 void DidStopLoading() override;
Miyoung Shin7cf88b42022-11-07 13:22:30672 void RestartNavigationAsCrossDocument(
673 std::unique_ptr<NavigationRequest> navigation_request) override;
Miyoung Shin1504eb712022-12-07 10:32:18674 bool Reload() override;
Julie Jeongeun Kimc1b07c32022-11-11 10:26:32675 Navigator& GetCurrentNavigator() override;
Miyoung Shine16cd2262022-11-30 05:52:16676 RenderFrameHostManager& GetRenderFrameHostManager() override;
Miyoung Shin64fd1bea2023-01-04 04:22:08677 FrameTreeNode* GetOpener() const override;
Julie Jeongeun Kim2132b37f82022-11-23 08:30:46678 void SetFocusedFrame(SiteInstanceGroup* source) override;
Julie Jeongeun Kim0e242242022-11-30 10:45:09679 void DidChangeReferrerPolicy(
680 network::mojom::ReferrerPolicy referrer_policy) override;
Miyoung Shin8a66ec022022-11-28 23:50:09681 // Updates the user activation state in the browser frame tree and in the
682 // frame trees in all renderer processes except the renderer for this node
683 // (which initiated the update). Returns |false| if the update tries to
684 // consume an already consumed/expired transient state, |true| otherwise. See
685 // the comment on `user_activation_state_` in RenderFrameHostImpl.
686 //
687 // The |notification_type| parameter is used for histograms, only for the case
688 // |update_state == kNotifyActivation|.
689 bool UpdateUserActivationState(
690 blink::mojom::UserActivationUpdateType update_type,
691 blink::mojom::UserActivationNotificationType notification_type) override;
Nate Chapin47276a62023-02-16 16:53:44692 void DidConsumeHistoryUserActivation() override;
Charlie Reis734db662024-01-11 18:20:03693 void DidOpenDocumentInputStream() override;
Miyoung Shinff13ed22022-11-30 09:21:47694 std::unique_ptr<NavigationRequest>
695 CreateNavigationRequestForSynchronousRendererCommit(
696 RenderFrameHostImpl* render_frame_host,
697 bool is_same_document,
698 const GURL& url,
699 const url::Origin& origin,
Arthur Sonzognic686e8f2024-01-11 08:36:37700 const std::optional<GURL>& initiator_base_url,
Miyoung Shinff13ed22022-11-30 09:21:47701 const net::IsolationInfo& isolation_info_for_subresources,
702 blink::mojom::ReferrerPtr referrer,
703 const ui::PageTransition& transition,
704 bool should_replace_current_entry,
705 const std::string& method,
706 bool has_transient_activation,
707 bool is_overriding_user_agent,
708 const std::vector<GURL>& redirects,
709 const GURL& original_url,
710 std::unique_ptr<CrossOriginEmbedderPolicyReporter> coep_reporter,
Camille Lamy36afacd2025-01-16 14:25:18711 std::unique_ptr<DocumentIsolationPolicyReporter> dip_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;
Kevin McNeef1b0f0b2024-09-17 21:49:41716 FrameType GetCurrentFrameType() const override;
Miyoung Shinff13ed22022-11-30 09:21:47717
Mingyu Lei7956b8b2023-07-24 08:24:08718 // Restart the navigation restoring the page from the back-forward cache
719 // as a regular non-BFCached history navigation.
720 //
721 // The restart itself is asynchronous as it's dangerous to restart navigation
722 // with arbitrary state on the stack (another navigation might be starting),
723 // so this function only posts the actual task to do all the work (See
724 // `RestartBackForwardCachedNavigationImpl()`).
725 void RestartBackForwardCachedNavigationAsync(int nav_entry_id);
726
727 // Cancel the asynchronous task that would restart the BFCache navigation.
728 // This should be called whenever a FrameTreeNode's NavigationRequest would
729 // normally get cancelled, including when another NavigationRequest starts.
730 // This preserves the previous behavior where a restarting BFCache
731 // NavigationRequest is kept around until the task to create the new
732 // navigation is run, or until that NavigationRequest gets deleted (which
733 // cancels the task).
734 void CancelRestartingBackForwardCacheNavigation();
735
Christian Biesingere1865c57c2023-10-20 15:19:29736 base::SafeRef<FrameTreeNode> GetSafeRef() {
737 return weak_factory_.GetSafeRef();
738 }
739
danakjc492bf82020-09-09 20:02:44740 private:
Yuzu Saijo03dbf9b2022-07-22 04:29:45741 friend class CSPEmbeddedEnforcementUnitTest;
Charlie Hubb5943d2021-03-09 19:46:12742 FRIEND_TEST_ALL_PREFIXES(SitePerProcessPermissionsPolicyBrowserTest,
danakjc492bf82020-09-09 20:02:44743 ContainerPolicyDynamic);
Charlie Hubb5943d2021-03-09 19:46:12744 FRIEND_TEST_ALL_PREFIXES(SitePerProcessPermissionsPolicyBrowserTest,
danakjc492bf82020-09-09 20:02:44745 ContainerPolicySandboxDynamic);
Yuzu Saijo03dbf9b2022-07-22 04:29:45746 FRIEND_TEST_ALL_PREFIXES(NavigationRequestTest, StorageKeyToCommit);
Arthur Sonzogni64457592022-11-22 11:08:59747 FRIEND_TEST_ALL_PREFIXES(
748 NavigationRequestTest,
749 NavigationToCredentiallessDocumentNetworkIsolationInfo);
Yuzu Saijo03dbf9b2022-07-22 04:29:45750 FRIEND_TEST_ALL_PREFIXES(RenderFrameHostImplTest,
Arthur Sonzogni64457592022-11-22 11:08:59751 ChildOfCredentiallessIsCredentialless);
Yifan Luo86a79f42022-08-16 18:38:27752 FRIEND_TEST_ALL_PREFIXES(ContentPasswordManagerDriverTest,
Arthur Sonzogni64457592022-11-22 11:08:59753 PasswordAutofillDisabledOnCredentiallessIframe);
danakjc492bf82020-09-09 20:02:44754
Dominic Farolino8a2187b2021-12-24 20:44:21755 // Called by the destructor. When `this` is an outer dummy FrameTreeNode
756 // representing an inner FrameTree, this method destroys said inner FrameTree.
757 void DestroyInnerFrameTreeIfExists();
758
danakjc492bf82020-09-09 20:02:44759 class OpenerDestroyedObserver;
760
danakjc492bf82020-09-09 20:02:44761 // The |notification_type| parameter is used for histograms only.
Liam Brady38b84562024-03-07 22:11:26762 // |sticky_only| is set to true when propagating sticky user activation during
763 // cross-document navigations. The transient state remains unchanged.
danakjc492bf82020-09-09 20:02:44764 bool NotifyUserActivation(
Liam Brady38b84562024-03-07 22:11:26765 blink::mojom::UserActivationNotificationType notification_type,
766 bool sticky_only = false);
767
768 bool NotifyUserActivationStickyOnly();
danakjc492bf82020-09-09 20:02:44769
770 bool ConsumeTransientUserActivation();
771
772 bool ClearUserActivation();
773
774 // Verify that the renderer process is allowed to set user activation on this
775 // frame by checking whether this frame's RenderWidgetHost had previously seen
776 // an input event that might lead to user activation. If user activation
777 // should be allowed, this returns true and also clears corresponding pending
778 // user activation state in the widget. Otherwise, this returns false.
779 bool VerifyUserActivation();
780
Mingyu Lei7956b8b2023-07-24 08:24:08781 // See `RestartBackForwardCachedNavigationAsync()`.
782 void RestartBackForwardCachedNavigationImpl(int nav_entry_id);
783
Avi Drissmanbd153642024-09-03 18:58:05784 // The browser-global FrameTreeNodeId generator.
785 static FrameTreeNodeId::Generator frame_tree_node_id_generator_;
danakjc492bf82020-09-09 20:02:44786
Arthur Sonzognif6785ec2022-12-05 10:11:50787 // The FrameTree owning |this|. It can change with Prerender2 during
788 // activation.
789 raw_ref<FrameTree> frame_tree_;
danakjc492bf82020-09-09 20:02:44790
danakjc492bf82020-09-09 20:02:44791 // A browser-global identifier for the frame in the page, which stays stable
792 // even if the frame does a cross-process navigation.
Avi Drissmanbd153642024-09-03 18:58:05793 const FrameTreeNodeId frame_tree_node_id_;
danakjc492bf82020-09-09 20:02:44794
795 // The RenderFrameHost owning this FrameTreeNode, which cannot change for the
796 // life of this FrameTreeNode. |nullptr| if this node is the root.
Keishi Hattori0e45c022021-11-27 09:25:52797 const raw_ptr<RenderFrameHostImpl> parent_;
danakjc492bf82020-09-09 20:02:44798
danakjc492bf82020-09-09 20:02:44799 // The frame that opened this frame, if any. Will be set to null if the
800 // opener is closed, or if this frame disowns its opener by setting its
801 // window.opener to null.
Keishi Hattori0e45c022021-11-27 09:25:52802 raw_ptr<FrameTreeNode> opener_ = nullptr;
danakjc492bf82020-09-09 20:02:44803
804 // An observer that clears this node's |opener_| if the opener is destroyed.
805 // This observer is added to the |opener_|'s observer list when the |opener_|
806 // is set to a non-null node, and it is removed from that list when |opener_|
807 // changes or when this node is destroyed. It is also cleared if |opener_|
808 // is disowned.
809 std::unique_ptr<OpenerDestroyedObserver> opener_observer_;
810
Rakina Zata Amni3a48ae42022-05-05 03:39:56811 // Unlike `opener_`, the "original opener chain" doesn't reflect
812 // window.opener, which can be suppressed or updated. The "original opener"
813 // is the main frame of the actual opener of this frame. This traces the all
814 // the way back, so if the original opener was closed (deleted or severed due
815 // to COOP), but _it_ had an original opener, this will return the original
816 // opener's original opener, etc. So this value will always be set as long as
817 // there is at least one live frame in the chain whose connection is not
818 // severed due to COOP.
819 raw_ptr<FrameTreeNode> first_live_main_frame_in_original_opener_chain_ =
820 nullptr;
danakjc492bf82020-09-09 20:02:44821
Wolfgang Beyerd8809db2020-09-30 15:29:39822 // The devtools frame token of the frame which opened this frame. This is
823 // not cleared even if the opener is destroyed or disowns the frame.
Arthur Sonzognic686e8f2024-01-11 08:36:37824 std::optional<base::UnguessableToken> opener_devtools_frame_token_;
Wolfgang Beyerd8809db2020-09-30 15:29:39825
Rakina Zata Amni3a48ae42022-05-05 03:39:56826 // An observer that updates this node's
827 // |first_live_main_frame_in_original_opener_chain_| to the next original
828 // opener in the chain if the original opener is destroyed.
danakjc492bf82020-09-09 20:02:44829 std::unique_ptr<OpenerDestroyedObserver> original_opener_observer_;
830
arthursonzogni034bb9c2020-10-01 08:29:56831 // When created by an opener, the URL specified in window.open(url)
832 // Please refer to {Get,Set}InitialPopupURL() documentation.
833 GURL initial_popup_url_;
834
835 // When created using window.open, the origin of the creator.
836 // Please refer to {Get,Set}PopupCreatorOrigin() documentation.
837 url::Origin popup_creator_origin_;
838
W. James MacLean81b8d01f2022-01-25 20:50:59839 // If the url from the the last BeginNavigation is about:srcdoc, this value
840 // stores the srcdoc_attribute's value for re-use in history navigations.
841 std::string srcdoc_value_;
842
Charlie Reis734db662024-01-11 18:20:03843 // Whether this frame is still on the initial about:blank document or the
844 // synchronously committed about:blank document committed at frame creation,
845 // and its "initial empty document"-ness is still true.
846 // This will be false if either of these has happened:
847 // - The current RenderFrameHost commits a cross-document navigation that is
848 // not the synchronously committed about:blank document per:
849 // https://html.spec.whatwg.org/multipage/browsers.html#creating-browsing-contexts:is-initial-about:blank
850 // - The document's input stream has been opened with document.open(), per
851 // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#opening-the-input-stream:is-initial-about:blank
852 // NOTE: we treat both the "initial about:blank document" and the
853 // "synchronously committed about:blank document" as the initial empty
854 // document. In the future, we plan to remove the synchronous about:blank
855 // commit so that this state will only be true if the frame is on the
856 // "initial about:blank document". See also:
857 // - https://github.com/whatwg/html/issues/6863
858 // - https://crbug.com/1215096
859 //
860 // Note that cross-document navigations update this state at
861 // DidCommitNavigation() time. Thus, this is still true when a cross-document
862 // navigation from an initial empty document is in the pending-commit window,
863 // after sending the CommitNavigation IPC but before receiving
864 // DidCommitNavigation(). This is in contrast to
865 // has_committed_any_navigation(), which is updated in CommitNavigation().
866 // TODO(alexmos): Consider updating this at CommitNavigation() time as well to
867 // match the has_committed_any_navigation() behavior.
868 bool is_on_initial_empty_document_ = true;
869
danakjc492bf82020-09-09 20:02:44870 // Whether the frame's owner element in the parent document is collapsed.
arthursonzogni9816b9192021-03-29 16:09:19871 bool is_collapsed_ = false;
danakjc492bf82020-09-09 20:02:44872
Daniel Cheng6ac128172021-05-25 18:49:01873 // The type of frame owner for this frame. This is only relevant for non-main
874 // frames.
Kevin McNee43fe8292021-10-04 22:59:41875 const blink::FrameOwnerElementType frame_owner_element_type_ =
876 blink::FrameOwnerElementType::kNone;
Daniel Cheng9bd90f92021-04-23 20:49:45877
Daniel Cheng6ac128172021-05-25 18:49:01878 // The tree scope type of frame owner element, i.e. whether the element is in
879 // the document tree (https://dom.spec.whatwg.org/#document-trees) or the
880 // shadow tree (https://dom.spec.whatwg.org/#shadow-trees). This is only
881 // relevant for non-main frames.
882 const blink::mojom::TreeScopeType tree_scope_type_ =
883 blink::mojom::TreeScopeType::kDocument;
884
danakjc492bf82020-09-09 20:02:44885 // Track the pending sandbox flags and container policy for this frame. When a
886 // parent frame dynamically updates 'sandbox', 'allow', 'allowfullscreen',
887 // 'allowpaymentrequest' or 'src' attributes, the updated policy for the frame
Harkiran Bolaria4eacb3a2021-12-13 20:03:47888 // is stored here, and transferred into
889 // render_manager_.current_replication_state().frame_policy when they take
890 // effect on the next frame navigation.
danakjc492bf82020-09-09 20:02:44891 blink::FramePolicy pending_frame_policy_;
892
893 // Whether the frame was created by javascript. This is useful to prune
894 // history entries when the frame is removed (because frames created by
895 // scripts are never recreated with the same unique name - see
896 // https://crbug.com/500260).
arthursonzogni9816b9192021-03-29 16:09:19897 const bool is_created_by_script_;
danakjc492bf82020-09-09 20:02:44898
danakjc492bf82020-09-09 20:02:44899 // Tracks the scrolling and margin properties for this frame. These
900 // properties affect the child renderer but are stored on its parent's
901 // frame element. When this frame's parent dynamically updates these
902 // properties, we update them here too.
903 //
904 // Note that dynamic updates only take effect on the next frame navigation.
905 blink::mojom::FrameOwnerProperties frame_owner_properties_;
906
Yuzu Saijo03dbf9b2022-07-22 04:29:45907 // Contains the tracked HTML attributes of the corresponding iframe element,
908 // such as 'id' and 'src'.
909 blink::mojom::IframeAttributesPtr attributes_;
Antonio Sartori5abc8de2021-07-13 08:42:47910
danakjc492bf82020-09-09 20:02:44911 // Owns an ongoing NavigationRequest until it is ready to commit. It will then
912 // be reset and a RenderFrameHost will be responsible for the navigation.
913 std::unique_ptr<NavigationRequest> navigation_request_;
914
915 // List of objects observing this FrameTreeNode.
916 base::ObserverList<Observer>::Unchecked observers_;
917
918 base::TimeTicks last_focus_time_;
919
arthursonzogni9816b9192021-03-29 16:09:19920 bool was_discarded_ = false;
danakjc492bf82020-09-09 20:02:44921
Abhijeet Kandalkar3f29bc42022-09-23 12:39:58922 const FencedFrameStatus fenced_frame_status_ =
923 FencedFrameStatus::kNotNestedInFencedFrame;
Harkiran Bolaria16f2c48d2022-04-22 12:39:57924
Garrett Tanzerc69f4642022-08-15 22:15:14925 // If this is a fenced frame resulting from a urn:uuid navigation, this
926 // contains all the metadata specifying the resulting context.
Alison Gale770f3fc2024-04-27 00:39:58927 // TODO(crbug.com/40202462): Move this into the FrameTree once ShadowDOM
Garrett Tanzer34cb92fe2022-09-28 17:50:54928 // and urn iframes are gone.
Arthur Sonzognic686e8f2024-01-11 08:36:37929 std::optional<FencedFrameProperties> fenced_frame_properties_;
Garrett Tanzerc69f4642022-08-15 22:15:14930
Mingyu Lei7956b8b2023-07-24 08:24:08931 // The tracker of the task that restarts the BFCache navigation. It might be
932 // used to cancel the task.
933 // See `CancelRestartingBackForwardCacheNavigation()`.
934 base::CancelableTaskTracker restart_back_forward_cached_navigation_tracker_;
935
Lukasz Anforowicz147141962020-12-16 18:03:24936 // Manages creation and swapping of RenderFrameHosts for this frame.
937 //
938 // This field needs to be declared last, because destruction of
939 // RenderFrameHostManager may call arbitrary callbacks (e.g. via
940 // WebContentsObserver::DidFinishNavigation fired after RenderFrameHostManager
941 // destructs a RenderFrameHostImpl and its NavigationRequest). Such callbacks
942 // may try to use FrameTreeNode's fields above - this would be an undefined
943 // behavior if the fields (even trivially-destructible ones) were destructed
944 // before the RenderFrameHostManager's destructor runs. See also
945 // https://crbug.com/1157988.
946 RenderFrameHostManager render_manager_;
Mingyu Lei7956b8b2023-07-24 08:24:08947
948 base::WeakPtrFactory<FrameTreeNode> weak_factory_{this};
danakjc492bf82020-09-09 20:02:44949};
950
951} // namespace content
952
953#endif // CONTENT_BROWSER_RENDERER_HOST_FRAME_TREE_NODE_H_