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