blob: ce5eb1309e48ed6636e924220bd820e2e24d9dd1 [file] [log] [blame]
danakjc492bf82020-09-09 20:02:441// 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"
15#include "base/macros.h"
16#include "base/memory/ref_counted.h"
17#include "content/browser/renderer_host/frame_tree.h"
18#include "content/browser/renderer_host/frame_tree_node_blame_context.h"
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"
22#include "content/common/content_export.h"
danakjc492bf82020-09-09 20:02:4423#include "services/network/public/mojom/content_security_policy.mojom-forward.h"
Lei Zhang698df03c2021-05-21 04:23:3424#include "third_party/abseil-cpp/absl/types/optional.h"
danakjc492bf82020-09-09 20:02:4425#include "third_party/blink/public/common/frame/frame_policy.h"
26#include "third_party/blink/public/common/frame/user_activation_state.h"
27#include "third_party/blink/public/mojom/frame/frame_owner_element_type.mojom.h"
28#include "third_party/blink/public/mojom/frame/frame_owner_properties.mojom.h"
Gyuyoung Kimc16e52e92021-03-19 02:45:3729#include "third_party/blink/public/mojom/frame/frame_replication_state.mojom-forward.h"
Daniel Cheng6ac128172021-05-25 18:49:0130#include "third_party/blink/public/mojom/frame/tree_scope_type.mojom.h"
danakjc492bf82020-09-09 20:02:4431#include "third_party/blink/public/mojom/frame/user_activation_update_types.mojom.h"
32#include "third_party/blink/public/mojom/security_context/insecure_request_policy.mojom-forward.h"
33
34#include "url/gurl.h"
35#include "url/origin.h"
36
37namespace content {
38
39class NavigationRequest;
40class RenderFrameHostImpl;
41class NavigationEntryImpl;
42
43// When a page contains iframes, its renderer process maintains a tree structure
44// of those frames. We are mirroring this tree in the browser process. This
45// class represents a node in this tree and is a wrapper for all objects that
46// are frame-specific (as opposed to page-specific).
47//
48// Each FrameTreeNode has a current RenderFrameHost, which can change over
49// time as the frame is navigated. Any immediate subframes of the current
50// document are tracked using FrameTreeNodes owned by the current
51// RenderFrameHost, rather than as children of FrameTreeNode itself. This
52// allows subframe FrameTreeNodes to stay alive while a RenderFrameHost is
53// still alive - for example while pending deletion, after a new current
54// RenderFrameHost has replaced it.
55class CONTENT_EXPORT FrameTreeNode {
56 public:
57 class Observer {
58 public:
59 // Invoked when a FrameTreeNode is being destroyed.
60 virtual void OnFrameTreeNodeDestroyed(FrameTreeNode* node) {}
61
62 // Invoked when a FrameTreeNode becomes focused.
63 virtual void OnFrameTreeNodeFocused(FrameTreeNode* node) {}
64
Fergal Dalya1d569972021-03-16 03:24:5365 virtual ~Observer() = default;
danakjc492bf82020-09-09 20:02:4466 };
67
68 static const int kFrameTreeNodeInvalidId;
69
70 // Returns the FrameTreeNode with the given global |frame_tree_node_id|,
71 // regardless of which FrameTree it is in.
72 static FrameTreeNode* GloballyFindByID(int frame_tree_node_id);
73
74 // Returns the FrameTreeNode for the given |rfh|. Same as
75 // rfh->frame_tree_node(), but also supports nullptrs.
76 static FrameTreeNode* From(RenderFrameHost* rfh);
77
78 // Callers are are expected to initialize sandbox flags separately after
79 // calling the constructor.
80 FrameTreeNode(
81 FrameTree* frame_tree,
82 RenderFrameHostImpl* parent,
Daniel Cheng6ac128172021-05-25 18:49:0183 blink::mojom::TreeScopeType tree_scope_type,
danakjc492bf82020-09-09 20:02:4484 const std::string& name,
85 const std::string& unique_name,
86 bool is_created_by_script,
87 const base::UnguessableToken& devtools_frame_token,
88 const blink::mojom::FrameOwnerProperties& frame_owner_properties,
89 blink::mojom::FrameOwnerElementType owner_type);
90
91 ~FrameTreeNode();
92
93 void AddObserver(Observer* observer);
94 void RemoveObserver(Observer* observer);
95
96 bool IsMainFrame() const;
97
arthursonzogni76098e52020-11-25 14:18:4598 // Clears any state in this node which was set by the document itself (CSP &
99 // UserActivationState) and notifies proxies as appropriate. Invoked after
100 // committing navigation to a new document (since the new document comes with
101 // a fresh set of CSP).
102 // TODO(arthursonzogni): Remove this function. The frame/document must not be
103 // left temporarily with lax state.
Hiroki Nakagawaab309622021-05-19 16:38:13104 void ResetForNavigation();
danakjc492bf82020-09-09 20:02:44105
106 FrameTree* frame_tree() const { return frame_tree_; }
107 Navigator& navigator() { return frame_tree()->navigator(); }
108
109 RenderFrameHostManager* render_manager() { return &render_manager_; }
110 int frame_tree_node_id() const { return frame_tree_node_id_; }
Antonio Sartori90f41212021-01-22 10:08:34111 const std::string& frame_name() const { return replication_state_->name; }
danakjc492bf82020-09-09 20:02:44112
113 const std::string& unique_name() const {
Antonio Sartori90f41212021-01-22 10:08:34114 return replication_state_->unique_name;
danakjc492bf82020-09-09 20:02:44115 }
116
117 // See comment on the member declaration.
118 const base::UnguessableToken& devtools_frame_token() const {
119 return devtools_frame_token_;
120 }
121
122 size_t child_count() const { return current_frame_host()->child_count(); }
123
124 unsigned int depth() const { return depth_; }
125
126 RenderFrameHostImpl* parent() const { return parent_; }
127
128 FrameTreeNode* opener() const { return opener_; }
129
130 FrameTreeNode* original_opener() const { return original_opener_; }
131
Anton Bikineevf62d1bf2021-05-15 17:56:07132 const absl::optional<base::UnguessableToken>& opener_devtools_frame_token() {
Wolfgang Beyerd8809db2020-09-30 15:29:39133 return opener_devtools_frame_token_;
134 }
135
danakjc492bf82020-09-09 20:02:44136 // Gets the total number of descendants to this FrameTreeNode in addition to
137 // this node.
138 size_t GetFrameTreeSize() const;
139
140 // Assigns a new opener for this node and, if |opener| is non-null, registers
141 // an observer that will clear this node's opener if |opener| is ever
142 // destroyed.
143 void SetOpener(FrameTreeNode* opener);
144
145 // Assigns the initial opener for this node, and if |opener| is non-null,
146 // registers an observer that will clear this node's opener if |opener| is
147 // ever destroyed. The value set here is the root of the tree.
148 //
149 // It is not possible to change the opener once it was set.
150 void SetOriginalOpener(FrameTreeNode* opener);
151
Wolfgang Beyerd8809db2020-09-30 15:29:39152 // Assigns an opener frame id for this node. This string id is only set once
153 // and cannot be changed. It persists, even if the |opener| is destroyed. It
154 // is used for attribution in the DevTools frontend.
155 void SetOpenerDevtoolsFrameToken(
156 base::UnguessableToken opener_devtools_frame_token);
157
danakjc492bf82020-09-09 20:02:44158 FrameTreeNode* child_at(size_t index) const {
159 return current_frame_host()->child_at(index);
160 }
161
162 // Returns the URL of the last committed page in the current frame.
163 const GURL& current_url() const {
164 return current_frame_host()->GetLastCommittedURL();
165 }
166
167 // Sets the last committed URL for this frame and updates
168 // has_committed_real_load accordingly.
169 void SetCurrentURL(const GURL& url);
170
Rakina Zata Amnifc4cc3d42021-06-10 09:03:56171 // Returns true if SetCurrentURL has been called with a non-blank URL.
172 // TODO(https://crbug.com/1215096): Migrate most usage of
173 // has_committed_real_load() to call
174 // is_on_initial_empty_document_or_subsequent_empty_documents() instead.
danakjc492bf82020-09-09 20:02:44175 bool has_committed_real_load() const { return has_committed_real_load_; }
176
Rakina Zata Amnifc4cc3d42021-06-10 09:03:56177 // Returns true if SetCurrentURL has been called with a non-blank URL or
178 // if the current document's input stream has been opened with
179 // document.open(). For more details, see the definition of
180 // `is_on_initial_empty_document_or_subsequent_empty_documents_`.
181 bool is_on_initial_empty_document_or_subsequent_empty_documents() const {
182 return is_on_initial_empty_document_or_subsequent_empty_documents_;
183 }
184
185 // Sets `is_on_initial_empty_document_or_subsequent_empty_documents_` to
186 // false. Must only be called after the current document's input stream has
187 // been opened with document.open().
188 void DidOpenDocumentInputStream() {
189 is_on_initial_empty_document_or_subsequent_empty_documents_ = false;
190 }
Rakina Zata Amnid09b6112021-06-05 06:20:14191
danakjc492bf82020-09-09 20:02:44192 // Returns whether the frame's owner element in the parent document is
193 // collapsed, that is, removed from the layout as if it did not exist, as per
194 // request by the embedder (of the content/ layer).
195 bool is_collapsed() const { return is_collapsed_; }
196
197 // Sets whether to collapse the frame's owner element in the parent document,
198 // that is, to remove it from the layout as if it did not exist, as per
199 // request by the embedder (of the content/ layer). Cannot be called for main
200 // frames.
201 //
202 // This only has an effect for <iframe> owner elements, and is a no-op when
203 // called on sub-frames hosted in <frame>, <object>, and <embed> elements.
204 void SetCollapsed(bool collapsed);
205
206 // Returns the origin of the last committed page in this frame.
207 // WARNING: To get the last committed origin for a particular
208 // RenderFrameHost, use RenderFrameHost::GetLastCommittedOrigin() instead,
209 // which will behave correctly even when the RenderFrameHost is not the
210 // current one for this frame (such as when it's pending deletion).
211 const url::Origin& current_origin() const {
Antonio Sartori90f41212021-01-22 10:08:34212 return replication_state_->origin;
danakjc492bf82020-09-09 20:02:44213 }
214
215 // Set the current origin and notify proxies about the update.
216 void SetCurrentOrigin(const url::Origin& origin,
217 bool is_potentially_trustworthy_unique_origin);
218
219 // Set the current name and notify proxies about the update.
220 void SetFrameName(const std::string& name, const std::string& unique_name);
221
danakjc492bf82020-09-09 20:02:44222 // Sets the current insecure request policy, and notifies proxies about the
223 // update.
224 void SetInsecureRequestPolicy(blink::mojom::InsecureRequestPolicy policy);
225
226 // Sets the current set of insecure urls to upgrade, and notifies proxies
227 // about the update.
228 void SetInsecureNavigationsSet(
229 const std::vector<uint32_t>& insecure_navigations_set);
230
231 // Returns the latest frame policy (sandbox flags and container policy) for
232 // this frame. This includes flags inherited from parent frames and the latest
233 // flags from the <iframe> element hosting this frame. The returned policies
234 // may not yet have taken effect, since "sandbox" and "allow" attribute
235 // updates in an <iframe> element take effect on next navigation. To retrieve
236 // the currently active policy for this frame, use effective_frame_policy().
237 const blink::FramePolicy& pending_frame_policy() const {
238 return pending_frame_policy_;
239 }
240
241 // Update this frame's sandbox flags and container policy. This is called
242 // when a parent frame updates the "sandbox" attribute in the <iframe> element
243 // for this frame, or any of the attributes which affect the container policy
244 // ("allowfullscreen", "allowpaymentrequest", "allow", and "src".)
245 // These policies won't take effect until next navigation. If this frame's
246 // parent is itself sandboxed, the parent's sandbox flags are combined with
247 // those in |frame_policy|.
248 // Attempting to change the container policy on the main frame will have no
249 // effect.
250 void SetPendingFramePolicy(blink::FramePolicy frame_policy);
251
252 // Returns the currently active frame policy for this frame, including the
253 // sandbox flags which were present at the time the document was loaded, and
Charlie Hu5130d25e2021-03-05 21:53:39254 // the permissions policy container policy, which is set by the iframe's
danakjc492bf82020-09-09 20:02:44255 // allowfullscreen, allowpaymentrequest, and allow attributes, along with the
256 // origin of the iframe's src attribute (which may be different from the URL
257 // of the document currently loaded into the frame). This does not include
258 // policy changes that have been made by updating the containing iframe
259 // element attributes since the frame was last navigated; use
260 // pending_frame_policy() for those.
261 const blink::FramePolicy& effective_frame_policy() const {
Antonio Sartori90f41212021-01-22 10:08:34262 return replication_state_->frame_policy;
danakjc492bf82020-09-09 20:02:44263 }
264
265 // Set the frame_policy provided in function parameter as active frame policy,
266 // while leaving pending_frame_policy_ untouched.
267 bool CommitFramePolicy(const blink::FramePolicy& frame_policy);
268
269 const blink::mojom::FrameOwnerProperties& frame_owner_properties() {
270 return frame_owner_properties_;
271 }
272
273 void set_frame_owner_properties(
274 const blink::mojom::FrameOwnerProperties& frame_owner_properties) {
275 frame_owner_properties_ = frame_owner_properties;
276 }
277
278 const network::mojom::ContentSecurityPolicy* csp_attribute() {
279 return csp_attribute_.get();
280 }
281
282 void set_csp_attribute(
283 network::mojom::ContentSecurityPolicyPtr parsed_csp_attribute) {
284 csp_attribute_ = std::move(parsed_csp_attribute);
285 }
286
287 bool HasSameOrigin(const FrameTreeNode& node) const {
Antonio Sartori90f41212021-01-22 10:08:34288 return replication_state_->origin.IsSameOriginWith(
289 node.replication_state_->origin);
danakjc492bf82020-09-09 20:02:44290 }
291
Gyuyoung Kimc16e52e92021-03-19 02:45:37292 const blink::mojom::FrameReplicationState& current_replication_state() const {
Antonio Sartori90f41212021-01-22 10:08:34293 return *replication_state_;
danakjc492bf82020-09-09 20:02:44294 }
295
296 RenderFrameHostImpl* current_frame_host() const {
297 return render_manager_.current_frame_host();
298 }
299
300 // Return the node immediately preceding this node in its parent's children,
301 // or nullptr if there is no such node.
302 FrameTreeNode* PreviousSibling() const;
303
304 // Return the node immediately following this node in its parent's children,
305 // or nullptr if there is no such node.
306 FrameTreeNode* NextSibling() const;
307
308 // Returns true if this node is in a loading state.
309 bool IsLoading() const;
310
Alex Moshchuk9b0fd822020-10-26 23:08:15311 // Returns true if this node has a cross-document navigation in progress.
312 bool HasPendingCrossDocumentNavigation() const;
313
danakjc492bf82020-09-09 20:02:44314 NavigationRequest* navigation_request() { return navigation_request_.get(); }
315
316 // Transfers the ownership of the NavigationRequest to |render_frame_host|.
317 // From ReadyToCommit to DidCommit, the NavigationRequest is owned by the
318 // RenderFrameHost that is committing the navigation.
319 void TransferNavigationRequestOwnership(
320 RenderFrameHostImpl* render_frame_host);
321
322 // Takes ownership of |navigation_request| and makes it the current
323 // NavigationRequest of this frame. This corresponds to the start of a new
324 // navigation. If there was an ongoing navigation request before calling this
325 // function, it is canceled. |navigation_request| should not be null.
326 void CreatedNavigationRequest(
327 std::unique_ptr<NavigationRequest> navigation_request);
328
329 // Resets the current navigation request. If |keep_state| is true, any state
330 // created by the NavigationRequest (e.g. speculative RenderFrameHost,
331 // loading state) will not be reset by the function.
332 void ResetNavigationRequest(bool keep_state);
333
334 // A RenderFrameHost in this node started loading.
335 // |to_different_document| will be true unless the load is a fragment
336 // navigation, or triggered by history.pushState/replaceState.
337 // |was_previously_loading| is false if the FrameTree was not loading before.
338 // The caller is required to provide this boolean as the delegate should only
339 // be notified if the FrameTree went from non-loading to loading state.
340 // However, when it is called, the FrameTree should be in a loading state.
341 void DidStartLoading(bool to_different_document, bool was_previously_loading);
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
383 void OnSetHadStickyUserActivationBeforeNavigation(bool value);
384
385 // Returns the sandbox flags currently in effect for this frame. This includes
386 // flags inherited from parent frames, the currently active flags from the
387 // <iframe> element hosting this frame, as well as any flags set from a
388 // Content-Security-Policy HTTP header. This does not include flags that have
389 // have been updated in an <iframe> element but have not taken effect yet; use
390 // pending_frame_policy() for those. To see the flags which will take effect
391 // on navigation (which does not include the CSP-set flags), use
392 // effective_frame_policy().
393 network::mojom::WebSandboxFlags active_sandbox_flags() const {
Antonio Sartori90f41212021-01-22 10:08:34394 return replication_state_->active_sandbox_flags;
danakjc492bf82020-09-09 20:02:44395 }
396
397 // Updates the active sandbox flags in this frame, in response to a
398 // Content-Security-Policy header adding additional flags, in addition to
399 // those given to this frame by its parent, or in response to the
Charlie Hu5130d25e2021-03-05 21:53:39400 // Permissions-Policy header being set. Note that on navigation, these updates
danakjc492bf82020-09-09 20:02:44401 // will be cleared, and the flags in the pending frame policy will be applied
402 // to the frame.
Alexander Timin45b716c2020-11-06 01:40:31403 // Returns true iff this operation has changed state of either sandbox flags
Charlie Hu5130d25e2021-03-05 21:53:39404 // or permissions policy.
Alexander Timin45b716c2020-11-06 01:40:31405 bool UpdateFramePolicyHeaders(
danakjc492bf82020-09-09 20:02:44406 network::mojom::WebSandboxFlags sandbox_flags,
Charlie Hue24f04832021-03-04 21:07:06407 const blink::ParsedPermissionsPolicy& parsed_header);
danakjc492bf82020-09-09 20:02:44408
409 // Returns whether the frame received a user gesture on a previous navigation
410 // on the same eTLD+1.
411 bool has_received_user_gesture_before_nav() const {
Antonio Sartori90f41212021-01-22 10:08:34412 return replication_state_->has_received_user_gesture_before_nav;
danakjc492bf82020-09-09 20:02:44413 }
414
415 // When a tab is discarded, WebContents sets was_discarded on its
416 // root FrameTreeNode.
417 // In addition, when a child frame is created, this bit is passed on from
418 // parent to child.
419 // When a navigation request is created, was_discarded is passed on to the
420 // request and reset to false in FrameTreeNode.
421 void set_was_discarded() { was_discarded_ = true; }
422 bool was_discarded() const { return was_discarded_; }
423
424 // Returns the sticky bit of the User Activation v2 state of the
425 // |FrameTreeNode|.
426 bool HasStickyUserActivation() const {
427 return user_activation_state_.HasBeenActive();
428 }
429
430 // Returns the transient bit of the User Activation v2 state of the
431 // |FrameTreeNode|.
432 bool HasTransientUserActivation() {
433 return user_activation_state_.IsActive();
434 }
435
436 // Remove history entries for all frames created by script in this frame's
437 // subtree. If a frame created by a script is removed, then its history entry
438 // will never be reused - this saves memory.
439 void PruneChildFrameNavigationEntries(NavigationEntryImpl* entry);
440
441 blink::mojom::FrameOwnerElementType frame_owner_element_type() const {
Daniel Cheng9bd90f92021-04-23 20:49:45442 return frame_owner_element_type_;
danakjc492bf82020-09-09 20:02:44443 }
danakjc492bf82020-09-09 20:02:44444
Daniel Cheng6ac128172021-05-25 18:49:01445 blink::mojom::TreeScopeType tree_scope_type() const {
446 return tree_scope_type_;
447 }
448
Alex Turner10d557a42021-06-01 19:06:49449 void SetIsAdSubframe(bool is_ad_subframe);
danakjc492bf82020-09-09 20:02:44450
arthursonzogni034bb9c2020-10-01 08:29:56451 // The initial popup URL for new window opened using:
452 // `window.open(initial_popup_url)`.
453 // An empty GURL otherwise.
454 //
455 // [WARNING] There is no guarantee the FrameTreeNode will ever host a
456 // document served from this URL. The FrameTreeNode always starts hosting the
457 // initial empty document and attempts a navigation toward this URL. However
458 // the navigation might be delayed, redirected and even cancelled.
459 void SetInitialPopupURL(const GURL& initial_popup_url);
460 const GURL& initial_popup_url() const { return initial_popup_url_; }
461
462 // The origin of the document that used window.open() to create this frame.
463 // Otherwise, an opaque Origin with a nonce different from all previously
464 // existing Origins.
465 void SetPopupCreatorOrigin(const url::Origin& popup_creator_origin);
466 const url::Origin& popup_creator_origin() const {
467 return popup_creator_origin_;
468 }
469
Harkiran Bolaria59290d62021-03-17 01:53:01470 // Sets the associated FrameTree for this node. The node can change FrameTrees
471 // when blink::features::Prerender2 is enabled, which allows a page loaded in
472 // the prerendered FrameTree to be used for a navigation in the primary frame
473 // tree.
474 void SetFrameTree(FrameTree& frame_tree);
475
Alexander Timinf785f342021-03-18 00:00:56476 // Write a representation of this object into a trace.
Alexander Timinbebb2002021-04-20 15:42:24477 void WriteIntoTrace(perfetto::TracedValue context) const;
Alexander Timinf785f342021-03-18 00:00:56478
Carlos Caballero76711352021-03-24 17:38:21479 // Returns true the node is navigating, i.e. it has an associated
480 // NavigationRequest.
481 bool HasNavigation();
482
danakjc492bf82020-09-09 20:02:44483 private:
Charlie Hubb5943d2021-03-09 19:46:12484 FRIEND_TEST_ALL_PREFIXES(SitePerProcessPermissionsPolicyBrowserTest,
danakjc492bf82020-09-09 20:02:44485 ContainerPolicyDynamic);
Charlie Hubb5943d2021-03-09 19:46:12486 FRIEND_TEST_ALL_PREFIXES(SitePerProcessPermissionsPolicyBrowserTest,
danakjc492bf82020-09-09 20:02:44487 ContainerPolicySandboxDynamic);
488
489 class OpenerDestroyedObserver;
490
491 FrameTreeNode* GetSibling(int relative_offset) const;
492
493 // The |notification_type| parameter is used for histograms only.
494 bool NotifyUserActivation(
495 blink::mojom::UserActivationNotificationType notification_type);
496
497 bool ConsumeTransientUserActivation();
498
499 bool ClearUserActivation();
500
501 // Verify that the renderer process is allowed to set user activation on this
502 // frame by checking whether this frame's RenderWidgetHost had previously seen
503 // an input event that might lead to user activation. If user activation
504 // should be allowed, this returns true and also clears corresponding pending
505 // user activation state in the widget. Otherwise, this returns false.
506 bool VerifyUserActivation();
507
508 // The next available browser-global FrameTreeNode ID.
509 static int next_frame_tree_node_id_;
510
511 // The FrameTree that owns us.
512 FrameTree* frame_tree_; // not owned.
513
danakjc492bf82020-09-09 20:02:44514 // A browser-global identifier for the frame in the page, which stays stable
515 // even if the frame does a cross-process navigation.
516 const int frame_tree_node_id_;
517
518 // The RenderFrameHost owning this FrameTreeNode, which cannot change for the
519 // life of this FrameTreeNode. |nullptr| if this node is the root.
520 RenderFrameHostImpl* const parent_;
521
522 // Number of edges from this node to the root. 0 if this is the root.
523 const unsigned int depth_;
524
525 // The frame that opened this frame, if any. Will be set to null if the
526 // opener is closed, or if this frame disowns its opener by setting its
527 // window.opener to null.
arthursonzogni9816b9192021-03-29 16:09:19528 FrameTreeNode* opener_ = nullptr;
danakjc492bf82020-09-09 20:02:44529
530 // An observer that clears this node's |opener_| if the opener is destroyed.
531 // This observer is added to the |opener_|'s observer list when the |opener_|
532 // is set to a non-null node, and it is removed from that list when |opener_|
533 // changes or when this node is destroyed. It is also cleared if |opener_|
534 // is disowned.
535 std::unique_ptr<OpenerDestroyedObserver> opener_observer_;
536
537 // The frame that opened this frame, if any. Contrary to opener_, this
538 // cannot be changed unless the original opener is destroyed.
arthursonzogni9816b9192021-03-29 16:09:19539 FrameTreeNode* original_opener_ = nullptr;
danakjc492bf82020-09-09 20:02:44540
Wolfgang Beyerd8809db2020-09-30 15:29:39541 // The devtools frame token of the frame which opened this frame. This is
542 // not cleared even if the opener is destroyed or disowns the frame.
Anton Bikineevf62d1bf2021-05-15 17:56:07543 absl::optional<base::UnguessableToken> opener_devtools_frame_token_;
Wolfgang Beyerd8809db2020-09-30 15:29:39544
danakjc492bf82020-09-09 20:02:44545 // An observer that clears this node's |original_opener_| if the opener is
546 // destroyed.
547 std::unique_ptr<OpenerDestroyedObserver> original_opener_observer_;
548
arthursonzogni034bb9c2020-10-01 08:29:56549 // When created by an opener, the URL specified in window.open(url)
550 // Please refer to {Get,Set}InitialPopupURL() documentation.
551 GURL initial_popup_url_;
552
553 // When created using window.open, the origin of the creator.
554 // Please refer to {Get,Set}PopupCreatorOrigin() documentation.
555 url::Origin popup_creator_origin_;
556
Rakina Zata Amnifc4cc3d42021-06-10 09:03:56557 // Returns true iff SetCurrentURL has been called with a non-blank URL.
558 // TODO(https://crbug.com/1215096): Migrate all current usage of this to
559 // use `is_on_initial_empty_document_or_subsequent_empty_documents_` instead.
560 bool has_committed_real_load_ = false;
561
562 // Whether this frame is still on the initial about:blank document or any
563 // subsequent about:blank documents committed after the initial about:blank
564 // document. This will be false if either of these has happened:
Rakina Zata Amnid09b6112021-06-05 06:20:14565 // - SetCurrentUrl() has been called with a non about:blank URL.
566 // - The document's input stream has been opened with document.open().
567 // See:
568 // https://html.spec.whatwg.org/multipage/dynamic-markup-insertion.html#opening-the-input-stream:is-initial-about:blank
Rakina Zata Amnifc4cc3d42021-06-10 09:03:56569 // TODO(https://crbug.com/1215096): Make this false after non-initial
Rakina Zata Amnid09b6112021-06-05 06:20:14570 // about:blank commits as well, making this only track whether the current
Rakina Zata Amnifc4cc3d42021-06-10 09:03:56571 // document is the initial empty document or not. Currently we are still
572 // preserving most of the old behavior of `has_committed_real_load_` (except
573 // for the document.open() bit here) due to our current handling of initial
574 // empty document for session history and navigation (where we treat the
575 // the initial about:blank document and subsequent about:blank documents the
576 // same way).
577 bool is_on_initial_empty_document_or_subsequent_empty_documents_ = true;
danakjc492bf82020-09-09 20:02:44578
579 // Whether the frame's owner element in the parent document is collapsed.
arthursonzogni9816b9192021-03-29 16:09:19580 bool is_collapsed_ = false;
danakjc492bf82020-09-09 20:02:44581
Daniel Cheng6ac128172021-05-25 18:49:01582 // The type of frame owner for this frame. This is only relevant for non-main
583 // frames.
Daniel Cheng9bd90f92021-04-23 20:49:45584 const blink::mojom::FrameOwnerElementType frame_owner_element_type_ =
585 blink::mojom::FrameOwnerElementType::kNone;
586
Daniel Cheng6ac128172021-05-25 18:49:01587 // The tree scope type of frame owner element, i.e. whether the element is in
588 // the document tree (https://dom.spec.whatwg.org/#document-trees) or the
589 // shadow tree (https://dom.spec.whatwg.org/#shadow-trees). This is only
590 // relevant for non-main frames.
591 const blink::mojom::TreeScopeType tree_scope_type_ =
592 blink::mojom::TreeScopeType::kDocument;
593
danakjc492bf82020-09-09 20:02:44594 // Track information that needs to be replicated to processes that have
595 // proxies for this frame.
Gyuyoung Kimc16e52e92021-03-19 02:45:37596 blink::mojom::FrameReplicationStatePtr replication_state_;
danakjc492bf82020-09-09 20:02:44597
598 // Track the pending sandbox flags and container policy for this frame. When a
599 // parent frame dynamically updates 'sandbox', 'allow', 'allowfullscreen',
600 // 'allowpaymentrequest' or 'src' attributes, the updated policy for the frame
Antonio Sartori90f41212021-01-22 10:08:34601 // is stored here, and transferred into replication_state_->frame_policy when
danakjc492bf82020-09-09 20:02:44602 // they take effect on the next frame navigation.
603 blink::FramePolicy pending_frame_policy_;
604
605 // Whether the frame was created by javascript. This is useful to prune
606 // history entries when the frame is removed (because frames created by
607 // scripts are never recreated with the same unique name - see
608 // https://crbug.com/500260).
arthursonzogni9816b9192021-03-29 16:09:19609 const bool is_created_by_script_;
danakjc492bf82020-09-09 20:02:44610
611 // Used for devtools instrumentation and trace-ability. The token is
612 // propagated to Blink's LocalFrame and both Blink and content/
613 // can tag calls and requests with this token in order to attribute them
614 // to the context frame.
615 // |devtools_frame_token_| is only defined by the browser process and is never
616 // sent back from the renderer in the control calls. It should be never used
617 // to look up the FrameTreeNode instance.
arthursonzogni9816b9192021-03-29 16:09:19618 const base::UnguessableToken devtools_frame_token_;
danakjc492bf82020-09-09 20:02:44619
620 // Tracks the scrolling and margin properties for this frame. These
621 // properties affect the child renderer but are stored on its parent's
622 // frame element. When this frame's parent dynamically updates these
623 // properties, we update them here too.
624 //
625 // Note that dynamic updates only take effect on the next frame navigation.
626 blink::mojom::FrameOwnerProperties frame_owner_properties_;
627
628 // Contains the current parsed value of the 'csp' attribute of this frame.
629 network::mojom::ContentSecurityPolicyPtr csp_attribute_;
630
631 // Owns an ongoing NavigationRequest until it is ready to commit. It will then
632 // be reset and a RenderFrameHost will be responsible for the navigation.
633 std::unique_ptr<NavigationRequest> navigation_request_;
634
635 // List of objects observing this FrameTreeNode.
636 base::ObserverList<Observer>::Unchecked observers_;
637
638 base::TimeTicks last_focus_time_;
639
arthursonzogni9816b9192021-03-29 16:09:19640 bool was_discarded_ = false;
danakjc492bf82020-09-09 20:02:44641
642 // The user activation state of the current frame. See |UserActivationState|
643 // for details on how this state is maintained.
644 blink::UserActivationState user_activation_state_;
645
646 // A helper for tracing the snapshots of this FrameTreeNode and attributing
647 // browser process activities to this node (when possible). It is unrelated
648 // to the core logic of FrameTreeNode.
649 FrameTreeNodeBlameContext blame_context_;
650
Lukasz Anforowicz147141962020-12-16 18:03:24651 // Manages creation and swapping of RenderFrameHosts for this frame.
652 //
653 // This field needs to be declared last, because destruction of
654 // RenderFrameHostManager may call arbitrary callbacks (e.g. via
655 // WebContentsObserver::DidFinishNavigation fired after RenderFrameHostManager
656 // destructs a RenderFrameHostImpl and its NavigationRequest). Such callbacks
657 // may try to use FrameTreeNode's fields above - this would be an undefined
658 // behavior if the fields (even trivially-destructible ones) were destructed
659 // before the RenderFrameHostManager's destructor runs. See also
660 // https://crbug.com/1157988.
661 RenderFrameHostManager render_manager_;
662
danakjc492bf82020-09-09 20:02:44663 DISALLOW_COPY_AND_ASSIGN(FrameTreeNode);
664};
665
666} // namespace content
667
668#endif // CONTENT_BROWSER_RENDERER_HOST_FRAME_TREE_NODE_H_