blob: b72d529a84339ab238dc6ee65a403c381413cb29 [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>
8
[email protected]9b159a52013-10-03 17:24:559#include <queue>
Takuto Ikutaadf31eb2019-01-05 00:32:4810#include <unordered_map>
dcheng36b6aec92015-12-26 06:16:3611#include <utility>
[email protected]9b159a52013-10-03 17:24:5512
Mustaq Ahmeda5dfa60b2018-12-08 00:30:1413#include "base/feature_list.h"
scottmg6ece5ae2017-02-01 18:25:1914#include "base/lazy_instance.h"
avib7348942015-12-25 20:57:1015#include "base/macros.h"
Liviu Tintad9391fb92020-09-28 23:50:0716#include "base/metrics/histogram_functions.h"
dcheng23ca947d2016-05-04 20:04:1517#include "base/metrics/histogram_macros.h"
[email protected]9b159a52013-10-03 17:24:5518#include "base/stl_util.h"
Daniel Cheng6ca7f1c92017-08-09 21:45:4119#include "base/strings/string_util.h"
Andrey Kosyakovf2d4ff72018-10-29 20:09:5920#include "content/browser/devtools/devtools_instrumentation.h"
danakjc492bf82020-09-09 20:02:4421#include "content/browser/renderer_host/navigation_controller_impl.h"
22#include "content/browser/renderer_host/navigation_request.h"
23#include "content/browser/renderer_host/navigator.h"
24#include "content/browser/renderer_host/navigator_delegate.h"
25#include "content/browser/renderer_host/render_frame_host_impl.h"
[email protected]94d0cc12013-12-18 00:07:4126#include "content/browser/renderer_host/render_view_host_impl.h"
clamyf73862c42015-07-08 12:31:3327#include "content/common/frame_messages.h"
Lucas Furukawa Gadanief8290a2019-07-29 20:27:5128#include "content/common/navigation_params.h"
29#include "content/common/navigation_params_utils.h"
dmazzonie950ea232015-03-13 21:39:4530#include "content/public/browser/browser_thread.h"
Mustaq Ahmeda5dfa60b2018-12-08 00:30:1431#include "content/public/common/content_features.h"
Arthur Sonzognif21fb512018-11-06 09:31:5832#include "content/public/common/navigation_policy.h"
arthursonzognib93a4472020-04-10 07:38:0033#include "services/network/public/cpp/web_sandbox_flags.h"
34#include "services/network/public/mojom/web_sandbox_flags.mojom-shared.h"
Antonio Gomes4b2c5132020-01-16 11:49:4835#include "third_party/blink/public/mojom/frame/user_activation_update_types.mojom.h"
Julie Jeongeun Kimd90e2dd2020-03-03 11:45:3736#include "third_party/blink/public/mojom/security_context/insecure_request_policy.mojom.h"
[email protected]9b159a52013-10-03 17:24:5537
38namespace content {
39
dmazzonie950ea232015-03-13 21:39:4540namespace {
41
42// This is a global map between frame_tree_node_ids and pointers to
43// FrameTreeNodes.
Takuto Ikutaadf31eb2019-01-05 00:32:4844typedef std::unordered_map<int, FrameTreeNode*> FrameTreeNodeIdMap;
dmazzonie950ea232015-03-13 21:39:4545
scottmg5e65e3a2017-03-08 08:48:4646base::LazyInstance<FrameTreeNodeIdMap>::DestructorAtExit
47 g_frame_tree_node_id_map = LAZY_INSTANCE_INITIALIZER;
dmazzonie950ea232015-03-13 21:39:4548
fdegansa696e5112015-04-17 01:57:5949// These values indicate the loading progress status. The minimum progress
50// value matches what Blink's ProgressTracker has traditionally used for a
51// minimum progress value.
fdegansa696e5112015-04-17 01:57:5952const double kLoadingProgressMinimum = 0.1;
53const double kLoadingProgressDone = 1.0;
dmazzonie950ea232015-03-13 21:39:4554
fdegansa696e5112015-04-17 01:57:5955} // namespace
fdegans1d16355162015-03-26 11:58:3456
alexmose201c7cd2015-06-10 17:14:2157// This observer watches the opener of its owner FrameTreeNode and clears the
58// owner's opener if the opener is destroyed.
59class FrameTreeNode::OpenerDestroyedObserver : public FrameTreeNode::Observer {
60 public:
jochen6004a362017-02-04 00:11:4061 OpenerDestroyedObserver(FrameTreeNode* owner, bool observing_original_opener)
62 : owner_(owner), observing_original_opener_(observing_original_opener) {}
alexmose201c7cd2015-06-10 17:14:2163
64 // FrameTreeNode::Observer
65 void OnFrameTreeNodeDestroyed(FrameTreeNode* node) override {
jochen6004a362017-02-04 00:11:4066 if (observing_original_opener_) {
Avi Drissman36465f332017-09-11 20:49:3967 // The "original owner" is special. It's used for attribution, and clients
68 // walk down the original owner chain. Therefore, if a link in the chain
69 // is being destroyed, reconnect the observation to the parent of the link
70 // being destroyed.
jochen6004a362017-02-04 00:11:4071 CHECK_EQ(owner_->original_opener(), node);
Avi Drissman36465f332017-09-11 20:49:3972 owner_->SetOriginalOpener(node->original_opener());
73 // |this| is deleted at this point.
jochen6004a362017-02-04 00:11:4074 } else {
75 CHECK_EQ(owner_->opener(), node);
76 owner_->SetOpener(nullptr);
Avi Drissman36465f332017-09-11 20:49:3977 // |this| is deleted at this point.
jochen6004a362017-02-04 00:11:4078 }
alexmose201c7cd2015-06-10 17:14:2179 }
80
81 private:
82 FrameTreeNode* owner_;
jochen6004a362017-02-04 00:11:4083 bool observing_original_opener_;
alexmose201c7cd2015-06-10 17:14:2184
85 DISALLOW_COPY_AND_ASSIGN(OpenerDestroyedObserver);
86};
87
Kevin McNee88e61552020-10-22 20:41:1188const int FrameTreeNode::kFrameTreeNodeInvalidId = -1;
89
90static_assert(FrameTreeNode::kFrameTreeNodeInvalidId ==
91 RenderFrameHost::kNoFrameTreeNodeId,
92 "Have consistent sentinel values for an invalid FTN id.");
93
vishal.b782eb5d2015-04-29 12:22:5794int FrameTreeNode::next_frame_tree_node_id_ = 1;
[email protected]9b159a52013-10-03 17:24:5595
dmazzonie950ea232015-03-13 21:39:4596// static
vishal.b782eb5d2015-04-29 12:22:5797FrameTreeNode* FrameTreeNode::GloballyFindByID(int frame_tree_node_id) {
mostynb366eaf12015-03-26 00:51:1998 DCHECK_CURRENTLY_ON(BrowserThread::UI);
rob97250742015-12-10 17:45:1599 FrameTreeNodeIdMap* nodes = g_frame_tree_node_id_map.Pointer();
jdoerrie55ec69d2018-10-08 13:34:46100 auto it = nodes->find(frame_tree_node_id);
dmazzonie950ea232015-03-13 21:39:45101 return it == nodes->end() ? nullptr : it->second;
102}
103
Alexander Timin381e7e182020-04-28 19:04:03104// static
105FrameTreeNode* FrameTreeNode::From(RenderFrameHost* rfh) {
106 if (!rfh)
107 return nullptr;
108 return static_cast<RenderFrameHostImpl*>(rfh)->frame_tree_node();
109}
110
Julie Jeongeun Kim70a2e4e2020-02-21 05:09:54111FrameTreeNode::FrameTreeNode(
112 FrameTree* frame_tree,
Alexander Timin381e7e182020-04-28 19:04:03113 RenderFrameHostImpl* parent,
Antonio Gomes9d5c1ef2020-04-30 20:56:41114 blink::mojom::TreeScopeType scope,
Julie Jeongeun Kim70a2e4e2020-02-21 05:09:54115 const std::string& name,
116 const std::string& unique_name,
117 bool is_created_by_script,
118 const base::UnguessableToken& devtools_frame_token,
119 const blink::mojom::FrameOwnerProperties& frame_owner_properties,
Antonio Gomes58d38062020-04-30 01:50:14120 blink::mojom::FrameOwnerElementType owner_type)
[email protected]bffc8302014-01-23 20:52:16121 : frame_tree_(frame_tree),
Lucas Furukawa Gadani72cc21c2018-09-04 18:50:46122 render_manager_(this, frame_tree->manager_delegate()),
[email protected]bffc8302014-01-23 20:52:16123 frame_tree_node_id_(next_frame_tree_node_id_++),
xiaochengh98488162016-05-19 15:17:59124 parent_(parent),
Alexander Timin381e7e182020-04-28 19:04:03125 depth_(parent ? parent->frame_tree_node()->depth_ + 1 : 0u),
alexmose201c7cd2015-06-10 17:14:21126 opener_(nullptr),
jochen6004a362017-02-04 00:11:40127 original_opener_(nullptr),
creisf0f069a2015-07-23 23:51:53128 has_committed_real_load_(false),
engedy6e2e0992017-05-25 18:58:42129 is_collapsed_(false),
estarka886b8d2015-12-18 21:53:08130 replication_state_(
131 scope,
132 name,
lukasza464d8692016-02-22 19:26:32133 unique_name,
Julie Jeongeun Kimd90e2dd2020-03-03 11:45:37134 blink::mojom::InsecureRequestPolicy::
135 kLeaveInsecureRequestsAlone /* should enforce strict mixed content
136 checking */
137 ,
arthursonzogni4b62a5cb2018-01-17 14:14:26138 std::vector<uint32_t>()
139 /* hashes of hosts for insecure request upgrades */,
japhet61835ae12017-01-20 01:25:39140 false /* is a potentially trustworthy unique origin */,
danakj359a4342020-05-29 20:38:39141 false /* has an active user gesture */,
Ehsan Karamad192a8da2018-10-21 03:48:08142 false /* has received a user gesture before nav */,
143 owner_type),
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45144 is_created_by_script_(is_created_by_script),
Pavel Feldman25234722017-10-11 02:49:06145 devtools_frame_token_(devtools_frame_token),
lazyboy70605c32015-11-03 01:27:31146 frame_owner_properties_(frame_owner_properties),
Shubhie Panickerddf2a4e2018-03-06 00:09:06147 was_discarded_(false),
Alexander Timin381e7e182020-04-28 19:04:03148 blame_context_(frame_tree_node_id_, FrameTreeNode::From(parent)) {
rob97250742015-12-10 17:45:15149 std::pair<FrameTreeNodeIdMap::iterator, bool> result =
dmazzonie950ea232015-03-13 21:39:45150 g_frame_tree_node_id_map.Get().insert(
151 std::make_pair(frame_tree_node_id_, this));
152 CHECK(result.second);
benjhaydend4da63d2016-03-11 21:29:33153
xiaochenghb9554bb2016-05-21 14:20:48154 // Note: this should always be done last in the constructor.
155 blame_context_.Initialize();
alexmos998581d2015-01-22 01:01:59156}
[email protected]9b159a52013-10-03 17:24:55157
158FrameTreeNode::~FrameTreeNode() {
Nasko Oskov252ae042018-10-04 21:44:12159 // Remove the children.
160 current_frame_host()->ResetChildren();
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45161
Nate Chapin22ea6592019-03-05 22:29:02162 current_frame_host()->ResetLoadingState();
163
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45164 // If the removed frame was created by a script, then its history entry will
165 // never be reused - we can save some memory by removing the history entry.
166 // See also https://crbug.com/784356.
167 if (is_created_by_script_ && parent_) {
168 NavigationEntryImpl* nav_entry = static_cast<NavigationEntryImpl*>(
Fergal Daly09d6c762020-05-29 02:05:18169 navigator().GetController()->GetLastCommittedEntry());
Lukasz Anforowicz7bfb2e92017-11-22 17:19:45170 if (nav_entry) {
171 nav_entry->RemoveEntryForFrame(this,
172 /* only_if_different_position = */ false);
173 }
174 }
175
dmazzonie950ea232015-03-13 21:39:45176 frame_tree_->FrameRemoved(this);
ericwilligers254597b2016-10-17 10:32:31177 for (auto& observer : observers_)
178 observer.OnFrameTreeNodeDestroyed(this);
alexmose201c7cd2015-06-10 17:14:21179
180 if (opener_)
181 opener_->RemoveObserver(opener_observer_.get());
jochen6004a362017-02-04 00:11:40182 if (original_opener_)
183 original_opener_->RemoveObserver(original_opener_observer_.get());
dmazzonie950ea232015-03-13 21:39:45184
185 g_frame_tree_node_id_map.Get().erase(frame_tree_node_id_);
jam39258caf2016-11-02 14:48:18186
danakjf9400602019-06-07 15:44:58187 bool did_stop_loading = false;
188
jam39258caf2016-11-02 14:48:18189 if (navigation_request_) {
danakjf9400602019-06-07 15:44:58190 navigation_request_.reset();
Arthur Hemery0dd65812019-08-01 14:18:45191 // If a frame with a pending navigation is detached, make sure the
192 // WebContents (and its observers) update their loading state.
danakjf9400602019-06-07 15:44:58193 did_stop_loading = true;
jam39258caf2016-11-02 14:48:18194 }
Nate Chapin22ea6592019-03-05 22:29:02195
danakjf9400602019-06-07 15:44:58196 // ~SiteProcessCountTracker DCHECKs in some tests if the speculative
197 // RenderFrameHostImpl is not destroyed last. Ideally this would be closer to
198 // (possible before) the ResetLoadingState() call above.
199 //
200 // There is an inherent race condition causing bugs 838348/915179/et al, where
201 // the renderer may have committed the speculative main frame and the browser
202 // has not heard about it yet. If this is a main frame, then in that case the
203 // speculative RenderFrame was unable to be deleted (it is owned by the
204 // renderer) and we should not be able to cancel the navigation at this point.
205 // CleanUpNavigation() would normally be called here but it will try to undo
206 // the navigation and expose the race condition. When it replaces the main
207 // frame with a RenderFrameProxy, that leaks the committed main frame, leaving
208 // the frame and its friend group with pointers that will become invalid
209 // shortly as we are shutting everything down and deleting the RenderView etc.
210 // We avoid this problematic situation by not calling CleanUpNavigation() or
211 // DiscardUnusedFrame() here. The speculative RenderFrameHost is simply
212 // returned and deleted immediately. This satisfies the requirement that the
213 // speculative RenderFrameHost is removed from the RenderFrameHostManager
214 // before it is destroyed.
215 if (render_manager_.speculative_frame_host()) {
216 did_stop_loading |= render_manager_.speculative_frame_host()->is_loading();
217 render_manager_.UnsetSpeculativeRenderFrameHost();
218 }
219
220 if (did_stop_loading)
221 DidStopLoading();
222
Nate Chapin22ea6592019-03-05 22:29:02223 DCHECK(!IsLoading());
[email protected]9b159a52013-10-03 17:24:55224}
225
alexmose201c7cd2015-06-10 17:14:21226void FrameTreeNode::AddObserver(Observer* observer) {
227 observers_.AddObserver(observer);
228}
229
230void FrameTreeNode::RemoveObserver(Observer* observer) {
231 observers_.RemoveObserver(observer);
232}
233
[email protected]94d0cc12013-12-18 00:07:41234bool FrameTreeNode::IsMainFrame() const {
235 return frame_tree_->root() == this;
236}
237
Alexander Timin45b716c2020-11-06 01:40:31238FrameTreeNode::ResetForNavigationResult FrameTreeNode::ResetForNavigation(
239 bool was_served_from_back_forward_cache) {
240 // TODO(altimin,carlscab): Remove this logic after the relevant states are
241 // moved to RenderFrameHost or BrowsingInstanceFrameState.
242 ResetForNavigationResult result;
243
Ian Clelland5cbaaf82017-11-27 22:00:03244 replication_state_.accumulated_csp_headers.clear();
Alexander Timin45b716c2020-11-06 01:40:31245 if (!was_served_from_back_forward_cache) {
246 render_manager_.OnDidResetContentSecurityPolicy();
247 } else {
248 for (auto& policy : current_frame_host()->ContentSecurityPolicies()) {
249 replication_state_.accumulated_csp_headers.push_back(*policy->header);
250 }
251 // Note: there is no need to call OnDidResetContentSecurityPolicy or any
252 // other update as the proxies are being restored from bfcache as well and
253 // they already have the correct value.
254 }
Ian Clelland5cbaaf82017-11-27 22:00:03255
Ian Clellandedb8c5dd2018-03-01 17:01:37256 // Clear any CSP-set sandbox flags, and the declared feature policy for the
257 // frame.
Alexander Timin45b716c2020-11-06 01:40:31258 // TODO(https://crbug.com/1145886): Remove this.
259 result.changed_frame_policy =
260 UpdateFramePolicyHeaders(network::mojom::WebSandboxFlags::kNone, {});
Shivani Sharmac4f561582018-11-15 15:58:39261
Mustaq Ahmedc53e4c562019-01-29 19:05:09262 // This frame has had its user activation bits cleared in the renderer
263 // before arriving here. We just need to clear them here and in the other
264 // renderer processes that may have a reference to this frame.
Alexander Timin45b716c2020-11-06 01:40:31265 //
266 // We do not take user activation into account when calculating
267 // |ResetForNavigationResult|, as we are using it to determine bfcache
268 // eligibility and the page can get another user gesture after restore.
Antonio Gomes4b2c5132020-01-16 11:49:48269 UpdateUserActivationState(
Mustaq Ahmeddc195e5b2020-08-04 18:45:11270 blink::mojom::UserActivationUpdateType::kClearActivation,
271 blink::mojom::UserActivationNotificationType::kNone);
Alexander Timin45b716c2020-11-06 01:40:31272
273 return result;
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) {
339 if (!origin.IsSameOriginWith(replication_state_.origin) ||
340 replication_state_.has_potentially_trustworthy_unique_origin !=
341 is_potentially_trustworthy_unique_origin) {
342 render_manager_.OnDidUpdateOrigin(origin,
343 is_potentially_trustworthy_unique_origin);
344 }
alexmosa7a4ff822015-04-27 17:59:56345 replication_state_.origin = origin;
estarkbd8e26f2016-03-16 23:30:37346 replication_state_.has_potentially_trustworthy_unique_origin =
347 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
lukasza464d8692016-02-22 19:26:32359void FrameTreeNode::SetFrameName(const std::string& name,
360 const std::string& unique_name) {
361 if (name == replication_state_.name) {
362 // |unique_name| shouldn't change unless |name| changes.
363 DCHECK_EQ(unique_name, replication_state_.unique_name);
364 return;
365 }
lukasza5140a412016-09-15 21:12:30366
367 if (parent()) {
368 // Non-main frames should have a non-empty unique name.
369 DCHECK(!unique_name.empty());
370 } else {
371 // Unique name of main frames should always stay empty.
372 DCHECK(unique_name.empty());
373 }
374
Daniel Cheng6ca7f1c92017-08-09 21:45:41375 // Note the unique name should only be able to change before the first real
376 // load is committed, but that's not strongly enforced here.
lukasza464d8692016-02-22 19:26:32377 render_manager_.OnDidUpdateName(name, unique_name);
alexmosa7a4ff822015-04-27 17:59:56378 replication_state_.name = name;
lukasza464d8692016-02-22 19:26:32379 replication_state_.unique_name = unique_name;
alexmosbe2f4c32015-03-10 02:30:23380}
381
arthursonzogni662aa652017-03-28 11:09:50382void FrameTreeNode::AddContentSecurityPolicies(
arthursonzogni35a95c72020-01-15 17:49:43383 std::vector<network::mojom::ContentSecurityPolicyHeaderPtr> headers) {
384 for (auto& header : headers)
385 replication_state_.accumulated_csp_headers.push_back(*header);
386 render_manager_.OnDidAddContentSecurityPolicies(std::move(headers));
lukasza8e1c02e42016-05-17 20:05:10387}
388
mkwstf672e7ef2016-06-09 20:51:07389void FrameTreeNode::SetInsecureRequestPolicy(
Julie Jeongeun Kimd90e2dd2020-03-03 11:45:37390 blink::mojom::InsecureRequestPolicy policy) {
mkwstf672e7ef2016-06-09 20:51:07391 if (policy == replication_state_.insecure_request_policy)
estarka886b8d2015-12-18 21:53:08392 return;
mkwstf672e7ef2016-06-09 20:51:07393 render_manager_.OnEnforceInsecureRequestPolicy(policy);
394 replication_state_.insecure_request_policy = policy;
estarka886b8d2015-12-18 21:53:08395}
396
arthursonzogni4b62a5cb2018-01-17 14:14:26397void FrameTreeNode::SetInsecureNavigationsSet(
398 const std::vector<uint32_t>& insecure_navigations_set) {
399 DCHECK(std::is_sorted(insecure_navigations_set.begin(),
400 insecure_navigations_set.end()));
401 if (insecure_navigations_set == replication_state_.insecure_navigations_set)
402 return;
403 render_manager_.OnEnforceInsecureNavigationsSet(insecure_navigations_set);
404 replication_state_.insecure_navigations_set = insecure_navigations_set;
405}
406
Luna Luc3fdacdf2017-11-08 04:48:53407void FrameTreeNode::SetPendingFramePolicy(blink::FramePolicy frame_policy) {
Ian Clellandcdc4f312017-10-13 22:24:12408 pending_frame_policy_.sandbox_flags = frame_policy.sandbox_flags;
Dave Tapuska9b153a942020-02-10 19:35:10409 pending_frame_policy_.disallow_document_access =
410 frame_policy.disallow_document_access;
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();
443 if (speculative_frame_host && speculative_frame_host->is_loading())
444 return true;
fdegans4a49ce932015-03-12 17:11:37445 return current_frame_host->is_loading();
446}
447
Alex Moshchuk9b0fd822020-10-26 23:08:15448bool FrameTreeNode::HasPendingCrossDocumentNavigation() const {
449 // Having a |navigation_request_| on FrameTreeNode implies that there's an
450 // ongoing navigation that hasn't reached the ReadyToCommit state. If the
451 // navigation is between ReadyToCommit and DidCommitNavigation, the
452 // NavigationRequest will be held by RenderFrameHost, which is checked below.
453 if (navigation_request_ && !navigation_request_->IsSameDocument())
454 return true;
455
456 // Having a speculative RenderFrameHost should imply a cross-document
457 // navigation.
458 if (render_manager_.speculative_frame_host())
459 return true;
460
461 return render_manager_.current_frame_host()
462 ->HasPendingCommitForCrossDocumentNavigation();
463}
464
Charlie Hu5ffc0152019-12-06 15:59:53465bool FrameTreeNode::CommitFramePolicy(
466 const blink::FramePolicy& new_frame_policy) {
467 bool did_change_flags = new_frame_policy.sandbox_flags !=
Ian Clellandcdc4f312017-10-13 22:24:12468 replication_state_.frame_policy.sandbox_flags;
iclelland92f8c0b2017-04-19 12:43:05469 bool did_change_container_policy =
Charlie Hu5ffc0152019-12-06 15:59:53470 new_frame_policy.container_policy !=
Ian Clellandcdc4f312017-10-13 22:24:12471 replication_state_.frame_policy.container_policy;
Charlie Hue1b77ac2019-12-13 21:30:17472 bool did_change_required_document_policy =
473 pending_frame_policy_.required_document_policy !=
474 replication_state_.frame_policy.required_document_policy;
Dave Tapuska9b153a942020-02-10 19:35:10475 bool did_change_document_access =
476 new_frame_policy.disallow_document_access !=
477 replication_state_.frame_policy.disallow_document_access;
iclelland92f8c0b2017-04-19 12:43:05478 if (did_change_flags)
Ian Clellandcdc4f312017-10-13 22:24:12479 replication_state_.frame_policy.sandbox_flags =
Charlie Hu5ffc0152019-12-06 15:59:53480 new_frame_policy.sandbox_flags;
iclelland92f8c0b2017-04-19 12:43:05481 if (did_change_container_policy)
Ian Clellandcdc4f312017-10-13 22:24:12482 replication_state_.frame_policy.container_policy =
Charlie Hu5ffc0152019-12-06 15:59:53483 new_frame_policy.container_policy;
Charlie Hue1b77ac2019-12-13 21:30:17484 if (did_change_required_document_policy)
485 replication_state_.frame_policy.required_document_policy =
486 new_frame_policy.required_document_policy;
Dave Tapuska9b153a942020-02-10 19:35:10487 if (did_change_document_access)
488 replication_state_.frame_policy.disallow_document_access =
489 new_frame_policy.disallow_document_access;
Charlie Hue1b77ac2019-12-13 21:30:17490
Charlie Hu5ffc0152019-12-06 15:59:53491 UpdateFramePolicyHeaders(new_frame_policy.sandbox_flags,
Ian Clellandedb8c5dd2018-03-01 17:01:37492 replication_state_.feature_policy_header);
Charlie Hue1b77ac2019-12-13 21:30:17493 return did_change_flags || did_change_container_policy ||
Dave Tapuska9b153a942020-02-10 19:35:10494 did_change_required_document_policy || did_change_document_access;
alexmos6b294562015-03-05 19:24:10495}
496
Arthur Hemeryc3380172018-01-22 14:00:17497void FrameTreeNode::TransferNavigationRequestOwnership(
498 RenderFrameHostImpl* render_frame_host) {
Andrey Kosyakovf2d4ff72018-10-29 20:09:59499 devtools_instrumentation::OnResetNavigationRequest(navigation_request_.get());
Arthur Hemeryc3380172018-01-22 14:00:17500 render_frame_host->SetNavigationRequest(std::move(navigation_request_));
501}
502
carloskc49005eb2015-06-16 11:25:07503void FrameTreeNode::CreatedNavigationRequest(
dcheng9bfa5162016-04-09 01:00:57504 std::unique_ptr<NavigationRequest> navigation_request) {
arthursonzognic79c251c2016-08-18 15:00:37505 // This is never called when navigating to a Javascript URL. For the loading
506 // state, this matches what Blink is doing: Blink doesn't send throbber
507 // notifications for Javascript URLS.
508 DCHECK(!navigation_request->common_params().url.SchemeIs(
509 url::kJavaScriptScheme));
510
clamy44e84ce2016-02-22 15:38:25511 bool was_previously_loading = frame_tree()->IsLoading();
512
clamy82a2f4d2016-02-02 14:20:41513 // There's no need to reset the state: there's still an ongoing load, and the
514 // RenderFrameHostManager will take care of updates to the speculative
515 // RenderFrameHost in DidCreateNavigationRequest below.
jamcd0b7b22017-03-24 22:13:05516 if (was_previously_loading) {
Mohamed Abdelhalimf03d4a22019-10-01 13:34:31517 if (navigation_request_ && navigation_request_->IsNavigationStarted()) {
jamcd0b7b22017-03-24 22:13:05518 // Mark the old request as aborted.
Mohamed Abdelhalimb4db22a2019-06-18 10:46:52519 navigation_request_->set_net_error(net::ERR_ABORTED);
jamcd0b7b22017-03-24 22:13:05520 }
Arthur Hemery241b9392019-10-24 11:08:41521 ResetNavigationRequest(true);
jamcd0b7b22017-03-24 22:13:05522 }
clamy44e84ce2016-02-22 15:38:25523
524 navigation_request_ = std::move(navigation_request);
Shubhie Panickerddf2a4e2018-03-06 00:09:06525 if (was_discarded_) {
526 navigation_request_->set_was_discarded();
527 was_discarded_ = false;
528 }
clamy8e2e299202016-04-05 11:44:59529 render_manager()->DidCreateNavigationRequest(navigation_request_.get());
fdegans39ff0382015-04-29 19:04:39530
Lucas Furukawa Gadanief8290a2019-07-29 20:27:51531 bool to_different_document = !NavigationTypeUtils::IsSameDocument(
arthursonzogni92f18682017-02-08 23:00:04532 navigation_request_->common_params().navigation_type);
533
534 DidStartLoading(to_different_document, was_previously_loading);
clamydcb434c12015-04-16 19:29:16535}
536
Arthur Hemery241b9392019-10-24 11:08:41537void FrameTreeNode::ResetNavigationRequest(bool keep_state) {
fdegans39ff0382015-04-29 19:04:39538 if (!navigation_request_)
539 return;
John Abd-El-Malekdcc7bf42017-09-12 22:30:23540
Andrey Kosyakovf2d4ff72018-10-29 20:09:59541 devtools_instrumentation::OnResetNavigationRequest(navigation_request_.get());
clamydcb434c12015-04-16 19:29:16542 navigation_request_.reset();
fdegans39ff0382015-04-29 19:04:39543
clamy82a2f4d2016-02-02 14:20:41544 if (keep_state)
fdegans39ff0382015-04-29 19:04:39545 return;
546
clamy82a2f4d2016-02-02 14:20:41547 // The RenderFrameHostManager should clean up any speculative RenderFrameHost
548 // it created for the navigation. Also register that the load stopped.
fdegans39ff0382015-04-29 19:04:39549 DidStopLoading();
550 render_manager_.CleanUpNavigation();
clamydcb434c12015-04-16 19:29:16551}
552
clamy44e84ce2016-02-22 15:38:25553void FrameTreeNode::DidStartLoading(bool to_different_document,
554 bool was_previously_loading) {
Camille Lamyefd54b02018-10-04 16:54:14555 TRACE_EVENT2("navigation", "FrameTreeNode::DidStartLoading",
556 "frame_tree_node", frame_tree_node_id(), "to different document",
557 to_different_document);
fdegansa696e5112015-04-17 01:57:59558 // Any main frame load to a new document should reset the load progress since
559 // it will replace the current page and any frames. The WebContents will
560 // be notified when DidChangeLoadProgress is called.
561 if (to_different_document && IsMainFrame())
562 frame_tree_->ResetLoadProgress();
563
564 // Notify the WebContents.
clamy44e84ce2016-02-22 15:38:25565 if (!was_previously_loading)
Fergal Daly09d6c762020-05-29 02:05:18566 navigator().GetDelegate()->DidStartLoading(this, to_different_document);
fdegansa696e5112015-04-17 01:57:59567
568 // Set initial load progress and update overall progress. This will notify
569 // the WebContents of the load progress change.
570 DidChangeLoadProgress(kLoadingProgressMinimum);
571
572 // Notify the RenderFrameHostManager of the event.
573 render_manager()->OnDidStartLoading();
574}
575
576void FrameTreeNode::DidStopLoading() {
Camille Lamyefd54b02018-10-04 16:54:14577 TRACE_EVENT1("navigation", "FrameTreeNode::DidStopLoading", "frame_tree_node",
578 frame_tree_node_id());
fdegansa696e5112015-04-17 01:57:59579 // Set final load progress and update overall progress. This will notify
580 // the WebContents of the load progress change.
581 DidChangeLoadProgress(kLoadingProgressDone);
582
Lucas Furukawa Gadani6faef602019-05-06 21:16:03583 // Notify the RenderFrameHostManager of the event.
584 render_manager()->OnDidStopLoading();
585
fdegansa696e5112015-04-17 01:57:59586 // Notify the WebContents.
587 if (!frame_tree_->IsLoading())
Fergal Daly09d6c762020-05-29 02:05:18588 navigator().GetDelegate()->DidStopLoading();
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);
594 if (IsMainFrame())
595 frame_tree_->UpdateLoadProgress(load_progress);
fdegansa696e5112015-04-17 01:57:59596}
597
clamyf73862c42015-07-08 12:31:33598bool FrameTreeNode::StopLoading() {
arthursonzogni66f711c2019-10-08 14:40:36599 if (navigation_request_ && navigation_request_->IsNavigationStarted())
600 navigation_request_->set_net_error(net::ERR_ABORTED);
Arthur Hemery241b9392019-10-24 11:08:41601 ResetNavigationRequest(false);
clamyf73862c42015-07-08 12:31:33602
603 // TODO(nasko): see if child frames should send IPCs in site-per-process
604 // mode.
605 if (!IsMainFrame())
606 return true;
607
608 render_manager_.Stop();
609 return true;
610}
611
alexmos21acae52015-11-07 01:04:43612void FrameTreeNode::DidFocus() {
613 last_focus_time_ = base::TimeTicks::Now();
ericwilligers254597b2016-10-17 10:32:31614 for (auto& observer : observers_)
615 observer.OnFrameTreeNodeFocused(this);
alexmos21acae52015-11-07 01:04:43616}
617
clamy44e84ce2016-02-22 15:38:25618void FrameTreeNode::BeforeUnloadCanceled() {
619 // TODO(clamy): Support BeforeUnload in subframes.
620 if (!IsMainFrame())
621 return;
622
623 RenderFrameHostImpl* current_frame_host =
624 render_manager_.current_frame_host();
625 DCHECK(current_frame_host);
626 current_frame_host->ResetLoadingState();
627
clamy610c63b32017-12-22 15:05:18628 RenderFrameHostImpl* speculative_frame_host =
629 render_manager_.speculative_frame_host();
630 if (speculative_frame_host)
631 speculative_frame_host->ResetLoadingState();
632 // Note: there is no need to set an error code on the NavigationHandle here
633 // as it has not been created yet. It is only created when the
Antonio Gomes8678a202020-03-02 20:03:25634 // BeforeUnloadCompleted callback is invoked.
clamy610c63b32017-12-22 15:05:18635 if (navigation_request_)
Arthur Hemery241b9392019-10-24 11:08:41636 ResetNavigationRequest(false);
clamy44e84ce2016-02-22 15:38:25637}
638
Mustaq Ahmedecb5c38e2020-07-29 00:34:30639bool FrameTreeNode::NotifyUserActivation(
640 blink::mojom::UserActivationNotificationType notification_type) {
Alexander Timina1dfadaa2020-04-28 13:30:06641 for (RenderFrameHostImpl* rfh = current_frame_host(); rfh;
642 rfh = rfh->GetParent()) {
643 if (!rfh->frame_tree_node()->user_activation_state_.HasBeenActive())
644 rfh->DidReceiveFirstUserActivation();
Mustaq Ahmedecb5c38e2020-07-29 00:34:30645 rfh->frame_tree_node()->user_activation_state_.Activate(notification_type);
John Delaneyedd8d6c2019-01-25 00:23:57646 }
danakj359a4342020-05-29 20:38:39647 replication_state_.has_active_user_gesture = true;
Mustaq Ahmeda5dfa60b2018-12-08 00:30:14648
Mustaq Ahmed0180320f2019-03-21 16:07:01649 // See the "Same-origin Visibility" section in |UserActivationState| class
650 // doc.
Mustaq Ahmede5f12562019-10-30 18:02:03651 if (base::FeatureList::IsEnabled(
Mustaq Ahmeda5dfa60b2018-12-08 00:30:14652 features::kUserActivationSameOriginVisibility)) {
653 const url::Origin& current_origin =
654 this->current_frame_host()->GetLastCommittedOrigin();
655 for (FrameTreeNode* node : frame_tree()->Nodes()) {
656 if (node->current_frame_host()->GetLastCommittedOrigin().IsSameOriginWith(
657 current_origin)) {
Mustaq Ahmedecb5c38e2020-07-29 00:34:30658 node->user_activation_state_.Activate(notification_type);
Mustaq Ahmeda5dfa60b2018-12-08 00:30:14659 }
660 }
661 }
662
Shivani Sharma20749e922019-03-11 17:00:26663 NavigationControllerImpl* controller =
Fergal Daly09d6c762020-05-29 02:05:18664 static_cast<NavigationControllerImpl*>(navigator().GetController());
Shivani Sharma20749e922019-03-11 17:00:26665 if (controller)
666 controller->NotifyUserActivation();
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();
danakj359a4342020-05-29 20:38:39675 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();
danakj359a4342020-05-29 20:38:39682 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 {
719 // TODO(crbug.com/848778): We need to decide what to do when user
720 // activation verification failed. NOTREACHED here will make all
721 // 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);
Becca Hughes60af7d42017-12-12 10:53:15735 replication_state_.has_received_user_gesture_before_nav = value;
736}
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,
Ian Clellandedb8c5dd2018-03-01 17:01:37758 const blink::ParsedFeaturePolicy& parsed_header) {
759 bool changed = false;
760 if (replication_state_.feature_policy_header != parsed_header) {
761 replication_state_.feature_policy_header = parsed_header;
762 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;
Ian Clellandedb8c5dd2018-03-01 17:01:37768 if (replication_state_.active_sandbox_flags != updated_flags) {
769 replication_state_.active_sandbox_flags = updated_flags;
770 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
Ehsan Karamad39407082019-02-19 23:38:19791void FrameTreeNode::SetOpenerFeaturePolicyState(
Kent Tamura326c2db2020-07-20 06:28:05792 const blink::FeaturePolicyFeatureState& feature_state) {
Ehsan Karamad39407082019-02-19 23:38:19793 DCHECK(IsMainFrame());
794 if (base::FeatureList::IsEnabled(features::kFeaturePolicyForSandbox)) {
795 replication_state_.opener_feature_state = feature_state;
796 }
797}
798
Yao Xiao24ec9aa2020-01-28 16:36:00799void FrameTreeNode::SetAdFrameType(blink::mojom::AdFrameType ad_frame_type) {
800 DCHECK_NE(ad_frame_type, blink::mojom::AdFrameType::kNonAd);
801 if (replication_state_.ad_frame_type == blink::mojom::AdFrameType::kNonAd) {
802 replication_state_.ad_frame_type = ad_frame_type;
803 render_manager()->OnDidSetAdFrameType(ad_frame_type);
804 } else {
805 DCHECK_EQ(ad_frame_type, replication_state_.ad_frame_type);
806 }
807}
808
arthursonzogni034bb9c2020-10-01 08:29:56809void FrameTreeNode::SetInitialPopupURL(const GURL& initial_popup_url) {
810 DCHECK(initial_popup_url_.is_empty());
811 DCHECK(!has_committed_real_load_);
812 initial_popup_url_ = initial_popup_url;
813}
814
815void FrameTreeNode::SetPopupCreatorOrigin(
816 const url::Origin& popup_creator_origin) {
817 DCHECK(!has_committed_real_load_);
818 popup_creator_origin_ = popup_creator_origin;
819}
820
[email protected]9b159a52013-10-03 17:24:55821} // namespace content