blob: 0f303afa07ad617024c50f4cca73d4815ccb8bb8 [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.h"
26#include "content/common/navigation_params_utils.h"
dmazzonie950ea232015-03-13 21:39:4527#include "content/public/browser/browser_thread.h"
Mustaq Ahmeda5dfa60b2018-12-08 00:30:1428#include "content/public/common/content_features.h"
arthursonzognib93a4472020-04-10 07:38:0029#include "services/network/public/cpp/web_sandbox_flags.h"
30#include "services/network/public/mojom/web_sandbox_flags.mojom-shared.h"
Harkiran Bolaria59290d62021-03-17 01:53:0131#include "third_party/blink/public/common/features.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// These values indicate the loading progress status. The minimum progress
47// value matches what Blink's ProgressTracker has traditionally used for a
48// minimum progress value.
fdegansa696e5112015-04-17 01:57:5949const double kLoadingProgressMinimum = 0.1;
50const double kLoadingProgressDone = 1.0;
dmazzonie950ea232015-03-13 21:39:4551
fdegansa696e5112015-04-17 01:57:5952} // namespace
fdegans1d16355162015-03-26 11:58:3453
alexmose201c7cd2015-06-10 17:14:2154// This observer watches the opener of its owner FrameTreeNode and clears the
55// owner's opener if the opener is destroyed.
56class FrameTreeNode::OpenerDestroyedObserver : public FrameTreeNode::Observer {
57 public:
jochen6004a362017-02-04 00:11:4058 OpenerDestroyedObserver(FrameTreeNode* owner, bool observing_original_opener)
59 : owner_(owner), observing_original_opener_(observing_original_opener) {}
alexmose201c7cd2015-06-10 17:14:2160
61 // FrameTreeNode::Observer
62 void OnFrameTreeNodeDestroyed(FrameTreeNode* node) override {
jochen6004a362017-02-04 00:11:4063 if (observing_original_opener_) {
Avi Drissman36465f332017-09-11 20:49:3964 // The "original owner" is special. It's used for attribution, and clients
65 // walk down the original owner chain. Therefore, if a link in the chain
66 // is being destroyed, reconnect the observation to the parent of the link
67 // being destroyed.
jochen6004a362017-02-04 00:11:4068 CHECK_EQ(owner_->original_opener(), node);
Avi Drissman36465f332017-09-11 20:49:3969 owner_->SetOriginalOpener(node->original_opener());
70 // |this| is deleted at this point.
jochen6004a362017-02-04 00:11:4071 } else {
72 CHECK_EQ(owner_->opener(), node);
73 owner_->SetOpener(nullptr);
Avi Drissman36465f332017-09-11 20:49:3974 // |this| is deleted at this point.
jochen6004a362017-02-04 00:11:4075 }
alexmose201c7cd2015-06-10 17:14:2176 }
77
78 private:
79 FrameTreeNode* owner_;
jochen6004a362017-02-04 00:11:4080 bool observing_original_opener_;
alexmose201c7cd2015-06-10 17:14:2181
82 DISALLOW_COPY_AND_ASSIGN(OpenerDestroyedObserver);
83};
84
Kevin McNee88e61552020-10-22 20:41:1185const int FrameTreeNode::kFrameTreeNodeInvalidId = -1;
86
87static_assert(FrameTreeNode::kFrameTreeNodeInvalidId ==
88 RenderFrameHost::kNoFrameTreeNodeId,
89 "Have consistent sentinel values for an invalid FTN id.");
90
vishal.b782eb5d2015-04-29 12:22:5791int FrameTreeNode::next_frame_tree_node_id_ = 1;
[email protected]9b159a52013-10-03 17:24:5592
dmazzonie950ea232015-03-13 21:39:4593// static
vishal.b782eb5d2015-04-29 12:22:5794FrameTreeNode* FrameTreeNode::GloballyFindByID(int frame_tree_node_id) {
mostynb366eaf12015-03-26 00:51:1995 DCHECK_CURRENTLY_ON(BrowserThread::UI);
rob97250742015-12-10 17:45:1596 FrameTreeNodeIdMap* nodes = g_frame_tree_node_id_map.Pointer();
jdoerrie55ec69d2018-10-08 13:34:4697 auto it = nodes->find(frame_tree_node_id);
dmazzonie950ea232015-03-13 21:39:4598 return it == nodes->end() ? nullptr : it->second;
99}
100
Alexander Timin381e7e182020-04-28 19:04:03101// static
102FrameTreeNode* FrameTreeNode::From(RenderFrameHost* rfh) {
103 if (!rfh)
104 return nullptr;
105 return static_cast<RenderFrameHostImpl*>(rfh)->frame_tree_node();
106}
107
Julie Jeongeun Kim70a2e4e2020-02-21 05:09:54108FrameTreeNode::FrameTreeNode(
109 FrameTree* frame_tree,
Alexander Timin381e7e182020-04-28 19:04:03110 RenderFrameHostImpl* parent,
Daniel Cheng6ac128172021-05-25 18:49:01111 blink::mojom::TreeScopeType tree_scope_type,
Julie Jeongeun Kim70a2e4e2020-02-21 05:09:54112 const std::string& name,
113 const std::string& unique_name,
114 bool is_created_by_script,
115 const base::UnguessableToken& devtools_frame_token,
116 const blink::mojom::FrameOwnerProperties& frame_owner_properties,
Dominic Farolino08662c82021-06-11 07:36:34117 blink::mojom::FrameOwnerElementType owner_type,
118 const blink::FramePolicy& frame_policy)
[email protected]bffc8302014-01-23 20:52:16119 : frame_tree_(frame_tree),
[email protected]bffc8302014-01-23 20:52:16120 frame_tree_node_id_(next_frame_tree_node_id_++),
xiaochengh98488162016-05-19 15:17:59121 parent_(parent),
Alexander Timin381e7e182020-04-28 19:04:03122 depth_(parent ? parent->frame_tree_node()->depth_ + 1 : 0u),
Daniel Cheng9bd90f92021-04-23 20:49:45123 frame_owner_element_type_(owner_type),
Daniel Cheng6ac128172021-05-25 18:49:01124 tree_scope_type_(tree_scope_type),
Gyuyoung Kimc16e52e92021-03-19 02:45:37125 replication_state_(blink::mojom::FrameReplicationState::New(
Antonio Sartori90f41212021-01-22 10:08:34126 url::Origin(),
estarka886b8d2015-12-18 21:53:08127 name,
lukasza464d8692016-02-22 19:26:32128 unique_name,
Charlie Hue24f04832021-03-04 21:07:06129 blink::ParsedPermissionsPolicy(),
Antonio Sartori90f41212021-01-22 10:08:34130 network::mojom::WebSandboxFlags::kNone,
Dominic Farolino08662c82021-06-11 07:36:34131 frame_policy,
Daniel Cheng9bd90f92021-04-23 20:49:45132 // should enforce strict mixed content checking
133 blink::mojom::InsecureRequestPolicy::kLeaveInsecureRequestsAlone,
134 // hashes of hosts for insecure request upgrades
135 std::vector<uint32_t>(),
japhet61835ae12017-01-20 01:25:39136 false /* is a potentially trustworthy unique origin */,
danakj359a4342020-05-29 20:38:39137 false /* has an active user gesture */,
Ehsan Karamad192a8da2018-10-21 03:48:08138 false /* has received a user gesture before nav */,
Alex Turner10d557a42021-06-01 19:06:49139 false /* is_ad_subframe */)),
Dominic Farolino08662c82021-06-11 07:36:34140 pending_frame_policy_(frame_policy),
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45141 is_created_by_script_(is_created_by_script),
Pavel Feldman25234722017-10-11 02:49:06142 devtools_frame_token_(devtools_frame_token),
lazyboy70605c32015-11-03 01:27:31143 frame_owner_properties_(frame_owner_properties),
Lukasz Anforowicz147141962020-12-16 18:03:24144 blame_context_(frame_tree_node_id_, FrameTreeNode::From(parent)),
145 render_manager_(this, frame_tree->manager_delegate()) {
rob97250742015-12-10 17:45:15146 std::pair<FrameTreeNodeIdMap::iterator, bool> result =
dmazzonie950ea232015-03-13 21:39:45147 g_frame_tree_node_id_map.Get().insert(
148 std::make_pair(frame_tree_node_id_, this));
149 CHECK(result.second);
benjhaydend4da63d2016-03-11 21:29:33150
xiaochenghb9554bb2016-05-21 14:20:48151 // Note: this should always be done last in the constructor.
152 blame_context_.Initialize();
alexmos998581d2015-01-22 01:01:59153}
[email protected]9b159a52013-10-03 17:24:55154
155FrameTreeNode::~FrameTreeNode() {
Harkiran Bolaria59290d62021-03-17 01:53:01156 // The current frame host may be null when destroying the old frame tree
157 // during prerender activation. However, in such cases, the FrameTree and its
158 // root FrameTreeNode objects are deleted immediately with activation. In all
159 // other cases, there should always be a current frame host.
Harkiran Bolaria59290d62021-03-17 01:53:01160 if (current_frame_host()) {
161 // Remove the children.
162 current_frame_host()->ResetChildren();
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45163
Harkiran Bolaria59290d62021-03-17 01:53:01164 current_frame_host()->ResetLoadingState();
165 } else {
Hiroki Nakagawa0a90bd42021-04-21 01:53:05166 DCHECK(blink::features::IsPrerender2Enabled());
Harkiran Bolaria59290d62021-03-17 01:53:01167 DCHECK(!parent()); // Only main documents can be activated.
168 DCHECK(!opener()); // Prerendered frame trees can't have openers.
169
170 // Activation is not allowed during ongoing navigations.
171 DCHECK(!navigation_request_);
172
Carlos Caballerod1c80432021-04-20 08:16:32173 // TODO(https://crbug.com/1199693): Need to determine how to handle pending
Harkiran Bolaria59290d62021-03-17 01:53:01174 // deletions, as observers will be notified.
175 DCHECK(!render_manager()->speculative_frame_host());
176 }
Nate Chapin22ea6592019-03-05 22:29:02177
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45178 // If the removed frame was created by a script, then its history entry will
179 // never be reused - we can save some memory by removing the history entry.
180 // See also https://crbug.com/784356.
181 if (is_created_by_script_ && parent_) {
Carlos Caballero04aab362021-02-15 17:38:16182 NavigationEntryImpl* nav_entry =
183 navigator().controller().GetLastCommittedEntry();
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45184 if (nav_entry) {
185 nav_entry->RemoveEntryForFrame(this,
186 /* only_if_different_position = */ false);
187 }
188 }
189
dmazzonie950ea232015-03-13 21:39:45190 frame_tree_->FrameRemoved(this);
Carlos Caballero6ff6ace2021-02-05 16:53:00191
192 // Do not dispatch notification for the root frame as ~WebContentsImpl already
193 // dispatches it for now.
194 // TODO(https://crbug.com/1170277): This is only needed because the FrameTree
195 // is a member of WebContentsImpl and we would call back into it during
196 // destruction. We should clean up the FrameTree destruction code and call the
197 // delegate unconditionally.
198 if (parent())
199 render_manager_.delegate()->OnFrameTreeNodeDestroyed(this);
200
ericwilligers254597b2016-10-17 10:32:31201 for (auto& observer : observers_)
202 observer.OnFrameTreeNodeDestroyed(this);
Lukasz Anforowicz147141962020-12-16 18:03:24203 observers_.Clear();
alexmose201c7cd2015-06-10 17:14:21204
205 if (opener_)
206 opener_->RemoveObserver(opener_observer_.get());
jochen6004a362017-02-04 00:11:40207 if (original_opener_)
208 original_opener_->RemoveObserver(original_opener_observer_.get());
dmazzonie950ea232015-03-13 21:39:45209
210 g_frame_tree_node_id_map.Get().erase(frame_tree_node_id_);
jam39258caf2016-11-02 14:48:18211
danakjf9400602019-06-07 15:44:58212 bool did_stop_loading = false;
213
jam39258caf2016-11-02 14:48:18214 if (navigation_request_) {
danakjf9400602019-06-07 15:44:58215 navigation_request_.reset();
Arthur Hemery0dd65812019-08-01 14:18:45216 // If a frame with a pending navigation is detached, make sure the
217 // WebContents (and its observers) update their loading state.
danakjf9400602019-06-07 15:44:58218 did_stop_loading = true;
jam39258caf2016-11-02 14:48:18219 }
Nate Chapin22ea6592019-03-05 22:29:02220
danakjf9400602019-06-07 15:44:58221 // ~SiteProcessCountTracker DCHECKs in some tests if the speculative
222 // RenderFrameHostImpl is not destroyed last. Ideally this would be closer to
223 // (possible before) the ResetLoadingState() call above.
224 //
225 // There is an inherent race condition causing bugs 838348/915179/et al, where
226 // the renderer may have committed the speculative main frame and the browser
227 // has not heard about it yet. If this is a main frame, then in that case the
228 // speculative RenderFrame was unable to be deleted (it is owned by the
229 // renderer) and we should not be able to cancel the navigation at this point.
230 // CleanUpNavigation() would normally be called here but it will try to undo
231 // the navigation and expose the race condition. When it replaces the main
232 // frame with a RenderFrameProxy, that leaks the committed main frame, leaving
233 // the frame and its friend group with pointers that will become invalid
234 // shortly as we are shutting everything down and deleting the RenderView etc.
235 // We avoid this problematic situation by not calling CleanUpNavigation() or
236 // DiscardUnusedFrame() here. The speculative RenderFrameHost is simply
237 // returned and deleted immediately. This satisfies the requirement that the
238 // speculative RenderFrameHost is removed from the RenderFrameHostManager
239 // before it is destroyed.
240 if (render_manager_.speculative_frame_host()) {
241 did_stop_loading |= render_manager_.speculative_frame_host()->is_loading();
242 render_manager_.UnsetSpeculativeRenderFrameHost();
243 }
244
245 if (did_stop_loading)
246 DidStopLoading();
247
Harkiran Bolaria59290d62021-03-17 01:53:01248 // IsLoading() requires that current_frame_host() is non-null.
249 DCHECK(!current_frame_host() || !IsLoading());
[email protected]9b159a52013-10-03 17:24:55250}
251
alexmose201c7cd2015-06-10 17:14:21252void FrameTreeNode::AddObserver(Observer* observer) {
253 observers_.AddObserver(observer);
254}
255
256void FrameTreeNode::RemoveObserver(Observer* observer) {
257 observers_.RemoveObserver(observer);
258}
259
[email protected]94d0cc12013-12-18 00:07:41260bool FrameTreeNode::IsMainFrame() const {
261 return frame_tree_->root() == this;
262}
263
Hiroki Nakagawaab309622021-05-19 16:38:13264void FrameTreeNode::ResetForNavigation() {
arthursonzogni76098e52020-11-25 14:18:45265 // This frame has had its user activation bits cleared in the renderer before
266 // arriving here. We just need to clear them here and in the other renderer
267 // processes that may have a reference to this frame.
Alexander Timin45b716c2020-11-06 01:40:31268 //
269 // We do not take user activation into account when calculating
270 // |ResetForNavigationResult|, as we are using it to determine bfcache
271 // eligibility and the page can get another user gesture after restore.
Antonio Gomes4b2c5132020-01-16 11:49:48272 UpdateUserActivationState(
Mustaq Ahmeddc195e5b2020-08-04 18:45:11273 blink::mojom::UserActivationUpdateType::kClearActivation,
274 blink::mojom::UserActivationNotificationType::kNone);
Ian Clelland5cbaaf82017-11-27 22:00:03275}
276
yilkal34a3d752019-08-30 18:20:30277size_t FrameTreeNode::GetFrameTreeSize() const {
278 if (is_collapsed())
279 return 0;
280
281 size_t size = 0;
282 for (size_t i = 0; i < child_count(); i++) {
283 size += child_at(i)->GetFrameTreeSize();
284 }
285
286 // Account for this node.
287 size++;
288 return size;
289}
290
alexmose201c7cd2015-06-10 17:14:21291void FrameTreeNode::SetOpener(FrameTreeNode* opener) {
292 if (opener_) {
293 opener_->RemoveObserver(opener_observer_.get());
294 opener_observer_.reset();
295 }
296
297 opener_ = opener;
298
299 if (opener_) {
Jeremy Roman04f27c372017-10-27 15:20:55300 opener_observer_ = std::make_unique<OpenerDestroyedObserver>(this, false);
alexmose201c7cd2015-06-10 17:14:21301 opener_->AddObserver(opener_observer_.get());
302 }
303}
304
Wolfgang Beyerd8809db2020-09-30 15:29:39305void FrameTreeNode::SetOpenerDevtoolsFrameToken(
306 base::UnguessableToken opener_devtools_frame_token) {
307 DCHECK(!opener_devtools_frame_token_ ||
308 opener_devtools_frame_token_->is_empty());
309 opener_devtools_frame_token_ = std::move(opener_devtools_frame_token);
310}
311
jochen6004a362017-02-04 00:11:40312void FrameTreeNode::SetOriginalOpener(FrameTreeNode* opener) {
Avi Drissman36465f332017-09-11 20:49:39313 // The original opener tracks main frames only.
avi8d1aa162017-03-27 18:27:37314 DCHECK(opener == nullptr || !opener->parent());
jochen6004a362017-02-04 00:11:40315
Avi Drissman36465f332017-09-11 20:49:39316 if (original_opener_) {
317 original_opener_->RemoveObserver(original_opener_observer_.get());
318 original_opener_observer_.reset();
319 }
320
jochen6004a362017-02-04 00:11:40321 original_opener_ = opener;
322
323 if (original_opener_) {
jochen6004a362017-02-04 00:11:40324 original_opener_observer_ =
Jeremy Roman04f27c372017-10-27 15:20:55325 std::make_unique<OpenerDestroyedObserver>(this, true);
jochen6004a362017-02-04 00:11:40326 original_opener_->AddObserver(original_opener_observer_.get());
327 }
328}
329
creisf0f069a2015-07-23 23:51:53330void FrameTreeNode::SetCurrentURL(const GURL& url) {
Rakina Zata Amnifc4cc3d42021-06-10 09:03:56331 if (!has_committed_real_load_ && !url.IsAboutBlank()) {
creisf0f069a2015-07-23 23:51:53332 has_committed_real_load_ = true;
Rakina Zata Amnifc4cc3d42021-06-10 09:03:56333 is_on_initial_empty_document_or_subsequent_empty_documents_ = false;
334 }
Erik Chen173bf3042017-07-31 06:06:21335 current_frame_host()->SetLastCommittedUrl(url);
xiaochenghb9554bb2016-05-21 14:20:48336 blame_context_.TakeSnapshot();
creisf0f069a2015-07-23 23:51:53337}
338
estarkbd8e26f2016-03-16 23:30:37339void FrameTreeNode::SetCurrentOrigin(
340 const url::Origin& origin,
341 bool is_potentially_trustworthy_unique_origin) {
Antonio Sartori90f41212021-01-22 10:08:34342 if (!origin.IsSameOriginWith(replication_state_->origin) ||
343 replication_state_->has_potentially_trustworthy_unique_origin !=
estarkbd8e26f2016-03-16 23:30:37344 is_potentially_trustworthy_unique_origin) {
345 render_manager_.OnDidUpdateOrigin(origin,
346 is_potentially_trustworthy_unique_origin);
347 }
Antonio Sartori90f41212021-01-22 10:08:34348 replication_state_->origin = origin;
349 replication_state_->has_potentially_trustworthy_unique_origin =
estarkbd8e26f2016-03-16 23:30:37350 is_potentially_trustworthy_unique_origin;
alexmosa7a4ff822015-04-27 17:59:56351}
alexmosbe2f4c32015-03-10 02:30:23352
engedy6e2e0992017-05-25 18:58:42353void FrameTreeNode::SetCollapsed(bool collapsed) {
354 DCHECK(!IsMainFrame());
355 if (is_collapsed_ == collapsed)
356 return;
357
358 is_collapsed_ = collapsed;
359 render_manager_.OnDidChangeCollapsedState(collapsed);
360}
361
Harkiran Bolaria59290d62021-03-17 01:53:01362void FrameTreeNode::SetFrameTree(FrameTree& frame_tree) {
Hiroki Nakagawa0a90bd42021-04-21 01:53:05363 DCHECK(blink::features::IsPrerender2Enabled());
Harkiran Bolaria59290d62021-03-17 01:53:01364 frame_tree_ = &frame_tree;
365}
366
lukasza464d8692016-02-22 19:26:32367void FrameTreeNode::SetFrameName(const std::string& name,
368 const std::string& unique_name) {
Antonio Sartori90f41212021-01-22 10:08:34369 if (name == replication_state_->name) {
lukasza464d8692016-02-22 19:26:32370 // |unique_name| shouldn't change unless |name| changes.
Antonio Sartori90f41212021-01-22 10:08:34371 DCHECK_EQ(unique_name, replication_state_->unique_name);
lukasza464d8692016-02-22 19:26:32372 return;
373 }
lukasza5140a412016-09-15 21:12:30374
375 if (parent()) {
376 // Non-main frames should have a non-empty unique name.
377 DCHECK(!unique_name.empty());
378 } else {
379 // Unique name of main frames should always stay empty.
380 DCHECK(unique_name.empty());
381 }
382
Daniel Cheng6ca7f1c92017-08-09 21:45:41383 // Note the unique name should only be able to change before the first real
384 // load is committed, but that's not strongly enforced here.
lukasza464d8692016-02-22 19:26:32385 render_manager_.OnDidUpdateName(name, unique_name);
Antonio Sartori90f41212021-01-22 10:08:34386 replication_state_->name = name;
387 replication_state_->unique_name = unique_name;
alexmosbe2f4c32015-03-10 02:30:23388}
389
mkwstf672e7ef2016-06-09 20:51:07390void FrameTreeNode::SetInsecureRequestPolicy(
Julie Jeongeun Kimd90e2dd2020-03-03 11:45:37391 blink::mojom::InsecureRequestPolicy policy) {
Antonio Sartori90f41212021-01-22 10:08:34392 if (policy == replication_state_->insecure_request_policy)
estarka886b8d2015-12-18 21:53:08393 return;
mkwstf672e7ef2016-06-09 20:51:07394 render_manager_.OnEnforceInsecureRequestPolicy(policy);
Antonio Sartori90f41212021-01-22 10:08:34395 replication_state_->insecure_request_policy = policy;
estarka886b8d2015-12-18 21:53:08396}
397
arthursonzogni4b62a5cb2018-01-17 14:14:26398void FrameTreeNode::SetInsecureNavigationsSet(
399 const std::vector<uint32_t>& insecure_navigations_set) {
400 DCHECK(std::is_sorted(insecure_navigations_set.begin(),
401 insecure_navigations_set.end()));
Antonio Sartori90f41212021-01-22 10:08:34402 if (insecure_navigations_set == replication_state_->insecure_navigations_set)
arthursonzogni4b62a5cb2018-01-17 14:14:26403 return;
404 render_manager_.OnEnforceInsecureNavigationsSet(insecure_navigations_set);
Antonio Sartori90f41212021-01-22 10:08:34405 replication_state_->insecure_navigations_set = insecure_navigations_set;
arthursonzogni4b62a5cb2018-01-17 14:14:26406}
407
Luna Luc3fdacdf2017-11-08 04:48:53408void FrameTreeNode::SetPendingFramePolicy(blink::FramePolicy frame_policy) {
Dominic Farolino08662c82021-06-11 07:36:34409 // The |is_fenced| bit should never be able to transition from what its
410 // initial value was. Since we never expect to be in a position where it can
411 // even be updated to new value, if we catch this happening we have to kill
412 // the renderer and refuse to accept any other frame policy changes here.
413 if (pending_frame_policy_.is_fenced != frame_policy.is_fenced) {
414 mojo::ReportBadMessage(
415 "The `is_fenced` FramePolicy bit is const and should never be changed");
416 return;
417 }
418
Ian Clellandcdc4f312017-10-13 22:24:12419 pending_frame_policy_.sandbox_flags = frame_policy.sandbox_flags;
alexmos6e940102016-01-19 22:47:25420
Ian Clellandcdc4f312017-10-13 22:24:12421 if (parent()) {
422 // Subframes should always inherit their parent's sandbox flags.
Alexander Timin381e7e182020-04-28 19:04:03423 pending_frame_policy_.sandbox_flags |=
424 parent()->frame_tree_node()->active_sandbox_flags();
Charlie Hue1b77ac2019-12-13 21:30:17425 // This is only applied on subframes; container policy and required document
426 // policy are not mutable on main frame.
Ian Clellandcdc4f312017-10-13 22:24:12427 pending_frame_policy_.container_policy = frame_policy.container_policy;
Charlie Hue1b77ac2019-12-13 21:30:17428 pending_frame_policy_.required_document_policy =
429 frame_policy.required_document_policy;
Ian Clellandcdc4f312017-10-13 22:24:12430 }
iclelland92f8c0b2017-04-19 12:43:05431}
432
alexmos9f8705a2015-05-06 19:58:59433FrameTreeNode* FrameTreeNode::PreviousSibling() const {
paulmeyer322777fb2016-05-16 23:15:39434 return GetSibling(-1);
435}
alexmos9f8705a2015-05-06 19:58:59436
paulmeyer322777fb2016-05-16 23:15:39437FrameTreeNode* FrameTreeNode::NextSibling() const {
438 return GetSibling(1);
alexmos9f8705a2015-05-06 19:58:59439}
440
fdegans4a49ce932015-03-12 17:11:37441bool FrameTreeNode::IsLoading() const {
442 RenderFrameHostImpl* current_frame_host =
443 render_manager_.current_frame_host();
fdegans4a49ce932015-03-12 17:11:37444
445 DCHECK(current_frame_host);
fdegans39ff0382015-04-29 19:04:39446
clamy610c63b32017-12-22 15:05:18447 if (navigation_request_)
448 return true;
clamy11e11512015-07-07 16:42:17449
clamy610c63b32017-12-22 15:05:18450 RenderFrameHostImpl* speculative_frame_host =
451 render_manager_.speculative_frame_host();
452 if (speculative_frame_host && speculative_frame_host->is_loading())
453 return true;
fdegans4a49ce932015-03-12 17:11:37454 return current_frame_host->is_loading();
455}
456
Alex Moshchuk9b0fd822020-10-26 23:08:15457bool FrameTreeNode::HasPendingCrossDocumentNavigation() const {
458 // Having a |navigation_request_| on FrameTreeNode implies that there's an
459 // ongoing navigation that hasn't reached the ReadyToCommit state. If the
460 // navigation is between ReadyToCommit and DidCommitNavigation, the
461 // NavigationRequest will be held by RenderFrameHost, which is checked below.
462 if (navigation_request_ && !navigation_request_->IsSameDocument())
463 return true;
464
465 // Having a speculative RenderFrameHost should imply a cross-document
466 // navigation.
467 if (render_manager_.speculative_frame_host())
468 return true;
469
470 return render_manager_.current_frame_host()
471 ->HasPendingCommitForCrossDocumentNavigation();
472}
473
Charlie Hu5ffc0152019-12-06 15:59:53474bool FrameTreeNode::CommitFramePolicy(
475 const blink::FramePolicy& new_frame_policy) {
476 bool did_change_flags = new_frame_policy.sandbox_flags !=
Antonio Sartori90f41212021-01-22 10:08:34477 replication_state_->frame_policy.sandbox_flags;
iclelland92f8c0b2017-04-19 12:43:05478 bool did_change_container_policy =
Charlie Hu5ffc0152019-12-06 15:59:53479 new_frame_policy.container_policy !=
Antonio Sartori90f41212021-01-22 10:08:34480 replication_state_->frame_policy.container_policy;
Charlie Hue1b77ac2019-12-13 21:30:17481 bool did_change_required_document_policy =
482 pending_frame_policy_.required_document_policy !=
Antonio Sartori90f41212021-01-22 10:08:34483 replication_state_->frame_policy.required_document_policy;
Dominic Farolino08662c82021-06-11 07:36:34484 DCHECK_EQ(new_frame_policy.is_fenced,
485 replication_state_->frame_policy.is_fenced);
Antonio Sartori90f41212021-01-22 10:08:34486 if (did_change_flags) {
487 replication_state_->frame_policy.sandbox_flags =
Charlie Hu5ffc0152019-12-06 15:59:53488 new_frame_policy.sandbox_flags;
Antonio Sartori90f41212021-01-22 10:08:34489 }
490 if (did_change_container_policy) {
491 replication_state_->frame_policy.container_policy =
Charlie Hu5ffc0152019-12-06 15:59:53492 new_frame_policy.container_policy;
Antonio Sartori90f41212021-01-22 10:08:34493 }
494 if (did_change_required_document_policy) {
495 replication_state_->frame_policy.required_document_policy =
Charlie Hue1b77ac2019-12-13 21:30:17496 new_frame_policy.required_document_policy;
Antonio Sartori90f41212021-01-22 10:08:34497 }
Charlie Hue1b77ac2019-12-13 21:30:17498
Charlie Hu5ffc0152019-12-06 15:59:53499 UpdateFramePolicyHeaders(new_frame_policy.sandbox_flags,
Charlie Hue20fe2f2021-03-07 03:39:59500 replication_state_->permissions_policy_header);
Charlie Hue1b77ac2019-12-13 21:30:17501 return did_change_flags || did_change_container_policy ||
Dave Tapuska7fdfc2f2021-06-08 17:38:40502 did_change_required_document_policy;
alexmos6b294562015-03-05 19:24:10503}
504
Arthur Hemeryc3380172018-01-22 14:00:17505void FrameTreeNode::TransferNavigationRequestOwnership(
506 RenderFrameHostImpl* render_frame_host) {
Andrey Kosyakovf2d4ff72018-10-29 20:09:59507 devtools_instrumentation::OnResetNavigationRequest(navigation_request_.get());
Arthur Hemeryc3380172018-01-22 14:00:17508 render_frame_host->SetNavigationRequest(std::move(navigation_request_));
509}
510
carloskc49005eb2015-06-16 11:25:07511void FrameTreeNode::CreatedNavigationRequest(
dcheng9bfa5162016-04-09 01:00:57512 std::unique_ptr<NavigationRequest> navigation_request) {
arthursonzognic79c251c2016-08-18 15:00:37513 // This is never called when navigating to a Javascript URL. For the loading
514 // state, this matches what Blink is doing: Blink doesn't send throbber
515 // notifications for Javascript URLS.
516 DCHECK(!navigation_request->common_params().url.SchemeIs(
517 url::kJavaScriptScheme));
518
clamy44e84ce2016-02-22 15:38:25519 bool was_previously_loading = frame_tree()->IsLoading();
520
clamy82a2f4d2016-02-02 14:20:41521 // There's no need to reset the state: there's still an ongoing load, and the
522 // RenderFrameHostManager will take care of updates to the speculative
523 // RenderFrameHost in DidCreateNavigationRequest below.
jamcd0b7b22017-03-24 22:13:05524 if (was_previously_loading) {
Mohamed Abdelhalimf03d4a22019-10-01 13:34:31525 if (navigation_request_ && navigation_request_->IsNavigationStarted()) {
jamcd0b7b22017-03-24 22:13:05526 // Mark the old request as aborted.
Mohamed Abdelhalimb4db22a2019-06-18 10:46:52527 navigation_request_->set_net_error(net::ERR_ABORTED);
jamcd0b7b22017-03-24 22:13:05528 }
Arthur Hemery241b9392019-10-24 11:08:41529 ResetNavigationRequest(true);
jamcd0b7b22017-03-24 22:13:05530 }
clamy44e84ce2016-02-22 15:38:25531
532 navigation_request_ = std::move(navigation_request);
Shubhie Panickerddf2a4e2018-03-06 00:09:06533 if (was_discarded_) {
534 navigation_request_->set_was_discarded();
535 was_discarded_ = false;
536 }
clamy8e2e299202016-04-05 11:44:59537 render_manager()->DidCreateNavigationRequest(navigation_request_.get());
fdegans39ff0382015-04-29 19:04:39538
Lucas Furukawa Gadanief8290a2019-07-29 20:27:51539 bool to_different_document = !NavigationTypeUtils::IsSameDocument(
arthursonzogni92f18682017-02-08 23:00:04540 navigation_request_->common_params().navigation_type);
541
542 DidStartLoading(to_different_document, was_previously_loading);
clamydcb434c12015-04-16 19:29:16543}
544
Arthur Hemery241b9392019-10-24 11:08:41545void FrameTreeNode::ResetNavigationRequest(bool keep_state) {
fdegans39ff0382015-04-29 19:04:39546 if (!navigation_request_)
547 return;
John Abd-El-Malekdcc7bf42017-09-12 22:30:23548
Andrey Kosyakovf2d4ff72018-10-29 20:09:59549 devtools_instrumentation::OnResetNavigationRequest(navigation_request_.get());
clamydcb434c12015-04-16 19:29:16550 navigation_request_.reset();
fdegans39ff0382015-04-29 19:04:39551
clamy82a2f4d2016-02-02 14:20:41552 if (keep_state)
fdegans39ff0382015-04-29 19:04:39553 return;
554
clamy82a2f4d2016-02-02 14:20:41555 // The RenderFrameHostManager should clean up any speculative RenderFrameHost
556 // it created for the navigation. Also register that the load stopped.
fdegans39ff0382015-04-29 19:04:39557 DidStopLoading();
558 render_manager_.CleanUpNavigation();
clamydcb434c12015-04-16 19:29:16559}
560
clamy44e84ce2016-02-22 15:38:25561void FrameTreeNode::DidStartLoading(bool to_different_document,
562 bool was_previously_loading) {
Camille Lamyefd54b02018-10-04 16:54:14563 TRACE_EVENT2("navigation", "FrameTreeNode::DidStartLoading",
564 "frame_tree_node", frame_tree_node_id(), "to different document",
565 to_different_document);
fdegansa696e5112015-04-17 01:57:59566
Carlos Caballero03262522021-02-05 14:49:58567 frame_tree_->DidStartLoadingNode(*this, to_different_document,
568 was_previously_loading);
fdegansa696e5112015-04-17 01:57:59569
570 // Set initial load progress and update overall progress. This will notify
571 // the WebContents of the load progress change.
572 DidChangeLoadProgress(kLoadingProgressMinimum);
573
574 // Notify the RenderFrameHostManager of the event.
575 render_manager()->OnDidStartLoading();
576}
577
578void FrameTreeNode::DidStopLoading() {
Camille Lamyefd54b02018-10-04 16:54:14579 TRACE_EVENT1("navigation", "FrameTreeNode::DidStopLoading", "frame_tree_node",
580 frame_tree_node_id());
fdegansa696e5112015-04-17 01:57:59581 // Set final load progress and update overall progress. This will notify
582 // the WebContents of the load progress change.
583 DidChangeLoadProgress(kLoadingProgressDone);
584
Lucas Furukawa Gadani6faef602019-05-06 21:16:03585 // Notify the RenderFrameHostManager of the event.
586 render_manager()->OnDidStopLoading();
587
Carlos Caballero03262522021-02-05 14:49:58588 frame_tree_->DidStopLoadingNode(*this);
fdegansa696e5112015-04-17 01:57:59589}
590
591void FrameTreeNode::DidChangeLoadProgress(double load_progress) {
Nate Chapin93536702018-02-07 00:12:21592 DCHECK_GE(load_progress, kLoadingProgressMinimum);
593 DCHECK_LE(load_progress, kLoadingProgressDone);
Carlos Caballero03262522021-02-05 14:49:58594 frame_tree_->DidChangeLoadProgressForNode(*this, load_progress);
fdegansa696e5112015-04-17 01:57:59595}
596
clamyf73862c42015-07-08 12:31:33597bool FrameTreeNode::StopLoading() {
arthursonzogni66f711c2019-10-08 14:40:36598 if (navigation_request_ && navigation_request_->IsNavigationStarted())
599 navigation_request_->set_net_error(net::ERR_ABORTED);
Arthur Hemery241b9392019-10-24 11:08:41600 ResetNavigationRequest(false);
clamyf73862c42015-07-08 12:31:33601
clamyf73862c42015-07-08 12:31:33602 if (!IsMainFrame())
603 return true;
604
605 render_manager_.Stop();
606 return true;
607}
608
alexmos21acae52015-11-07 01:04:43609void FrameTreeNode::DidFocus() {
610 last_focus_time_ = base::TimeTicks::Now();
ericwilligers254597b2016-10-17 10:32:31611 for (auto& observer : observers_)
612 observer.OnFrameTreeNodeFocused(this);
alexmos21acae52015-11-07 01:04:43613}
614
clamy44e84ce2016-02-22 15:38:25615void FrameTreeNode::BeforeUnloadCanceled() {
616 // TODO(clamy): Support BeforeUnload in subframes.
617 if (!IsMainFrame())
618 return;
619
620 RenderFrameHostImpl* current_frame_host =
621 render_manager_.current_frame_host();
622 DCHECK(current_frame_host);
623 current_frame_host->ResetLoadingState();
624
clamy610c63b32017-12-22 15:05:18625 RenderFrameHostImpl* speculative_frame_host =
626 render_manager_.speculative_frame_host();
627 if (speculative_frame_host)
628 speculative_frame_host->ResetLoadingState();
Alexander Timin23c110b2021-01-14 02:39:04629 // Note: there is no need to set an error code on the NavigationHandle as
630 // the observers have not been notified about its creation.
631 // We also reset navigation request only when this navigation request was
632 // responsible for this dialog, as a new navigation request might cancel
633 // existing unrelated dialog.
634 if (navigation_request_ && navigation_request_->IsWaitingForBeforeUnload())
Arthur Hemery241b9392019-10-24 11:08:41635 ResetNavigationRequest(false);
clamy44e84ce2016-02-22 15:38:25636}
637
Mustaq Ahmedecb5c38e2020-07-29 00:34:30638bool FrameTreeNode::NotifyUserActivation(
639 blink::mojom::UserActivationNotificationType notification_type) {
Alex Moshchuk03904192021-04-02 07:29:08640 // User Activation V2 requires activating all ancestor frames in addition to
641 // the current frame. See
642 // https://html.spec.whatwg.org/multipage/interaction.html#tracking-user-activation.
Alexander Timina1dfadaa2020-04-28 13:30:06643 for (RenderFrameHostImpl* rfh = current_frame_host(); rfh;
644 rfh = rfh->GetParent()) {
John Delaneyb625dca92021-04-14 17:00:34645 rfh->DidReceiveUserActivation();
Mustaq Ahmedecb5c38e2020-07-29 00:34:30646 rfh->frame_tree_node()->user_activation_state_.Activate(notification_type);
John Delaneyedd8d6c2019-01-25 00:23:57647 }
Alex Moshchuk03904192021-04-02 07:29:08648
Antonio Sartori90f41212021-01-22 10:08:34649 replication_state_->has_active_user_gesture = true;
Mustaq Ahmeda5dfa60b2018-12-08 00:30:14650
Mustaq Ahmed0180320f2019-03-21 16:07:01651 // See the "Same-origin Visibility" section in |UserActivationState| class
652 // doc.
Mustaq Ahmede5f12562019-10-30 18:02:03653 if (base::FeatureList::IsEnabled(
Mustaq Ahmeda5dfa60b2018-12-08 00:30:14654 features::kUserActivationSameOriginVisibility)) {
655 const url::Origin& current_origin =
656 this->current_frame_host()->GetLastCommittedOrigin();
657 for (FrameTreeNode* node : frame_tree()->Nodes()) {
658 if (node->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith(
659 current_origin)) {
Mustaq Ahmedecb5c38e2020-07-29 00:34:30660 node->user_activation_state_.Activate(notification_type);
Mustaq Ahmeda5dfa60b2018-12-08 00:30:14661 }
662 }
663 }
664
Carlos Caballero40b0efd2021-01-26 11:55:00665 navigator().controller().NotifyUserActivation();
Alex Moshchuk03904192021-04-02 07:29:08666 current_frame_host()->MaybeIsolateForUserActivation();
Shivani Sharma194877032019-03-07 17:52:47667
Mustaq Ahmedc4cb7162018-06-05 16:28:36668 return true;
669}
670
671bool FrameTreeNode::ConsumeTransientUserActivation() {
672 bool was_active = user_activation_state_.IsActive();
673 for (FrameTreeNode* node : frame_tree()->Nodes())
674 node->user_activation_state_.ConsumeIfActive();
Antonio Sartori90f41212021-01-22 10:08:34675 replication_state_->has_active_user_gesture = false;
Mustaq Ahmedc4cb7162018-06-05 16:28:36676 return was_active;
677}
678
Shivani Sharmac4f561582018-11-15 15:58:39679bool FrameTreeNode::ClearUserActivation() {
Shivani Sharmac4f561582018-11-15 15:58:39680 for (FrameTreeNode* node : frame_tree()->SubtreeNodes(this))
681 node->user_activation_state_.Clear();
Antonio Sartori90f41212021-01-22 10:08:34682 replication_state_->has_active_user_gesture = false;
Shivani Sharmac4f561582018-11-15 15:58:39683 return true;
684}
685
Ella Ge9caed612019-08-09 16:17:25686bool FrameTreeNode::VerifyUserActivation() {
Ella Gea78f6772019-12-11 10:35:25687 DCHECK(base::FeatureList::IsEnabled(
688 features::kBrowserVerifiedUserActivationMouse) ||
689 base::FeatureList::IsEnabled(
690 features::kBrowserVerifiedUserActivationKeyboard));
691
Ella Ge9caed612019-08-09 16:17:25692 return render_manager_.current_frame_host()
693 ->GetRenderWidgetHost()
Mustaq Ahmed83bb1722019-10-22 20:00:10694 ->RemovePendingUserActivationIfAvailable();
Ella Ge9caed612019-08-09 16:17:25695}
696
Mustaq Ahmedc4cb7162018-06-05 16:28:36697bool FrameTreeNode::UpdateUserActivationState(
Mustaq Ahmeddc195e5b2020-08-04 18:45:11698 blink::mojom::UserActivationUpdateType update_type,
699 blink::mojom::UserActivationNotificationType notification_type) {
Ella Ge9caed612019-08-09 16:17:25700 bool update_result = false;
Mustaq Ahmedc4cb7162018-06-05 16:28:36701 switch (update_type) {
Antonio Gomes4b2c5132020-01-16 11:49:48702 case blink::mojom::UserActivationUpdateType::kConsumeTransientActivation:
Ella Ge9caed612019-08-09 16:17:25703 update_result = ConsumeTransientUserActivation();
704 break;
Antonio Gomes4b2c5132020-01-16 11:49:48705 case blink::mojom::UserActivationUpdateType::kNotifyActivation:
Mustaq Ahmeddc195e5b2020-08-04 18:45:11706 update_result = NotifyUserActivation(notification_type);
Ella Ge9caed612019-08-09 16:17:25707 break;
Antonio Gomes4b2c5132020-01-16 11:49:48708 case blink::mojom::UserActivationUpdateType::
Liviu Tintad9391fb92020-09-28 23:50:07709 kNotifyActivationPendingBrowserVerification: {
710 const bool user_activation_verified = VerifyUserActivation();
711 // Add UMA metric for when browser user activation verification succeeds
712 base::UmaHistogramBoolean("Event.BrowserVerifiedUserActivation",
713 user_activation_verified);
714 if (user_activation_verified) {
Mustaq Ahmedecb5c38e2020-07-29 00:34:30715 update_result = NotifyUserActivation(
Mustaq Ahmed2cfb0402020-09-29 19:24:35716 blink::mojom::UserActivationNotificationType::kInteraction);
Antonio Gomes4b2c5132020-01-16 11:49:48717 update_type = blink::mojom::UserActivationUpdateType::kNotifyActivation;
Ella Ge9caed612019-08-09 16:17:25718 } else {
arthursonzogni9816b9192021-03-29 16:09:19719 // TODO(https://crbug.com/848778): We need to decide what to do when
720 // user activation verification failed. NOTREACHED here will make all
Ella Ge9caed612019-08-09 16:17:25721 // unrelated tests that inject event to renderer fail.
722 return false;
723 }
Liviu Tintad9391fb92020-09-28 23:50:07724 } break;
Antonio Gomes4b2c5132020-01-16 11:49:48725 case blink::mojom::UserActivationUpdateType::kClearActivation:
Ella Ge9caed612019-08-09 16:17:25726 update_result = ClearUserActivation();
727 break;
Mustaq Ahmedc4cb7162018-06-05 16:28:36728 }
Mustaq Ahmeddc195e5b2020-08-04 18:45:11729 render_manager_.UpdateUserActivationState(update_type, notification_type);
Ella Ge9caed612019-08-09 16:17:25730 return update_result;
japhet61835ae12017-01-20 01:25:39731}
732
Mustaq Ahmed01261742019-12-16 15:49:06733void FrameTreeNode::OnSetHadStickyUserActivationBeforeNavigation(bool value) {
734 render_manager_.OnSetHadStickyUserActivationBeforeNavigation(value);
Antonio Sartori90f41212021-01-22 10:08:34735 replication_state_->has_received_user_gesture_before_nav = value;
Becca Hughes60af7d42017-12-12 10:53:15736}
737
paulmeyer322777fb2016-05-16 23:15:39738FrameTreeNode* FrameTreeNode::GetSibling(int relative_offset) const {
paulmeyerf3119f52016-05-17 17:37:19739 if (!parent_ || !parent_->child_count())
paulmeyer322777fb2016-05-16 23:15:39740 return nullptr;
741
742 for (size_t i = 0; i < parent_->child_count(); ++i) {
743 if (parent_->child_at(i) == this) {
744 if ((relative_offset < 0 && static_cast<size_t>(-relative_offset) > i) ||
745 i + relative_offset >= parent_->child_count()) {
746 return nullptr;
747 }
748 return parent_->child_at(i + relative_offset);
749 }
750 }
751
752 NOTREACHED() << "FrameTreeNode not found in its parent's children.";
753 return nullptr;
754}
755
Alexander Timin45b716c2020-11-06 01:40:31756bool FrameTreeNode::UpdateFramePolicyHeaders(
arthursonzognib93a4472020-04-10 07:38:00757 network::mojom::WebSandboxFlags sandbox_flags,
Charlie Hue24f04832021-03-04 21:07:06758 const blink::ParsedPermissionsPolicy& parsed_header) {
Ian Clellandedb8c5dd2018-03-01 17:01:37759 bool changed = false;
Charlie Hue20fe2f2021-03-07 03:39:59760 if (replication_state_->permissions_policy_header != parsed_header) {
761 replication_state_->permissions_policy_header = parsed_header;
Ian Clellandedb8c5dd2018-03-01 17:01:37762 changed = true;
763 }
Ian Clelland5cbaaf82017-11-27 22:00:03764 // TODO(iclelland): Kill the renderer if sandbox flags is not a subset of the
765 // currently effective sandbox flags from the frame. https://crbug.com/740556
arthursonzognib93a4472020-04-10 07:38:00766 network::mojom::WebSandboxFlags updated_flags =
Ian Clelland5cbaaf82017-11-27 22:00:03767 sandbox_flags | effective_frame_policy().sandbox_flags;
Antonio Sartori90f41212021-01-22 10:08:34768 if (replication_state_->active_sandbox_flags != updated_flags) {
769 replication_state_->active_sandbox_flags = updated_flags;
Ian Clellandedb8c5dd2018-03-01 17:01:37770 changed = true;
771 }
772 // Notify any proxies if the policies have been changed.
773 if (changed)
774 render_manager()->OnDidSetFramePolicyHeaders();
Alexander Timin45b716c2020-11-06 01:40:31775 return changed;
Ian Clelland5cbaaf82017-11-27 22:00:03776}
777
Arthur Sonzognif8840b92018-11-07 14:10:35778void FrameTreeNode::PruneChildFrameNavigationEntries(
779 NavigationEntryImpl* entry) {
780 for (size_t i = 0; i < current_frame_host()->child_count(); ++i) {
781 FrameTreeNode* child = current_frame_host()->child_at(i);
782 if (child->is_created_by_script_) {
783 entry->RemoveEntryForFrame(child,
784 /* only_if_different_position = */ false);
785 } else {
786 child->PruneChildFrameNavigationEntries(entry);
787 }
788 }
789}
790
Alex Turner10d557a42021-06-01 19:06:49791void FrameTreeNode::SetIsAdSubframe(bool is_ad_subframe) {
792 if (is_ad_subframe == replication_state_->is_ad_subframe)
Alex Turner5a09c462021-03-17 17:07:35793 return;
794
Alex Turner10d557a42021-06-01 19:06:49795 replication_state_->is_ad_subframe = is_ad_subframe;
796 render_manager()->OnDidSetIsAdSubframe(is_ad_subframe);
Yao Xiao24ec9aa2020-01-28 16:36:00797}
798
arthursonzogni034bb9c2020-10-01 08:29:56799void FrameTreeNode::SetInitialPopupURL(const GURL& initial_popup_url) {
800 DCHECK(initial_popup_url_.is_empty());
801 DCHECK(!has_committed_real_load_);
802 initial_popup_url_ = initial_popup_url;
803}
804
805void FrameTreeNode::SetPopupCreatorOrigin(
806 const url::Origin& popup_creator_origin) {
807 DCHECK(!has_committed_real_load_);
808 popup_creator_origin_ = popup_creator_origin;
809}
810
Alexander Timinbebb2002021-04-20 15:42:24811void FrameTreeNode::WriteIntoTrace(perfetto::TracedValue context) const {
Alexander Timinf785f342021-03-18 00:00:56812 auto dict = std::move(context).WriteDictionary();
813 dict.Add("id", frame_tree_node_id());
814 dict.Add("is_main_frame", IsMainFrame());
815}
816
Carlos Caballero76711352021-03-24 17:38:21817bool FrameTreeNode::HasNavigation() {
818 if (navigation_request())
819 return true;
820
821 // Same-RenderFrameHost navigation is committing:
822 if (current_frame_host()->HasPendingCommitNavigation())
823 return true;
824
825 // Cross-RenderFrameHost navigation is committing:
826 if (render_manager()->speculative_frame_host())
827 return true;
828
829 return false;
830}
831
[email protected]9b159a52013-10-03 17:24:55832} // namespace content