blob: 9f8d03c71d4a6f9c16089ddddbb37e49f5618ebd [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"
Christian Biesingere1865c57c2023-10-20 15:19:2916#include "base/memory/safe_ref.h"
David Sanders2c1194d92022-04-19 23:32:3217#include "base/memory/scoped_refptr.h"
David Sandersd4bf5eb2022-03-17 07:12:0518#include "base/observer_list.h"
Mingyu Lei7956b8b2023-07-24 08:24:0819#include "base/task/cancelable_task_tracker.h"
Daniel Cheng390e2a72022-09-28 06:07:5320#include "content/browser/renderer_host/navigation_discard_reason.h"
danakjc492bf82020-09-09 20:02:4421#include "content/browser/renderer_host/navigator.h"
22#include "content/browser/renderer_host/render_frame_host_impl.h"
23#include "content/browser/renderer_host/render_frame_host_manager.h"
Miyoung Shin7cf88b42022-11-07 13:22:3024#include "content/browser/renderer_host/render_frame_host_owner.h"
danakjc492bf82020-09-09 20:02:4425#include "content/common/content_export.h"
Julie Jeongeun Kimf38c1eca2021-12-14 07:46:5526#include "content/public/browser/frame_type.h"
danakjc492bf82020-09-09 20:02:4427#include "services/network/public/mojom/content_security_policy.mojom-forward.h"
Julie Jeongeun Kim0e242242022-11-30 10:45:0928#include "services/network/public/mojom/referrer_policy.mojom-forward.h"
Lei Zhang698df03c2021-05-21 04:23:3429#include "third_party/abseil-cpp/absl/types/optional.h"
Kevin McNee43fe8292021-10-04 22:59:4130#include "third_party/blink/public/common/frame/frame_owner_element_type.h"
danakjc492bf82020-09-09 20:02:4431#include "third_party/blink/public/common/frame/frame_policy.h"
danakjc492bf82020-09-09 20:02:4432#include "third_party/blink/public/mojom/frame/frame_owner_properties.mojom.h"
Gyuyoung Kimc16e52e92021-03-19 02:45:3733#include "third_party/blink/public/mojom/frame/frame_replication_state.mojom-forward.h"
Daniel Cheng6ac128172021-05-25 18:49:0134#include "third_party/blink/public/mojom/frame/tree_scope_type.mojom.h"
David Sanders2c1194d92022-04-19 23:32:3235#include "third_party/blink/public/mojom/frame/user_activation_update_types.mojom-forward.h"
Miyoung Shinaf9a34362023-01-31 02:46:5136#include "third_party/blink/public/mojom/webauthn/virtual_authenticator.mojom-forward.h"
danakjc492bf82020-09-09 20:02:4437
Gabriel Charetted87f10f2022-03-31 00:44:2238#include "base/time/time.h"
danakjc492bf82020-09-09 20:02:4439#include "url/gurl.h"
40#include "url/origin.h"
41
42namespace content {
43
44class NavigationRequest;
45class RenderFrameHostImpl;
46class NavigationEntryImpl;
Paul Semel3e241042022-10-11 12:57:3147class FrameTree;
danakjc492bf82020-09-09 20:02:4448
49// When a page contains iframes, its renderer process maintains a tree structure
50// of those frames. We are mirroring this tree in the browser process. This
51// class represents a node in this tree and is a wrapper for all objects that
52// are frame-specific (as opposed to page-specific).
53//
54// Each FrameTreeNode has a current RenderFrameHost, which can change over
55// time as the frame is navigated. Any immediate subframes of the current
56// document are tracked using FrameTreeNodes owned by the current
57// RenderFrameHost, rather than as children of FrameTreeNode itself. This
58// allows subframe FrameTreeNodes to stay alive while a RenderFrameHost is
59// still alive - for example while pending deletion, after a new current
60// RenderFrameHost has replaced it.
Miyoung Shin7cf88b42022-11-07 13:22:3061class CONTENT_EXPORT FrameTreeNode : public RenderFrameHostOwner {
danakjc492bf82020-09-09 20:02:4462 public:
63 class Observer {
64 public:
65 // Invoked when a FrameTreeNode is being destroyed.
66 virtual void OnFrameTreeNodeDestroyed(FrameTreeNode* node) {}
67
68 // Invoked when a FrameTreeNode becomes focused.
69 virtual void OnFrameTreeNodeFocused(FrameTreeNode* node) {}
70
Arthur Hemerye4659282022-03-28 08:36:1571 // Invoked when a FrameTreeNode moves to a different BrowsingInstance and
72 // the popups it opened should be disowned.
73 virtual void OnFrameTreeNodeDisownedOpenee(FrameTreeNode* node) {}
74
Fergal Dalya1d569972021-03-16 03:24:5375 virtual ~Observer() = default;
danakjc492bf82020-09-09 20:02:4476 };
77
78 static const int kFrameTreeNodeInvalidId;
79
80 // Returns the FrameTreeNode with the given global |frame_tree_node_id|,
81 // regardless of which FrameTree it is in.
82 static FrameTreeNode* GloballyFindByID(int frame_tree_node_id);
83
84 // Returns the FrameTreeNode for the given |rfh|. Same as
85 // rfh->frame_tree_node(), but also supports nullptrs.
86 static FrameTreeNode* From(RenderFrameHost* rfh);
87
88 // Callers are are expected to initialize sandbox flags separately after
89 // calling the constructor.
90 FrameTreeNode(
Arthur Sonzognif6785ec2022-12-05 10:11:5091 FrameTree& frame_tree,
danakjc492bf82020-09-09 20:02:4492 RenderFrameHostImpl* parent,
Daniel Cheng6ac128172021-05-25 18:49:0193 blink::mojom::TreeScopeType tree_scope_type,
danakjc492bf82020-09-09 20:02:4494 bool is_created_by_script,
danakjc492bf82020-09-09 20:02:4495 const blink::mojom::FrameOwnerProperties& frame_owner_properties,
Kevin McNee43fe8292021-10-04 22:59:4196 blink::FrameOwnerElementType owner_type,
Dominic Farolino08662c82021-06-11 07:36:3497 const blink::FramePolicy& frame_owner);
danakjc492bf82020-09-09 20:02:4498
Peter Boström828b9022021-09-21 02:28:4399 FrameTreeNode(const FrameTreeNode&) = delete;
100 FrameTreeNode& operator=(const FrameTreeNode&) = delete;
101
Miyoung Shin7cf88b42022-11-07 13:22:30102 ~FrameTreeNode() override;
danakjc492bf82020-09-09 20:02:44103
104 void AddObserver(Observer* observer);
105 void RemoveObserver(Observer* observer);
106
Ian Vollick25a9d032022-04-12 23:20:17107 // Frame trees may be nested so it can be the case that IsMainFrame() is true,
108 // but is not the outermost main frame. In particular, !IsMainFrame() cannot
109 // be used to check if the frame is an embedded frame -- use
110 // !IsOutermostMainFrame() instead. NB: this does not escape guest views;
111 // IsOutermostMainFrame will be true for the outermost main frame in an inner
112 // guest view.
danakjc492bf82020-09-09 20:02:44113 bool IsMainFrame() const;
Arthur Hemerya06697f2023-03-14 09:20:57114 bool IsOutermostMainFrame() const;
danakjc492bf82020-09-09 20:02:44115
arthursonzogni76098e52020-11-25 14:18:45116 // Clears any state in this node which was set by the document itself (CSP &
117 // UserActivationState) and notifies proxies as appropriate. Invoked after
118 // committing navigation to a new document (since the new document comes with
119 // a fresh set of CSP).
120 // TODO(arthursonzogni): Remove this function. The frame/document must not be
121 // left temporarily with lax state.
Hiroki Nakagawaab309622021-05-19 16:38:13122 void ResetForNavigation();
danakjc492bf82020-09-09 20:02:44123
Arthur Sonzognif6785ec2022-12-05 10:11:50124 FrameTree& frame_tree() const { return frame_tree_.get(); }
Paul Semel3e241042022-10-11 12:57:31125 Navigator& navigator();
danakjc492bf82020-09-09 20:02:44126
127 RenderFrameHostManager* render_manager() { return &render_manager_; }
Alexander Timin33e2e2c12022-03-03 04:21:33128 const RenderFrameHostManager* render_manager() const {
129 return &render_manager_;
130 }
danakjc492bf82020-09-09 20:02:44131 int frame_tree_node_id() const { return frame_tree_node_id_; }
Yuzu Saijo03dbf9b2022-07-22 04:29:45132 // This reflects window.name, which is initially set to the the "name"
133 // attribute. But this won't reflect changes of 'name' attribute and instead
134 // reflect changes to the Window object's name property.
135 // This is different from IframeAttributes' name in that this will not get
136 // updated when 'name' attribute gets updated.
Harkiran Bolaria4eacb3a2021-12-13 20:03:47137 const std::string& frame_name() const {
138 return render_manager_.current_replication_state().name;
139 }
danakjc492bf82020-09-09 20:02:44140
141 const std::string& unique_name() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47142 return render_manager_.current_replication_state().unique_name;
danakjc492bf82020-09-09 20:02:44143 }
144
danakjc492bf82020-09-09 20:02:44145 size_t child_count() const { return current_frame_host()->child_count(); }
146
danakjc492bf82020-09-09 20:02:44147 RenderFrameHostImpl* parent() const { return parent_; }
148
Dave Tapuskac8de3b02021-12-03 21:51:01149 // See `RenderFrameHost::GetParentOrOuterDocument()` for
150 // documentation.
Arthur Hemerya06697f2023-03-14 09:20:57151 RenderFrameHostImpl* GetParentOrOuterDocument() const;
Dave Tapuskac8de3b02021-12-03 21:51:01152
153 // See `RenderFrameHostImpl::GetParentOrOuterDocumentOrEmbedder()` for
154 // documentation.
155 RenderFrameHostImpl* GetParentOrOuterDocumentOrEmbedder();
156
danakjc492bf82020-09-09 20:02:44157 FrameTreeNode* opener() const { return opener_; }
158
Rakina Zata Amni3a48ae42022-05-05 03:39:56159 FrameTreeNode* first_live_main_frame_in_original_opener_chain() const {
160 return first_live_main_frame_in_original_opener_chain_;
161 }
danakjc492bf82020-09-09 20:02:44162
Anton Bikineevf62d1bf2021-05-15 17:56:07163 const absl::optional<base::UnguessableToken>& opener_devtools_frame_token() {
Wolfgang Beyerd8809db2020-09-30 15:29:39164 return opener_devtools_frame_token_;
165 }
166
Julie Jeongeun Kimf38c1eca2021-12-14 07:46:55167 // Returns the type of the frame. Refer to frame_type.h for the details.
168 FrameType GetFrameType() const;
169
danakjc492bf82020-09-09 20:02:44170 // Assigns a new opener for this node and, if |opener| is non-null, registers
171 // an observer that will clear this node's opener if |opener| is ever
172 // destroyed.
173 void SetOpener(FrameTreeNode* opener);
174
175 // Assigns the initial opener for this node, and if |opener| is non-null,
176 // registers an observer that will clear this node's opener if |opener| is
177 // ever destroyed. The value set here is the root of the tree.
178 //
179 // It is not possible to change the opener once it was set.
180 void SetOriginalOpener(FrameTreeNode* opener);
181
Wolfgang Beyerd8809db2020-09-30 15:29:39182 // Assigns an opener frame id for this node. This string id is only set once
183 // and cannot be changed. It persists, even if the |opener| is destroyed. It
184 // is used for attribution in the DevTools frontend.
185 void SetOpenerDevtoolsFrameToken(
186 base::UnguessableToken opener_devtools_frame_token);
187
danakjc492bf82020-09-09 20:02:44188 FrameTreeNode* child_at(size_t index) const {
189 return current_frame_host()->child_at(index);
190 }
191
192 // Returns the URL of the last committed page in the current frame.
193 const GURL& current_url() const {
194 return current_frame_host()->GetLastCommittedURL();
195 }
196
Abhijeet Kandalkarb86993b2022-11-22 05:17:40197 // Note that the current RenderFrameHost might not exist yet when calling this
198 // during FrameTreeNode initialization. In this case the FrameTreeNode must be
199 // on the initial empty document. Refer RFHI::is_initial_empty_document for a
200 // more details.
Rakina Zata Amni86c88fa2021-11-01 01:27:30201 bool is_on_initial_empty_document() const {
Abhijeet Kandalkarb86993b2022-11-22 05:17:40202 return current_frame_host()
203 ? current_frame_host()->is_initial_empty_document()
204 : true;
Rakina Zata Amnifc4cc3d42021-06-10 09:03:56205 }
206
danakjc492bf82020-09-09 20:02:44207 // Returns whether the frame's owner element in the parent document is
208 // collapsed, that is, removed from the layout as if it did not exist, as per
209 // request by the embedder (of the content/ layer).
210 bool is_collapsed() const { return is_collapsed_; }
211
212 // Sets whether to collapse the frame's owner element in the parent document,
213 // that is, to remove it from the layout as if it did not exist, as per
214 // request by the embedder (of the content/ layer). Cannot be called for main
215 // frames.
216 //
217 // This only has an effect for <iframe> owner elements, and is a no-op when
218 // called on sub-frames hosted in <frame>, <object>, and <embed> elements.
219 void SetCollapsed(bool collapsed);
220
221 // Returns the origin of the last committed page in this frame.
222 // WARNING: To get the last committed origin for a particular
223 // RenderFrameHost, use RenderFrameHost::GetLastCommittedOrigin() instead,
224 // which will behave correctly even when the RenderFrameHost is not the
225 // current one for this frame (such as when it's pending deletion).
226 const url::Origin& current_origin() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47227 return render_manager_.current_replication_state().origin;
danakjc492bf82020-09-09 20:02:44228 }
229
danakjc492bf82020-09-09 20:02:44230 // Returns the latest frame policy (sandbox flags and container policy) for
231 // this frame. This includes flags inherited from parent frames and the latest
232 // flags from the <iframe> element hosting this frame. The returned policies
233 // may not yet have taken effect, since "sandbox" and "allow" attribute
Liam Brady25a14162022-12-02 15:25:57234 // updates in an <iframe> element take effect on next navigation. For
235 // <fencedframe> elements, not everything in the frame policy might actually
236 // take effect after the navigation. To retrieve the currently active policy
237 // for this frame, use effective_frame_policy().
danakjc492bf82020-09-09 20:02:44238 const blink::FramePolicy& pending_frame_policy() const {
239 return pending_frame_policy_;
240 }
241
242 // Update this frame's sandbox flags and container policy. This is called
243 // when a parent frame updates the "sandbox" attribute in the <iframe> element
244 // for this frame, or any of the attributes which affect the container policy
245 // ("allowfullscreen", "allowpaymentrequest", "allow", and "src".)
246 // These policies won't take effect until next navigation. If this frame's
247 // parent is itself sandboxed, the parent's sandbox flags are combined with
248 // those in |frame_policy|.
249 // Attempting to change the container policy on the main frame will have no
250 // effect.
251 void SetPendingFramePolicy(blink::FramePolicy frame_policy);
252
253 // Returns the currently active frame policy for this frame, including the
254 // sandbox flags which were present at the time the document was loaded, and
Charlie Hu5130d25e2021-03-05 21:53:39255 // the permissions policy container policy, which is set by the iframe's
danakjc492bf82020-09-09 20:02:44256 // allowfullscreen, allowpaymentrequest, and allow attributes, along with the
257 // origin of the iframe's src attribute (which may be different from the URL
258 // of the document currently loaded into the frame). This does not include
259 // policy changes that have been made by updating the containing iframe
260 // element attributes since the frame was last navigated; use
261 // pending_frame_policy() for those.
262 const blink::FramePolicy& effective_frame_policy() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47263 return render_manager_.current_replication_state().frame_policy;
danakjc492bf82020-09-09 20:02:44264 }
265
danakjc492bf82020-09-09 20:02:44266 const blink::mojom::FrameOwnerProperties& frame_owner_properties() {
267 return frame_owner_properties_;
268 }
269
270 void set_frame_owner_properties(
271 const blink::mojom::FrameOwnerProperties& frame_owner_properties) {
272 frame_owner_properties_ = frame_owner_properties;
273 }
274
Yuzu Saijo03dbf9b2022-07-22 04:29:45275 // Reflects the attributes of the corresponding iframe html element, such
Arthur Sonzogni64457592022-11-22 11:08:59276 // as 'credentialless', 'id', 'name' and 'src'. These values should not be
Yuzu Saijo03dbf9b2022-07-22 04:29:45277 // exposed to cross-origin renderers.
278 const network::mojom::ContentSecurityPolicy* csp_attribute() const {
279 return attributes_->parsed_csp_attribute.get();
danakjc492bf82020-09-09 20:02:44280 }
Yao Xiao9c54b3e2023-03-14 04:25:04281 // Tracks iframe's 'browsingtopics' attribute, indicating whether the
282 // navigation requests on this frame should calculate and send the
283 // `Sec-Browsing-Topics` header.
284 bool browsing_topics() const { return attributes_->browsing_topics; }
Camillia Smith Barnes6d2966c82023-08-23 21:16:18285
286 // Tracks iframe's 'sharedstoragewritable' attribute, indicating what value
Camillia Smith Barnesc267be62023-11-01 20:01:02287 // the the corresponding
288 // `network::ResourceRequest::shared_storage_writable_eligible` should take
289 // for the navigation(s) on this frame, pending a permissions policy check. If
290 // true, and if the permissions policy check returns "enabled", the network
Camillia Smith Barnes6d2966c82023-08-23 21:16:18291 // service will send the `Shared-Storage-Write` request header.
Camillia Smith Barnesc267be62023-11-01 20:01:02292 bool shared_storage_writable_opted_in() const {
293 return attributes_->shared_storage_writable_opted_in;
Camillia Smith Barnes6d2966c82023-08-23 21:16:18294 }
Yuzu Saijodc870f92023-01-20 03:39:11295 const absl::optional<std::string> html_id() const { return attributes_->id; }
Yuzu Saijo03dbf9b2022-07-22 04:29:45296 // This tracks iframe's 'name' attribute instead of window.name, which is
297 // tracked in FrameReplicationState. See the comment for frame_name() for
298 // more details.
Yuzu Saijodc870f92023-01-20 03:39:11299 const absl::optional<std::string> html_name() const {
300 return attributes_->name;
301 }
302 const absl::optional<std::string> html_src() const {
303 return attributes_->src;
304 }
danakjc492bf82020-09-09 20:02:44305
Yuzu Saijo03dbf9b2022-07-22 04:29:45306 void SetAttributes(blink::mojom::IframeAttributesPtr attributes);
Antonio Sartori5abc8de2021-07-13 08:42:47307
danakjc492bf82020-09-09 20:02:44308 bool HasSameOrigin(const FrameTreeNode& node) const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47309 return render_manager_.current_replication_state().origin.IsSameOriginWith(
310 node.current_replication_state().origin);
danakjc492bf82020-09-09 20:02:44311 }
312
Gyuyoung Kimc16e52e92021-03-19 02:45:37313 const blink::mojom::FrameReplicationState& current_replication_state() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47314 return render_manager_.current_replication_state();
danakjc492bf82020-09-09 20:02:44315 }
316
317 RenderFrameHostImpl* current_frame_host() const {
318 return render_manager_.current_frame_host();
319 }
320
danakjc492bf82020-09-09 20:02:44321 // Returns true if this node is in a loading state.
322 bool IsLoading() const;
Nate Chapin470dbc62023-04-25 16:34:38323 LoadingState GetLoadingState() const;
danakjc492bf82020-09-09 20:02:44324
Alex Moshchuk9b0fd822020-10-26 23:08:15325 // Returns true if this node has a cross-document navigation in progress.
326 bool HasPendingCrossDocumentNavigation() const;
327
danakjc492bf82020-09-09 20:02:44328 NavigationRequest* navigation_request() { return navigation_request_.get(); }
329
330 // Transfers the ownership of the NavigationRequest to |render_frame_host|.
331 // From ReadyToCommit to DidCommit, the NavigationRequest is owned by the
332 // RenderFrameHost that is committing the navigation.
333 void TransferNavigationRequestOwnership(
334 RenderFrameHostImpl* render_frame_host);
335
336 // Takes ownership of |navigation_request| and makes it the current
337 // NavigationRequest of this frame. This corresponds to the start of a new
338 // navigation. If there was an ongoing navigation request before calling this
339 // function, it is canceled. |navigation_request| should not be null.
Charlie Reis09952ee2022-12-08 16:35:07340 void TakeNavigationRequest(
danakjc492bf82020-09-09 20:02:44341 std::unique_ptr<NavigationRequest> navigation_request);
342
Rakina Zata Amnif8f2bb62022-11-23 05:54:32343 // Resets the navigation request owned by `this` (which shouldn't have reached
344 // the "pending commit" stage yet) and any state created by it, including the
Rakina Zata Amni33175cb92022-11-24 02:46:03345 // speculative RenderFrameHost (if there are no other navigations associated
346 // with it). Note that this does not affect navigations that have reached the
347 // "pending commit" stage, which are owned by their corresponding
348 // RenderFrameHosts instead.
Daniel Cheng390e2a72022-09-28 06:07:53349 void ResetNavigationRequest(NavigationDiscardReason reason);
350
Rakina Zata Amnif8f2bb62022-11-23 05:54:32351 // Similar to `ResetNavigationRequest()`, but keeps the state created by the
Daniel Cheng390e2a72022-09-28 06:07:53352 // NavigationRequest (e.g. speculative RenderFrameHost, loading state).
353 void ResetNavigationRequestButKeepState();
danakjc492bf82020-09-09 20:02:44354
danakjc492bf82020-09-09 20:02:44355 // The load progress for a RenderFrameHost in this node was updated to
356 // |load_progress|. This will notify the FrameTree which will in turn notify
357 // the WebContents.
358 void DidChangeLoadProgress(double load_progress);
359
360 // Called when the user directed the page to stop loading. Stops all loads
361 // happening in the FrameTreeNode. This method should be used with
362 // FrameTree::ForEach to stop all loads in the entire FrameTree.
363 bool StopLoading();
364
365 // Returns the time this frame was last focused.
366 base::TimeTicks last_focus_time() const { return last_focus_time_; }
367
368 // Called when this node becomes focused. Updates the node's last focused
369 // time and notifies observers.
370 void DidFocus();
371
372 // Called when the user closed the modal dialogue for BeforeUnload and
373 // cancelled the navigation. This should stop any load happening in the
374 // FrameTreeNode.
375 void BeforeUnloadCanceled();
376
danakjc492bf82020-09-09 20:02:44377 // Returns the sandbox flags currently in effect for this frame. This includes
378 // flags inherited from parent frames, the currently active flags from the
379 // <iframe> element hosting this frame, as well as any flags set from a
380 // Content-Security-Policy HTTP header. This does not include flags that have
381 // have been updated in an <iframe> element but have not taken effect yet; use
382 // pending_frame_policy() for those. To see the flags which will take effect
383 // on navigation (which does not include the CSP-set flags), use
384 // effective_frame_policy().
385 network::mojom::WebSandboxFlags active_sandbox_flags() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47386 return render_manager_.current_replication_state().active_sandbox_flags;
danakjc492bf82020-09-09 20:02:44387 }
388
danakjc492bf82020-09-09 20:02:44389 // Returns whether the frame received a user gesture on a previous navigation
390 // on the same eTLD+1.
391 bool has_received_user_gesture_before_nav() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47392 return render_manager_.current_replication_state()
393 .has_received_user_gesture_before_nav;
danakjc492bf82020-09-09 20:02:44394 }
395
396 // When a tab is discarded, WebContents sets was_discarded on its
397 // root FrameTreeNode.
398 // In addition, when a child frame is created, this bit is passed on from
399 // parent to child.
400 // When a navigation request is created, was_discarded is passed on to the
401 // request and reset to false in FrameTreeNode.
402 void set_was_discarded() { was_discarded_ = true; }
403 bool was_discarded() const { return was_discarded_; }
404
Miyoung Shin8a66ec022022-11-28 23:50:09405 // Deprecated. Use directly HasStickyUserActivation in RFHI.
danakjc492bf82020-09-09 20:02:44406 // Returns the sticky bit of the User Activation v2 state of the
407 // |FrameTreeNode|.
408 bool HasStickyUserActivation() const {
Miyoung Shin8a66ec022022-11-28 23:50:09409 return current_frame_host()->HasStickyUserActivation();
danakjc492bf82020-09-09 20:02:44410 }
411
Miyoung Shin8a66ec022022-11-28 23:50:09412 // Deprecated. Use directly HasStickyUserActivation in RFHI.
danakjc492bf82020-09-09 20:02:44413 // Returns the transient bit of the User Activation v2 state of the
414 // |FrameTreeNode|.
415 bool HasTransientUserActivation() {
Miyoung Shin8a66ec022022-11-28 23:50:09416 return current_frame_host()->HasTransientUserActivation();
danakjc492bf82020-09-09 20:02:44417 }
418
419 // Remove history entries for all frames created by script in this frame's
420 // subtree. If a frame created by a script is removed, then its history entry
421 // will never be reused - this saves memory.
422 void PruneChildFrameNavigationEntries(NavigationEntryImpl* entry);
423
Abhijeet Kandalkarb43affa72022-09-27 16:48:01424 using FencedFrameStatus = RenderFrameHostImpl::FencedFrameStatus;
Abhijeet Kandalkar3f29bc42022-09-23 12:39:58425 FencedFrameStatus fenced_frame_status() const { return fenced_frame_status_; }
426
Kevin McNee43fe8292021-10-04 22:59:41427 blink::FrameOwnerElementType frame_owner_element_type() const {
Daniel Cheng9bd90f92021-04-23 20:49:45428 return frame_owner_element_type_;
danakjc492bf82020-09-09 20:02:44429 }
danakjc492bf82020-09-09 20:02:44430
Daniel Cheng6ac128172021-05-25 18:49:01431 blink::mojom::TreeScopeType tree_scope_type() const {
432 return tree_scope_type_;
433 }
434
arthursonzogni034bb9c2020-10-01 08:29:56435 // The initial popup URL for new window opened using:
436 // `window.open(initial_popup_url)`.
437 // An empty GURL otherwise.
438 //
439 // [WARNING] There is no guarantee the FrameTreeNode will ever host a
440 // document served from this URL. The FrameTreeNode always starts hosting the
441 // initial empty document and attempts a navigation toward this URL. However
442 // the navigation might be delayed, redirected and even cancelled.
443 void SetInitialPopupURL(const GURL& initial_popup_url);
444 const GURL& initial_popup_url() const { return initial_popup_url_; }
445
446 // The origin of the document that used window.open() to create this frame.
447 // Otherwise, an opaque Origin with a nonce different from all previously
448 // existing Origins.
449 void SetPopupCreatorOrigin(const url::Origin& popup_creator_origin);
450 const url::Origin& popup_creator_origin() const {
451 return popup_creator_origin_;
452 }
453
Harkiran Bolaria59290d62021-03-17 01:53:01454 // Sets the associated FrameTree for this node. The node can change FrameTrees
Domenic Denicola7767a9c2023-07-13 15:36:39455 // as part of prerendering, which allows a page loaded in the prerendered
456 // FrameTree to be used for a navigation in the primary frame tree.
Harkiran Bolaria59290d62021-03-17 01:53:01457 void SetFrameTree(FrameTree& frame_tree);
458
Alexander Timin074cd182022-03-23 18:11:22459 using TraceProto = perfetto::protos::pbzero::FrameTreeNodeInfo;
Alexander Timinf785f342021-03-18 00:00:56460 // Write a representation of this object into a trace.
Alexander Timin074cd182022-03-23 18:11:22461 void WriteIntoTrace(perfetto::TracedProto<TraceProto> proto) const;
Alexander Timinf785f342021-03-18 00:00:56462
Carlos Caballero76711352021-03-24 17:38:21463 // Returns true the node is navigating, i.e. it has an associated
464 // NavigationRequest.
465 bool HasNavigation();
466
shivanigithubf3ddff52021-07-03 22:06:30467 // Fenced frames (meta-bug crbug.com/1111084):
shivanigithub4cd016a2021-09-20 21:10:30468 // Note that these two functions cannot be invoked from a FrameTree's or
469 // its root node's constructor since they require the frame tree and the
470 // root node to be completely constructed.
471 //
shivanigithubf3ddff52021-07-03 22:06:30472 // Returns false if fenced frames are disabled. Returns true if the feature is
473 // enabled and if |this| is a fenced frame. Returns false for
474 // iframes embedded in a fenced frame. To clarify: for the MPArch
475 // implementation this only returns true if |this| is the actual
476 // root node of the inner FrameTree and not the proxy FrameTreeNode in the
477 // outer FrameTree.
Dominic Farolino4bc10ee2021-08-31 00:37:36478 bool IsFencedFrameRoot() const;
shivanigithubf3ddff52021-07-03 22:06:30479
480 // Returns false if fenced frames are disabled. Returns true if the
481 // feature is enabled and if |this| or any of its ancestor nodes is a
482 // fenced frame.
483 bool IsInFencedFrameTree() const;
484
shivanigithub4cd016a2021-09-20 21:10:30485 // Returns a valid nonce if `IsInFencedFrameTree()` returns true for `this`.
Garrett Tanzer34cb92fe2022-09-28 17:50:54486 // Returns nullopt otherwise.
487 //
488 // Nonce used in the net::IsolationInfo and blink::StorageKey for a fenced
489 // frame and any iframes nested within it. Not set if this frame is not in a
490 // fenced frame's FrameTree. Note that this could be a field in FrameTree for
491 // the MPArch version but for the shadow DOM version we need to keep it here
492 // since the fenced frame root is not a main frame for the latter. The value
493 // of the nonce will be the same for all of the the iframes inside a fenced
494 // frame tree. If there is a nested fenced frame it will have a different
495 // nonce than its parent fenced frame. The nonce will stay the same across
496 // navigations initiated from the fenced frame tree because it is always used
497 // in conjunction with other fields of the keys and would be good to access
498 // the same storage across same-origin navigations. If the navigation is
499 // same-origin/site then the same network stack partition/storage will be
500 // reused and if it's cross-origin/site then other parts of the key will
501 // change and so, even with the same nonce, another partition will be used.
502 // But if the navigation is initiated from the embedder, the nonce will be
503 // reinitialized irrespective of same or cross origin such that there is no
504 // privacy leak via storage shared between two embedder initiated navigations.
505 // Note that this reinitialization is implemented for all embedder-initiated
506 // navigations in MPArch, but only urn:uuid navigations in ShadowDOM.
507 absl::optional<base::UnguessableToken> GetFencedFrameNonce();
shivanigithub4cd016a2021-09-20 21:10:30508
Garrett Tanzer34cb92fe2022-09-28 17:50:54509 // If applicable, initialize the default fenced frame properties. Right now,
510 // this means setting a new fenced frame nonce. See comment on
shivanigithub4cd016a2021-09-20 21:10:30511 // fenced_frame_nonce() for when it is set to a non-null value. Invoked
512 // by FrameTree::Init() or FrameTree::AddFrame().
Garrett Tanzer34cb92fe2022-09-28 17:50:54513 void SetFencedFramePropertiesIfNeeded();
shivanigithub4cd016a2021-09-20 21:10:30514
Garrett Tanzer291a2d52023-03-20 22:41:57515 // Set the current FencedFrameProperties to have "opaque ads mode".
516 // This should only be used during tests, when the proper embedder-initiated
517 // fenced frame root urn/config navigation flow isn't available.
518 // TODO(crbug.com/1347953): Refactor and expand use of test utils so there is
519 // a consistent way to do this properly everywhere. Consider removing
520 // arbitrary restrictions in "default mode" so that using opaque ads mode is
521 // less necessary.
522 void SetFencedFramePropertiesOpaqueAdsModeForTesting() {
523 if (fenced_frame_properties_.has_value()) {
524 fenced_frame_properties_->mode_ =
525 blink::FencedFrame::DeprecatedFencedFrameMode::kOpaqueAds;
526 }
527 }
528
529 // Returns the mode attribute from the `FencedFrameProperties` if this frame
530 // is in a fenced frame tree, otherwise returns `kDefault`.
531 blink::FencedFrame::DeprecatedFencedFrameMode GetDeprecatedFencedFrameMode();
Nan Lin171fe9a2022-02-17 16:42:16532
Dave Tapuskac8de3b02021-12-03 21:51:01533 // Helper for GetParentOrOuterDocument/GetParentOrOuterDocumentOrEmbedder.
534 // Do not use directly.
Kevin McNee86e64ee2023-02-17 16:35:50535 // `escape_guest_view` determines whether to iterate out of guest views and is
536 // the behaviour distinction between GetParentOrOuterDocument and
537 // GetParentOrOuterDocumentOrEmbedder. See the comment on
538 // GetParentOrOuterDocumentOrEmbedder for details.
539 // `include_prospective` includes embedders which own our frame tree, but have
540 // not yet attached it to the outer frame tree.
Arthur Hemerya06697f2023-03-14 09:20:57541 RenderFrameHostImpl* GetParentOrOuterDocumentHelper(
542 bool escape_guest_view,
543 bool include_prospective) const;
Dave Tapuskac8de3b02021-12-03 21:51:01544
Harkiran Bolariab4437fd2021-08-11 17:51:22545 // Sets the unique_name and name fields on replication_state_. To be used in
546 // prerender activation to make sure the FrameTreeNode replication state is
547 // correct after the RenderFrameHost is moved between FrameTreeNodes. The
548 // renderers should already have the correct value, so unlike
549 // FrameTreeNode::SetFrameName, we do not notify them here.
Harkiran Bolaria4eacb3a2021-12-13 20:03:47550 // TODO(https://crbug.com/1237091): Remove this once the BrowsingContextState
551 // is implemented to utilize the new path.
Harkiran Bolariab4437fd2021-08-11 17:51:22552 void set_frame_name_for_activation(const std::string& unique_name,
553 const std::string& name) {
Harkiran Bolaria0b3bdef02022-03-10 13:04:40554 current_frame_host()->browsing_context_state()->set_frame_name(unique_name,
555 name);
Harkiran Bolariab4437fd2021-08-11 17:51:22556 }
557
Nan Linaaf84f72021-12-02 22:31:56558 // Returns true if error page isolation is enabled.
559 bool IsErrorPageIsolationEnabled() const;
560
W. James MacLean81b8d01f2022-01-25 20:50:59561 // Functions to store and retrieve a frame's srcdoc value on this
562 // FrameTreeNode.
563 void SetSrcdocValue(const std::string& srcdoc_value);
564 const std::string& srcdoc_value() const { return srcdoc_value_; }
565
Garrett Tanzerc69f4642022-08-15 22:15:14566 void set_fenced_frame_properties(
Garrett Tanzer29de7112022-12-06 21:26:32567 const absl::optional<FencedFrameProperties>& fenced_frame_properties) {
Garrett Tanzer2975eeac2022-08-22 16:34:01568 // TODO(crbug.com/1262022): Reenable this DCHECK once ShadowDOM and
569 // loading urns in iframes (for FLEDGE OT) are gone.
570 // DCHECK_EQ(fenced_frame_status_,
571 // RenderFrameHostImpl::FencedFrameStatus::kFencedFrameRoot);
Garrett Tanzerc69f4642022-08-15 22:15:14572 fenced_frame_properties_ = fenced_frame_properties;
573 }
574
Xiaochen Zhou86f2e712023-09-13 19:55:04575 // This function returns the fenced frame properties associated with the given
576 // source.
577 // - If `source_node` is set to `kClosestAncestor`, the fenced frame
578 // properties are obtained by a bottom-up traversal from this node.
579 // - If `source_node` is set tp `kFrameTreeRoot`, the fenced frame properties
580 // from the fenced frame tree root are returned.
581 // For example, for an urn iframe that is nested inside a fenced frame.
582 // Calling this function from the nested urn iframe with `source_node` set to:
583 // - `kClosestAncestor`: returns the fenced frame properties from the urn
584 // iframe.
585 // - `kFrameTreeRoot`: returns the fenced frame properties from the fenced
586 // frame.
587 // Clients should decide which one to use depending on how the application of
588 // the fenced frame properties interact with urn iframes.
589 // TODO(crbug.com/1355857): Once navigation support for urn::uuid in iframes
590 // is deprecated, remove the parameter `node_source`.
Xiaochen Zhou90858e82023-05-31 15:47:37591 const absl::optional<FencedFrameProperties>& GetFencedFrameProperties(
Xiaochen Zhou86f2e712023-09-13 19:55:04592 FencedFramePropertiesNodeSource node_source =
593 FencedFramePropertiesNodeSource::kClosestAncestor);
Garrett Tanzerc69f4642022-08-15 22:15:14594
Liam Brady6da2cc9e2023-01-30 17:09:43595 // Called from the currently active document via the
596 // `Fence.setReportEventDataForAutomaticBeacons` JS API.
597 void SetFencedFrameAutomaticBeaconReportEventData(
Liam Brady95434ea62023-11-02 19:18:32598 blink::mojom::AutomaticBeaconType event_type,
Liam Brady6da2cc9e2023-01-30 17:09:43599 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()`.
Liam Brady95434ea62023-11-02 19:18:32608 void MaybeResetFencedFrameAutomaticBeaconReportEventData(
609 blink::mojom::AutomaticBeaconType event_type);
Liam Brady6da2cc9e2023-01-30 17:09:43610
Yao Xiaof9ae90a2023-03-01 20:52:44611 // Returns the number of fenced frame boundaries above this frame. The
Yao Xiaoa2337ad2022-10-12 20:59:29612 // outermost main frame's frame tree has fenced frame depth 0, a topmost
613 // fenced frame tree embedded in the outermost main frame has fenced frame
614 // depth 1, etc.
Yao Xiaof9ae90a2023-03-01 20:52:44615 //
616 // Also, sets `shared_storage_fenced_frame_root_count` to the
617 // number of fenced frame boundaries (roots) above this frame that originate
618 // from shared storage. This is used to check whether a fenced frame
619 // originates from shared storage only (i.e. not from FLEDGE).
620 // TODO(crbug.com/1347953): Remove this check once we put permissions inside
621 // FencedFrameConfig.
622 size_t GetFencedFrameDepth(size_t& shared_storage_fenced_frame_root_count);
Yao Xiaoa2337ad2022-10-12 20:59:29623
624 // Traverse up from this node. Return all valid
625 // `node->fenced_frame_properties_->shared_storage_budget_metadata` (i.e. this
626 // node is subjected to the shared storage budgeting associated with those
627 // metadata). Every node that originates from sharedStorage.selectURL() will
628 // have an associated metadata. This indicates that the metadata can only
629 // possibly be associated with a fenced frame root, unless when
630 // `kAllowURNsInIframes` is enabled in which case they could be be associated
631 // with any node.
Garrett Tanzer29de7112022-12-06 21:26:32632 std::vector<const SharedStorageBudgetMetadata*>
Yao Xiao1ac702d2022-06-08 17:20:49633 FindSharedStorageBudgetMetadata();
634
Camillia Smith Barnes7218518c2023-03-06 19:02:17635 // Returns any shared storage context string that was written to a
636 // `blink::FencedFrameConfig` before navigation via
637 // `setSharedStorageContext()`, as long as the request is for a same-origin
638 // frame within the config's fenced frame tree (or a same-origin descendant of
639 // a URN iframe).
640 absl::optional<std::u16string> GetEmbedderSharedStorageContextIfAllowed();
641
Harkiran Bolariaebbe7702022-02-22 19:19:03642 // Accessor to BrowsingContextState for subframes only. Only main frame
643 // navigations can change BrowsingInstances and BrowsingContextStates,
644 // therefore for subframes associated BrowsingContextState never changes. This
645 // helper method makes this more explicit and guards against calling this on
646 // main frames (there an appropriate BrowsingContextState should be obtained
647 // from RenderFrameHost or from RenderFrameProxyHost as e.g. during
648 // cross-BrowsingInstance navigations multiple BrowsingContextStates exist in
649 // the same frame).
650 const scoped_refptr<BrowsingContextState>&
651 GetBrowsingContextStateForSubframe() const;
652
Arthur Hemerye4659282022-03-28 08:36:15653 // Clears the opener property of popups referencing this FrameTreeNode as
654 // their opener.
655 void ClearOpenerReferences();
656
Liam Brady95d36d12023-03-13 21:13:06657 // Calculates whether one of the ancestor frames or this frame has a CSPEE in
658 // place. This is eventually sent over to LocalFrame in the renderer where it
659 // will be used by NavigatorAuction::canLoadAdAuctionFencedFrame for
660 // information it can't get on its own.
Liam Bradyd2a41e152022-07-19 13:58:48661 bool AncestorOrSelfHasCSPEE() const;
662
Arthur Sonzogni8e8eb1f2023-01-10 14:51:01663 // Reset every navigation in this frame, and its descendants. This is called
664 // after the <iframe> element has been removed, or after the document owning
665 // this frame has been navigated away.
666 //
667 // This takes into account:
668 // - Non-pending commit NavigationRequest owned by the FrameTreeNode
669 // - Pending commit NavigationRequest owned by the current RenderFrameHost
670 // - Speculative RenderFrameHost and its pending commit NavigationRequests.
671 void ResetAllNavigationsForFrameDetach();
672
Miyoung Shin7cf88b42022-11-07 13:22:30673 // RenderFrameHostOwner implementation:
Nate Chapin470dbc62023-04-25 16:34:38674 void DidStartLoading(LoadingState previous_frame_tree_loading_state) override;
Julie Jeongeun Kim07c077bd2022-12-05 08:40:31675 void DidStopLoading() override;
Miyoung Shin7cf88b42022-11-07 13:22:30676 void RestartNavigationAsCrossDocument(
677 std::unique_ptr<NavigationRequest> navigation_request) override;
Miyoung Shin1504eb712022-12-07 10:32:18678 bool Reload() override;
Julie Jeongeun Kimc1b07c32022-11-11 10:26:32679 Navigator& GetCurrentNavigator() override;
Miyoung Shine16cd2262022-11-30 05:52:16680 RenderFrameHostManager& GetRenderFrameHostManager() override;
Miyoung Shin64fd1bea2023-01-04 04:22:08681 FrameTreeNode* GetOpener() const override;
Julie Jeongeun Kim2132b37f82022-11-23 08:30:46682 void SetFocusedFrame(SiteInstanceGroup* source) override;
Julie Jeongeun Kim0e242242022-11-30 10:45:09683 void DidChangeReferrerPolicy(
684 network::mojom::ReferrerPolicy referrer_policy) override;
Miyoung Shin7cf88b42022-11-07 13:22:30685
Miyoung Shin8a66ec022022-11-28 23:50:09686 // Updates the user activation state in the browser frame tree and in the
687 // frame trees in all renderer processes except the renderer for this node
688 // (which initiated the update). Returns |false| if the update tries to
689 // consume an already consumed/expired transient state, |true| otherwise. See
690 // the comment on `user_activation_state_` in RenderFrameHostImpl.
691 //
692 // The |notification_type| parameter is used for histograms, only for the case
693 // |update_state == kNotifyActivation|.
694 bool UpdateUserActivationState(
695 blink::mojom::UserActivationUpdateType update_type,
696 blink::mojom::UserActivationNotificationType notification_type) override;
697
Nate Chapin47276a62023-02-16 16:53:44698 void DidConsumeHistoryUserActivation() override;
699
Miyoung Shinff13ed22022-11-30 09:21:47700 std::unique_ptr<NavigationRequest>
701 CreateNavigationRequestForSynchronousRendererCommit(
702 RenderFrameHostImpl* render_frame_host,
703 bool is_same_document,
704 const GURL& url,
705 const url::Origin& origin,
W. James MacLean23e90a12022-12-21 04:38:21706 const absl::optional<GURL>& initiator_base_url,
Miyoung Shinff13ed22022-11-30 09:21:47707 const net::IsolationInfo& isolation_info_for_subresources,
708 blink::mojom::ReferrerPtr referrer,
709 const ui::PageTransition& transition,
710 bool should_replace_current_entry,
711 const std::string& method,
712 bool has_transient_activation,
713 bool is_overriding_user_agent,
714 const std::vector<GURL>& redirects,
715 const GURL& original_url,
716 std::unique_ptr<CrossOriginEmbedderPolicyReporter> coep_reporter,
Miyoung Shinff13ed22022-11-30 09:21:47717 int http_response_code) override;
Miyoung Shinb5561802022-12-01 08:21:35718 void CancelNavigation() override;
Miyoung Shinc9ff4812023-01-05 08:58:05719 bool Credentialless() const override;
Miyoung Shinaf9a34362023-01-31 02:46:51720#if !BUILDFLAG(IS_ANDROID)
721 void GetVirtualAuthenticatorManager(
722 mojo::PendingReceiver<blink::test::mojom::VirtualAuthenticatorManager>
723 receiver) override;
724#endif
Miyoung Shinff13ed22022-11-30 09:21:47725
Mingyu Lei7956b8b2023-07-24 08:24:08726 // Restart the navigation restoring the page from the back-forward cache
727 // as a regular non-BFCached history navigation.
728 //
729 // The restart itself is asynchronous as it's dangerous to restart navigation
730 // with arbitrary state on the stack (another navigation might be starting),
731 // so this function only posts the actual task to do all the work (See
732 // `RestartBackForwardCachedNavigationImpl()`).
733 void RestartBackForwardCachedNavigationAsync(int nav_entry_id);
734
735 // Cancel the asynchronous task that would restart the BFCache navigation.
736 // This should be called whenever a FrameTreeNode's NavigationRequest would
737 // normally get cancelled, including when another NavigationRequest starts.
738 // This preserves the previous behavior where a restarting BFCache
739 // NavigationRequest is kept around until the task to create the new
740 // navigation is run, or until that NavigationRequest gets deleted (which
741 // cancels the task).
742 void CancelRestartingBackForwardCacheNavigation();
743
Christian Biesingere1865c57c2023-10-20 15:19:29744 base::SafeRef<FrameTreeNode> GetSafeRef() {
745 return weak_factory_.GetSafeRef();
746 }
747
danakjc492bf82020-09-09 20:02:44748 private:
Yuzu Saijo03dbf9b2022-07-22 04:29:45749 friend class CSPEmbeddedEnforcementUnitTest;
Charlie Hubb5943d2021-03-09 19:46:12750 FRIEND_TEST_ALL_PREFIXES(SitePerProcessPermissionsPolicyBrowserTest,
danakjc492bf82020-09-09 20:02:44751 ContainerPolicyDynamic);
Charlie Hubb5943d2021-03-09 19:46:12752 FRIEND_TEST_ALL_PREFIXES(SitePerProcessPermissionsPolicyBrowserTest,
danakjc492bf82020-09-09 20:02:44753 ContainerPolicySandboxDynamic);
Yuzu Saijo03dbf9b2022-07-22 04:29:45754 FRIEND_TEST_ALL_PREFIXES(NavigationRequestTest, StorageKeyToCommit);
Arthur Sonzogni64457592022-11-22 11:08:59755 FRIEND_TEST_ALL_PREFIXES(
756 NavigationRequestTest,
757 NavigationToCredentiallessDocumentNetworkIsolationInfo);
Yuzu Saijo03dbf9b2022-07-22 04:29:45758 FRIEND_TEST_ALL_PREFIXES(RenderFrameHostImplTest,
Arthur Sonzogni64457592022-11-22 11:08:59759 ChildOfCredentiallessIsCredentialless);
Yifan Luo86a79f42022-08-16 18:38:27760 FRIEND_TEST_ALL_PREFIXES(ContentPasswordManagerDriverTest,
Arthur Sonzogni64457592022-11-22 11:08:59761 PasswordAutofillDisabledOnCredentiallessIframe);
danakjc492bf82020-09-09 20:02:44762
Dominic Farolino8a2187b2021-12-24 20:44:21763 // Called by the destructor. When `this` is an outer dummy FrameTreeNode
764 // representing an inner FrameTree, this method destroys said inner FrameTree.
765 void DestroyInnerFrameTreeIfExists();
766
danakjc492bf82020-09-09 20:02:44767 class OpenerDestroyedObserver;
768
danakjc492bf82020-09-09 20:02:44769 // The |notification_type| parameter is used for histograms only.
770 bool NotifyUserActivation(
771 blink::mojom::UserActivationNotificationType notification_type);
772
773 bool ConsumeTransientUserActivation();
774
775 bool ClearUserActivation();
776
777 // Verify that the renderer process is allowed to set user activation on this
778 // frame by checking whether this frame's RenderWidgetHost had previously seen
779 // an input event that might lead to user activation. If user activation
780 // should be allowed, this returns true and also clears corresponding pending
781 // user activation state in the widget. Otherwise, this returns false.
782 bool VerifyUserActivation();
783
Xiaochen Zhou90858e82023-05-31 15:47:37784 // See comments for `GetFencedFrameProperties()`.
785 absl::optional<FencedFrameProperties>& GetFencedFramePropertiesForEditing(
Xiaochen Zhou86f2e712023-09-13 19:55:04786 FencedFramePropertiesNodeSource node_source =
787 FencedFramePropertiesNodeSource::kClosestAncestor);
Liam Brady6da2cc9e2023-01-30 17:09:43788
Mingyu Lei7956b8b2023-07-24 08:24:08789 // See `RestartBackForwardCachedNavigationAsync()`.
790 void RestartBackForwardCachedNavigationImpl(int nav_entry_id);
791
danakjc492bf82020-09-09 20:02:44792 // The next available browser-global FrameTreeNode ID.
793 static int next_frame_tree_node_id_;
794
Arthur Sonzognif6785ec2022-12-05 10:11:50795 // The FrameTree owning |this|. It can change with Prerender2 during
796 // activation.
797 raw_ref<FrameTree> frame_tree_;
danakjc492bf82020-09-09 20:02:44798
danakjc492bf82020-09-09 20:02:44799 // A browser-global identifier for the frame in the page, which stays stable
800 // even if the frame does a cross-process navigation.
801 const int frame_tree_node_id_;
802
803 // The RenderFrameHost owning this FrameTreeNode, which cannot change for the
804 // life of this FrameTreeNode. |nullptr| if this node is the root.
Keishi Hattori0e45c022021-11-27 09:25:52805 const raw_ptr<RenderFrameHostImpl> parent_;
danakjc492bf82020-09-09 20:02:44806
danakjc492bf82020-09-09 20:02:44807 // The frame that opened this frame, if any. Will be set to null if the
808 // opener is closed, or if this frame disowns its opener by setting its
809 // window.opener to null.
Keishi Hattori0e45c022021-11-27 09:25:52810 raw_ptr<FrameTreeNode> opener_ = nullptr;
danakjc492bf82020-09-09 20:02:44811
812 // An observer that clears this node's |opener_| if the opener is destroyed.
813 // This observer is added to the |opener_|'s observer list when the |opener_|
814 // is set to a non-null node, and it is removed from that list when |opener_|
815 // changes or when this node is destroyed. It is also cleared if |opener_|
816 // is disowned.
817 std::unique_ptr<OpenerDestroyedObserver> opener_observer_;
818
Rakina Zata Amni3a48ae42022-05-05 03:39:56819 // Unlike `opener_`, the "original opener chain" doesn't reflect
820 // window.opener, which can be suppressed or updated. The "original opener"
821 // is the main frame of the actual opener of this frame. This traces the all
822 // the way back, so if the original opener was closed (deleted or severed due
823 // to COOP), but _it_ had an original opener, this will return the original
824 // opener's original opener, etc. So this value will always be set as long as
825 // there is at least one live frame in the chain whose connection is not
826 // severed due to COOP.
827 raw_ptr<FrameTreeNode> first_live_main_frame_in_original_opener_chain_ =
828 nullptr;
danakjc492bf82020-09-09 20:02:44829
Wolfgang Beyerd8809db2020-09-30 15:29:39830 // The devtools frame token of the frame which opened this frame. This is
831 // not cleared even if the opener is destroyed or disowns the frame.
Anton Bikineevf62d1bf2021-05-15 17:56:07832 absl::optional<base::UnguessableToken> opener_devtools_frame_token_;
Wolfgang Beyerd8809db2020-09-30 15:29:39833
Rakina Zata Amni3a48ae42022-05-05 03:39:56834 // An observer that updates this node's
835 // |first_live_main_frame_in_original_opener_chain_| to the next original
836 // opener in the chain if the original opener is destroyed.
danakjc492bf82020-09-09 20:02:44837 std::unique_ptr<OpenerDestroyedObserver> original_opener_observer_;
838
arthursonzogni034bb9c2020-10-01 08:29:56839 // When created by an opener, the URL specified in window.open(url)
840 // Please refer to {Get,Set}InitialPopupURL() documentation.
841 GURL initial_popup_url_;
842
843 // When created using window.open, the origin of the creator.
844 // Please refer to {Get,Set}PopupCreatorOrigin() documentation.
845 url::Origin popup_creator_origin_;
846
W. James MacLean81b8d01f2022-01-25 20:50:59847 // If the url from the the last BeginNavigation is about:srcdoc, this value
848 // stores the srcdoc_attribute's value for re-use in history navigations.
849 std::string srcdoc_value_;
850
danakjc492bf82020-09-09 20:02:44851 // Whether the frame's owner element in the parent document is collapsed.
arthursonzogni9816b9192021-03-29 16:09:19852 bool is_collapsed_ = false;
danakjc492bf82020-09-09 20:02:44853
Daniel Cheng6ac128172021-05-25 18:49:01854 // The type of frame owner for this frame. This is only relevant for non-main
855 // frames.
Kevin McNee43fe8292021-10-04 22:59:41856 const blink::FrameOwnerElementType frame_owner_element_type_ =
857 blink::FrameOwnerElementType::kNone;
Daniel Cheng9bd90f92021-04-23 20:49:45858
Daniel Cheng6ac128172021-05-25 18:49:01859 // The tree scope type of frame owner element, i.e. whether the element is in
860 // the document tree (https://dom.spec.whatwg.org/#document-trees) or the
861 // shadow tree (https://dom.spec.whatwg.org/#shadow-trees). This is only
862 // relevant for non-main frames.
863 const blink::mojom::TreeScopeType tree_scope_type_ =
864 blink::mojom::TreeScopeType::kDocument;
865
danakjc492bf82020-09-09 20:02:44866 // Track the pending sandbox flags and container policy for this frame. When a
867 // parent frame dynamically updates 'sandbox', 'allow', 'allowfullscreen',
868 // 'allowpaymentrequest' or 'src' attributes, the updated policy for the frame
Harkiran Bolaria4eacb3a2021-12-13 20:03:47869 // is stored here, and transferred into
870 // render_manager_.current_replication_state().frame_policy when they take
871 // effect on the next frame navigation.
danakjc492bf82020-09-09 20:02:44872 blink::FramePolicy pending_frame_policy_;
873
874 // Whether the frame was created by javascript. This is useful to prune
875 // history entries when the frame is removed (because frames created by
876 // scripts are never recreated with the same unique name - see
877 // https://crbug.com/500260).
arthursonzogni9816b9192021-03-29 16:09:19878 const bool is_created_by_script_;
danakjc492bf82020-09-09 20:02:44879
danakjc492bf82020-09-09 20:02:44880 // Tracks the scrolling and margin properties for this frame. These
881 // properties affect the child renderer but are stored on its parent's
882 // frame element. When this frame's parent dynamically updates these
883 // properties, we update them here too.
884 //
885 // Note that dynamic updates only take effect on the next frame navigation.
886 blink::mojom::FrameOwnerProperties frame_owner_properties_;
887
Yuzu Saijo03dbf9b2022-07-22 04:29:45888 // Contains the tracked HTML attributes of the corresponding iframe element,
889 // such as 'id' and 'src'.
890 blink::mojom::IframeAttributesPtr attributes_;
Antonio Sartori5abc8de2021-07-13 08:42:47891
danakjc492bf82020-09-09 20:02:44892 // Owns an ongoing NavigationRequest until it is ready to commit. It will then
893 // be reset and a RenderFrameHost will be responsible for the navigation.
894 std::unique_ptr<NavigationRequest> navigation_request_;
895
896 // List of objects observing this FrameTreeNode.
897 base::ObserverList<Observer>::Unchecked observers_;
898
899 base::TimeTicks last_focus_time_;
900
arthursonzogni9816b9192021-03-29 16:09:19901 bool was_discarded_ = false;
danakjc492bf82020-09-09 20:02:44902
Abhijeet Kandalkar3f29bc42022-09-23 12:39:58903 const FencedFrameStatus fenced_frame_status_ =
904 FencedFrameStatus::kNotNestedInFencedFrame;
Harkiran Bolaria16f2c48d2022-04-22 12:39:57905
Garrett Tanzerc69f4642022-08-15 22:15:14906 // If this is a fenced frame resulting from a urn:uuid navigation, this
907 // contains all the metadata specifying the resulting context.
Garrett Tanzer34cb92fe2022-09-28 17:50:54908 // TODO(crbug.com/1262022): Move this into the FrameTree once ShadowDOM
909 // and urn iframes are gone.
Garrett Tanzer29de7112022-12-06 21:26:32910 absl::optional<FencedFrameProperties> fenced_frame_properties_;
Garrett Tanzerc69f4642022-08-15 22:15:14911
Mingyu Lei7956b8b2023-07-24 08:24:08912 // The tracker of the task that restarts the BFCache navigation. It might be
913 // used to cancel the task.
914 // See `CancelRestartingBackForwardCacheNavigation()`.
915 base::CancelableTaskTracker restart_back_forward_cached_navigation_tracker_;
916
Lukasz Anforowicz147141962020-12-16 18:03:24917 // Manages creation and swapping of RenderFrameHosts for this frame.
918 //
919 // This field needs to be declared last, because destruction of
920 // RenderFrameHostManager may call arbitrary callbacks (e.g. via
921 // WebContentsObserver::DidFinishNavigation fired after RenderFrameHostManager
922 // destructs a RenderFrameHostImpl and its NavigationRequest). Such callbacks
923 // may try to use FrameTreeNode's fields above - this would be an undefined
924 // behavior if the fields (even trivially-destructible ones) were destructed
925 // before the RenderFrameHostManager's destructor runs. See also
926 // https://crbug.com/1157988.
927 RenderFrameHostManager render_manager_;
Mingyu Lei7956b8b2023-07-24 08:24:08928
929 base::WeakPtrFactory<FrameTreeNode> weak_factory_{this};
danakjc492bf82020-09-09 20:02:44930};
931
932} // namespace content
933
934#endif // CONTENT_BROWSER_RENDERER_HOST_FRAME_TREE_NODE_H_