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