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