Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CONTENT_BROWSER_RENDERER_HOST_FRAME_TREE_NODE_H_ |
| 6 | #define CONTENT_BROWSER_RENDERER_HOST_FRAME_TREE_NODE_H_ |
| 7 | |
| 8 | #include <stddef.h> |
| 9 | |
| 10 | #include <memory> |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 11 | #include <optional> |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 12 | #include <string> |
David Sanders | 2c1194d9 | 2022-04-19 23:32:32 | [diff] [blame] | 13 | #include <utility> |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 14 | |
| 15 | #include "base/gtest_prod_util.h" |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 16 | #include "base/memory/raw_ptr.h" |
Christian Biesinger | e1865c57c | 2023-10-20 15:19:29 | [diff] [blame] | 17 | #include "base/memory/safe_ref.h" |
David Sanders | 2c1194d9 | 2022-04-19 23:32:32 | [diff] [blame] | 18 | #include "base/memory/scoped_refptr.h" |
David Sanders | d4bf5eb | 2022-03-17 07:12:05 | [diff] [blame] | 19 | #include "base/observer_list.h" |
Mingyu Lei | 7956b8b | 2023-07-24 08:24:08 | [diff] [blame] | 20 | #include "base/task/cancelable_task_tracker.h" |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 21 | #include "base/time/time.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 22 | #include "content/browser/renderer_host/navigator.h" |
| 23 | #include "content/browser/renderer_host/render_frame_host_impl.h" |
| 24 | #include "content/browser/renderer_host/render_frame_host_manager.h" |
Miyoung Shin | 7cf88b4 | 2022-11-07 13:22:30 | [diff] [blame] | 25 | #include "content/browser/renderer_host/render_frame_host_owner.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 26 | #include "content/common/content_export.h" |
Julie Jeongeun Kim | f38c1eca | 2021-12-14 07:46:55 | [diff] [blame] | 27 | #include "content/public/browser/frame_type.h" |
Rakina Zata Amni | 58681c6 | 2024-06-25 06:32:13 | [diff] [blame] | 28 | #include "content/public/browser/navigation_discard_reason.h" |
Anguluri Aravind Kumar | a8aa595 | 2025-02-23 02:53:07 | [diff] [blame] | 29 | #include "services/network/public/cpp/is_potentially_trustworthy.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 30 | #include "services/network/public/mojom/content_security_policy.mojom-forward.h" |
Julie Jeongeun Kim | 0e24224 | 2022-11-30 10:45:09 | [diff] [blame] | 31 | #include "services/network/public/mojom/referrer_policy.mojom-forward.h" |
Kevin McNee | 43fe829 | 2021-10-04 22:59:41 | [diff] [blame] | 32 | #include "third_party/blink/public/common/frame/frame_owner_element_type.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 33 | #include "third_party/blink/public/common/frame/frame_policy.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 34 | #include "third_party/blink/public/mojom/frame/frame_owner_properties.mojom.h" |
Gyuyoung Kim | c16e52e9 | 2021-03-19 02:45:37 | [diff] [blame] | 35 | #include "third_party/blink/public/mojom/frame/frame_replication_state.mojom-forward.h" |
Daniel Cheng | 6ac12817 | 2021-05-25 18:49:01 | [diff] [blame] | 36 | #include "third_party/blink/public/mojom/frame/tree_scope_type.mojom.h" |
David Sanders | 2c1194d9 | 2022-04-19 23:32:32 | [diff] [blame] | 37 | #include "third_party/blink/public/mojom/frame/user_activation_update_types.mojom-forward.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 38 | #include "url/gurl.h" |
| 39 | #include "url/origin.h" |
| 40 | |
| 41 | namespace content { |
| 42 | |
| 43 | class NavigationRequest; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 44 | class NavigationEntryImpl; |
Paul Semel | 3e24104 | 2022-10-11 12:57:31 | [diff] [blame] | 45 | class FrameTree; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 46 | |
| 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 Shin | 7cf88b4 | 2022-11-07 13:22:30 | [diff] [blame] | 59 | class CONTENT_EXPORT FrameTreeNode : public RenderFrameHostOwner { |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 60 | 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 Hemery | e465928 | 2022-03-28 08:36:15 | [diff] [blame] | 69 | // 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 Daly | a1d56997 | 2021-03-16 03:24:53 | [diff] [blame] | 73 | virtual ~Observer() = default; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 74 | }; |
| 75 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 76 | // Returns the FrameTreeNode with the given global |frame_tree_node_id|, |
| 77 | // regardless of which FrameTree it is in. |
Avi Drissman | bd15364 | 2024-09-03 18:58:05 | [diff] [blame] | 78 | static FrameTreeNode* GloballyFindByID(FrameTreeNodeId frame_tree_node_id); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 79 | |
| 80 | // Returns the FrameTreeNode for the given |rfh|. Same as |
| 81 | // rfh->frame_tree_node(), but also supports nullptrs. |
| 82 | static FrameTreeNode* From(RenderFrameHost* rfh); |
| 83 | |
| 84 | // Callers are are expected to initialize sandbox flags separately after |
| 85 | // calling the constructor. |
| 86 | FrameTreeNode( |
Arthur Sonzogni | f6785ec | 2022-12-05 10:11:50 | [diff] [blame] | 87 | FrameTree& frame_tree, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 88 | RenderFrameHostImpl* parent, |
Daniel Cheng | 6ac12817 | 2021-05-25 18:49:01 | [diff] [blame] | 89 | blink::mojom::TreeScopeType tree_scope_type, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 90 | bool is_created_by_script, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 91 | const blink::mojom::FrameOwnerProperties& frame_owner_properties, |
Kevin McNee | 43fe829 | 2021-10-04 22:59:41 | [diff] [blame] | 92 | blink::FrameOwnerElementType owner_type, |
Dominic Farolino | 08662c8 | 2021-06-11 07:36:34 | [diff] [blame] | 93 | const blink::FramePolicy& frame_owner); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 94 | |
Peter Boström | 828b902 | 2021-09-21 02:28:43 | [diff] [blame] | 95 | FrameTreeNode(const FrameTreeNode&) = delete; |
| 96 | FrameTreeNode& operator=(const FrameTreeNode&) = delete; |
| 97 | |
Miyoung Shin | 7cf88b4 | 2022-11-07 13:22:30 | [diff] [blame] | 98 | ~FrameTreeNode() override; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 99 | |
| 100 | void AddObserver(Observer* observer); |
| 101 | void RemoveObserver(Observer* observer); |
| 102 | |
Ian Vollick | 25a9d03 | 2022-04-12 23:20:17 | [diff] [blame] | 103 | // Frame trees may be nested so it can be the case that IsMainFrame() is true, |
| 104 | // but is not the outermost main frame. In particular, !IsMainFrame() cannot |
| 105 | // be used to check if the frame is an embedded frame -- use |
| 106 | // !IsOutermostMainFrame() instead. NB: this does not escape guest views; |
| 107 | // IsOutermostMainFrame will be true for the outermost main frame in an inner |
| 108 | // guest view. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 109 | bool IsMainFrame() const; |
Arthur Hemery | a06697f | 2023-03-14 09:20:57 | [diff] [blame] | 110 | bool IsOutermostMainFrame() const; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 111 | |
Anguluri Aravind Kumar | a8aa595 | 2025-02-23 02:53:07 | [diff] [blame] | 112 | // Returns true if all the ancestors of the current frame have a potentially |
| 113 | // trustworthy origin. |
| 114 | bool AreAncestorsSecure(); |
| 115 | |
Arthur Sonzogni | f6785ec | 2022-12-05 10:11:50 | [diff] [blame] | 116 | FrameTree& frame_tree() const { return frame_tree_.get(); } |
Paul Semel | 3e24104 | 2022-10-11 12:57:31 | [diff] [blame] | 117 | Navigator& navigator(); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 118 | |
| 119 | RenderFrameHostManager* render_manager() { return &render_manager_; } |
Alexander Timin | 33e2e2c1 | 2022-03-03 04:21:33 | [diff] [blame] | 120 | const RenderFrameHostManager* render_manager() const { |
| 121 | return &render_manager_; |
| 122 | } |
Avi Drissman | bd15364 | 2024-09-03 18:58:05 | [diff] [blame] | 123 | FrameTreeNodeId frame_tree_node_id() const { return frame_tree_node_id_; } |
Yuzu Saijo | 03dbf9b | 2022-07-22 04:29:45 | [diff] [blame] | 124 | // This reflects window.name, which is initially set to the the "name" |
| 125 | // attribute. But this won't reflect changes of 'name' attribute and instead |
| 126 | // reflect changes to the Window object's name property. |
| 127 | // This is different from IframeAttributes' name in that this will not get |
| 128 | // updated when 'name' attribute gets updated. |
Harkiran Bolaria | 4eacb3a | 2021-12-13 20:03:47 | [diff] [blame] | 129 | const std::string& frame_name() const { |
| 130 | return render_manager_.current_replication_state().name; |
| 131 | } |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 132 | |
| 133 | const std::string& unique_name() const { |
Harkiran Bolaria | 4eacb3a | 2021-12-13 20:03:47 | [diff] [blame] | 134 | return render_manager_.current_replication_state().unique_name; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 135 | } |
| 136 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 137 | size_t child_count() const { return current_frame_host()->child_count(); } |
| 138 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 139 | RenderFrameHostImpl* parent() const { return parent_; } |
| 140 | |
Dave Tapuska | c8de3b0 | 2021-12-03 21:51:01 | [diff] [blame] | 141 | // See `RenderFrameHost::GetParentOrOuterDocument()` for |
| 142 | // documentation. |
Arthur Hemery | a06697f | 2023-03-14 09:20:57 | [diff] [blame] | 143 | RenderFrameHostImpl* GetParentOrOuterDocument() const; |
Dave Tapuska | c8de3b0 | 2021-12-03 21:51:01 | [diff] [blame] | 144 | |
| 145 | // See `RenderFrameHostImpl::GetParentOrOuterDocumentOrEmbedder()` for |
| 146 | // documentation. |
| 147 | RenderFrameHostImpl* GetParentOrOuterDocumentOrEmbedder(); |
| 148 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 149 | FrameTreeNode* opener() const { return opener_; } |
| 150 | |
Rakina Zata Amni | 3a48ae4 | 2022-05-05 03:39:56 | [diff] [blame] | 151 | FrameTreeNode* first_live_main_frame_in_original_opener_chain() const { |
| 152 | return first_live_main_frame_in_original_opener_chain_; |
| 153 | } |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 154 | |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 155 | const std::optional<base::UnguessableToken>& opener_devtools_frame_token() { |
Wolfgang Beyer | d8809db | 2020-09-30 15:29:39 | [diff] [blame] | 156 | return opener_devtools_frame_token_; |
| 157 | } |
| 158 | |
Julie Jeongeun Kim | f38c1eca | 2021-12-14 07:46:55 | [diff] [blame] | 159 | // Returns the type of the frame. Refer to frame_type.h for the details. |
| 160 | FrameType GetFrameType() const; |
| 161 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 162 | // Assigns a new opener for this node and, if |opener| is non-null, registers |
| 163 | // an observer that will clear this node's opener if |opener| is ever |
| 164 | // destroyed. |
| 165 | void SetOpener(FrameTreeNode* opener); |
| 166 | |
| 167 | // Assigns the initial opener for this node, and if |opener| is non-null, |
| 168 | // registers an observer that will clear this node's opener if |opener| is |
| 169 | // ever destroyed. The value set here is the root of the tree. |
| 170 | // |
| 171 | // It is not possible to change the opener once it was set. |
| 172 | void SetOriginalOpener(FrameTreeNode* opener); |
| 173 | |
Wolfgang Beyer | d8809db | 2020-09-30 15:29:39 | [diff] [blame] | 174 | // Assigns an opener frame id for this node. This string id is only set once |
| 175 | // and cannot be changed. It persists, even if the |opener| is destroyed. It |
| 176 | // is used for attribution in the DevTools frontend. |
| 177 | void SetOpenerDevtoolsFrameToken( |
| 178 | base::UnguessableToken opener_devtools_frame_token); |
| 179 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 180 | FrameTreeNode* child_at(size_t index) const { |
| 181 | return current_frame_host()->child_at(index); |
| 182 | } |
| 183 | |
| 184 | // Returns the URL of the last committed page in the current frame. |
| 185 | const GURL& current_url() const { |
| 186 | return current_frame_host()->GetLastCommittedURL(); |
| 187 | } |
| 188 | |
Charlie Reis | 734db66 | 2024-01-11 18:20:03 | [diff] [blame] | 189 | // Moves this frame out of the initial empty document state, which is a |
| 190 | // one-way change for FrameTreeNode (i.e., it cannot go back into the initial |
| 191 | // empty document state). |
| 192 | void set_not_on_initial_empty_document() { |
| 193 | is_on_initial_empty_document_ = false; |
| 194 | } |
| 195 | |
| 196 | // Returns false if the frame has committed a document that is not the initial |
| 197 | // empty document, or if the current document's input stream has been opened |
| 198 | // with document.open(), causing the document to lose its "initial empty |
| 199 | // document" status. For more details, see the definition of |
| 200 | // `is_on_initial_empty_document_`. |
Rakina Zata Amni | 86c88fa | 2021-11-01 01:27:30 | [diff] [blame] | 201 | bool is_on_initial_empty_document() const { |
Charlie Reis | 734db66 | 2024-01-11 18:20:03 | [diff] [blame] | 202 | return is_on_initial_empty_document_; |
Rakina Zata Amni | fc4cc3d4 | 2021-06-10 09:03:56 | [diff] [blame] | 203 | } |
| 204 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 205 | // 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 Bolaria | 4eacb3a | 2021-12-13 20:03:47 | [diff] [blame] | 225 | return render_manager_.current_replication_state().origin; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 226 | } |
| 227 | |
Andrew Verge | 7233e66 | 2025-05-13 13:09:23 | [diff] [blame] | 228 | // Returns the origin of the last *successfully* committed page in this |
| 229 | // frame. This may be different from current_origin() if the current page is |
| 230 | // an error page. |
| 231 | // IMPORTANT: Use current_origin() instead, as all security-relevant decisions |
| 232 | // should be made using the current origin of the frame. The last successful |
| 233 | // origin is only relevant for specific abuse mitigations that require |
| 234 | // tracking the previous state of a frame before an error page navigation. |
| 235 | const url::Origin& last_successful_origin() const { |
| 236 | return last_successful_origin_; |
| 237 | } |
| 238 | |
| 239 | void set_last_successful_origin(const url::Origin& origin) { |
| 240 | last_successful_origin_ = origin; |
| 241 | } |
| 242 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 243 | // Returns the latest frame policy (sandbox flags and container policy) for |
| 244 | // this frame. This includes flags inherited from parent frames and the latest |
| 245 | // flags from the <iframe> element hosting this frame. The returned policies |
| 246 | // may not yet have taken effect, since "sandbox" and "allow" attribute |
Liam Brady | 25a1416 | 2022-12-02 15:25:57 | [diff] [blame] | 247 | // updates in an <iframe> element take effect on next navigation. For |
| 248 | // <fencedframe> elements, not everything in the frame policy might actually |
| 249 | // take effect after the navigation. To retrieve the currently active policy |
| 250 | // for this frame, use effective_frame_policy(). |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 251 | const blink::FramePolicy& pending_frame_policy() const { |
| 252 | return pending_frame_policy_; |
| 253 | } |
| 254 | |
Ming-Ying Chung | 0430c59 | 2025-01-21 00:33:10 | [diff] [blame] | 255 | // Update this frame's sandbox flags, container policy and deferred fetch |
| 256 | // policy. |
| 257 | // This is called when either |
| 258 | // - a parent frame updates the "sandbox" attribute in the <iframe> element |
| 259 | // for this frame |
| 260 | // - any of the attributes which affect the container policy |
| 261 | // ("allowfullscreen", "allowpaymentrequest", "allow", and "src".) |
| 262 | // - a frame begins navigation which leads to calculation of deferred fetch |
| 263 | // policy. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 264 | // These policies won't take effect until next navigation. If this frame's |
| 265 | // parent is itself sandboxed, the parent's sandbox flags are combined with |
| 266 | // those in |frame_policy|. |
| 267 | // Attempting to change the container policy on the main frame will have no |
| 268 | // effect. |
| 269 | void SetPendingFramePolicy(blink::FramePolicy frame_policy); |
| 270 | |
| 271 | // Returns the currently active frame policy for this frame, including the |
| 272 | // sandbox flags which were present at the time the document was loaded, and |
Charlie Hu | 5130d25e | 2021-03-05 21:53:39 | [diff] [blame] | 273 | // the permissions policy container policy, which is set by the iframe's |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 274 | // allowfullscreen, allowpaymentrequest, and allow attributes, along with the |
| 275 | // origin of the iframe's src attribute (which may be different from the URL |
| 276 | // of the document currently loaded into the frame). This does not include |
| 277 | // policy changes that have been made by updating the containing iframe |
| 278 | // element attributes since the frame was last navigated; use |
| 279 | // pending_frame_policy() for those. |
| 280 | const blink::FramePolicy& effective_frame_policy() const { |
Harkiran Bolaria | 4eacb3a | 2021-12-13 20:03:47 | [diff] [blame] | 281 | return render_manager_.current_replication_state().frame_policy; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 282 | } |
| 283 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 284 | const blink::mojom::FrameOwnerProperties& frame_owner_properties() { |
| 285 | return frame_owner_properties_; |
| 286 | } |
| 287 | |
| 288 | void set_frame_owner_properties( |
| 289 | const blink::mojom::FrameOwnerProperties& frame_owner_properties) { |
| 290 | frame_owner_properties_ = frame_owner_properties; |
| 291 | } |
| 292 | |
Yuzu Saijo | 03dbf9b | 2022-07-22 04:29:45 | [diff] [blame] | 293 | // Reflects the attributes of the corresponding iframe html element, such |
Arthur Sonzogni | 6445759 | 2022-11-22 11:08:59 | [diff] [blame] | 294 | // as 'credentialless', 'id', 'name' and 'src'. These values should not be |
Yuzu Saijo | 03dbf9b | 2022-07-22 04:29:45 | [diff] [blame] | 295 | // exposed to cross-origin renderers. |
| 296 | const network::mojom::ContentSecurityPolicy* csp_attribute() const { |
| 297 | return attributes_->parsed_csp_attribute.get(); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 298 | } |
Yao Xiao | 9c54b3e | 2023-03-14 04:25:04 | [diff] [blame] | 299 | // Tracks iframe's 'browsingtopics' attribute, indicating whether the |
| 300 | // navigation requests on this frame should calculate and send the |
| 301 | // `Sec-Browsing-Topics` header. |
| 302 | bool browsing_topics() const { return attributes_->browsing_topics; } |
Camillia Smith Barnes | 6d2966c8 | 2023-08-23 21:16:18 | [diff] [blame] | 303 | |
Orr Bernstein | a0cc679 | 2023-11-14 22:12:35 | [diff] [blame] | 304 | // Tracks iframe's 'adauctionheaders' attribute, indicating whether the |
| 305 | // navigation request on this frame should calculate and send the |
| 306 | // 'Sec-Ad-Auction-Fetch` header. |
| 307 | bool ad_auction_headers() const { return attributes_->ad_auction_headers; } |
| 308 | |
Camillia Smith Barnes | 6d2966c8 | 2023-08-23 21:16:18 | [diff] [blame] | 309 | // Tracks iframe's 'sharedstoragewritable' attribute, indicating what value |
Camillia Smith Barnes | c267be6 | 2023-11-01 20:01:02 | [diff] [blame] | 310 | // the the corresponding |
| 311 | // `network::ResourceRequest::shared_storage_writable_eligible` should take |
| 312 | // for the navigation(s) on this frame, pending a permissions policy check. If |
| 313 | // true, and if the permissions policy check returns "enabled", the network |
Camillia Smith Barnes | 6d2966c8 | 2023-08-23 21:16:18 | [diff] [blame] | 314 | // service will send the `Shared-Storage-Write` request header. |
Camillia Smith Barnes | c267be6 | 2023-11-01 20:01:02 | [diff] [blame] | 315 | bool shared_storage_writable_opted_in() const { |
| 316 | return attributes_->shared_storage_writable_opted_in; |
Camillia Smith Barnes | 6d2966c8 | 2023-08-23 21:16:18 | [diff] [blame] | 317 | } |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 318 | const std::optional<std::string> html_id() const { return attributes_->id; } |
Yuzu Saijo | 03dbf9b | 2022-07-22 04:29:45 | [diff] [blame] | 319 | // This tracks iframe's 'name' attribute instead of window.name, which is |
| 320 | // tracked in FrameReplicationState. See the comment for frame_name() for |
| 321 | // more details. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 322 | const std::optional<std::string> html_name() const { |
Yuzu Saijo | dc870f9 | 2023-01-20 03:39:11 | [diff] [blame] | 323 | return attributes_->name; |
| 324 | } |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 325 | const std::optional<std::string> html_src() const { return attributes_->src; } |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 326 | |
Yuzu Saijo | 03dbf9b | 2022-07-22 04:29:45 | [diff] [blame] | 327 | void SetAttributes(blink::mojom::IframeAttributesPtr attributes); |
Antonio Sartori | 5abc8de | 2021-07-13 08:42:47 | [diff] [blame] | 328 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 329 | bool HasSameOrigin(const FrameTreeNode& node) const { |
Harkiran Bolaria | 4eacb3a | 2021-12-13 20:03:47 | [diff] [blame] | 330 | return render_manager_.current_replication_state().origin.IsSameOriginWith( |
| 331 | node.current_replication_state().origin); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 332 | } |
| 333 | |
Gyuyoung Kim | c16e52e9 | 2021-03-19 02:45:37 | [diff] [blame] | 334 | const blink::mojom::FrameReplicationState& current_replication_state() const { |
Harkiran Bolaria | 4eacb3a | 2021-12-13 20:03:47 | [diff] [blame] | 335 | return render_manager_.current_replication_state(); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | RenderFrameHostImpl* current_frame_host() const { |
| 339 | return render_manager_.current_frame_host(); |
| 340 | } |
| 341 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 342 | // Returns true if this node is in a loading state. |
| 343 | bool IsLoading() const; |
Nate Chapin | 470dbc6 | 2023-04-25 16:34:38 | [diff] [blame] | 344 | LoadingState GetLoadingState() const; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 345 | |
Alex Moshchuk | 9b0fd82 | 2020-10-26 23:08:15 | [diff] [blame] | 346 | // Returns true if this node has a cross-document navigation in progress. |
| 347 | bool HasPendingCrossDocumentNavigation() const; |
| 348 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 349 | NavigationRequest* navigation_request() { return navigation_request_.get(); } |
| 350 | |
| 351 | // Transfers the ownership of the NavigationRequest to |render_frame_host|. |
| 352 | // From ReadyToCommit to DidCommit, the NavigationRequest is owned by the |
| 353 | // RenderFrameHost that is committing the navigation. |
| 354 | void TransferNavigationRequestOwnership( |
| 355 | RenderFrameHostImpl* render_frame_host); |
| 356 | |
| 357 | // Takes ownership of |navigation_request| and makes it the current |
| 358 | // NavigationRequest of this frame. This corresponds to the start of a new |
| 359 | // navigation. If there was an ongoing navigation request before calling this |
| 360 | // function, it is canceled. |navigation_request| should not be null. |
Charlie Reis | 09952ee | 2022-12-08 16:35:07 | [diff] [blame] | 361 | void TakeNavigationRequest( |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 362 | std::unique_ptr<NavigationRequest> navigation_request); |
| 363 | |
Rakina Zata Amni | f8f2bb6 | 2022-11-23 05:54:32 | [diff] [blame] | 364 | // Resets the navigation request owned by `this` (which shouldn't have reached |
| 365 | // the "pending commit" stage yet) and any state created by it, including the |
Rakina Zata Amni | 33175cb9 | 2022-11-24 02:46:03 | [diff] [blame] | 366 | // speculative RenderFrameHost (if there are no other navigations associated |
| 367 | // with it). Note that this does not affect navigations that have reached the |
| 368 | // "pending commit" stage, which are owned by their corresponding |
| 369 | // RenderFrameHosts instead. |
Daniel Cheng | 390e2a7 | 2022-09-28 06:07:53 | [diff] [blame] | 370 | void ResetNavigationRequest(NavigationDiscardReason reason); |
| 371 | |
Rakina Zata Amni | f8f2bb6 | 2022-11-23 05:54:32 | [diff] [blame] | 372 | // Similar to `ResetNavigationRequest()`, but keeps the state created by the |
Daniel Cheng | 390e2a7 | 2022-09-28 06:07:53 | [diff] [blame] | 373 | // NavigationRequest (e.g. speculative RenderFrameHost, loading state). |
Rakina Zata Amni | 58681c6 | 2024-06-25 06:32:13 | [diff] [blame] | 374 | void ResetNavigationRequestButKeepState(NavigationDiscardReason reason); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 375 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 376 | // The load progress for a RenderFrameHost in this node was updated to |
| 377 | // |load_progress|. This will notify the FrameTree which will in turn notify |
| 378 | // the WebContents. |
| 379 | void DidChangeLoadProgress(double load_progress); |
| 380 | |
| 381 | // Called when the user directed the page to stop loading. Stops all loads |
| 382 | // happening in the FrameTreeNode. This method should be used with |
| 383 | // FrameTree::ForEach to stop all loads in the entire FrameTree. |
| 384 | bool StopLoading(); |
| 385 | |
| 386 | // Returns the time this frame was last focused. |
| 387 | base::TimeTicks last_focus_time() const { return last_focus_time_; } |
| 388 | |
| 389 | // Called when this node becomes focused. Updates the node's last focused |
| 390 | // time and notifies observers. |
| 391 | void DidFocus(); |
| 392 | |
| 393 | // Called when the user closed the modal dialogue for BeforeUnload and |
| 394 | // cancelled the navigation. This should stop any load happening in the |
| 395 | // FrameTreeNode. |
| 396 | void BeforeUnloadCanceled(); |
| 397 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 398 | // Returns the sandbox flags currently in effect for this frame. This includes |
| 399 | // flags inherited from parent frames, the currently active flags from the |
| 400 | // <iframe> element hosting this frame, as well as any flags set from a |
| 401 | // Content-Security-Policy HTTP header. This does not include flags that have |
| 402 | // have been updated in an <iframe> element but have not taken effect yet; use |
| 403 | // pending_frame_policy() for those. To see the flags which will take effect |
| 404 | // on navigation (which does not include the CSP-set flags), use |
| 405 | // effective_frame_policy(). |
| 406 | network::mojom::WebSandboxFlags active_sandbox_flags() const { |
Harkiran Bolaria | 4eacb3a | 2021-12-13 20:03:47 | [diff] [blame] | 407 | return render_manager_.current_replication_state().active_sandbox_flags; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 408 | } |
| 409 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 410 | // Returns whether the frame received a user gesture on a previous navigation |
| 411 | // on the same eTLD+1. |
| 412 | bool has_received_user_gesture_before_nav() const { |
Harkiran Bolaria | 4eacb3a | 2021-12-13 20:03:47 | [diff] [blame] | 413 | return render_manager_.current_replication_state() |
| 414 | .has_received_user_gesture_before_nav; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | // When a tab is discarded, WebContents sets was_discarded on its |
| 418 | // root FrameTreeNode. |
| 419 | // In addition, when a child frame is created, this bit is passed on from |
| 420 | // parent to child. |
| 421 | // When a navigation request is created, was_discarded is passed on to the |
| 422 | // request and reset to false in FrameTreeNode. |
| 423 | void set_was_discarded() { was_discarded_ = true; } |
| 424 | bool was_discarded() const { return was_discarded_; } |
| 425 | |
Miyoung Shin | 8a66ec02 | 2022-11-28 23:50:09 | [diff] [blame] | 426 | // Deprecated. Use directly HasStickyUserActivation in RFHI. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 427 | // Returns the sticky bit of the User Activation v2 state of the |
| 428 | // |FrameTreeNode|. |
| 429 | bool HasStickyUserActivation() const { |
Miyoung Shin | 8a66ec02 | 2022-11-28 23:50:09 | [diff] [blame] | 430 | return current_frame_host()->HasStickyUserActivation(); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 431 | } |
| 432 | |
Miyoung Shin | 8a66ec02 | 2022-11-28 23:50:09 | [diff] [blame] | 433 | // Deprecated. Use directly HasStickyUserActivation in RFHI. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 434 | // Returns the transient bit of the User Activation v2 state of the |
| 435 | // |FrameTreeNode|. |
| 436 | bool HasTransientUserActivation() { |
Miyoung Shin | 8a66ec02 | 2022-11-28 23:50:09 | [diff] [blame] | 437 | return current_frame_host()->HasTransientUserActivation(); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | // Remove history entries for all frames created by script in this frame's |
| 441 | // subtree. If a frame created by a script is removed, then its history entry |
| 442 | // will never be reused - this saves memory. |
| 443 | void PruneChildFrameNavigationEntries(NavigationEntryImpl* entry); |
| 444 | |
Abhijeet Kandalkar | b43affa7 | 2022-09-27 16:48:01 | [diff] [blame] | 445 | using FencedFrameStatus = RenderFrameHostImpl::FencedFrameStatus; |
Abhijeet Kandalkar | 3f29bc4 | 2022-09-23 12:39:58 | [diff] [blame] | 446 | FencedFrameStatus fenced_frame_status() const { return fenced_frame_status_; } |
| 447 | |
Kevin McNee | 43fe829 | 2021-10-04 22:59:41 | [diff] [blame] | 448 | blink::FrameOwnerElementType frame_owner_element_type() const { |
Daniel Cheng | 9bd90f9 | 2021-04-23 20:49:45 | [diff] [blame] | 449 | return frame_owner_element_type_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 450 | } |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 451 | |
Daniel Cheng | 6ac12817 | 2021-05-25 18:49:01 | [diff] [blame] | 452 | blink::mojom::TreeScopeType tree_scope_type() const { |
| 453 | return tree_scope_type_; |
| 454 | } |
| 455 | |
arthursonzogni | 034bb9c | 2020-10-01 08:29:56 | [diff] [blame] | 456 | // The initial popup URL for new window opened using: |
| 457 | // `window.open(initial_popup_url)`. |
| 458 | // An empty GURL otherwise. |
| 459 | // |
| 460 | // [WARNING] There is no guarantee the FrameTreeNode will ever host a |
| 461 | // document served from this URL. The FrameTreeNode always starts hosting the |
| 462 | // initial empty document and attempts a navigation toward this URL. However |
| 463 | // the navigation might be delayed, redirected and even cancelled. |
| 464 | void SetInitialPopupURL(const GURL& initial_popup_url); |
| 465 | const GURL& initial_popup_url() const { return initial_popup_url_; } |
| 466 | |
| 467 | // The origin of the document that used window.open() to create this frame. |
| 468 | // Otherwise, an opaque Origin with a nonce different from all previously |
| 469 | // existing Origins. |
| 470 | void SetPopupCreatorOrigin(const url::Origin& popup_creator_origin); |
| 471 | const url::Origin& popup_creator_origin() const { |
| 472 | return popup_creator_origin_; |
| 473 | } |
| 474 | |
Harkiran Bolaria | 59290d6 | 2021-03-17 01:53:01 | [diff] [blame] | 475 | // Sets the associated FrameTree for this node. The node can change FrameTrees |
Domenic Denicola | 7767a9c | 2023-07-13 15:36:39 | [diff] [blame] | 476 | // as part of prerendering, which allows a page loaded in the prerendered |
| 477 | // FrameTree to be used for a navigation in the primary frame tree. |
Harkiran Bolaria | 59290d6 | 2021-03-17 01:53:01 | [diff] [blame] | 478 | void SetFrameTree(FrameTree& frame_tree); |
| 479 | |
Alexander Timin | 074cd18 | 2022-03-23 18:11:22 | [diff] [blame] | 480 | using TraceProto = perfetto::protos::pbzero::FrameTreeNodeInfo; |
Alexander Timin | f785f34 | 2021-03-18 00:00:56 | [diff] [blame] | 481 | // Write a representation of this object into a trace. |
Alexander Timin | 074cd18 | 2022-03-23 18:11:22 | [diff] [blame] | 482 | void WriteIntoTrace(perfetto::TracedProto<TraceProto> proto) const; |
Alexander Timin | f785f34 | 2021-03-18 00:00:56 | [diff] [blame] | 483 | |
Carlos Caballero | 7671135 | 2021-03-24 17:38:21 | [diff] [blame] | 484 | // Returns true the node is navigating, i.e. it has an associated |
| 485 | // NavigationRequest. |
| 486 | bool HasNavigation(); |
| 487 | |
murakinonoka | 97a8f04 | 2024-01-10 09:17:07 | [diff] [blame] | 488 | // Returns true if there are any navigations happening in FrameTreeNode that |
| 489 | // is pending commit (i.e. between ReadyToCommit and DidCommit). Note that |
| 490 | // those navigations won't live in the FrameTreeNode itself, as they will |
| 491 | // already be owned by the committing RenderFrameHost (either the current |
| 492 | // RenderFrameHost or the speculative RenderFrameHost). |
| 493 | bool HasPendingCommitNavigation(); |
| 494 | |
shivanigithub | f3ddff5 | 2021-07-03 22:06:30 | [diff] [blame] | 495 | // Fenced frames (meta-bug crbug.com/1111084): |
shivanigithub | 4cd016a | 2021-09-20 21:10:30 | [diff] [blame] | 496 | // Note that these two functions cannot be invoked from a FrameTree's or |
| 497 | // its root node's constructor since they require the frame tree and the |
| 498 | // root node to be completely constructed. |
| 499 | // |
shivanigithub | f3ddff5 | 2021-07-03 22:06:30 | [diff] [blame] | 500 | // Returns false if fenced frames are disabled. Returns true if the feature is |
| 501 | // enabled and if |this| is a fenced frame. Returns false for |
| 502 | // iframes embedded in a fenced frame. To clarify: for the MPArch |
| 503 | // implementation this only returns true if |this| is the actual |
| 504 | // root node of the inner FrameTree and not the proxy FrameTreeNode in the |
| 505 | // outer FrameTree. |
Dominic Farolino | 4bc10ee | 2021-08-31 00:37:36 | [diff] [blame] | 506 | bool IsFencedFrameRoot() const; |
shivanigithub | f3ddff5 | 2021-07-03 22:06:30 | [diff] [blame] | 507 | |
| 508 | // Returns false if fenced frames are disabled. Returns true if the |
| 509 | // feature is enabled and if |this| or any of its ancestor nodes is a |
| 510 | // fenced frame. |
| 511 | bool IsInFencedFrameTree() const; |
| 512 | |
shivanigithub | 4cd016a | 2021-09-20 21:10:30 | [diff] [blame] | 513 | // Returns a valid nonce if `IsInFencedFrameTree()` returns true for `this`. |
Garrett Tanzer | 34cb92fe | 2022-09-28 17:50:54 | [diff] [blame] | 514 | // Returns nullopt otherwise. |
| 515 | // |
| 516 | // Nonce used in the net::IsolationInfo and blink::StorageKey for a fenced |
| 517 | // frame and any iframes nested within it. Not set if this frame is not in a |
| 518 | // fenced frame's FrameTree. Note that this could be a field in FrameTree for |
| 519 | // the MPArch version but for the shadow DOM version we need to keep it here |
| 520 | // since the fenced frame root is not a main frame for the latter. The value |
| 521 | // of the nonce will be the same for all of the the iframes inside a fenced |
| 522 | // frame tree. If there is a nested fenced frame it will have a different |
| 523 | // nonce than its parent fenced frame. The nonce will stay the same across |
| 524 | // navigations initiated from the fenced frame tree because it is always used |
| 525 | // in conjunction with other fields of the keys and would be good to access |
| 526 | // the same storage across same-origin navigations. If the navigation is |
| 527 | // same-origin/site then the same network stack partition/storage will be |
| 528 | // reused and if it's cross-origin/site then other parts of the key will |
| 529 | // change and so, even with the same nonce, another partition will be used. |
| 530 | // But if the navigation is initiated from the embedder, the nonce will be |
| 531 | // reinitialized irrespective of same or cross origin such that there is no |
| 532 | // privacy leak via storage shared between two embedder initiated navigations. |
| 533 | // Note that this reinitialization is implemented for all embedder-initiated |
| 534 | // navigations in MPArch, but only urn:uuid navigations in ShadowDOM. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 535 | std::optional<base::UnguessableToken> GetFencedFrameNonce(); |
shivanigithub | 4cd016a | 2021-09-20 21:10:30 | [diff] [blame] | 536 | |
Garrett Tanzer | 34cb92fe | 2022-09-28 17:50:54 | [diff] [blame] | 537 | // If applicable, initialize the default fenced frame properties. Right now, |
| 538 | // this means setting a new fenced frame nonce. See comment on |
shivanigithub | 4cd016a | 2021-09-20 21:10:30 | [diff] [blame] | 539 | // fenced_frame_nonce() for when it is set to a non-null value. Invoked |
| 540 | // by FrameTree::Init() or FrameTree::AddFrame(). |
Garrett Tanzer | 34cb92fe | 2022-09-28 17:50:54 | [diff] [blame] | 541 | void SetFencedFramePropertiesIfNeeded(); |
shivanigithub | 4cd016a | 2021-09-20 21:10:30 | [diff] [blame] | 542 | |
Garrett Tanzer | 291a2d5 | 2023-03-20 22:41:57 | [diff] [blame] | 543 | // Set the current FencedFrameProperties to have "opaque ads mode". |
| 544 | // This should only be used during tests, when the proper embedder-initiated |
| 545 | // fenced frame root urn/config navigation flow isn't available. |
Alison Gale | 770f3fc | 2024-04-27 00:39:58 | [diff] [blame] | 546 | // TODO(crbug.com/40233168): Refactor and expand use of test utils so there is |
Garrett Tanzer | 291a2d5 | 2023-03-20 22:41:57 | [diff] [blame] | 547 | // a consistent way to do this properly everywhere. Consider removing |
| 548 | // arbitrary restrictions in "default mode" so that using opaque ads mode is |
| 549 | // less necessary. |
| 550 | void SetFencedFramePropertiesOpaqueAdsModeForTesting() { |
| 551 | if (fenced_frame_properties_.has_value()) { |
Garrett Tanzer | 0698070 | 2023-12-12 19:48:20 | [diff] [blame] | 552 | fenced_frame_properties_ |
| 553 | ->SetFencedFramePropertiesOpaqueAdsModeForTesting(); |
Garrett Tanzer | 291a2d5 | 2023-03-20 22:41:57 | [diff] [blame] | 554 | } |
| 555 | } |
| 556 | |
| 557 | // Returns the mode attribute from the `FencedFrameProperties` if this frame |
| 558 | // is in a fenced frame tree, otherwise returns `kDefault`. |
| 559 | blink::FencedFrame::DeprecatedFencedFrameMode GetDeprecatedFencedFrameMode(); |
Nan Lin | 171fe9a | 2022-02-17 16:42:16 | [diff] [blame] | 560 | |
Dave Tapuska | c8de3b0 | 2021-12-03 21:51:01 | [diff] [blame] | 561 | // Helper for GetParentOrOuterDocument/GetParentOrOuterDocumentOrEmbedder. |
| 562 | // Do not use directly. |
Kevin McNee | 86e64ee | 2023-02-17 16:35:50 | [diff] [blame] | 563 | // `escape_guest_view` determines whether to iterate out of guest views and is |
| 564 | // the behaviour distinction between GetParentOrOuterDocument and |
| 565 | // GetParentOrOuterDocumentOrEmbedder. See the comment on |
| 566 | // GetParentOrOuterDocumentOrEmbedder for details. |
| 567 | // `include_prospective` includes embedders which own our frame tree, but have |
| 568 | // not yet attached it to the outer frame tree. |
Arthur Hemery | a06697f | 2023-03-14 09:20:57 | [diff] [blame] | 569 | RenderFrameHostImpl* GetParentOrOuterDocumentHelper( |
| 570 | bool escape_guest_view, |
| 571 | bool include_prospective) const; |
Dave Tapuska | c8de3b0 | 2021-12-03 21:51:01 | [diff] [blame] | 572 | |
Harkiran Bolaria | b4437fd | 2021-08-11 17:51:22 | [diff] [blame] | 573 | // Sets the unique_name and name fields on replication_state_. To be used in |
| 574 | // prerender activation to make sure the FrameTreeNode replication state is |
| 575 | // correct after the RenderFrameHost is moved between FrameTreeNodes. The |
| 576 | // renderers should already have the correct value, so unlike |
| 577 | // FrameTreeNode::SetFrameName, we do not notify them here. |
Alison Gale | 770f3fc | 2024-04-27 00:39:58 | [diff] [blame] | 578 | // TODO(crbug.com/40192974): Remove this once the BrowsingContextState |
Harkiran Bolaria | 4eacb3a | 2021-12-13 20:03:47 | [diff] [blame] | 579 | // is implemented to utilize the new path. |
Harkiran Bolaria | b4437fd | 2021-08-11 17:51:22 | [diff] [blame] | 580 | void set_frame_name_for_activation(const std::string& unique_name, |
| 581 | const std::string& name) { |
Harkiran Bolaria | 0b3bdef0 | 2022-03-10 13:04:40 | [diff] [blame] | 582 | current_frame_host()->browsing_context_state()->set_frame_name(unique_name, |
| 583 | name); |
Harkiran Bolaria | b4437fd | 2021-08-11 17:51:22 | [diff] [blame] | 584 | } |
| 585 | |
Nan Lin | aaf84f7 | 2021-12-02 22:31:56 | [diff] [blame] | 586 | // Returns true if error page isolation is enabled. |
| 587 | bool IsErrorPageIsolationEnabled() const; |
| 588 | |
W. James MacLean | 81b8d01f | 2022-01-25 20:50:59 | [diff] [blame] | 589 | // Functions to store and retrieve a frame's srcdoc value on this |
| 590 | // FrameTreeNode. |
| 591 | void SetSrcdocValue(const std::string& srcdoc_value); |
| 592 | const std::string& srcdoc_value() const { return srcdoc_value_; } |
| 593 | |
Garrett Tanzer | c69f464 | 2022-08-15 22:15:14 | [diff] [blame] | 594 | void set_fenced_frame_properties( |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 595 | const std::optional<FencedFrameProperties>& fenced_frame_properties) { |
Alison Gale | 770f3fc | 2024-04-27 00:39:58 | [diff] [blame] | 596 | // TODO(crbug.com/40202462): Reenable this DCHECK once ShadowDOM and |
Garrett Tanzer | 2975eeac | 2022-08-22 16:34:01 | [diff] [blame] | 597 | // loading urns in iframes (for FLEDGE OT) are gone. |
| 598 | // DCHECK_EQ(fenced_frame_status_, |
| 599 | // RenderFrameHostImpl::FencedFrameStatus::kFencedFrameRoot); |
Garrett Tanzer | c69f464 | 2022-08-15 22:15:14 | [diff] [blame] | 600 | fenced_frame_properties_ = fenced_frame_properties; |
| 601 | } |
| 602 | |
Xiaochen Zhou | 86f2e71 | 2023-09-13 19:55:04 | [diff] [blame] | 603 | // This function returns the fenced frame properties associated with the given |
| 604 | // source. |
| 605 | // - If `source_node` is set to `kClosestAncestor`, the fenced frame |
| 606 | // properties are obtained by a bottom-up traversal from this node. |
| 607 | // - If `source_node` is set tp `kFrameTreeRoot`, the fenced frame properties |
| 608 | // from the fenced frame tree root are returned. |
| 609 | // For example, for an urn iframe that is nested inside a fenced frame. |
| 610 | // Calling this function from the nested urn iframe with `source_node` set to: |
| 611 | // - `kClosestAncestor`: returns the fenced frame properties from the urn |
| 612 | // iframe. |
| 613 | // - `kFrameTreeRoot`: returns the fenced frame properties from the fenced |
| 614 | // frame. |
| 615 | // Clients should decide which one to use depending on how the application of |
| 616 | // the fenced frame properties interact with urn iframes. |
Alison Gale | 770f3fc | 2024-04-27 00:39:58 | [diff] [blame] | 617 | // TODO(crbug.com/40060657): Once navigation support for urn::uuid in iframes |
Xiaochen Zhou | 86f2e71 | 2023-09-13 19:55:04 | [diff] [blame] | 618 | // is deprecated, remove the parameter `node_source`. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 619 | std::optional<FencedFrameProperties>& GetFencedFrameProperties( |
Xiaochen Zhou | 86f2e71 | 2023-09-13 19:55:04 | [diff] [blame] | 620 | FencedFramePropertiesNodeSource node_source = |
| 621 | FencedFramePropertiesNodeSource::kClosestAncestor); |
Garrett Tanzer | c69f464 | 2022-08-15 22:15:14 | [diff] [blame] | 622 | |
Liam Brady | 27da6a2 | 2024-06-05 16:35:34 | [diff] [blame] | 623 | // Helper function for getting the FrameTreeNode that houses the relevant |
| 624 | // FencedFrameProperties when GetFencedFrameProperties() is called with |
| 625 | // kClosestAncestor. |
| 626 | FrameTreeNode* GetClosestAncestorWithFencedFrameProperties(); |
| 627 | |
Liam Brady | 86ca048 | 2023-12-06 19:49:25 | [diff] [blame] | 628 | bool HasFencedFrameProperties() const { |
| 629 | return fenced_frame_properties_.has_value(); |
| 630 | } |
| 631 | |
Yao Xiao | f9ae90a | 2023-03-01 20:52:44 | [diff] [blame] | 632 | // Returns the number of fenced frame boundaries above this frame. The |
Yao Xiao | a2337ad | 2022-10-12 20:59:29 | [diff] [blame] | 633 | // outermost main frame's frame tree has fenced frame depth 0, a topmost |
| 634 | // fenced frame tree embedded in the outermost main frame has fenced frame |
| 635 | // depth 1, etc. |
Yao Xiao | f9ae90a | 2023-03-01 20:52:44 | [diff] [blame] | 636 | // |
| 637 | // Also, sets `shared_storage_fenced_frame_root_count` to the |
| 638 | // number of fenced frame boundaries (roots) above this frame that originate |
| 639 | // from shared storage. This is used to check whether a fenced frame |
| 640 | // originates from shared storage only (i.e. not from FLEDGE). |
Alison Gale | 770f3fc | 2024-04-27 00:39:58 | [diff] [blame] | 641 | // TODO(crbug.com/40233168): Remove this check once we put permissions inside |
Yao Xiao | f9ae90a | 2023-03-01 20:52:44 | [diff] [blame] | 642 | // FencedFrameConfig. |
| 643 | size_t GetFencedFrameDepth(size_t& shared_storage_fenced_frame_root_count); |
Yao Xiao | a2337ad | 2022-10-12 20:59:29 | [diff] [blame] | 644 | |
| 645 | // Traverse up from this node. Return all valid |
| 646 | // `node->fenced_frame_properties_->shared_storage_budget_metadata` (i.e. this |
| 647 | // node is subjected to the shared storage budgeting associated with those |
| 648 | // metadata). Every node that originates from sharedStorage.selectURL() will |
| 649 | // have an associated metadata. This indicates that the metadata can only |
| 650 | // possibly be associated with a fenced frame root, unless when |
| 651 | // `kAllowURNsInIframes` is enabled in which case they could be be associated |
| 652 | // with any node. |
Garrett Tanzer | 29de711 | 2022-12-06 21:26:32 | [diff] [blame] | 653 | std::vector<const SharedStorageBudgetMetadata*> |
Yao Xiao | 1ac702d | 2022-06-08 17:20:49 | [diff] [blame] | 654 | FindSharedStorageBudgetMetadata(); |
| 655 | |
Camillia Smith Barnes | 7218518c | 2023-03-06 19:02:17 | [diff] [blame] | 656 | // Returns any shared storage context string that was written to a |
| 657 | // `blink::FencedFrameConfig` before navigation via |
| 658 | // `setSharedStorageContext()`, as long as the request is for a same-origin |
| 659 | // frame within the config's fenced frame tree (or a same-origin descendant of |
| 660 | // a URN iframe). |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 661 | std::optional<std::u16string> GetEmbedderSharedStorageContextIfAllowed(); |
Camillia Smith Barnes | 7218518c | 2023-03-06 19:02:17 | [diff] [blame] | 662 | |
Harkiran Bolaria | ebbe770 | 2022-02-22 19:19:03 | [diff] [blame] | 663 | // Accessor to BrowsingContextState for subframes only. Only main frame |
| 664 | // navigations can change BrowsingInstances and BrowsingContextStates, |
| 665 | // therefore for subframes associated BrowsingContextState never changes. This |
| 666 | // helper method makes this more explicit and guards against calling this on |
| 667 | // main frames (there an appropriate BrowsingContextState should be obtained |
| 668 | // from RenderFrameHost or from RenderFrameProxyHost as e.g. during |
| 669 | // cross-BrowsingInstance navigations multiple BrowsingContextStates exist in |
| 670 | // the same frame). |
| 671 | const scoped_refptr<BrowsingContextState>& |
| 672 | GetBrowsingContextStateForSubframe() const; |
| 673 | |
Arthur Hemery | e465928 | 2022-03-28 08:36:15 | [diff] [blame] | 674 | // Clears the opener property of popups referencing this FrameTreeNode as |
| 675 | // their opener. |
| 676 | void ClearOpenerReferences(); |
| 677 | |
Liam Brady | 95d36d1 | 2023-03-13 21:13:06 | [diff] [blame] | 678 | // Calculates whether one of the ancestor frames or this frame has a CSPEE in |
| 679 | // place. This is eventually sent over to LocalFrame in the renderer where it |
| 680 | // will be used by NavigatorAuction::canLoadAdAuctionFencedFrame for |
| 681 | // information it can't get on its own. |
Liam Brady | d2a41e15 | 2022-07-19 13:58:48 | [diff] [blame] | 682 | bool AncestorOrSelfHasCSPEE() const; |
| 683 | |
Arthur Sonzogni | 8e8eb1f | 2023-01-10 14:51:01 | [diff] [blame] | 684 | // Reset every navigation in this frame, and its descendants. This is called |
| 685 | // after the <iframe> element has been removed, or after the document owning |
| 686 | // this frame has been navigated away. |
| 687 | // |
| 688 | // This takes into account: |
| 689 | // - Non-pending commit NavigationRequest owned by the FrameTreeNode |
| 690 | // - Pending commit NavigationRequest owned by the current RenderFrameHost |
| 691 | // - Speculative RenderFrameHost and its pending commit NavigationRequests. |
| 692 | void ResetAllNavigationsForFrameDetach(); |
| 693 | |
Miyoung Shin | 7cf88b4 | 2022-11-07 13:22:30 | [diff] [blame] | 694 | // RenderFrameHostOwner implementation: |
Nate Chapin | 470dbc6 | 2023-04-25 16:34:38 | [diff] [blame] | 695 | void DidStartLoading(LoadingState previous_frame_tree_loading_state) override; |
Julie Jeongeun Kim | 07c077bd | 2022-12-05 08:40:31 | [diff] [blame] | 696 | void DidStopLoading() override; |
Miyoung Shin | 7cf88b4 | 2022-11-07 13:22:30 | [diff] [blame] | 697 | void RestartNavigationAsCrossDocument( |
| 698 | std::unique_ptr<NavigationRequest> navigation_request) override; |
Miyoung Shin | 1504eb71 | 2022-12-07 10:32:18 | [diff] [blame] | 699 | bool Reload() override; |
Julie Jeongeun Kim | c1b07c3 | 2022-11-11 10:26:32 | [diff] [blame] | 700 | Navigator& GetCurrentNavigator() override; |
Miyoung Shin | e16cd226 | 2022-11-30 05:52:16 | [diff] [blame] | 701 | RenderFrameHostManager& GetRenderFrameHostManager() override; |
Miyoung Shin | 64fd1bea | 2023-01-04 04:22:08 | [diff] [blame] | 702 | FrameTreeNode* GetOpener() const override; |
Julie Jeongeun Kim | 2132b37f8 | 2022-11-23 08:30:46 | [diff] [blame] | 703 | void SetFocusedFrame(SiteInstanceGroup* source) override; |
Julie Jeongeun Kim | 0e24224 | 2022-11-30 10:45:09 | [diff] [blame] | 704 | void DidChangeReferrerPolicy( |
| 705 | network::mojom::ReferrerPolicy referrer_policy) override; |
Miyoung Shin | 8a66ec02 | 2022-11-28 23:50:09 | [diff] [blame] | 706 | // Updates the user activation state in the browser frame tree and in the |
| 707 | // frame trees in all renderer processes except the renderer for this node |
| 708 | // (which initiated the update). Returns |false| if the update tries to |
| 709 | // consume an already consumed/expired transient state, |true| otherwise. See |
| 710 | // the comment on `user_activation_state_` in RenderFrameHostImpl. |
| 711 | // |
| 712 | // The |notification_type| parameter is used for histograms, only for the case |
| 713 | // |update_state == kNotifyActivation|. |
| 714 | bool UpdateUserActivationState( |
| 715 | blink::mojom::UserActivationUpdateType update_type, |
| 716 | blink::mojom::UserActivationNotificationType notification_type) override; |
Nate Chapin | 47276a6 | 2023-02-16 16:53:44 | [diff] [blame] | 717 | void DidConsumeHistoryUserActivation() override; |
Charlie Reis | 734db66 | 2024-01-11 18:20:03 | [diff] [blame] | 718 | void DidOpenDocumentInputStream() override; |
Miyoung Shin | ff13ed2 | 2022-11-30 09:21:47 | [diff] [blame] | 719 | std::unique_ptr<NavigationRequest> |
| 720 | CreateNavigationRequestForSynchronousRendererCommit( |
| 721 | RenderFrameHostImpl* render_frame_host, |
| 722 | bool is_same_document, |
| 723 | const GURL& url, |
| 724 | const url::Origin& origin, |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 725 | const std::optional<GURL>& initiator_base_url, |
Miyoung Shin | ff13ed2 | 2022-11-30 09:21:47 | [diff] [blame] | 726 | const net::IsolationInfo& isolation_info_for_subresources, |
| 727 | blink::mojom::ReferrerPtr referrer, |
| 728 | const ui::PageTransition& transition, |
| 729 | bool should_replace_current_entry, |
| 730 | const std::string& method, |
| 731 | bool has_transient_activation, |
| 732 | bool is_overriding_user_agent, |
| 733 | const std::vector<GURL>& redirects, |
| 734 | const GURL& original_url, |
| 735 | std::unique_ptr<CrossOriginEmbedderPolicyReporter> coep_reporter, |
Camille Lamy | 36afacd | 2025-01-16 14:25:18 | [diff] [blame] | 736 | std::unique_ptr<DocumentIsolationPolicyReporter> dip_reporter, |
Charlie Reis | e1d9b818 | 2025-04-02 04:32:12 | [diff] [blame] | 737 | int http_response_code, |
| 738 | base::TimeTicks actual_navigation_start) override; |
Rakina Zata Amni | 58681c6 | 2024-06-25 06:32:13 | [diff] [blame] | 739 | void CancelNavigation(NavigationDiscardReason reason) override; |
Thomas Lukaszewicz | 1b672fe | 2024-09-17 08:35:03 | [diff] [blame] | 740 | void ResetNavigationsForDiscard() override; |
Miyoung Shin | c9ff481 | 2023-01-05 08:58:05 | [diff] [blame] | 741 | bool Credentialless() const override; |
Kevin McNee | f1b0f0b | 2024-09-17 21:49:41 | [diff] [blame] | 742 | FrameType GetCurrentFrameType() const override; |
Miyoung Shin | ff13ed2 | 2022-11-30 09:21:47 | [diff] [blame] | 743 | |
Mingyu Lei | 7956b8b | 2023-07-24 08:24:08 | [diff] [blame] | 744 | // Restart the navigation restoring the page from the back-forward cache |
| 745 | // as a regular non-BFCached history navigation. |
| 746 | // |
| 747 | // The restart itself is asynchronous as it's dangerous to restart navigation |
| 748 | // with arbitrary state on the stack (another navigation might be starting), |
| 749 | // so this function only posts the actual task to do all the work (See |
| 750 | // `RestartBackForwardCachedNavigationImpl()`). |
| 751 | void RestartBackForwardCachedNavigationAsync(int nav_entry_id); |
| 752 | |
| 753 | // Cancel the asynchronous task that would restart the BFCache navigation. |
| 754 | // This should be called whenever a FrameTreeNode's NavigationRequest would |
| 755 | // normally get cancelled, including when another NavigationRequest starts. |
| 756 | // This preserves the previous behavior where a restarting BFCache |
| 757 | // NavigationRequest is kept around until the task to create the new |
| 758 | // navigation is run, or until that NavigationRequest gets deleted (which |
| 759 | // cancels the task). |
| 760 | void CancelRestartingBackForwardCacheNavigation(); |
| 761 | |
Christian Biesinger | e1865c57c | 2023-10-20 15:19:29 | [diff] [blame] | 762 | base::SafeRef<FrameTreeNode> GetSafeRef() { |
| 763 | return weak_factory_.GetSafeRef(); |
| 764 | } |
| 765 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 766 | private: |
Yuzu Saijo | 03dbf9b | 2022-07-22 04:29:45 | [diff] [blame] | 767 | friend class CSPEmbeddedEnforcementUnitTest; |
Charlie Hu | bb5943d | 2021-03-09 19:46:12 | [diff] [blame] | 768 | FRIEND_TEST_ALL_PREFIXES(SitePerProcessPermissionsPolicyBrowserTest, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 769 | ContainerPolicyDynamic); |
Charlie Hu | bb5943d | 2021-03-09 19:46:12 | [diff] [blame] | 770 | FRIEND_TEST_ALL_PREFIXES(SitePerProcessPermissionsPolicyBrowserTest, |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 771 | ContainerPolicySandboxDynamic); |
Yuzu Saijo | 03dbf9b | 2022-07-22 04:29:45 | [diff] [blame] | 772 | FRIEND_TEST_ALL_PREFIXES(NavigationRequestTest, StorageKeyToCommit); |
Arthur Sonzogni | 6445759 | 2022-11-22 11:08:59 | [diff] [blame] | 773 | FRIEND_TEST_ALL_PREFIXES( |
| 774 | NavigationRequestTest, |
| 775 | NavigationToCredentiallessDocumentNetworkIsolationInfo); |
Yuzu Saijo | 03dbf9b | 2022-07-22 04:29:45 | [diff] [blame] | 776 | FRIEND_TEST_ALL_PREFIXES(RenderFrameHostImplTest, |
Arthur Sonzogni | 6445759 | 2022-11-22 11:08:59 | [diff] [blame] | 777 | ChildOfCredentiallessIsCredentialless); |
Yifan Luo | 86a79f4 | 2022-08-16 18:38:27 | [diff] [blame] | 778 | FRIEND_TEST_ALL_PREFIXES(ContentPasswordManagerDriverTest, |
Arthur Sonzogni | 6445759 | 2022-11-22 11:08:59 | [diff] [blame] | 779 | PasswordAutofillDisabledOnCredentiallessIframe); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 780 | |
Dominic Farolino | 8a2187b | 2021-12-24 20:44:21 | [diff] [blame] | 781 | // Called by the destructor. When `this` is an outer dummy FrameTreeNode |
| 782 | // representing an inner FrameTree, this method destroys said inner FrameTree. |
| 783 | void DestroyInnerFrameTreeIfExists(); |
| 784 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 785 | class OpenerDestroyedObserver; |
| 786 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 787 | // The |notification_type| parameter is used for histograms only. |
Liam Brady | 38b8456 | 2024-03-07 22:11:26 | [diff] [blame] | 788 | // |sticky_only| is set to true when propagating sticky user activation during |
| 789 | // cross-document navigations. The transient state remains unchanged. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 790 | bool NotifyUserActivation( |
Liam Brady | 38b8456 | 2024-03-07 22:11:26 | [diff] [blame] | 791 | blink::mojom::UserActivationNotificationType notification_type, |
| 792 | bool sticky_only = false); |
| 793 | |
| 794 | bool NotifyUserActivationStickyOnly(); |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 795 | |
| 796 | bool ConsumeTransientUserActivation(); |
| 797 | |
| 798 | bool ClearUserActivation(); |
| 799 | |
| 800 | // Verify that the renderer process is allowed to set user activation on this |
| 801 | // frame by checking whether this frame's RenderWidgetHost had previously seen |
| 802 | // an input event that might lead to user activation. If user activation |
| 803 | // should be allowed, this returns true and also clears corresponding pending |
| 804 | // user activation state in the widget. Otherwise, this returns false. |
| 805 | bool VerifyUserActivation(); |
| 806 | |
Mingyu Lei | 7956b8b | 2023-07-24 08:24:08 | [diff] [blame] | 807 | // See `RestartBackForwardCachedNavigationAsync()`. |
| 808 | void RestartBackForwardCachedNavigationImpl(int nav_entry_id); |
| 809 | |
Avi Drissman | bd15364 | 2024-09-03 18:58:05 | [diff] [blame] | 810 | // The browser-global FrameTreeNodeId generator. |
| 811 | static FrameTreeNodeId::Generator frame_tree_node_id_generator_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 812 | |
Arthur Sonzogni | f6785ec | 2022-12-05 10:11:50 | [diff] [blame] | 813 | // The FrameTree owning |this|. It can change with Prerender2 during |
| 814 | // activation. |
| 815 | raw_ref<FrameTree> frame_tree_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 816 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 817 | // A browser-global identifier for the frame in the page, which stays stable |
| 818 | // even if the frame does a cross-process navigation. |
Avi Drissman | bd15364 | 2024-09-03 18:58:05 | [diff] [blame] | 819 | const FrameTreeNodeId frame_tree_node_id_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 820 | |
| 821 | // The RenderFrameHost owning this FrameTreeNode, which cannot change for the |
| 822 | // life of this FrameTreeNode. |nullptr| if this node is the root. |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 823 | const raw_ptr<RenderFrameHostImpl> parent_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 824 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 825 | // The frame that opened this frame, if any. Will be set to null if the |
| 826 | // opener is closed, or if this frame disowns its opener by setting its |
| 827 | // window.opener to null. |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 828 | raw_ptr<FrameTreeNode> opener_ = nullptr; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 829 | |
| 830 | // An observer that clears this node's |opener_| if the opener is destroyed. |
| 831 | // This observer is added to the |opener_|'s observer list when the |opener_| |
| 832 | // is set to a non-null node, and it is removed from that list when |opener_| |
| 833 | // changes or when this node is destroyed. It is also cleared if |opener_| |
| 834 | // is disowned. |
| 835 | std::unique_ptr<OpenerDestroyedObserver> opener_observer_; |
| 836 | |
Rakina Zata Amni | 3a48ae4 | 2022-05-05 03:39:56 | [diff] [blame] | 837 | // Unlike `opener_`, the "original opener chain" doesn't reflect |
| 838 | // window.opener, which can be suppressed or updated. The "original opener" |
| 839 | // is the main frame of the actual opener of this frame. This traces the all |
| 840 | // the way back, so if the original opener was closed (deleted or severed due |
| 841 | // to COOP), but _it_ had an original opener, this will return the original |
| 842 | // opener's original opener, etc. So this value will always be set as long as |
| 843 | // there is at least one live frame in the chain whose connection is not |
| 844 | // severed due to COOP. |
| 845 | raw_ptr<FrameTreeNode> first_live_main_frame_in_original_opener_chain_ = |
| 846 | nullptr; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 847 | |
Wolfgang Beyer | d8809db | 2020-09-30 15:29:39 | [diff] [blame] | 848 | // The devtools frame token of the frame which opened this frame. This is |
| 849 | // not cleared even if the opener is destroyed or disowns the frame. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 850 | std::optional<base::UnguessableToken> opener_devtools_frame_token_; |
Wolfgang Beyer | d8809db | 2020-09-30 15:29:39 | [diff] [blame] | 851 | |
Rakina Zata Amni | 3a48ae4 | 2022-05-05 03:39:56 | [diff] [blame] | 852 | // An observer that updates this node's |
| 853 | // |first_live_main_frame_in_original_opener_chain_| to the next original |
| 854 | // opener in the chain if the original opener is destroyed. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 855 | std::unique_ptr<OpenerDestroyedObserver> original_opener_observer_; |
| 856 | |
arthursonzogni | 034bb9c | 2020-10-01 08:29:56 | [diff] [blame] | 857 | // When created by an opener, the URL specified in window.open(url) |
| 858 | // Please refer to {Get,Set}InitialPopupURL() documentation. |
| 859 | GURL initial_popup_url_; |
| 860 | |
| 861 | // When created using window.open, the origin of the creator. |
| 862 | // Please refer to {Get,Set}PopupCreatorOrigin() documentation. |
| 863 | url::Origin popup_creator_origin_; |
| 864 | |
W. James MacLean | 81b8d01f | 2022-01-25 20:50:59 | [diff] [blame] | 865 | // If the url from the the last BeginNavigation is about:srcdoc, this value |
| 866 | // stores the srcdoc_attribute's value for re-use in history navigations. |
| 867 | std::string srcdoc_value_; |
| 868 | |
Charlie Reis | 734db66 | 2024-01-11 18:20:03 | [diff] [blame] | 869 | // Whether this frame is still on the initial about:blank document or the |
| 870 | // synchronously committed about:blank document committed at frame creation, |
| 871 | // and its "initial empty document"-ness is still true. |
| 872 | // This will be false if either of these has happened: |
| 873 | // - The current RenderFrameHost commits a cross-document navigation that is |
| 874 | // not the synchronously committed about:blank document per: |
| 875 | // https://html.spec.whatwg.org/multipage/browsers.html#creating-browsing-contexts:is-initial-about:blank |
| 876 | // - The document's input stream has been opened with document.open(), per |
| 877 | // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#opening-the-input-stream:is-initial-about:blank |
| 878 | // NOTE: we treat both the "initial about:blank document" and the |
| 879 | // "synchronously committed about:blank document" as the initial empty |
| 880 | // document. In the future, we plan to remove the synchronous about:blank |
| 881 | // commit so that this state will only be true if the frame is on the |
| 882 | // "initial about:blank document". See also: |
| 883 | // - https://github.com/whatwg/html/issues/6863 |
| 884 | // - https://crbug.com/1215096 |
| 885 | // |
| 886 | // Note that cross-document navigations update this state at |
| 887 | // DidCommitNavigation() time. Thus, this is still true when a cross-document |
| 888 | // navigation from an initial empty document is in the pending-commit window, |
| 889 | // after sending the CommitNavigation IPC but before receiving |
| 890 | // DidCommitNavigation(). This is in contrast to |
| 891 | // has_committed_any_navigation(), which is updated in CommitNavigation(). |
| 892 | // TODO(alexmos): Consider updating this at CommitNavigation() time as well to |
| 893 | // match the has_committed_any_navigation() behavior. |
| 894 | bool is_on_initial_empty_document_ = true; |
| 895 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 896 | // Whether the frame's owner element in the parent document is collapsed. |
arthursonzogni | 9816b919 | 2021-03-29 16:09:19 | [diff] [blame] | 897 | bool is_collapsed_ = false; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 898 | |
Daniel Cheng | 6ac12817 | 2021-05-25 18:49:01 | [diff] [blame] | 899 | // The type of frame owner for this frame. This is only relevant for non-main |
| 900 | // frames. |
Kevin McNee | 43fe829 | 2021-10-04 22:59:41 | [diff] [blame] | 901 | const blink::FrameOwnerElementType frame_owner_element_type_ = |
| 902 | blink::FrameOwnerElementType::kNone; |
Daniel Cheng | 9bd90f9 | 2021-04-23 20:49:45 | [diff] [blame] | 903 | |
Daniel Cheng | 6ac12817 | 2021-05-25 18:49:01 | [diff] [blame] | 904 | // The tree scope type of frame owner element, i.e. whether the element is in |
| 905 | // the document tree (https://dom.spec.whatwg.org/#document-trees) or the |
| 906 | // shadow tree (https://dom.spec.whatwg.org/#shadow-trees). This is only |
| 907 | // relevant for non-main frames. |
| 908 | const blink::mojom::TreeScopeType tree_scope_type_ = |
| 909 | blink::mojom::TreeScopeType::kDocument; |
| 910 | |
Ming-Ying Chung | 0430c59 | 2025-01-21 00:33:10 | [diff] [blame] | 911 | // Track the pending sandbox flags, container policy, and deferred fetch |
| 912 | // policy for this frame. |
| 913 | // When a parent frame dynamically updates 'sandbox', 'allow', |
| 914 | // 'allowfullscreen', 'allowpaymentrequest' or 'src' attributes, the updated |
| 915 | // policy for the frame is stored here, and transferred into |
Harkiran Bolaria | 4eacb3a | 2021-12-13 20:03:47 | [diff] [blame] | 916 | // render_manager_.current_replication_state().frame_policy when they take |
| 917 | // effect on the next frame navigation. |
Ming-Ying Chung | 0430c59 | 2025-01-21 00:33:10 | [diff] [blame] | 918 | // |
| 919 | // Note that updates to FramePolicy from the renderer side must be explicitly |
| 920 | // set in this field via `SetPendingFramePolicy()`; Otherwise, the browser |
| 921 | // side won't have it saved and can't pass it to new RenderFrameHost. |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 922 | blink::FramePolicy pending_frame_policy_; |
| 923 | |
| 924 | // Whether the frame was created by javascript. This is useful to prune |
| 925 | // history entries when the frame is removed (because frames created by |
| 926 | // scripts are never recreated with the same unique name - see |
| 927 | // https://crbug.com/500260). |
arthursonzogni | 9816b919 | 2021-03-29 16:09:19 | [diff] [blame] | 928 | const bool is_created_by_script_; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 929 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 930 | // Tracks the scrolling and margin properties for this frame. These |
| 931 | // properties affect the child renderer but are stored on its parent's |
| 932 | // frame element. When this frame's parent dynamically updates these |
| 933 | // properties, we update them here too. |
| 934 | // |
| 935 | // Note that dynamic updates only take effect on the next frame navigation. |
| 936 | blink::mojom::FrameOwnerProperties frame_owner_properties_; |
| 937 | |
Yuzu Saijo | 03dbf9b | 2022-07-22 04:29:45 | [diff] [blame] | 938 | // Contains the tracked HTML attributes of the corresponding iframe element, |
| 939 | // such as 'id' and 'src'. |
| 940 | blink::mojom::IframeAttributesPtr attributes_; |
Antonio Sartori | 5abc8de | 2021-07-13 08:42:47 | [diff] [blame] | 941 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 942 | // Owns an ongoing NavigationRequest until it is ready to commit. It will then |
| 943 | // be reset and a RenderFrameHost will be responsible for the navigation. |
| 944 | std::unique_ptr<NavigationRequest> navigation_request_; |
| 945 | |
| 946 | // List of objects observing this FrameTreeNode. |
| 947 | base::ObserverList<Observer>::Unchecked observers_; |
| 948 | |
| 949 | base::TimeTicks last_focus_time_; |
| 950 | |
arthursonzogni | 9816b919 | 2021-03-29 16:09:19 | [diff] [blame] | 951 | bool was_discarded_ = false; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 952 | |
Abhijeet Kandalkar | 3f29bc4 | 2022-09-23 12:39:58 | [diff] [blame] | 953 | const FencedFrameStatus fenced_frame_status_ = |
| 954 | FencedFrameStatus::kNotNestedInFencedFrame; |
Harkiran Bolaria | 16f2c48d | 2022-04-22 12:39:57 | [diff] [blame] | 955 | |
Garrett Tanzer | c69f464 | 2022-08-15 22:15:14 | [diff] [blame] | 956 | // If this is a fenced frame resulting from a urn:uuid navigation, this |
| 957 | // contains all the metadata specifying the resulting context. |
Alison Gale | 770f3fc | 2024-04-27 00:39:58 | [diff] [blame] | 958 | // TODO(crbug.com/40202462): Move this into the FrameTree once ShadowDOM |
Garrett Tanzer | 34cb92fe | 2022-09-28 17:50:54 | [diff] [blame] | 959 | // and urn iframes are gone. |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 960 | std::optional<FencedFrameProperties> fenced_frame_properties_; |
Garrett Tanzer | c69f464 | 2022-08-15 22:15:14 | [diff] [blame] | 961 | |
Mingyu Lei | 7956b8b | 2023-07-24 08:24:08 | [diff] [blame] | 962 | // The tracker of the task that restarts the BFCache navigation. It might be |
| 963 | // used to cancel the task. |
| 964 | // See `CancelRestartingBackForwardCacheNavigation()`. |
| 965 | base::CancelableTaskTracker restart_back_forward_cached_navigation_tracker_; |
| 966 | |
Andrew Verge | 7233e66 | 2025-05-13 13:09:23 | [diff] [blame] | 967 | // The last successfully committed origin in this frame. Set in two scenarios: |
| 968 | // 1. By RenderFrameHostImpl::DidNavigate() when a navigation in this frame |
| 969 | // succeeds. |
| 970 | // 2. By RenderFrameHostImpl::SetOriginDependentStateOfNewFrame() when a new |
| 971 | // frame is first created, which will reflect the origin of the initial |
| 972 | // about::blank document before any navigation has committed. |
| 973 | url::Origin last_successful_origin_; |
| 974 | |
Lukasz Anforowicz | 14714196 | 2020-12-16 18:03:24 | [diff] [blame] | 975 | // Manages creation and swapping of RenderFrameHosts for this frame. |
| 976 | // |
| 977 | // This field needs to be declared last, because destruction of |
| 978 | // RenderFrameHostManager may call arbitrary callbacks (e.g. via |
| 979 | // WebContentsObserver::DidFinishNavigation fired after RenderFrameHostManager |
| 980 | // destructs a RenderFrameHostImpl and its NavigationRequest). Such callbacks |
| 981 | // may try to use FrameTreeNode's fields above - this would be an undefined |
| 982 | // behavior if the fields (even trivially-destructible ones) were destructed |
| 983 | // before the RenderFrameHostManager's destructor runs. See also |
| 984 | // https://crbug.com/1157988. |
| 985 | RenderFrameHostManager render_manager_; |
Mingyu Lei | 7956b8b | 2023-07-24 08:24:08 | [diff] [blame] | 986 | |
| 987 | base::WeakPtrFactory<FrameTreeNode> weak_factory_{this}; |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 988 | }; |
| 989 | |
| 990 | } // namespace content |
| 991 | |
| 992 | #endif // CONTENT_BROWSER_RENDERER_HOST_FRAME_TREE_NODE_H_ |