blob: a43a2e3097674a4f16afd6aad113aab50040e908 [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"
Daniel Cheng390e2a72022-09-28 06:07:5318#include "content/browser/renderer_host/navigation_discard_reason.h"
danakjc492bf82020-09-09 20:02:4419#include "content/browser/renderer_host/navigator.h"
20#include "content/browser/renderer_host/render_frame_host_impl.h"
21#include "content/browser/renderer_host/render_frame_host_manager.h"
Miyoung Shin7cf88b42022-11-07 13:22:3022#include "content/browser/renderer_host/render_frame_host_owner.h"
danakjc492bf82020-09-09 20:02:4423#include "content/common/content_export.h"
Julie Jeongeun Kimf38c1eca2021-12-14 07:46:5524#include "content/public/browser/frame_type.h"
danakjc492bf82020-09-09 20:02:4425#include "services/network/public/mojom/content_security_policy.mojom-forward.h"
Julie Jeongeun Kim0e242242022-11-30 10:45:0926#include "services/network/public/mojom/referrer_policy.mojom-forward.h"
Lei Zhang698df03c2021-05-21 04:23:3427#include "third_party/abseil-cpp/absl/types/optional.h"
Kevin McNee43fe8292021-10-04 22:59:4128#include "third_party/blink/public/common/frame/frame_owner_element_type.h"
danakjc492bf82020-09-09 20:02:4429#include "third_party/blink/public/common/frame/frame_policy.h"
danakjc492bf82020-09-09 20:02:4430#include "third_party/blink/public/mojom/frame/frame_owner_properties.mojom.h"
Gyuyoung Kimc16e52e92021-03-19 02:45:3731#include "third_party/blink/public/mojom/frame/frame_replication_state.mojom-forward.h"
Daniel Cheng6ac128172021-05-25 18:49:0132#include "third_party/blink/public/mojom/frame/tree_scope_type.mojom.h"
David Sanders2c1194d92022-04-19 23:32:3233#include "third_party/blink/public/mojom/frame/user_activation_update_types.mojom-forward.h"
Miyoung Shinaf9a34362023-01-31 02:46:5134#include "third_party/blink/public/mojom/webauthn/virtual_authenticator.mojom-forward.h"
danakjc492bf82020-09-09 20:02:4435
Gabriel Charetted87f10f2022-03-31 00:44:2236#include "base/time/time.h"
danakjc492bf82020-09-09 20:02:4437#include "url/gurl.h"
38#include "url/origin.h"
39
40namespace content {
41
42class NavigationRequest;
43class RenderFrameHostImpl;
44class NavigationEntryImpl;
Paul Semel3e241042022-10-11 12:57:3145class FrameTree;
danakjc492bf82020-09-09 20:02:4446
47// When a page contains iframes, its renderer process maintains a tree structure
48// of those frames. We are mirroring this tree in the browser process. This
49// class represents a node in this tree and is a wrapper for all objects that
50// are frame-specific (as opposed to page-specific).
51//
52// Each FrameTreeNode has a current RenderFrameHost, which can change over
53// time as the frame is navigated. Any immediate subframes of the current
54// document are tracked using FrameTreeNodes owned by the current
55// RenderFrameHost, rather than as children of FrameTreeNode itself. This
56// allows subframe FrameTreeNodes to stay alive while a RenderFrameHost is
57// still alive - for example while pending deletion, after a new current
58// RenderFrameHost has replaced it.
Miyoung Shin7cf88b42022-11-07 13:22:3059class CONTENT_EXPORT FrameTreeNode : public RenderFrameHostOwner {
danakjc492bf82020-09-09 20:02:4460 public:
61 class Observer {
62 public:
63 // Invoked when a FrameTreeNode is being destroyed.
64 virtual void OnFrameTreeNodeDestroyed(FrameTreeNode* node) {}
65
66 // Invoked when a FrameTreeNode becomes focused.
67 virtual void OnFrameTreeNodeFocused(FrameTreeNode* node) {}
68
Arthur Hemerye4659282022-03-28 08:36:1569 // Invoked when a FrameTreeNode moves to a different BrowsingInstance and
70 // the popups it opened should be disowned.
71 virtual void OnFrameTreeNodeDisownedOpenee(FrameTreeNode* node) {}
72
Fergal Dalya1d569972021-03-16 03:24:5373 virtual ~Observer() = default;
danakjc492bf82020-09-09 20:02:4474 };
75
76 static const int kFrameTreeNodeInvalidId;
77
78 // Returns the FrameTreeNode with the given global |frame_tree_node_id|,
79 // regardless of which FrameTree it is in.
80 static FrameTreeNode* GloballyFindByID(int frame_tree_node_id);
81
82 // Returns the FrameTreeNode for the given |rfh|. Same as
83 // rfh->frame_tree_node(), but also supports nullptrs.
84 static FrameTreeNode* From(RenderFrameHost* rfh);
85
86 // Callers are are expected to initialize sandbox flags separately after
87 // calling the constructor.
88 FrameTreeNode(
Arthur Sonzognif6785ec2022-12-05 10:11:5089 FrameTree& frame_tree,
danakjc492bf82020-09-09 20:02:4490 RenderFrameHostImpl* parent,
Daniel Cheng6ac128172021-05-25 18:49:0191 blink::mojom::TreeScopeType tree_scope_type,
danakjc492bf82020-09-09 20:02:4492 bool is_created_by_script,
danakjc492bf82020-09-09 20:02:4493 const blink::mojom::FrameOwnerProperties& frame_owner_properties,
Kevin McNee43fe8292021-10-04 22:59:4194 blink::FrameOwnerElementType owner_type,
Dominic Farolino08662c82021-06-11 07:36:3495 const blink::FramePolicy& frame_owner);
danakjc492bf82020-09-09 20:02:4496
Peter Boström828b9022021-09-21 02:28:4397 FrameTreeNode(const FrameTreeNode&) = delete;
98 FrameTreeNode& operator=(const FrameTreeNode&) = delete;
99
Miyoung Shin7cf88b42022-11-07 13:22:30100 ~FrameTreeNode() override;
danakjc492bf82020-09-09 20:02:44101
102 void AddObserver(Observer* observer);
103 void RemoveObserver(Observer* observer);
104
Ian Vollick25a9d032022-04-12 23:20:17105 // Frame trees may be nested so it can be the case that IsMainFrame() is true,
106 // but is not the outermost main frame. In particular, !IsMainFrame() cannot
107 // be used to check if the frame is an embedded frame -- use
108 // !IsOutermostMainFrame() instead. NB: this does not escape guest views;
109 // IsOutermostMainFrame will be true for the outermost main frame in an inner
110 // guest view.
danakjc492bf82020-09-09 20:02:44111 bool IsMainFrame() const;
Arthur Hemerya06697f2023-03-14 09:20:57112 bool IsOutermostMainFrame() const;
danakjc492bf82020-09-09 20:02:44113
arthursonzogni76098e52020-11-25 14:18:45114 // Clears any state in this node which was set by the document itself (CSP &
115 // UserActivationState) and notifies proxies as appropriate. Invoked after
116 // committing navigation to a new document (since the new document comes with
117 // a fresh set of CSP).
118 // TODO(arthursonzogni): Remove this function. The frame/document must not be
119 // left temporarily with lax state.
Hiroki Nakagawaab309622021-05-19 16:38:13120 void ResetForNavigation();
danakjc492bf82020-09-09 20:02:44121
Arthur Sonzognif6785ec2022-12-05 10:11:50122 FrameTree& frame_tree() const { return frame_tree_.get(); }
Paul Semel3e241042022-10-11 12:57:31123 Navigator& navigator();
danakjc492bf82020-09-09 20:02:44124
125 RenderFrameHostManager* render_manager() { return &render_manager_; }
Alexander Timin33e2e2c12022-03-03 04:21:33126 const RenderFrameHostManager* render_manager() const {
127 return &render_manager_;
128 }
danakjc492bf82020-09-09 20:02:44129 int frame_tree_node_id() const { return frame_tree_node_id_; }
Yuzu Saijo03dbf9b2022-07-22 04:29:45130 // This reflects window.name, which is initially set to the the "name"
131 // attribute. But this won't reflect changes of 'name' attribute and instead
132 // reflect changes to the Window object's name property.
133 // This is different from IframeAttributes' name in that this will not get
134 // updated when 'name' attribute gets updated.
Harkiran Bolaria4eacb3a2021-12-13 20:03:47135 const std::string& frame_name() const {
136 return render_manager_.current_replication_state().name;
137 }
danakjc492bf82020-09-09 20:02:44138
139 const std::string& unique_name() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47140 return render_manager_.current_replication_state().unique_name;
danakjc492bf82020-09-09 20:02:44141 }
142
danakjc492bf82020-09-09 20:02:44143 size_t child_count() const { return current_frame_host()->child_count(); }
144
danakjc492bf82020-09-09 20:02:44145 RenderFrameHostImpl* parent() const { return parent_; }
146
Dave Tapuskac8de3b02021-12-03 21:51:01147 // See `RenderFrameHost::GetParentOrOuterDocument()` for
148 // documentation.
Arthur Hemerya06697f2023-03-14 09:20:57149 RenderFrameHostImpl* GetParentOrOuterDocument() const;
Dave Tapuskac8de3b02021-12-03 21:51:01150
151 // See `RenderFrameHostImpl::GetParentOrOuterDocumentOrEmbedder()` for
152 // documentation.
153 RenderFrameHostImpl* GetParentOrOuterDocumentOrEmbedder();
154
danakjc492bf82020-09-09 20:02:44155 FrameTreeNode* opener() const { return opener_; }
156
Rakina Zata Amni3a48ae42022-05-05 03:39:56157 FrameTreeNode* first_live_main_frame_in_original_opener_chain() const {
158 return first_live_main_frame_in_original_opener_chain_;
159 }
danakjc492bf82020-09-09 20:02:44160
Anton Bikineevf62d1bf2021-05-15 17:56:07161 const absl::optional<base::UnguessableToken>& opener_devtools_frame_token() {
Wolfgang Beyerd8809db2020-09-30 15:29:39162 return opener_devtools_frame_token_;
163 }
164
Julie Jeongeun Kimf38c1eca2021-12-14 07:46:55165 // Returns the type of the frame. Refer to frame_type.h for the details.
166 FrameType GetFrameType() const;
167
danakjc492bf82020-09-09 20:02:44168 // Assigns a new opener for this node and, if |opener| is non-null, registers
169 // an observer that will clear this node's opener if |opener| is ever
170 // destroyed.
171 void SetOpener(FrameTreeNode* opener);
172
173 // Assigns the initial opener for this node, and if |opener| is non-null,
174 // registers an observer that will clear this node's opener if |opener| is
175 // ever destroyed. The value set here is the root of the tree.
176 //
177 // It is not possible to change the opener once it was set.
178 void SetOriginalOpener(FrameTreeNode* opener);
179
Wolfgang Beyerd8809db2020-09-30 15:29:39180 // Assigns an opener frame id for this node. This string id is only set once
181 // and cannot be changed. It persists, even if the |opener| is destroyed. It
182 // is used for attribution in the DevTools frontend.
183 void SetOpenerDevtoolsFrameToken(
184 base::UnguessableToken opener_devtools_frame_token);
185
danakjc492bf82020-09-09 20:02:44186 FrameTreeNode* child_at(size_t index) const {
187 return current_frame_host()->child_at(index);
188 }
189
190 // Returns the URL of the last committed page in the current frame.
191 const GURL& current_url() const {
192 return current_frame_host()->GetLastCommittedURL();
193 }
194
Abhijeet Kandalkarb86993b2022-11-22 05:17:40195 // Note that the current RenderFrameHost might not exist yet when calling this
196 // during FrameTreeNode initialization. In this case the FrameTreeNode must be
197 // on the initial empty document. Refer RFHI::is_initial_empty_document for a
198 // more details.
Rakina Zata Amni86c88fa2021-11-01 01:27:30199 bool is_on_initial_empty_document() const {
Abhijeet Kandalkarb86993b2022-11-22 05:17:40200 return current_frame_host()
201 ? current_frame_host()->is_initial_empty_document()
202 : true;
Rakina Zata Amnifc4cc3d42021-06-10 09:03:56203 }
204
danakjc492bf82020-09-09 20:02:44205 // Returns whether the frame's owner element in the parent document is
206 // collapsed, that is, removed from the layout as if it did not exist, as per
207 // request by the embedder (of the content/ layer).
208 bool is_collapsed() const { return is_collapsed_; }
209
210 // Sets whether to collapse the frame's owner element in the parent document,
211 // that is, to remove it from the layout as if it did not exist, as per
212 // request by the embedder (of the content/ layer). Cannot be called for main
213 // frames.
214 //
215 // This only has an effect for <iframe> owner elements, and is a no-op when
216 // called on sub-frames hosted in <frame>, <object>, and <embed> elements.
217 void SetCollapsed(bool collapsed);
218
219 // Returns the origin of the last committed page in this frame.
220 // WARNING: To get the last committed origin for a particular
221 // RenderFrameHost, use RenderFrameHost::GetLastCommittedOrigin() instead,
222 // which will behave correctly even when the RenderFrameHost is not the
223 // current one for this frame (such as when it's pending deletion).
224 const url::Origin& current_origin() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47225 return render_manager_.current_replication_state().origin;
danakjc492bf82020-09-09 20:02:44226 }
227
danakjc492bf82020-09-09 20:02:44228 // Returns the latest frame policy (sandbox flags and container policy) for
229 // this frame. This includes flags inherited from parent frames and the latest
230 // flags from the <iframe> element hosting this frame. The returned policies
231 // may not yet have taken effect, since "sandbox" and "allow" attribute
Liam Brady25a14162022-12-02 15:25:57232 // updates in an <iframe> element take effect on next navigation. For
233 // <fencedframe> elements, not everything in the frame policy might actually
234 // take effect after the navigation. To retrieve the currently active policy
235 // for this frame, use effective_frame_policy().
danakjc492bf82020-09-09 20:02:44236 const blink::FramePolicy& pending_frame_policy() const {
237 return pending_frame_policy_;
238 }
239
240 // Update this frame's sandbox flags and container policy. This is called
241 // when a parent frame updates the "sandbox" attribute in the <iframe> element
242 // for this frame, or any of the attributes which affect the container policy
243 // ("allowfullscreen", "allowpaymentrequest", "allow", and "src".)
244 // These policies won't take effect until next navigation. If this frame's
245 // parent is itself sandboxed, the parent's sandbox flags are combined with
246 // those in |frame_policy|.
247 // Attempting to change the container policy on the main frame will have no
248 // effect.
249 void SetPendingFramePolicy(blink::FramePolicy frame_policy);
250
251 // Returns the currently active frame policy for this frame, including the
252 // sandbox flags which were present at the time the document was loaded, and
Charlie Hu5130d25e2021-03-05 21:53:39253 // the permissions policy container policy, which is set by the iframe's
danakjc492bf82020-09-09 20:02:44254 // allowfullscreen, allowpaymentrequest, and allow attributes, along with the
255 // origin of the iframe's src attribute (which may be different from the URL
256 // of the document currently loaded into the frame). This does not include
257 // policy changes that have been made by updating the containing iframe
258 // element attributes since the frame was last navigated; use
259 // pending_frame_policy() for those.
260 const blink::FramePolicy& effective_frame_policy() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47261 return render_manager_.current_replication_state().frame_policy;
danakjc492bf82020-09-09 20:02:44262 }
263
danakjc492bf82020-09-09 20:02:44264 const blink::mojom::FrameOwnerProperties& frame_owner_properties() {
265 return frame_owner_properties_;
266 }
267
268 void set_frame_owner_properties(
269 const blink::mojom::FrameOwnerProperties& frame_owner_properties) {
270 frame_owner_properties_ = frame_owner_properties;
271 }
272
Yuzu Saijo03dbf9b2022-07-22 04:29:45273 // Reflects the attributes of the corresponding iframe html element, such
Arthur Sonzogni64457592022-11-22 11:08:59274 // as 'credentialless', 'id', 'name' and 'src'. These values should not be
Yuzu Saijo03dbf9b2022-07-22 04:29:45275 // exposed to cross-origin renderers.
276 const network::mojom::ContentSecurityPolicy* csp_attribute() const {
277 return attributes_->parsed_csp_attribute.get();
danakjc492bf82020-09-09 20:02:44278 }
Yao Xiao9c54b3e2023-03-14 04:25:04279 // Tracks iframe's 'browsingtopics' attribute, indicating whether the
280 // navigation requests on this frame should calculate and send the
281 // `Sec-Browsing-Topics` header.
282 bool browsing_topics() const { return attributes_->browsing_topics; }
Yuzu Saijodc870f92023-01-20 03:39:11283 const absl::optional<std::string> html_id() const { return attributes_->id; }
Yuzu Saijo03dbf9b2022-07-22 04:29:45284 // This tracks iframe's 'name' attribute instead of window.name, which is
285 // tracked in FrameReplicationState. See the comment for frame_name() for
286 // more details.
Yuzu Saijodc870f92023-01-20 03:39:11287 const absl::optional<std::string> html_name() const {
288 return attributes_->name;
289 }
290 const absl::optional<std::string> html_src() const {
291 return attributes_->src;
292 }
danakjc492bf82020-09-09 20:02:44293
Yuzu Saijo03dbf9b2022-07-22 04:29:45294 void SetAttributes(blink::mojom::IframeAttributesPtr attributes);
Antonio Sartori5abc8de2021-07-13 08:42:47295
danakjc492bf82020-09-09 20:02:44296 bool HasSameOrigin(const FrameTreeNode& node) const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47297 return render_manager_.current_replication_state().origin.IsSameOriginWith(
298 node.current_replication_state().origin);
danakjc492bf82020-09-09 20:02:44299 }
300
Gyuyoung Kimc16e52e92021-03-19 02:45:37301 const blink::mojom::FrameReplicationState& current_replication_state() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47302 return render_manager_.current_replication_state();
danakjc492bf82020-09-09 20:02:44303 }
304
305 RenderFrameHostImpl* current_frame_host() const {
306 return render_manager_.current_frame_host();
307 }
308
danakjc492bf82020-09-09 20:02:44309 // Returns true if this node is in a loading state.
310 bool IsLoading() const;
Nate Chapin470dbc62023-04-25 16:34:38311 LoadingState GetLoadingState() const;
danakjc492bf82020-09-09 20:02:44312
Alex Moshchuk9b0fd822020-10-26 23:08:15313 // Returns true if this node has a cross-document navigation in progress.
314 bool HasPendingCrossDocumentNavigation() const;
315
danakjc492bf82020-09-09 20:02:44316 NavigationRequest* navigation_request() { return navigation_request_.get(); }
317
318 // Transfers the ownership of the NavigationRequest to |render_frame_host|.
319 // From ReadyToCommit to DidCommit, the NavigationRequest is owned by the
320 // RenderFrameHost that is committing the navigation.
321 void TransferNavigationRequestOwnership(
322 RenderFrameHostImpl* render_frame_host);
323
324 // Takes ownership of |navigation_request| and makes it the current
325 // NavigationRequest of this frame. This corresponds to the start of a new
326 // navigation. If there was an ongoing navigation request before calling this
327 // function, it is canceled. |navigation_request| should not be null.
Charlie Reis09952ee2022-12-08 16:35:07328 void TakeNavigationRequest(
danakjc492bf82020-09-09 20:02:44329 std::unique_ptr<NavigationRequest> navigation_request);
330
Rakina Zata Amnif8f2bb62022-11-23 05:54:32331 // Resets the navigation request owned by `this` (which shouldn't have reached
332 // the "pending commit" stage yet) and any state created by it, including the
Rakina Zata Amni33175cb92022-11-24 02:46:03333 // speculative RenderFrameHost (if there are no other navigations associated
334 // with it). Note that this does not affect navigations that have reached the
335 // "pending commit" stage, which are owned by their corresponding
336 // RenderFrameHosts instead.
Daniel Cheng390e2a72022-09-28 06:07:53337 void ResetNavigationRequest(NavigationDiscardReason reason);
338
Rakina Zata Amnif8f2bb62022-11-23 05:54:32339 // Similar to `ResetNavigationRequest()`, but keeps the state created by the
Daniel Cheng390e2a72022-09-28 06:07:53340 // NavigationRequest (e.g. speculative RenderFrameHost, loading state).
341 void ResetNavigationRequestButKeepState();
danakjc492bf82020-09-09 20:02:44342
danakjc492bf82020-09-09 20:02:44343 // The load progress for a RenderFrameHost in this node was updated to
344 // |load_progress|. This will notify the FrameTree which will in turn notify
345 // the WebContents.
346 void DidChangeLoadProgress(double load_progress);
347
348 // Called when the user directed the page to stop loading. Stops all loads
349 // happening in the FrameTreeNode. This method should be used with
350 // FrameTree::ForEach to stop all loads in the entire FrameTree.
351 bool StopLoading();
352
353 // Returns the time this frame was last focused.
354 base::TimeTicks last_focus_time() const { return last_focus_time_; }
355
356 // Called when this node becomes focused. Updates the node's last focused
357 // time and notifies observers.
358 void DidFocus();
359
360 // Called when the user closed the modal dialogue for BeforeUnload and
361 // cancelled the navigation. This should stop any load happening in the
362 // FrameTreeNode.
363 void BeforeUnloadCanceled();
364
danakjc492bf82020-09-09 20:02:44365 // Returns the sandbox flags currently in effect for this frame. This includes
366 // flags inherited from parent frames, the currently active flags from the
367 // <iframe> element hosting this frame, as well as any flags set from a
368 // Content-Security-Policy HTTP header. This does not include flags that have
369 // have been updated in an <iframe> element but have not taken effect yet; use
370 // pending_frame_policy() for those. To see the flags which will take effect
371 // on navigation (which does not include the CSP-set flags), use
372 // effective_frame_policy().
373 network::mojom::WebSandboxFlags active_sandbox_flags() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47374 return render_manager_.current_replication_state().active_sandbox_flags;
danakjc492bf82020-09-09 20:02:44375 }
376
danakjc492bf82020-09-09 20:02:44377 // Returns whether the frame received a user gesture on a previous navigation
378 // on the same eTLD+1.
379 bool has_received_user_gesture_before_nav() const {
Harkiran Bolaria4eacb3a2021-12-13 20:03:47380 return render_manager_.current_replication_state()
381 .has_received_user_gesture_before_nav;
danakjc492bf82020-09-09 20:02:44382 }
383
384 // When a tab is discarded, WebContents sets was_discarded on its
385 // root FrameTreeNode.
386 // In addition, when a child frame is created, this bit is passed on from
387 // parent to child.
388 // When a navigation request is created, was_discarded is passed on to the
389 // request and reset to false in FrameTreeNode.
390 void set_was_discarded() { was_discarded_ = true; }
391 bool was_discarded() const { return was_discarded_; }
392
Miyoung Shin8a66ec022022-11-28 23:50:09393 // Deprecated. Use directly HasStickyUserActivation in RFHI.
danakjc492bf82020-09-09 20:02:44394 // Returns the sticky bit of the User Activation v2 state of the
395 // |FrameTreeNode|.
396 bool HasStickyUserActivation() const {
Miyoung Shin8a66ec022022-11-28 23:50:09397 return current_frame_host()->HasStickyUserActivation();
danakjc492bf82020-09-09 20:02:44398 }
399
Miyoung Shin8a66ec022022-11-28 23:50:09400 // Deprecated. Use directly HasStickyUserActivation in RFHI.
danakjc492bf82020-09-09 20:02:44401 // Returns the transient bit of the User Activation v2 state of the
402 // |FrameTreeNode|.
403 bool HasTransientUserActivation() {
Miyoung Shin8a66ec022022-11-28 23:50:09404 return current_frame_host()->HasTransientUserActivation();
danakjc492bf82020-09-09 20:02:44405 }
406
407 // Remove history entries for all frames created by script in this frame's
408 // subtree. If a frame created by a script is removed, then its history entry
409 // will never be reused - this saves memory.
410 void PruneChildFrameNavigationEntries(NavigationEntryImpl* entry);
411
Abhijeet Kandalkarb43affa72022-09-27 16:48:01412 using FencedFrameStatus = RenderFrameHostImpl::FencedFrameStatus;
Abhijeet Kandalkar3f29bc42022-09-23 12:39:58413 FencedFrameStatus fenced_frame_status() const { return fenced_frame_status_; }
414
Kevin McNee43fe8292021-10-04 22:59:41415 blink::FrameOwnerElementType frame_owner_element_type() const {
Daniel Cheng9bd90f92021-04-23 20:49:45416 return frame_owner_element_type_;
danakjc492bf82020-09-09 20:02:44417 }
danakjc492bf82020-09-09 20:02:44418
Daniel Cheng6ac128172021-05-25 18:49:01419 blink::mojom::TreeScopeType tree_scope_type() const {
420 return tree_scope_type_;
421 }
422
arthursonzogni034bb9c2020-10-01 08:29:56423 // The initial popup URL for new window opened using:
424 // `window.open(initial_popup_url)`.
425 // An empty GURL otherwise.
426 //
427 // [WARNING] There is no guarantee the FrameTreeNode will ever host a
428 // document served from this URL. The FrameTreeNode always starts hosting the
429 // initial empty document and attempts a navigation toward this URL. However
430 // the navigation might be delayed, redirected and even cancelled.
431 void SetInitialPopupURL(const GURL& initial_popup_url);
432 const GURL& initial_popup_url() const { return initial_popup_url_; }
433
434 // The origin of the document that used window.open() to create this frame.
435 // Otherwise, an opaque Origin with a nonce different from all previously
436 // existing Origins.
437 void SetPopupCreatorOrigin(const url::Origin& popup_creator_origin);
438 const url::Origin& popup_creator_origin() const {
439 return popup_creator_origin_;
440 }
441
Harkiran Bolaria59290d62021-03-17 01:53:01442 // Sets the associated FrameTree for this node. The node can change FrameTrees
Domenic Denicola7767a9c2023-07-13 15:36:39443 // as part of prerendering, which allows a page loaded in the prerendered
444 // FrameTree to be used for a navigation in the primary frame tree.
Harkiran Bolaria59290d62021-03-17 01:53:01445 void SetFrameTree(FrameTree& frame_tree);
446
Alexander Timin074cd182022-03-23 18:11:22447 using TraceProto = perfetto::protos::pbzero::FrameTreeNodeInfo;
Alexander Timinf785f342021-03-18 00:00:56448 // Write a representation of this object into a trace.
Alexander Timin074cd182022-03-23 18:11:22449 void WriteIntoTrace(perfetto::TracedProto<TraceProto> proto) const;
Alexander Timinf785f342021-03-18 00:00:56450
Carlos Caballero76711352021-03-24 17:38:21451 // Returns true the node is navigating, i.e. it has an associated
452 // NavigationRequest.
453 bool HasNavigation();
454
shivanigithubf3ddff52021-07-03 22:06:30455 // Fenced frames (meta-bug crbug.com/1111084):
shivanigithub4cd016a2021-09-20 21:10:30456 // Note that these two functions cannot be invoked from a FrameTree's or
457 // its root node's constructor since they require the frame tree and the
458 // root node to be completely constructed.
459 //
shivanigithubf3ddff52021-07-03 22:06:30460 // Returns false if fenced frames are disabled. Returns true if the feature is
461 // enabled and if |this| is a fenced frame. Returns false for
462 // iframes embedded in a fenced frame. To clarify: for the MPArch
463 // implementation this only returns true if |this| is the actual
464 // root node of the inner FrameTree and not the proxy FrameTreeNode in the
465 // outer FrameTree.
Dominic Farolino4bc10ee2021-08-31 00:37:36466 bool IsFencedFrameRoot() const;
shivanigithubf3ddff52021-07-03 22:06:30467
468 // Returns false if fenced frames are disabled. Returns true if the
469 // feature is enabled and if |this| or any of its ancestor nodes is a
470 // fenced frame.
471 bool IsInFencedFrameTree() const;
472
shivanigithub4cd016a2021-09-20 21:10:30473 // Returns a valid nonce if `IsInFencedFrameTree()` returns true for `this`.
Garrett Tanzer34cb92fe2022-09-28 17:50:54474 // Returns nullopt otherwise.
475 //
476 // Nonce used in the net::IsolationInfo and blink::StorageKey for a fenced
477 // frame and any iframes nested within it. Not set if this frame is not in a
478 // fenced frame's FrameTree. Note that this could be a field in FrameTree for
479 // the MPArch version but for the shadow DOM version we need to keep it here
480 // since the fenced frame root is not a main frame for the latter. The value
481 // of the nonce will be the same for all of the the iframes inside a fenced
482 // frame tree. If there is a nested fenced frame it will have a different
483 // nonce than its parent fenced frame. The nonce will stay the same across
484 // navigations initiated from the fenced frame tree because it is always used
485 // in conjunction with other fields of the keys and would be good to access
486 // the same storage across same-origin navigations. If the navigation is
487 // same-origin/site then the same network stack partition/storage will be
488 // reused and if it's cross-origin/site then other parts of the key will
489 // change and so, even with the same nonce, another partition will be used.
490 // But if the navigation is initiated from the embedder, the nonce will be
491 // reinitialized irrespective of same or cross origin such that there is no
492 // privacy leak via storage shared between two embedder initiated navigations.
493 // Note that this reinitialization is implemented for all embedder-initiated
494 // navigations in MPArch, but only urn:uuid navigations in ShadowDOM.
495 absl::optional<base::UnguessableToken> GetFencedFrameNonce();
shivanigithub4cd016a2021-09-20 21:10:30496
Garrett Tanzer34cb92fe2022-09-28 17:50:54497 // If applicable, initialize the default fenced frame properties. Right now,
498 // this means setting a new fenced frame nonce. See comment on
shivanigithub4cd016a2021-09-20 21:10:30499 // fenced_frame_nonce() for when it is set to a non-null value. Invoked
500 // by FrameTree::Init() or FrameTree::AddFrame().
Garrett Tanzer34cb92fe2022-09-28 17:50:54501 void SetFencedFramePropertiesIfNeeded();
shivanigithub4cd016a2021-09-20 21:10:30502
Garrett Tanzer291a2d52023-03-20 22:41:57503 // Set the current FencedFrameProperties to have "opaque ads mode".
504 // This should only be used during tests, when the proper embedder-initiated
505 // fenced frame root urn/config navigation flow isn't available.
506 // TODO(crbug.com/1347953): Refactor and expand use of test utils so there is
507 // a consistent way to do this properly everywhere. Consider removing
508 // arbitrary restrictions in "default mode" so that using opaque ads mode is
509 // less necessary.
510 void SetFencedFramePropertiesOpaqueAdsModeForTesting() {
511 if (fenced_frame_properties_.has_value()) {
512 fenced_frame_properties_->mode_ =
513 blink::FencedFrame::DeprecatedFencedFrameMode::kOpaqueAds;
514 }
515 }
516
517 // Returns the mode attribute from the `FencedFrameProperties` if this frame
518 // is in a fenced frame tree, otherwise returns `kDefault`.
519 blink::FencedFrame::DeprecatedFencedFrameMode GetDeprecatedFencedFrameMode();
Nan Lin171fe9a2022-02-17 16:42:16520
Dave Tapuskac8de3b02021-12-03 21:51:01521 // Helper for GetParentOrOuterDocument/GetParentOrOuterDocumentOrEmbedder.
522 // Do not use directly.
Kevin McNee86e64ee2023-02-17 16:35:50523 // `escape_guest_view` determines whether to iterate out of guest views and is
524 // the behaviour distinction between GetParentOrOuterDocument and
525 // GetParentOrOuterDocumentOrEmbedder. See the comment on
526 // GetParentOrOuterDocumentOrEmbedder for details.
527 // `include_prospective` includes embedders which own our frame tree, but have
528 // not yet attached it to the outer frame tree.
Arthur Hemerya06697f2023-03-14 09:20:57529 RenderFrameHostImpl* GetParentOrOuterDocumentHelper(
530 bool escape_guest_view,
531 bool include_prospective) const;
Dave Tapuskac8de3b02021-12-03 21:51:01532
Harkiran Bolariab4437fd2021-08-11 17:51:22533 // Sets the unique_name and name fields on replication_state_. To be used in
534 // prerender activation to make sure the FrameTreeNode replication state is
535 // correct after the RenderFrameHost is moved between FrameTreeNodes. The
536 // renderers should already have the correct value, so unlike
537 // FrameTreeNode::SetFrameName, we do not notify them here.
Harkiran Bolaria4eacb3a2021-12-13 20:03:47538 // TODO(https://crbug.com/1237091): Remove this once the BrowsingContextState
539 // is implemented to utilize the new path.
Harkiran Bolariab4437fd2021-08-11 17:51:22540 void set_frame_name_for_activation(const std::string& unique_name,
541 const std::string& name) {
Harkiran Bolaria0b3bdef02022-03-10 13:04:40542 current_frame_host()->browsing_context_state()->set_frame_name(unique_name,
543 name);
Harkiran Bolariab4437fd2021-08-11 17:51:22544 }
545
Nan Linaaf84f72021-12-02 22:31:56546 // Returns true if error page isolation is enabled.
547 bool IsErrorPageIsolationEnabled() const;
548
W. James MacLean81b8d01f2022-01-25 20:50:59549 // Functions to store and retrieve a frame's srcdoc value on this
550 // FrameTreeNode.
551 void SetSrcdocValue(const std::string& srcdoc_value);
552 const std::string& srcdoc_value() const { return srcdoc_value_; }
553
Garrett Tanzerc69f4642022-08-15 22:15:14554 void set_fenced_frame_properties(
Garrett Tanzer29de7112022-12-06 21:26:32555 const absl::optional<FencedFrameProperties>& fenced_frame_properties) {
Garrett Tanzer2975eeac2022-08-22 16:34:01556 // TODO(crbug.com/1262022): Reenable this DCHECK once ShadowDOM and
557 // loading urns in iframes (for FLEDGE OT) are gone.
558 // DCHECK_EQ(fenced_frame_status_,
559 // RenderFrameHostImpl::FencedFrameStatus::kFencedFrameRoot);
Garrett Tanzerc69f4642022-08-15 22:15:14560 fenced_frame_properties_ = fenced_frame_properties;
561 }
562
Xiaochen Zhou90858e82023-05-31 15:47:37563 // By default, this function checks the fenced frame root's properties if one
564 // exists, and then otherwise traverses the frame tree to find urn iframe
565 // roots. This doesn't work correctly for urn iframes nested inside of fenced
566 // frames. Enable `force_tree_traversal` to skip the fenced frame root short
567 // circuit and always traverse the tree.
568 // TODO(crbug.com/1355857): This function has the correct semantics when
569 // `force_tree_traversal` is set to true. It is set to false for urn iframes
570 // nested in fenced frames to work correctly in some cases. For example,
571 // storage partitioning. Once those issues are resolved, remove this parameter
572 // entirely.
573 const absl::optional<FencedFrameProperties>& GetFencedFrameProperties(
574 bool force_tree_traversal = false);
Garrett Tanzerc69f4642022-08-15 22:15:14575
Liam Brady6da2cc9e2023-01-30 17:09:43576 // Called from the currently active document via the
577 // `Fence.setReportEventDataForAutomaticBeacons` JS API.
578 void SetFencedFrameAutomaticBeaconReportEventData(
579 const std::string& event_data,
Nan Lindbce6e32023-05-10 22:42:55580 const std::vector<blink::FencedFrame::ReportingDestination>& destinations,
581 network::AttributionReportingRuntimeFeatures
582 attribution_reporting_runtime_features) override;
Liam Brady6da2cc9e2023-01-30 17:09:43583
Yao Xiaof9ae90a2023-03-01 20:52:44584 // Returns the number of fenced frame boundaries above this frame. The
Yao Xiaoa2337ad2022-10-12 20:59:29585 // outermost main frame's frame tree has fenced frame depth 0, a topmost
586 // fenced frame tree embedded in the outermost main frame has fenced frame
587 // depth 1, etc.
Yao Xiaof9ae90a2023-03-01 20:52:44588 //
589 // Also, sets `shared_storage_fenced_frame_root_count` to the
590 // number of fenced frame boundaries (roots) above this frame that originate
591 // from shared storage. This is used to check whether a fenced frame
592 // originates from shared storage only (i.e. not from FLEDGE).
593 // TODO(crbug.com/1347953): Remove this check once we put permissions inside
594 // FencedFrameConfig.
595 size_t GetFencedFrameDepth(size_t& shared_storage_fenced_frame_root_count);
Yao Xiaoa2337ad2022-10-12 20:59:29596
597 // Traverse up from this node. Return all valid
598 // `node->fenced_frame_properties_->shared_storage_budget_metadata` (i.e. this
599 // node is subjected to the shared storage budgeting associated with those
600 // metadata). Every node that originates from sharedStorage.selectURL() will
601 // have an associated metadata. This indicates that the metadata can only
602 // possibly be associated with a fenced frame root, unless when
603 // `kAllowURNsInIframes` is enabled in which case they could be be associated
604 // with any node.
Garrett Tanzer29de7112022-12-06 21:26:32605 std::vector<const SharedStorageBudgetMetadata*>
Yao Xiao1ac702d2022-06-08 17:20:49606 FindSharedStorageBudgetMetadata();
607
Camillia Smith Barnes7218518c2023-03-06 19:02:17608 // Returns any shared storage context string that was written to a
609 // `blink::FencedFrameConfig` before navigation via
610 // `setSharedStorageContext()`, as long as the request is for a same-origin
611 // frame within the config's fenced frame tree (or a same-origin descendant of
612 // a URN iframe).
613 absl::optional<std::u16string> GetEmbedderSharedStorageContextIfAllowed();
614
Harkiran Bolariaebbe7702022-02-22 19:19:03615 // Accessor to BrowsingContextState for subframes only. Only main frame
616 // navigations can change BrowsingInstances and BrowsingContextStates,
617 // therefore for subframes associated BrowsingContextState never changes. This
618 // helper method makes this more explicit and guards against calling this on
619 // main frames (there an appropriate BrowsingContextState should be obtained
620 // from RenderFrameHost or from RenderFrameProxyHost as e.g. during
621 // cross-BrowsingInstance navigations multiple BrowsingContextStates exist in
622 // the same frame).
623 const scoped_refptr<BrowsingContextState>&
624 GetBrowsingContextStateForSubframe() const;
625
Arthur Hemerye4659282022-03-28 08:36:15626 // Clears the opener property of popups referencing this FrameTreeNode as
627 // their opener.
628 void ClearOpenerReferences();
629
Liam Brady95d36d12023-03-13 21:13:06630 // Calculates whether one of the ancestor frames or this frame has a CSPEE in
631 // place. This is eventually sent over to LocalFrame in the renderer where it
632 // will be used by NavigatorAuction::canLoadAdAuctionFencedFrame for
633 // information it can't get on its own.
Liam Bradyd2a41e152022-07-19 13:58:48634 bool AncestorOrSelfHasCSPEE() const;
635
Arthur Sonzogni8e8eb1f2023-01-10 14:51:01636 // Reset every navigation in this frame, and its descendants. This is called
637 // after the <iframe> element has been removed, or after the document owning
638 // this frame has been navigated away.
639 //
640 // This takes into account:
641 // - Non-pending commit NavigationRequest owned by the FrameTreeNode
642 // - Pending commit NavigationRequest owned by the current RenderFrameHost
643 // - Speculative RenderFrameHost and its pending commit NavigationRequests.
644 void ResetAllNavigationsForFrameDetach();
645
Miyoung Shin7cf88b42022-11-07 13:22:30646 // RenderFrameHostOwner implementation:
Nate Chapin470dbc62023-04-25 16:34:38647 void DidStartLoading(LoadingState previous_frame_tree_loading_state) override;
Julie Jeongeun Kim07c077bd2022-12-05 08:40:31648 void DidStopLoading() override;
Miyoung Shin7cf88b42022-11-07 13:22:30649 void RestartNavigationAsCrossDocument(
650 std::unique_ptr<NavigationRequest> navigation_request) override;
Miyoung Shin1504eb712022-12-07 10:32:18651 bool Reload() override;
Julie Jeongeun Kimc1b07c32022-11-11 10:26:32652 Navigator& GetCurrentNavigator() override;
Miyoung Shine16cd2262022-11-30 05:52:16653 RenderFrameHostManager& GetRenderFrameHostManager() override;
Miyoung Shin64fd1bea2023-01-04 04:22:08654 FrameTreeNode* GetOpener() const override;
Julie Jeongeun Kim2132b37f82022-11-23 08:30:46655 void SetFocusedFrame(SiteInstanceGroup* source) override;
Julie Jeongeun Kim0e242242022-11-30 10:45:09656 void DidChangeReferrerPolicy(
657 network::mojom::ReferrerPolicy referrer_policy) override;
Miyoung Shin7cf88b42022-11-07 13:22:30658
Miyoung Shin8a66ec022022-11-28 23:50:09659 // Updates the user activation state in the browser frame tree and in the
660 // frame trees in all renderer processes except the renderer for this node
661 // (which initiated the update). Returns |false| if the update tries to
662 // consume an already consumed/expired transient state, |true| otherwise. See
663 // the comment on `user_activation_state_` in RenderFrameHostImpl.
664 //
665 // The |notification_type| parameter is used for histograms, only for the case
666 // |update_state == kNotifyActivation|.
667 bool UpdateUserActivationState(
668 blink::mojom::UserActivationUpdateType update_type,
669 blink::mojom::UserActivationNotificationType notification_type) override;
670
Nate Chapin47276a62023-02-16 16:53:44671 void DidConsumeHistoryUserActivation() override;
672
Miyoung Shinff13ed22022-11-30 09:21:47673 std::unique_ptr<NavigationRequest>
674 CreateNavigationRequestForSynchronousRendererCommit(
675 RenderFrameHostImpl* render_frame_host,
676 bool is_same_document,
677 const GURL& url,
678 const url::Origin& origin,
W. James MacLean23e90a12022-12-21 04:38:21679 const absl::optional<GURL>& initiator_base_url,
Miyoung Shinff13ed22022-11-30 09:21:47680 const net::IsolationInfo& isolation_info_for_subresources,
681 blink::mojom::ReferrerPtr referrer,
682 const ui::PageTransition& transition,
683 bool should_replace_current_entry,
684 const std::string& method,
685 bool has_transient_activation,
686 bool is_overriding_user_agent,
687 const std::vector<GURL>& redirects,
688 const GURL& original_url,
689 std::unique_ptr<CrossOriginEmbedderPolicyReporter> coep_reporter,
Miyoung Shinff13ed22022-11-30 09:21:47690 int http_response_code) override;
Miyoung Shinb5561802022-12-01 08:21:35691 void CancelNavigation() override;
Miyoung Shinc9ff4812023-01-05 08:58:05692 bool Credentialless() const override;
Miyoung Shinaf9a34362023-01-31 02:46:51693#if !BUILDFLAG(IS_ANDROID)
694 void GetVirtualAuthenticatorManager(
695 mojo::PendingReceiver<blink::test::mojom::VirtualAuthenticatorManager>
696 receiver) override;
697#endif
Miyoung Shinff13ed22022-11-30 09:21:47698
danakjc492bf82020-09-09 20:02:44699 private:
Yuzu Saijo03dbf9b2022-07-22 04:29:45700 friend class CSPEmbeddedEnforcementUnitTest;
Charlie Hubb5943d2021-03-09 19:46:12701 FRIEND_TEST_ALL_PREFIXES(SitePerProcessPermissionsPolicyBrowserTest,
danakjc492bf82020-09-09 20:02:44702 ContainerPolicyDynamic);
Charlie Hubb5943d2021-03-09 19:46:12703 FRIEND_TEST_ALL_PREFIXES(SitePerProcessPermissionsPolicyBrowserTest,
danakjc492bf82020-09-09 20:02:44704 ContainerPolicySandboxDynamic);
Yuzu Saijo03dbf9b2022-07-22 04:29:45705 FRIEND_TEST_ALL_PREFIXES(NavigationRequestTest, StorageKeyToCommit);
Arthur Sonzogni64457592022-11-22 11:08:59706 FRIEND_TEST_ALL_PREFIXES(
707 NavigationRequestTest,
708 NavigationToCredentiallessDocumentNetworkIsolationInfo);
Yuzu Saijo03dbf9b2022-07-22 04:29:45709 FRIEND_TEST_ALL_PREFIXES(RenderFrameHostImplTest,
Arthur Sonzogni64457592022-11-22 11:08:59710 ChildOfCredentiallessIsCredentialless);
Yifan Luo86a79f42022-08-16 18:38:27711 FRIEND_TEST_ALL_PREFIXES(ContentPasswordManagerDriverTest,
Arthur Sonzogni64457592022-11-22 11:08:59712 PasswordAutofillDisabledOnCredentiallessIframe);
danakjc492bf82020-09-09 20:02:44713
Dominic Farolino8a2187b2021-12-24 20:44:21714 // Called by the destructor. When `this` is an outer dummy FrameTreeNode
715 // representing an inner FrameTree, this method destroys said inner FrameTree.
716 void DestroyInnerFrameTreeIfExists();
717
danakjc492bf82020-09-09 20:02:44718 class OpenerDestroyedObserver;
719
danakjc492bf82020-09-09 20:02:44720 // The |notification_type| parameter is used for histograms only.
721 bool NotifyUserActivation(
722 blink::mojom::UserActivationNotificationType notification_type);
723
724 bool ConsumeTransientUserActivation();
725
726 bool ClearUserActivation();
727
728 // Verify that the renderer process is allowed to set user activation on this
729 // frame by checking whether this frame's RenderWidgetHost had previously seen
730 // an input event that might lead to user activation. If user activation
731 // should be allowed, this returns true and also clears corresponding pending
732 // user activation state in the widget. Otherwise, this returns false.
733 bool VerifyUserActivation();
734
Xiaochen Zhou90858e82023-05-31 15:47:37735 // See comments for `GetFencedFrameProperties()`.
736 absl::optional<FencedFrameProperties>& GetFencedFramePropertiesForEditing(
737 bool force_tree_traversal = false);
Liam Brady6da2cc9e2023-01-30 17:09:43738
danakjc492bf82020-09-09 20:02:44739 // The next available browser-global FrameTreeNode ID.
740 static int next_frame_tree_node_id_;
741
Arthur Sonzognif6785ec2022-12-05 10:11:50742 // The FrameTree owning |this|. It can change with Prerender2 during
743 // activation.
744 raw_ref<FrameTree> frame_tree_;
danakjc492bf82020-09-09 20:02:44745
danakjc492bf82020-09-09 20:02:44746 // A browser-global identifier for the frame in the page, which stays stable
747 // even if the frame does a cross-process navigation.
748 const int frame_tree_node_id_;
749
750 // The RenderFrameHost owning this FrameTreeNode, which cannot change for the
751 // life of this FrameTreeNode. |nullptr| if this node is the root.
Keishi Hattori0e45c022021-11-27 09:25:52752 const raw_ptr<RenderFrameHostImpl> parent_;
danakjc492bf82020-09-09 20:02:44753
danakjc492bf82020-09-09 20:02:44754 // The frame that opened this frame, if any. Will be set to null if the
755 // opener is closed, or if this frame disowns its opener by setting its
756 // window.opener to null.
Keishi Hattori0e45c022021-11-27 09:25:52757 raw_ptr<FrameTreeNode> opener_ = nullptr;
danakjc492bf82020-09-09 20:02:44758
759 // An observer that clears this node's |opener_| if the opener is destroyed.
760 // This observer is added to the |opener_|'s observer list when the |opener_|
761 // is set to a non-null node, and it is removed from that list when |opener_|
762 // changes or when this node is destroyed. It is also cleared if |opener_|
763 // is disowned.
764 std::unique_ptr<OpenerDestroyedObserver> opener_observer_;
765
Rakina Zata Amni3a48ae42022-05-05 03:39:56766 // Unlike `opener_`, the "original opener chain" doesn't reflect
767 // window.opener, which can be suppressed or updated. The "original opener"
768 // is the main frame of the actual opener of this frame. This traces the all
769 // the way back, so if the original opener was closed (deleted or severed due
770 // to COOP), but _it_ had an original opener, this will return the original
771 // opener's original opener, etc. So this value will always be set as long as
772 // there is at least one live frame in the chain whose connection is not
773 // severed due to COOP.
774 raw_ptr<FrameTreeNode> first_live_main_frame_in_original_opener_chain_ =
775 nullptr;
danakjc492bf82020-09-09 20:02:44776
Wolfgang Beyerd8809db2020-09-30 15:29:39777 // The devtools frame token of the frame which opened this frame. This is
778 // not cleared even if the opener is destroyed or disowns the frame.
Anton Bikineevf62d1bf2021-05-15 17:56:07779 absl::optional<base::UnguessableToken> opener_devtools_frame_token_;
Wolfgang Beyerd8809db2020-09-30 15:29:39780
Rakina Zata Amni3a48ae42022-05-05 03:39:56781 // An observer that updates this node's
782 // |first_live_main_frame_in_original_opener_chain_| to the next original
783 // opener in the chain if the original opener is destroyed.
danakjc492bf82020-09-09 20:02:44784 std::unique_ptr<OpenerDestroyedObserver> original_opener_observer_;
785
arthursonzogni034bb9c2020-10-01 08:29:56786 // When created by an opener, the URL specified in window.open(url)
787 // Please refer to {Get,Set}InitialPopupURL() documentation.
788 GURL initial_popup_url_;
789
790 // When created using window.open, the origin of the creator.
791 // Please refer to {Get,Set}PopupCreatorOrigin() documentation.
792 url::Origin popup_creator_origin_;
793
W. James MacLean81b8d01f2022-01-25 20:50:59794 // If the url from the the last BeginNavigation is about:srcdoc, this value
795 // stores the srcdoc_attribute's value for re-use in history navigations.
796 std::string srcdoc_value_;
797
danakjc492bf82020-09-09 20:02:44798 // Whether the frame's owner element in the parent document is collapsed.
arthursonzogni9816b9192021-03-29 16:09:19799 bool is_collapsed_ = false;
danakjc492bf82020-09-09 20:02:44800
Daniel Cheng6ac128172021-05-25 18:49:01801 // The type of frame owner for this frame. This is only relevant for non-main
802 // frames.
Kevin McNee43fe8292021-10-04 22:59:41803 const blink::FrameOwnerElementType frame_owner_element_type_ =
804 blink::FrameOwnerElementType::kNone;
Daniel Cheng9bd90f92021-04-23 20:49:45805
Daniel Cheng6ac128172021-05-25 18:49:01806 // The tree scope type of frame owner element, i.e. whether the element is in
807 // the document tree (https://dom.spec.whatwg.org/#document-trees) or the
808 // shadow tree (https://dom.spec.whatwg.org/#shadow-trees). This is only
809 // relevant for non-main frames.
810 const blink::mojom::TreeScopeType tree_scope_type_ =
811 blink::mojom::TreeScopeType::kDocument;
812
danakjc492bf82020-09-09 20:02:44813 // Track the pending sandbox flags and container policy for this frame. When a
814 // parent frame dynamically updates 'sandbox', 'allow', 'allowfullscreen',
815 // 'allowpaymentrequest' or 'src' attributes, the updated policy for the frame
Harkiran Bolaria4eacb3a2021-12-13 20:03:47816 // is stored here, and transferred into
817 // render_manager_.current_replication_state().frame_policy when they take
818 // effect on the next frame navigation.
danakjc492bf82020-09-09 20:02:44819 blink::FramePolicy pending_frame_policy_;
820
821 // Whether the frame was created by javascript. This is useful to prune
822 // history entries when the frame is removed (because frames created by
823 // scripts are never recreated with the same unique name - see
824 // https://crbug.com/500260).
arthursonzogni9816b9192021-03-29 16:09:19825 const bool is_created_by_script_;
danakjc492bf82020-09-09 20:02:44826
danakjc492bf82020-09-09 20:02:44827 // Tracks the scrolling and margin properties for this frame. These
828 // properties affect the child renderer but are stored on its parent's
829 // frame element. When this frame's parent dynamically updates these
830 // properties, we update them here too.
831 //
832 // Note that dynamic updates only take effect on the next frame navigation.
833 blink::mojom::FrameOwnerProperties frame_owner_properties_;
834
Yuzu Saijo03dbf9b2022-07-22 04:29:45835 // Contains the tracked HTML attributes of the corresponding iframe element,
836 // such as 'id' and 'src'.
837 blink::mojom::IframeAttributesPtr attributes_;
Antonio Sartori5abc8de2021-07-13 08:42:47838
danakjc492bf82020-09-09 20:02:44839 // Owns an ongoing NavigationRequest until it is ready to commit. It will then
840 // be reset and a RenderFrameHost will be responsible for the navigation.
841 std::unique_ptr<NavigationRequest> navigation_request_;
842
843 // List of objects observing this FrameTreeNode.
844 base::ObserverList<Observer>::Unchecked observers_;
845
846 base::TimeTicks last_focus_time_;
847
arthursonzogni9816b9192021-03-29 16:09:19848 bool was_discarded_ = false;
danakjc492bf82020-09-09 20:02:44849
Abhijeet Kandalkar3f29bc42022-09-23 12:39:58850 const FencedFrameStatus fenced_frame_status_ =
851 FencedFrameStatus::kNotNestedInFencedFrame;
Harkiran Bolaria16f2c48d2022-04-22 12:39:57852
Garrett Tanzerc69f4642022-08-15 22:15:14853 // If this is a fenced frame resulting from a urn:uuid navigation, this
854 // contains all the metadata specifying the resulting context.
Garrett Tanzer34cb92fe2022-09-28 17:50:54855 // TODO(crbug.com/1262022): Move this into the FrameTree once ShadowDOM
856 // and urn iframes are gone.
Garrett Tanzer29de7112022-12-06 21:26:32857 absl::optional<FencedFrameProperties> fenced_frame_properties_;
Garrett Tanzerc69f4642022-08-15 22:15:14858
Lukasz Anforowicz147141962020-12-16 18:03:24859 // Manages creation and swapping of RenderFrameHosts for this frame.
860 //
861 // This field needs to be declared last, because destruction of
862 // RenderFrameHostManager may call arbitrary callbacks (e.g. via
863 // WebContentsObserver::DidFinishNavigation fired after RenderFrameHostManager
864 // destructs a RenderFrameHostImpl and its NavigationRequest). Such callbacks
865 // may try to use FrameTreeNode's fields above - this would be an undefined
866 // behavior if the fields (even trivially-destructible ones) were destructed
867 // before the RenderFrameHostManager's destructor runs. See also
868 // https://crbug.com/1157988.
869 RenderFrameHostManager render_manager_;
danakjc492bf82020-09-09 20:02:44870};
871
872} // namespace content
873
874#endif // CONTENT_BROWSER_RENDERER_HOST_FRAME_TREE_NODE_H_