blob: ab1108d8cc8c1baddc32fabd5963ce914bc3d880 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2013 The Chromium Authors
danakjc492bf82020-09-09 20:02:442// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_BROWSER_RENDERER_HOST_FRAME_TREE_NODE_H_
6#define CONTENT_BROWSER_RENDERER_HOST_FRAME_TREE_NODE_H_
7
8#include <stddef.h>
9
10#include <memory>
11#include <string>
David Sanders2c1194d92022-04-19 23:32:3212#include <utility>
danakjc492bf82020-09-09 20:02:4413
14#include "base/gtest_prod_util.h"
Keishi Hattori0e45c022021-11-27 09:25:5215#include "base/memory/raw_ptr.h"
David Sanders2c1194d92022-04-19 23:32:3216#include "base/memory/scoped_refptr.h"
David Sandersd4bf5eb2022-03-17 07:12:0517#include "base/observer_list.h"
Mingyu Lei7956b8b2023-07-24 08:24:0818#include "base/task/cancelable_task_tracker.h"
Daniel Cheng390e2a72022-09-28 06:07:5319#include "content/browser/renderer_host/navigation_discard_reason.h"
danakjc492bf82020-09-09 20:02:4420#include "content/browser/renderer_host/navigator.h"
21#include "content/browser/renderer_host/render_frame_host_impl.h"
22#include "content/browser/renderer_host/render_frame_host_manager.h"
Miyoung Shin7cf88b42022-11-07 13:22:3023#include "content/browser/renderer_host/render_frame_host_owner.h"
danakjc492bf82020-09-09 20:02:4424#include "content/common/content_export.h"
Julie Jeongeun Kimf38c1eca2021-12-14 07:46:5525#include "content/public/browser/frame_type.h"
danakjc492bf82020-09-09 20:02:4426#include "services/network/public/mojom/content_security_policy.mojom-forward.h"
Julie Jeongeun Kim0e242242022-11-30 10:45:0927#include "services/network/public/mojom/referrer_policy.mojom-forward.h"
Lei Zhang698df03c2021-05-21 04:23:3428#include "third_party/abseil-cpp/absl/types/optional.h"
Kevin McNee43fe8292021-10-04 22:59:4129#include "third_party/blink/public/common/frame/frame_owner_element_type.h"
danakjc492bf82020-09-09 20:02:4430#include "third_party/blink/public/common/frame/frame_policy.h"
danakjc492bf82020-09-09 20:02:4431#include "third_party/blink/public/mojom/frame/frame_owner_properties.mojom.h"
Gyuyoung Kimc16e52e92021-03-19 02:45:3732#include "third_party/blink/public/mojom/frame/frame_replication_state.mojom-forward.h"
Daniel Cheng6ac128172021-05-25 18:49:0133#include "third_party/blink/public/mojom/frame/tree_scope_type.mojom.h"
David Sanders2c1194d92022-04-19 23:32:3234#include "third_party/blink/public/mojom/frame/user_activation_update_types.mojom-forward.h"
Miyoung Shinaf9a34362023-01-31 02:46:5135#include "third_party/blink/public/mojom/webauthn/virtual_authenticator.mojom-forward.h"
danakjc492bf82020-09-09 20:02:4436
Gabriel Charetted87f10f2022-03-31 00:44:2237#include "base/time/time.h"
danakjc492bf82020-09-09 20:02:4438#include "url/gurl.h"
39#include "url/origin.h"
40
Mingyu Lei4c13aad82023-08-27 07:55:1441namespace features {
42
43// Enable dumping when the a NavigationRequest with evicted RFH for BFCache
44// restore is moved to the FrameTreeNode.
45// This is a feature for debugging and should only be enabled on non-stable
46// channel.
47BASE_DECLARE_FEATURE(
48 kDumpWhenFrameTreeNodeTakesNavigationRequestWithEvictedBFCacheRFH);
49
50} // namespace features
51
danakjc492bf82020-09-09 20:02:4452namespace content {
53
54class NavigationRequest;
55class RenderFrameHostImpl;
56class NavigationEntryImpl;
Paul Semel3e241042022-10-11 12:57:3157class FrameTree;
danakjc492bf82020-09-09 20:02:4458
59// When a page contains iframes, its renderer process maintains a tree structure
60// of those frames. We are mirroring this tree in the browser process. This
61// class represents a node in this tree and is a wrapper for all objects that
62// are frame-specific (as opposed to page-specific).
63//
64// Each FrameTreeNode has a current RenderFrameHost, which can change over
65// time as the frame is navigated. Any immediate subframes of the current
66// document are tracked using FrameTreeNodes owned by the current
67// RenderFrameHost, rather than as children of FrameTreeNode itself. This
68// allows subframe FrameTreeNodes to stay alive while a RenderFrameHost is
69// still alive - for example while pending deletion, after a new current
70// RenderFrameHost has replaced it.
Miyoung Shin7cf88b42022-11-07 13:22:3071class CONTENT_EXPORT FrameTreeNode : public RenderFrameHostOwner {
danakjc492bf82020-09-09 20:02:4472 public:
73 class Observer {
74 public:
75 // Invoked when a FrameTreeNode is being destroyed.
76 virtual void OnFrameTreeNodeDestroyed(FrameTreeNode* node) {}
77
78 // Invoked when a FrameTreeNode becomes focused.
79 virtual void OnFrameTreeNodeFocused(FrameTreeNode* node) {}
80
Arthur Hemerye4659282022-03-28 08:36:1581 // Invoked when a FrameTreeNode moves to a different BrowsingInstance and
82 // the popups it opened should be disowned.
83 virtual void OnFrameTreeNodeDisownedOpenee(FrameTreeNode* node) {}
84
Fergal Dalya1d569972021-03-16 03:24:5385 virtual ~Observer() = default;
danakjc492bf82020-09-09 20:02:4486 };
87
88 static const int kFrameTreeNodeInvalidId;
89
90 // Returns the FrameTreeNode with the given global |frame_tree_node_id|,
91 // regardless of which FrameTree it is in.
92 static FrameTreeNode* GloballyFindByID(int frame_tree_node_id);
93
94 // Returns the FrameTreeNode for the given |rfh|. Same as
95 // rfh->frame_tree_node(), but also supports nullptrs.
96 static FrameTreeNode* From(RenderFrameHost* rfh);
97
98 // Callers are are expected to initialize sandbox flags separately after
99 // calling the constructor.
100 FrameTreeNode(
Arthur Sonzognif6785ec2022-12-05 10:11:50101 FrameTree& frame_tree,
danakjc492bf82020-09-09 20:02:44102 RenderFrameHostImpl* parent,
Daniel Cheng6ac128172021-05-25 18:49:01103 blink::mojom::TreeScopeType tree_scope_type,
danakjc492bf82020-09-09 20:02:44104 bool is_created_by_script,
danakjc492bf82020-09-09 20:02:44105 const blink::mojom::FrameOwnerProperties& frame_owner_properties,
Kevin McNee43fe8292021-10-04 22:59:41106 blink::FrameOwnerElementType owner_type,
Dominic Farolino08662c82021-06-11 07:36:34107 const blink::FramePolicy& frame_owner);
danakjc492bf82020-09-09 20:02:44108
Peter Boström828b9022021-09-21 02:28:43109 FrameTreeNode(const FrameTreeNode&) = delete;
110 FrameTreeNode& operator=(const FrameTreeNode&) = delete;
111
Miyoung Shin7cf88b42022-11-07 13:22:30112 ~FrameTreeNode() override;
danakjc492bf82020-09-09 20:02:44113
114 void AddObserver(Observer* observer);
115 void RemoveObserver(Observer* observer);
116
Ian Vollick25a9d032022-04-12 23:20:17117 // Frame trees may be nested so it can be the case that IsMainFrame() is true,
118 // but is not the outermost main frame. In particular, !IsMainFrame() cannot
119 // be used to check if the frame is an embedded frame -- use
120 // !IsOutermostMainFrame() instead. NB: this does not escape guest views;
121 // IsOutermostMainFrame will be true for the outermost main frame in an inner
122 // guest view.
danakjc492bf82020-09-09 20:02:44123 bool IsMainFrame() const;
Arthur Hemerya06697f2023-03-14 09:20:57124 bool IsOutermostMainFrame() const;
danakjc492bf82020-09-09 20:02:44125
arthursonzogni76098e52020-11-25 14:18:45126 // Clears any state in this node which was set by the document itself (CSP &
127 // UserActivationState) and notifies proxies as appropriate. Invoked after
128 // committing navigation to a new document (since the new document comes with
129 // a fresh set of CSP).
130 // TODO(arthursonzogni): Remove this function. The frame/document must not be
131 // left temporarily with lax state.
Hiroki Nakagawaab309622021-05-19 16:38:13132 void ResetForNavigation();
danakjc492bf82020-09-09 20:02:44133
Arthur Sonzognif6785ec2022-12-05 10:11:50134 FrameTree& frame_tree() const { return frame_tree_.get(); }
Paul Semel3e241042022-10-11 12:57:31135 Navigator& navigator();
danakjc492bf82020-09-09 20:02:44136
137 RenderFrameHostManager* render_manager() { return &render_manager_; }
Alexander Timin33e2e2c12022-03-03 04:21:33138 const RenderFrameHostManager* render_manager() const {
139 return &render_manager_;
140 }
danakjc492bf82020-09-09 20:02:44141 int frame_tree_node_id() const { return frame_tree_node_id_; }
Yuzu Saijo03dbf9b2022-07-22 04:29:45142 // This reflects window.name, which is initially set to the the "name"
143 // attribute. But this won't reflect changes of 'name' attribute and instead
144 // reflect changes to the Window object's name property.
145 // This is different from IframeAttributes' name in that this will not get
146 // updated when 'name' attribute gets updated.
Harkiran Bolaria4eacb3a2021-12-13 20:03:47147 const std::string& frame_name() const {
148 return render_manager_.current_replication_state().name;
149 }
danakjc492bf82020-09-09 20:02:44150
151 const std::string& unique_name() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47152 return render_manager_.current_replication_state().unique_name;
danakjc492bf82020-09-09 20:02:44153 }
154
danakjc492bf82020-09-09 20:02:44155 size_t child_count() const { return current_frame_host()->child_count(); }
156
danakjc492bf82020-09-09 20:02:44157 RenderFrameHostImpl* parent() const { return parent_; }
158
Dave Tapuskac8de3b02021-12-03 21:51:01159 // See `RenderFrameHost::GetParentOrOuterDocument()` for
160 // documentation.
Arthur Hemerya06697f2023-03-14 09:20:57161 RenderFrameHostImpl* GetParentOrOuterDocument() const;
Dave Tapuskac8de3b02021-12-03 21:51:01162
163 // See `RenderFrameHostImpl::GetParentOrOuterDocumentOrEmbedder()` for
164 // documentation.
165 RenderFrameHostImpl* GetParentOrOuterDocumentOrEmbedder();
166
danakjc492bf82020-09-09 20:02:44167 FrameTreeNode* opener() const { return opener_; }
168
Rakina Zata Amni3a48ae42022-05-05 03:39:56169 FrameTreeNode* first_live_main_frame_in_original_opener_chain() const {
170 return first_live_main_frame_in_original_opener_chain_;
171 }
danakjc492bf82020-09-09 20:02:44172
Anton Bikineevf62d1bf2021-05-15 17:56:07173 const absl::optional<base::UnguessableToken>& opener_devtools_frame_token() {
Wolfgang Beyerd8809db2020-09-30 15:29:39174 return opener_devtools_frame_token_;
175 }
176
Julie Jeongeun Kimf38c1eca2021-12-14 07:46:55177 // Returns the type of the frame. Refer to frame_type.h for the details.
178 FrameType GetFrameType() const;
179
danakjc492bf82020-09-09 20:02:44180 // Assigns a new opener for this node and, if |opener| is non-null, registers
181 // an observer that will clear this node's opener if |opener| is ever
182 // destroyed.
183 void SetOpener(FrameTreeNode* opener);
184
185 // Assigns the initial opener for this node, and if |opener| is non-null,
186 // registers an observer that will clear this node's opener if |opener| is
187 // ever destroyed. The value set here is the root of the tree.
188 //
189 // It is not possible to change the opener once it was set.
190 void SetOriginalOpener(FrameTreeNode* opener);
191
Wolfgang Beyerd8809db2020-09-30 15:29:39192 // Assigns an opener frame id for this node. This string id is only set once
193 // and cannot be changed. It persists, even if the |opener| is destroyed. It
194 // is used for attribution in the DevTools frontend.
195 void SetOpenerDevtoolsFrameToken(
196 base::UnguessableToken opener_devtools_frame_token);
197
danakjc492bf82020-09-09 20:02:44198 FrameTreeNode* child_at(size_t index) const {
199 return current_frame_host()->child_at(index);
200 }
201
202 // Returns the URL of the last committed page in the current frame.
203 const GURL& current_url() const {
204 return current_frame_host()->GetLastCommittedURL();
205 }
206
Abhijeet Kandalkarb86993b2022-11-22 05:17:40207 // Note that the current RenderFrameHost might not exist yet when calling this
208 // during FrameTreeNode initialization. In this case the FrameTreeNode must be
209 // on the initial empty document. Refer RFHI::is_initial_empty_document for a
210 // more details.
Rakina Zata Amni86c88fa2021-11-01 01:27:30211 bool is_on_initial_empty_document() const {
Abhijeet Kandalkarb86993b2022-11-22 05:17:40212 return current_frame_host()
213 ? current_frame_host()->is_initial_empty_document()
214 : true;
Rakina Zata Amnifc4cc3d42021-06-10 09:03:56215 }
216
danakjc492bf82020-09-09 20:02:44217 // Returns whether the frame's owner element in the parent document is
218 // collapsed, that is, removed from the layout as if it did not exist, as per
219 // request by the embedder (of the content/ layer).
220 bool is_collapsed() const { return is_collapsed_; }
221
222 // Sets whether to collapse the frame's owner element in the parent document,
223 // that is, to remove it from the layout as if it did not exist, as per
224 // request by the embedder (of the content/ layer). Cannot be called for main
225 // frames.
226 //
227 // This only has an effect for <iframe> owner elements, and is a no-op when
228 // called on sub-frames hosted in <frame>, <object>, and <embed> elements.
229 void SetCollapsed(bool collapsed);
230
231 // Returns the origin of the last committed page in this frame.
232 // WARNING: To get the last committed origin for a particular
233 // RenderFrameHost, use RenderFrameHost::GetLastCommittedOrigin() instead,
234 // which will behave correctly even when the RenderFrameHost is not the
235 // current one for this frame (such as when it's pending deletion).
236 const url::Origin& current_origin() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47237 return render_manager_.current_replication_state().origin;
danakjc492bf82020-09-09 20:02:44238 }
239
danakjc492bf82020-09-09 20:02:44240 // Returns the latest frame policy (sandbox flags and container policy) for
241 // this frame. This includes flags inherited from parent frames and the latest
242 // flags from the <iframe> element hosting this frame. The returned policies
243 // may not yet have taken effect, since "sandbox" and "allow" attribute
Liam Brady25a14162022-12-02 15:25:57244 // updates in an <iframe> element take effect on next navigation. For
245 // <fencedframe> elements, not everything in the frame policy might actually
246 // take effect after the navigation. To retrieve the currently active policy
247 // for this frame, use effective_frame_policy().
danakjc492bf82020-09-09 20:02:44248 const blink::FramePolicy& pending_frame_policy() const {
249 return pending_frame_policy_;
250 }
251
252 // Update this frame's sandbox flags and container policy. This is called
253 // when a parent frame updates the "sandbox" attribute in the <iframe> element
254 // for this frame, or any of the attributes which affect the container policy
255 // ("allowfullscreen", "allowpaymentrequest", "allow", and "src".)
256 // These policies won't take effect until next navigation. If this frame's
257 // parent is itself sandboxed, the parent's sandbox flags are combined with
258 // those in |frame_policy|.
259 // Attempting to change the container policy on the main frame will have no
260 // effect.
261 void SetPendingFramePolicy(blink::FramePolicy frame_policy);
262
263 // Returns the currently active frame policy for this frame, including the
264 // sandbox flags which were present at the time the document was loaded, and
Charlie Hu5130d25e2021-03-05 21:53:39265 // the permissions policy container policy, which is set by the iframe's
danakjc492bf82020-09-09 20:02:44266 // allowfullscreen, allowpaymentrequest, and allow attributes, along with the
267 // origin of the iframe's src attribute (which may be different from the URL
268 // of the document currently loaded into the frame). This does not include
269 // policy changes that have been made by updating the containing iframe
270 // element attributes since the frame was last navigated; use
271 // pending_frame_policy() for those.
272 const blink::FramePolicy& effective_frame_policy() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47273 return render_manager_.current_replication_state().frame_policy;
danakjc492bf82020-09-09 20:02:44274 }
275
danakjc492bf82020-09-09 20:02:44276 const blink::mojom::FrameOwnerProperties& frame_owner_properties() {
277 return frame_owner_properties_;
278 }
279
280 void set_frame_owner_properties(
281 const blink::mojom::FrameOwnerProperties& frame_owner_properties) {
282 frame_owner_properties_ = frame_owner_properties;
283 }
284
Yuzu Saijo03dbf9b2022-07-22 04:29:45285 // Reflects the attributes of the corresponding iframe html element, such
Arthur Sonzogni64457592022-11-22 11:08:59286 // as 'credentialless', 'id', 'name' and 'src'. These values should not be
Yuzu Saijo03dbf9b2022-07-22 04:29:45287 // exposed to cross-origin renderers.
288 const network::mojom::ContentSecurityPolicy* csp_attribute() const {
289 return attributes_->parsed_csp_attribute.get();
danakjc492bf82020-09-09 20:02:44290 }
Yao Xiao9c54b3e2023-03-14 04:25:04291 // Tracks iframe's 'browsingtopics' attribute, indicating whether the
292 // navigation requests on this frame should calculate and send the
293 // `Sec-Browsing-Topics` header.
294 bool browsing_topics() const { return attributes_->browsing_topics; }
Camillia Smith Barnes6d2966c82023-08-23 21:16:18295
296 // Tracks iframe's 'sharedstoragewritable' attribute, indicating what value
297 // the the corresponding `network::ResourceRequest::shared_storage_writable`
298 // should take for the navigation(s) on this frame. If true, the network
299 // service will send the `Shared-Storage-Write` request header.
300 bool shared_storage_writable() const {
301 return attributes_->shared_storage_writable;
302 }
Yuzu Saijodc870f92023-01-20 03:39:11303 const absl::optional<std::string> html_id() const { return attributes_->id; }
Yuzu Saijo03dbf9b2022-07-22 04:29:45304 // This tracks iframe's 'name' attribute instead of window.name, which is
305 // tracked in FrameReplicationState. See the comment for frame_name() for
306 // more details.
Yuzu Saijodc870f92023-01-20 03:39:11307 const absl::optional<std::string> html_name() const {
308 return attributes_->name;
309 }
310 const absl::optional<std::string> html_src() const {
311 return attributes_->src;
312 }
danakjc492bf82020-09-09 20:02:44313
Yuzu Saijo03dbf9b2022-07-22 04:29:45314 void SetAttributes(blink::mojom::IframeAttributesPtr attributes);
Antonio Sartori5abc8de2021-07-13 08:42:47315
danakjc492bf82020-09-09 20:02:44316 bool HasSameOrigin(const FrameTreeNode& node) const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47317 return render_manager_.current_replication_state().origin.IsSameOriginWith(
318 node.current_replication_state().origin);
danakjc492bf82020-09-09 20:02:44319 }
320
Gyuyoung Kimc16e52e92021-03-19 02:45:37321 const blink::mojom::FrameReplicationState& current_replication_state() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47322 return render_manager_.current_replication_state();
danakjc492bf82020-09-09 20:02:44323 }
324
325 RenderFrameHostImpl* current_frame_host() const {
326 return render_manager_.current_frame_host();
327 }
328
danakjc492bf82020-09-09 20:02:44329 // Returns true if this node is in a loading state.
330 bool IsLoading() const;
Nate Chapin470dbc62023-04-25 16:34:38331 LoadingState GetLoadingState() const;
danakjc492bf82020-09-09 20:02:44332
Alex Moshchuk9b0fd822020-10-26 23:08:15333 // Returns true if this node has a cross-document navigation in progress.
334 bool HasPendingCrossDocumentNavigation() const;
335
danakjc492bf82020-09-09 20:02:44336 NavigationRequest* navigation_request() { return navigation_request_.get(); }
337
338 // Transfers the ownership of the NavigationRequest to |render_frame_host|.
339 // From ReadyToCommit to DidCommit, the NavigationRequest is owned by the
340 // RenderFrameHost that is committing the navigation.
341 void TransferNavigationRequestOwnership(
342 RenderFrameHostImpl* render_frame_host);
343
344 // Takes ownership of |navigation_request| and makes it the current
345 // NavigationRequest of this frame. This corresponds to the start of a new
346 // navigation. If there was an ongoing navigation request before calling this
347 // function, it is canceled. |navigation_request| should not be null.
Charlie Reis09952ee2022-12-08 16:35:07348 void TakeNavigationRequest(
danakjc492bf82020-09-09 20:02:44349 std::unique_ptr<NavigationRequest> navigation_request);
350
Rakina Zata Amnif8f2bb62022-11-23 05:54:32351 // Resets the navigation request owned by `this` (which shouldn't have reached
352 // the "pending commit" stage yet) and any state created by it, including the
Rakina Zata Amni33175cb92022-11-24 02:46:03353 // speculative RenderFrameHost (if there are no other navigations associated
354 // with it). Note that this does not affect navigations that have reached the
355 // "pending commit" stage, which are owned by their corresponding
356 // RenderFrameHosts instead.
Daniel Cheng390e2a72022-09-28 06:07:53357 void ResetNavigationRequest(NavigationDiscardReason reason);
358
Rakina Zata Amnif8f2bb62022-11-23 05:54:32359 // Similar to `ResetNavigationRequest()`, but keeps the state created by the
Daniel Cheng390e2a72022-09-28 06:07:53360 // NavigationRequest (e.g. speculative RenderFrameHost, loading state).
361 void ResetNavigationRequestButKeepState();
danakjc492bf82020-09-09 20:02:44362
danakjc492bf82020-09-09 20:02:44363 // The load progress for a RenderFrameHost in this node was updated to
364 // |load_progress|. This will notify the FrameTree which will in turn notify
365 // the WebContents.
366 void DidChangeLoadProgress(double load_progress);
367
368 // Called when the user directed the page to stop loading. Stops all loads
369 // happening in the FrameTreeNode. This method should be used with
370 // FrameTree::ForEach to stop all loads in the entire FrameTree.
371 bool StopLoading();
372
373 // Returns the time this frame was last focused.
374 base::TimeTicks last_focus_time() const { return last_focus_time_; }
375
376 // Called when this node becomes focused. Updates the node's last focused
377 // time and notifies observers.
378 void DidFocus();
379
380 // Called when the user closed the modal dialogue for BeforeUnload and
381 // cancelled the navigation. This should stop any load happening in the
382 // FrameTreeNode.
383 void BeforeUnloadCanceled();
384
danakjc492bf82020-09-09 20:02:44385 // Returns the sandbox flags currently in effect for this frame. This includes
386 // flags inherited from parent frames, the currently active flags from the
387 // <iframe> element hosting this frame, as well as any flags set from a
388 // Content-Security-Policy HTTP header. This does not include flags that have
389 // have been updated in an <iframe> element but have not taken effect yet; use
390 // pending_frame_policy() for those. To see the flags which will take effect
391 // on navigation (which does not include the CSP-set flags), use
392 // effective_frame_policy().
393 network::mojom::WebSandboxFlags active_sandbox_flags() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47394 return render_manager_.current_replication_state().active_sandbox_flags;
danakjc492bf82020-09-09 20:02:44395 }
396
danakjc492bf82020-09-09 20:02:44397 // Returns whether the frame received a user gesture on a previous navigation
398 // on the same eTLD+1.
399 bool has_received_user_gesture_before_nav() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47400 return render_manager_.current_replication_state()
401 .has_received_user_gesture_before_nav;
danakjc492bf82020-09-09 20:02:44402 }
403
404 // When a tab is discarded, WebContents sets was_discarded on its
405 // root FrameTreeNode.
406 // In addition, when a child frame is created, this bit is passed on from
407 // parent to child.
408 // When a navigation request is created, was_discarded is passed on to the
409 // request and reset to false in FrameTreeNode.
410 void set_was_discarded() { was_discarded_ = true; }
411 bool was_discarded() const { return was_discarded_; }
412
Miyoung Shin8a66ec022022-11-28 23:50:09413 // Deprecated. Use directly HasStickyUserActivation in RFHI.
danakjc492bf82020-09-09 20:02:44414 // Returns the sticky bit of the User Activation v2 state of the
415 // |FrameTreeNode|.
416 bool HasStickyUserActivation() const {
Miyoung Shin8a66ec022022-11-28 23:50:09417 return current_frame_host()->HasStickyUserActivation();
danakjc492bf82020-09-09 20:02:44418 }
419
Miyoung Shin8a66ec022022-11-28 23:50:09420 // Deprecated. Use directly HasStickyUserActivation in RFHI.
danakjc492bf82020-09-09 20:02:44421 // Returns the transient bit of the User Activation v2 state of the
422 // |FrameTreeNode|.
423 bool HasTransientUserActivation() {
Miyoung Shin8a66ec022022-11-28 23:50:09424 return current_frame_host()->HasTransientUserActivation();
danakjc492bf82020-09-09 20:02:44425 }
426
427 // Remove history entries for all frames created by script in this frame's
428 // subtree. If a frame created by a script is removed, then its history entry
429 // will never be reused - this saves memory.
430 void PruneChildFrameNavigationEntries(NavigationEntryImpl* entry);
431
Abhijeet Kandalkarb43affa72022-09-27 16:48:01432 using FencedFrameStatus = RenderFrameHostImpl::FencedFrameStatus;
Abhijeet Kandalkar3f29bc42022-09-23 12:39:58433 FencedFrameStatus fenced_frame_status() const { return fenced_frame_status_; }
434
Kevin McNee43fe8292021-10-04 22:59:41435 blink::FrameOwnerElementType frame_owner_element_type() const {
Daniel Cheng9bd90f92021-04-23 20:49:45436 return frame_owner_element_type_;
danakjc492bf82020-09-09 20:02:44437 }
danakjc492bf82020-09-09 20:02:44438
Daniel Cheng6ac128172021-05-25 18:49:01439 blink::mojom::TreeScopeType tree_scope_type() const {
440 return tree_scope_type_;
441 }
442
arthursonzogni034bb9c2020-10-01 08:29:56443 // The initial popup URL for new window opened using:
444 // `window.open(initial_popup_url)`.
445 // An empty GURL otherwise.
446 //
447 // [WARNING] There is no guarantee the FrameTreeNode will ever host a
448 // document served from this URL. The FrameTreeNode always starts hosting the
449 // initial empty document and attempts a navigation toward this URL. However
450 // the navigation might be delayed, redirected and even cancelled.
451 void SetInitialPopupURL(const GURL& initial_popup_url);
452 const GURL& initial_popup_url() const { return initial_popup_url_; }
453
454 // The origin of the document that used window.open() to create this frame.
455 // Otherwise, an opaque Origin with a nonce different from all previously
456 // existing Origins.
457 void SetPopupCreatorOrigin(const url::Origin& popup_creator_origin);
458 const url::Origin& popup_creator_origin() const {
459 return popup_creator_origin_;
460 }
461
Harkiran Bolaria59290d62021-03-17 01:53:01462 // Sets the associated FrameTree for this node. The node can change FrameTrees
Domenic Denicola7767a9c2023-07-13 15:36:39463 // as part of prerendering, which allows a page loaded in the prerendered
464 // FrameTree to be used for a navigation in the primary frame tree.
Harkiran Bolaria59290d62021-03-17 01:53:01465 void SetFrameTree(FrameTree& frame_tree);
466
Alexander Timin074cd182022-03-23 18:11:22467 using TraceProto = perfetto::protos::pbzero::FrameTreeNodeInfo;
Alexander Timinf785f342021-03-18 00:00:56468 // Write a representation of this object into a trace.
Alexander Timin074cd182022-03-23 18:11:22469 void WriteIntoTrace(perfetto::TracedProto<TraceProto> proto) const;
Alexander Timinf785f342021-03-18 00:00:56470
Carlos Caballero76711352021-03-24 17:38:21471 // Returns true the node is navigating, i.e. it has an associated
472 // NavigationRequest.
473 bool HasNavigation();
474
shivanigithubf3ddff52021-07-03 22:06:30475 // Fenced frames (meta-bug crbug.com/1111084):
shivanigithub4cd016a2021-09-20 21:10:30476 // Note that these two functions cannot be invoked from a FrameTree's or
477 // its root node's constructor since they require the frame tree and the
478 // root node to be completely constructed.
479 //
shivanigithubf3ddff52021-07-03 22:06:30480 // Returns false if fenced frames are disabled. Returns true if the feature is
481 // enabled and if |this| is a fenced frame. Returns false for
482 // iframes embedded in a fenced frame. To clarify: for the MPArch
483 // implementation this only returns true if |this| is the actual
484 // root node of the inner FrameTree and not the proxy FrameTreeNode in the
485 // outer FrameTree.
Dominic Farolino4bc10ee2021-08-31 00:37:36486 bool IsFencedFrameRoot() const;
shivanigithubf3ddff52021-07-03 22:06:30487
488 // Returns false if fenced frames are disabled. Returns true if the
489 // feature is enabled and if |this| or any of its ancestor nodes is a
490 // fenced frame.
491 bool IsInFencedFrameTree() const;
492
shivanigithub4cd016a2021-09-20 21:10:30493 // Returns a valid nonce if `IsInFencedFrameTree()` returns true for `this`.
Garrett Tanzer34cb92fe2022-09-28 17:50:54494 // Returns nullopt otherwise.
495 //
496 // Nonce used in the net::IsolationInfo and blink::StorageKey for a fenced
497 // frame and any iframes nested within it. Not set if this frame is not in a
498 // fenced frame's FrameTree. Note that this could be a field in FrameTree for
499 // the MPArch version but for the shadow DOM version we need to keep it here
500 // since the fenced frame root is not a main frame for the latter. The value
501 // of the nonce will be the same for all of the the iframes inside a fenced
502 // frame tree. If there is a nested fenced frame it will have a different
503 // nonce than its parent fenced frame. The nonce will stay the same across
504 // navigations initiated from the fenced frame tree because it is always used
505 // in conjunction with other fields of the keys and would be good to access
506 // the same storage across same-origin navigations. If the navigation is
507 // same-origin/site then the same network stack partition/storage will be
508 // reused and if it's cross-origin/site then other parts of the key will
509 // change and so, even with the same nonce, another partition will be used.
510 // But if the navigation is initiated from the embedder, the nonce will be
511 // reinitialized irrespective of same or cross origin such that there is no
512 // privacy leak via storage shared between two embedder initiated navigations.
513 // Note that this reinitialization is implemented for all embedder-initiated
514 // navigations in MPArch, but only urn:uuid navigations in ShadowDOM.
515 absl::optional<base::UnguessableToken> GetFencedFrameNonce();
shivanigithub4cd016a2021-09-20 21:10:30516
Garrett Tanzer34cb92fe2022-09-28 17:50:54517 // If applicable, initialize the default fenced frame properties. Right now,
518 // this means setting a new fenced frame nonce. See comment on
shivanigithub4cd016a2021-09-20 21:10:30519 // fenced_frame_nonce() for when it is set to a non-null value. Invoked
520 // by FrameTree::Init() or FrameTree::AddFrame().
Garrett Tanzer34cb92fe2022-09-28 17:50:54521 void SetFencedFramePropertiesIfNeeded();
shivanigithub4cd016a2021-09-20 21:10:30522
Garrett Tanzer291a2d52023-03-20 22:41:57523 // Set the current FencedFrameProperties to have "opaque ads mode".
524 // This should only be used during tests, when the proper embedder-initiated
525 // fenced frame root urn/config navigation flow isn't available.
526 // TODO(crbug.com/1347953): Refactor and expand use of test utils so there is
527 // a consistent way to do this properly everywhere. Consider removing
528 // arbitrary restrictions in "default mode" so that using opaque ads mode is
529 // less necessary.
530 void SetFencedFramePropertiesOpaqueAdsModeForTesting() {
531 if (fenced_frame_properties_.has_value()) {
532 fenced_frame_properties_->mode_ =
533 blink::FencedFrame::DeprecatedFencedFrameMode::kOpaqueAds;
534 }
535 }
536
537 // Returns the mode attribute from the `FencedFrameProperties` if this frame
538 // is in a fenced frame tree, otherwise returns `kDefault`.
539 blink::FencedFrame::DeprecatedFencedFrameMode GetDeprecatedFencedFrameMode();
Nan Lin171fe9a2022-02-17 16:42:16540
Dave Tapuskac8de3b02021-12-03 21:51:01541 // Helper for GetParentOrOuterDocument/GetParentOrOuterDocumentOrEmbedder.
542 // Do not use directly.
Kevin McNee86e64ee2023-02-17 16:35:50543 // `escape_guest_view` determines whether to iterate out of guest views and is
544 // the behaviour distinction between GetParentOrOuterDocument and
545 // GetParentOrOuterDocumentOrEmbedder. See the comment on
546 // GetParentOrOuterDocumentOrEmbedder for details.
547 // `include_prospective` includes embedders which own our frame tree, but have
548 // not yet attached it to the outer frame tree.
Arthur Hemerya06697f2023-03-14 09:20:57549 RenderFrameHostImpl* GetParentOrOuterDocumentHelper(
550 bool escape_guest_view,
551 bool include_prospective) const;
Dave Tapuskac8de3b02021-12-03 21:51:01552
Harkiran Bolariab4437fd2021-08-11 17:51:22553 // Sets the unique_name and name fields on replication_state_. To be used in
554 // prerender activation to make sure the FrameTreeNode replication state is
555 // correct after the RenderFrameHost is moved between FrameTreeNodes. The
556 // renderers should already have the correct value, so unlike
557 // FrameTreeNode::SetFrameName, we do not notify them here.
Harkiran Bolaria4eacb3a2021-12-13 20:03:47558 // TODO(https://crbug.com/1237091): Remove this once the BrowsingContextState
559 // is implemented to utilize the new path.
Harkiran Bolariab4437fd2021-08-11 17:51:22560 void set_frame_name_for_activation(const std::string& unique_name,
561 const std::string& name) {
Harkiran Bolaria0b3bdef02022-03-10 13:04:40562 current_frame_host()->browsing_context_state()->set_frame_name(unique_name,
563 name);
Harkiran Bolariab4437fd2021-08-11 17:51:22564 }
565
Nan Linaaf84f72021-12-02 22:31:56566 // Returns true if error page isolation is enabled.
567 bool IsErrorPageIsolationEnabled() const;
568
W. James MacLean81b8d01f2022-01-25 20:50:59569 // Functions to store and retrieve a frame's srcdoc value on this
570 // FrameTreeNode.
571 void SetSrcdocValue(const std::string& srcdoc_value);
572 const std::string& srcdoc_value() const { return srcdoc_value_; }
573
Garrett Tanzerc69f4642022-08-15 22:15:14574 void set_fenced_frame_properties(
Garrett Tanzer29de7112022-12-06 21:26:32575 const absl::optional<FencedFrameProperties>& fenced_frame_properties) {
Garrett Tanzer2975eeac2022-08-22 16:34:01576 // TODO(crbug.com/1262022): Reenable this DCHECK once ShadowDOM and
577 // loading urns in iframes (for FLEDGE OT) are gone.
578 // DCHECK_EQ(fenced_frame_status_,
579 // RenderFrameHostImpl::FencedFrameStatus::kFencedFrameRoot);
Garrett Tanzerc69f4642022-08-15 22:15:14580 fenced_frame_properties_ = fenced_frame_properties;
581 }
582
Xiaochen Zhou90858e82023-05-31 15:47:37583 // By default, this function checks the fenced frame root's properties if one
584 // exists, and then otherwise traverses the frame tree to find urn iframe
585 // roots. This doesn't work correctly for urn iframes nested inside of fenced
586 // frames. Enable `force_tree_traversal` to skip the fenced frame root short
587 // circuit and always traverse the tree.
588 // TODO(crbug.com/1355857): This function has the correct semantics when
589 // `force_tree_traversal` is set to true. It is set to false for urn iframes
590 // nested in fenced frames to work correctly in some cases. For example,
591 // storage partitioning. Once those issues are resolved, remove this parameter
592 // entirely.
593 const absl::optional<FencedFrameProperties>& GetFencedFrameProperties(
594 bool force_tree_traversal = false);
Garrett Tanzerc69f4642022-08-15 22:15:14595
Liam Brady6da2cc9e2023-01-30 17:09:43596 // Called from the currently active document via the
597 // `Fence.setReportEventDataForAutomaticBeacons` JS API.
598 void SetFencedFrameAutomaticBeaconReportEventData(
599 const std::string& event_data,
Nan Lindbce6e32023-05-10 22:42:55600 const std::vector<blink::FencedFrame::ReportingDestination>& destinations,
601 network::AttributionReportingRuntimeFeatures
Liam Bradybe6621d12023-07-20 19:43:40602 attribution_reporting_runtime_features,
603 bool once) override;
604
605 // Helper function to clear out automatic beacon data after one automatic
606 // beacon if `once` was set to true when calling
607 // `setReportEventDataForAutomaticBeacons()`.
608 void MaybeResetFencedFrameAutomaticBeaconReportEventData();
Liam Brady6da2cc9e2023-01-30 17:09:43609
Yao Xiaof9ae90a2023-03-01 20:52:44610 // Returns the number of fenced frame boundaries above this frame. The
Yao Xiaoa2337ad2022-10-12 20:59:29611 // outermost main frame's frame tree has fenced frame depth 0, a topmost
612 // fenced frame tree embedded in the outermost main frame has fenced frame
613 // depth 1, etc.
Yao Xiaof9ae90a2023-03-01 20:52:44614 //
615 // Also, sets `shared_storage_fenced_frame_root_count` to the
616 // number of fenced frame boundaries (roots) above this frame that originate
617 // from shared storage. This is used to check whether a fenced frame
618 // originates from shared storage only (i.e. not from FLEDGE).
619 // TODO(crbug.com/1347953): Remove this check once we put permissions inside
620 // FencedFrameConfig.
621 size_t GetFencedFrameDepth(size_t& shared_storage_fenced_frame_root_count);
Yao Xiaoa2337ad2022-10-12 20:59:29622
623 // Traverse up from this node. Return all valid
624 // `node->fenced_frame_properties_->shared_storage_budget_metadata` (i.e. this
625 // node is subjected to the shared storage budgeting associated with those
626 // metadata). Every node that originates from sharedStorage.selectURL() will
627 // have an associated metadata. This indicates that the metadata can only
628 // possibly be associated with a fenced frame root, unless when
629 // `kAllowURNsInIframes` is enabled in which case they could be be associated
630 // with any node.
Garrett Tanzer29de7112022-12-06 21:26:32631 std::vector<const SharedStorageBudgetMetadata*>
Yao Xiao1ac702d2022-06-08 17:20:49632 FindSharedStorageBudgetMetadata();
633
Camillia Smith Barnes7218518c2023-03-06 19:02:17634 // Returns any shared storage context string that was written to a
635 // `blink::FencedFrameConfig` before navigation via
636 // `setSharedStorageContext()`, as long as the request is for a same-origin
637 // frame within the config's fenced frame tree (or a same-origin descendant of
638 // a URN iframe).
639 absl::optional<std::u16string> GetEmbedderSharedStorageContextIfAllowed();
640
Harkiran Bolariaebbe7702022-02-22 19:19:03641 // Accessor to BrowsingContextState for subframes only. Only main frame
642 // navigations can change BrowsingInstances and BrowsingContextStates,
643 // therefore for subframes associated BrowsingContextState never changes. This
644 // helper method makes this more explicit and guards against calling this on
645 // main frames (there an appropriate BrowsingContextState should be obtained
646 // from RenderFrameHost or from RenderFrameProxyHost as e.g. during
647 // cross-BrowsingInstance navigations multiple BrowsingContextStates exist in
648 // the same frame).
649 const scoped_refptr<BrowsingContextState>&
650 GetBrowsingContextStateForSubframe() const;
651
Arthur Hemerye4659282022-03-28 08:36:15652 // Clears the opener property of popups referencing this FrameTreeNode as
653 // their opener.
654 void ClearOpenerReferences();
655
Liam Brady95d36d12023-03-13 21:13:06656 // Calculates whether one of the ancestor frames or this frame has a CSPEE in
657 // place. This is eventually sent over to LocalFrame in the renderer where it
658 // will be used by NavigatorAuction::canLoadAdAuctionFencedFrame for
659 // information it can't get on its own.
Liam Bradyd2a41e152022-07-19 13:58:48660 bool AncestorOrSelfHasCSPEE() const;
661
Arthur Sonzogni8e8eb1f2023-01-10 14:51:01662 // Reset every navigation in this frame, and its descendants. This is called
663 // after the <iframe> element has been removed, or after the document owning
664 // this frame has been navigated away.
665 //
666 // This takes into account:
667 // - Non-pending commit NavigationRequest owned by the FrameTreeNode
668 // - Pending commit NavigationRequest owned by the current RenderFrameHost
669 // - Speculative RenderFrameHost and its pending commit NavigationRequests.
670 void ResetAllNavigationsForFrameDetach();
671
Miyoung Shin7cf88b42022-11-07 13:22:30672 // RenderFrameHostOwner implementation:
Nate Chapin470dbc62023-04-25 16:34:38673 void DidStartLoading(LoadingState previous_frame_tree_loading_state) override;
Julie Jeongeun Kim07c077bd2022-12-05 08:40:31674 void DidStopLoading() override;
Miyoung Shin7cf88b42022-11-07 13:22:30675 void RestartNavigationAsCrossDocument(
676 std::unique_ptr<NavigationRequest> navigation_request) override;
Miyoung Shin1504eb712022-12-07 10:32:18677 bool Reload() override;
Julie Jeongeun Kimc1b07c32022-11-11 10:26:32678 Navigator& GetCurrentNavigator() override;
Miyoung Shine16cd2262022-11-30 05:52:16679 RenderFrameHostManager& GetRenderFrameHostManager() override;
Miyoung Shin64fd1bea2023-01-04 04:22:08680 FrameTreeNode* GetOpener() const override;
Julie Jeongeun Kim2132b37f82022-11-23 08:30:46681 void SetFocusedFrame(SiteInstanceGroup* source) override;
Julie Jeongeun Kim0e242242022-11-30 10:45:09682 void DidChangeReferrerPolicy(
683 network::mojom::ReferrerPolicy referrer_policy) override;
Miyoung Shin7cf88b42022-11-07 13:22:30684
Miyoung Shin8a66ec022022-11-28 23:50:09685 // Updates the user activation state in the browser frame tree and in the
686 // frame trees in all renderer processes except the renderer for this node
687 // (which initiated the update). Returns |false| if the update tries to
688 // consume an already consumed/expired transient state, |true| otherwise. See
689 // the comment on `user_activation_state_` in RenderFrameHostImpl.
690 //
691 // The |notification_type| parameter is used for histograms, only for the case
692 // |update_state == kNotifyActivation|.
693 bool UpdateUserActivationState(
694 blink::mojom::UserActivationUpdateType update_type,
695 blink::mojom::UserActivationNotificationType notification_type) override;
696
Nate Chapin47276a62023-02-16 16:53:44697 void DidConsumeHistoryUserActivation() override;
698
Miyoung Shinff13ed22022-11-30 09:21:47699 std::unique_ptr<NavigationRequest>
700 CreateNavigationRequestForSynchronousRendererCommit(
701 RenderFrameHostImpl* render_frame_host,
702 bool is_same_document,
703 const GURL& url,
704 const url::Origin& origin,
W. James MacLean23e90a12022-12-21 04:38:21705 const absl::optional<GURL>& initiator_base_url,
Miyoung Shinff13ed22022-11-30 09:21:47706 const net::IsolationInfo& isolation_info_for_subresources,
707 blink::mojom::ReferrerPtr referrer,
708 const ui::PageTransition& transition,
709 bool should_replace_current_entry,
710 const std::string& method,
711 bool has_transient_activation,
712 bool is_overriding_user_agent,
713 const std::vector<GURL>& redirects,
714 const GURL& original_url,
715 std::unique_ptr<CrossOriginEmbedderPolicyReporter> coep_reporter,
Miyoung Shinff13ed22022-11-30 09:21:47716 int http_response_code) override;
Miyoung Shinb5561802022-12-01 08:21:35717 void CancelNavigation() override;
Miyoung Shinc9ff4812023-01-05 08:58:05718 bool Credentialless() const override;
Miyoung Shinaf9a34362023-01-31 02:46:51719#if !BUILDFLAG(IS_ANDROID)
720 void GetVirtualAuthenticatorManager(
721 mojo::PendingReceiver<blink::test::mojom::VirtualAuthenticatorManager>
722 receiver) override;
723#endif
Miyoung Shinff13ed22022-11-30 09:21:47724
Mingyu Lei7956b8b2023-07-24 08:24:08725 // Restart the navigation restoring the page from the back-forward cache
726 // as a regular non-BFCached history navigation.
727 //
728 // The restart itself is asynchronous as it's dangerous to restart navigation
729 // with arbitrary state on the stack (another navigation might be starting),
730 // so this function only posts the actual task to do all the work (See
731 // `RestartBackForwardCachedNavigationImpl()`).
732 void RestartBackForwardCachedNavigationAsync(int nav_entry_id);
733
734 // Cancel the asynchronous task that would restart the BFCache navigation.
735 // This should be called whenever a FrameTreeNode's NavigationRequest would
736 // normally get cancelled, including when another NavigationRequest starts.
737 // This preserves the previous behavior where a restarting BFCache
738 // NavigationRequest is kept around until the task to create the new
739 // navigation is run, or until that NavigationRequest gets deleted (which
740 // cancels the task).
741 void CancelRestartingBackForwardCacheNavigation();
742
danakjc492bf82020-09-09 20:02:44743 private:
Yuzu Saijo03dbf9b2022-07-22 04:29:45744 friend class CSPEmbeddedEnforcementUnitTest;
Charlie Hubb5943d2021-03-09 19:46:12745 FRIEND_TEST_ALL_PREFIXES(SitePerProcessPermissionsPolicyBrowserTest,
danakjc492bf82020-09-09 20:02:44746 ContainerPolicyDynamic);
Charlie Hubb5943d2021-03-09 19:46:12747 FRIEND_TEST_ALL_PREFIXES(SitePerProcessPermissionsPolicyBrowserTest,
danakjc492bf82020-09-09 20:02:44748 ContainerPolicySandboxDynamic);
Yuzu Saijo03dbf9b2022-07-22 04:29:45749 FRIEND_TEST_ALL_PREFIXES(NavigationRequestTest, StorageKeyToCommit);
Arthur Sonzogni64457592022-11-22 11:08:59750 FRIEND_TEST_ALL_PREFIXES(
751 NavigationRequestTest,
752 NavigationToCredentiallessDocumentNetworkIsolationInfo);
Yuzu Saijo03dbf9b2022-07-22 04:29:45753 FRIEND_TEST_ALL_PREFIXES(RenderFrameHostImplTest,
Arthur Sonzogni64457592022-11-22 11:08:59754 ChildOfCredentiallessIsCredentialless);
Yifan Luo86a79f42022-08-16 18:38:27755 FRIEND_TEST_ALL_PREFIXES(ContentPasswordManagerDriverTest,
Arthur Sonzogni64457592022-11-22 11:08:59756 PasswordAutofillDisabledOnCredentiallessIframe);
danakjc492bf82020-09-09 20:02:44757
Dominic Farolino8a2187b2021-12-24 20:44:21758 // Called by the destructor. When `this` is an outer dummy FrameTreeNode
759 // representing an inner FrameTree, this method destroys said inner FrameTree.
760 void DestroyInnerFrameTreeIfExists();
761
danakjc492bf82020-09-09 20:02:44762 class OpenerDestroyedObserver;
763
danakjc492bf82020-09-09 20:02:44764 // The |notification_type| parameter is used for histograms only.
765 bool NotifyUserActivation(
766 blink::mojom::UserActivationNotificationType notification_type);
767
768 bool ConsumeTransientUserActivation();
769
770 bool ClearUserActivation();
771
772 // Verify that the renderer process is allowed to set user activation on this
773 // frame by checking whether this frame's RenderWidgetHost had previously seen
774 // an input event that might lead to user activation. If user activation
775 // should be allowed, this returns true and also clears corresponding pending
776 // user activation state in the widget. Otherwise, this returns false.
777 bool VerifyUserActivation();
778
Xiaochen Zhou90858e82023-05-31 15:47:37779 // See comments for `GetFencedFrameProperties()`.
780 absl::optional<FencedFrameProperties>& GetFencedFramePropertiesForEditing(
781 bool force_tree_traversal = false);
Liam Brady6da2cc9e2023-01-30 17:09:43782
Mingyu Lei7956b8b2023-07-24 08:24:08783 // See `RestartBackForwardCachedNavigationAsync()`.
784 void RestartBackForwardCachedNavigationImpl(int nav_entry_id);
785
danakjc492bf82020-09-09 20:02:44786 // The next available browser-global FrameTreeNode ID.
787 static int next_frame_tree_node_id_;
788
Arthur Sonzognif6785ec2022-12-05 10:11:50789 // The FrameTree owning |this|. It can change with Prerender2 during
790 // activation.
791 raw_ref<FrameTree> frame_tree_;
danakjc492bf82020-09-09 20:02:44792
danakjc492bf82020-09-09 20:02:44793 // A browser-global identifier for the frame in the page, which stays stable
794 // even if the frame does a cross-process navigation.
795 const int frame_tree_node_id_;
796
797 // The RenderFrameHost owning this FrameTreeNode, which cannot change for the
798 // life of this FrameTreeNode. |nullptr| if this node is the root.
Keishi Hattori0e45c022021-11-27 09:25:52799 const raw_ptr<RenderFrameHostImpl> parent_;
danakjc492bf82020-09-09 20:02:44800
danakjc492bf82020-09-09 20:02:44801 // The frame that opened this frame, if any. Will be set to null if the
802 // opener is closed, or if this frame disowns its opener by setting its
803 // window.opener to null.
Keishi Hattori0e45c022021-11-27 09:25:52804 raw_ptr<FrameTreeNode> opener_ = nullptr;
danakjc492bf82020-09-09 20:02:44805
806 // An observer that clears this node's |opener_| if the opener is destroyed.
807 // This observer is added to the |opener_|'s observer list when the |opener_|
808 // is set to a non-null node, and it is removed from that list when |opener_|
809 // changes or when this node is destroyed. It is also cleared if |opener_|
810 // is disowned.
811 std::unique_ptr<OpenerDestroyedObserver> opener_observer_;
812
Rakina Zata Amni3a48ae42022-05-05 03:39:56813 // Unlike `opener_`, the "original opener chain" doesn't reflect
814 // window.opener, which can be suppressed or updated. The "original opener"
815 // is the main frame of the actual opener of this frame. This traces the all
816 // the way back, so if the original opener was closed (deleted or severed due
817 // to COOP), but _it_ had an original opener, this will return the original
818 // opener's original opener, etc. So this value will always be set as long as
819 // there is at least one live frame in the chain whose connection is not
820 // severed due to COOP.
821 raw_ptr<FrameTreeNode> first_live_main_frame_in_original_opener_chain_ =
822 nullptr;
danakjc492bf82020-09-09 20:02:44823
Wolfgang Beyerd8809db2020-09-30 15:29:39824 // The devtools frame token of the frame which opened this frame. This is
825 // not cleared even if the opener is destroyed or disowns the frame.
Anton Bikineevf62d1bf2021-05-15 17:56:07826 absl::optional<base::UnguessableToken> opener_devtools_frame_token_;
Wolfgang Beyerd8809db2020-09-30 15:29:39827
Rakina Zata Amni3a48ae42022-05-05 03:39:56828 // An observer that updates this node's
829 // |first_live_main_frame_in_original_opener_chain_| to the next original
830 // opener in the chain if the original opener is destroyed.
danakjc492bf82020-09-09 20:02:44831 std::unique_ptr<OpenerDestroyedObserver> original_opener_observer_;
832
arthursonzogni034bb9c2020-10-01 08:29:56833 // When created by an opener, the URL specified in window.open(url)
834 // Please refer to {Get,Set}InitialPopupURL() documentation.
835 GURL initial_popup_url_;
836
837 // When created using window.open, the origin of the creator.
838 // Please refer to {Get,Set}PopupCreatorOrigin() documentation.
839 url::Origin popup_creator_origin_;
840
W. James MacLean81b8d01f2022-01-25 20:50:59841 // If the url from the the last BeginNavigation is about:srcdoc, this value
842 // stores the srcdoc_attribute's value for re-use in history navigations.
843 std::string srcdoc_value_;
844
danakjc492bf82020-09-09 20:02:44845 // Whether the frame's owner element in the parent document is collapsed.
arthursonzogni9816b9192021-03-29 16:09:19846 bool is_collapsed_ = false;
danakjc492bf82020-09-09 20:02:44847
Daniel Cheng6ac128172021-05-25 18:49:01848 // The type of frame owner for this frame. This is only relevant for non-main
849 // frames.
Kevin McNee43fe8292021-10-04 22:59:41850 const blink::FrameOwnerElementType frame_owner_element_type_ =
851 blink::FrameOwnerElementType::kNone;
Daniel Cheng9bd90f92021-04-23 20:49:45852
Daniel Cheng6ac128172021-05-25 18:49:01853 // The tree scope type of frame owner element, i.e. whether the element is in
854 // the document tree (https://dom.spec.whatwg.org/#document-trees) or the
855 // shadow tree (https://dom.spec.whatwg.org/#shadow-trees). This is only
856 // relevant for non-main frames.
857 const blink::mojom::TreeScopeType tree_scope_type_ =
858 blink::mojom::TreeScopeType::kDocument;
859
danakjc492bf82020-09-09 20:02:44860 // Track the pending sandbox flags and container policy for this frame. When a
861 // parent frame dynamically updates 'sandbox', 'allow', 'allowfullscreen',
862 // 'allowpaymentrequest' or 'src' attributes, the updated policy for the frame
Harkiran Bolaria4eacb3a2021-12-13 20:03:47863 // is stored here, and transferred into
864 // render_manager_.current_replication_state().frame_policy when they take
865 // effect on the next frame navigation.
danakjc492bf82020-09-09 20:02:44866 blink::FramePolicy pending_frame_policy_;
867
868 // Whether the frame was created by javascript. This is useful to prune
869 // history entries when the frame is removed (because frames created by
870 // scripts are never recreated with the same unique name - see
871 // https://crbug.com/500260).
arthursonzogni9816b9192021-03-29 16:09:19872 const bool is_created_by_script_;
danakjc492bf82020-09-09 20:02:44873
danakjc492bf82020-09-09 20:02:44874 // Tracks the scrolling and margin properties for this frame. These
875 // properties affect the child renderer but are stored on its parent's
876 // frame element. When this frame's parent dynamically updates these
877 // properties, we update them here too.
878 //
879 // Note that dynamic updates only take effect on the next frame navigation.
880 blink::mojom::FrameOwnerProperties frame_owner_properties_;
881
Yuzu Saijo03dbf9b2022-07-22 04:29:45882 // Contains the tracked HTML attributes of the corresponding iframe element,
883 // such as 'id' and 'src'.
884 blink::mojom::IframeAttributesPtr attributes_;
Antonio Sartori5abc8de2021-07-13 08:42:47885
danakjc492bf82020-09-09 20:02:44886 // Owns an ongoing NavigationRequest until it is ready to commit. It will then
887 // be reset and a RenderFrameHost will be responsible for the navigation.
888 std::unique_ptr<NavigationRequest> navigation_request_;
889
890 // List of objects observing this FrameTreeNode.
891 base::ObserverList<Observer>::Unchecked observers_;
892
893 base::TimeTicks last_focus_time_;
894
arthursonzogni9816b9192021-03-29 16:09:19895 bool was_discarded_ = false;
danakjc492bf82020-09-09 20:02:44896
Abhijeet Kandalkar3f29bc42022-09-23 12:39:58897 const FencedFrameStatus fenced_frame_status_ =
898 FencedFrameStatus::kNotNestedInFencedFrame;
Harkiran Bolaria16f2c48d2022-04-22 12:39:57899
Garrett Tanzerc69f4642022-08-15 22:15:14900 // If this is a fenced frame resulting from a urn:uuid navigation, this
901 // contains all the metadata specifying the resulting context.
Garrett Tanzer34cb92fe2022-09-28 17:50:54902 // TODO(crbug.com/1262022): Move this into the FrameTree once ShadowDOM
903 // and urn iframes are gone.
Garrett Tanzer29de7112022-12-06 21:26:32904 absl::optional<FencedFrameProperties> fenced_frame_properties_;
Garrett Tanzerc69f4642022-08-15 22:15:14905
Mingyu Lei7956b8b2023-07-24 08:24:08906 // The tracker of the task that restarts the BFCache navigation. It might be
907 // used to cancel the task.
908 // See `CancelRestartingBackForwardCacheNavigation()`.
909 base::CancelableTaskTracker restart_back_forward_cached_navigation_tracker_;
910
Lukasz Anforowicz147141962020-12-16 18:03:24911 // Manages creation and swapping of RenderFrameHosts for this frame.
912 //
913 // This field needs to be declared last, because destruction of
914 // RenderFrameHostManager may call arbitrary callbacks (e.g. via
915 // WebContentsObserver::DidFinishNavigation fired after RenderFrameHostManager
916 // destructs a RenderFrameHostImpl and its NavigationRequest). Such callbacks
917 // may try to use FrameTreeNode's fields above - this would be an undefined
918 // behavior if the fields (even trivially-destructible ones) were destructed
919 // before the RenderFrameHostManager's destructor runs. See also
920 // https://crbug.com/1157988.
921 RenderFrameHostManager render_manager_;
Mingyu Lei7956b8b2023-07-24 08:24:08922
923 base::WeakPtrFactory<FrameTreeNode> weak_factory_{this};
danakjc492bf82020-09-09 20:02:44924};
925
926} // namespace content
927
928#endif // CONTENT_BROWSER_RENDERER_HOST_FRAME_TREE_NODE_H_