blob: ee872a2d2bc0f12c9c0d092770decffade04fe0b [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"
[email protected]9b159a52013-10-03 17:24:5517#include "base/stl_util.h"
Daniel Cheng6ca7f1c92017-08-09 21:45:4118#include "base/strings/string_util.h"
Andrey Kosyakovf2d4ff72018-10-29 20:09:5919#include "content/browser/devtools/devtools_instrumentation.h"
danakjc492bf82020-09-09 20:02:4420#include "content/browser/renderer_host/navigation_controller_impl.h"
21#include "content/browser/renderer_host/navigation_request.h"
22#include "content/browser/renderer_host/navigator.h"
23#include "content/browser/renderer_host/navigator_delegate.h"
24#include "content/browser/renderer_host/render_frame_host_impl.h"
[email protected]94d0cc12013-12-18 00:07:4125#include "content/browser/renderer_host/render_view_host_impl.h"
Lucas Furukawa Gadanief8290a2019-07-29 20:27:5126#include "content/common/navigation_params.h"
27#include "content/common/navigation_params_utils.h"
dmazzonie950ea232015-03-13 21:39:4528#include "content/public/browser/browser_thread.h"
Mustaq Ahmeda5dfa60b2018-12-08 00:30:1429#include "content/public/common/content_features.h"
arthursonzognib93a4472020-04-10 07:38:0030#include "services/network/public/cpp/web_sandbox_flags.h"
31#include "services/network/public/mojom/web_sandbox_flags.mojom-shared.h"
Harkiran Bolaria59290d62021-03-17 01:53:0132#include "third_party/blink/public/common/features.h"
Antonio Gomes4b2c5132020-01-16 11:49:4833#include "third_party/blink/public/mojom/frame/user_activation_update_types.mojom.h"
Julie Jeongeun Kimd90e2dd2020-03-03 11:45:3734#include "third_party/blink/public/mojom/security_context/insecure_request_policy.mojom.h"
[email protected]9b159a52013-10-03 17:24:5535
36namespace content {
37
dmazzonie950ea232015-03-13 21:39:4538namespace {
39
40// This is a global map between frame_tree_node_ids and pointers to
41// FrameTreeNodes.
Takuto Ikutaadf31eb2019-01-05 00:32:4842typedef std::unordered_map<int, FrameTreeNode*> FrameTreeNodeIdMap;
dmazzonie950ea232015-03-13 21:39:4543
scottmg5e65e3a2017-03-08 08:48:4644base::LazyInstance<FrameTreeNodeIdMap>::DestructorAtExit
45 g_frame_tree_node_id_map = LAZY_INSTANCE_INITIALIZER;
dmazzonie950ea232015-03-13 21:39:4546
fdegansa696e5112015-04-17 01:57:5947// These values indicate the loading progress status. The minimum progress
48// value matches what Blink's ProgressTracker has traditionally used for a
49// minimum progress value.
fdegansa696e5112015-04-17 01:57:5950const double kLoadingProgressMinimum = 0.1;
51const double kLoadingProgressDone = 1.0;
dmazzonie950ea232015-03-13 21:39:4552
fdegansa696e5112015-04-17 01:57:5953} // namespace
fdegans1d16355162015-03-26 11:58:3454
alexmose201c7cd2015-06-10 17:14:2155// This observer watches the opener of its owner FrameTreeNode and clears the
56// owner's opener if the opener is destroyed.
57class FrameTreeNode::OpenerDestroyedObserver : public FrameTreeNode::Observer {
58 public:
jochen6004a362017-02-04 00:11:4059 OpenerDestroyedObserver(FrameTreeNode* owner, bool observing_original_opener)
60 : owner_(owner), observing_original_opener_(observing_original_opener) {}
alexmose201c7cd2015-06-10 17:14:2161
62 // FrameTreeNode::Observer
63 void OnFrameTreeNodeDestroyed(FrameTreeNode* node) override {
jochen6004a362017-02-04 00:11:4064 if (observing_original_opener_) {
Avi Drissman36465f332017-09-11 20:49:3965 // The "original owner" is special. It's used for attribution, and clients
66 // walk down the original owner chain. Therefore, if a link in the chain
67 // is being destroyed, reconnect the observation to the parent of the link
68 // being destroyed.
jochen6004a362017-02-04 00:11:4069 CHECK_EQ(owner_->original_opener(), node);
Avi Drissman36465f332017-09-11 20:49:3970 owner_->SetOriginalOpener(node->original_opener());
71 // |this| is deleted at this point.
jochen6004a362017-02-04 00:11:4072 } else {
73 CHECK_EQ(owner_->opener(), node);
74 owner_->SetOpener(nullptr);
Avi Drissman36465f332017-09-11 20:49:3975 // |this| is deleted at this point.
jochen6004a362017-02-04 00:11:4076 }
alexmose201c7cd2015-06-10 17:14:2177 }
78
79 private:
80 FrameTreeNode* owner_;
jochen6004a362017-02-04 00:11:4081 bool observing_original_opener_;
alexmose201c7cd2015-06-10 17:14:2182
83 DISALLOW_COPY_AND_ASSIGN(OpenerDestroyedObserver);
84};
85
Kevin McNee88e61552020-10-22 20:41:1186const int FrameTreeNode::kFrameTreeNodeInvalidId = -1;
87
88static_assert(FrameTreeNode::kFrameTreeNodeInvalidId ==
89 RenderFrameHost::kNoFrameTreeNodeId,
90 "Have consistent sentinel values for an invalid FTN id.");
91
vishal.b782eb5d2015-04-29 12:22:5792int FrameTreeNode::next_frame_tree_node_id_ = 1;
[email protected]9b159a52013-10-03 17:24:5593
dmazzonie950ea232015-03-13 21:39:4594// static
vishal.b782eb5d2015-04-29 12:22:5795FrameTreeNode* FrameTreeNode::GloballyFindByID(int frame_tree_node_id) {
mostynb366eaf12015-03-26 00:51:1996 DCHECK_CURRENTLY_ON(BrowserThread::UI);
rob97250742015-12-10 17:45:1597 FrameTreeNodeIdMap* nodes = g_frame_tree_node_id_map.Pointer();
jdoerrie55ec69d2018-10-08 13:34:4698 auto it = nodes->find(frame_tree_node_id);
dmazzonie950ea232015-03-13 21:39:4599 return it == nodes->end() ? nullptr : it->second;
100}
101
Alexander Timin381e7e182020-04-28 19:04:03102// static
103FrameTreeNode* FrameTreeNode::From(RenderFrameHost* rfh) {
104 if (!rfh)
105 return nullptr;
106 return static_cast<RenderFrameHostImpl*>(rfh)->frame_tree_node();
107}
108
Julie Jeongeun Kim70a2e4e2020-02-21 05:09:54109FrameTreeNode::FrameTreeNode(
110 FrameTree* frame_tree,
Alexander Timin381e7e182020-04-28 19:04:03111 RenderFrameHostImpl* parent,
Antonio Gomes9d5c1ef2020-04-30 20:56:41112 blink::mojom::TreeScopeType scope,
Julie Jeongeun Kim70a2e4e2020-02-21 05:09:54113 const std::string& name,
114 const std::string& unique_name,
115 bool is_created_by_script,
116 const base::UnguessableToken& devtools_frame_token,
117 const blink::mojom::FrameOwnerProperties& frame_owner_properties,
Antonio Gomes58d38062020-04-30 01:50:14118 blink::mojom::FrameOwnerElementType owner_type)
[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),
Gyuyoung Kimc16e52e92021-03-19 02:45:37124 replication_state_(blink::mojom::FrameReplicationState::New(
Antonio Sartori90f41212021-01-22 10:08:34125 url::Origin(),
estarka886b8d2015-12-18 21:53:08126 name,
lukasza464d8692016-02-22 19:26:32127 unique_name,
Charlie Hue24f04832021-03-04 21:07:06128 blink::ParsedPermissionsPolicy(),
Antonio Sartori90f41212021-01-22 10:08:34129 network::mojom::WebSandboxFlags::kNone,
130 blink::FramePolicy(),
Antonio Sartori90f41212021-01-22 10:08:34131 scope,
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 */,
Antonio Sartori90f41212021-01-22 10:08:34139 blink::mojom::AdFrameType::kNonAd)),
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45140 is_created_by_script_(is_created_by_script),
Pavel Feldman25234722017-10-11 02:49:06141 devtools_frame_token_(devtools_frame_token),
lazyboy70605c32015-11-03 01:27:31142 frame_owner_properties_(frame_owner_properties),
Lukasz Anforowicz147141962020-12-16 18:03:24143 blame_context_(frame_tree_node_id_, FrameTreeNode::From(parent)),
144 render_manager_(this, frame_tree->manager_delegate()) {
rob97250742015-12-10 17:45:15145 std::pair<FrameTreeNodeIdMap::iterator, bool> result =
dmazzonie950ea232015-03-13 21:39:45146 g_frame_tree_node_id_map.Get().insert(
147 std::make_pair(frame_tree_node_id_, this));
148 CHECK(result.second);
benjhaydend4da63d2016-03-11 21:29:33149
xiaochenghb9554bb2016-05-21 14:20:48150 // Note: this should always be done last in the constructor.
151 blame_context_.Initialize();
alexmos998581d2015-01-22 01:01:59152}
[email protected]9b159a52013-10-03 17:24:55153
154FrameTreeNode::~FrameTreeNode() {
Harkiran Bolaria59290d62021-03-17 01:53:01155 // The current frame host may be null when destroying the old frame tree
156 // during prerender activation. However, in such cases, the FrameTree and its
157 // root FrameTreeNode objects are deleted immediately with activation. In all
158 // other cases, there should always be a current frame host.
Harkiran Bolaria59290d62021-03-17 01:53:01159 if (current_frame_host()) {
160 // Remove the children.
161 current_frame_host()->ResetChildren();
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45162
Harkiran Bolaria59290d62021-03-17 01:53:01163 current_frame_host()->ResetLoadingState();
164 } else {
Hiroki Nakagawa0a90bd42021-04-21 01:53:05165 DCHECK(blink::features::IsPrerender2Enabled());
Harkiran Bolaria59290d62021-03-17 01:53:01166 DCHECK(!parent()); // Only main documents can be activated.
167 DCHECK(!opener()); // Prerendered frame trees can't have openers.
168
169 // Activation is not allowed during ongoing navigations.
170 DCHECK(!navigation_request_);
171
Carlos Caballerod1c80432021-04-20 08:16:32172 // TODO(https://crbug.com/1199693): Need to determine how to handle pending
Harkiran Bolaria59290d62021-03-17 01:53:01173 // deletions, as observers will be notified.
174 DCHECK(!render_manager()->speculative_frame_host());
175 }
Nate Chapin22ea6592019-03-05 22:29:02176
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45177 // If the removed frame was created by a script, then its history entry will
178 // never be reused - we can save some memory by removing the history entry.
179 // See also https://crbug.com/784356.
180 if (is_created_by_script_ && parent_) {
Carlos Caballero04aab362021-02-15 17:38:16181 NavigationEntryImpl* nav_entry =
182 navigator().controller().GetLastCommittedEntry();
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45183 if (nav_entry) {
184 nav_entry->RemoveEntryForFrame(this,
185 /* only_if_different_position = */ false);
186 }
187 }
188
dmazzonie950ea232015-03-13 21:39:45189 frame_tree_->FrameRemoved(this);
Carlos Caballero6ff6ace2021-02-05 16:53:00190
191 // Do not dispatch notification for the root frame as ~WebContentsImpl already
192 // dispatches it for now.
193 // TODO(https://crbug.com/1170277): This is only needed because the FrameTree
194 // is a member of WebContentsImpl and we would call back into it during
195 // destruction. We should clean up the FrameTree destruction code and call the
196 // delegate unconditionally.
197 if (parent())
198 render_manager_.delegate()->OnFrameTreeNodeDestroyed(this);
199
ericwilligers254597b2016-10-17 10:32:31200 for (auto& observer : observers_)
201 observer.OnFrameTreeNodeDestroyed(this);
Lukasz Anforowicz147141962020-12-16 18:03:24202 observers_.Clear();
alexmose201c7cd2015-06-10 17:14:21203
204 if (opener_)
205 opener_->RemoveObserver(opener_observer_.get());
jochen6004a362017-02-04 00:11:40206 if (original_opener_)
207 original_opener_->RemoveObserver(original_opener_observer_.get());
dmazzonie950ea232015-03-13 21:39:45208
209 g_frame_tree_node_id_map.Get().erase(frame_tree_node_id_);
jam39258caf2016-11-02 14:48:18210
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();
Arthur Hemery0dd65812019-08-01 14:18:45215 // If a frame with a pending navigation is detached, make sure the
216 // WebContents (and its observers) update their loading state.
danakjf9400602019-06-07 15:44:58217 did_stop_loading = true;
jam39258caf2016-11-02 14:48:18218 }
Nate Chapin22ea6592019-03-05 22:29:02219
danakjf9400602019-06-07 15:44:58220 // ~SiteProcessCountTracker DCHECKs in some tests if the speculative
221 // RenderFrameHostImpl is not destroyed last. Ideally this would be closer to
222 // (possible before) the ResetLoadingState() call above.
223 //
224 // There is an inherent race condition causing bugs 838348/915179/et al, where
225 // the renderer may have committed the speculative main frame and the browser
226 // has not heard about it yet. If this is a main frame, then in that case the
227 // speculative RenderFrame was unable to be deleted (it is owned by the
228 // renderer) and we should not be able to cancel the navigation at this point.
229 // CleanUpNavigation() would normally be called here but it will try to undo
230 // the navigation and expose the race condition. When it replaces the main
231 // frame with a RenderFrameProxy, that leaks the committed main frame, leaving
232 // the frame and its friend group with pointers that will become invalid
233 // shortly as we are shutting everything down and deleting the RenderView etc.
234 // We avoid this problematic situation by not calling CleanUpNavigation() or
235 // DiscardUnusedFrame() here. The speculative RenderFrameHost is simply
236 // returned and deleted immediately. This satisfies the requirement that the
237 // speculative RenderFrameHost is removed from the RenderFrameHostManager
238 // before it is destroyed.
239 if (render_manager_.speculative_frame_host()) {
240 did_stop_loading |= render_manager_.speculative_frame_host()->is_loading();
241 render_manager_.UnsetSpeculativeRenderFrameHost();
242 }
243
244 if (did_stop_loading)
245 DidStopLoading();
246
Harkiran Bolaria59290d62021-03-17 01:53:01247 // IsLoading() requires that current_frame_host() is non-null.
248 DCHECK(!current_frame_host() || !IsLoading());
[email protected]9b159a52013-10-03 17:24:55249}
250
alexmose201c7cd2015-06-10 17:14:21251void FrameTreeNode::AddObserver(Observer* observer) {
252 observers_.AddObserver(observer);
253}
254
255void FrameTreeNode::RemoveObserver(Observer* observer) {
256 observers_.RemoveObserver(observer);
257}
258
[email protected]94d0cc12013-12-18 00:07:41259bool FrameTreeNode::IsMainFrame() const {
260 return frame_tree_->root() == this;
261}
262
Hiroki Nakagawaab309622021-05-19 16:38:13263void FrameTreeNode::ResetForNavigation() {
arthursonzogni76098e52020-11-25 14:18:45264 // This frame has had its user activation bits cleared in the renderer before
265 // arriving here. We just need to clear them here and in the other renderer
266 // processes that may have a reference to this frame.
Alexander Timin45b716c2020-11-06 01:40:31267 //
268 // We do not take user activation into account when calculating
269 // |ResetForNavigationResult|, as we are using it to determine bfcache
270 // eligibility and the page can get another user gesture after restore.
Antonio Gomes4b2c5132020-01-16 11:49:48271 UpdateUserActivationState(
Mustaq Ahmeddc195e5b2020-08-04 18:45:11272 blink::mojom::UserActivationUpdateType::kClearActivation,
273 blink::mojom::UserActivationNotificationType::kNone);
Ian Clelland5cbaaf82017-11-27 22:00:03274}
275
yilkal34a3d752019-08-30 18:20:30276size_t FrameTreeNode::GetFrameTreeSize() const {
277 if (is_collapsed())
278 return 0;
279
280 size_t size = 0;
281 for (size_t i = 0; i < child_count(); i++) {
282 size += child_at(i)->GetFrameTreeSize();
283 }
284
285 // Account for this node.
286 size++;
287 return size;
288}
289
alexmose201c7cd2015-06-10 17:14:21290void FrameTreeNode::SetOpener(FrameTreeNode* opener) {
291 if (opener_) {
292 opener_->RemoveObserver(opener_observer_.get());
293 opener_observer_.reset();
294 }
295
296 opener_ = opener;
297
298 if (opener_) {
Jeremy Roman04f27c372017-10-27 15:20:55299 opener_observer_ = std::make_unique<OpenerDestroyedObserver>(this, false);
alexmose201c7cd2015-06-10 17:14:21300 opener_->AddObserver(opener_observer_.get());
301 }
302}
303
Wolfgang Beyerd8809db2020-09-30 15:29:39304void FrameTreeNode::SetOpenerDevtoolsFrameToken(
305 base::UnguessableToken opener_devtools_frame_token) {
306 DCHECK(!opener_devtools_frame_token_ ||
307 opener_devtools_frame_token_->is_empty());
308 opener_devtools_frame_token_ = std::move(opener_devtools_frame_token);
309}
310
jochen6004a362017-02-04 00:11:40311void FrameTreeNode::SetOriginalOpener(FrameTreeNode* opener) {
Avi Drissman36465f332017-09-11 20:49:39312 // The original opener tracks main frames only.
avi8d1aa162017-03-27 18:27:37313 DCHECK(opener == nullptr || !opener->parent());
jochen6004a362017-02-04 00:11:40314
Avi Drissman36465f332017-09-11 20:49:39315 if (original_opener_) {
316 original_opener_->RemoveObserver(original_opener_observer_.get());
317 original_opener_observer_.reset();
318 }
319
jochen6004a362017-02-04 00:11:40320 original_opener_ = opener;
321
322 if (original_opener_) {
jochen6004a362017-02-04 00:11:40323 original_opener_observer_ =
Jeremy Roman04f27c372017-10-27 15:20:55324 std::make_unique<OpenerDestroyedObserver>(this, true);
jochen6004a362017-02-04 00:11:40325 original_opener_->AddObserver(original_opener_observer_.get());
326 }
327}
328
creisf0f069a2015-07-23 23:51:53329void FrameTreeNode::SetCurrentURL(const GURL& url) {
Balazs Engedyc8a7cccf2018-03-12 23:00:49330 if (!has_committed_real_load_ && !url.IsAboutBlank())
creisf0f069a2015-07-23 23:51:53331 has_committed_real_load_ = true;
Erik Chen173bf3042017-07-31 06:06:21332 current_frame_host()->SetLastCommittedUrl(url);
xiaochenghb9554bb2016-05-21 14:20:48333 blame_context_.TakeSnapshot();
creisf0f069a2015-07-23 23:51:53334}
335
estarkbd8e26f2016-03-16 23:30:37336void FrameTreeNode::SetCurrentOrigin(
337 const url::Origin& origin,
338 bool is_potentially_trustworthy_unique_origin) {
Antonio Sartori90f41212021-01-22 10:08:34339 if (!origin.IsSameOriginWith(replication_state_->origin) ||
340 replication_state_->has_potentially_trustworthy_unique_origin !=
estarkbd8e26f2016-03-16 23:30:37341 is_potentially_trustworthy_unique_origin) {
342 render_manager_.OnDidUpdateOrigin(origin,
343 is_potentially_trustworthy_unique_origin);
344 }
Antonio Sartori90f41212021-01-22 10:08:34345 replication_state_->origin = origin;
346 replication_state_->has_potentially_trustworthy_unique_origin =
estarkbd8e26f2016-03-16 23:30:37347 is_potentially_trustworthy_unique_origin;
alexmosa7a4ff822015-04-27 17:59:56348}
alexmosbe2f4c32015-03-10 02:30:23349
engedy6e2e0992017-05-25 18:58:42350void FrameTreeNode::SetCollapsed(bool collapsed) {
351 DCHECK(!IsMainFrame());
352 if (is_collapsed_ == collapsed)
353 return;
354
355 is_collapsed_ = collapsed;
356 render_manager_.OnDidChangeCollapsedState(collapsed);
357}
358
Harkiran Bolaria59290d62021-03-17 01:53:01359void FrameTreeNode::SetFrameTree(FrameTree& frame_tree) {
Hiroki Nakagawa0a90bd42021-04-21 01:53:05360 DCHECK(blink::features::IsPrerender2Enabled());
Harkiran Bolaria59290d62021-03-17 01:53:01361 frame_tree_ = &frame_tree;
362}
363
lukasza464d8692016-02-22 19:26:32364void FrameTreeNode::SetFrameName(const std::string& name,
365 const std::string& unique_name) {
Antonio Sartori90f41212021-01-22 10:08:34366 if (name == replication_state_->name) {
lukasza464d8692016-02-22 19:26:32367 // |unique_name| shouldn't change unless |name| changes.
Antonio Sartori90f41212021-01-22 10:08:34368 DCHECK_EQ(unique_name, replication_state_->unique_name);
lukasza464d8692016-02-22 19:26:32369 return;
370 }
lukasza5140a412016-09-15 21:12:30371
372 if (parent()) {
373 // Non-main frames should have a non-empty unique name.
374 DCHECK(!unique_name.empty());
375 } else {
376 // Unique name of main frames should always stay empty.
377 DCHECK(unique_name.empty());
378 }
379
Daniel Cheng6ca7f1c92017-08-09 21:45:41380 // Note the unique name should only be able to change before the first real
381 // load is committed, but that's not strongly enforced here.
lukasza464d8692016-02-22 19:26:32382 render_manager_.OnDidUpdateName(name, unique_name);
Antonio Sartori90f41212021-01-22 10:08:34383 replication_state_->name = name;
384 replication_state_->unique_name = unique_name;
alexmosbe2f4c32015-03-10 02:30:23385}
386
mkwstf672e7ef2016-06-09 20:51:07387void FrameTreeNode::SetInsecureRequestPolicy(
Julie Jeongeun Kimd90e2dd2020-03-03 11:45:37388 blink::mojom::InsecureRequestPolicy policy) {
Antonio Sartori90f41212021-01-22 10:08:34389 if (policy == replication_state_->insecure_request_policy)
estarka886b8d2015-12-18 21:53:08390 return;
mkwstf672e7ef2016-06-09 20:51:07391 render_manager_.OnEnforceInsecureRequestPolicy(policy);
Antonio Sartori90f41212021-01-22 10:08:34392 replication_state_->insecure_request_policy = policy;
estarka886b8d2015-12-18 21:53:08393}
394
arthursonzogni4b62a5cb2018-01-17 14:14:26395void FrameTreeNode::SetInsecureNavigationsSet(
396 const std::vector<uint32_t>& insecure_navigations_set) {
397 DCHECK(std::is_sorted(insecure_navigations_set.begin(),
398 insecure_navigations_set.end()));
Antonio Sartori90f41212021-01-22 10:08:34399 if (insecure_navigations_set == replication_state_->insecure_navigations_set)
arthursonzogni4b62a5cb2018-01-17 14:14:26400 return;
401 render_manager_.OnEnforceInsecureNavigationsSet(insecure_navigations_set);
Antonio Sartori90f41212021-01-22 10:08:34402 replication_state_->insecure_navigations_set = insecure_navigations_set;
arthursonzogni4b62a5cb2018-01-17 14:14:26403}
404
Luna Luc3fdacdf2017-11-08 04:48:53405void FrameTreeNode::SetPendingFramePolicy(blink::FramePolicy frame_policy) {
Ian Clellandcdc4f312017-10-13 22:24:12406 pending_frame_policy_.sandbox_flags = frame_policy.sandbox_flags;
Dave Tapuska9b153a942020-02-10 19:35:10407 pending_frame_policy_.disallow_document_access =
408 frame_policy.disallow_document_access;
alexmos6e940102016-01-19 22:47:25409
Ian Clellandcdc4f312017-10-13 22:24:12410 if (parent()) {
411 // Subframes should always inherit their parent's sandbox flags.
Alexander Timin381e7e182020-04-28 19:04:03412 pending_frame_policy_.sandbox_flags |=
413 parent()->frame_tree_node()->active_sandbox_flags();
Charlie Hue1b77ac2019-12-13 21:30:17414 // This is only applied on subframes; container policy and required document
415 // policy are not mutable on main frame.
Ian Clellandcdc4f312017-10-13 22:24:12416 pending_frame_policy_.container_policy = frame_policy.container_policy;
Charlie Hue1b77ac2019-12-13 21:30:17417 pending_frame_policy_.required_document_policy =
418 frame_policy.required_document_policy;
Ian Clellandcdc4f312017-10-13 22:24:12419 }
iclelland92f8c0b2017-04-19 12:43:05420}
421
alexmos9f8705a2015-05-06 19:58:59422FrameTreeNode* FrameTreeNode::PreviousSibling() const {
paulmeyer322777fb2016-05-16 23:15:39423 return GetSibling(-1);
424}
alexmos9f8705a2015-05-06 19:58:59425
paulmeyer322777fb2016-05-16 23:15:39426FrameTreeNode* FrameTreeNode::NextSibling() const {
427 return GetSibling(1);
alexmos9f8705a2015-05-06 19:58:59428}
429
fdegans4a49ce932015-03-12 17:11:37430bool FrameTreeNode::IsLoading() const {
431 RenderFrameHostImpl* current_frame_host =
432 render_manager_.current_frame_host();
fdegans4a49ce932015-03-12 17:11:37433
434 DCHECK(current_frame_host);
fdegans39ff0382015-04-29 19:04:39435
clamy610c63b32017-12-22 15:05:18436 if (navigation_request_)
437 return true;
clamy11e11512015-07-07 16:42:17438
clamy610c63b32017-12-22 15:05:18439 RenderFrameHostImpl* speculative_frame_host =
440 render_manager_.speculative_frame_host();
441 if (speculative_frame_host && speculative_frame_host->is_loading())
442 return true;
fdegans4a49ce932015-03-12 17:11:37443 return current_frame_host->is_loading();
444}
445
Alex Moshchuk9b0fd822020-10-26 23:08:15446bool FrameTreeNode::HasPendingCrossDocumentNavigation() const {
447 // Having a |navigation_request_| on FrameTreeNode implies that there's an
448 // ongoing navigation that hasn't reached the ReadyToCommit state. If the
449 // navigation is between ReadyToCommit and DidCommitNavigation, the
450 // NavigationRequest will be held by RenderFrameHost, which is checked below.
451 if (navigation_request_ && !navigation_request_->IsSameDocument())
452 return true;
453
454 // Having a speculative RenderFrameHost should imply a cross-document
455 // navigation.
456 if (render_manager_.speculative_frame_host())
457 return true;
458
459 return render_manager_.current_frame_host()
460 ->HasPendingCommitForCrossDocumentNavigation();
461}
462
Charlie Hu5ffc0152019-12-06 15:59:53463bool FrameTreeNode::CommitFramePolicy(
464 const blink::FramePolicy& new_frame_policy) {
465 bool did_change_flags = new_frame_policy.sandbox_flags !=
Antonio Sartori90f41212021-01-22 10:08:34466 replication_state_->frame_policy.sandbox_flags;
iclelland92f8c0b2017-04-19 12:43:05467 bool did_change_container_policy =
Charlie Hu5ffc0152019-12-06 15:59:53468 new_frame_policy.container_policy !=
Antonio Sartori90f41212021-01-22 10:08:34469 replication_state_->frame_policy.container_policy;
Charlie Hue1b77ac2019-12-13 21:30:17470 bool did_change_required_document_policy =
471 pending_frame_policy_.required_document_policy !=
Antonio Sartori90f41212021-01-22 10:08:34472 replication_state_->frame_policy.required_document_policy;
Dave Tapuska9b153a942020-02-10 19:35:10473 bool did_change_document_access =
474 new_frame_policy.disallow_document_access !=
Antonio Sartori90f41212021-01-22 10:08:34475 replication_state_->frame_policy.disallow_document_access;
476 if (did_change_flags) {
477 replication_state_->frame_policy.sandbox_flags =
Charlie Hu5ffc0152019-12-06 15:59:53478 new_frame_policy.sandbox_flags;
Antonio Sartori90f41212021-01-22 10:08:34479 }
480 if (did_change_container_policy) {
481 replication_state_->frame_policy.container_policy =
Charlie Hu5ffc0152019-12-06 15:59:53482 new_frame_policy.container_policy;
Antonio Sartori90f41212021-01-22 10:08:34483 }
484 if (did_change_required_document_policy) {
485 replication_state_->frame_policy.required_document_policy =
Charlie Hue1b77ac2019-12-13 21:30:17486 new_frame_policy.required_document_policy;
Antonio Sartori90f41212021-01-22 10:08:34487 }
488 if (did_change_document_access) {
489 replication_state_->frame_policy.disallow_document_access =
Dave Tapuska9b153a942020-02-10 19:35:10490 new_frame_policy.disallow_document_access;
Antonio Sartori90f41212021-01-22 10:08:34491 }
Charlie Hue1b77ac2019-12-13 21:30:17492
Charlie Hu5ffc0152019-12-06 15:59:53493 UpdateFramePolicyHeaders(new_frame_policy.sandbox_flags,
Charlie Hue20fe2f2021-03-07 03:39:59494 replication_state_->permissions_policy_header);
Charlie Hue1b77ac2019-12-13 21:30:17495 return did_change_flags || did_change_container_policy ||
Dave Tapuska9b153a942020-02-10 19:35:10496 did_change_required_document_policy || did_change_document_access;
alexmos6b294562015-03-05 19:24:10497}
498
Arthur Hemeryc3380172018-01-22 14:00:17499void FrameTreeNode::TransferNavigationRequestOwnership(
500 RenderFrameHostImpl* render_frame_host) {
Andrey Kosyakovf2d4ff72018-10-29 20:09:59501 devtools_instrumentation::OnResetNavigationRequest(navigation_request_.get());
Arthur Hemeryc3380172018-01-22 14:00:17502 render_frame_host->SetNavigationRequest(std::move(navigation_request_));
503}
504
carloskc49005eb2015-06-16 11:25:07505void FrameTreeNode::CreatedNavigationRequest(
dcheng9bfa5162016-04-09 01:00:57506 std::unique_ptr<NavigationRequest> navigation_request) {
arthursonzognic79c251c2016-08-18 15:00:37507 // This is never called when navigating to a Javascript URL. For the loading
508 // state, this matches what Blink is doing: Blink doesn't send throbber
509 // notifications for Javascript URLS.
510 DCHECK(!navigation_request->common_params().url.SchemeIs(
511 url::kJavaScriptScheme));
512
clamy44e84ce2016-02-22 15:38:25513 bool was_previously_loading = frame_tree()->IsLoading();
514
clamy82a2f4d2016-02-02 14:20:41515 // There's no need to reset the state: there's still an ongoing load, and the
516 // RenderFrameHostManager will take care of updates to the speculative
517 // RenderFrameHost in DidCreateNavigationRequest below.
jamcd0b7b22017-03-24 22:13:05518 if (was_previously_loading) {
Mohamed Abdelhalimf03d4a22019-10-01 13:34:31519 if (navigation_request_ && navigation_request_->IsNavigationStarted()) {
jamcd0b7b22017-03-24 22:13:05520 // Mark the old request as aborted.
Mohamed Abdelhalimb4db22a2019-06-18 10:46:52521 navigation_request_->set_net_error(net::ERR_ABORTED);
jamcd0b7b22017-03-24 22:13:05522 }
Arthur Hemery241b9392019-10-24 11:08:41523 ResetNavigationRequest(true);
jamcd0b7b22017-03-24 22:13:05524 }
clamy44e84ce2016-02-22 15:38:25525
526 navigation_request_ = std::move(navigation_request);
Shubhie Panickerddf2a4e2018-03-06 00:09:06527 if (was_discarded_) {
528 navigation_request_->set_was_discarded();
529 was_discarded_ = false;
530 }
clamy8e2e299202016-04-05 11:44:59531 render_manager()->DidCreateNavigationRequest(navigation_request_.get());
fdegans39ff0382015-04-29 19:04:39532
Lucas Furukawa Gadanief8290a2019-07-29 20:27:51533 bool to_different_document = !NavigationTypeUtils::IsSameDocument(
arthursonzogni92f18682017-02-08 23:00:04534 navigation_request_->common_params().navigation_type);
535
536 DidStartLoading(to_different_document, was_previously_loading);
clamydcb434c12015-04-16 19:29:16537}
538
Arthur Hemery241b9392019-10-24 11:08:41539void FrameTreeNode::ResetNavigationRequest(bool keep_state) {
fdegans39ff0382015-04-29 19:04:39540 if (!navigation_request_)
541 return;
John Abd-El-Malekdcc7bf42017-09-12 22:30:23542
Andrey Kosyakovf2d4ff72018-10-29 20:09:59543 devtools_instrumentation::OnResetNavigationRequest(navigation_request_.get());
clamydcb434c12015-04-16 19:29:16544 navigation_request_.reset();
fdegans39ff0382015-04-29 19:04:39545
clamy82a2f4d2016-02-02 14:20:41546 if (keep_state)
fdegans39ff0382015-04-29 19:04:39547 return;
548
clamy82a2f4d2016-02-02 14:20:41549 // The RenderFrameHostManager should clean up any speculative RenderFrameHost
550 // it created for the navigation. Also register that the load stopped.
fdegans39ff0382015-04-29 19:04:39551 DidStopLoading();
552 render_manager_.CleanUpNavigation();
clamydcb434c12015-04-16 19:29:16553}
554
clamy44e84ce2016-02-22 15:38:25555void FrameTreeNode::DidStartLoading(bool to_different_document,
556 bool was_previously_loading) {
Camille Lamyefd54b02018-10-04 16:54:14557 TRACE_EVENT2("navigation", "FrameTreeNode::DidStartLoading",
558 "frame_tree_node", frame_tree_node_id(), "to different document",
559 to_different_document);
fdegansa696e5112015-04-17 01:57:59560
Carlos Caballero03262522021-02-05 14:49:58561 frame_tree_->DidStartLoadingNode(*this, to_different_document,
562 was_previously_loading);
fdegansa696e5112015-04-17 01:57:59563
564 // Set initial load progress and update overall progress. This will notify
565 // the WebContents of the load progress change.
566 DidChangeLoadProgress(kLoadingProgressMinimum);
567
568 // Notify the RenderFrameHostManager of the event.
569 render_manager()->OnDidStartLoading();
570}
571
572void FrameTreeNode::DidStopLoading() {
Camille Lamyefd54b02018-10-04 16:54:14573 TRACE_EVENT1("navigation", "FrameTreeNode::DidStopLoading", "frame_tree_node",
574 frame_tree_node_id());
fdegansa696e5112015-04-17 01:57:59575 // Set final load progress and update overall progress. This will notify
576 // the WebContents of the load progress change.
577 DidChangeLoadProgress(kLoadingProgressDone);
578
Lucas Furukawa Gadani6faef602019-05-06 21:16:03579 // Notify the RenderFrameHostManager of the event.
580 render_manager()->OnDidStopLoading();
581
Carlos Caballero03262522021-02-05 14:49:58582 frame_tree_->DidStopLoadingNode(*this);
fdegansa696e5112015-04-17 01:57:59583}
584
585void FrameTreeNode::DidChangeLoadProgress(double load_progress) {
Nate Chapin93536702018-02-07 00:12:21586 DCHECK_GE(load_progress, kLoadingProgressMinimum);
587 DCHECK_LE(load_progress, kLoadingProgressDone);
Carlos Caballero03262522021-02-05 14:49:58588 frame_tree_->DidChangeLoadProgressForNode(*this, load_progress);
fdegansa696e5112015-04-17 01:57:59589}
590
clamyf73862c42015-07-08 12:31:33591bool FrameTreeNode::StopLoading() {
arthursonzogni66f711c2019-10-08 14:40:36592 if (navigation_request_ && navigation_request_->IsNavigationStarted())
593 navigation_request_->set_net_error(net::ERR_ABORTED);
Arthur Hemery241b9392019-10-24 11:08:41594 ResetNavigationRequest(false);
clamyf73862c42015-07-08 12:31:33595
clamyf73862c42015-07-08 12:31:33596 if (!IsMainFrame())
597 return true;
598
599 render_manager_.Stop();
600 return true;
601}
602
alexmos21acae52015-11-07 01:04:43603void FrameTreeNode::DidFocus() {
604 last_focus_time_ = base::TimeTicks::Now();
ericwilligers254597b2016-10-17 10:32:31605 for (auto& observer : observers_)
606 observer.OnFrameTreeNodeFocused(this);
alexmos21acae52015-11-07 01:04:43607}
608
clamy44e84ce2016-02-22 15:38:25609void FrameTreeNode::BeforeUnloadCanceled() {
610 // TODO(clamy): Support BeforeUnload in subframes.
611 if (!IsMainFrame())
612 return;
613
614 RenderFrameHostImpl* current_frame_host =
615 render_manager_.current_frame_host();
616 DCHECK(current_frame_host);
617 current_frame_host->ResetLoadingState();
618
clamy610c63b32017-12-22 15:05:18619 RenderFrameHostImpl* speculative_frame_host =
620 render_manager_.speculative_frame_host();
621 if (speculative_frame_host)
622 speculative_frame_host->ResetLoadingState();
Alexander Timin23c110b2021-01-14 02:39:04623 // Note: there is no need to set an error code on the NavigationHandle as
624 // the observers have not been notified about its creation.
625 // We also reset navigation request only when this navigation request was
626 // responsible for this dialog, as a new navigation request might cancel
627 // existing unrelated dialog.
628 if (navigation_request_ && navigation_request_->IsWaitingForBeforeUnload())
Arthur Hemery241b9392019-10-24 11:08:41629 ResetNavigationRequest(false);
clamy44e84ce2016-02-22 15:38:25630}
631
Mustaq Ahmedecb5c38e2020-07-29 00:34:30632bool FrameTreeNode::NotifyUserActivation(
633 blink::mojom::UserActivationNotificationType notification_type) {
Alex Moshchuk03904192021-04-02 07:29:08634 // User Activation V2 requires activating all ancestor frames in addition to
635 // the current frame. See
636 // https://html.spec.whatwg.org/multipage/interaction.html#tracking-user-activation.
Alexander Timina1dfadaa2020-04-28 13:30:06637 for (RenderFrameHostImpl* rfh = current_frame_host(); rfh;
638 rfh = rfh->GetParent()) {
John Delaneyb625dca92021-04-14 17:00:34639 rfh->DidReceiveUserActivation();
Mustaq Ahmedecb5c38e2020-07-29 00:34:30640 rfh->frame_tree_node()->user_activation_state_.Activate(notification_type);
John Delaneyedd8d6c2019-01-25 00:23:57641 }
Alex Moshchuk03904192021-04-02 07:29:08642
Antonio Sartori90f41212021-01-22 10:08:34643 replication_state_->has_active_user_gesture = true;
Mustaq Ahmeda5dfa60b2018-12-08 00:30:14644
Mustaq Ahmed0180320f2019-03-21 16:07:01645 // See the "Same-origin Visibility" section in |UserActivationState| class
646 // doc.
Mustaq Ahmede5f12562019-10-30 18:02:03647 if (base::FeatureList::IsEnabled(
Mustaq Ahmeda5dfa60b2018-12-08 00:30:14648 features::kUserActivationSameOriginVisibility)) {
649 const url::Origin& current_origin =
650 this->current_frame_host()->GetLastCommittedOrigin();
651 for (FrameTreeNode* node : frame_tree()->Nodes()) {
652 if (node->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith(
653 current_origin)) {
Mustaq Ahmedecb5c38e2020-07-29 00:34:30654 node->user_activation_state_.Activate(notification_type);
Mustaq Ahmeda5dfa60b2018-12-08 00:30:14655 }
656 }
657 }
658
Carlos Caballero40b0efd2021-01-26 11:55:00659 navigator().controller().NotifyUserActivation();
Alex Moshchuk03904192021-04-02 07:29:08660 current_frame_host()->MaybeIsolateForUserActivation();
Shivani Sharma194877032019-03-07 17:52:47661
Mustaq Ahmedc4cb7162018-06-05 16:28:36662 return true;
663}
664
665bool FrameTreeNode::ConsumeTransientUserActivation() {
666 bool was_active = user_activation_state_.IsActive();
667 for (FrameTreeNode* node : frame_tree()->Nodes())
668 node->user_activation_state_.ConsumeIfActive();
Antonio Sartori90f41212021-01-22 10:08:34669 replication_state_->has_active_user_gesture = false;
Mustaq Ahmedc4cb7162018-06-05 16:28:36670 return was_active;
671}
672
Shivani Sharmac4f561582018-11-15 15:58:39673bool FrameTreeNode::ClearUserActivation() {
Shivani Sharmac4f561582018-11-15 15:58:39674 for (FrameTreeNode* node : frame_tree()->SubtreeNodes(this))
675 node->user_activation_state_.Clear();
Antonio Sartori90f41212021-01-22 10:08:34676 replication_state_->has_active_user_gesture = false;
Shivani Sharmac4f561582018-11-15 15:58:39677 return true;
678}
679
Ella Ge9caed612019-08-09 16:17:25680bool FrameTreeNode::VerifyUserActivation() {
Ella Gea78f6772019-12-11 10:35:25681 DCHECK(base::FeatureList::IsEnabled(
682 features::kBrowserVerifiedUserActivationMouse) ||
683 base::FeatureList::IsEnabled(
684 features::kBrowserVerifiedUserActivationKeyboard));
685
Ella Ge9caed612019-08-09 16:17:25686 return render_manager_.current_frame_host()
687 ->GetRenderWidgetHost()
Mustaq Ahmed83bb1722019-10-22 20:00:10688 ->RemovePendingUserActivationIfAvailable();
Ella Ge9caed612019-08-09 16:17:25689}
690
Mustaq Ahmedc4cb7162018-06-05 16:28:36691bool FrameTreeNode::UpdateUserActivationState(
Mustaq Ahmeddc195e5b2020-08-04 18:45:11692 blink::mojom::UserActivationUpdateType update_type,
693 blink::mojom::UserActivationNotificationType notification_type) {
Ella Ge9caed612019-08-09 16:17:25694 bool update_result = false;
Mustaq Ahmedc4cb7162018-06-05 16:28:36695 switch (update_type) {
Antonio Gomes4b2c5132020-01-16 11:49:48696 case blink::mojom::UserActivationUpdateType::kConsumeTransientActivation:
Ella Ge9caed612019-08-09 16:17:25697 update_result = ConsumeTransientUserActivation();
698 break;
Antonio Gomes4b2c5132020-01-16 11:49:48699 case blink::mojom::UserActivationUpdateType::kNotifyActivation:
Mustaq Ahmeddc195e5b2020-08-04 18:45:11700 update_result = NotifyUserActivation(notification_type);
Ella Ge9caed612019-08-09 16:17:25701 break;
Antonio Gomes4b2c5132020-01-16 11:49:48702 case blink::mojom::UserActivationUpdateType::
Liviu Tintad9391fb92020-09-28 23:50:07703 kNotifyActivationPendingBrowserVerification: {
704 const bool user_activation_verified = VerifyUserActivation();
705 // Add UMA metric for when browser user activation verification succeeds
706 base::UmaHistogramBoolean("Event.BrowserVerifiedUserActivation",
707 user_activation_verified);
708 if (user_activation_verified) {
Mustaq Ahmedecb5c38e2020-07-29 00:34:30709 update_result = NotifyUserActivation(
Mustaq Ahmed2cfb0402020-09-29 19:24:35710 blink::mojom::UserActivationNotificationType::kInteraction);
Antonio Gomes4b2c5132020-01-16 11:49:48711 update_type = blink::mojom::UserActivationUpdateType::kNotifyActivation;
Ella Ge9caed612019-08-09 16:17:25712 } else {
arthursonzogni9816b9192021-03-29 16:09:19713 // TODO(https://crbug.com/848778): We need to decide what to do when
714 // user activation verification failed. NOTREACHED here will make all
Ella Ge9caed612019-08-09 16:17:25715 // unrelated tests that inject event to renderer fail.
716 return false;
717 }
Liviu Tintad9391fb92020-09-28 23:50:07718 } break;
Antonio Gomes4b2c5132020-01-16 11:49:48719 case blink::mojom::UserActivationUpdateType::kClearActivation:
Ella Ge9caed612019-08-09 16:17:25720 update_result = ClearUserActivation();
721 break;
Mustaq Ahmedc4cb7162018-06-05 16:28:36722 }
Mustaq Ahmeddc195e5b2020-08-04 18:45:11723 render_manager_.UpdateUserActivationState(update_type, notification_type);
Ella Ge9caed612019-08-09 16:17:25724 return update_result;
japhet61835ae12017-01-20 01:25:39725}
726
Mustaq Ahmed01261742019-12-16 15:49:06727void FrameTreeNode::OnSetHadStickyUserActivationBeforeNavigation(bool value) {
728 render_manager_.OnSetHadStickyUserActivationBeforeNavigation(value);
Antonio Sartori90f41212021-01-22 10:08:34729 replication_state_->has_received_user_gesture_before_nav = value;
Becca Hughes60af7d42017-12-12 10:53:15730}
731
paulmeyer322777fb2016-05-16 23:15:39732FrameTreeNode* FrameTreeNode::GetSibling(int relative_offset) const {
paulmeyerf3119f52016-05-17 17:37:19733 if (!parent_ || !parent_->child_count())
paulmeyer322777fb2016-05-16 23:15:39734 return nullptr;
735
736 for (size_t i = 0; i < parent_->child_count(); ++i) {
737 if (parent_->child_at(i) == this) {
738 if ((relative_offset < 0 && static_cast<size_t>(-relative_offset) > i) ||
739 i + relative_offset >= parent_->child_count()) {
740 return nullptr;
741 }
742 return parent_->child_at(i + relative_offset);
743 }
744 }
745
746 NOTREACHED() << "FrameTreeNode not found in its parent's children.";
747 return nullptr;
748}
749
Alexander Timin45b716c2020-11-06 01:40:31750bool FrameTreeNode::UpdateFramePolicyHeaders(
arthursonzognib93a4472020-04-10 07:38:00751 network::mojom::WebSandboxFlags sandbox_flags,
Charlie Hue24f04832021-03-04 21:07:06752 const blink::ParsedPermissionsPolicy& parsed_header) {
Ian Clellandedb8c5dd2018-03-01 17:01:37753 bool changed = false;
Charlie Hue20fe2f2021-03-07 03:39:59754 if (replication_state_->permissions_policy_header != parsed_header) {
755 replication_state_->permissions_policy_header = parsed_header;
Ian Clellandedb8c5dd2018-03-01 17:01:37756 changed = true;
757 }
Ian Clelland5cbaaf82017-11-27 22:00:03758 // TODO(iclelland): Kill the renderer if sandbox flags is not a subset of the
759 // currently effective sandbox flags from the frame. https://crbug.com/740556
arthursonzognib93a4472020-04-10 07:38:00760 network::mojom::WebSandboxFlags updated_flags =
Ian Clelland5cbaaf82017-11-27 22:00:03761 sandbox_flags | effective_frame_policy().sandbox_flags;
Antonio Sartori90f41212021-01-22 10:08:34762 if (replication_state_->active_sandbox_flags != updated_flags) {
763 replication_state_->active_sandbox_flags = updated_flags;
Ian Clellandedb8c5dd2018-03-01 17:01:37764 changed = true;
765 }
766 // Notify any proxies if the policies have been changed.
767 if (changed)
768 render_manager()->OnDidSetFramePolicyHeaders();
Alexander Timin45b716c2020-11-06 01:40:31769 return changed;
Ian Clelland5cbaaf82017-11-27 22:00:03770}
771
Arthur Sonzognif8840b92018-11-07 14:10:35772void FrameTreeNode::PruneChildFrameNavigationEntries(
773 NavigationEntryImpl* entry) {
774 for (size_t i = 0; i < current_frame_host()->child_count(); ++i) {
775 FrameTreeNode* child = current_frame_host()->child_at(i);
776 if (child->is_created_by_script_) {
777 entry->RemoveEntryForFrame(child,
778 /* only_if_different_position = */ false);
779 } else {
780 child->PruneChildFrameNavigationEntries(entry);
781 }
782 }
783}
784
Yao Xiao24ec9aa2020-01-28 16:36:00785void FrameTreeNode::SetAdFrameType(blink::mojom::AdFrameType ad_frame_type) {
Alex Turner5a09c462021-03-17 17:07:35786 if (ad_frame_type == replication_state_->ad_frame_type)
787 return;
788
789 replication_state_->ad_frame_type = ad_frame_type;
790 render_manager()->OnDidSetAdFrameType(ad_frame_type);
Yao Xiao24ec9aa2020-01-28 16:36:00791}
792
arthursonzogni034bb9c2020-10-01 08:29:56793void FrameTreeNode::SetInitialPopupURL(const GURL& initial_popup_url) {
794 DCHECK(initial_popup_url_.is_empty());
795 DCHECK(!has_committed_real_load_);
796 initial_popup_url_ = initial_popup_url;
797}
798
799void FrameTreeNode::SetPopupCreatorOrigin(
800 const url::Origin& popup_creator_origin) {
801 DCHECK(!has_committed_real_load_);
802 popup_creator_origin_ = popup_creator_origin;
803}
804
Alexander Timinbebb2002021-04-20 15:42:24805void FrameTreeNode::WriteIntoTrace(perfetto::TracedValue context) const {
Alexander Timinf785f342021-03-18 00:00:56806 auto dict = std::move(context).WriteDictionary();
807 dict.Add("id", frame_tree_node_id());
808 dict.Add("is_main_frame", IsMainFrame());
809}
810
Carlos Caballero76711352021-03-24 17:38:21811bool FrameTreeNode::HasNavigation() {
812 if (navigation_request())
813 return true;
814
815 // Same-RenderFrameHost navigation is committing:
816 if (current_frame_host()->HasPendingCommitNavigation())
817 return true;
818
819 // Cross-RenderFrameHost navigation is committing:
820 if (render_manager()->speculative_frame_host())
821 return true;
822
823 return false;
824}
825
[email protected]9b159a52013-10-03 17:24:55826} // namespace content