blob: 52056bade3502aa7e26dd1f123470efe13b6eac3 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2013 The Chromium Authors
[email protected]9b159a52013-10-03 17:24:552// 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"
Miyoung Shinff13ed22022-11-30 09:21:4723#include "content/browser/network/cross_origin_embedder_policy_reporter.h"
Paul Semel3e241042022-10-11 12:57:3124#include "content/browser/renderer_host/frame_tree.h"
danakjc492bf82020-09-09 20:02:4425#include "content/browser/renderer_host/navigation_controller_impl.h"
26#include "content/browser/renderer_host/navigation_request.h"
27#include "content/browser/renderer_host/navigator.h"
28#include "content/browser/renderer_host/navigator_delegate.h"
29#include "content/browser/renderer_host/render_frame_host_impl.h"
[email protected]94d0cc12013-12-18 00:07:4130#include "content/browser/renderer_host/render_view_host_impl.h"
Adam Langley1e03fb02023-03-16 23:02:0331#include "content/browser/webauth/authenticator_environment.h"
Lucas Furukawa Gadanief8290a2019-07-29 20:27:5132#include "content/common/navigation_params_utils.h"
dmazzonie950ea232015-03-13 21:39:4533#include "content/public/browser/browser_thread.h"
Nan Linaaf84f72021-12-02 22:31:5634#include "content/public/browser/site_isolation_policy.h"
Mustaq Ahmeda5dfa60b2018-12-08 00:30:1435#include "content/public/common/content_features.h"
arthursonzognib93a4472020-04-10 07:38:0036#include "services/network/public/cpp/web_sandbox_flags.h"
37#include "services/network/public/mojom/web_sandbox_flags.mojom-shared.h"
Harkiran Bolaria59290d62021-03-17 01:53:0138#include "third_party/blink/public/common/features.h"
Liam Bradyb0f1f0e2022-08-19 21:42:1139#include "third_party/blink/public/common/frame/fenced_frame_sandbox_flags.h"
Sreeja Kamishetty0be3b1b2021-08-12 17:04:1540#include "third_party/blink/public/common/loader/loader_constants.h"
Antonio Gomes4b2c5132020-01-16 11:49:4841#include "third_party/blink/public/mojom/frame/user_activation_update_types.mojom.h"
Julie Jeongeun Kimd90e2dd2020-03-03 11:45:3742#include "third_party/blink/public/mojom/security_context/insecure_request_policy.mojom.h"
[email protected]9b159a52013-10-03 17:24:5543
44namespace content {
45
dmazzonie950ea232015-03-13 21:39:4546namespace {
47
48// This is a global map between frame_tree_node_ids and pointers to
49// FrameTreeNodes.
Takuto Ikutaadf31eb2019-01-05 00:32:4850typedef std::unordered_map<int, FrameTreeNode*> FrameTreeNodeIdMap;
dmazzonie950ea232015-03-13 21:39:4551
scottmg5e65e3a2017-03-08 08:48:4652base::LazyInstance<FrameTreeNodeIdMap>::DestructorAtExit
53 g_frame_tree_node_id_map = LAZY_INSTANCE_INITIALIZER;
dmazzonie950ea232015-03-13 21:39:4554
Nan Line376738a2022-03-25 22:05:4155FencedFrame* FindFencedFrame(const FrameTreeNode* frame_tree_node) {
56 // TODO(crbug.com/1123606): Consider having a pointer to `FencedFrame` in
57 // `FrameTreeNode` or having a map between them.
58
59 // Try and find the `FencedFrame` that `frame_tree_node` represents.
60 DCHECK(frame_tree_node->parent());
61 std::vector<FencedFrame*> fenced_frames =
62 frame_tree_node->parent()->GetFencedFrames();
63 for (FencedFrame* fenced_frame : fenced_frames) {
64 if (frame_tree_node->frame_tree_node_id() ==
65 fenced_frame->GetOuterDelegateFrameTreeNodeId()) {
66 return fenced_frame;
67 }
68 }
69 return nullptr;
70}
71
fdegansa696e5112015-04-17 01:57:5972} // namespace
fdegans1d16355162015-03-26 11:58:3473
alexmose201c7cd2015-06-10 17:14:2174// This observer watches the opener of its owner FrameTreeNode and clears the
Arthur Hemerye4659282022-03-28 08:36:1575// owner's opener if the opener is destroyed or swaps BrowsingInstance.
alexmose201c7cd2015-06-10 17:14:2176class FrameTreeNode::OpenerDestroyedObserver : public FrameTreeNode::Observer {
77 public:
jochen6004a362017-02-04 00:11:4078 OpenerDestroyedObserver(FrameTreeNode* owner, bool observing_original_opener)
79 : owner_(owner), observing_original_opener_(observing_original_opener) {}
alexmose201c7cd2015-06-10 17:14:2180
Peter Boström9b036532021-10-28 23:37:2881 OpenerDestroyedObserver(const OpenerDestroyedObserver&) = delete;
82 OpenerDestroyedObserver& operator=(const OpenerDestroyedObserver&) = delete;
83
alexmose201c7cd2015-06-10 17:14:2184 // FrameTreeNode::Observer
85 void OnFrameTreeNodeDestroyed(FrameTreeNode* node) override {
Arthur Hemerye4659282022-03-28 08:36:1586 NullifyOpener(node);
87 }
88
89 // FrameTreeNode::Observer
90 void OnFrameTreeNodeDisownedOpenee(FrameTreeNode* node) override {
91 NullifyOpener(node);
92 }
93
94 void NullifyOpener(FrameTreeNode* node) {
jochen6004a362017-02-04 00:11:4095 if (observing_original_opener_) {
Rakina Zata Amni3a48ae42022-05-05 03:39:5696 // The "original opener" is special. It's used for attribution, and
97 // clients walk down the original opener chain. Therefore, if a link in
98 // the chain is being destroyed, reconnect the observation to the parent
99 // of the link being destroyed.
100 CHECK_EQ(owner_->first_live_main_frame_in_original_opener_chain(), node);
101 owner_->SetOriginalOpener(
102 node->first_live_main_frame_in_original_opener_chain());
Avi Drissman36465f332017-09-11 20:49:39103 // |this| is deleted at this point.
jochen6004a362017-02-04 00:11:40104 } else {
105 CHECK_EQ(owner_->opener(), node);
106 owner_->SetOpener(nullptr);
Avi Drissman36465f332017-09-11 20:49:39107 // |this| is deleted at this point.
jochen6004a362017-02-04 00:11:40108 }
alexmose201c7cd2015-06-10 17:14:21109 }
110
111 private:
Keishi Hattori0e45c022021-11-27 09:25:52112 raw_ptr<FrameTreeNode> owner_;
jochen6004a362017-02-04 00:11:40113 bool observing_original_opener_;
alexmose201c7cd2015-06-10 17:14:21114};
115
Kevin McNee88e61552020-10-22 20:41:11116const int FrameTreeNode::kFrameTreeNodeInvalidId = -1;
117
118static_assert(FrameTreeNode::kFrameTreeNodeInvalidId ==
119 RenderFrameHost::kNoFrameTreeNodeId,
120 "Have consistent sentinel values for an invalid FTN id.");
121
vishal.b782eb5d2015-04-29 12:22:57122int FrameTreeNode::next_frame_tree_node_id_ = 1;
[email protected]9b159a52013-10-03 17:24:55123
dmazzonie950ea232015-03-13 21:39:45124// static
vishal.b782eb5d2015-04-29 12:22:57125FrameTreeNode* FrameTreeNode::GloballyFindByID(int frame_tree_node_id) {
mostynb366eaf12015-03-26 00:51:19126 DCHECK_CURRENTLY_ON(BrowserThread::UI);
rob97250742015-12-10 17:45:15127 FrameTreeNodeIdMap* nodes = g_frame_tree_node_id_map.Pointer();
jdoerrie55ec69d2018-10-08 13:34:46128 auto it = nodes->find(frame_tree_node_id);
dmazzonie950ea232015-03-13 21:39:45129 return it == nodes->end() ? nullptr : it->second;
130}
131
Alexander Timin381e7e182020-04-28 19:04:03132// static
133FrameTreeNode* FrameTreeNode::From(RenderFrameHost* rfh) {
134 if (!rfh)
135 return nullptr;
136 return static_cast<RenderFrameHostImpl*>(rfh)->frame_tree_node();
137}
138
Abhijeet Kandalkarb43affa72022-09-27 16:48:01139FrameTreeNode::FencedFrameStatus ComputeFencedFrameStatus(
Arthur Sonzognif6785ec2022-12-05 10:11:50140 const FrameTree& frame_tree,
Harkiran Bolaria16f2c48d2022-04-22 12:39:57141 RenderFrameHostImpl* parent,
142 const blink::FramePolicy& frame_policy) {
Abhijeet Kandalkarb43affa72022-09-27 16:48:01143 using FencedFrameStatus = FrameTreeNode::FencedFrameStatus;
Dominic Farolino0b067632022-11-11 02:57:49144 if (blink::features::IsFencedFramesEnabled() &&
Arthur Sonzognif6785ec2022-12-05 10:11:50145 frame_tree.type() == FrameTree::Type::kFencedFrame) {
Dominic Farolino0b067632022-11-11 02:57:49146 if (!parent)
147 return FencedFrameStatus::kFencedFrameRoot;
148 return FencedFrameStatus::kIframeNestedWithinFencedFrame;
Harkiran Bolaria16f2c48d2022-04-22 12:39:57149 }
150
Abhijeet Kandalkar3f29bc42022-09-23 12:39:58151 return FencedFrameStatus::kNotNestedInFencedFrame;
Harkiran Bolaria16f2c48d2022-04-22 12:39:57152}
153
Julie Jeongeun Kim70a2e4e2020-02-21 05:09:54154FrameTreeNode::FrameTreeNode(
Arthur Sonzognif6785ec2022-12-05 10:11:50155 FrameTree& frame_tree,
Alexander Timin381e7e182020-04-28 19:04:03156 RenderFrameHostImpl* parent,
Daniel Cheng6ac128172021-05-25 18:49:01157 blink::mojom::TreeScopeType tree_scope_type,
Julie Jeongeun Kim70a2e4e2020-02-21 05:09:54158 bool is_created_by_script,
Julie Jeongeun Kim70a2e4e2020-02-21 05:09:54159 const blink::mojom::FrameOwnerProperties& frame_owner_properties,
Kevin McNee43fe8292021-10-04 22:59:41160 blink::FrameOwnerElementType owner_type,
Dominic Farolino08662c82021-06-11 07:36:34161 const blink::FramePolicy& frame_policy)
[email protected]bffc8302014-01-23 20:52:16162 : frame_tree_(frame_tree),
[email protected]bffc8302014-01-23 20:52:16163 frame_tree_node_id_(next_frame_tree_node_id_++),
xiaochengh98488162016-05-19 15:17:59164 parent_(parent),
Daniel Cheng9bd90f92021-04-23 20:49:45165 frame_owner_element_type_(owner_type),
Daniel Cheng6ac128172021-05-25 18:49:01166 tree_scope_type_(tree_scope_type),
Dominic Farolino08662c82021-06-11 07:36:34167 pending_frame_policy_(frame_policy),
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45168 is_created_by_script_(is_created_by_script),
lazyboy70605c32015-11-03 01:27:31169 frame_owner_properties_(frame_owner_properties),
Yuzu Saijo03dbf9b2022-07-22 04:29:45170 attributes_(blink::mojom::IframeAttributes::New()),
Harkiran Bolaria16f2c48d2022-04-22 12:39:57171 fenced_frame_status_(
Arthur Sonzognif6785ec2022-12-05 10:11:50172 ComputeFencedFrameStatus(frame_tree, parent_, frame_policy)),
173 render_manager_(this, frame_tree.manager_delegate()) {
Harkiran Bolariaa8347782022-04-06 09:25:11174 TRACE_EVENT_BEGIN("navigation", "FrameTreeNode",
175 perfetto::Track::FromPointer(this),
176 "frame_tree_node_when_created", this);
rob97250742015-12-10 17:45:15177 std::pair<FrameTreeNodeIdMap::iterator, bool> result =
dmazzonie950ea232015-03-13 21:39:45178 g_frame_tree_node_id_map.Get().insert(
179 std::make_pair(frame_tree_node_id_, this));
180 CHECK(result.second);
alexmos998581d2015-01-22 01:01:59181}
[email protected]9b159a52013-10-03 17:24:55182
Dominic Farolino8a2187b2021-12-24 20:44:21183void FrameTreeNode::DestroyInnerFrameTreeIfExists() {
184 // If `this` is an dummy outer delegate node, then we really are representing
185 // an inner FrameTree for one of the following consumers:
186 // - `Portal`
187 // - `FencedFrame`
188 // - `GuestView`
189 // If we are representing a `FencedFrame` object, we need to destroy it
190 // alongside ourself. `Portals` and `GuestView` however, *currently* have a
191 // more complex lifetime and are dealt with separately.
192 bool is_outer_dummy_node = false;
193 if (current_frame_host() &&
194 current_frame_host()->inner_tree_main_frame_tree_node_id() !=
195 FrameTreeNode::kFrameTreeNodeInvalidId) {
196 is_outer_dummy_node = true;
197 }
198
199 if (is_outer_dummy_node) {
Nan Line376738a2022-03-25 22:05:41200 FencedFrame* doomed_fenced_frame = FindFencedFrame(this);
Dominic Farolino8a2187b2021-12-24 20:44:21201 // `doomed_fenced_frame` might not actually exist, because some outer dummy
202 // `FrameTreeNode`s might correspond to `Portal`s, which do not have their
203 // lifetime managed in the same way as `FencedFrames`.
204 if (doomed_fenced_frame) {
205 parent()->DestroyFencedFrame(*doomed_fenced_frame);
206 }
207 }
208}
209
[email protected]9b159a52013-10-03 17:24:55210FrameTreeNode::~FrameTreeNode() {
Harkiran Bolariaa8347782022-04-06 09:25:11211 TRACE_EVENT("navigation", "FrameTreeNode::~FrameTreeNode");
Daniel Chengc3d1e8d2021-06-23 02:11:45212 // There should always be a current RenderFrameHost except during prerender
213 // activation. Prerender activation moves the current RenderFrameHost from
214 // the old FrameTree's FrameTreeNode to the new FrameTree's FrameTreeNode and
215 // then destroys the old FrameTree. See
216 // `RenderFrameHostManager::TakePrerenderedPage()`.
Harkiran Bolaria59290d62021-03-17 01:53:01217 if (current_frame_host()) {
218 // Remove the children.
219 current_frame_host()->ResetChildren();
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45220
Harkiran Bolaria59290d62021-03-17 01:53:01221 current_frame_host()->ResetLoadingState();
222 } else {
Harkiran Bolaria59290d62021-03-17 01:53:01223 DCHECK(!parent()); // Only main documents can be activated.
224 DCHECK(!opener()); // Prerendered frame trees can't have openers.
225
226 // Activation is not allowed during ongoing navigations.
Kevin McNeeb63b1ce2023-03-27 14:57:20227 CHECK(!navigation_request_);
Harkiran Bolaria59290d62021-03-17 01:53:01228
Carlos Caballerod1c80432021-04-20 08:16:32229 // TODO(https://crbug.com/1199693): Need to determine how to handle pending
Harkiran Bolaria59290d62021-03-17 01:53:01230 // deletions, as observers will be notified.
Kevin McNeeb63b1ce2023-03-27 14:57:20231 CHECK(!render_manager()->speculative_frame_host());
Harkiran Bolaria59290d62021-03-17 01:53:01232 }
Nate Chapin22ea6592019-03-05 22:29:02233
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45234 // If the removed frame was created by a script, then its history entry will
235 // never be reused - we can save some memory by removing the history entry.
236 // See also https://crbug.com/784356.
237 if (is_created_by_script_ && parent_) {
Carlos Caballero04aab362021-02-15 17:38:16238 NavigationEntryImpl* nav_entry =
239 navigator().controller().GetLastCommittedEntry();
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45240 if (nav_entry) {
241 nav_entry->RemoveEntryForFrame(this,
242 /* only_if_different_position = */ false);
243 }
244 }
245
dmazzonie950ea232015-03-13 21:39:45246 frame_tree_->FrameRemoved(this);
Carlos Caballero6ff6ace2021-02-05 16:53:00247
Dominic Farolino8a2187b2021-12-24 20:44:21248 DestroyInnerFrameTreeIfExists();
249
Alex Rudenkobfc5c192022-11-03 07:27:37250 devtools_instrumentation::OnFrameTreeNodeDestroyed(*this);
Carlos Caballero6ff6ace2021-02-05 16:53:00251 // Do not dispatch notification for the root frame as ~WebContentsImpl already
252 // dispatches it for now.
253 // TODO(https://crbug.com/1170277): This is only needed because the FrameTree
254 // is a member of WebContentsImpl and we would call back into it during
255 // destruction. We should clean up the FrameTree destruction code and call the
256 // delegate unconditionally.
257 if (parent())
258 render_manager_.delegate()->OnFrameTreeNodeDestroyed(this);
259
ericwilligers254597b2016-10-17 10:32:31260 for (auto& observer : observers_)
261 observer.OnFrameTreeNodeDestroyed(this);
Lukasz Anforowicz147141962020-12-16 18:03:24262 observers_.Clear();
alexmose201c7cd2015-06-10 17:14:21263
264 if (opener_)
265 opener_->RemoveObserver(opener_observer_.get());
Rakina Zata Amni3a48ae42022-05-05 03:39:56266 if (first_live_main_frame_in_original_opener_chain_)
267 first_live_main_frame_in_original_opener_chain_->RemoveObserver(
268 original_opener_observer_.get());
dmazzonie950ea232015-03-13 21:39:45269
270 g_frame_tree_node_id_map.Get().erase(frame_tree_node_id_);
jam39258caf2016-11-02 14:48:18271
Daniel Chengc3d1e8d2021-06-23 02:11:45272 // If a frame with a pending navigation is detached, make sure the
273 // WebContents (and its observers) update their loading state.
274 // TODO(dcheng): This should just check `IsLoading()`, but `IsLoading()`
275 // assumes that `current_frame_host_` is not null. This is incompatible with
276 // prerender activation when destroying the old frame tree (see above).
danakjf9400602019-06-07 15:44:58277 bool did_stop_loading = false;
278
jam39258caf2016-11-02 14:48:18279 if (navigation_request_) {
danakjf9400602019-06-07 15:44:58280 navigation_request_.reset();
danakjf9400602019-06-07 15:44:58281 did_stop_loading = true;
jam39258caf2016-11-02 14:48:18282 }
Nate Chapin22ea6592019-03-05 22:29:02283
danakjf9400602019-06-07 15:44:58284 // ~SiteProcessCountTracker DCHECKs in some tests if the speculative
285 // RenderFrameHostImpl is not destroyed last. Ideally this would be closer to
286 // (possible before) the ResetLoadingState() call above.
danakjf9400602019-06-07 15:44:58287 if (render_manager_.speculative_frame_host()) {
Daniel Chengc3d1e8d2021-06-23 02:11:45288 // TODO(dcheng): Shouldn't a FrameTreeNode with a speculative
289 // RenderFrameHost always be considered loading?
danakjf9400602019-06-07 15:44:58290 did_stop_loading |= render_manager_.speculative_frame_host()->is_loading();
Daniel Chengc3d1e8d2021-06-23 02:11:45291 // `FrameTree::Shutdown()` has special handling for the main frame's
292 // speculative RenderFrameHost, and the speculative RenderFrameHost should
293 // already be reset for main frames.
294 DCHECK(!IsMainFrame());
295
296 // This does not use `UnsetSpeculativeRenderFrameHost()`: if the speculative
297 // RenderFrameHost has already reached kPendingCommit, it would needlessly
298 // re-create a proxy for a frame that's going away.
299 render_manager_.DiscardSpeculativeRenderFrameHostForShutdown();
danakjf9400602019-06-07 15:44:58300 }
301
302 if (did_stop_loading)
303 DidStopLoading();
304
Harkiran Bolaria59290d62021-03-17 01:53:01305 // IsLoading() requires that current_frame_host() is non-null.
306 DCHECK(!current_frame_host() || !IsLoading());
Harkiran Bolariaa8347782022-04-06 09:25:11307
308 // Matches the TRACE_EVENT_BEGIN in the constructor.
309 TRACE_EVENT_END("navigation", perfetto::Track::FromPointer(this));
[email protected]9b159a52013-10-03 17:24:55310}
311
alexmose201c7cd2015-06-10 17:14:21312void FrameTreeNode::AddObserver(Observer* observer) {
313 observers_.AddObserver(observer);
314}
315
316void FrameTreeNode::RemoveObserver(Observer* observer) {
317 observers_.RemoveObserver(observer);
318}
319
[email protected]94d0cc12013-12-18 00:07:41320bool FrameTreeNode::IsMainFrame() const {
321 return frame_tree_->root() == this;
322}
323
Paul Semel3e241042022-10-11 12:57:31324Navigator& FrameTreeNode::navigator() {
Arthur Sonzognif6785ec2022-12-05 10:11:50325 return frame_tree().navigator();
Paul Semel3e241042022-10-11 12:57:31326}
327
Arthur Hemerya06697f2023-03-14 09:20:57328bool FrameTreeNode::IsOutermostMainFrame() const {
Ian Vollick25a9d032022-04-12 23:20:17329 return !GetParentOrOuterDocument();
330}
331
Hiroki Nakagawaab309622021-05-19 16:38:13332void FrameTreeNode::ResetForNavigation() {
arthursonzogni76098e52020-11-25 14:18:45333 // This frame has had its user activation bits cleared in the renderer before
334 // arriving here. We just need to clear them here and in the other renderer
335 // processes that may have a reference to this frame.
Alexander Timin45b716c2020-11-06 01:40:31336 //
337 // We do not take user activation into account when calculating
338 // |ResetForNavigationResult|, as we are using it to determine bfcache
339 // eligibility and the page can get another user gesture after restore.
Antonio Gomes4b2c5132020-01-16 11:49:48340 UpdateUserActivationState(
Mustaq Ahmeddc195e5b2020-08-04 18:45:11341 blink::mojom::UserActivationUpdateType::kClearActivation,
342 blink::mojom::UserActivationNotificationType::kNone);
Ian Clelland5cbaaf82017-11-27 22:00:03343}
344
Arthur Hemerya06697f2023-03-14 09:20:57345RenderFrameHostImpl* FrameTreeNode::GetParentOrOuterDocument() const {
Kevin McNee86e64ee2023-02-17 16:35:50346 return GetParentOrOuterDocumentHelper(/*escape_guest_view=*/false,
347 /*include_prospective=*/true);
Dave Tapuskac8de3b02021-12-03 21:51:01348}
349
350RenderFrameHostImpl* FrameTreeNode::GetParentOrOuterDocumentOrEmbedder() {
Kevin McNee86e64ee2023-02-17 16:35:50351 return GetParentOrOuterDocumentHelper(/*escape_guest_view=*/true,
352 /*include_prospective=*/true);
Dave Tapuskac8de3b02021-12-03 21:51:01353}
354
355RenderFrameHostImpl* FrameTreeNode::GetParentOrOuterDocumentHelper(
Kevin McNee86e64ee2023-02-17 16:35:50356 bool escape_guest_view,
Arthur Hemerya06697f2023-03-14 09:20:57357 bool include_prospective) const {
Dave Tapuskac8de3b02021-12-03 21:51:01358 // Find the parent in the FrameTree (iframe).
Kevin McNee86e64ee2023-02-17 16:35:50359 if (parent_) {
Dave Tapuskac8de3b02021-12-03 21:51:01360 return parent_;
Kevin McNee86e64ee2023-02-17 16:35:50361 }
Dave Tapuskac8de3b02021-12-03 21:51:01362
363 if (!escape_guest_view) {
364 // If we are not a fenced frame root nor inside a portal then return early.
365 // This code does not escape GuestViews.
Kevin McNee86e64ee2023-02-17 16:35:50366 if (!IsFencedFrameRoot() && !frame_tree_->delegate()->IsPortal()) {
Dave Tapuskac8de3b02021-12-03 21:51:01367 return nullptr;
Kevin McNee86e64ee2023-02-17 16:35:50368 }
Dave Tapuskac8de3b02021-12-03 21:51:01369 }
370
371 // Find the parent in the outer embedder (GuestView, Portal, or Fenced Frame).
372 FrameTreeNode* frame_in_embedder = render_manager()->GetOuterDelegateNode();
Kevin McNee86e64ee2023-02-17 16:35:50373 if (frame_in_embedder) {
Dave Tapuskac8de3b02021-12-03 21:51:01374 return frame_in_embedder->current_frame_host()->GetParent();
Kevin McNee86e64ee2023-02-17 16:35:50375 }
376
377 // Consider embedders which own our frame tree, but have not yet attached it
378 // to the outer frame tree.
379 if (include_prospective) {
380 RenderFrameHostImpl* prospective_outer_document =
381 frame_tree_->delegate()->GetProspectiveOuterDocument();
382 if (prospective_outer_document) {
383 return prospective_outer_document;
384 }
385 }
Dave Tapuskac8de3b02021-12-03 21:51:01386
387 // No parent found.
388 return nullptr;
389}
390
Julie Jeongeun Kimf38c1eca2021-12-14 07:46:55391FrameType FrameTreeNode::GetFrameType() const {
392 if (!IsMainFrame())
393 return FrameType::kSubframe;
394
Arthur Sonzognif6785ec2022-12-05 10:11:50395 switch (frame_tree().type()) {
Julie Jeongeun Kimf38c1eca2021-12-14 07:46:55396 case FrameTree::Type::kPrimary:
397 return FrameType::kPrimaryMainFrame;
398 case FrameTree::Type::kPrerender:
399 return FrameType::kPrerenderMainFrame;
400 case FrameTree::Type::kFencedFrame:
Julie Jeongeun Kimf38c1eca2021-12-14 07:46:55401 return FrameType::kFencedFrameRoot;
402 }
403}
404
alexmose201c7cd2015-06-10 17:14:21405void FrameTreeNode::SetOpener(FrameTreeNode* opener) {
Harkiran Bolariaa8347782022-04-06 09:25:11406 TRACE_EVENT("navigation", "FrameTreeNode::SetOpener",
407 ChromeTrackEvent::kFrameTreeNodeInfo, opener);
alexmose201c7cd2015-06-10 17:14:21408 if (opener_) {
409 opener_->RemoveObserver(opener_observer_.get());
410 opener_observer_.reset();
411 }
412
413 opener_ = opener;
414
415 if (opener_) {
Jeremy Roman04f27c372017-10-27 15:20:55416 opener_observer_ = std::make_unique<OpenerDestroyedObserver>(this, false);
alexmose201c7cd2015-06-10 17:14:21417 opener_->AddObserver(opener_observer_.get());
418 }
419}
420
Wolfgang Beyerd8809db2020-09-30 15:29:39421void FrameTreeNode::SetOpenerDevtoolsFrameToken(
422 base::UnguessableToken opener_devtools_frame_token) {
423 DCHECK(!opener_devtools_frame_token_ ||
424 opener_devtools_frame_token_->is_empty());
425 opener_devtools_frame_token_ = std::move(opener_devtools_frame_token);
426}
427
jochen6004a362017-02-04 00:11:40428void FrameTreeNode::SetOriginalOpener(FrameTreeNode* opener) {
Avi Drissman36465f332017-09-11 20:49:39429 // The original opener tracks main frames only.
avi8d1aa162017-03-27 18:27:37430 DCHECK(opener == nullptr || !opener->parent());
jochen6004a362017-02-04 00:11:40431
Rakina Zata Amni3a48ae42022-05-05 03:39:56432 if (first_live_main_frame_in_original_opener_chain_) {
433 first_live_main_frame_in_original_opener_chain_->RemoveObserver(
434 original_opener_observer_.get());
Avi Drissman36465f332017-09-11 20:49:39435 original_opener_observer_.reset();
436 }
437
Rakina Zata Amni3a48ae42022-05-05 03:39:56438 first_live_main_frame_in_original_opener_chain_ = opener;
jochen6004a362017-02-04 00:11:40439
Rakina Zata Amni3a48ae42022-05-05 03:39:56440 if (first_live_main_frame_in_original_opener_chain_) {
441 original_opener_observer_ = std::make_unique<OpenerDestroyedObserver>(
442 this, true /* observing_original_opener */);
443 first_live_main_frame_in_original_opener_chain_->AddObserver(
444 original_opener_observer_.get());
jochen6004a362017-02-04 00:11:40445 }
446}
447
engedy6e2e0992017-05-25 18:58:42448void FrameTreeNode::SetCollapsed(bool collapsed) {
Dave Tapuska65e50aa2022-03-09 23:44:13449 DCHECK(!IsMainFrame() || IsFencedFrameRoot());
engedy6e2e0992017-05-25 18:58:42450 if (is_collapsed_ == collapsed)
451 return;
452
453 is_collapsed_ = collapsed;
454 render_manager_.OnDidChangeCollapsedState(collapsed);
455}
456
Harkiran Bolaria59290d62021-03-17 01:53:01457void FrameTreeNode::SetFrameTree(FrameTree& frame_tree) {
Arthur Sonzognif6785ec2022-12-05 10:11:50458 frame_tree_ = frame_tree;
Kevin McNeeb110d0c2021-10-26 15:53:00459 DCHECK(current_frame_host());
460 current_frame_host()->SetFrameTree(frame_tree);
461 RenderFrameHostImpl* speculative_frame_host =
462 render_manager_.speculative_frame_host();
463 if (speculative_frame_host)
464 speculative_frame_host->SetFrameTree(frame_tree);
Harkiran Bolaria59290d62021-03-17 01:53:01465}
466
Luna Luc3fdacdf2017-11-08 04:48:53467void FrameTreeNode::SetPendingFramePolicy(blink::FramePolicy frame_policy) {
Liam Bradyb0f1f0e2022-08-19 21:42:11468 // Inside of a fenced frame, the sandbox flags should not be able to change
469 // from its initial value. If the flags change, we have to assume the change
470 // came from a compromised renderer and terminate it.
471 // We will only do the check if the sandbox flags are already set to
472 // kFencedFrameForcedSandboxFlags. This is to allow the sandbox flags to
473 // be set initially (go from kNone -> kFencedFrameForcedSandboxFlags). Once
474 // it has been set, it cannot change to another value.
Dominic Farolino0b067632022-11-11 02:57:49475 // If the flags do change via a compromised fenced frame, then
476 // `RenderFrameHostImpl::DidChangeFramePolicy()` will detect that the change
477 // wasn't initiated by the parent, and will terminate the renderer before we
478 // reach this point, so we can CHECK() here.
479 bool fenced_frame_sandbox_flags_changed =
480 (IsFencedFrameRoot() &&
481 pending_frame_policy_.sandbox_flags ==
482 blink::kFencedFrameForcedSandboxFlags &&
483 frame_policy.sandbox_flags != blink::kFencedFrameForcedSandboxFlags);
484 CHECK(!fenced_frame_sandbox_flags_changed);
Liam Bradyb0f1f0e2022-08-19 21:42:11485
Ian Clellandcdc4f312017-10-13 22:24:12486 pending_frame_policy_.sandbox_flags = frame_policy.sandbox_flags;
alexmos6e940102016-01-19 22:47:25487
Ian Clellandcdc4f312017-10-13 22:24:12488 if (parent()) {
489 // Subframes should always inherit their parent's sandbox flags.
Alexander Timin381e7e182020-04-28 19:04:03490 pending_frame_policy_.sandbox_flags |=
Harkiran Bolaria4eacb3a2021-12-13 20:03:47491 parent()->browsing_context_state()->active_sandbox_flags();
Charlie Hue1b77ac2019-12-13 21:30:17492 // This is only applied on subframes; container policy and required document
493 // policy are not mutable on main frame.
Ian Clellandcdc4f312017-10-13 22:24:12494 pending_frame_policy_.container_policy = frame_policy.container_policy;
Charlie Hue1b77ac2019-12-13 21:30:17495 pending_frame_policy_.required_document_policy =
496 frame_policy.required_document_policy;
Ian Clellandcdc4f312017-10-13 22:24:12497 }
Liam Brady25a14162022-12-02 15:25:57498
499 // Fenced frame roots do not have a parent, so add an extra check here to
500 // still allow a fenced frame to properly set its container policy. The
501 // required document policy and sandbox flags should stay unmodified.
502 if (IsFencedFrameRoot()) {
503 DCHECK(pending_frame_policy_.required_document_policy.empty());
504 DCHECK_EQ(pending_frame_policy_.sandbox_flags, frame_policy.sandbox_flags);
505 pending_frame_policy_.container_policy = frame_policy.container_policy;
506 }
iclelland92f8c0b2017-04-19 12:43:05507}
508
Yuzu Saijo03dbf9b2022-07-22 04:29:45509void FrameTreeNode::SetAttributes(
510 blink::mojom::IframeAttributesPtr attributes) {
Miyoung Shinc9ff4812023-01-05 08:58:05511 if (!Credentialless() && attributes->credentialless) {
Arthur Sonzogni64457592022-11-22 11:08:59512 // Log this only when credentialless is changed to true.
Arthur Sonzogni2e9c6111392022-05-02 08:37:13513 GetContentClient()->browser()->LogWebFeatureForCurrentPage(
514 parent_, blink::mojom::WebFeature::kAnonymousIframe);
515 }
Yuzu Saijo03dbf9b2022-07-22 04:29:45516 attributes_ = std::move(attributes);
Arthur Sonzogni2e9c6111392022-05-02 08:37:13517}
518
fdegans4a49ce932015-03-12 17:11:37519bool FrameTreeNode::IsLoading() const {
Nate Chapin470dbc62023-04-25 16:34:38520 return GetLoadingState() != LoadingState::NONE;
521}
522
523LoadingState FrameTreeNode::GetLoadingState() const {
fdegans4a49ce932015-03-12 17:11:37524 RenderFrameHostImpl* current_frame_host =
525 render_manager_.current_frame_host();
fdegans4a49ce932015-03-12 17:11:37526 DCHECK(current_frame_host);
fdegans39ff0382015-04-29 19:04:39527
Nate Chapin470dbc62023-04-25 16:34:38528 if (navigation_request_) {
529 // If navigation_request_ is non-null, the navigation has not been moved to
530 // the RenderFrameHostImpl or sent to the renderer to be committed. This
531 // loading UI policy is provisional, as the navigation API might "intercept"
532 // a same-document commit and change it from LOADING_WITHOUT_UI to
533 // LOADING_UI_REQUESTED.
534 return navigation_request_->IsSameDocument()
535 ? LoadingState::LOADING_WITHOUT_UI
536 : LoadingState::LOADING_UI_REQUESTED;
537 }
clamy11e11512015-07-07 16:42:17538
clamy610c63b32017-12-22 15:05:18539 RenderFrameHostImpl* speculative_frame_host =
540 render_manager_.speculative_frame_host();
Daniel Chengc3d1e8d2021-06-23 02:11:45541 // TODO(dcheng): Shouldn't a FrameTreeNode with a speculative RenderFrameHost
542 // always be considered loading?
Nate Chapin470dbc62023-04-25 16:34:38543 if (speculative_frame_host && speculative_frame_host->is_loading()) {
544 return LoadingState::LOADING_UI_REQUESTED;
545 }
546 return current_frame_host->loading_state();
fdegans4a49ce932015-03-12 17:11:37547}
548
Alex Moshchuk9b0fd822020-10-26 23:08:15549bool FrameTreeNode::HasPendingCrossDocumentNavigation() const {
550 // Having a |navigation_request_| on FrameTreeNode implies that there's an
551 // ongoing navigation that hasn't reached the ReadyToCommit state. If the
552 // navigation is between ReadyToCommit and DidCommitNavigation, the
553 // NavigationRequest will be held by RenderFrameHost, which is checked below.
554 if (navigation_request_ && !navigation_request_->IsSameDocument())
555 return true;
556
557 // Having a speculative RenderFrameHost should imply a cross-document
558 // navigation.
559 if (render_manager_.speculative_frame_host())
560 return true;
561
562 return render_manager_.current_frame_host()
563 ->HasPendingCommitForCrossDocumentNavigation();
564}
565
Arthur Hemeryc3380172018-01-22 14:00:17566void FrameTreeNode::TransferNavigationRequestOwnership(
567 RenderFrameHostImpl* render_frame_host) {
Andrey Kosyakovf2d4ff72018-10-29 20:09:59568 devtools_instrumentation::OnResetNavigationRequest(navigation_request_.get());
Arthur Hemeryc3380172018-01-22 14:00:17569 render_frame_host->SetNavigationRequest(std::move(navigation_request_));
570}
571
Charlie Reis09952ee2022-12-08 16:35:07572void FrameTreeNode::TakeNavigationRequest(
dcheng9bfa5162016-04-09 01:00:57573 std::unique_ptr<NavigationRequest> navigation_request) {
arthursonzognic79c251c2016-08-18 15:00:37574 // This is never called when navigating to a Javascript URL. For the loading
575 // state, this matches what Blink is doing: Blink doesn't send throbber
576 // notifications for Javascript URLS.
577 DCHECK(!navigation_request->common_params().url.SchemeIs(
578 url::kJavaScriptScheme));
579
Nate Chapin470dbc62023-04-25 16:34:38580 LoadingState previous_frame_tree_loading_state =
581 frame_tree().LoadingTree()->GetLoadingState();
clamy44e84ce2016-02-22 15:38:25582
Rakina Zata Amnif8f2bb62022-11-23 05:54:32583 // Reset the previous NavigationRequest owned by `this`. However, there's no
584 // need to reset the state: there's still an ongoing load, and the
clamy82a2f4d2016-02-02 14:20:41585 // RenderFrameHostManager will take care of updates to the speculative
586 // RenderFrameHost in DidCreateNavigationRequest below.
Nate Chapin470dbc62023-04-25 16:34:38587 if (previous_frame_tree_loading_state != LoadingState::NONE) {
Mohamed Abdelhalimf03d4a22019-10-01 13:34:31588 if (navigation_request_ && navigation_request_->IsNavigationStarted()) {
jamcd0b7b22017-03-24 22:13:05589 // Mark the old request as aborted.
Mohamed Abdelhalimb4db22a2019-06-18 10:46:52590 navigation_request_->set_net_error(net::ERR_ABORTED);
jamcd0b7b22017-03-24 22:13:05591 }
Daniel Cheng390e2a72022-09-28 06:07:53592 ResetNavigationRequestButKeepState();
jamcd0b7b22017-03-24 22:13:05593 }
clamy44e84ce2016-02-22 15:38:25594
595 navigation_request_ = std::move(navigation_request);
Shubhie Panickerddf2a4e2018-03-06 00:09:06596 if (was_discarded_) {
597 navigation_request_->set_was_discarded();
598 was_discarded_ = false;
599 }
clamy8e2e299202016-04-05 11:44:59600 render_manager()->DidCreateNavigationRequest(navigation_request_.get());
Nate Chapin470dbc62023-04-25 16:34:38601 DidStartLoading(previous_frame_tree_loading_state);
clamydcb434c12015-04-16 19:29:16602}
603
Daniel Cheng390e2a72022-09-28 06:07:53604void FrameTreeNode::ResetNavigationRequest(NavigationDiscardReason reason) {
605 if (!navigation_request_)
606 return;
607
608 ResetNavigationRequestButKeepState();
609
610 // The RenderFrameHostManager should clean up any speculative RenderFrameHost
611 // it created for the navigation. Also register that the load stopped.
612 DidStopLoading();
Rakina Zata Amnif8f2bb62022-11-23 05:54:32613 render_manager_.DiscardSpeculativeRFHIfUnused(reason);
Daniel Cheng390e2a72022-09-28 06:07:53614}
615
616void FrameTreeNode::ResetNavigationRequestButKeepState() {
fdegans39ff0382015-04-29 19:04:39617 if (!navigation_request_)
618 return;
John Abd-El-Malekdcc7bf42017-09-12 22:30:23619
Andrey Kosyakovf2d4ff72018-10-29 20:09:59620 devtools_instrumentation::OnResetNavigationRequest(navigation_request_.get());
clamydcb434c12015-04-16 19:29:16621 navigation_request_.reset();
622}
623
Nate Chapin470dbc62023-04-25 16:34:38624void FrameTreeNode::DidStartLoading(
625 LoadingState previous_frame_tree_loading_state) {
Camille Lamyefd54b02018-10-04 16:54:14626 TRACE_EVENT2("navigation", "FrameTreeNode::DidStartLoading",
Nate Chapin470dbc62023-04-25 16:34:38627 "frame_tree_node", frame_tree_node_id(), "loading_state",
628 GetLoadingState());
Clark DuVallc97bcf72021-12-08 22:58:24629 base::ElapsedTimer timer;
fdegansa696e5112015-04-17 01:57:59630
Nate Chapin470dbc62023-04-25 16:34:38631 frame_tree().LoadingTree()->NodeLoadingStateChanged(
632 *this, previous_frame_tree_loading_state);
fdegansa696e5112015-04-17 01:57:59633
634 // Set initial load progress and update overall progress. This will notify
635 // the WebContents of the load progress change.
Sreeja Kamishetty15f9944a22022-03-10 10:16:08636 //
637 // Only notify when the load is triggered from primary/prerender main frame as
638 // we only update load progress for these nodes which happens when the frame
639 // tree matches the loading tree.
Arthur Sonzognif6785ec2022-12-05 10:11:50640 if (&frame_tree() == frame_tree().LoadingTree())
Sreeja Kamishetty15f9944a22022-03-10 10:16:08641 DidChangeLoadProgress(blink::kInitialLoadProgress);
fdegansa696e5112015-04-17 01:57:59642
Harkiran Bolaria3f83fba72022-03-10 17:48:40643 // Notify the proxies of the event.
644 current_frame_host()->browsing_context_state()->OnDidStartLoading();
Clark DuVallc97bcf72021-12-08 22:58:24645 base::UmaHistogramTimes(
646 base::StrCat({"Navigation.DidStartLoading.",
Ian Vollick5f45867c2022-08-05 08:29:56647 IsOutermostMainFrame() ? "MainFrame" : "Subframe"}),
Clark DuVallc97bcf72021-12-08 22:58:24648 timer.Elapsed());
fdegansa696e5112015-04-17 01:57:59649}
650
651void FrameTreeNode::DidStopLoading() {
Camille Lamyefd54b02018-10-04 16:54:14652 TRACE_EVENT1("navigation", "FrameTreeNode::DidStopLoading", "frame_tree_node",
653 frame_tree_node_id());
fdegansa696e5112015-04-17 01:57:59654 // Set final load progress and update overall progress. This will notify
655 // the WebContents of the load progress change.
Sreeja Kamishetty15f9944a22022-03-10 10:16:08656 //
657 // Only notify when the load is triggered from primary/prerender main frame as
658 // we only update load progress for these nodes which happens when the frame
659 // tree matches the loading tree.
Arthur Sonzognif6785ec2022-12-05 10:11:50660 if (&frame_tree() == frame_tree().LoadingTree())
Sreeja Kamishetty15f9944a22022-03-10 10:16:08661 DidChangeLoadProgress(blink::kFinalLoadProgress);
fdegansa696e5112015-04-17 01:57:59662
Harkiran Bolaria3f83fba72022-03-10 17:48:40663 // Notify the proxies of the event.
664 current_frame_host()->browsing_context_state()->OnDidStopLoading();
Lucas Furukawa Gadani6faef602019-05-06 21:16:03665
Arthur Sonzognif6785ec2022-12-05 10:11:50666 FrameTree* loading_tree = frame_tree().LoadingTree();
Nate Chapin470dbc62023-04-25 16:34:38667 // When loading tree is null, ignore invoking NodeLoadingStateChanged as the
668 // frame tree is already deleted. This can happen when prerendering gets
669 // cancelled and DidStopLoading is called during FrameTree destruction.
670 if (loading_tree && !loading_tree->IsLoadingIncludingInnerFrameTrees()) {
671 // If `loading_tree->IsLoadingIncludingInnerFrameTrees()` is now false, this
672 // was the last FrameTreeNode to be loading, and the FrameTree as a whole
673 // has now stopped loading. Notify the FrameTree.
674 // It doesn't matter whether we pass LOADING_UI_REQUESTED or
675 // LOADING_WITHOUT_UI as the previous_frame_tree_loading_state param,
676 // because the previous value is only used to detect when the FrameTree's
677 // overall loading state hasn't changed, and we know that the new state will
678 // be LoadingState::NONE.
679 loading_tree->NodeLoadingStateChanged(*this,
680 LoadingState::LOADING_UI_REQUESTED);
681 }
fdegansa696e5112015-04-17 01:57:59682}
683
684void FrameTreeNode::DidChangeLoadProgress(double load_progress) {
Sreeja Kamishetty0be3b1b2021-08-12 17:04:15685 DCHECK_GE(load_progress, blink::kInitialLoadProgress);
686 DCHECK_LE(load_progress, blink::kFinalLoadProgress);
687 current_frame_host()->DidChangeLoadProgress(load_progress);
fdegansa696e5112015-04-17 01:57:59688}
689
clamyf73862c42015-07-08 12:31:33690bool FrameTreeNode::StopLoading() {
arthursonzogni66f711c2019-10-08 14:40:36691 if (navigation_request_ && navigation_request_->IsNavigationStarted())
692 navigation_request_->set_net_error(net::ERR_ABORTED);
Daniel Cheng390e2a72022-09-28 06:07:53693 ResetNavigationRequest(NavigationDiscardReason::kCancelled);
clamyf73862c42015-07-08 12:31:33694
clamyf73862c42015-07-08 12:31:33695 if (!IsMainFrame())
696 return true;
697
698 render_manager_.Stop();
699 return true;
700}
701
alexmos21acae52015-11-07 01:04:43702void FrameTreeNode::DidFocus() {
703 last_focus_time_ = base::TimeTicks::Now();
ericwilligers254597b2016-10-17 10:32:31704 for (auto& observer : observers_)
705 observer.OnFrameTreeNodeFocused(this);
alexmos21acae52015-11-07 01:04:43706}
707
clamy44e84ce2016-02-22 15:38:25708void FrameTreeNode::BeforeUnloadCanceled() {
Julie Jeongeun Kim8cf7ae32022-05-02 03:47:29709 // TODO(clamy): Support BeforeUnload in subframes. Fenced Frames don't run
710 // BeforeUnload. Maybe need to check whether other MPArch inner pages cases
711 // need beforeunload(e.g., portals, GuestView if it gets ported to MPArch).
Ian Vollick1c6dd3e2022-04-13 02:06:26712 if (!IsOutermostMainFrame())
clamy44e84ce2016-02-22 15:38:25713 return;
714
715 RenderFrameHostImpl* current_frame_host =
716 render_manager_.current_frame_host();
717 DCHECK(current_frame_host);
718 current_frame_host->ResetLoadingState();
719
clamy610c63b32017-12-22 15:05:18720 RenderFrameHostImpl* speculative_frame_host =
721 render_manager_.speculative_frame_host();
722 if (speculative_frame_host)
723 speculative_frame_host->ResetLoadingState();
Alexander Timin23c110b2021-01-14 02:39:04724 // Note: there is no need to set an error code on the NavigationHandle as
725 // the observers have not been notified about its creation.
726 // We also reset navigation request only when this navigation request was
727 // responsible for this dialog, as a new navigation request might cancel
728 // existing unrelated dialog.
Daniel Cheng390e2a72022-09-28 06:07:53729 if (navigation_request_ && navigation_request_->IsWaitingForBeforeUnload()) {
730 ResetNavigationRequest(NavigationDiscardReason::kCancelled);
731 }
clamy44e84ce2016-02-22 15:38:25732}
733
Mustaq Ahmedecb5c38e2020-07-29 00:34:30734bool FrameTreeNode::NotifyUserActivation(
735 blink::mojom::UserActivationNotificationType notification_type) {
Alex Moshchuk03904192021-04-02 07:29:08736 // User Activation V2 requires activating all ancestor frames in addition to
737 // the current frame. See
738 // https://html.spec.whatwg.org/multipage/interaction.html#tracking-user-activation.
Alexander Timina1dfadaa2020-04-28 13:30:06739 for (RenderFrameHostImpl* rfh = current_frame_host(); rfh;
740 rfh = rfh->GetParent()) {
John Delaneyb625dca92021-04-14 17:00:34741 rfh->DidReceiveUserActivation();
Miyoung Shin8a66ec022022-11-28 23:50:09742 rfh->ActivateUserActivation(notification_type);
John Delaneyedd8d6c2019-01-25 00:23:57743 }
Alex Moshchuk03904192021-04-02 07:29:08744
Harkiran Bolaria0b3bdef02022-03-10 13:04:40745 current_frame_host()->browsing_context_state()->set_has_active_user_gesture(
746 true);
Mustaq Ahmeda5dfa60b2018-12-08 00:30:14747
Mustaq Ahmed0180320f2019-03-21 16:07:01748 // See the "Same-origin Visibility" section in |UserActivationState| class
749 // doc.
Mustaq Ahmede5f12562019-10-30 18:02:03750 if (base::FeatureList::IsEnabled(
Garrett Tanzer753cc532022-03-02 21:30:59751 features::kUserActivationSameOriginVisibility)) {
Mustaq Ahmeda5dfa60b2018-12-08 00:30:14752 const url::Origin& current_origin =
753 this->current_frame_host()->GetLastCommittedOrigin();
Arthur Sonzognif6785ec2022-12-05 10:11:50754 for (FrameTreeNode* node : frame_tree().Nodes()) {
Mustaq Ahmeda5dfa60b2018-12-08 00:30:14755 if (node->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith(
756 current_origin)) {
Miyoung Shin8a66ec022022-11-28 23:50:09757 node->current_frame_host()->ActivateUserActivation(notification_type);
Mustaq Ahmeda5dfa60b2018-12-08 00:30:14758 }
759 }
760 }
761
Carlos Caballero40b0efd2021-01-26 11:55:00762 navigator().controller().NotifyUserActivation();
Alex Moshchuk03904192021-04-02 07:29:08763 current_frame_host()->MaybeIsolateForUserActivation();
Shivani Sharma194877032019-03-07 17:52:47764
Mustaq Ahmedc4cb7162018-06-05 16:28:36765 return true;
766}
767
768bool FrameTreeNode::ConsumeTransientUserActivation() {
Miyoung Shin8a66ec022022-11-28 23:50:09769 bool was_active = current_frame_host()->IsActiveUserActivation();
Arthur Sonzognif6785ec2022-12-05 10:11:50770 for (FrameTreeNode* node : frame_tree().Nodes()) {
Miyoung Shin8a66ec022022-11-28 23:50:09771 node->current_frame_host()->ConsumeTransientUserActivation();
Garrett Tanzer753cc532022-03-02 21:30:59772 }
Harkiran Bolaria0b3bdef02022-03-10 13:04:40773 current_frame_host()->browsing_context_state()->set_has_active_user_gesture(
774 false);
Mustaq Ahmedc4cb7162018-06-05 16:28:36775 return was_active;
776}
777
Shivani Sharmac4f561582018-11-15 15:58:39778bool FrameTreeNode::ClearUserActivation() {
Arthur Sonzognif6785ec2022-12-05 10:11:50779 for (FrameTreeNode* node : frame_tree().SubtreeNodes(this))
Miyoung Shin8a66ec022022-11-28 23:50:09780 node->current_frame_host()->ClearUserActivation();
Harkiran Bolaria0b3bdef02022-03-10 13:04:40781 current_frame_host()->browsing_context_state()->set_has_active_user_gesture(
782 false);
Shivani Sharmac4f561582018-11-15 15:58:39783 return true;
784}
785
Ella Ge9caed612019-08-09 16:17:25786bool FrameTreeNode::VerifyUserActivation() {
Ella Gea78f6772019-12-11 10:35:25787 DCHECK(base::FeatureList::IsEnabled(
788 features::kBrowserVerifiedUserActivationMouse) ||
789 base::FeatureList::IsEnabled(
790 features::kBrowserVerifiedUserActivationKeyboard));
791
Ella Ge9caed612019-08-09 16:17:25792 return render_manager_.current_frame_host()
793 ->GetRenderWidgetHost()
Mustaq Ahmed83bb1722019-10-22 20:00:10794 ->RemovePendingUserActivationIfAvailable();
Ella Ge9caed612019-08-09 16:17:25795}
796
Mustaq Ahmedc4cb7162018-06-05 16:28:36797bool FrameTreeNode::UpdateUserActivationState(
Mustaq Ahmeddc195e5b2020-08-04 18:45:11798 blink::mojom::UserActivationUpdateType update_type,
799 blink::mojom::UserActivationNotificationType notification_type) {
Ella Ge9caed612019-08-09 16:17:25800 bool update_result = false;
Mustaq Ahmedc4cb7162018-06-05 16:28:36801 switch (update_type) {
Antonio Gomes4b2c5132020-01-16 11:49:48802 case blink::mojom::UserActivationUpdateType::kConsumeTransientActivation:
Ella Ge9caed612019-08-09 16:17:25803 update_result = ConsumeTransientUserActivation();
804 break;
Antonio Gomes4b2c5132020-01-16 11:49:48805 case blink::mojom::UserActivationUpdateType::kNotifyActivation:
Mustaq Ahmeddc195e5b2020-08-04 18:45:11806 update_result = NotifyUserActivation(notification_type);
Ella Ge9caed612019-08-09 16:17:25807 break;
Antonio Gomes4b2c5132020-01-16 11:49:48808 case blink::mojom::UserActivationUpdateType::
Liviu Tintad9391fb92020-09-28 23:50:07809 kNotifyActivationPendingBrowserVerification: {
810 const bool user_activation_verified = VerifyUserActivation();
811 // Add UMA metric for when browser user activation verification succeeds
812 base::UmaHistogramBoolean("Event.BrowserVerifiedUserActivation",
813 user_activation_verified);
814 if (user_activation_verified) {
Mustaq Ahmedecb5c38e2020-07-29 00:34:30815 update_result = NotifyUserActivation(
Mustaq Ahmed2cfb0402020-09-29 19:24:35816 blink::mojom::UserActivationNotificationType::kInteraction);
Antonio Gomes4b2c5132020-01-16 11:49:48817 update_type = blink::mojom::UserActivationUpdateType::kNotifyActivation;
Ella Ge9caed612019-08-09 16:17:25818 } else {
arthursonzogni9816b9192021-03-29 16:09:19819 // TODO(https://crbug.com/848778): We need to decide what to do when
820 // user activation verification failed. NOTREACHED here will make all
Ella Ge9caed612019-08-09 16:17:25821 // unrelated tests that inject event to renderer fail.
822 return false;
823 }
Liviu Tintad9391fb92020-09-28 23:50:07824 } break;
Antonio Gomes4b2c5132020-01-16 11:49:48825 case blink::mojom::UserActivationUpdateType::kClearActivation:
Ella Ge9caed612019-08-09 16:17:25826 update_result = ClearUserActivation();
827 break;
Mustaq Ahmedc4cb7162018-06-05 16:28:36828 }
Mustaq Ahmeddc195e5b2020-08-04 18:45:11829 render_manager_.UpdateUserActivationState(update_type, notification_type);
Ella Ge9caed612019-08-09 16:17:25830 return update_result;
japhet61835ae12017-01-20 01:25:39831}
832
Nate Chapin47276a62023-02-16 16:53:44833void FrameTreeNode::DidConsumeHistoryUserActivation() {
834 for (FrameTreeNode* node : frame_tree().Nodes()) {
835 node->current_frame_host()->ConsumeHistoryUserActivation();
836 }
837}
838
Arthur Sonzognif8840b92018-11-07 14:10:35839void FrameTreeNode::PruneChildFrameNavigationEntries(
840 NavigationEntryImpl* entry) {
841 for (size_t i = 0; i < current_frame_host()->child_count(); ++i) {
842 FrameTreeNode* child = current_frame_host()->child_at(i);
843 if (child->is_created_by_script_) {
844 entry->RemoveEntryForFrame(child,
845 /* only_if_different_position = */ false);
846 } else {
847 child->PruneChildFrameNavigationEntries(entry);
848 }
849 }
850}
851
arthursonzogni034bb9c2020-10-01 08:29:56852void FrameTreeNode::SetInitialPopupURL(const GURL& initial_popup_url) {
853 DCHECK(initial_popup_url_.is_empty());
Abhijeet Kandalkarb86993b2022-11-22 05:17:40854 DCHECK(is_on_initial_empty_document());
arthursonzogni034bb9c2020-10-01 08:29:56855 initial_popup_url_ = initial_popup_url;
856}
857
858void FrameTreeNode::SetPopupCreatorOrigin(
859 const url::Origin& popup_creator_origin) {
Abhijeet Kandalkarb86993b2022-11-22 05:17:40860 DCHECK(is_on_initial_empty_document());
arthursonzogni034bb9c2020-10-01 08:29:56861 popup_creator_origin_ = popup_creator_origin;
862}
863
Rakina Zata Amni4b1968d2021-09-09 03:29:47864void FrameTreeNode::WriteIntoTrace(
Alexander Timin074cd182022-03-23 18:11:22865 perfetto::TracedProto<TraceProto> proto) const {
Rakina Zata Amni4b1968d2021-09-09 03:29:47866 proto->set_frame_tree_node_id(frame_tree_node_id());
Alexander Timin074cd182022-03-23 18:11:22867 proto->set_is_main_frame(IsMainFrame());
868 proto.Set(TraceProto::kCurrentFrameHost, current_frame_host());
869 proto.Set(TraceProto::kSpeculativeFrameHost,
870 render_manager()->speculative_frame_host());
Rakina Zata Amni4b1968d2021-09-09 03:29:47871}
872
Carlos Caballero76711352021-03-24 17:38:21873bool FrameTreeNode::HasNavigation() {
874 if (navigation_request())
875 return true;
876
877 // Same-RenderFrameHost navigation is committing:
878 if (current_frame_host()->HasPendingCommitNavigation())
879 return true;
880
881 // Cross-RenderFrameHost navigation is committing:
882 if (render_manager()->speculative_frame_host())
883 return true;
884
885 return false;
886}
887
Dominic Farolino4bc10ee2021-08-31 00:37:36888bool FrameTreeNode::IsFencedFrameRoot() const {
Abhijeet Kandalkar3f29bc42022-09-23 12:39:58889 return fenced_frame_status_ == FencedFrameStatus::kFencedFrameRoot;
shivanigithubf3ddff52021-07-03 22:06:30890}
891
892bool FrameTreeNode::IsInFencedFrameTree() const {
Abhijeet Kandalkar3f29bc42022-09-23 12:39:58893 return fenced_frame_status_ != FencedFrameStatus::kNotNestedInFencedFrame;
shivanigithubf3ddff52021-07-03 22:06:30894}
895
Garrett Tanzer29de7112022-12-06 21:26:32896const absl::optional<FencedFrameProperties>&
Xiaochen Zhou90858e82023-05-31 15:47:37897FrameTreeNode::GetFencedFrameProperties(bool force_tree_traversal) {
898 return GetFencedFramePropertiesForEditing(force_tree_traversal);
Liam Brady6da2cc9e2023-01-30 17:09:43899}
900
901absl::optional<FencedFrameProperties>&
Xiaochen Zhou90858e82023-05-31 15:47:37902FrameTreeNode::GetFencedFramePropertiesForEditing(bool force_tree_traversal) {
903 if (!force_tree_traversal && IsInFencedFrameTree()) {
Liam Brady6da2cc9e2023-01-30 17:09:43904 return frame_tree().root()->fenced_frame_properties_;
Garrett Tanzer34cb92fe2022-09-28 17:50:54905 }
906
Liam Brady6da2cc9e2023-01-30 17:09:43907 // If we might be in a urn iframe, try to find the "urn iframe root",
908 // and, if it exists, return the attached `FencedFrameProperties`.
Xiaochen Zhou90858e82023-05-31 15:47:37909 if (force_tree_traversal || blink::features::IsAllowURNsInIframeEnabled()) {
Liam Brady6da2cc9e2023-01-30 17:09:43910 FrameTreeNode* node = this;
Xiaochen Zhou90858e82023-05-31 15:47:37911 while (node) {
Liam Brady6da2cc9e2023-01-30 17:09:43912 if (node->fenced_frame_properties_.has_value()) {
913 return node->fenced_frame_properties_;
914 }
Xiaochen Zhou90858e82023-05-31 15:47:37915 node = node->parent() ? node->parent()->frame_tree_node() : nullptr;
Liam Brady6da2cc9e2023-01-30 17:09:43916 }
917 }
918
919 return fenced_frame_properties_;
920}
921
Liam Bradybe6621d12023-07-20 19:43:40922void FrameTreeNode::MaybeResetFencedFrameAutomaticBeaconReportEventData() {
923 absl::optional<FencedFrameProperties>& properties =
924 GetFencedFramePropertiesForEditing(/*force_tree_traversal=*/true);
925 // `properties` will exist for both fenced frames as well as iframes loaded
926 // with a urn:uuid.
927 if (!properties) {
928 return;
929 }
930 properties->MaybeResetAutomaticBeaconData();
931}
932
Liam Brady6da2cc9e2023-01-30 17:09:43933void FrameTreeNode::SetFencedFrameAutomaticBeaconReportEventData(
934 const std::string& event_data,
Nan Lindbce6e32023-05-10 22:42:55935 const std::vector<blink::FencedFrame::ReportingDestination>& destinations,
936 network::AttributionReportingRuntimeFeatures
Liam Bradybe6621d12023-07-20 19:43:40937 attribution_reporting_runtime_features,
938 bool once) {
Liam Brady6da2cc9e2023-01-30 17:09:43939 absl::optional<FencedFrameProperties>& properties =
Xiaochen Zhou90858e82023-05-31 15:47:37940 GetFencedFramePropertiesForEditing(
941 /*force_tree_traversal=*/true);
Liam Brady6da2cc9e2023-01-30 17:09:43942 // `properties` will exist for both fenced frames as well as iframes loaded
943 // with a urn:uuid. This allows URN iframes to call this function without
944 // getting bad-messaged.
945 if (!properties || !properties->fenced_frame_reporter_) {
946 mojo::ReportBadMessage(
947 "Automatic beacon data can only be set in fenced frames or iframes "
Garrett Tanzer06c02f02023-02-20 21:24:41948 "loaded from a config with a fenced frame reporter.");
949 return;
950 }
951 // This metadata should only be present in the renderer in frames that are
952 // same-origin to the mapped url.
953 if (!properties->mapped_url_.has_value() ||
954 !current_origin().IsSameOriginWith(url::Origin::Create(
955 properties->mapped_url_->GetValueIgnoringVisibility()))) {
956 mojo::ReportBadMessage(
957 "Automatic beacon data can only be set from documents that are same-"
958 "origin to the mapped url from the fenced frame config.");
Liam Brady6da2cc9e2023-01-30 17:09:43959 return;
960 }
Liam Bradybe6621d12023-07-20 19:43:40961 properties->UpdateAutomaticBeaconData(
962 event_data, destinations, attribution_reporting_runtime_features, once);
Garrett Tanzer34cb92fe2022-09-28 17:50:54963}
964
Yao Xiaof9ae90a2023-03-01 20:52:44965size_t FrameTreeNode::GetFencedFrameDepth(
966 size_t& shared_storage_fenced_frame_root_count) {
967 DCHECK_EQ(shared_storage_fenced_frame_root_count, 0u);
968
Yao Xiaoa2337ad2022-10-12 20:59:29969 size_t depth = 0;
970 FrameTreeNode* node = this;
971
972 while (node->fenced_frame_status() !=
973 FencedFrameStatus::kNotNestedInFencedFrame) {
974 if (node->fenced_frame_status() == FencedFrameStatus::kFencedFrameRoot) {
975 depth += 1;
Yao Xiaof9ae90a2023-03-01 20:52:44976
977 // This implies the fenced frame is from shared storage.
978 if (node->fenced_frame_properties_ &&
979 node->fenced_frame_properties_->shared_storage_budget_metadata_) {
980 shared_storage_fenced_frame_root_count += 1;
981 }
Yao Xiaoa2337ad2022-10-12 20:59:29982 } else {
983 DCHECK_EQ(node->fenced_frame_status(),
984 FencedFrameStatus::kIframeNestedWithinFencedFrame);
985 }
986
987 DCHECK(node->GetParentOrOuterDocument());
988 node = node->GetParentOrOuterDocument()->frame_tree_node();
989 }
990
991 return depth;
992}
993
Garrett Tanzer34cb92fe2022-09-28 17:50:54994absl::optional<base::UnguessableToken> FrameTreeNode::GetFencedFrameNonce() {
995 auto& root_fenced_frame_properties = GetFencedFrameProperties();
996 if (!root_fenced_frame_properties.has_value()) {
997 return absl::nullopt;
998 }
Garrett Tanzer29de7112022-12-06 21:26:32999 if (root_fenced_frame_properties->partition_nonce_.has_value()) {
1000 return root_fenced_frame_properties->partition_nonce_
1001 ->GetValueIgnoringVisibility();
1002 }
1003 // It is only possible for there to be `FencedFrameProperties` but no
1004 // partition nonce in urn iframes (when not nested inside a fenced frame).
1005 CHECK(blink::features::IsAllowURNsInIframeEnabled());
1006 CHECK(!IsInFencedFrameTree());
1007 return absl::nullopt;
Garrett Tanzer34cb92fe2022-09-28 17:50:541008}
1009
1010void FrameTreeNode::SetFencedFramePropertiesIfNeeded() {
1011 if (!IsFencedFrameRoot()) {
shivanigithub4cd016a2021-09-20 21:10:301012 return;
1013 }
1014
Garrett Tanzer34cb92fe2022-09-28 17:50:541015 // The fenced frame properties are set only on the fenced frame root.
1016 // In the future, they will be set on the FrameTree instead.
Garrett Tanzer29de7112022-12-06 21:26:321017 fenced_frame_properties_ = FencedFrameProperties();
shivanigithub4cd016a2021-09-20 21:10:301018}
1019
Garrett Tanzer291a2d52023-03-20 22:41:571020blink::FencedFrame::DeprecatedFencedFrameMode
1021FrameTreeNode::GetDeprecatedFencedFrameMode() {
Garrett Tanzera42fdef2022-06-13 16:09:141022 if (!IsInFencedFrameTree()) {
Garrett Tanzer291a2d52023-03-20 22:41:571023 return blink::FencedFrame::DeprecatedFencedFrameMode::kDefault;
Garrett Tanzera42fdef2022-06-13 16:09:141024 }
Nan Lin171fe9a2022-02-17 16:42:161025
Garrett Tanzer291a2d52023-03-20 22:41:571026 auto& root_fenced_frame_properties = GetFencedFrameProperties();
1027 if (!root_fenced_frame_properties.has_value()) {
1028 return blink::FencedFrame::DeprecatedFencedFrameMode::kDefault;
1029 }
Nan Lin171fe9a2022-02-17 16:42:161030
Garrett Tanzer291a2d52023-03-20 22:41:571031 return root_fenced_frame_properties->mode_;
Nan Lin171fe9a2022-02-17 16:42:161032}
1033
Nan Linaaf84f72021-12-02 22:31:561034bool FrameTreeNode::IsErrorPageIsolationEnabled() const {
Nan Lind9de87d2022-03-18 16:53:031035 // Error page isolation is enabled for main frames only (crbug.com/1092524).
Nan Lind9de87d2022-03-18 16:53:031036 return SiteIsolationPolicy::IsErrorPageIsolationEnabled(IsMainFrame());
Nan Linaaf84f72021-12-02 22:31:561037}
1038
W. James MacLean81b8d01f2022-01-25 20:50:591039void FrameTreeNode::SetSrcdocValue(const std::string& srcdoc_value) {
1040 srcdoc_value_ = srcdoc_value;
1041}
1042
Garrett Tanzer29de7112022-12-06 21:26:321043std::vector<const SharedStorageBudgetMetadata*>
Yao Xiao1ac702d2022-06-08 17:20:491044FrameTreeNode::FindSharedStorageBudgetMetadata() {
Garrett Tanzer29de7112022-12-06 21:26:321045 std::vector<const SharedStorageBudgetMetadata*> result;
Yao Xiao1ac702d2022-06-08 17:20:491046 FrameTreeNode* node = this;
1047
1048 while (true) {
Garrett Tanzer2975eeac2022-08-22 16:34:011049 if (node->fenced_frame_properties_ &&
Garrett Tanzer29de7112022-12-06 21:26:321050 node->fenced_frame_properties_->shared_storage_budget_metadata_) {
1051 result.emplace_back(
1052 node->fenced_frame_properties_->shared_storage_budget_metadata_
1053 ->GetValueIgnoringVisibility());
Yao Xiao1ac702d2022-06-08 17:20:491054 }
1055
Garrett Tanzer29de7112022-12-06 21:26:321056 if (!node->GetParentOrOuterDocument()) {
Yao Xiao1ac702d2022-06-08 17:20:491057 break;
1058 }
Garrett Tanzer29de7112022-12-06 21:26:321059
1060 node = node->GetParentOrOuterDocument()->frame_tree_node();
Yao Xiao1ac702d2022-06-08 17:20:491061 }
1062
Yao Xiaoa2337ad2022-10-12 20:59:291063 return result;
Yao Xiao1ac702d2022-06-08 17:20:491064}
1065
Camillia Smith Barnes7218518c2023-03-06 19:02:171066absl::optional<std::u16string>
1067FrameTreeNode::GetEmbedderSharedStorageContextIfAllowed() {
1068 absl::optional<FencedFrameProperties>& properties =
1069 GetFencedFramePropertiesForEditing();
1070 // We only return embedder context for frames that are same origin with the
1071 // fenced frame root or ancestor URN iframe.
1072 if (!properties || !properties->mapped_url_.has_value() ||
1073 !current_origin().IsSameOriginWith(url::Origin::Create(
1074 properties->mapped_url_->GetValueIgnoringVisibility()))) {
1075 return absl::nullopt;
1076 }
1077 return properties->embedder_shared_storage_context_;
1078}
1079
Harkiran Bolariaebbe7702022-02-22 19:19:031080const scoped_refptr<BrowsingContextState>&
1081FrameTreeNode::GetBrowsingContextStateForSubframe() const {
1082 DCHECK(!IsMainFrame());
1083 return current_frame_host()->browsing_context_state();
1084}
1085
Arthur Hemerye4659282022-03-28 08:36:151086void FrameTreeNode::ClearOpenerReferences() {
1087 // Simulate the FrameTreeNode being dead to opener observers. They will
1088 // nullify their opener.
1089 // Note: observers remove themselves from observers_, no need to take care of
1090 // that manually.
1091 for (auto& observer : observers_)
1092 observer.OnFrameTreeNodeDisownedOpenee(this);
1093}
1094
Liam Bradyd2a41e152022-07-19 13:58:481095bool FrameTreeNode::AncestorOrSelfHasCSPEE() const {
1096 // Check if CSPEE is set in this frame or any ancestor frames.
Yuzu Saijo03dbf9b2022-07-22 04:29:451097 return csp_attribute() || (parent() && parent()->required_csp());
Liam Bradyd2a41e152022-07-19 13:58:481098}
1099
Arthur Sonzogni8e8eb1f2023-01-10 14:51:011100void FrameTreeNode::ResetAllNavigationsForFrameDetach() {
1101 NavigationDiscardReason reason = NavigationDiscardReason::kWillRemoveFrame;
1102 for (FrameTreeNode* frame : frame_tree().SubtreeNodes(this)) {
1103 frame->ResetNavigationRequest(reason);
1104 frame->current_frame_host()->ResetOwnedNavigationRequests(reason);
1105 frame->GetRenderFrameHostManager().DiscardSpeculativeRFH(reason);
1106 }
1107}
1108
Miyoung Shin7cf88b42022-11-07 13:22:301109void FrameTreeNode::RestartNavigationAsCrossDocument(
1110 std::unique_ptr<NavigationRequest> navigation_request) {
1111 navigator().RestartNavigationAsCrossDocument(std::move(navigation_request));
1112}
1113
Miyoung Shin1504eb712022-12-07 10:32:181114bool FrameTreeNode::Reload() {
1115 return navigator().controller().ReloadFrame(this);
1116}
1117
Julie Jeongeun Kimc1b07c32022-11-11 10:26:321118Navigator& FrameTreeNode::GetCurrentNavigator() {
1119 return navigator();
1120}
1121
Miyoung Shine16cd2262022-11-30 05:52:161122RenderFrameHostManager& FrameTreeNode::GetRenderFrameHostManager() {
1123 return render_manager_;
1124}
1125
Miyoung Shin64fd1bea2023-01-04 04:22:081126FrameTreeNode* FrameTreeNode::GetOpener() const {
1127 return opener_;
1128}
1129
Julie Jeongeun Kim2132b37f82022-11-23 08:30:461130void FrameTreeNode::SetFocusedFrame(SiteInstanceGroup* source) {
1131 frame_tree_->delegate()->SetFocusedFrame(this, source);
1132}
1133
Julie Jeongeun Kim0e242242022-11-30 10:45:091134void FrameTreeNode::DidChangeReferrerPolicy(
1135 network::mojom::ReferrerPolicy referrer_policy) {
1136 navigator().controller().DidChangeReferrerPolicy(this, referrer_policy);
1137}
1138
Miyoung Shinff13ed22022-11-30 09:21:471139std::unique_ptr<NavigationRequest>
1140FrameTreeNode::CreateNavigationRequestForSynchronousRendererCommit(
1141 RenderFrameHostImpl* render_frame_host,
1142 bool is_same_document,
1143 const GURL& url,
1144 const url::Origin& origin,
W. James MacLean23e90a12022-12-21 04:38:211145 const absl::optional<GURL>& initiator_base_url,
Miyoung Shinff13ed22022-11-30 09:21:471146 const net::IsolationInfo& isolation_info_for_subresources,
1147 blink::mojom::ReferrerPtr referrer,
1148 const ui::PageTransition& transition,
1149 bool should_replace_current_entry,
1150 const std::string& method,
1151 bool has_transient_activation,
1152 bool is_overriding_user_agent,
1153 const std::vector<GURL>& redirects,
1154 const GURL& original_url,
1155 std::unique_ptr<CrossOriginEmbedderPolicyReporter> coep_reporter,
Miyoung Shinff13ed22022-11-30 09:21:471156 int http_response_code) {
1157 return NavigationRequest::CreateForSynchronousRendererCommit(
1158 this, render_frame_host, is_same_document, url, origin,
W. James MacLean23e90a12022-12-21 04:38:211159 initiator_base_url, isolation_info_for_subresources, std::move(referrer),
1160 transition, should_replace_current_entry, method,
1161 has_transient_activation, is_overriding_user_agent, redirects,
Kunihiko Sakamoto2ae79e62023-05-26 00:34:151162 original_url, std::move(coep_reporter), http_response_code);
Miyoung Shinff13ed22022-11-30 09:21:471163}
1164
Miyoung Shinb5561802022-12-01 08:21:351165void FrameTreeNode::CancelNavigation() {
1166 if (navigation_request() && navigation_request()->IsNavigationStarted()) {
1167 navigation_request()->set_net_error(net::ERR_ABORTED);
1168 }
1169 ResetNavigationRequest(NavigationDiscardReason::kCancelled);
1170}
1171
Miyoung Shinc9ff4812023-01-05 08:58:051172bool FrameTreeNode::Credentialless() const {
1173 return attributes_->credentialless;
1174}
1175
Miyoung Shinaf9a34362023-01-31 02:46:511176#if !BUILDFLAG(IS_ANDROID)
1177void FrameTreeNode::GetVirtualAuthenticatorManager(
1178 mojo::PendingReceiver<blink::test::mojom::VirtualAuthenticatorManager>
1179 receiver) {
Adam Langley1e03fb02023-03-16 23:02:031180 auto* environment_singleton = AuthenticatorEnvironment::GetInstance();
Miyoung Shinaf9a34362023-01-31 02:46:511181 environment_singleton->EnableVirtualAuthenticatorFor(this,
1182 /*enable_ui=*/false);
1183 environment_singleton->AddVirtualAuthenticatorReceiver(this,
1184 std::move(receiver));
1185}
1186#endif // !BUILDFLAG(IS_ANDROID)
1187
[email protected]9b159a52013-10-03 17:24:551188} // namespace content