blob: bfc4351a75931d8dd6c31714f2505453eb8ae08e [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"
avib7348942015-12-25 20:57:1014#include "base/macros.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"
Daniel Cheng6ca7f1c92017-08-09 21:45:4117#include "base/strings/string_util.h"
Andrey Kosyakovf2d4ff72018-10-29 20:09:5918#include "content/browser/devtools/devtools_instrumentation.h"
danakjc492bf82020-09-09 20:02:4419#include "content/browser/renderer_host/navigation_controller_impl.h"
20#include "content/browser/renderer_host/navigation_request.h"
21#include "content/browser/renderer_host/navigator.h"
22#include "content/browser/renderer_host/navigator_delegate.h"
23#include "content/browser/renderer_host/render_frame_host_impl.h"
[email protected]94d0cc12013-12-18 00:07:4124#include "content/browser/renderer_host/render_view_host_impl.h"
Lucas Furukawa Gadanief8290a2019-07-29 20:27:5125#include "content/common/navigation_params_utils.h"
dmazzonie950ea232015-03-13 21:39:4526#include "content/public/browser/browser_thread.h"
Mustaq Ahmeda5dfa60b2018-12-08 00:30:1427#include "content/public/common/content_features.h"
arthursonzognib93a4472020-04-10 07:38:0028#include "services/network/public/cpp/web_sandbox_flags.h"
29#include "services/network/public/mojom/web_sandbox_flags.mojom-shared.h"
Harkiran Bolaria59290d62021-03-17 01:53:0130#include "third_party/blink/public/common/features.h"
Sreeja Kamishetty0be3b1b2021-08-12 17:04:1531#include "third_party/blink/public/common/loader/loader_constants.h"
Antonio Gomes4b2c5132020-01-16 11:49:4832#include "third_party/blink/public/mojom/frame/user_activation_update_types.mojom.h"
Julie Jeongeun Kimd90e2dd2020-03-03 11:45:3733#include "third_party/blink/public/mojom/security_context/insecure_request_policy.mojom.h"
[email protected]9b159a52013-10-03 17:24:5534
35namespace content {
36
dmazzonie950ea232015-03-13 21:39:4537namespace {
38
39// This is a global map between frame_tree_node_ids and pointers to
40// FrameTreeNodes.
Takuto Ikutaadf31eb2019-01-05 00:32:4841typedef std::unordered_map<int, FrameTreeNode*> FrameTreeNodeIdMap;
dmazzonie950ea232015-03-13 21:39:4542
scottmg5e65e3a2017-03-08 08:48:4643base::LazyInstance<FrameTreeNodeIdMap>::DestructorAtExit
44 g_frame_tree_node_id_map = LAZY_INSTANCE_INITIALIZER;
dmazzonie950ea232015-03-13 21:39:4545
fdegansa696e5112015-04-17 01:57:5946} // namespace
fdegans1d16355162015-03-26 11:58:3447
alexmose201c7cd2015-06-10 17:14:2148// This observer watches the opener of its owner FrameTreeNode and clears the
49// owner's opener if the opener is destroyed.
50class FrameTreeNode::OpenerDestroyedObserver : public FrameTreeNode::Observer {
51 public:
jochen6004a362017-02-04 00:11:4052 OpenerDestroyedObserver(FrameTreeNode* owner, bool observing_original_opener)
53 : owner_(owner), observing_original_opener_(observing_original_opener) {}
alexmose201c7cd2015-06-10 17:14:2154
55 // FrameTreeNode::Observer
56 void OnFrameTreeNodeDestroyed(FrameTreeNode* node) override {
jochen6004a362017-02-04 00:11:4057 if (observing_original_opener_) {
Avi Drissman36465f332017-09-11 20:49:3958 // The "original owner" is special. It's used for attribution, and clients
59 // walk down the original owner chain. Therefore, if a link in the chain
60 // is being destroyed, reconnect the observation to the parent of the link
61 // being destroyed.
jochen6004a362017-02-04 00:11:4062 CHECK_EQ(owner_->original_opener(), node);
Avi Drissman36465f332017-09-11 20:49:3963 owner_->SetOriginalOpener(node->original_opener());
64 // |this| is deleted at this point.
jochen6004a362017-02-04 00:11:4065 } else {
66 CHECK_EQ(owner_->opener(), node);
67 owner_->SetOpener(nullptr);
Avi Drissman36465f332017-09-11 20:49:3968 // |this| is deleted at this point.
jochen6004a362017-02-04 00:11:4069 }
alexmose201c7cd2015-06-10 17:14:2170 }
71
72 private:
73 FrameTreeNode* owner_;
jochen6004a362017-02-04 00:11:4074 bool observing_original_opener_;
alexmose201c7cd2015-06-10 17:14:2175
76 DISALLOW_COPY_AND_ASSIGN(OpenerDestroyedObserver);
77};
78
Kevin McNee88e61552020-10-22 20:41:1179const int FrameTreeNode::kFrameTreeNodeInvalidId = -1;
80
81static_assert(FrameTreeNode::kFrameTreeNodeInvalidId ==
82 RenderFrameHost::kNoFrameTreeNodeId,
83 "Have consistent sentinel values for an invalid FTN id.");
84
vishal.b782eb5d2015-04-29 12:22:5785int FrameTreeNode::next_frame_tree_node_id_ = 1;
[email protected]9b159a52013-10-03 17:24:5586
dmazzonie950ea232015-03-13 21:39:4587// static
vishal.b782eb5d2015-04-29 12:22:5788FrameTreeNode* FrameTreeNode::GloballyFindByID(int frame_tree_node_id) {
mostynb366eaf12015-03-26 00:51:1989 DCHECK_CURRENTLY_ON(BrowserThread::UI);
rob97250742015-12-10 17:45:1590 FrameTreeNodeIdMap* nodes = g_frame_tree_node_id_map.Pointer();
jdoerrie55ec69d2018-10-08 13:34:4691 auto it = nodes->find(frame_tree_node_id);
dmazzonie950ea232015-03-13 21:39:4592 return it == nodes->end() ? nullptr : it->second;
93}
94
Alexander Timin381e7e182020-04-28 19:04:0395// static
96FrameTreeNode* FrameTreeNode::From(RenderFrameHost* rfh) {
97 if (!rfh)
98 return nullptr;
99 return static_cast<RenderFrameHostImpl*>(rfh)->frame_tree_node();
100}
101
Julie Jeongeun Kim70a2e4e2020-02-21 05:09:54102FrameTreeNode::FrameTreeNode(
103 FrameTree* frame_tree,
Alexander Timin381e7e182020-04-28 19:04:03104 RenderFrameHostImpl* parent,
Daniel Cheng6ac128172021-05-25 18:49:01105 blink::mojom::TreeScopeType tree_scope_type,
Julie Jeongeun Kim70a2e4e2020-02-21 05:09:54106 const std::string& name,
107 const std::string& unique_name,
108 bool is_created_by_script,
109 const base::UnguessableToken& devtools_frame_token,
110 const blink::mojom::FrameOwnerProperties& frame_owner_properties,
Dominic Farolino08662c82021-06-11 07:36:34111 blink::mojom::FrameOwnerElementType owner_type,
112 const blink::FramePolicy& frame_policy)
[email protected]bffc8302014-01-23 20:52:16113 : frame_tree_(frame_tree),
[email protected]bffc8302014-01-23 20:52:16114 frame_tree_node_id_(next_frame_tree_node_id_++),
xiaochengh98488162016-05-19 15:17:59115 parent_(parent),
Daniel Cheng9bd90f92021-04-23 20:49:45116 frame_owner_element_type_(owner_type),
Daniel Cheng6ac128172021-05-25 18:49:01117 tree_scope_type_(tree_scope_type),
Gyuyoung Kimc16e52e92021-03-19 02:45:37118 replication_state_(blink::mojom::FrameReplicationState::New(
Antonio Sartori90f41212021-01-22 10:08:34119 url::Origin(),
estarka886b8d2015-12-18 21:53:08120 name,
lukasza464d8692016-02-22 19:26:32121 unique_name,
Charlie Hue24f04832021-03-04 21:07:06122 blink::ParsedPermissionsPolicy(),
Antonio Sartori90f41212021-01-22 10:08:34123 network::mojom::WebSandboxFlags::kNone,
Dominic Farolino08662c82021-06-11 07:36:34124 frame_policy,
Daniel Cheng9bd90f92021-04-23 20:49:45125 // should enforce strict mixed content checking
126 blink::mojom::InsecureRequestPolicy::kLeaveInsecureRequestsAlone,
127 // hashes of hosts for insecure request upgrades
128 std::vector<uint32_t>(),
japhet61835ae12017-01-20 01:25:39129 false /* is a potentially trustworthy unique origin */,
danakj359a4342020-05-29 20:38:39130 false /* has an active user gesture */,
Ehsan Karamad192a8da2018-10-21 03:48:08131 false /* has received a user gesture before nav */,
Alex Turner10d557a42021-06-01 19:06:49132 false /* is_ad_subframe */)),
Dominic Farolino08662c82021-06-11 07:36:34133 pending_frame_policy_(frame_policy),
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45134 is_created_by_script_(is_created_by_script),
Pavel Feldman25234722017-10-11 02:49:06135 devtools_frame_token_(devtools_frame_token),
lazyboy70605c32015-11-03 01:27:31136 frame_owner_properties_(frame_owner_properties),
Lukasz Anforowicz147141962020-12-16 18:03:24137 blame_context_(frame_tree_node_id_, FrameTreeNode::From(parent)),
138 render_manager_(this, frame_tree->manager_delegate()) {
rob97250742015-12-10 17:45:15139 std::pair<FrameTreeNodeIdMap::iterator, bool> result =
dmazzonie950ea232015-03-13 21:39:45140 g_frame_tree_node_id_map.Get().insert(
141 std::make_pair(frame_tree_node_id_, this));
142 CHECK(result.second);
benjhaydend4da63d2016-03-11 21:29:33143
xiaochenghb9554bb2016-05-21 14:20:48144 // Note: this should always be done last in the constructor.
145 blame_context_.Initialize();
alexmos998581d2015-01-22 01:01:59146}
[email protected]9b159a52013-10-03 17:24:55147
148FrameTreeNode::~FrameTreeNode() {
Daniel Chengc3d1e8d2021-06-23 02:11:45149 // There should always be a current RenderFrameHost except during prerender
150 // activation. Prerender activation moves the current RenderFrameHost from
151 // the old FrameTree's FrameTreeNode to the new FrameTree's FrameTreeNode and
152 // then destroys the old FrameTree. See
153 // `RenderFrameHostManager::TakePrerenderedPage()`.
Harkiran Bolaria59290d62021-03-17 01:53:01154 if (current_frame_host()) {
155 // Remove the children.
156 current_frame_host()->ResetChildren();
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45157
Harkiran Bolaria59290d62021-03-17 01:53:01158 current_frame_host()->ResetLoadingState();
159 } else {
Hiroki Nakagawa0a90bd42021-04-21 01:53:05160 DCHECK(blink::features::IsPrerender2Enabled());
Harkiran Bolaria59290d62021-03-17 01:53:01161 DCHECK(!parent()); // Only main documents can be activated.
162 DCHECK(!opener()); // Prerendered frame trees can't have openers.
163
164 // Activation is not allowed during ongoing navigations.
165 DCHECK(!navigation_request_);
166
Carlos Caballerod1c80432021-04-20 08:16:32167 // TODO(https://crbug.com/1199693): Need to determine how to handle pending
Harkiran Bolaria59290d62021-03-17 01:53:01168 // deletions, as observers will be notified.
169 DCHECK(!render_manager()->speculative_frame_host());
170 }
Nate Chapin22ea6592019-03-05 22:29:02171
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45172 // If the removed frame was created by a script, then its history entry will
173 // never be reused - we can save some memory by removing the history entry.
174 // See also https://crbug.com/784356.
175 if (is_created_by_script_ && parent_) {
Carlos Caballero04aab362021-02-15 17:38:16176 NavigationEntryImpl* nav_entry =
177 navigator().controller().GetLastCommittedEntry();
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45178 if (nav_entry) {
179 nav_entry->RemoveEntryForFrame(this,
180 /* only_if_different_position = */ false);
181 }
182 }
183
dmazzonie950ea232015-03-13 21:39:45184 frame_tree_->FrameRemoved(this);
Carlos Caballero6ff6ace2021-02-05 16:53:00185
186 // Do not dispatch notification for the root frame as ~WebContentsImpl already
187 // dispatches it for now.
188 // TODO(https://crbug.com/1170277): This is only needed because the FrameTree
189 // is a member of WebContentsImpl and we would call back into it during
190 // destruction. We should clean up the FrameTree destruction code and call the
191 // delegate unconditionally.
192 if (parent())
193 render_manager_.delegate()->OnFrameTreeNodeDestroyed(this);
194
ericwilligers254597b2016-10-17 10:32:31195 for (auto& observer : observers_)
196 observer.OnFrameTreeNodeDestroyed(this);
Lukasz Anforowicz147141962020-12-16 18:03:24197 observers_.Clear();
alexmose201c7cd2015-06-10 17:14:21198
199 if (opener_)
200 opener_->RemoveObserver(opener_observer_.get());
jochen6004a362017-02-04 00:11:40201 if (original_opener_)
202 original_opener_->RemoveObserver(original_opener_observer_.get());
dmazzonie950ea232015-03-13 21:39:45203
204 g_frame_tree_node_id_map.Get().erase(frame_tree_node_id_);
jam39258caf2016-11-02 14:48:18205
Daniel Chengc3d1e8d2021-06-23 02:11:45206 // If a frame with a pending navigation is detached, make sure the
207 // WebContents (and its observers) update their loading state.
208 // TODO(dcheng): This should just check `IsLoading()`, but `IsLoading()`
209 // assumes that `current_frame_host_` is not null. This is incompatible with
210 // prerender activation when destroying the old frame tree (see above).
danakjf9400602019-06-07 15:44:58211 bool did_stop_loading = false;
212
jam39258caf2016-11-02 14:48:18213 if (navigation_request_) {
danakjf9400602019-06-07 15:44:58214 navigation_request_.reset();
danakjf9400602019-06-07 15:44:58215 did_stop_loading = true;
jam39258caf2016-11-02 14:48:18216 }
Nate Chapin22ea6592019-03-05 22:29:02217
danakjf9400602019-06-07 15:44:58218 // ~SiteProcessCountTracker DCHECKs in some tests if the speculative
219 // RenderFrameHostImpl is not destroyed last. Ideally this would be closer to
220 // (possible before) the ResetLoadingState() call above.
danakjf9400602019-06-07 15:44:58221 if (render_manager_.speculative_frame_host()) {
Daniel Chengc3d1e8d2021-06-23 02:11:45222 // TODO(dcheng): Shouldn't a FrameTreeNode with a speculative
223 // RenderFrameHost always be considered loading?
danakjf9400602019-06-07 15:44:58224 did_stop_loading |= render_manager_.speculative_frame_host()->is_loading();
Daniel Chengc3d1e8d2021-06-23 02:11:45225 // `FrameTree::Shutdown()` has special handling for the main frame's
226 // speculative RenderFrameHost, and the speculative RenderFrameHost should
227 // already be reset for main frames.
228 DCHECK(!IsMainFrame());
229
230 // This does not use `UnsetSpeculativeRenderFrameHost()`: if the speculative
231 // RenderFrameHost has already reached kPendingCommit, it would needlessly
232 // re-create a proxy for a frame that's going away.
233 render_manager_.DiscardSpeculativeRenderFrameHostForShutdown();
danakjf9400602019-06-07 15:44:58234 }
235
236 if (did_stop_loading)
237 DidStopLoading();
238
Harkiran Bolaria59290d62021-03-17 01:53:01239 // IsLoading() requires that current_frame_host() is non-null.
240 DCHECK(!current_frame_host() || !IsLoading());
[email protected]9b159a52013-10-03 17:24:55241}
242
alexmose201c7cd2015-06-10 17:14:21243void FrameTreeNode::AddObserver(Observer* observer) {
244 observers_.AddObserver(observer);
245}
246
247void FrameTreeNode::RemoveObserver(Observer* observer) {
248 observers_.RemoveObserver(observer);
249}
250
[email protected]94d0cc12013-12-18 00:07:41251bool FrameTreeNode::IsMainFrame() const {
252 return frame_tree_->root() == this;
253}
254
Hiroki Nakagawaab309622021-05-19 16:38:13255void FrameTreeNode::ResetForNavigation() {
arthursonzogni76098e52020-11-25 14:18:45256 // This frame has had its user activation bits cleared in the renderer before
257 // arriving here. We just need to clear them here and in the other renderer
258 // processes that may have a reference to this frame.
Alexander Timin45b716c2020-11-06 01:40:31259 //
260 // We do not take user activation into account when calculating
261 // |ResetForNavigationResult|, as we are using it to determine bfcache
262 // eligibility and the page can get another user gesture after restore.
Antonio Gomes4b2c5132020-01-16 11:49:48263 UpdateUserActivationState(
Mustaq Ahmeddc195e5b2020-08-04 18:45:11264 blink::mojom::UserActivationUpdateType::kClearActivation,
265 blink::mojom::UserActivationNotificationType::kNone);
Ian Clelland5cbaaf82017-11-27 22:00:03266}
267
yilkal34a3d752019-08-30 18:20:30268size_t FrameTreeNode::GetFrameTreeSize() const {
269 if (is_collapsed())
270 return 0;
271
272 size_t size = 0;
273 for (size_t i = 0; i < child_count(); i++) {
274 size += child_at(i)->GetFrameTreeSize();
275 }
276
277 // Account for this node.
278 size++;
279 return size;
280}
281
alexmose201c7cd2015-06-10 17:14:21282void FrameTreeNode::SetOpener(FrameTreeNode* opener) {
283 if (opener_) {
284 opener_->RemoveObserver(opener_observer_.get());
285 opener_observer_.reset();
286 }
287
288 opener_ = opener;
289
290 if (opener_) {
Jeremy Roman04f27c372017-10-27 15:20:55291 opener_observer_ = std::make_unique<OpenerDestroyedObserver>(this, false);
alexmose201c7cd2015-06-10 17:14:21292 opener_->AddObserver(opener_observer_.get());
293 }
294}
295
Wolfgang Beyerd8809db2020-09-30 15:29:39296void FrameTreeNode::SetOpenerDevtoolsFrameToken(
297 base::UnguessableToken opener_devtools_frame_token) {
298 DCHECK(!opener_devtools_frame_token_ ||
299 opener_devtools_frame_token_->is_empty());
300 opener_devtools_frame_token_ = std::move(opener_devtools_frame_token);
301}
302
jochen6004a362017-02-04 00:11:40303void FrameTreeNode::SetOriginalOpener(FrameTreeNode* opener) {
Avi Drissman36465f332017-09-11 20:49:39304 // The original opener tracks main frames only.
avi8d1aa162017-03-27 18:27:37305 DCHECK(opener == nullptr || !opener->parent());
jochen6004a362017-02-04 00:11:40306
Avi Drissman36465f332017-09-11 20:49:39307 if (original_opener_) {
308 original_opener_->RemoveObserver(original_opener_observer_.get());
309 original_opener_observer_.reset();
310 }
311
jochen6004a362017-02-04 00:11:40312 original_opener_ = opener;
313
314 if (original_opener_) {
jochen6004a362017-02-04 00:11:40315 original_opener_observer_ =
Jeremy Roman04f27c372017-10-27 15:20:55316 std::make_unique<OpenerDestroyedObserver>(this, true);
jochen6004a362017-02-04 00:11:40317 original_opener_->AddObserver(original_opener_observer_.get());
318 }
319}
320
creisf0f069a2015-07-23 23:51:53321void FrameTreeNode::SetCurrentURL(const GURL& url) {
Rakina Zata Amnifc4cc3d42021-06-10 09:03:56322 if (!has_committed_real_load_ && !url.IsAboutBlank()) {
creisf0f069a2015-07-23 23:51:53323 has_committed_real_load_ = true;
Rakina Zata Amnifc4cc3d42021-06-10 09:03:56324 is_on_initial_empty_document_or_subsequent_empty_documents_ = false;
325 }
Erik Chen173bf3042017-07-31 06:06:21326 current_frame_host()->SetLastCommittedUrl(url);
xiaochenghb9554bb2016-05-21 14:20:48327 blame_context_.TakeSnapshot();
creisf0f069a2015-07-23 23:51:53328}
329
estarkbd8e26f2016-03-16 23:30:37330void FrameTreeNode::SetCurrentOrigin(
331 const url::Origin& origin,
332 bool is_potentially_trustworthy_unique_origin) {
Antonio Sartori90f41212021-01-22 10:08:34333 if (!origin.IsSameOriginWith(replication_state_->origin) ||
334 replication_state_->has_potentially_trustworthy_unique_origin !=
estarkbd8e26f2016-03-16 23:30:37335 is_potentially_trustworthy_unique_origin) {
336 render_manager_.OnDidUpdateOrigin(origin,
337 is_potentially_trustworthy_unique_origin);
338 }
Antonio Sartori90f41212021-01-22 10:08:34339 replication_state_->origin = origin;
340 replication_state_->has_potentially_trustworthy_unique_origin =
estarkbd8e26f2016-03-16 23:30:37341 is_potentially_trustworthy_unique_origin;
alexmosa7a4ff822015-04-27 17:59:56342}
alexmosbe2f4c32015-03-10 02:30:23343
engedy6e2e0992017-05-25 18:58:42344void FrameTreeNode::SetCollapsed(bool collapsed) {
345 DCHECK(!IsMainFrame());
346 if (is_collapsed_ == collapsed)
347 return;
348
349 is_collapsed_ = collapsed;
350 render_manager_.OnDidChangeCollapsedState(collapsed);
351}
352
Harkiran Bolaria59290d62021-03-17 01:53:01353void FrameTreeNode::SetFrameTree(FrameTree& frame_tree) {
Hiroki Nakagawa0a90bd42021-04-21 01:53:05354 DCHECK(blink::features::IsPrerender2Enabled());
Harkiran Bolaria59290d62021-03-17 01:53:01355 frame_tree_ = &frame_tree;
356}
357
lukasza464d8692016-02-22 19:26:32358void FrameTreeNode::SetFrameName(const std::string& name,
359 const std::string& unique_name) {
Antonio Sartori90f41212021-01-22 10:08:34360 if (name == replication_state_->name) {
lukasza464d8692016-02-22 19:26:32361 // |unique_name| shouldn't change unless |name| changes.
Antonio Sartori90f41212021-01-22 10:08:34362 DCHECK_EQ(unique_name, replication_state_->unique_name);
lukasza464d8692016-02-22 19:26:32363 return;
364 }
lukasza5140a412016-09-15 21:12:30365
366 if (parent()) {
367 // Non-main frames should have a non-empty unique name.
368 DCHECK(!unique_name.empty());
369 } else {
370 // Unique name of main frames should always stay empty.
371 DCHECK(unique_name.empty());
372 }
373
Daniel Cheng6ca7f1c92017-08-09 21:45:41374 // Note the unique name should only be able to change before the first real
375 // load is committed, but that's not strongly enforced here.
lukasza464d8692016-02-22 19:26:32376 render_manager_.OnDidUpdateName(name, unique_name);
Antonio Sartori90f41212021-01-22 10:08:34377 replication_state_->name = name;
378 replication_state_->unique_name = unique_name;
alexmosbe2f4c32015-03-10 02:30:23379}
380
mkwstf672e7ef2016-06-09 20:51:07381void FrameTreeNode::SetInsecureRequestPolicy(
Julie Jeongeun Kimd90e2dd2020-03-03 11:45:37382 blink::mojom::InsecureRequestPolicy policy) {
Antonio Sartori90f41212021-01-22 10:08:34383 if (policy == replication_state_->insecure_request_policy)
estarka886b8d2015-12-18 21:53:08384 return;
mkwstf672e7ef2016-06-09 20:51:07385 render_manager_.OnEnforceInsecureRequestPolicy(policy);
Antonio Sartori90f41212021-01-22 10:08:34386 replication_state_->insecure_request_policy = policy;
estarka886b8d2015-12-18 21:53:08387}
388
arthursonzogni4b62a5cb2018-01-17 14:14:26389void FrameTreeNode::SetInsecureNavigationsSet(
390 const std::vector<uint32_t>& insecure_navigations_set) {
391 DCHECK(std::is_sorted(insecure_navigations_set.begin(),
392 insecure_navigations_set.end()));
Antonio Sartori90f41212021-01-22 10:08:34393 if (insecure_navigations_set == replication_state_->insecure_navigations_set)
arthursonzogni4b62a5cb2018-01-17 14:14:26394 return;
395 render_manager_.OnEnforceInsecureNavigationsSet(insecure_navigations_set);
Antonio Sartori90f41212021-01-22 10:08:34396 replication_state_->insecure_navigations_set = insecure_navigations_set;
arthursonzogni4b62a5cb2018-01-17 14:14:26397}
398
Luna Luc3fdacdf2017-11-08 04:48:53399void FrameTreeNode::SetPendingFramePolicy(blink::FramePolicy frame_policy) {
Dominic Farolino08662c82021-06-11 07:36:34400 // The |is_fenced| bit should never be able to transition from what its
401 // initial value was. Since we never expect to be in a position where it can
402 // even be updated to new value, if we catch this happening we have to kill
403 // the renderer and refuse to accept any other frame policy changes here.
404 if (pending_frame_policy_.is_fenced != frame_policy.is_fenced) {
405 mojo::ReportBadMessage(
406 "The `is_fenced` FramePolicy bit is const and should never be changed");
407 return;
408 }
409
Ian Clellandcdc4f312017-10-13 22:24:12410 pending_frame_policy_.sandbox_flags = frame_policy.sandbox_flags;
alexmos6e940102016-01-19 22:47:25411
Ian Clellandcdc4f312017-10-13 22:24:12412 if (parent()) {
413 // Subframes should always inherit their parent's sandbox flags.
Alexander Timin381e7e182020-04-28 19:04:03414 pending_frame_policy_.sandbox_flags |=
415 parent()->frame_tree_node()->active_sandbox_flags();
Charlie Hue1b77ac2019-12-13 21:30:17416 // This is only applied on subframes; container policy and required document
417 // policy are not mutable on main frame.
Ian Clellandcdc4f312017-10-13 22:24:12418 pending_frame_policy_.container_policy = frame_policy.container_policy;
Charlie Hue1b77ac2019-12-13 21:30:17419 pending_frame_policy_.required_document_policy =
420 frame_policy.required_document_policy;
Ian Clellandcdc4f312017-10-13 22:24:12421 }
iclelland92f8c0b2017-04-19 12:43:05422}
423
alexmos9f8705a2015-05-06 19:58:59424FrameTreeNode* FrameTreeNode::PreviousSibling() const {
paulmeyer322777fb2016-05-16 23:15:39425 return GetSibling(-1);
426}
alexmos9f8705a2015-05-06 19:58:59427
paulmeyer322777fb2016-05-16 23:15:39428FrameTreeNode* FrameTreeNode::NextSibling() const {
429 return GetSibling(1);
alexmos9f8705a2015-05-06 19:58:59430}
431
fdegans4a49ce932015-03-12 17:11:37432bool FrameTreeNode::IsLoading() const {
433 RenderFrameHostImpl* current_frame_host =
434 render_manager_.current_frame_host();
fdegans4a49ce932015-03-12 17:11:37435
436 DCHECK(current_frame_host);
fdegans39ff0382015-04-29 19:04:39437
clamy610c63b32017-12-22 15:05:18438 if (navigation_request_)
439 return true;
clamy11e11512015-07-07 16:42:17440
clamy610c63b32017-12-22 15:05:18441 RenderFrameHostImpl* speculative_frame_host =
442 render_manager_.speculative_frame_host();
Daniel Chengc3d1e8d2021-06-23 02:11:45443 // TODO(dcheng): Shouldn't a FrameTreeNode with a speculative RenderFrameHost
444 // always be considered loading?
clamy610c63b32017-12-22 15:05:18445 if (speculative_frame_host && speculative_frame_host->is_loading())
446 return true;
fdegans4a49ce932015-03-12 17:11:37447 return current_frame_host->is_loading();
448}
449
Alex Moshchuk9b0fd822020-10-26 23:08:15450bool FrameTreeNode::HasPendingCrossDocumentNavigation() const {
451 // Having a |navigation_request_| on FrameTreeNode implies that there's an
452 // ongoing navigation that hasn't reached the ReadyToCommit state. If the
453 // navigation is between ReadyToCommit and DidCommitNavigation, the
454 // NavigationRequest will be held by RenderFrameHost, which is checked below.
455 if (navigation_request_ && !navigation_request_->IsSameDocument())
456 return true;
457
458 // Having a speculative RenderFrameHost should imply a cross-document
459 // navigation.
460 if (render_manager_.speculative_frame_host())
461 return true;
462
463 return render_manager_.current_frame_host()
464 ->HasPendingCommitForCrossDocumentNavigation();
465}
466
Charlie Hu5ffc0152019-12-06 15:59:53467bool FrameTreeNode::CommitFramePolicy(
468 const blink::FramePolicy& new_frame_policy) {
469 bool did_change_flags = new_frame_policy.sandbox_flags !=
Antonio Sartori90f41212021-01-22 10:08:34470 replication_state_->frame_policy.sandbox_flags;
iclelland92f8c0b2017-04-19 12:43:05471 bool did_change_container_policy =
Charlie Hu5ffc0152019-12-06 15:59:53472 new_frame_policy.container_policy !=
Antonio Sartori90f41212021-01-22 10:08:34473 replication_state_->frame_policy.container_policy;
Charlie Hue1b77ac2019-12-13 21:30:17474 bool did_change_required_document_policy =
475 pending_frame_policy_.required_document_policy !=
Antonio Sartori90f41212021-01-22 10:08:34476 replication_state_->frame_policy.required_document_policy;
Dominic Farolino08662c82021-06-11 07:36:34477 DCHECK_EQ(new_frame_policy.is_fenced,
478 replication_state_->frame_policy.is_fenced);
Antonio Sartori90f41212021-01-22 10:08:34479 if (did_change_flags) {
480 replication_state_->frame_policy.sandbox_flags =
Charlie Hu5ffc0152019-12-06 15:59:53481 new_frame_policy.sandbox_flags;
Antonio Sartori90f41212021-01-22 10:08:34482 }
483 if (did_change_container_policy) {
484 replication_state_->frame_policy.container_policy =
Charlie Hu5ffc0152019-12-06 15:59:53485 new_frame_policy.container_policy;
Antonio Sartori90f41212021-01-22 10:08:34486 }
487 if (did_change_required_document_policy) {
488 replication_state_->frame_policy.required_document_policy =
Charlie Hue1b77ac2019-12-13 21:30:17489 new_frame_policy.required_document_policy;
Antonio Sartori90f41212021-01-22 10:08:34490 }
Charlie Hue1b77ac2019-12-13 21:30:17491
Charlie Hu5ffc0152019-12-06 15:59:53492 UpdateFramePolicyHeaders(new_frame_policy.sandbox_flags,
Charlie Hue20fe2f2021-03-07 03:39:59493 replication_state_->permissions_policy_header);
Charlie Hue1b77ac2019-12-13 21:30:17494 return did_change_flags || did_change_container_policy ||
Dave Tapuska7fdfc2f2021-06-08 17:38:40495 did_change_required_document_policy;
alexmos6b294562015-03-05 19:24:10496}
497
Arthur Hemeryc3380172018-01-22 14:00:17498void FrameTreeNode::TransferNavigationRequestOwnership(
499 RenderFrameHostImpl* render_frame_host) {
Andrey Kosyakovf2d4ff72018-10-29 20:09:59500 devtools_instrumentation::OnResetNavigationRequest(navigation_request_.get());
Arthur Hemeryc3380172018-01-22 14:00:17501 render_frame_host->SetNavigationRequest(std::move(navigation_request_));
502}
503
carloskc49005eb2015-06-16 11:25:07504void FrameTreeNode::CreatedNavigationRequest(
dcheng9bfa5162016-04-09 01:00:57505 std::unique_ptr<NavigationRequest> navigation_request) {
arthursonzognic79c251c2016-08-18 15:00:37506 // This is never called when navigating to a Javascript URL. For the loading
507 // state, this matches what Blink is doing: Blink doesn't send throbber
508 // notifications for Javascript URLS.
509 DCHECK(!navigation_request->common_params().url.SchemeIs(
510 url::kJavaScriptScheme));
511
clamy44e84ce2016-02-22 15:38:25512 bool was_previously_loading = frame_tree()->IsLoading();
513
clamy82a2f4d2016-02-02 14:20:41514 // There's no need to reset the state: there's still an ongoing load, and the
515 // RenderFrameHostManager will take care of updates to the speculative
516 // RenderFrameHost in DidCreateNavigationRequest below.
jamcd0b7b22017-03-24 22:13:05517 if (was_previously_loading) {
Mohamed Abdelhalimf03d4a22019-10-01 13:34:31518 if (navigation_request_ && navigation_request_->IsNavigationStarted()) {
jamcd0b7b22017-03-24 22:13:05519 // Mark the old request as aborted.
Mohamed Abdelhalimb4db22a2019-06-18 10:46:52520 navigation_request_->set_net_error(net::ERR_ABORTED);
jamcd0b7b22017-03-24 22:13:05521 }
Arthur Hemery241b9392019-10-24 11:08:41522 ResetNavigationRequest(true);
jamcd0b7b22017-03-24 22:13:05523 }
clamy44e84ce2016-02-22 15:38:25524
525 navigation_request_ = std::move(navigation_request);
Shubhie Panickerddf2a4e2018-03-06 00:09:06526 if (was_discarded_) {
527 navigation_request_->set_was_discarded();
528 was_discarded_ = false;
529 }
clamy8e2e299202016-04-05 11:44:59530 render_manager()->DidCreateNavigationRequest(navigation_request_.get());
fdegans39ff0382015-04-29 19:04:39531
Lucas Furukawa Gadanief8290a2019-07-29 20:27:51532 bool to_different_document = !NavigationTypeUtils::IsSameDocument(
arthursonzogni92f18682017-02-08 23:00:04533 navigation_request_->common_params().navigation_type);
534
535 DidStartLoading(to_different_document, was_previously_loading);
clamydcb434c12015-04-16 19:29:16536}
537
Arthur Hemery241b9392019-10-24 11:08:41538void FrameTreeNode::ResetNavigationRequest(bool keep_state) {
fdegans39ff0382015-04-29 19:04:39539 if (!navigation_request_)
540 return;
John Abd-El-Malekdcc7bf42017-09-12 22:30:23541
Andrey Kosyakovf2d4ff72018-10-29 20:09:59542 devtools_instrumentation::OnResetNavigationRequest(navigation_request_.get());
clamydcb434c12015-04-16 19:29:16543 navigation_request_.reset();
fdegans39ff0382015-04-29 19:04:39544
clamy82a2f4d2016-02-02 14:20:41545 if (keep_state)
fdegans39ff0382015-04-29 19:04:39546 return;
547
clamy82a2f4d2016-02-02 14:20:41548 // The RenderFrameHostManager should clean up any speculative RenderFrameHost
549 // it created for the navigation. Also register that the load stopped.
fdegans39ff0382015-04-29 19:04:39550 DidStopLoading();
551 render_manager_.CleanUpNavigation();
clamydcb434c12015-04-16 19:29:16552}
553
clamy44e84ce2016-02-22 15:38:25554void FrameTreeNode::DidStartLoading(bool to_different_document,
555 bool was_previously_loading) {
Camille Lamyefd54b02018-10-04 16:54:14556 TRACE_EVENT2("navigation", "FrameTreeNode::DidStartLoading",
557 "frame_tree_node", frame_tree_node_id(), "to different document",
558 to_different_document);
fdegansa696e5112015-04-17 01:57:59559
Carlos Caballero03262522021-02-05 14:49:58560 frame_tree_->DidStartLoadingNode(*this, to_different_document,
561 was_previously_loading);
fdegansa696e5112015-04-17 01:57:59562
563 // Set initial load progress and update overall progress. This will notify
564 // the WebContents of the load progress change.
Sreeja Kamishetty0be3b1b2021-08-12 17:04:15565 DidChangeLoadProgress(blink::kInitialLoadProgress);
fdegansa696e5112015-04-17 01:57:59566
567 // Notify the RenderFrameHostManager of the event.
568 render_manager()->OnDidStartLoading();
569}
570
571void FrameTreeNode::DidStopLoading() {
Camille Lamyefd54b02018-10-04 16:54:14572 TRACE_EVENT1("navigation", "FrameTreeNode::DidStopLoading", "frame_tree_node",
573 frame_tree_node_id());
fdegansa696e5112015-04-17 01:57:59574 // Set final load progress and update overall progress. This will notify
575 // the WebContents of the load progress change.
Sreeja Kamishetty0be3b1b2021-08-12 17:04:15576 DidChangeLoadProgress(blink::kFinalLoadProgress);
fdegansa696e5112015-04-17 01:57:59577
Lucas Furukawa Gadani6faef602019-05-06 21:16:03578 // Notify the RenderFrameHostManager of the event.
579 render_manager()->OnDidStopLoading();
580
Carlos Caballero03262522021-02-05 14:49:58581 frame_tree_->DidStopLoadingNode(*this);
fdegansa696e5112015-04-17 01:57:59582}
583
584void FrameTreeNode::DidChangeLoadProgress(double load_progress) {
Sreeja Kamishetty0be3b1b2021-08-12 17:04:15585 DCHECK_GE(load_progress, blink::kInitialLoadProgress);
586 DCHECK_LE(load_progress, blink::kFinalLoadProgress);
587 current_frame_host()->DidChangeLoadProgress(load_progress);
fdegansa696e5112015-04-17 01:57:59588}
589
clamyf73862c42015-07-08 12:31:33590bool FrameTreeNode::StopLoading() {
arthursonzogni66f711c2019-10-08 14:40:36591 if (navigation_request_ && navigation_request_->IsNavigationStarted())
592 navigation_request_->set_net_error(net::ERR_ABORTED);
Arthur Hemery241b9392019-10-24 11:08:41593 ResetNavigationRequest(false);
clamyf73862c42015-07-08 12:31:33594
clamyf73862c42015-07-08 12:31:33595 if (!IsMainFrame())
596 return true;
597
598 render_manager_.Stop();
599 return true;
600}
601
alexmos21acae52015-11-07 01:04:43602void FrameTreeNode::DidFocus() {
603 last_focus_time_ = base::TimeTicks::Now();
ericwilligers254597b2016-10-17 10:32:31604 for (auto& observer : observers_)
605 observer.OnFrameTreeNodeFocused(this);
alexmos21acae52015-11-07 01:04:43606}
607
clamy44e84ce2016-02-22 15:38:25608void FrameTreeNode::BeforeUnloadCanceled() {
609 // TODO(clamy): Support BeforeUnload in subframes.
610 if (!IsMainFrame())
611 return;
612
613 RenderFrameHostImpl* current_frame_host =
614 render_manager_.current_frame_host();
615 DCHECK(current_frame_host);
616 current_frame_host->ResetLoadingState();
617
clamy610c63b32017-12-22 15:05:18618 RenderFrameHostImpl* speculative_frame_host =
619 render_manager_.speculative_frame_host();
620 if (speculative_frame_host)
621 speculative_frame_host->ResetLoadingState();
Alexander Timin23c110b2021-01-14 02:39:04622 // Note: there is no need to set an error code on the NavigationHandle as
623 // the observers have not been notified about its creation.
624 // We also reset navigation request only when this navigation request was
625 // responsible for this dialog, as a new navigation request might cancel
626 // existing unrelated dialog.
627 if (navigation_request_ && navigation_request_->IsWaitingForBeforeUnload())
Arthur Hemery241b9392019-10-24 11:08:41628 ResetNavigationRequest(false);
clamy44e84ce2016-02-22 15:38:25629}
630
Mustaq Ahmedecb5c38e2020-07-29 00:34:30631bool FrameTreeNode::NotifyUserActivation(
632 blink::mojom::UserActivationNotificationType notification_type) {
Alex Moshchuk03904192021-04-02 07:29:08633 // User Activation V2 requires activating all ancestor frames in addition to
634 // the current frame. See
635 // https://html.spec.whatwg.org/multipage/interaction.html#tracking-user-activation.
Alexander Timina1dfadaa2020-04-28 13:30:06636 for (RenderFrameHostImpl* rfh = current_frame_host(); rfh;
637 rfh = rfh->GetParent()) {
John Delaneyb625dca92021-04-14 17:00:34638 rfh->DidReceiveUserActivation();
Mustaq Ahmedecb5c38e2020-07-29 00:34:30639 rfh->frame_tree_node()->user_activation_state_.Activate(notification_type);
John Delaneyedd8d6c2019-01-25 00:23:57640 }
Alex Moshchuk03904192021-04-02 07:29:08641
Antonio Sartori90f41212021-01-22 10:08:34642 replication_state_->has_active_user_gesture = true;
Mustaq Ahmeda5dfa60b2018-12-08 00:30:14643
Mustaq Ahmed0180320f2019-03-21 16:07:01644 // See the "Same-origin Visibility" section in |UserActivationState| class
645 // doc.
Mustaq Ahmede5f12562019-10-30 18:02:03646 if (base::FeatureList::IsEnabled(
Mustaq Ahmeda5dfa60b2018-12-08 00:30:14647 features::kUserActivationSameOriginVisibility)) {
648 const url::Origin& current_origin =
649 this->current_frame_host()->GetLastCommittedOrigin();
650 for (FrameTreeNode* node : frame_tree()->Nodes()) {
651 if (node->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith(
652 current_origin)) {
Mustaq Ahmedecb5c38e2020-07-29 00:34:30653 node->user_activation_state_.Activate(notification_type);
Mustaq Ahmeda5dfa60b2018-12-08 00:30:14654 }
655 }
656 }
657
Carlos Caballero40b0efd2021-01-26 11:55:00658 navigator().controller().NotifyUserActivation();
Alex Moshchuk03904192021-04-02 07:29:08659 current_frame_host()->MaybeIsolateForUserActivation();
Shivani Sharma194877032019-03-07 17:52:47660
Mustaq Ahmedc4cb7162018-06-05 16:28:36661 return true;
662}
663
664bool FrameTreeNode::ConsumeTransientUserActivation() {
665 bool was_active = user_activation_state_.IsActive();
666 for (FrameTreeNode* node : frame_tree()->Nodes())
667 node->user_activation_state_.ConsumeIfActive();
Antonio Sartori90f41212021-01-22 10:08:34668 replication_state_->has_active_user_gesture = false;
Mustaq Ahmedc4cb7162018-06-05 16:28:36669 return was_active;
670}
671
Shivani Sharmac4f561582018-11-15 15:58:39672bool FrameTreeNode::ClearUserActivation() {
Shivani Sharmac4f561582018-11-15 15:58:39673 for (FrameTreeNode* node : frame_tree()->SubtreeNodes(this))
674 node->user_activation_state_.Clear();
Antonio Sartori90f41212021-01-22 10:08:34675 replication_state_->has_active_user_gesture = false;
Shivani Sharmac4f561582018-11-15 15:58:39676 return true;
677}
678
Ella Ge9caed612019-08-09 16:17:25679bool FrameTreeNode::VerifyUserActivation() {
Ella Gea78f6772019-12-11 10:35:25680 DCHECK(base::FeatureList::IsEnabled(
681 features::kBrowserVerifiedUserActivationMouse) ||
682 base::FeatureList::IsEnabled(
683 features::kBrowserVerifiedUserActivationKeyboard));
684
Ella Ge9caed612019-08-09 16:17:25685 return render_manager_.current_frame_host()
686 ->GetRenderWidgetHost()
Mustaq Ahmed83bb1722019-10-22 20:00:10687 ->RemovePendingUserActivationIfAvailable();
Ella Ge9caed612019-08-09 16:17:25688}
689
Mustaq Ahmedc4cb7162018-06-05 16:28:36690bool FrameTreeNode::UpdateUserActivationState(
Mustaq Ahmeddc195e5b2020-08-04 18:45:11691 blink::mojom::UserActivationUpdateType update_type,
692 blink::mojom::UserActivationNotificationType notification_type) {
Ella Ge9caed612019-08-09 16:17:25693 bool update_result = false;
Mustaq Ahmedc4cb7162018-06-05 16:28:36694 switch (update_type) {
Antonio Gomes4b2c5132020-01-16 11:49:48695 case blink::mojom::UserActivationUpdateType::kConsumeTransientActivation:
Ella Ge9caed612019-08-09 16:17:25696 update_result = ConsumeTransientUserActivation();
697 break;
Antonio Gomes4b2c5132020-01-16 11:49:48698 case blink::mojom::UserActivationUpdateType::kNotifyActivation:
Mustaq Ahmeddc195e5b2020-08-04 18:45:11699 update_result = NotifyUserActivation(notification_type);
Ella Ge9caed612019-08-09 16:17:25700 break;
Antonio Gomes4b2c5132020-01-16 11:49:48701 case blink::mojom::UserActivationUpdateType::
Liviu Tintad9391fb92020-09-28 23:50:07702 kNotifyActivationPendingBrowserVerification: {
703 const bool user_activation_verified = VerifyUserActivation();
704 // Add UMA metric for when browser user activation verification succeeds
705 base::UmaHistogramBoolean("Event.BrowserVerifiedUserActivation",
706 user_activation_verified);
707 if (user_activation_verified) {
Mustaq Ahmedecb5c38e2020-07-29 00:34:30708 update_result = NotifyUserActivation(
Mustaq Ahmed2cfb0402020-09-29 19:24:35709 blink::mojom::UserActivationNotificationType::kInteraction);
Antonio Gomes4b2c5132020-01-16 11:49:48710 update_type = blink::mojom::UserActivationUpdateType::kNotifyActivation;
Ella Ge9caed612019-08-09 16:17:25711 } else {
arthursonzogni9816b9192021-03-29 16:09:19712 // TODO(https://crbug.com/848778): We need to decide what to do when
713 // user activation verification failed. NOTREACHED here will make all
Ella Ge9caed612019-08-09 16:17:25714 // unrelated tests that inject event to renderer fail.
715 return false;
716 }
Liviu Tintad9391fb92020-09-28 23:50:07717 } break;
Antonio Gomes4b2c5132020-01-16 11:49:48718 case blink::mojom::UserActivationUpdateType::kClearActivation:
Ella Ge9caed612019-08-09 16:17:25719 update_result = ClearUserActivation();
720 break;
Mustaq Ahmedc4cb7162018-06-05 16:28:36721 }
Mustaq Ahmeddc195e5b2020-08-04 18:45:11722 render_manager_.UpdateUserActivationState(update_type, notification_type);
Ella Ge9caed612019-08-09 16:17:25723 return update_result;
japhet61835ae12017-01-20 01:25:39724}
725
Mustaq Ahmed01261742019-12-16 15:49:06726void FrameTreeNode::OnSetHadStickyUserActivationBeforeNavigation(bool value) {
727 render_manager_.OnSetHadStickyUserActivationBeforeNavigation(value);
Antonio Sartori90f41212021-01-22 10:08:34728 replication_state_->has_received_user_gesture_before_nav = value;
Becca Hughes60af7d42017-12-12 10:53:15729}
730
paulmeyer322777fb2016-05-16 23:15:39731FrameTreeNode* FrameTreeNode::GetSibling(int relative_offset) const {
paulmeyerf3119f52016-05-17 17:37:19732 if (!parent_ || !parent_->child_count())
paulmeyer322777fb2016-05-16 23:15:39733 return nullptr;
734
735 for (size_t i = 0; i < parent_->child_count(); ++i) {
736 if (parent_->child_at(i) == this) {
737 if ((relative_offset < 0 && static_cast<size_t>(-relative_offset) > i) ||
738 i + relative_offset >= parent_->child_count()) {
739 return nullptr;
740 }
741 return parent_->child_at(i + relative_offset);
742 }
743 }
744
745 NOTREACHED() << "FrameTreeNode not found in its parent's children.";
746 return nullptr;
747}
748
Alexander Timin45b716c2020-11-06 01:40:31749bool FrameTreeNode::UpdateFramePolicyHeaders(
arthursonzognib93a4472020-04-10 07:38:00750 network::mojom::WebSandboxFlags sandbox_flags,
Charlie Hue24f04832021-03-04 21:07:06751 const blink::ParsedPermissionsPolicy& parsed_header) {
Ian Clellandedb8c5dd2018-03-01 17:01:37752 bool changed = false;
Charlie Hue20fe2f2021-03-07 03:39:59753 if (replication_state_->permissions_policy_header != parsed_header) {
754 replication_state_->permissions_policy_header = parsed_header;
Ian Clellandedb8c5dd2018-03-01 17:01:37755 changed = true;
756 }
Ian Clelland5cbaaf82017-11-27 22:00:03757 // TODO(iclelland): Kill the renderer if sandbox flags is not a subset of the
758 // currently effective sandbox flags from the frame. https://crbug.com/740556
arthursonzognib93a4472020-04-10 07:38:00759 network::mojom::WebSandboxFlags updated_flags =
Ian Clelland5cbaaf82017-11-27 22:00:03760 sandbox_flags | effective_frame_policy().sandbox_flags;
Antonio Sartori90f41212021-01-22 10:08:34761 if (replication_state_->active_sandbox_flags != updated_flags) {
762 replication_state_->active_sandbox_flags = updated_flags;
Ian Clellandedb8c5dd2018-03-01 17:01:37763 changed = true;
764 }
765 // Notify any proxies if the policies have been changed.
766 if (changed)
767 render_manager()->OnDidSetFramePolicyHeaders();
Alexander Timin45b716c2020-11-06 01:40:31768 return changed;
Ian Clelland5cbaaf82017-11-27 22:00:03769}
770
Arthur Sonzognif8840b92018-11-07 14:10:35771void FrameTreeNode::PruneChildFrameNavigationEntries(
772 NavigationEntryImpl* entry) {
773 for (size_t i = 0; i < current_frame_host()->child_count(); ++i) {
774 FrameTreeNode* child = current_frame_host()->child_at(i);
775 if (child->is_created_by_script_) {
776 entry->RemoveEntryForFrame(child,
777 /* only_if_different_position = */ false);
778 } else {
779 child->PruneChildFrameNavigationEntries(entry);
780 }
781 }
782}
783
Alex Turner10d557a42021-06-01 19:06:49784void FrameTreeNode::SetIsAdSubframe(bool is_ad_subframe) {
785 if (is_ad_subframe == replication_state_->is_ad_subframe)
Alex Turner5a09c462021-03-17 17:07:35786 return;
787
Alex Turner10d557a42021-06-01 19:06:49788 replication_state_->is_ad_subframe = is_ad_subframe;
789 render_manager()->OnDidSetIsAdSubframe(is_ad_subframe);
Yao Xiao24ec9aa2020-01-28 16:36:00790}
791
arthursonzogni034bb9c2020-10-01 08:29:56792void FrameTreeNode::SetInitialPopupURL(const GURL& initial_popup_url) {
793 DCHECK(initial_popup_url_.is_empty());
794 DCHECK(!has_committed_real_load_);
795 initial_popup_url_ = initial_popup_url;
796}
797
798void FrameTreeNode::SetPopupCreatorOrigin(
799 const url::Origin& popup_creator_origin) {
800 DCHECK(!has_committed_real_load_);
801 popup_creator_origin_ = popup_creator_origin;
802}
803
Alexander Timinbebb2002021-04-20 15:42:24804void FrameTreeNode::WriteIntoTrace(perfetto::TracedValue context) const {
Alexander Timinf785f342021-03-18 00:00:56805 auto dict = std::move(context).WriteDictionary();
806 dict.Add("id", frame_tree_node_id());
807 dict.Add("is_main_frame", IsMainFrame());
808}
809
Rakina Zata Amni4b1968d2021-09-09 03:29:47810void FrameTreeNode::WriteIntoTrace(
811 perfetto::TracedProto<perfetto::protos::pbzero::FrameTreeNodeInfo> proto) {
812 proto->set_is_main_frame(IsMainFrame());
813 proto->set_frame_tree_node_id(frame_tree_node_id());
814 proto->set_has_speculative_render_frame_host(
815 !!render_manager()->speculative_frame_host());
816}
817
Carlos Caballero76711352021-03-24 17:38:21818bool FrameTreeNode::HasNavigation() {
819 if (navigation_request())
820 return true;
821
822 // Same-RenderFrameHost navigation is committing:
823 if (current_frame_host()->HasPendingCommitNavigation())
824 return true;
825
826 // Cross-RenderFrameHost navigation is committing:
827 if (render_manager()->speculative_frame_host())
828 return true;
829
830 return false;
831}
832
Dominic Farolino4bc10ee2021-08-31 00:37:36833bool FrameTreeNode::IsFencedFrameRoot() const {
shivanigithubf3ddff52021-07-03 22:06:30834 if (!blink::features::IsFencedFramesEnabled())
835 return false;
836
837 switch (blink::features::kFencedFramesImplementationTypeParam.Get()) {
838 case blink::features::FencedFramesImplementationType::kMPArch: {
Dominic Farolino4bc10ee2021-08-31 00:37:36839 return IsMainFrame() &&
840 frame_tree()->type() == FrameTree::Type::kFencedFrame;
shivanigithubf3ddff52021-07-03 22:06:30841 }
842 case blink::features::FencedFramesImplementationType::kShadowDOM: {
843 return effective_frame_policy().is_fenced;
844 }
845 default:
846 return false;
847 }
848}
849
850bool FrameTreeNode::IsInFencedFrameTree() const {
851 if (!blink::features::IsFencedFramesEnabled())
852 return false;
853
854 switch (blink::features::kFencedFramesImplementationTypeParam.Get()) {
855 case blink::features::FencedFramesImplementationType::kMPArch:
Dominic Farolino4bc10ee2021-08-31 00:37:36856 return frame_tree()->type() == FrameTree::Type::kFencedFrame;
shivanigithubf3ddff52021-07-03 22:06:30857 case blink::features::FencedFramesImplementationType::kShadowDOM: {
858 auto* node = this;
859 while (node) {
860 if (node->effective_frame_policy().is_fenced) {
861 return true;
862 }
863 node = node->parent() ? node->parent()->frame_tree_node() : nullptr;
864 }
865 return false;
866 }
867 default:
868 return false;
869 }
870}
871
[email protected]9b159a52013-10-03 17:24:55872} // namespace content