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