blob: ac13436447da875ab111a162c3a4ad775fff5712 [file] [log] [blame]
[email protected]9b159a52013-10-03 17:24:551// 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
danakjc492bf82020-09-09 20:02:445#include "content/browser/renderer_host/frame_tree_node.h"
[email protected]9b159a52013-10-03 17:24:556
Daniel Cheng6ca7f1c92017-08-09 21:45:417#include <math.h>
[email protected]9b159a52013-10-03 17:24:558#include <queue>
Takuto Ikutaadf31eb2019-01-05 00:32:489#include <unordered_map>
dcheng36b6aec92015-12-26 06:16:3610#include <utility>
[email protected]9b159a52013-10-03 17:24:5511
Mustaq Ahmeda5dfa60b2018-12-08 00:30:1412#include "base/feature_list.h"
scottmg6ece5ae2017-02-01 18:25:1913#include "base/lazy_instance.h"
Keishi Hattori0e45c022021-11-27 09:25:5214#include "base/memory/raw_ptr.h"
Liviu Tintad9391fb92020-09-28 23:50:0715#include "base/metrics/histogram_functions.h"
dcheng23ca947d2016-05-04 20:04:1516#include "base/metrics/histogram_macros.h"
David Sandersd4bf5eb2022-03-17 07:12:0517#include "base/observer_list.h"
Clark DuVallc97bcf72021-12-08 22:58:2418#include "base/strings/strcat.h"
Daniel Cheng6ca7f1c92017-08-09 21:45:4119#include "base/strings/string_util.h"
Clark DuVallc97bcf72021-12-08 22:58:2420#include "base/timer/elapsed_timer.h"
Andrey Kosyakovf2d4ff72018-10-29 20:09:5921#include "content/browser/devtools/devtools_instrumentation.h"
Dominic Farolino8a2187b2021-12-24 20:44:2122#include "content/browser/fenced_frame/fenced_frame.h"
danakjc492bf82020-09-09 20:02:4423#include "content/browser/renderer_host/navigation_controller_impl.h"
24#include "content/browser/renderer_host/navigation_request.h"
25#include "content/browser/renderer_host/navigator.h"
26#include "content/browser/renderer_host/navigator_delegate.h"
27#include "content/browser/renderer_host/render_frame_host_impl.h"
[email protected]94d0cc12013-12-18 00:07:4128#include "content/browser/renderer_host/render_view_host_impl.h"
Lucas Furukawa Gadanief8290a2019-07-29 20:27:5129#include "content/common/navigation_params_utils.h"
dmazzonie950ea232015-03-13 21:39:4530#include "content/public/browser/browser_thread.h"
Nan Linaaf84f72021-12-02 22:31:5631#include "content/public/browser/site_isolation_policy.h"
Mustaq Ahmeda5dfa60b2018-12-08 00:30:1432#include "content/public/common/content_features.h"
arthursonzognib93a4472020-04-10 07:38:0033#include "services/network/public/cpp/web_sandbox_flags.h"
34#include "services/network/public/mojom/web_sandbox_flags.mojom-shared.h"
Harkiran Bolaria59290d62021-03-17 01:53:0135#include "third_party/blink/public/common/features.h"
Sreeja Kamishetty0be3b1b2021-08-12 17:04:1536#include "third_party/blink/public/common/loader/loader_constants.h"
Antonio Gomes4b2c5132020-01-16 11:49:4837#include "third_party/blink/public/mojom/frame/user_activation_update_types.mojom.h"
Julie Jeongeun Kimd90e2dd2020-03-03 11:45:3738#include "third_party/blink/public/mojom/security_context/insecure_request_policy.mojom.h"
[email protected]9b159a52013-10-03 17:24:5539
40namespace content {
41
dmazzonie950ea232015-03-13 21:39:4542namespace {
43
44// This is a global map between frame_tree_node_ids and pointers to
45// FrameTreeNodes.
Takuto Ikutaadf31eb2019-01-05 00:32:4846typedef std::unordered_map<int, FrameTreeNode*> FrameTreeNodeIdMap;
dmazzonie950ea232015-03-13 21:39:4547
scottmg5e65e3a2017-03-08 08:48:4648base::LazyInstance<FrameTreeNodeIdMap>::DestructorAtExit
49 g_frame_tree_node_id_map = LAZY_INSTANCE_INITIALIZER;
dmazzonie950ea232015-03-13 21:39:4550
Nan Line376738a2022-03-25 22:05:4151FencedFrame* FindFencedFrame(const FrameTreeNode* frame_tree_node) {
52 // TODO(crbug.com/1123606): Consider having a pointer to `FencedFrame` in
53 // `FrameTreeNode` or having a map between them.
54
55 // Try and find the `FencedFrame` that `frame_tree_node` represents.
56 DCHECK(frame_tree_node->parent());
57 std::vector<FencedFrame*> fenced_frames =
58 frame_tree_node->parent()->GetFencedFrames();
59 for (FencedFrame* fenced_frame : fenced_frames) {
60 if (frame_tree_node->frame_tree_node_id() ==
61 fenced_frame->GetOuterDelegateFrameTreeNodeId()) {
62 return fenced_frame;
63 }
64 }
65 return nullptr;
66}
67
fdegansa696e5112015-04-17 01:57:5968} // namespace
fdegans1d16355162015-03-26 11:58:3469
alexmose201c7cd2015-06-10 17:14:2170// This observer watches the opener of its owner FrameTreeNode and clears the
71// owner's opener if the opener is destroyed.
72class FrameTreeNode::OpenerDestroyedObserver : public FrameTreeNode::Observer {
73 public:
jochen6004a362017-02-04 00:11:4074 OpenerDestroyedObserver(FrameTreeNode* owner, bool observing_original_opener)
75 : owner_(owner), observing_original_opener_(observing_original_opener) {}
alexmose201c7cd2015-06-10 17:14:2176
Peter Boström9b036532021-10-28 23:37:2877 OpenerDestroyedObserver(const OpenerDestroyedObserver&) = delete;
78 OpenerDestroyedObserver& operator=(const OpenerDestroyedObserver&) = delete;
79
alexmose201c7cd2015-06-10 17:14:2180 // FrameTreeNode::Observer
81 void OnFrameTreeNodeDestroyed(FrameTreeNode* node) override {
jochen6004a362017-02-04 00:11:4082 if (observing_original_opener_) {
Avi Drissman36465f332017-09-11 20:49:3983 // The "original owner" is special. It's used for attribution, and clients
84 // walk down the original owner chain. Therefore, if a link in the chain
85 // is being destroyed, reconnect the observation to the parent of the link
86 // being destroyed.
jochen6004a362017-02-04 00:11:4087 CHECK_EQ(owner_->original_opener(), node);
Avi Drissman36465f332017-09-11 20:49:3988 owner_->SetOriginalOpener(node->original_opener());
89 // |this| is deleted at this point.
jochen6004a362017-02-04 00:11:4090 } else {
91 CHECK_EQ(owner_->opener(), node);
92 owner_->SetOpener(nullptr);
Avi Drissman36465f332017-09-11 20:49:3993 // |this| is deleted at this point.
jochen6004a362017-02-04 00:11:4094 }
alexmose201c7cd2015-06-10 17:14:2195 }
96
97 private:
Keishi Hattori0e45c022021-11-27 09:25:5298 raw_ptr<FrameTreeNode> owner_;
jochen6004a362017-02-04 00:11:4099 bool observing_original_opener_;
alexmose201c7cd2015-06-10 17:14:21100};
101
Kevin McNee88e61552020-10-22 20:41:11102const int FrameTreeNode::kFrameTreeNodeInvalidId = -1;
103
104static_assert(FrameTreeNode::kFrameTreeNodeInvalidId ==
105 RenderFrameHost::kNoFrameTreeNodeId,
106 "Have consistent sentinel values for an invalid FTN id.");
107
vishal.b782eb5d2015-04-29 12:22:57108int FrameTreeNode::next_frame_tree_node_id_ = 1;
[email protected]9b159a52013-10-03 17:24:55109
dmazzonie950ea232015-03-13 21:39:45110// static
vishal.b782eb5d2015-04-29 12:22:57111FrameTreeNode* FrameTreeNode::GloballyFindByID(int frame_tree_node_id) {
mostynb366eaf12015-03-26 00:51:19112 DCHECK_CURRENTLY_ON(BrowserThread::UI);
rob97250742015-12-10 17:45:15113 FrameTreeNodeIdMap* nodes = g_frame_tree_node_id_map.Pointer();
jdoerrie55ec69d2018-10-08 13:34:46114 auto it = nodes->find(frame_tree_node_id);
dmazzonie950ea232015-03-13 21:39:45115 return it == nodes->end() ? nullptr : it->second;
116}
117
Alexander Timin381e7e182020-04-28 19:04:03118// static
119FrameTreeNode* FrameTreeNode::From(RenderFrameHost* rfh) {
120 if (!rfh)
121 return nullptr;
122 return static_cast<RenderFrameHostImpl*>(rfh)->frame_tree_node();
123}
124
Julie Jeongeun Kim70a2e4e2020-02-21 05:09:54125FrameTreeNode::FrameTreeNode(
126 FrameTree* frame_tree,
Alexander Timin381e7e182020-04-28 19:04:03127 RenderFrameHostImpl* parent,
Daniel Cheng6ac128172021-05-25 18:49:01128 blink::mojom::TreeScopeType tree_scope_type,
Julie Jeongeun Kim70a2e4e2020-02-21 05:09:54129 bool is_created_by_script,
130 const base::UnguessableToken& devtools_frame_token,
131 const blink::mojom::FrameOwnerProperties& frame_owner_properties,
Kevin McNee43fe8292021-10-04 22:59:41132 blink::FrameOwnerElementType owner_type,
Dominic Farolino08662c82021-06-11 07:36:34133 const blink::FramePolicy& frame_policy)
[email protected]bffc8302014-01-23 20:52:16134 : frame_tree_(frame_tree),
[email protected]bffc8302014-01-23 20:52:16135 frame_tree_node_id_(next_frame_tree_node_id_++),
xiaochengh98488162016-05-19 15:17:59136 parent_(parent),
Daniel Cheng9bd90f92021-04-23 20:49:45137 frame_owner_element_type_(owner_type),
Daniel Cheng6ac128172021-05-25 18:49:01138 tree_scope_type_(tree_scope_type),
Dominic Farolino08662c82021-06-11 07:36:34139 pending_frame_policy_(frame_policy),
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45140 is_created_by_script_(is_created_by_script),
Pavel Feldman25234722017-10-11 02:49:06141 devtools_frame_token_(devtools_frame_token),
lazyboy70605c32015-11-03 01:27:31142 frame_owner_properties_(frame_owner_properties),
Lukasz Anforowicz147141962020-12-16 18:03:24143 blame_context_(frame_tree_node_id_, FrameTreeNode::From(parent)),
Harkiran Bolaria0b3bdef02022-03-10 13:04:40144 render_manager_(this, frame_tree->manager_delegate()) {
rob97250742015-12-10 17:45:15145 std::pair<FrameTreeNodeIdMap::iterator, bool> result =
dmazzonie950ea232015-03-13 21:39:45146 g_frame_tree_node_id_map.Get().insert(
147 std::make_pair(frame_tree_node_id_, this));
148 CHECK(result.second);
benjhaydend4da63d2016-03-11 21:29:33149
xiaochenghb9554bb2016-05-21 14:20:48150 // Note: this should always be done last in the constructor.
151 blame_context_.Initialize();
alexmos998581d2015-01-22 01:01:59152}
[email protected]9b159a52013-10-03 17:24:55153
Dominic Farolino8a2187b2021-12-24 20:44:21154void FrameTreeNode::DestroyInnerFrameTreeIfExists() {
155 // If `this` is an dummy outer delegate node, then we really are representing
156 // an inner FrameTree for one of the following consumers:
157 // - `Portal`
158 // - `FencedFrame`
159 // - `GuestView`
160 // If we are representing a `FencedFrame` object, we need to destroy it
161 // alongside ourself. `Portals` and `GuestView` however, *currently* have a
162 // more complex lifetime and are dealt with separately.
163 bool is_outer_dummy_node = false;
164 if (current_frame_host() &&
165 current_frame_host()->inner_tree_main_frame_tree_node_id() !=
166 FrameTreeNode::kFrameTreeNodeInvalidId) {
167 is_outer_dummy_node = true;
168 }
169
170 if (is_outer_dummy_node) {
Nan Line376738a2022-03-25 22:05:41171 FencedFrame* doomed_fenced_frame = FindFencedFrame(this);
Dominic Farolino8a2187b2021-12-24 20:44:21172 // `doomed_fenced_frame` might not actually exist, because some outer dummy
173 // `FrameTreeNode`s might correspond to `Portal`s, which do not have their
174 // lifetime managed in the same way as `FencedFrames`.
175 if (doomed_fenced_frame) {
176 parent()->DestroyFencedFrame(*doomed_fenced_frame);
177 }
178 }
179}
180
[email protected]9b159a52013-10-03 17:24:55181FrameTreeNode::~FrameTreeNode() {
Daniel Chengc3d1e8d2021-06-23 02:11:45182 // There should always be a current RenderFrameHost except during prerender
183 // activation. Prerender activation moves the current RenderFrameHost from
184 // the old FrameTree's FrameTreeNode to the new FrameTree's FrameTreeNode and
185 // then destroys the old FrameTree. See
186 // `RenderFrameHostManager::TakePrerenderedPage()`.
Harkiran Bolaria59290d62021-03-17 01:53:01187 if (current_frame_host()) {
188 // Remove the children.
189 current_frame_host()->ResetChildren();
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45190
Harkiran Bolaria59290d62021-03-17 01:53:01191 current_frame_host()->ResetLoadingState();
192 } else {
Hiroki Nakagawa0a90bd42021-04-21 01:53:05193 DCHECK(blink::features::IsPrerender2Enabled());
Harkiran Bolaria59290d62021-03-17 01:53:01194 DCHECK(!parent()); // Only main documents can be activated.
195 DCHECK(!opener()); // Prerendered frame trees can't have openers.
196
197 // Activation is not allowed during ongoing navigations.
198 DCHECK(!navigation_request_);
199
Carlos Caballerod1c80432021-04-20 08:16:32200 // TODO(https://crbug.com/1199693): Need to determine how to handle pending
Harkiran Bolaria59290d62021-03-17 01:53:01201 // deletions, as observers will be notified.
202 DCHECK(!render_manager()->speculative_frame_host());
203 }
Nate Chapin22ea6592019-03-05 22:29:02204
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45205 // If the removed frame was created by a script, then its history entry will
206 // never be reused - we can save some memory by removing the history entry.
207 // See also https://crbug.com/784356.
208 if (is_created_by_script_ && parent_) {
Carlos Caballero04aab362021-02-15 17:38:16209 NavigationEntryImpl* nav_entry =
210 navigator().controller().GetLastCommittedEntry();
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45211 if (nav_entry) {
212 nav_entry->RemoveEntryForFrame(this,
213 /* only_if_different_position = */ false);
214 }
215 }
216
dmazzonie950ea232015-03-13 21:39:45217 frame_tree_->FrameRemoved(this);
Carlos Caballero6ff6ace2021-02-05 16:53:00218
Dominic Farolino8a2187b2021-12-24 20:44:21219 DestroyInnerFrameTreeIfExists();
220
Carlos Caballero6ff6ace2021-02-05 16:53:00221 // Do not dispatch notification for the root frame as ~WebContentsImpl already
222 // dispatches it for now.
223 // TODO(https://crbug.com/1170277): This is only needed because the FrameTree
224 // is a member of WebContentsImpl and we would call back into it during
225 // destruction. We should clean up the FrameTree destruction code and call the
226 // delegate unconditionally.
227 if (parent())
228 render_manager_.delegate()->OnFrameTreeNodeDestroyed(this);
229
ericwilligers254597b2016-10-17 10:32:31230 for (auto& observer : observers_)
231 observer.OnFrameTreeNodeDestroyed(this);
Lukasz Anforowicz147141962020-12-16 18:03:24232 observers_.Clear();
alexmose201c7cd2015-06-10 17:14:21233
234 if (opener_)
235 opener_->RemoveObserver(opener_observer_.get());
jochen6004a362017-02-04 00:11:40236 if (original_opener_)
237 original_opener_->RemoveObserver(original_opener_observer_.get());
dmazzonie950ea232015-03-13 21:39:45238
239 g_frame_tree_node_id_map.Get().erase(frame_tree_node_id_);
jam39258caf2016-11-02 14:48:18240
Daniel Chengc3d1e8d2021-06-23 02:11:45241 // If a frame with a pending navigation is detached, make sure the
242 // WebContents (and its observers) update their loading state.
243 // TODO(dcheng): This should just check `IsLoading()`, but `IsLoading()`
244 // assumes that `current_frame_host_` is not null. This is incompatible with
245 // prerender activation when destroying the old frame tree (see above).
danakjf9400602019-06-07 15:44:58246 bool did_stop_loading = false;
247
jam39258caf2016-11-02 14:48:18248 if (navigation_request_) {
danakjf9400602019-06-07 15:44:58249 navigation_request_.reset();
danakjf9400602019-06-07 15:44:58250 did_stop_loading = true;
jam39258caf2016-11-02 14:48:18251 }
Nate Chapin22ea6592019-03-05 22:29:02252
danakjf9400602019-06-07 15:44:58253 // ~SiteProcessCountTracker DCHECKs in some tests if the speculative
254 // RenderFrameHostImpl is not destroyed last. Ideally this would be closer to
255 // (possible before) the ResetLoadingState() call above.
danakjf9400602019-06-07 15:44:58256 if (render_manager_.speculative_frame_host()) {
Daniel Chengc3d1e8d2021-06-23 02:11:45257 // TODO(dcheng): Shouldn't a FrameTreeNode with a speculative
258 // RenderFrameHost always be considered loading?
danakjf9400602019-06-07 15:44:58259 did_stop_loading |= render_manager_.speculative_frame_host()->is_loading();
Daniel Chengc3d1e8d2021-06-23 02:11:45260 // `FrameTree::Shutdown()` has special handling for the main frame's
261 // speculative RenderFrameHost, and the speculative RenderFrameHost should
262 // already be reset for main frames.
263 DCHECK(!IsMainFrame());
264
265 // This does not use `UnsetSpeculativeRenderFrameHost()`: if the speculative
266 // RenderFrameHost has already reached kPendingCommit, it would needlessly
267 // re-create a proxy for a frame that's going away.
268 render_manager_.DiscardSpeculativeRenderFrameHostForShutdown();
danakjf9400602019-06-07 15:44:58269 }
270
271 if (did_stop_loading)
272 DidStopLoading();
273
Harkiran Bolaria59290d62021-03-17 01:53:01274 // IsLoading() requires that current_frame_host() is non-null.
275 DCHECK(!current_frame_host() || !IsLoading());
[email protected]9b159a52013-10-03 17:24:55276}
277
alexmose201c7cd2015-06-10 17:14:21278void FrameTreeNode::AddObserver(Observer* observer) {
279 observers_.AddObserver(observer);
280}
281
282void FrameTreeNode::RemoveObserver(Observer* observer) {
283 observers_.RemoveObserver(observer);
284}
285
[email protected]94d0cc12013-12-18 00:07:41286bool FrameTreeNode::IsMainFrame() const {
287 return frame_tree_->root() == this;
288}
289
Hiroki Nakagawaab309622021-05-19 16:38:13290void FrameTreeNode::ResetForNavigation() {
arthursonzogni76098e52020-11-25 14:18:45291 // This frame has had its user activation bits cleared in the renderer before
292 // arriving here. We just need to clear them here and in the other renderer
293 // processes that may have a reference to this frame.
Alexander Timin45b716c2020-11-06 01:40:31294 //
295 // We do not take user activation into account when calculating
296 // |ResetForNavigationResult|, as we are using it to determine bfcache
297 // eligibility and the page can get another user gesture after restore.
Antonio Gomes4b2c5132020-01-16 11:49:48298 UpdateUserActivationState(
Mustaq Ahmeddc195e5b2020-08-04 18:45:11299 blink::mojom::UserActivationUpdateType::kClearActivation,
300 blink::mojom::UserActivationNotificationType::kNone);
Ian Clelland5cbaaf82017-11-27 22:00:03301}
302
Dave Tapuskac8de3b02021-12-03 21:51:01303RenderFrameHostImpl* FrameTreeNode::GetParentOrOuterDocument() {
304 return GetParentOrOuterDocumentHelper(/*escape_guest_view=*/false);
305}
306
307RenderFrameHostImpl* FrameTreeNode::GetParentOrOuterDocumentOrEmbedder() {
308 return GetParentOrOuterDocumentHelper(/*escape_guest_view=*/true);
309}
310
311RenderFrameHostImpl* FrameTreeNode::GetParentOrOuterDocumentHelper(
312 bool escape_guest_view) {
313 // Find the parent in the FrameTree (iframe).
314 if (parent_)
315 return parent_;
316
317 if (!escape_guest_view) {
318 // If we are not a fenced frame root nor inside a portal then return early.
319 // This code does not escape GuestViews.
320 if (!IsFencedFrameRoot() && !frame_tree_->delegate()->IsPortal())
321 return nullptr;
322 }
323
324 // Find the parent in the outer embedder (GuestView, Portal, or Fenced Frame).
325 FrameTreeNode* frame_in_embedder = render_manager()->GetOuterDelegateNode();
326 if (frame_in_embedder)
327 return frame_in_embedder->current_frame_host()->GetParent();
328
329 // No parent found.
330 return nullptr;
331}
332
Julie Jeongeun Kimf38c1eca2021-12-14 07:46:55333FrameType FrameTreeNode::GetFrameType() const {
334 if (!IsMainFrame())
335 return FrameType::kSubframe;
336
337 switch (frame_tree()->type()) {
338 case FrameTree::Type::kPrimary:
339 return FrameType::kPrimaryMainFrame;
340 case FrameTree::Type::kPrerender:
341 return FrameType::kPrerenderMainFrame;
342 case FrameTree::Type::kFencedFrame:
343 // We also have FencedFramesImplementationType::kShadowDOM for a
344 // fenced frame implementation based on <iframe> + shadowDOM,
345 // which will return kSubframe as it's a modified <iframe> rather
346 // than a dedicated FrameTree. This returns kSubframe for the
347 // shadow dom implementation in order to keep consistency (i.e.
348 // NavigationHandle::GetParentFrame returning non-null value for
349 // shadow-dom based FFs).
350 return FrameType::kFencedFrameRoot;
351 }
352}
353
alexmose201c7cd2015-06-10 17:14:21354void FrameTreeNode::SetOpener(FrameTreeNode* opener) {
355 if (opener_) {
356 opener_->RemoveObserver(opener_observer_.get());
357 opener_observer_.reset();
358 }
359
360 opener_ = opener;
361
362 if (opener_) {
Jeremy Roman04f27c372017-10-27 15:20:55363 opener_observer_ = std::make_unique<OpenerDestroyedObserver>(this, false);
alexmose201c7cd2015-06-10 17:14:21364 opener_->AddObserver(opener_observer_.get());
365 }
366}
367
Wolfgang Beyerd8809db2020-09-30 15:29:39368void FrameTreeNode::SetOpenerDevtoolsFrameToken(
369 base::UnguessableToken opener_devtools_frame_token) {
370 DCHECK(!opener_devtools_frame_token_ ||
371 opener_devtools_frame_token_->is_empty());
372 opener_devtools_frame_token_ = std::move(opener_devtools_frame_token);
373}
374
jochen6004a362017-02-04 00:11:40375void FrameTreeNode::SetOriginalOpener(FrameTreeNode* opener) {
Avi Drissman36465f332017-09-11 20:49:39376 // The original opener tracks main frames only.
avi8d1aa162017-03-27 18:27:37377 DCHECK(opener == nullptr || !opener->parent());
jochen6004a362017-02-04 00:11:40378
Avi Drissman36465f332017-09-11 20:49:39379 if (original_opener_) {
380 original_opener_->RemoveObserver(original_opener_observer_.get());
381 original_opener_observer_.reset();
382 }
383
jochen6004a362017-02-04 00:11:40384 original_opener_ = opener;
385
386 if (original_opener_) {
jochen6004a362017-02-04 00:11:40387 original_opener_observer_ =
Jeremy Roman04f27c372017-10-27 15:20:55388 std::make_unique<OpenerDestroyedObserver>(this, true);
jochen6004a362017-02-04 00:11:40389 original_opener_->AddObserver(original_opener_observer_.get());
390 }
391}
392
creisf0f069a2015-07-23 23:51:53393void FrameTreeNode::SetCurrentURL(const GURL& url) {
Erik Chen173bf3042017-07-31 06:06:21394 current_frame_host()->SetLastCommittedUrl(url);
xiaochenghb9554bb2016-05-21 14:20:48395 blame_context_.TakeSnapshot();
creisf0f069a2015-07-23 23:51:53396}
397
engedy6e2e0992017-05-25 18:58:42398void FrameTreeNode::SetCollapsed(bool collapsed) {
Dave Tapuska65e50aa2022-03-09 23:44:13399 DCHECK(!IsMainFrame() || IsFencedFrameRoot());
engedy6e2e0992017-05-25 18:58:42400 if (is_collapsed_ == collapsed)
401 return;
402
403 is_collapsed_ = collapsed;
404 render_manager_.OnDidChangeCollapsedState(collapsed);
405}
406
Harkiran Bolaria59290d62021-03-17 01:53:01407void FrameTreeNode::SetFrameTree(FrameTree& frame_tree) {
Hiroki Nakagawa0a90bd42021-04-21 01:53:05408 DCHECK(blink::features::IsPrerender2Enabled());
Harkiran Bolaria59290d62021-03-17 01:53:01409 frame_tree_ = &frame_tree;
Kevin McNeeb110d0c2021-10-26 15:53:00410 DCHECK(current_frame_host());
411 current_frame_host()->SetFrameTree(frame_tree);
412 RenderFrameHostImpl* speculative_frame_host =
413 render_manager_.speculative_frame_host();
414 if (speculative_frame_host)
415 speculative_frame_host->SetFrameTree(frame_tree);
Harkiran Bolaria59290d62021-03-17 01:53:01416}
417
Luna Luc3fdacdf2017-11-08 04:48:53418void FrameTreeNode::SetPendingFramePolicy(blink::FramePolicy frame_policy) {
Dominic Farolinobfd1f0292022-03-23 19:12:24419 // The `is_fenced` and `fenced_frame_mode` bits should never be able to
420 // transition from their initial values. Since we never expect to be in a
421 // position where it can even be updated to new value, if we catch this
422 // happening we have to kill the renderer and refuse to accept any other frame
423 // policy changes here.
424 if (pending_frame_policy_.is_fenced != frame_policy.is_fenced ||
425 pending_frame_policy_.fenced_frame_mode !=
426 frame_policy.fenced_frame_mode) {
Dominic Farolino08662c82021-06-11 07:36:34427 mojo::ReportBadMessage(
Dominic Farolinobfd1f0292022-03-23 19:12:24428 "FramePolicy properties dealing with fenced frames are considered "
429 "immutable, and therefore should never be changed by the renderer.");
Dominic Farolino08662c82021-06-11 07:36:34430 return;
431 }
432
Ian Clellandcdc4f312017-10-13 22:24:12433 pending_frame_policy_.sandbox_flags = frame_policy.sandbox_flags;
alexmos6e940102016-01-19 22:47:25434
Ian Clellandcdc4f312017-10-13 22:24:12435 if (parent()) {
436 // Subframes should always inherit their parent's sandbox flags.
Alexander Timin381e7e182020-04-28 19:04:03437 pending_frame_policy_.sandbox_flags |=
Harkiran Bolaria4eacb3a2021-12-13 20:03:47438 parent()->browsing_context_state()->active_sandbox_flags();
Charlie Hue1b77ac2019-12-13 21:30:17439 // This is only applied on subframes; container policy and required document
440 // policy are not mutable on main frame.
Ian Clellandcdc4f312017-10-13 22:24:12441 pending_frame_policy_.container_policy = frame_policy.container_policy;
Charlie Hue1b77ac2019-12-13 21:30:17442 pending_frame_policy_.required_document_policy =
443 frame_policy.required_document_policy;
Ian Clellandcdc4f312017-10-13 22:24:12444 }
iclelland92f8c0b2017-04-19 12:43:05445}
446
fdegans4a49ce932015-03-12 17:11:37447bool FrameTreeNode::IsLoading() const {
448 RenderFrameHostImpl* current_frame_host =
449 render_manager_.current_frame_host();
fdegans4a49ce932015-03-12 17:11:37450
451 DCHECK(current_frame_host);
fdegans39ff0382015-04-29 19:04:39452
clamy610c63b32017-12-22 15:05:18453 if (navigation_request_)
454 return true;
clamy11e11512015-07-07 16:42:17455
clamy610c63b32017-12-22 15:05:18456 RenderFrameHostImpl* speculative_frame_host =
457 render_manager_.speculative_frame_host();
Daniel Chengc3d1e8d2021-06-23 02:11:45458 // TODO(dcheng): Shouldn't a FrameTreeNode with a speculative RenderFrameHost
459 // always be considered loading?
clamy610c63b32017-12-22 15:05:18460 if (speculative_frame_host && speculative_frame_host->is_loading())
461 return true;
fdegans4a49ce932015-03-12 17:11:37462 return current_frame_host->is_loading();
463}
464
Alex Moshchuk9b0fd822020-10-26 23:08:15465bool FrameTreeNode::HasPendingCrossDocumentNavigation() const {
466 // Having a |navigation_request_| on FrameTreeNode implies that there's an
467 // ongoing navigation that hasn't reached the ReadyToCommit state. If the
468 // navigation is between ReadyToCommit and DidCommitNavigation, the
469 // NavigationRequest will be held by RenderFrameHost, which is checked below.
470 if (navigation_request_ && !navigation_request_->IsSameDocument())
471 return true;
472
473 // Having a speculative RenderFrameHost should imply a cross-document
474 // navigation.
475 if (render_manager_.speculative_frame_host())
476 return true;
477
478 return render_manager_.current_frame_host()
479 ->HasPendingCommitForCrossDocumentNavigation();
480}
481
Arthur Hemeryc3380172018-01-22 14:00:17482void FrameTreeNode::TransferNavigationRequestOwnership(
483 RenderFrameHostImpl* render_frame_host) {
Andrey Kosyakovf2d4ff72018-10-29 20:09:59484 devtools_instrumentation::OnResetNavigationRequest(navigation_request_.get());
Arthur Hemeryc3380172018-01-22 14:00:17485 render_frame_host->SetNavigationRequest(std::move(navigation_request_));
486}
487
carloskc49005eb2015-06-16 11:25:07488void FrameTreeNode::CreatedNavigationRequest(
dcheng9bfa5162016-04-09 01:00:57489 std::unique_ptr<NavigationRequest> navigation_request) {
arthursonzognic79c251c2016-08-18 15:00:37490 // This is never called when navigating to a Javascript URL. For the loading
491 // state, this matches what Blink is doing: Blink doesn't send throbber
492 // notifications for Javascript URLS.
493 DCHECK(!navigation_request->common_params().url.SchemeIs(
494 url::kJavaScriptScheme));
495
Sreeja Kamishetty15f9944a22022-03-10 10:16:08496 bool was_previously_loading = frame_tree()->LoadingTree()->IsLoading();
clamy44e84ce2016-02-22 15:38:25497
clamy82a2f4d2016-02-02 14:20:41498 // There's no need to reset the state: there's still an ongoing load, and the
499 // RenderFrameHostManager will take care of updates to the speculative
500 // RenderFrameHost in DidCreateNavigationRequest below.
jamcd0b7b22017-03-24 22:13:05501 if (was_previously_loading) {
Mohamed Abdelhalimf03d4a22019-10-01 13:34:31502 if (navigation_request_ && navigation_request_->IsNavigationStarted()) {
jamcd0b7b22017-03-24 22:13:05503 // Mark the old request as aborted.
Mohamed Abdelhalimb4db22a2019-06-18 10:46:52504 navigation_request_->set_net_error(net::ERR_ABORTED);
jamcd0b7b22017-03-24 22:13:05505 }
Arthur Hemery241b9392019-10-24 11:08:41506 ResetNavigationRequest(true);
jamcd0b7b22017-03-24 22:13:05507 }
clamy44e84ce2016-02-22 15:38:25508
509 navigation_request_ = std::move(navigation_request);
Shubhie Panickerddf2a4e2018-03-06 00:09:06510 if (was_discarded_) {
511 navigation_request_->set_was_discarded();
512 was_discarded_ = false;
513 }
clamy8e2e299202016-04-05 11:44:59514 render_manager()->DidCreateNavigationRequest(navigation_request_.get());
fdegans39ff0382015-04-29 19:04:39515
Lucas Furukawa Gadanief8290a2019-07-29 20:27:51516 bool to_different_document = !NavigationTypeUtils::IsSameDocument(
arthursonzogni92f18682017-02-08 23:00:04517 navigation_request_->common_params().navigation_type);
518
519 DidStartLoading(to_different_document, was_previously_loading);
clamydcb434c12015-04-16 19:29:16520}
521
Arthur Hemery241b9392019-10-24 11:08:41522void FrameTreeNode::ResetNavigationRequest(bool keep_state) {
fdegans39ff0382015-04-29 19:04:39523 if (!navigation_request_)
524 return;
John Abd-El-Malekdcc7bf42017-09-12 22:30:23525
Andrey Kosyakovf2d4ff72018-10-29 20:09:59526 devtools_instrumentation::OnResetNavigationRequest(navigation_request_.get());
clamydcb434c12015-04-16 19:29:16527 navigation_request_.reset();
fdegans39ff0382015-04-29 19:04:39528
clamy82a2f4d2016-02-02 14:20:41529 if (keep_state)
fdegans39ff0382015-04-29 19:04:39530 return;
531
clamy82a2f4d2016-02-02 14:20:41532 // The RenderFrameHostManager should clean up any speculative RenderFrameHost
533 // it created for the navigation. Also register that the load stopped.
fdegans39ff0382015-04-29 19:04:39534 DidStopLoading();
535 render_manager_.CleanUpNavigation();
clamydcb434c12015-04-16 19:29:16536}
537
Nate Chapin9aabf5f2021-11-12 00:31:19538void FrameTreeNode::DidStartLoading(bool should_show_loading_ui,
clamy44e84ce2016-02-22 15:38:25539 bool was_previously_loading) {
Camille Lamyefd54b02018-10-04 16:54:14540 TRACE_EVENT2("navigation", "FrameTreeNode::DidStartLoading",
Nate Chapin9aabf5f2021-11-12 00:31:19541 "frame_tree_node", frame_tree_node_id(),
542 "should_show_loading_ui ", should_show_loading_ui);
Clark DuVallc97bcf72021-12-08 22:58:24543 base::ElapsedTimer timer;
fdegansa696e5112015-04-17 01:57:59544
Sreeja Kamishetty15f9944a22022-03-10 10:16:08545 frame_tree()->LoadingTree()->DidStartLoadingNode(
546 *this, should_show_loading_ui, was_previously_loading);
fdegansa696e5112015-04-17 01:57:59547
548 // Set initial load progress and update overall progress. This will notify
549 // the WebContents of the load progress change.
Sreeja Kamishetty15f9944a22022-03-10 10:16:08550 //
551 // Only notify when the load is triggered from primary/prerender main frame as
552 // we only update load progress for these nodes which happens when the frame
553 // tree matches the loading tree.
554 if (frame_tree() == frame_tree()->LoadingTree())
555 DidChangeLoadProgress(blink::kInitialLoadProgress);
fdegansa696e5112015-04-17 01:57:59556
Harkiran Bolaria3f83fba72022-03-10 17:48:40557 // Notify the proxies of the event.
558 current_frame_host()->browsing_context_state()->OnDidStartLoading();
Clark DuVallc97bcf72021-12-08 22:58:24559 base::UmaHistogramTimes(
560 base::StrCat({"Navigation.DidStartLoading.",
561 IsMainFrame() ? "MainFrame" : "Subframe"}),
562 timer.Elapsed());
fdegansa696e5112015-04-17 01:57:59563}
564
565void FrameTreeNode::DidStopLoading() {
Camille Lamyefd54b02018-10-04 16:54:14566 TRACE_EVENT1("navigation", "FrameTreeNode::DidStopLoading", "frame_tree_node",
567 frame_tree_node_id());
fdegansa696e5112015-04-17 01:57:59568 // Set final load progress and update overall progress. This will notify
569 // the WebContents of the load progress change.
Sreeja Kamishetty15f9944a22022-03-10 10:16:08570 //
571 // Only notify when the load is triggered from primary/prerender main frame as
572 // we only update load progress for these nodes which happens when the frame
573 // tree matches the loading tree.
574 if (frame_tree() == frame_tree()->LoadingTree())
575 DidChangeLoadProgress(blink::kFinalLoadProgress);
fdegansa696e5112015-04-17 01:57:59576
Harkiran Bolaria3f83fba72022-03-10 17:48:40577 // Notify the proxies of the event.
578 current_frame_host()->browsing_context_state()->OnDidStopLoading();
Lucas Furukawa Gadani6faef602019-05-06 21:16:03579
Sreeja Kamishetty15f9944a22022-03-10 10:16:08580 FrameTree* loading_tree = frame_tree()->LoadingTree();
581 // When loading tree is null, ignore invoking DidStopLoadingNode as the frame
582 // tree is already deleted. This can happen when prerendering gets cancelled
583 // and DidStopLoading is called during FrameTree destruction.
584 if (loading_tree)
585 loading_tree->DidStopLoadingNode(*this);
fdegansa696e5112015-04-17 01:57:59586}
587
588void FrameTreeNode::DidChangeLoadProgress(double load_progress) {
Sreeja Kamishetty0be3b1b2021-08-12 17:04:15589 DCHECK_GE(load_progress, blink::kInitialLoadProgress);
590 DCHECK_LE(load_progress, blink::kFinalLoadProgress);
591 current_frame_host()->DidChangeLoadProgress(load_progress);
fdegansa696e5112015-04-17 01:57:59592}
593
clamyf73862c42015-07-08 12:31:33594bool FrameTreeNode::StopLoading() {
arthursonzogni66f711c2019-10-08 14:40:36595 if (navigation_request_ && navigation_request_->IsNavigationStarted())
596 navigation_request_->set_net_error(net::ERR_ABORTED);
Arthur Hemery241b9392019-10-24 11:08:41597 ResetNavigationRequest(false);
clamyf73862c42015-07-08 12:31:33598
clamyf73862c42015-07-08 12:31:33599 if (!IsMainFrame())
600 return true;
601
602 render_manager_.Stop();
603 return true;
604}
605
alexmos21acae52015-11-07 01:04:43606void FrameTreeNode::DidFocus() {
607 last_focus_time_ = base::TimeTicks::Now();
ericwilligers254597b2016-10-17 10:32:31608 for (auto& observer : observers_)
609 observer.OnFrameTreeNodeFocused(this);
alexmos21acae52015-11-07 01:04:43610}
611
clamy44e84ce2016-02-22 15:38:25612void FrameTreeNode::BeforeUnloadCanceled() {
613 // TODO(clamy): Support BeforeUnload in subframes.
614 if (!IsMainFrame())
615 return;
616
617 RenderFrameHostImpl* current_frame_host =
618 render_manager_.current_frame_host();
619 DCHECK(current_frame_host);
620 current_frame_host->ResetLoadingState();
621
clamy610c63b32017-12-22 15:05:18622 RenderFrameHostImpl* speculative_frame_host =
623 render_manager_.speculative_frame_host();
624 if (speculative_frame_host)
625 speculative_frame_host->ResetLoadingState();
Alexander Timin23c110b2021-01-14 02:39:04626 // Note: there is no need to set an error code on the NavigationHandle as
627 // the observers have not been notified about its creation.
628 // We also reset navigation request only when this navigation request was
629 // responsible for this dialog, as a new navigation request might cancel
630 // existing unrelated dialog.
631 if (navigation_request_ && navigation_request_->IsWaitingForBeforeUnload())
Arthur Hemery241b9392019-10-24 11:08:41632 ResetNavigationRequest(false);
clamy44e84ce2016-02-22 15:38:25633}
634
Mustaq Ahmedecb5c38e2020-07-29 00:34:30635bool FrameTreeNode::NotifyUserActivation(
636 blink::mojom::UserActivationNotificationType notification_type) {
Garrett Tanzer753cc532022-03-02 21:30:59637 // User activation notifications shouldn't propagate into/out of fenced
638 // frames.
639 // For ShadowDOM, fenced frames are in the same frame tree as their embedder,
640 // so we need to perform additional checks to enforce the boundary.
641 // For MPArch, fenced frames have a separate frame tree, so this boundary is
642 // enforced by default.
643 // https://docs.google.com/document/d/1WnIhXOFycoje_sEoZR3Mo0YNSR2Ki7LABIC_HEWFaog
644 bool shadow_dom_fenced_frame_enabled =
645 blink::features::IsFencedFramesEnabled() &&
646 blink::features::IsFencedFramesShadowDOMBased();
647
Alex Moshchuk03904192021-04-02 07:29:08648 // User Activation V2 requires activating all ancestor frames in addition to
649 // the current frame. See
650 // https://html.spec.whatwg.org/multipage/interaction.html#tracking-user-activation.
Alexander Timina1dfadaa2020-04-28 13:30:06651 for (RenderFrameHostImpl* rfh = current_frame_host(); rfh;
652 rfh = rfh->GetParent()) {
John Delaneyb625dca92021-04-14 17:00:34653 rfh->DidReceiveUserActivation();
Mustaq Ahmedecb5c38e2020-07-29 00:34:30654 rfh->frame_tree_node()->user_activation_state_.Activate(notification_type);
Garrett Tanzer753cc532022-03-02 21:30:59655
656 if (shadow_dom_fenced_frame_enabled &&
657 rfh->frame_tree_node()->IsFencedFrameRoot()) {
658 break;
659 }
John Delaneyedd8d6c2019-01-25 00:23:57660 }
Alex Moshchuk03904192021-04-02 07:29:08661
Harkiran Bolaria0b3bdef02022-03-10 13:04:40662 current_frame_host()->browsing_context_state()->set_has_active_user_gesture(
663 true);
Mustaq Ahmeda5dfa60b2018-12-08 00:30:14664
Garrett Tanzer753cc532022-03-02 21:30:59665 absl::optional<base::UnguessableToken> originator_nonce =
666 fenced_frame_nonce();
667
Mustaq Ahmed0180320f2019-03-21 16:07:01668 // See the "Same-origin Visibility" section in |UserActivationState| class
669 // doc.
Mustaq Ahmede5f12562019-10-30 18:02:03670 if (base::FeatureList::IsEnabled(
Garrett Tanzer753cc532022-03-02 21:30:59671 features::kUserActivationSameOriginVisibility)) {
Mustaq Ahmeda5dfa60b2018-12-08 00:30:14672 const url::Origin& current_origin =
673 this->current_frame_host()->GetLastCommittedOrigin();
674 for (FrameTreeNode* node : frame_tree()->Nodes()) {
Garrett Tanzer753cc532022-03-02 21:30:59675 if (shadow_dom_fenced_frame_enabled &&
676 node->fenced_frame_nonce() != originator_nonce) {
677 continue;
678 }
679
Mustaq Ahmeda5dfa60b2018-12-08 00:30:14680 if (node->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith(
681 current_origin)) {
Mustaq Ahmedecb5c38e2020-07-29 00:34:30682 node->user_activation_state_.Activate(notification_type);
Mustaq Ahmeda5dfa60b2018-12-08 00:30:14683 }
684 }
685 }
686
Carlos Caballero40b0efd2021-01-26 11:55:00687 navigator().controller().NotifyUserActivation();
Alex Moshchuk03904192021-04-02 07:29:08688 current_frame_host()->MaybeIsolateForUserActivation();
Shivani Sharma194877032019-03-07 17:52:47689
Mustaq Ahmedc4cb7162018-06-05 16:28:36690 return true;
691}
692
693bool FrameTreeNode::ConsumeTransientUserActivation() {
Garrett Tanzer753cc532022-03-02 21:30:59694 // User activation consumptions shouldn't propagate into/out of fenced
695 // frames.
696 // For ShadowDOM, fenced frames are in the same frame tree as their embedder,
697 // so we need to perform additional checks to enforce the boundary.
698 // For MPArch, fenced frames have a separate frame tree, so this boundary is
699 // enforced by default.
700 // https://docs.google.com/document/d/1WnIhXOFycoje_sEoZR3Mo0YNSR2Ki7LABIC_HEWFaog
701 bool shadow_dom_fenced_frame_enabled =
702 blink::features::IsFencedFramesEnabled() &&
703 blink::features::IsFencedFramesShadowDOMBased();
704 absl::optional<base::UnguessableToken> originator_nonce =
705 fenced_frame_nonce();
706
Mustaq Ahmedc4cb7162018-06-05 16:28:36707 bool was_active = user_activation_state_.IsActive();
Garrett Tanzer753cc532022-03-02 21:30:59708 for (FrameTreeNode* node : frame_tree()->Nodes()) {
709 if (shadow_dom_fenced_frame_enabled &&
710 node->fenced_frame_nonce() != originator_nonce) {
711 continue;
712 }
713
Mustaq Ahmedc4cb7162018-06-05 16:28:36714 node->user_activation_state_.ConsumeIfActive();
Garrett Tanzer753cc532022-03-02 21:30:59715 }
Harkiran Bolaria0b3bdef02022-03-10 13:04:40716 current_frame_host()->browsing_context_state()->set_has_active_user_gesture(
717 false);
Mustaq Ahmedc4cb7162018-06-05 16:28:36718 return was_active;
719}
720
Shivani Sharmac4f561582018-11-15 15:58:39721bool FrameTreeNode::ClearUserActivation() {
Shivani Sharmac4f561582018-11-15 15:58:39722 for (FrameTreeNode* node : frame_tree()->SubtreeNodes(this))
723 node->user_activation_state_.Clear();
Harkiran Bolaria0b3bdef02022-03-10 13:04:40724 current_frame_host()->browsing_context_state()->set_has_active_user_gesture(
725 false);
Shivani Sharmac4f561582018-11-15 15:58:39726 return true;
727}
728
Ella Ge9caed612019-08-09 16:17:25729bool FrameTreeNode::VerifyUserActivation() {
Ella Gea78f6772019-12-11 10:35:25730 DCHECK(base::FeatureList::IsEnabled(
731 features::kBrowserVerifiedUserActivationMouse) ||
732 base::FeatureList::IsEnabled(
733 features::kBrowserVerifiedUserActivationKeyboard));
734
Ella Ge9caed612019-08-09 16:17:25735 return render_manager_.current_frame_host()
736 ->GetRenderWidgetHost()
Mustaq Ahmed83bb1722019-10-22 20:00:10737 ->RemovePendingUserActivationIfAvailable();
Ella Ge9caed612019-08-09 16:17:25738}
739
Mustaq Ahmedc4cb7162018-06-05 16:28:36740bool FrameTreeNode::UpdateUserActivationState(
Mustaq Ahmeddc195e5b2020-08-04 18:45:11741 blink::mojom::UserActivationUpdateType update_type,
742 blink::mojom::UserActivationNotificationType notification_type) {
Ella Ge9caed612019-08-09 16:17:25743 bool update_result = false;
Mustaq Ahmedc4cb7162018-06-05 16:28:36744 switch (update_type) {
Antonio Gomes4b2c5132020-01-16 11:49:48745 case blink::mojom::UserActivationUpdateType::kConsumeTransientActivation:
Ella Ge9caed612019-08-09 16:17:25746 update_result = ConsumeTransientUserActivation();
747 break;
Antonio Gomes4b2c5132020-01-16 11:49:48748 case blink::mojom::UserActivationUpdateType::kNotifyActivation:
Mustaq Ahmeddc195e5b2020-08-04 18:45:11749 update_result = NotifyUserActivation(notification_type);
Ella Ge9caed612019-08-09 16:17:25750 break;
Antonio Gomes4b2c5132020-01-16 11:49:48751 case blink::mojom::UserActivationUpdateType::
Liviu Tintad9391fb92020-09-28 23:50:07752 kNotifyActivationPendingBrowserVerification: {
753 const bool user_activation_verified = VerifyUserActivation();
754 // Add UMA metric for when browser user activation verification succeeds
755 base::UmaHistogramBoolean("Event.BrowserVerifiedUserActivation",
756 user_activation_verified);
757 if (user_activation_verified) {
Mustaq Ahmedecb5c38e2020-07-29 00:34:30758 update_result = NotifyUserActivation(
Mustaq Ahmed2cfb0402020-09-29 19:24:35759 blink::mojom::UserActivationNotificationType::kInteraction);
Antonio Gomes4b2c5132020-01-16 11:49:48760 update_type = blink::mojom::UserActivationUpdateType::kNotifyActivation;
Ella Ge9caed612019-08-09 16:17:25761 } else {
arthursonzogni9816b9192021-03-29 16:09:19762 // TODO(https://crbug.com/848778): We need to decide what to do when
763 // user activation verification failed. NOTREACHED here will make all
Ella Ge9caed612019-08-09 16:17:25764 // unrelated tests that inject event to renderer fail.
765 return false;
766 }
Liviu Tintad9391fb92020-09-28 23:50:07767 } break;
Antonio Gomes4b2c5132020-01-16 11:49:48768 case blink::mojom::UserActivationUpdateType::kClearActivation:
Ella Ge9caed612019-08-09 16:17:25769 update_result = ClearUserActivation();
770 break;
Mustaq Ahmedc4cb7162018-06-05 16:28:36771 }
Mustaq Ahmeddc195e5b2020-08-04 18:45:11772 render_manager_.UpdateUserActivationState(update_type, notification_type);
Ella Ge9caed612019-08-09 16:17:25773 return update_result;
japhet61835ae12017-01-20 01:25:39774}
775
Arthur Sonzognif8840b92018-11-07 14:10:35776void FrameTreeNode::PruneChildFrameNavigationEntries(
777 NavigationEntryImpl* entry) {
778 for (size_t i = 0; i < current_frame_host()->child_count(); ++i) {
779 FrameTreeNode* child = current_frame_host()->child_at(i);
780 if (child->is_created_by_script_) {
781 entry->RemoveEntryForFrame(child,
782 /* only_if_different_position = */ false);
783 } else {
784 child->PruneChildFrameNavigationEntries(entry);
785 }
786 }
787}
788
arthursonzogni034bb9c2020-10-01 08:29:56789void FrameTreeNode::SetInitialPopupURL(const GURL& initial_popup_url) {
790 DCHECK(initial_popup_url_.is_empty());
Rakina Zata Amni4182b032021-11-01 04:22:01791 DCHECK(is_on_initial_empty_document_);
arthursonzogni034bb9c2020-10-01 08:29:56792 initial_popup_url_ = initial_popup_url;
793}
794
795void FrameTreeNode::SetPopupCreatorOrigin(
796 const url::Origin& popup_creator_origin) {
Rakina Zata Amni4182b032021-11-01 04:22:01797 DCHECK(is_on_initial_empty_document_);
arthursonzogni034bb9c2020-10-01 08:29:56798 popup_creator_origin_ = popup_creator_origin;
799}
800
Rakina Zata Amni4b1968d2021-09-09 03:29:47801void FrameTreeNode::WriteIntoTrace(
Alexander Timin074cd182022-03-23 18:11:22802 perfetto::TracedProto<TraceProto> proto) const {
Rakina Zata Amni4b1968d2021-09-09 03:29:47803 proto->set_frame_tree_node_id(frame_tree_node_id());
Alexander Timin074cd182022-03-23 18:11:22804 proto->set_is_main_frame(IsMainFrame());
805 proto.Set(TraceProto::kCurrentFrameHost, current_frame_host());
806 proto.Set(TraceProto::kSpeculativeFrameHost,
807 render_manager()->speculative_frame_host());
Rakina Zata Amni4b1968d2021-09-09 03:29:47808}
809
Carlos Caballero76711352021-03-24 17:38:21810bool FrameTreeNode::HasNavigation() {
811 if (navigation_request())
812 return true;
813
814 // Same-RenderFrameHost navigation is committing:
815 if (current_frame_host()->HasPendingCommitNavigation())
816 return true;
817
818 // Cross-RenderFrameHost navigation is committing:
819 if (render_manager()->speculative_frame_host())
820 return true;
821
822 return false;
823}
824
Dominic Farolino4bc10ee2021-08-31 00:37:36825bool FrameTreeNode::IsFencedFrameRoot() const {
Harkiran Bolaria0b3bdef02022-03-10 13:04:40826 return current_frame_host()->IsFencedFrameRootNoStatus();
shivanigithubf3ddff52021-07-03 22:06:30827}
828
829bool FrameTreeNode::IsInFencedFrameTree() const {
Harkiran Bolaria0b3bdef02022-03-10 13:04:40830 return current_frame_host()->IsInFencedFrameTree();
shivanigithubf3ddff52021-07-03 22:06:30831}
832
shivanigithub4cd016a2021-09-20 21:10:30833void FrameTreeNode::SetFencedFrameNonceIfNeeded() {
834 if (!IsInFencedFrameTree()) {
835 return;
836 }
837
838 if (IsFencedFrameRoot()) {
839 fenced_frame_nonce_ = base::UnguessableToken::Create();
840 return;
841 }
842
843 // For nested iframes in a fenced frame tree, propagate the same nonce as was
844 // set in the fenced frame root.
845 DCHECK(parent_);
846 absl::optional<base::UnguessableToken> nonce =
847 parent_->frame_tree_node()->fenced_frame_nonce();
848 DCHECK(nonce.has_value());
849 fenced_frame_nonce_ = nonce;
850}
851
Nan Line376738a2022-03-25 22:05:41852absl::optional<blink::mojom::FencedFrameMode>
853FrameTreeNode::GetFencedFrameMode() {
Nan Lin171fe9a2022-02-17 16:42:16854 if (!IsFencedFrameRoot())
Nan Line376738a2022-03-25 22:05:41855 return absl::nullopt;
Nan Lin171fe9a2022-02-17 16:42:16856
Nan Line376738a2022-03-25 22:05:41857 if (blink::features::IsFencedFramesShadowDOMBased())
858 return pending_frame_policy_.fenced_frame_mode;
Nan Lin171fe9a2022-02-17 16:42:16859
Nan Line376738a2022-03-25 22:05:41860 FrameTreeNode* outer_delegate = render_manager()->GetOuterDelegateNode();
861 DCHECK(outer_delegate);
862
863 FencedFrame* fenced_frame = FindFencedFrame(outer_delegate);
864 DCHECK(fenced_frame);
865
866 return fenced_frame->mode();
Nan Lin171fe9a2022-02-17 16:42:16867}
868
Nan Linaaf84f72021-12-02 22:31:56869bool FrameTreeNode::IsErrorPageIsolationEnabled() const {
Nan Lind9de87d2022-03-18 16:53:03870 // Error page isolation is enabled for main frames only (crbug.com/1092524).
871 // Note that this will also enable error page isolation for fenced frames in
872 // MPArch mode, but not ShadowDOM mode.
873 // See the issue in crbug.com/1264224#c7 for why it can't be enabled for
874 // ShadowDOM mode.
875 return SiteIsolationPolicy::IsErrorPageIsolationEnabled(IsMainFrame());
Nan Linaaf84f72021-12-02 22:31:56876}
877
W. James MacLean81b8d01f2022-01-25 20:50:59878void FrameTreeNode::SetSrcdocValue(const std::string& srcdoc_value) {
879 srcdoc_value_ = srcdoc_value;
880}
881
Harkiran Bolariaebbe7702022-02-22 19:19:03882const scoped_refptr<BrowsingContextState>&
883FrameTreeNode::GetBrowsingContextStateForSubframe() const {
884 DCHECK(!IsMainFrame());
885 return current_frame_host()->browsing_context_state();
886}
887
[email protected]9b159a52013-10-03 17:24:55888} // namespace content