blob: c220cfc58264bfc3fe4cfabc122b913d46fcfc3d [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"
Daniel Cheng390e2a72022-09-28 06:07:5322#include "content/browser/renderer_host/navigation_discard_reason.h"
danakjc492bf82020-09-09 20:02:4423#include "content/browser/renderer_host/navigator.h"
24#include "content/browser/renderer_host/render_frame_host_impl.h"
25#include "content/browser/renderer_host/render_frame_host_manager.h"
Miyoung Shin7cf88b42022-11-07 13:22:3026#include "content/browser/renderer_host/render_frame_host_owner.h"
danakjc492bf82020-09-09 20:02:4427#include "content/common/content_export.h"
Julie Jeongeun Kimf38c1eca2021-12-14 07:46:5528#include "content/public/browser/frame_type.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;
44class RenderFrameHostImpl;
45class NavigationEntryImpl;
Paul Semel3e241042022-10-11 12:57:3146class FrameTree;
danakjc492bf82020-09-09 20:02:4447
48// When a page contains iframes, its renderer process maintains a tree structure
49// of those frames. We are mirroring this tree in the browser process. This
50// class represents a node in this tree and is a wrapper for all objects that
51// are frame-specific (as opposed to page-specific).
52//
53// Each FrameTreeNode has a current RenderFrameHost, which can change over
54// time as the frame is navigated. Any immediate subframes of the current
55// document are tracked using FrameTreeNodes owned by the current
56// RenderFrameHost, rather than as children of FrameTreeNode itself. This
57// allows subframe FrameTreeNodes to stay alive while a RenderFrameHost is
58// still alive - for example while pending deletion, after a new current
59// RenderFrameHost has replaced it.
Miyoung Shin7cf88b42022-11-07 13:22:3060class CONTENT_EXPORT FrameTreeNode : public RenderFrameHostOwner {
danakjc492bf82020-09-09 20:02:4461 public:
62 class Observer {
63 public:
64 // Invoked when a FrameTreeNode is being destroyed.
65 virtual void OnFrameTreeNodeDestroyed(FrameTreeNode* node) {}
66
67 // Invoked when a FrameTreeNode becomes focused.
68 virtual void OnFrameTreeNodeFocused(FrameTreeNode* node) {}
69
Arthur Hemerye4659282022-03-28 08:36:1570 // Invoked when a FrameTreeNode moves to a different BrowsingInstance and
71 // the popups it opened should be disowned.
72 virtual void OnFrameTreeNodeDisownedOpenee(FrameTreeNode* node) {}
73
Fergal Dalya1d569972021-03-16 03:24:5374 virtual ~Observer() = default;
danakjc492bf82020-09-09 20:02:4475 };
76
77 static const int kFrameTreeNodeInvalidId;
78
79 // Returns the FrameTreeNode with the given global |frame_tree_node_id|,
80 // regardless of which FrameTree it is in.
81 static FrameTreeNode* GloballyFindByID(int frame_tree_node_id);
82
83 // Returns the FrameTreeNode for the given |rfh|. Same as
84 // rfh->frame_tree_node(), but also supports nullptrs.
85 static FrameTreeNode* From(RenderFrameHost* rfh);
86
87 // Callers are are expected to initialize sandbox flags separately after
88 // calling the constructor.
89 FrameTreeNode(
Arthur Sonzognif6785ec2022-12-05 10:11:5090 FrameTree& frame_tree,
danakjc492bf82020-09-09 20:02:4491 RenderFrameHostImpl* parent,
Daniel Cheng6ac128172021-05-25 18:49:0192 blink::mojom::TreeScopeType tree_scope_type,
danakjc492bf82020-09-09 20:02:4493 bool is_created_by_script,
danakjc492bf82020-09-09 20:02:4494 const blink::mojom::FrameOwnerProperties& frame_owner_properties,
Kevin McNee43fe8292021-10-04 22:59:4195 blink::FrameOwnerElementType owner_type,
Dominic Farolino08662c82021-06-11 07:36:3496 const blink::FramePolicy& frame_owner);
danakjc492bf82020-09-09 20:02:4497
Peter Boström828b9022021-09-21 02:28:4398 FrameTreeNode(const FrameTreeNode&) = delete;
99 FrameTreeNode& operator=(const FrameTreeNode&) = delete;
100
Miyoung Shin7cf88b42022-11-07 13:22:30101 ~FrameTreeNode() override;
danakjc492bf82020-09-09 20:02:44102
103 void AddObserver(Observer* observer);
104 void RemoveObserver(Observer* observer);
105
Ian Vollick25a9d032022-04-12 23:20:17106 // Frame trees may be nested so it can be the case that IsMainFrame() is true,
107 // but is not the outermost main frame. In particular, !IsMainFrame() cannot
108 // be used to check if the frame is an embedded frame -- use
109 // !IsOutermostMainFrame() instead. NB: this does not escape guest views;
110 // IsOutermostMainFrame will be true for the outermost main frame in an inner
111 // guest view.
danakjc492bf82020-09-09 20:02:44112 bool IsMainFrame() const;
Arthur Hemerya06697f2023-03-14 09:20:57113 bool IsOutermostMainFrame() const;
danakjc492bf82020-09-09 20:02:44114
arthursonzogni76098e52020-11-25 14:18:45115 // Clears any state in this node which was set by the document itself (CSP &
116 // UserActivationState) and notifies proxies as appropriate. Invoked after
117 // committing navigation to a new document (since the new document comes with
118 // a fresh set of CSP).
119 // TODO(arthursonzogni): Remove this function. The frame/document must not be
120 // left temporarily with lax state.
Hiroki Nakagawaab309622021-05-19 16:38:13121 void ResetForNavigation();
danakjc492bf82020-09-09 20:02:44122
Arthur Sonzognif6785ec2022-12-05 10:11:50123 FrameTree& frame_tree() const { return frame_tree_.get(); }
Paul Semel3e241042022-10-11 12:57:31124 Navigator& navigator();
danakjc492bf82020-09-09 20:02:44125
126 RenderFrameHostManager* render_manager() { return &render_manager_; }
Alexander Timin33e2e2c12022-03-03 04:21:33127 const RenderFrameHostManager* render_manager() const {
128 return &render_manager_;
129 }
danakjc492bf82020-09-09 20:02:44130 int frame_tree_node_id() const { return frame_tree_node_id_; }
Yuzu Saijo03dbf9b2022-07-22 04:29:45131 // This reflects window.name, which is initially set to the the "name"
132 // attribute. But this won't reflect changes of 'name' attribute and instead
133 // reflect changes to the Window object's name property.
134 // This is different from IframeAttributes' name in that this will not get
135 // updated when 'name' attribute gets updated.
Harkiran Bolaria4eacb3a2021-12-13 20:03:47136 const std::string& frame_name() const {
137 return render_manager_.current_replication_state().name;
138 }
danakjc492bf82020-09-09 20:02:44139
140 const std::string& unique_name() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47141 return render_manager_.current_replication_state().unique_name;
danakjc492bf82020-09-09 20:02:44142 }
143
danakjc492bf82020-09-09 20:02:44144 size_t child_count() const { return current_frame_host()->child_count(); }
145
danakjc492bf82020-09-09 20:02:44146 RenderFrameHostImpl* parent() const { return parent_; }
147
Dave Tapuskac8de3b02021-12-03 21:51:01148 // See `RenderFrameHost::GetParentOrOuterDocument()` for
149 // documentation.
Arthur Hemerya06697f2023-03-14 09:20:57150 RenderFrameHostImpl* GetParentOrOuterDocument() const;
Dave Tapuskac8de3b02021-12-03 21:51:01151
152 // See `RenderFrameHostImpl::GetParentOrOuterDocumentOrEmbedder()` for
153 // documentation.
154 RenderFrameHostImpl* GetParentOrOuterDocumentOrEmbedder();
155
danakjc492bf82020-09-09 20:02:44156 FrameTreeNode* opener() const { return opener_; }
157
Rakina Zata Amni3a48ae42022-05-05 03:39:56158 FrameTreeNode* first_live_main_frame_in_original_opener_chain() const {
159 return first_live_main_frame_in_original_opener_chain_;
160 }
danakjc492bf82020-09-09 20:02:44161
Arthur Sonzognic686e8f2024-01-11 08:36:37162 const std::optional<base::UnguessableToken>& opener_devtools_frame_token() {
Wolfgang Beyerd8809db2020-09-30 15:29:39163 return opener_devtools_frame_token_;
164 }
165
Julie Jeongeun Kimf38c1eca2021-12-14 07:46:55166 // Returns the type of the frame. Refer to frame_type.h for the details.
167 FrameType GetFrameType() const;
168
danakjc492bf82020-09-09 20:02:44169 // Assigns a new opener for this node and, if |opener| is non-null, registers
170 // an observer that will clear this node's opener if |opener| is ever
171 // destroyed.
172 void SetOpener(FrameTreeNode* opener);
173
174 // Assigns the initial opener for this node, and if |opener| is non-null,
175 // registers an observer that will clear this node's opener if |opener| is
176 // ever destroyed. The value set here is the root of the tree.
177 //
178 // It is not possible to change the opener once it was set.
179 void SetOriginalOpener(FrameTreeNode* opener);
180
Wolfgang Beyerd8809db2020-09-30 15:29:39181 // Assigns an opener frame id for this node. This string id is only set once
182 // and cannot be changed. It persists, even if the |opener| is destroyed. It
183 // is used for attribution in the DevTools frontend.
184 void SetOpenerDevtoolsFrameToken(
185 base::UnguessableToken opener_devtools_frame_token);
186
danakjc492bf82020-09-09 20:02:44187 FrameTreeNode* child_at(size_t index) const {
188 return current_frame_host()->child_at(index);
189 }
190
191 // Returns the URL of the last committed page in the current frame.
192 const GURL& current_url() const {
193 return current_frame_host()->GetLastCommittedURL();
194 }
195
Abhijeet Kandalkarb86993b2022-11-22 05:17:40196 // Note that the current RenderFrameHost might not exist yet when calling this
197 // during FrameTreeNode initialization. In this case the FrameTreeNode must be
198 // on the initial empty document. Refer RFHI::is_initial_empty_document for a
199 // more details.
Rakina Zata Amni86c88fa2021-11-01 01:27:30200 bool is_on_initial_empty_document() const {
Abhijeet Kandalkarb86993b2022-11-22 05:17:40201 return current_frame_host()
202 ? current_frame_host()->is_initial_empty_document()
203 : true;
Rakina Zata Amnifc4cc3d42021-06-10 09:03:56204 }
205
danakjc492bf82020-09-09 20:02:44206 // Returns whether the frame's owner element in the parent document is
207 // collapsed, that is, removed from the layout as if it did not exist, as per
208 // request by the embedder (of the content/ layer).
209 bool is_collapsed() const { return is_collapsed_; }
210
211 // Sets whether to collapse the frame's owner element in the parent document,
212 // that is, to remove it from the layout as if it did not exist, as per
213 // request by the embedder (of the content/ layer). Cannot be called for main
214 // frames.
215 //
216 // This only has an effect for <iframe> owner elements, and is a no-op when
217 // called on sub-frames hosted in <frame>, <object>, and <embed> elements.
218 void SetCollapsed(bool collapsed);
219
220 // Returns the origin of the last committed page in this frame.
221 // WARNING: To get the last committed origin for a particular
222 // RenderFrameHost, use RenderFrameHost::GetLastCommittedOrigin() instead,
223 // which will behave correctly even when the RenderFrameHost is not the
224 // current one for this frame (such as when it's pending deletion).
225 const url::Origin& current_origin() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47226 return render_manager_.current_replication_state().origin;
danakjc492bf82020-09-09 20:02:44227 }
228
danakjc492bf82020-09-09 20:02:44229 // Returns the latest frame policy (sandbox flags and container policy) for
230 // this frame. This includes flags inherited from parent frames and the latest
231 // flags from the <iframe> element hosting this frame. The returned policies
232 // may not yet have taken effect, since "sandbox" and "allow" attribute
Liam Brady25a14162022-12-02 15:25:57233 // updates in an <iframe> element take effect on next navigation. For
234 // <fencedframe> elements, not everything in the frame policy might actually
235 // take effect after the navigation. To retrieve the currently active policy
236 // for this frame, use effective_frame_policy().
danakjc492bf82020-09-09 20:02:44237 const blink::FramePolicy& pending_frame_policy() const {
238 return pending_frame_policy_;
239 }
240
241 // Update this frame's sandbox flags and container policy. This is called
242 // when a parent frame updates the "sandbox" attribute in the <iframe> element
243 // for this frame, or any of the attributes which affect the container policy
244 // ("allowfullscreen", "allowpaymentrequest", "allow", and "src".)
245 // These policies won't take effect until next navigation. If this frame's
246 // parent is itself sandboxed, the parent's sandbox flags are combined with
247 // those in |frame_policy|.
248 // Attempting to change the container policy on the main frame will have no
249 // effect.
250 void SetPendingFramePolicy(blink::FramePolicy frame_policy);
251
252 // Returns the currently active frame policy for this frame, including the
253 // sandbox flags which were present at the time the document was loaded, and
Charlie Hu5130d25e2021-03-05 21:53:39254 // the permissions policy container policy, which is set by the iframe's
danakjc492bf82020-09-09 20:02:44255 // allowfullscreen, allowpaymentrequest, and allow attributes, along with the
256 // origin of the iframe's src attribute (which may be different from the URL
257 // of the document currently loaded into the frame). This does not include
258 // policy changes that have been made by updating the containing iframe
259 // element attributes since the frame was last navigated; use
260 // pending_frame_policy() for those.
261 const blink::FramePolicy& effective_frame_policy() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47262 return render_manager_.current_replication_state().frame_policy;
danakjc492bf82020-09-09 20:02:44263 }
264
danakjc492bf82020-09-09 20:02:44265 const blink::mojom::FrameOwnerProperties& frame_owner_properties() {
266 return frame_owner_properties_;
267 }
268
269 void set_frame_owner_properties(
270 const blink::mojom::FrameOwnerProperties& frame_owner_properties) {
271 frame_owner_properties_ = frame_owner_properties;
272 }
273
Yuzu Saijo03dbf9b2022-07-22 04:29:45274 // Reflects the attributes of the corresponding iframe html element, such
Arthur Sonzogni64457592022-11-22 11:08:59275 // as 'credentialless', 'id', 'name' and 'src'. These values should not be
Yuzu Saijo03dbf9b2022-07-22 04:29:45276 // exposed to cross-origin renderers.
277 const network::mojom::ContentSecurityPolicy* csp_attribute() const {
278 return attributes_->parsed_csp_attribute.get();
danakjc492bf82020-09-09 20:02:44279 }
Yao Xiao9c54b3e2023-03-14 04:25:04280 // Tracks iframe's 'browsingtopics' attribute, indicating whether the
281 // navigation requests on this frame should calculate and send the
282 // `Sec-Browsing-Topics` header.
283 bool browsing_topics() const { return attributes_->browsing_topics; }
Camillia Smith Barnes6d2966c82023-08-23 21:16:18284
Orr Bernsteina0cc6792023-11-14 22:12:35285 // Tracks iframe's 'adauctionheaders' attribute, indicating whether the
286 // navigation request on this frame should calculate and send the
287 // 'Sec-Ad-Auction-Fetch` header.
288 bool ad_auction_headers() const { return attributes_->ad_auction_headers; }
289
Camillia Smith Barnes6d2966c82023-08-23 21:16:18290 // Tracks iframe's 'sharedstoragewritable' attribute, indicating what value
Camillia Smith Barnesc267be62023-11-01 20:01:02291 // the the corresponding
292 // `network::ResourceRequest::shared_storage_writable_eligible` should take
293 // for the navigation(s) on this frame, pending a permissions policy check. If
294 // true, and if the permissions policy check returns "enabled", the network
Camillia Smith Barnes6d2966c82023-08-23 21:16:18295 // service will send the `Shared-Storage-Write` request header.
Camillia Smith Barnesc267be62023-11-01 20:01:02296 bool shared_storage_writable_opted_in() const {
297 return attributes_->shared_storage_writable_opted_in;
Camillia Smith Barnes6d2966c82023-08-23 21:16:18298 }
Arthur Sonzognic686e8f2024-01-11 08:36:37299 const std::optional<std::string> html_id() const { return attributes_->id; }
Yuzu Saijo03dbf9b2022-07-22 04:29:45300 // This tracks iframe's 'name' attribute instead of window.name, which is
301 // tracked in FrameReplicationState. See the comment for frame_name() for
302 // more details.
Arthur Sonzognic686e8f2024-01-11 08:36:37303 const std::optional<std::string> html_name() const {
Yuzu Saijodc870f92023-01-20 03:39:11304 return attributes_->name;
305 }
Arthur Sonzognic686e8f2024-01-11 08:36:37306 const std::optional<std::string> html_src() const { return attributes_->src; }
danakjc492bf82020-09-09 20:02:44307
Yuzu Saijo03dbf9b2022-07-22 04:29:45308 void SetAttributes(blink::mojom::IframeAttributesPtr attributes);
Antonio Sartori5abc8de2021-07-13 08:42:47309
danakjc492bf82020-09-09 20:02:44310 bool HasSameOrigin(const FrameTreeNode& node) const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47311 return render_manager_.current_replication_state().origin.IsSameOriginWith(
312 node.current_replication_state().origin);
danakjc492bf82020-09-09 20:02:44313 }
314
Gyuyoung Kimc16e52e92021-03-19 02:45:37315 const blink::mojom::FrameReplicationState& current_replication_state() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47316 return render_manager_.current_replication_state();
danakjc492bf82020-09-09 20:02:44317 }
318
319 RenderFrameHostImpl* current_frame_host() const {
320 return render_manager_.current_frame_host();
321 }
322
danakjc492bf82020-09-09 20:02:44323 // Returns true if this node is in a loading state.
324 bool IsLoading() const;
Nate Chapin470dbc62023-04-25 16:34:38325 LoadingState GetLoadingState() const;
danakjc492bf82020-09-09 20:02:44326
Alex Moshchuk9b0fd822020-10-26 23:08:15327 // Returns true if this node has a cross-document navigation in progress.
328 bool HasPendingCrossDocumentNavigation() const;
329
danakjc492bf82020-09-09 20:02:44330 NavigationRequest* navigation_request() { return navigation_request_.get(); }
331
332 // Transfers the ownership of the NavigationRequest to |render_frame_host|.
333 // From ReadyToCommit to DidCommit, the NavigationRequest is owned by the
334 // RenderFrameHost that is committing the navigation.
335 void TransferNavigationRequestOwnership(
336 RenderFrameHostImpl* render_frame_host);
337
338 // Takes ownership of |navigation_request| and makes it the current
339 // NavigationRequest of this frame. This corresponds to the start of a new
340 // navigation. If there was an ongoing navigation request before calling this
341 // function, it is canceled. |navigation_request| should not be null.
Charlie Reis09952ee2022-12-08 16:35:07342 void TakeNavigationRequest(
danakjc492bf82020-09-09 20:02:44343 std::unique_ptr<NavigationRequest> navigation_request);
344
Rakina Zata Amnif8f2bb62022-11-23 05:54:32345 // Resets the navigation request owned by `this` (which shouldn't have reached
346 // the "pending commit" stage yet) and any state created by it, including the
Rakina Zata Amni33175cb92022-11-24 02:46:03347 // speculative RenderFrameHost (if there are no other navigations associated
348 // with it). Note that this does not affect navigations that have reached the
349 // "pending commit" stage, which are owned by their corresponding
350 // RenderFrameHosts instead.
Daniel Cheng390e2a72022-09-28 06:07:53351 void ResetNavigationRequest(NavigationDiscardReason reason);
352
Rakina Zata Amnif8f2bb62022-11-23 05:54:32353 // Similar to `ResetNavigationRequest()`, but keeps the state created by the
Daniel Cheng390e2a72022-09-28 06:07:53354 // NavigationRequest (e.g. speculative RenderFrameHost, loading state).
355 void ResetNavigationRequestButKeepState();
danakjc492bf82020-09-09 20:02:44356
danakjc492bf82020-09-09 20:02:44357 // The load progress for a RenderFrameHost in this node was updated to
358 // |load_progress|. This will notify the FrameTree which will in turn notify
359 // the WebContents.
360 void DidChangeLoadProgress(double load_progress);
361
362 // Called when the user directed the page to stop loading. Stops all loads
363 // happening in the FrameTreeNode. This method should be used with
364 // FrameTree::ForEach to stop all loads in the entire FrameTree.
365 bool StopLoading();
366
367 // Returns the time this frame was last focused.
368 base::TimeTicks last_focus_time() const { return last_focus_time_; }
369
370 // Called when this node becomes focused. Updates the node's last focused
371 // time and notifies observers.
372 void DidFocus();
373
374 // Called when the user closed the modal dialogue for BeforeUnload and
375 // cancelled the navigation. This should stop any load happening in the
376 // FrameTreeNode.
377 void BeforeUnloadCanceled();
378
danakjc492bf82020-09-09 20:02:44379 // Returns the sandbox flags currently in effect for this frame. This includes
380 // flags inherited from parent frames, the currently active flags from the
381 // <iframe> element hosting this frame, as well as any flags set from a
382 // Content-Security-Policy HTTP header. This does not include flags that have
383 // have been updated in an <iframe> element but have not taken effect yet; use
384 // pending_frame_policy() for those. To see the flags which will take effect
385 // on navigation (which does not include the CSP-set flags), use
386 // effective_frame_policy().
387 network::mojom::WebSandboxFlags active_sandbox_flags() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47388 return render_manager_.current_replication_state().active_sandbox_flags;
danakjc492bf82020-09-09 20:02:44389 }
390
danakjc492bf82020-09-09 20:02:44391 // Returns whether the frame received a user gesture on a previous navigation
392 // on the same eTLD+1.
393 bool has_received_user_gesture_before_nav() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47394 return render_manager_.current_replication_state()
395 .has_received_user_gesture_before_nav;
danakjc492bf82020-09-09 20:02:44396 }
397
398 // When a tab is discarded, WebContents sets was_discarded on its
399 // root FrameTreeNode.
400 // In addition, when a child frame is created, this bit is passed on from
401 // parent to child.
402 // When a navigation request is created, was_discarded is passed on to the
403 // request and reset to false in FrameTreeNode.
404 void set_was_discarded() { was_discarded_ = true; }
405 bool was_discarded() const { return was_discarded_; }
406
Miyoung Shin8a66ec022022-11-28 23:50:09407 // Deprecated. Use directly HasStickyUserActivation in RFHI.
danakjc492bf82020-09-09 20:02:44408 // Returns the sticky bit of the User Activation v2 state of the
409 // |FrameTreeNode|.
410 bool HasStickyUserActivation() const {
Miyoung Shin8a66ec022022-11-28 23:50:09411 return current_frame_host()->HasStickyUserActivation();
danakjc492bf82020-09-09 20:02:44412 }
413
Miyoung Shin8a66ec022022-11-28 23:50:09414 // Deprecated. Use directly HasStickyUserActivation in RFHI.
danakjc492bf82020-09-09 20:02:44415 // Returns the transient bit of the User Activation v2 state of the
416 // |FrameTreeNode|.
417 bool HasTransientUserActivation() {
Miyoung Shin8a66ec022022-11-28 23:50:09418 return current_frame_host()->HasTransientUserActivation();
danakjc492bf82020-09-09 20:02:44419 }
420
421 // Remove history entries for all frames created by script in this frame's
422 // subtree. If a frame created by a script is removed, then its history entry
423 // will never be reused - this saves memory.
424 void PruneChildFrameNavigationEntries(NavigationEntryImpl* entry);
425
Abhijeet Kandalkarb43affa72022-09-27 16:48:01426 using FencedFrameStatus = RenderFrameHostImpl::FencedFrameStatus;
Abhijeet Kandalkar3f29bc42022-09-23 12:39:58427 FencedFrameStatus fenced_frame_status() const { return fenced_frame_status_; }
428
Kevin McNee43fe8292021-10-04 22:59:41429 blink::FrameOwnerElementType frame_owner_element_type() const {
Daniel Cheng9bd90f92021-04-23 20:49:45430 return frame_owner_element_type_;
danakjc492bf82020-09-09 20:02:44431 }
danakjc492bf82020-09-09 20:02:44432
Daniel Cheng6ac128172021-05-25 18:49:01433 blink::mojom::TreeScopeType tree_scope_type() const {
434 return tree_scope_type_;
435 }
436
arthursonzogni034bb9c2020-10-01 08:29:56437 // The initial popup URL for new window opened using:
438 // `window.open(initial_popup_url)`.
439 // An empty GURL otherwise.
440 //
441 // [WARNING] There is no guarantee the FrameTreeNode will ever host a
442 // document served from this URL. The FrameTreeNode always starts hosting the
443 // initial empty document and attempts a navigation toward this URL. However
444 // the navigation might be delayed, redirected and even cancelled.
445 void SetInitialPopupURL(const GURL& initial_popup_url);
446 const GURL& initial_popup_url() const { return initial_popup_url_; }
447
448 // The origin of the document that used window.open() to create this frame.
449 // Otherwise, an opaque Origin with a nonce different from all previously
450 // existing Origins.
451 void SetPopupCreatorOrigin(const url::Origin& popup_creator_origin);
452 const url::Origin& popup_creator_origin() const {
453 return popup_creator_origin_;
454 }
455
Harkiran Bolaria59290d62021-03-17 01:53:01456 // Sets the associated FrameTree for this node. The node can change FrameTrees
Domenic Denicola7767a9c2023-07-13 15:36:39457 // as part of prerendering, which allows a page loaded in the prerendered
458 // FrameTree to be used for a navigation in the primary frame tree.
Harkiran Bolaria59290d62021-03-17 01:53:01459 void SetFrameTree(FrameTree& frame_tree);
460
Alexander Timin074cd182022-03-23 18:11:22461 using TraceProto = perfetto::protos::pbzero::FrameTreeNodeInfo;
Alexander Timinf785f342021-03-18 00:00:56462 // Write a representation of this object into a trace.
Alexander Timin074cd182022-03-23 18:11:22463 void WriteIntoTrace(perfetto::TracedProto<TraceProto> proto) const;
Alexander Timinf785f342021-03-18 00:00:56464
Carlos Caballero76711352021-03-24 17:38:21465 // Returns true the node is navigating, i.e. it has an associated
466 // NavigationRequest.
467 bool HasNavigation();
468
murakinonoka97a8f042024-01-10 09:17:07469 // Returns true if there are any navigations happening in FrameTreeNode that
470 // is pending commit (i.e. between ReadyToCommit and DidCommit). Note that
471 // those navigations won't live in the FrameTreeNode itself, as they will
472 // already be owned by the committing RenderFrameHost (either the current
473 // RenderFrameHost or the speculative RenderFrameHost).
474 bool HasPendingCommitNavigation();
475
shivanigithubf3ddff52021-07-03 22:06:30476 // Fenced frames (meta-bug crbug.com/1111084):
shivanigithub4cd016a2021-09-20 21:10:30477 // Note that these two functions cannot be invoked from a FrameTree's or
478 // its root node's constructor since they require the frame tree and the
479 // root node to be completely constructed.
480 //
shivanigithubf3ddff52021-07-03 22:06:30481 // Returns false if fenced frames are disabled. Returns true if the feature is
482 // enabled and if |this| is a fenced frame. Returns false for
483 // iframes embedded in a fenced frame. To clarify: for the MPArch
484 // implementation this only returns true if |this| is the actual
485 // root node of the inner FrameTree and not the proxy FrameTreeNode in the
486 // outer FrameTree.
Dominic Farolino4bc10ee2021-08-31 00:37:36487 bool IsFencedFrameRoot() const;
shivanigithubf3ddff52021-07-03 22:06:30488
489 // Returns false if fenced frames are disabled. Returns true if the
490 // feature is enabled and if |this| or any of its ancestor nodes is a
491 // fenced frame.
492 bool IsInFencedFrameTree() const;
493
shivanigithub4cd016a2021-09-20 21:10:30494 // Returns a valid nonce if `IsInFencedFrameTree()` returns true for `this`.
Garrett Tanzer34cb92fe2022-09-28 17:50:54495 // Returns nullopt otherwise.
496 //
497 // Nonce used in the net::IsolationInfo and blink::StorageKey for a fenced
498 // frame and any iframes nested within it. Not set if this frame is not in a
499 // fenced frame's FrameTree. Note that this could be a field in FrameTree for
500 // the MPArch version but for the shadow DOM version we need to keep it here
501 // since the fenced frame root is not a main frame for the latter. The value
502 // of the nonce will be the same for all of the the iframes inside a fenced
503 // frame tree. If there is a nested fenced frame it will have a different
504 // nonce than its parent fenced frame. The nonce will stay the same across
505 // navigations initiated from the fenced frame tree because it is always used
506 // in conjunction with other fields of the keys and would be good to access
507 // the same storage across same-origin navigations. If the navigation is
508 // same-origin/site then the same network stack partition/storage will be
509 // reused and if it's cross-origin/site then other parts of the key will
510 // change and so, even with the same nonce, another partition will be used.
511 // But if the navigation is initiated from the embedder, the nonce will be
512 // reinitialized irrespective of same or cross origin such that there is no
513 // privacy leak via storage shared between two embedder initiated navigations.
514 // Note that this reinitialization is implemented for all embedder-initiated
515 // navigations in MPArch, but only urn:uuid navigations in ShadowDOM.
Arthur Sonzognic686e8f2024-01-11 08:36:37516 std::optional<base::UnguessableToken> GetFencedFrameNonce();
shivanigithub4cd016a2021-09-20 21:10:30517
Garrett Tanzer34cb92fe2022-09-28 17:50:54518 // If applicable, initialize the default fenced frame properties. Right now,
519 // this means setting a new fenced frame nonce. See comment on
shivanigithub4cd016a2021-09-20 21:10:30520 // fenced_frame_nonce() for when it is set to a non-null value. Invoked
521 // by FrameTree::Init() or FrameTree::AddFrame().
Garrett Tanzer34cb92fe2022-09-28 17:50:54522 void SetFencedFramePropertiesIfNeeded();
shivanigithub4cd016a2021-09-20 21:10:30523
Garrett Tanzer291a2d52023-03-20 22:41:57524 // Set the current FencedFrameProperties to have "opaque ads mode".
525 // This should only be used during tests, when the proper embedder-initiated
526 // fenced frame root urn/config navigation flow isn't available.
527 // TODO(crbug.com/1347953): Refactor and expand use of test utils so there is
528 // a consistent way to do this properly everywhere. Consider removing
529 // arbitrary restrictions in "default mode" so that using opaque ads mode is
530 // less necessary.
531 void SetFencedFramePropertiesOpaqueAdsModeForTesting() {
532 if (fenced_frame_properties_.has_value()) {
Garrett Tanzer06980702023-12-12 19:48:20533 fenced_frame_properties_
534 ->SetFencedFramePropertiesOpaqueAdsModeForTesting();
Garrett Tanzer291a2d52023-03-20 22:41:57535 }
536 }
537
538 // Returns the mode attribute from the `FencedFrameProperties` if this frame
539 // is in a fenced frame tree, otherwise returns `kDefault`.
540 blink::FencedFrame::DeprecatedFencedFrameMode GetDeprecatedFencedFrameMode();
Nan Lin171fe9a2022-02-17 16:42:16541
Dave Tapuskac8de3b02021-12-03 21:51:01542 // Helper for GetParentOrOuterDocument/GetParentOrOuterDocumentOrEmbedder.
543 // Do not use directly.
Kevin McNee86e64ee2023-02-17 16:35:50544 // `escape_guest_view` determines whether to iterate out of guest views and is
545 // the behaviour distinction between GetParentOrOuterDocument and
546 // GetParentOrOuterDocumentOrEmbedder. See the comment on
547 // GetParentOrOuterDocumentOrEmbedder for details.
548 // `include_prospective` includes embedders which own our frame tree, but have
549 // not yet attached it to the outer frame tree.
Arthur Hemerya06697f2023-03-14 09:20:57550 RenderFrameHostImpl* GetParentOrOuterDocumentHelper(
551 bool escape_guest_view,
552 bool include_prospective) const;
Dave Tapuskac8de3b02021-12-03 21:51:01553
Harkiran Bolariab4437fd2021-08-11 17:51:22554 // Sets the unique_name and name fields on replication_state_. To be used in
555 // prerender activation to make sure the FrameTreeNode replication state is
556 // correct after the RenderFrameHost is moved between FrameTreeNodes. The
557 // renderers should already have the correct value, so unlike
558 // FrameTreeNode::SetFrameName, we do not notify them here.
Harkiran Bolaria4eacb3a2021-12-13 20:03:47559 // TODO(https://crbug.com/1237091): Remove this once the BrowsingContextState
560 // is implemented to utilize the new path.
Harkiran Bolariab4437fd2021-08-11 17:51:22561 void set_frame_name_for_activation(const std::string& unique_name,
562 const std::string& name) {
Harkiran Bolaria0b3bdef02022-03-10 13:04:40563 current_frame_host()->browsing_context_state()->set_frame_name(unique_name,
564 name);
Harkiran Bolariab4437fd2021-08-11 17:51:22565 }
566
Nan Linaaf84f72021-12-02 22:31:56567 // Returns true if error page isolation is enabled.
568 bool IsErrorPageIsolationEnabled() const;
569
W. James MacLean81b8d01f2022-01-25 20:50:59570 // Functions to store and retrieve a frame's srcdoc value on this
571 // FrameTreeNode.
572 void SetSrcdocValue(const std::string& srcdoc_value);
573 const std::string& srcdoc_value() const { return srcdoc_value_; }
574
Garrett Tanzerc69f4642022-08-15 22:15:14575 void set_fenced_frame_properties(
Arthur Sonzognic686e8f2024-01-11 08:36:37576 const std::optional<FencedFrameProperties>& fenced_frame_properties) {
Garrett Tanzer2975eeac2022-08-22 16:34:01577 // TODO(crbug.com/1262022): Reenable this DCHECK once ShadowDOM and
578 // loading urns in iframes (for FLEDGE OT) are gone.
579 // DCHECK_EQ(fenced_frame_status_,
580 // RenderFrameHostImpl::FencedFrameStatus::kFencedFrameRoot);
Garrett Tanzerc69f4642022-08-15 22:15:14581 fenced_frame_properties_ = fenced_frame_properties;
582 }
583
Xiaochen Zhou86f2e712023-09-13 19:55:04584 // This function returns the fenced frame properties associated with the given
585 // source.
586 // - If `source_node` is set to `kClosestAncestor`, the fenced frame
587 // properties are obtained by a bottom-up traversal from this node.
588 // - If `source_node` is set tp `kFrameTreeRoot`, the fenced frame properties
589 // from the fenced frame tree root are returned.
590 // For example, for an urn iframe that is nested inside a fenced frame.
591 // Calling this function from the nested urn iframe with `source_node` set to:
592 // - `kClosestAncestor`: returns the fenced frame properties from the urn
593 // iframe.
594 // - `kFrameTreeRoot`: returns the fenced frame properties from the fenced
595 // frame.
596 // Clients should decide which one to use depending on how the application of
597 // the fenced frame properties interact with urn iframes.
598 // TODO(crbug.com/1355857): Once navigation support for urn::uuid in iframes
599 // is deprecated, remove the parameter `node_source`.
Arthur Sonzognic686e8f2024-01-11 08:36:37600 std::optional<FencedFrameProperties>& GetFencedFrameProperties(
Xiaochen Zhou86f2e712023-09-13 19:55:04601 FencedFramePropertiesNodeSource node_source =
602 FencedFramePropertiesNodeSource::kClosestAncestor);
Garrett Tanzerc69f4642022-08-15 22:15:14603
Liam Brady86ca0482023-12-06 19:49:25604 bool HasFencedFrameProperties() const {
605 return fenced_frame_properties_.has_value();
606 }
607
Liam Brady6da2cc9e2023-01-30 17:09:43608 // Called from the currently active document via the
609 // `Fence.setReportEventDataForAutomaticBeacons` JS API.
610 void SetFencedFrameAutomaticBeaconReportEventData(
Liam Brady95434ea62023-11-02 19:18:32611 blink::mojom::AutomaticBeaconType event_type,
Liam Brady6da2cc9e2023-01-30 17:09:43612 const std::string& event_data,
Nan Lindbce6e32023-05-10 22:42:55613 const std::vector<blink::FencedFrame::ReportingDestination>& destinations,
Liam Brady86ca0482023-12-06 19:49:25614 bool once,
615 bool cross_origin_exposed) override;
Liam Bradybe6621d12023-07-20 19:43:40616
617 // Helper function to clear out automatic beacon data after one automatic
618 // beacon if `once` was set to true when calling
619 // `setReportEventDataForAutomaticBeacons()`.
Liam Brady95434ea62023-11-02 19:18:32620 void MaybeResetFencedFrameAutomaticBeaconReportEventData(
621 blink::mojom::AutomaticBeaconType event_type);
Liam Brady6da2cc9e2023-01-30 17:09:43622
Yao Xiaof9ae90a2023-03-01 20:52:44623 // Returns the number of fenced frame boundaries above this frame. The
Yao Xiaoa2337ad2022-10-12 20:59:29624 // outermost main frame's frame tree has fenced frame depth 0, a topmost
625 // fenced frame tree embedded in the outermost main frame has fenced frame
626 // depth 1, etc.
Yao Xiaof9ae90a2023-03-01 20:52:44627 //
628 // Also, sets `shared_storage_fenced_frame_root_count` to the
629 // number of fenced frame boundaries (roots) above this frame that originate
630 // from shared storage. This is used to check whether a fenced frame
631 // originates from shared storage only (i.e. not from FLEDGE).
632 // TODO(crbug.com/1347953): Remove this check once we put permissions inside
633 // FencedFrameConfig.
634 size_t GetFencedFrameDepth(size_t& shared_storage_fenced_frame_root_count);
Yao Xiaoa2337ad2022-10-12 20:59:29635
636 // Traverse up from this node. Return all valid
637 // `node->fenced_frame_properties_->shared_storage_budget_metadata` (i.e. this
638 // node is subjected to the shared storage budgeting associated with those
639 // metadata). Every node that originates from sharedStorage.selectURL() will
640 // have an associated metadata. This indicates that the metadata can only
641 // possibly be associated with a fenced frame root, unless when
642 // `kAllowURNsInIframes` is enabled in which case they could be be associated
643 // with any node.
Garrett Tanzer29de7112022-12-06 21:26:32644 std::vector<const SharedStorageBudgetMetadata*>
Yao Xiao1ac702d2022-06-08 17:20:49645 FindSharedStorageBudgetMetadata();
646
Camillia Smith Barnes7218518c2023-03-06 19:02:17647 // Returns any shared storage context string that was written to a
648 // `blink::FencedFrameConfig` before navigation via
649 // `setSharedStorageContext()`, as long as the request is for a same-origin
650 // frame within the config's fenced frame tree (or a same-origin descendant of
651 // a URN iframe).
Arthur Sonzognic686e8f2024-01-11 08:36:37652 std::optional<std::u16string> GetEmbedderSharedStorageContextIfAllowed();
Camillia Smith Barnes7218518c2023-03-06 19:02:17653
Harkiran Bolariaebbe7702022-02-22 19:19:03654 // Accessor to BrowsingContextState for subframes only. Only main frame
655 // navigations can change BrowsingInstances and BrowsingContextStates,
656 // therefore for subframes associated BrowsingContextState never changes. This
657 // helper method makes this more explicit and guards against calling this on
658 // main frames (there an appropriate BrowsingContextState should be obtained
659 // from RenderFrameHost or from RenderFrameProxyHost as e.g. during
660 // cross-BrowsingInstance navigations multiple BrowsingContextStates exist in
661 // the same frame).
662 const scoped_refptr<BrowsingContextState>&
663 GetBrowsingContextStateForSubframe() const;
664
Arthur Hemerye4659282022-03-28 08:36:15665 // Clears the opener property of popups referencing this FrameTreeNode as
666 // their opener.
667 void ClearOpenerReferences();
668
Liam Brady95d36d12023-03-13 21:13:06669 // Calculates whether one of the ancestor frames or this frame has a CSPEE in
670 // place. This is eventually sent over to LocalFrame in the renderer where it
671 // will be used by NavigatorAuction::canLoadAdAuctionFencedFrame for
672 // information it can't get on its own.
Liam Bradyd2a41e152022-07-19 13:58:48673 bool AncestorOrSelfHasCSPEE() const;
674
Arthur Sonzogni8e8eb1f2023-01-10 14:51:01675 // Reset every navigation in this frame, and its descendants. This is called
676 // after the <iframe> element has been removed, or after the document owning
677 // this frame has been navigated away.
678 //
679 // This takes into account:
680 // - Non-pending commit NavigationRequest owned by the FrameTreeNode
681 // - Pending commit NavigationRequest owned by the current RenderFrameHost
682 // - Speculative RenderFrameHost and its pending commit NavigationRequests.
683 void ResetAllNavigationsForFrameDetach();
684
Miyoung Shin7cf88b42022-11-07 13:22:30685 // RenderFrameHostOwner implementation:
Nate Chapin470dbc62023-04-25 16:34:38686 void DidStartLoading(LoadingState previous_frame_tree_loading_state) override;
Julie Jeongeun Kim07c077bd2022-12-05 08:40:31687 void DidStopLoading() override;
Miyoung Shin7cf88b42022-11-07 13:22:30688 void RestartNavigationAsCrossDocument(
689 std::unique_ptr<NavigationRequest> navigation_request) override;
Miyoung Shin1504eb712022-12-07 10:32:18690 bool Reload() override;
Julie Jeongeun Kimc1b07c32022-11-11 10:26:32691 Navigator& GetCurrentNavigator() override;
Miyoung Shine16cd2262022-11-30 05:52:16692 RenderFrameHostManager& GetRenderFrameHostManager() override;
Miyoung Shin64fd1bea2023-01-04 04:22:08693 FrameTreeNode* GetOpener() const override;
Julie Jeongeun Kim2132b37f82022-11-23 08:30:46694 void SetFocusedFrame(SiteInstanceGroup* source) override;
Julie Jeongeun Kim0e242242022-11-30 10:45:09695 void DidChangeReferrerPolicy(
696 network::mojom::ReferrerPolicy referrer_policy) override;
Miyoung Shin7cf88b42022-11-07 13:22:30697
Miyoung Shin8a66ec022022-11-28 23:50:09698 // Updates the user activation state in the browser frame tree and in the
699 // frame trees in all renderer processes except the renderer for this node
700 // (which initiated the update). Returns |false| if the update tries to
701 // consume an already consumed/expired transient state, |true| otherwise. See
702 // the comment on `user_activation_state_` in RenderFrameHostImpl.
703 //
704 // The |notification_type| parameter is used for histograms, only for the case
705 // |update_state == kNotifyActivation|.
706 bool UpdateUserActivationState(
707 blink::mojom::UserActivationUpdateType update_type,
708 blink::mojom::UserActivationNotificationType notification_type) override;
709
Nate Chapin47276a62023-02-16 16:53:44710 void DidConsumeHistoryUserActivation() override;
711
Miyoung Shinff13ed22022-11-30 09:21:47712 std::unique_ptr<NavigationRequest>
713 CreateNavigationRequestForSynchronousRendererCommit(
714 RenderFrameHostImpl* render_frame_host,
715 bool is_same_document,
716 const GURL& url,
717 const url::Origin& origin,
Arthur Sonzognic686e8f2024-01-11 08:36:37718 const std::optional<GURL>& initiator_base_url,
Miyoung Shinff13ed22022-11-30 09:21:47719 const net::IsolationInfo& isolation_info_for_subresources,
720 blink::mojom::ReferrerPtr referrer,
721 const ui::PageTransition& transition,
722 bool should_replace_current_entry,
723 const std::string& method,
724 bool has_transient_activation,
725 bool is_overriding_user_agent,
726 const std::vector<GURL>& redirects,
727 const GURL& original_url,
728 std::unique_ptr<CrossOriginEmbedderPolicyReporter> coep_reporter,
Miyoung Shinff13ed22022-11-30 09:21:47729 int http_response_code) override;
Miyoung Shinb5561802022-12-01 08:21:35730 void CancelNavigation() override;
Miyoung Shinc9ff4812023-01-05 08:58:05731 bool Credentialless() const override;
Miyoung Shinaf9a34362023-01-31 02:46:51732#if !BUILDFLAG(IS_ANDROID)
733 void GetVirtualAuthenticatorManager(
734 mojo::PendingReceiver<blink::test::mojom::VirtualAuthenticatorManager>
735 receiver) override;
736#endif
Miyoung Shinff13ed22022-11-30 09:21:47737
Mingyu Lei7956b8b2023-07-24 08:24:08738 // Restart the navigation restoring the page from the back-forward cache
739 // as a regular non-BFCached history navigation.
740 //
741 // The restart itself is asynchronous as it's dangerous to restart navigation
742 // with arbitrary state on the stack (another navigation might be starting),
743 // so this function only posts the actual task to do all the work (See
744 // `RestartBackForwardCachedNavigationImpl()`).
745 void RestartBackForwardCachedNavigationAsync(int nav_entry_id);
746
747 // Cancel the asynchronous task that would restart the BFCache navigation.
748 // This should be called whenever a FrameTreeNode's NavigationRequest would
749 // normally get cancelled, including when another NavigationRequest starts.
750 // This preserves the previous behavior where a restarting BFCache
751 // NavigationRequest is kept around until the task to create the new
752 // navigation is run, or until that NavigationRequest gets deleted (which
753 // cancels the task).
754 void CancelRestartingBackForwardCacheNavigation();
755
Christian Biesingere1865c57c2023-10-20 15:19:29756 base::SafeRef<FrameTreeNode> GetSafeRef() {
757 return weak_factory_.GetSafeRef();
758 }
759
danakjc492bf82020-09-09 20:02:44760 private:
Yuzu Saijo03dbf9b2022-07-22 04:29:45761 friend class CSPEmbeddedEnforcementUnitTest;
Charlie Hubb5943d2021-03-09 19:46:12762 FRIEND_TEST_ALL_PREFIXES(SitePerProcessPermissionsPolicyBrowserTest,
danakjc492bf82020-09-09 20:02:44763 ContainerPolicyDynamic);
Charlie Hubb5943d2021-03-09 19:46:12764 FRIEND_TEST_ALL_PREFIXES(SitePerProcessPermissionsPolicyBrowserTest,
danakjc492bf82020-09-09 20:02:44765 ContainerPolicySandboxDynamic);
Yuzu Saijo03dbf9b2022-07-22 04:29:45766 FRIEND_TEST_ALL_PREFIXES(NavigationRequestTest, StorageKeyToCommit);
Arthur Sonzogni64457592022-11-22 11:08:59767 FRIEND_TEST_ALL_PREFIXES(
768 NavigationRequestTest,
769 NavigationToCredentiallessDocumentNetworkIsolationInfo);
Yuzu Saijo03dbf9b2022-07-22 04:29:45770 FRIEND_TEST_ALL_PREFIXES(RenderFrameHostImplTest,
Arthur Sonzogni64457592022-11-22 11:08:59771 ChildOfCredentiallessIsCredentialless);
Yifan Luo86a79f42022-08-16 18:38:27772 FRIEND_TEST_ALL_PREFIXES(ContentPasswordManagerDriverTest,
Arthur Sonzogni64457592022-11-22 11:08:59773 PasswordAutofillDisabledOnCredentiallessIframe);
danakjc492bf82020-09-09 20:02:44774
Dominic Farolino8a2187b2021-12-24 20:44:21775 // Called by the destructor. When `this` is an outer dummy FrameTreeNode
776 // representing an inner FrameTree, this method destroys said inner FrameTree.
777 void DestroyInnerFrameTreeIfExists();
778
danakjc492bf82020-09-09 20:02:44779 class OpenerDestroyedObserver;
780
danakjc492bf82020-09-09 20:02:44781 // The |notification_type| parameter is used for histograms only.
782 bool NotifyUserActivation(
783 blink::mojom::UserActivationNotificationType notification_type);
784
785 bool ConsumeTransientUserActivation();
786
787 bool ClearUserActivation();
788
789 // Verify that the renderer process is allowed to set user activation on this
790 // frame by checking whether this frame's RenderWidgetHost had previously seen
791 // an input event that might lead to user activation. If user activation
792 // should be allowed, this returns true and also clears corresponding pending
793 // user activation state in the widget. Otherwise, this returns false.
794 bool VerifyUserActivation();
795
Mingyu Lei7956b8b2023-07-24 08:24:08796 // See `RestartBackForwardCachedNavigationAsync()`.
797 void RestartBackForwardCachedNavigationImpl(int nav_entry_id);
798
danakjc492bf82020-09-09 20:02:44799 // The next available browser-global FrameTreeNode ID.
800 static int next_frame_tree_node_id_;
801
Arthur Sonzognif6785ec2022-12-05 10:11:50802 // The FrameTree owning |this|. It can change with Prerender2 during
803 // activation.
804 raw_ref<FrameTree> frame_tree_;
danakjc492bf82020-09-09 20:02:44805
danakjc492bf82020-09-09 20:02:44806 // A browser-global identifier for the frame in the page, which stays stable
807 // even if the frame does a cross-process navigation.
808 const int frame_tree_node_id_;
809
810 // The RenderFrameHost owning this FrameTreeNode, which cannot change for the
811 // life of this FrameTreeNode. |nullptr| if this node is the root.
Keishi Hattori0e45c022021-11-27 09:25:52812 const raw_ptr<RenderFrameHostImpl> parent_;
danakjc492bf82020-09-09 20:02:44813
danakjc492bf82020-09-09 20:02:44814 // The frame that opened this frame, if any. Will be set to null if the
815 // opener is closed, or if this frame disowns its opener by setting its
816 // window.opener to null.
Keishi Hattori0e45c022021-11-27 09:25:52817 raw_ptr<FrameTreeNode> opener_ = nullptr;
danakjc492bf82020-09-09 20:02:44818
819 // An observer that clears this node's |opener_| if the opener is destroyed.
820 // This observer is added to the |opener_|'s observer list when the |opener_|
821 // is set to a non-null node, and it is removed from that list when |opener_|
822 // changes or when this node is destroyed. It is also cleared if |opener_|
823 // is disowned.
824 std::unique_ptr<OpenerDestroyedObserver> opener_observer_;
825
Rakina Zata Amni3a48ae42022-05-05 03:39:56826 // Unlike `opener_`, the "original opener chain" doesn't reflect
827 // window.opener, which can be suppressed or updated. The "original opener"
828 // is the main frame of the actual opener of this frame. This traces the all
829 // the way back, so if the original opener was closed (deleted or severed due
830 // to COOP), but _it_ had an original opener, this will return the original
831 // opener's original opener, etc. So this value will always be set as long as
832 // there is at least one live frame in the chain whose connection is not
833 // severed due to COOP.
834 raw_ptr<FrameTreeNode> first_live_main_frame_in_original_opener_chain_ =
835 nullptr;
danakjc492bf82020-09-09 20:02:44836
Wolfgang Beyerd8809db2020-09-30 15:29:39837 // The devtools frame token of the frame which opened this frame. This is
838 // not cleared even if the opener is destroyed or disowns the frame.
Arthur Sonzognic686e8f2024-01-11 08:36:37839 std::optional<base::UnguessableToken> opener_devtools_frame_token_;
Wolfgang Beyerd8809db2020-09-30 15:29:39840
Rakina Zata Amni3a48ae42022-05-05 03:39:56841 // An observer that updates this node's
842 // |first_live_main_frame_in_original_opener_chain_| to the next original
843 // opener in the chain if the original opener is destroyed.
danakjc492bf82020-09-09 20:02:44844 std::unique_ptr<OpenerDestroyedObserver> original_opener_observer_;
845
arthursonzogni034bb9c2020-10-01 08:29:56846 // When created by an opener, the URL specified in window.open(url)
847 // Please refer to {Get,Set}InitialPopupURL() documentation.
848 GURL initial_popup_url_;
849
850 // When created using window.open, the origin of the creator.
851 // Please refer to {Get,Set}PopupCreatorOrigin() documentation.
852 url::Origin popup_creator_origin_;
853
W. James MacLean81b8d01f2022-01-25 20:50:59854 // If the url from the the last BeginNavigation is about:srcdoc, this value
855 // stores the srcdoc_attribute's value for re-use in history navigations.
856 std::string srcdoc_value_;
857
danakjc492bf82020-09-09 20:02:44858 // Whether the frame's owner element in the parent document is collapsed.
arthursonzogni9816b9192021-03-29 16:09:19859 bool is_collapsed_ = false;
danakjc492bf82020-09-09 20:02:44860
Daniel Cheng6ac128172021-05-25 18:49:01861 // The type of frame owner for this frame. This is only relevant for non-main
862 // frames.
Kevin McNee43fe8292021-10-04 22:59:41863 const blink::FrameOwnerElementType frame_owner_element_type_ =
864 blink::FrameOwnerElementType::kNone;
Daniel Cheng9bd90f92021-04-23 20:49:45865
Daniel Cheng6ac128172021-05-25 18:49:01866 // The tree scope type of frame owner element, i.e. whether the element is in
867 // the document tree (https://dom.spec.whatwg.org/#document-trees) or the
868 // shadow tree (https://dom.spec.whatwg.org/#shadow-trees). This is only
869 // relevant for non-main frames.
870 const blink::mojom::TreeScopeType tree_scope_type_ =
871 blink::mojom::TreeScopeType::kDocument;
872
danakjc492bf82020-09-09 20:02:44873 // Track the pending sandbox flags and container policy for this frame. When a
874 // parent frame dynamically updates 'sandbox', 'allow', 'allowfullscreen',
875 // 'allowpaymentrequest' or 'src' attributes, the updated policy for the frame
Harkiran Bolaria4eacb3a2021-12-13 20:03:47876 // is stored here, and transferred into
877 // render_manager_.current_replication_state().frame_policy when they take
878 // effect on the next frame navigation.
danakjc492bf82020-09-09 20:02:44879 blink::FramePolicy pending_frame_policy_;
880
881 // Whether the frame was created by javascript. This is useful to prune
882 // history entries when the frame is removed (because frames created by
883 // scripts are never recreated with the same unique name - see
884 // https://crbug.com/500260).
arthursonzogni9816b9192021-03-29 16:09:19885 const bool is_created_by_script_;
danakjc492bf82020-09-09 20:02:44886
danakjc492bf82020-09-09 20:02:44887 // Tracks the scrolling and margin properties for this frame. These
888 // properties affect the child renderer but are stored on its parent's
889 // frame element. When this frame's parent dynamically updates these
890 // properties, we update them here too.
891 //
892 // Note that dynamic updates only take effect on the next frame navigation.
893 blink::mojom::FrameOwnerProperties frame_owner_properties_;
894
Yuzu Saijo03dbf9b2022-07-22 04:29:45895 // Contains the tracked HTML attributes of the corresponding iframe element,
896 // such as 'id' and 'src'.
897 blink::mojom::IframeAttributesPtr attributes_;
Antonio Sartori5abc8de2021-07-13 08:42:47898
danakjc492bf82020-09-09 20:02:44899 // Owns an ongoing NavigationRequest until it is ready to commit. It will then
900 // be reset and a RenderFrameHost will be responsible for the navigation.
901 std::unique_ptr<NavigationRequest> navigation_request_;
902
903 // List of objects observing this FrameTreeNode.
904 base::ObserverList<Observer>::Unchecked observers_;
905
906 base::TimeTicks last_focus_time_;
907
arthursonzogni9816b9192021-03-29 16:09:19908 bool was_discarded_ = false;
danakjc492bf82020-09-09 20:02:44909
Abhijeet Kandalkar3f29bc42022-09-23 12:39:58910 const FencedFrameStatus fenced_frame_status_ =
911 FencedFrameStatus::kNotNestedInFencedFrame;
Harkiran Bolaria16f2c48d2022-04-22 12:39:57912
Garrett Tanzerc69f4642022-08-15 22:15:14913 // If this is a fenced frame resulting from a urn:uuid navigation, this
914 // contains all the metadata specifying the resulting context.
Garrett Tanzer34cb92fe2022-09-28 17:50:54915 // TODO(crbug.com/1262022): Move this into the FrameTree once ShadowDOM
916 // and urn iframes are gone.
Arthur Sonzognic686e8f2024-01-11 08:36:37917 std::optional<FencedFrameProperties> fenced_frame_properties_;
Garrett Tanzerc69f4642022-08-15 22:15:14918
Mingyu Lei7956b8b2023-07-24 08:24:08919 // The tracker of the task that restarts the BFCache navigation. It might be
920 // used to cancel the task.
921 // See `CancelRestartingBackForwardCacheNavigation()`.
922 base::CancelableTaskTracker restart_back_forward_cached_navigation_tracker_;
923
Lukasz Anforowicz147141962020-12-16 18:03:24924 // Manages creation and swapping of RenderFrameHosts for this frame.
925 //
926 // This field needs to be declared last, because destruction of
927 // RenderFrameHostManager may call arbitrary callbacks (e.g. via
928 // WebContentsObserver::DidFinishNavigation fired after RenderFrameHostManager
929 // destructs a RenderFrameHostImpl and its NavigationRequest). Such callbacks
930 // may try to use FrameTreeNode's fields above - this would be an undefined
931 // behavior if the fields (even trivially-destructible ones) were destructed
932 // before the RenderFrameHostManager's destructor runs. See also
933 // https://crbug.com/1157988.
934 RenderFrameHostManager render_manager_;
Mingyu Lei7956b8b2023-07-24 08:24:08935
936 base::WeakPtrFactory<FrameTreeNode> weak_factory_{this};
danakjc492bf82020-09-09 20:02:44937};
938
939} // namespace content
940
941#endif // CONTENT_BROWSER_RENDERER_HOST_FRAME_TREE_NODE_H_