blob: 686b7b64eec1b45de1161389721ce4348899767a [file] [log] [blame]
[email protected]d4a8ca482013-10-30 21:06:401// Copyright 2013 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
creis4e2ecb72015-06-20 00:46:305/*
6 * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
7 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved.
9 * (http://www.torchmobile.com/)
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 *
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
21 * its contributors may be used to endorse or promote products derived
22 * from this software without specific prior written permission.
23 *
24 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
25 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
28 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
33 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 */
35
danakjc492bf82020-09-09 20:02:4436#include "content/browser/renderer_host/navigation_controller_impl.h"
initial.commit09911bf2008-07-26 23:55:2937
Lei Zhang96031532019-10-10 19:05:4738#include <algorithm>
dcheng36b6aec92015-12-26 06:16:3639#include <utility>
40
[email protected]c5b88d82012-10-06 17:03:3341#include "base/bind.h"
[email protected]eabfe1912014-05-12 10:07:2842#include "base/command_line.h"
initial.commit09911bf2008-07-26 23:55:2943#include "base/logging.h"
asvitkine30330812016-08-30 04:01:0844#include "base/metrics/histogram_macros.h"
Chris Hamilton83272dc2021-02-23 00:24:0245#include "base/stl_util.h"
Peter Kastingb53b81912021-04-28 19:23:3046#include "base/strings/string_piece.h"
[email protected]348fbaac2013-06-11 06:31:5147#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0048#include "base/strings/utf_string_conversions.h"
[email protected]a43858f2013-06-28 15:18:3749#include "base/time/time.h"
Carlos Caballero40b0efd2021-01-26 11:55:0050#include "base/trace_event/optional_trace_event.h"
Carlos Caballeroede6f8c2021-01-28 11:01:5051#include "base/trace_event/trace_conversion_helper.h"
ssid3e765612015-01-28 04:03:4252#include "base/trace_event/trace_event.h"
servolkf3955532015-05-16 00:01:5953#include "build/build_config.h"
[email protected]eabfe1912014-05-12 10:07:2854#include "cc/base/switches.h"
jamescookda2505812015-03-20 18:01:1855#include "content/browser/bad_message.h"
Marijn Kruisselbrink0c87e6e2018-06-22 22:57:3956#include "content/browser/blob_storage/chrome_blob_storage_context.h"
[email protected]825b1662012-03-12 19:07:3157#include "content/browser/browser_url_handler_impl.h"
[email protected]5f2aa722013-08-07 16:59:4158#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0459#include "content/browser/dom_storage/session_storage_namespace_impl.h"
danakjc492bf82020-09-09 20:02:4460#include "content/browser/renderer_host/debug_urls.h"
61#include "content/browser/renderer_host/frame_tree.h"
Carlos Caballero40b0efd2021-01-26 11:55:0062#include "content/browser/renderer_host/frame_tree_node.h"
danakjc492bf82020-09-09 20:02:4463#include "content/browser/renderer_host/navigation_entry_impl.h"
Nate Chapin214a86a2021-06-21 20:35:5764#include "content/browser/renderer_host/navigation_entry_restore_context_impl.h"
danakjc492bf82020-09-09 20:02:4465#include "content/browser/renderer_host/navigation_request.h"
66#include "content/browser/renderer_host/navigator.h"
67#include "content/browser/renderer_host/render_frame_host_delegate.h"
Carlos Caballero40b0efd2021-01-26 11:55:0068#include "content/browser/renderer_host/render_view_host_impl.h"
Sharon Yangd70a5392021-10-26 23:06:3269#include "content/browser/site_info.h"
[email protected]b6583592012-01-25 19:52:3370#include "content/browser/site_instance_impl.h"
Kunihiko Sakamoto346a74e2021-03-10 08:57:4871#include "content/browser/web_package/subresource_web_bundle_navigation_info.h"
Tsuyoshi Horo37493af2019-11-21 23:43:1472#include "content/browser/web_package/web_bundle_navigation_info.h"
Camille Lamy5193caa2018-10-12 11:59:4273#include "content/common/content_constants_internal.h"
Nate Chapind1fe3612021-04-16 20:45:5774#include "content/common/navigation_params_utils.h"
Nasko Oskovae49e292020-08-13 02:08:5175#include "content/common/trace_utils.h"
[email protected]ccb797302011-12-15 16:55:1176#include "content/public/browser/browser_context.h"
[email protected]d1198fd2012-08-13 22:50:1977#include "content/public/browser/content_browser_client.h"
Fergal Daly1336ac642021-09-14 15:13:1178#include "content/public/browser/disallow_activation_reason.h"
[email protected]d9083482012-01-06 00:38:4679#include "content/public/browser/invalidate_type.h"
[email protected]5b96836f2011-12-22 07:39:0080#include "content/public/browser/navigation_details.h"
[email protected]7f6f44c2011-12-14 13:23:3881#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1682#include "content/public/browser/notification_types.h"
Lei Zhang96031532019-10-10 19:05:4783#include "content/public/browser/render_view_host.h"
[email protected]9677a3c2012-12-22 04:18:5884#include "content/public/browser/render_widget_host.h"
85#include "content/public/browser/render_widget_host_view.h"
Mikel Astizba9cf2fd2017-12-17 10:38:1086#include "content/public/browser/replaced_navigation_entry_data.h"
[email protected]4c3a23582012-08-18 08:54:3487#include "content/public/browser/storage_partition.h"
[email protected]d1198fd2012-08-13 22:50:1988#include "content/public/common/content_client.h"
[email protected]7f6f44c2011-12-14 13:23:3889#include "content/public/common/content_constants.h"
toyoshim86e34ec2016-02-25 08:56:1090#include "content/public/common/content_features.h"
Lei Zhang96031532019-10-10 19:05:4791#include "content/public/common/url_constants.h"
clamy7fced7b2017-11-16 19:52:4392#include "content/public/common/url_utils.h"
servolkf3955532015-05-16 00:01:5993#include "media/base/mime_util.h"
[email protected]a23de8572009-06-03 02:16:3294#include "net/base/escape.h"
Arthur Sonzogni620cec62018-12-13 13:08:5795#include "net/http/http_status_code.h"
Shivani Sharma93329102019-01-24 19:44:1896#include "services/metrics/public/cpp/ukm_builders.h"
97#include "services/metrics/public/cpp/ukm_recorder.h"
Yue Ru Sun128804932020-09-30 22:19:1798#include "services/metrics/public/cpp/ukm_source_id.h"
Nan Lind91c8152021-10-21 16:22:3799#include "services/network/public/mojom/fetch_api.mojom.h"
[email protected]9677a3c2012-12-22 04:18:58100#include "skia/ext/platform_canvas.h"
Marijn Kruisselbrink0c87e6e2018-06-22 22:57:39101#include "third_party/blink/public/common/blob/blob_utils.h"
Gyuyoung Kim107c2a02021-04-13 01:49:30102#include "third_party/blink/public/common/chrome_debug_urls.h"
Miyoung Shin1c565c912021-03-17 12:11:21103#include "third_party/blink/public/common/history/session_history_constants.h"
Blink Reformata30d4232018-04-07 15:31:06104#include "third_party/blink/public/common/mime_util/mime_util.h"
Minggang Wanga13c796e2021-07-02 05:54:43105#include "third_party/blink/public/common/navigation/navigation_params.h"
Carlos Caballeroede6f8c2021-01-28 11:01:50106#include "third_party/blink/public/common/page_state/page_state_serialization.h"
Minggang Wangb9f3fa92021-07-01 15:30:31107#include "third_party/blink/public/mojom/navigation/navigation_params.mojom.h"
Minggang Wang7ee0c742021-06-16 16:16:51108#include "third_party/blink/public/mojom/navigation/prefetched_signed_exchange_info.mojom.h"
[email protected]cca6f392014-05-28 21:32:26109#include "url/url_constants.h"
initial.commit09911bf2008-07-26 23:55:29110
[email protected]8ff00d72012-10-23 19:12:21111namespace content {
[email protected]e9ba4472008-09-14 15:42:43112namespace {
113
114// Invoked when entries have been pruned, or removed. For example, if the
115// current entries are [google, digg, yahoo], with the current entry google,
116// and the user types in cnet, then digg and yahoo are pruned.
[email protected]d202a7c2012-01-04 07:53:47117void NotifyPrunedEntries(NavigationControllerImpl* nav_controller,
Shivani Sharmab9c46de82019-02-08 16:54:50118 int index,
[email protected]c12bf1a12008-09-17 16:28:49119 int count) {
[email protected]8ff00d72012-10-23 19:12:21120 PrunedDetails details;
Shivani Sharmab9c46de82019-02-08 16:54:50121 details.index = index;
[email protected]c12bf1a12008-09-17 16:28:49122 details.count = count;
Sam McNally5c087a32017-08-25 01:46:14123 nav_controller->delegate()->NotifyNavigationListPruned(details);
[email protected]e9ba4472008-09-14 15:42:43124}
125
[email protected]e9ba4472008-09-14 15:42:43126// Configure all the NavigationEntries in entries for restore. This resets
127// the transition type to reload and makes sure the content state isn't empty.
128void ConfigureEntriesForRestore(
dcheng9bfa5162016-04-09 01:00:57129 std::vector<std::unique_ptr<NavigationEntryImpl>>* entries,
toyoshim0df1d3a2016-09-09 09:52:48130 RestoreType type) {
Lei Zhang96031532019-10-10 19:05:47131 for (auto& entry : *entries) {
[email protected]e9ba4472008-09-14 15:42:43132 // Use a transition type of reload so that we don't incorrectly increase
133 // the typed count.
Lei Zhang96031532019-10-10 19:05:47134 entry->SetTransitionType(ui::PAGE_TRANSITION_RELOAD);
135 entry->set_restore_type(type);
[email protected]e9ba4472008-09-14 15:42:43136 }
137}
138
[email protected]bf70edce2012-06-20 22:32:22139// Determines whether or not we should be carrying over a user agent override
140// between two NavigationEntries.
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57141bool ShouldKeepOverride(NavigationEntry* last_entry) {
[email protected]bf70edce2012-06-20 22:32:22142 return last_entry && last_entry->GetIsOverridingUserAgent();
143}
144
Camille Lamy5193caa2018-10-12 11:59:42145// Determines whether to override user agent for a navigation.
146bool ShouldOverrideUserAgent(
147 NavigationController::UserAgentOverrideOption override_user_agent,
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57148 NavigationEntry* last_committed_entry) {
Camille Lamy5193caa2018-10-12 11:59:42149 switch (override_user_agent) {
150 case NavigationController::UA_OVERRIDE_INHERIT:
151 return ShouldKeepOverride(last_committed_entry);
152 case NavigationController::UA_OVERRIDE_TRUE:
153 return true;
154 case NavigationController::UA_OVERRIDE_FALSE:
155 return false;
Camille Lamy5193caa2018-10-12 11:59:42156 }
157 NOTREACHED();
158 return false;
159}
160
Rakina Zata Amni312822d72021-06-04 16:13:37161// Returns true if this navigation should be treated as a reload. For e.g.
clamy0a656e42018-02-06 18:18:28162// navigating to the last committed url via the address bar or clicking on a
Rakina Zata Amni312822d72021-06-04 16:13:37163// link which results in a navigation to the last committed URL (but wasn't
164// converted to do a replacement navigation in the renderer), etc.
Fergal Daly766177d2020-07-07 07:54:04165// |node| is the FrameTreeNode which is navigating. |url|, |virtual_url|,
166// |base_url_for_data_url|, |transition_type| correspond to the new navigation
167// (i.e. the pending NavigationEntry). |last_committed_entry| is the last
168// navigation that committed.
169bool ShouldTreatNavigationAsReload(FrameTreeNode* node,
170 const GURL& url,
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57171 const GURL& virtual_url,
172 const GURL& base_url_for_data_url,
173 ui::PageTransition transition_type,
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57174 bool is_post,
Rakina Zata Amni312822d72021-06-04 16:13:37175 bool should_replace_current_entry,
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57176 NavigationEntryImpl* last_committed_entry) {
Rakina Zata Amni312822d72021-06-04 16:13:37177 // Navigations intended to do a replacement shouldn't be converted to do a
178 // reload.
179 if (should_replace_current_entry)
clamy0a656e42018-02-06 18:18:28180 return false;
clamy0a656e42018-02-06 18:18:28181 // Only convert to reload if at least one navigation committed.
Rakina Zata Amniafd3c6582021-11-30 06:19:17182 if (last_committed_entry->IsInitialEntry())
ananta3bdd8ae2016-12-22 17:11:55183 return false;
184
arthursonzogni7a8243682017-12-14 16:41:42185 // Skip navigations initiated by external applications.
clamy0a656e42018-02-06 18:18:28186 if (transition_type & ui::PAGE_TRANSITION_FROM_API)
arthursonzogni7a8243682017-12-14 16:41:42187 return false;
188
ananta3bdd8ae2016-12-22 17:11:55189 // We treat (PAGE_TRANSITION_RELOAD | PAGE_TRANSITION_FROM_ADDRESS_BAR),
190 // PAGE_TRANSITION_TYPED or PAGE_TRANSITION_LINK transitions as navigations
191 // which should be treated as reloads.
clamy0a656e42018-02-06 18:18:28192 bool transition_type_can_be_converted = false;
193 if (ui::PageTransitionCoreTypeIs(transition_type,
194 ui::PAGE_TRANSITION_RELOAD) &&
195 (transition_type & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR)) {
196 transition_type_can_be_converted = true;
ananta3bdd8ae2016-12-22 17:11:55197 }
clamy0a656e42018-02-06 18:18:28198 if (ui::PageTransitionCoreTypeIs(transition_type,
ananta3bdd8ae2016-12-22 17:11:55199 ui::PAGE_TRANSITION_TYPED)) {
clamy0a656e42018-02-06 18:18:28200 transition_type_can_be_converted = true;
201 }
202 if (ui::PageTransitionCoreTypeIs(transition_type, ui::PAGE_TRANSITION_LINK))
203 transition_type_can_be_converted = true;
204 if (!transition_type_can_be_converted)
205 return false;
206
207 // This check is required for cases like view-source:, etc. Here the URL of
208 // the navigation entry would contain the url of the page, while the virtual
209 // URL contains the full URL including the view-source prefix.
210 if (virtual_url != last_committed_entry->GetVirtualURL())
211 return false;
212
Fergal Daly766177d2020-07-07 07:54:04213 // Check that the URLs match.
214 FrameNavigationEntry* frame_entry = last_committed_entry->GetFrameEntry(node);
215 // If there's no frame entry then by definition the URLs don't match.
216 if (!frame_entry)
217 return false;
218
219 if (url != frame_entry->url())
clamy0a656e42018-02-06 18:18:28220 return false;
221
222 // This check is required for Android WebView loadDataWithBaseURL. Apps
223 // can pass in anything in the base URL and we need to ensure that these
224 // match before classifying it as a reload.
225 if (url.SchemeIs(url::kDataScheme) && base_url_for_data_url.is_valid()) {
226 if (base_url_for_data_url != last_committed_entry->GetBaseURLForDataURL())
227 return false;
ananta3bdd8ae2016-12-22 17:11:55228 }
229
clamy0a656e42018-02-06 18:18:28230 // Skip entries with SSL errors.
231 if (last_committed_entry->ssl_error())
232 return false;
233
234 // Don't convert to a reload when the last navigation was a POST or the new
235 // navigation is a POST.
Fergal Daly766177d2020-07-07 07:54:04236 if (frame_entry->get_has_post_data() || is_post)
clamy0a656e42018-02-06 18:18:28237 return false;
238
239 return true;
ananta3bdd8ae2016-12-22 17:11:55240}
241
Nasko Oskov03912102019-01-11 00:21:32242bool DoesURLMatchOriginForNavigation(
243 const GURL& url,
Anton Bikineevf62d1bf2021-05-15 17:56:07244 const absl::optional<url::Origin>& origin,
Kunihiko Sakamoto346a74e2021-03-10 08:57:48245 SubresourceWebBundleNavigationInfo*
246 subresource_web_bundle_navigation_info) {
Nasko Oskov03912102019-01-11 00:21:32247 // If there is no origin supplied there is nothing to match. This can happen
248 // for navigations to a pending entry and therefore it should be allowed.
249 if (!origin)
250 return true;
251
Kunihiko Sakamoto260ee0a2021-10-15 01:44:08252 // Urn: and uuid-in-package: subframe from WebBundle has an opaque origin
253 // derived from the Bundle's origin.
254 // TODO(https://crbug.com/1257045): Remove urn: scheme support.
255 if ((url.SchemeIs(url::kUrnScheme) ||
256 url.SchemeIs(url::kUuidInPackageScheme)) &&
257 subresource_web_bundle_navigation_info) {
Kunihiko Sakamoto346a74e2021-03-10 08:57:48258 return origin->CanBeDerivedFrom(
259 subresource_web_bundle_navigation_info->bundle_url());
260 }
261
Nasko Oskov03912102019-01-11 00:21:32262 return origin->CanBeDerivedFrom(url);
263}
264
Anton Bikineevf62d1bf2021-05-15 17:56:07265absl::optional<url::Origin> GetCommittedOriginForFrameEntry(
Rakina Zata Amni3a1c0ec2021-04-15 03:35:12266 const mojom::DidCommitProvisionalLoadParams& params,
267 NavigationRequest* request) {
Nasko Oskov03912102019-01-11 00:21:32268 // Error pages commit in an opaque origin, yet have the real URL that resulted
269 // in an error as the |params.url|. Since successful reload of an error page
270 // should commit in the correct origin, setting the opaque origin on the
271 // FrameNavigationEntry will be incorrect.
Rakina Zata Amniafd3c6582021-11-30 06:19:17272 if (request && request->DidEncounterError())
Anton Bikineevf62d1bf2021-05-15 17:56:07273 return absl::nullopt;
Nasko Oskov03912102019-01-11 00:21:32274
Rakina Zata Amni3a1c0ec2021-04-15 03:35:12275 // We also currently don't save committed origins for loadDataWithBaseURL
276 // navigations (probably accidentally). Without this check, navigations to
277 // the FrameNavigationEntry might fail the DoesURLMatchOriginForNavigation()
278 // check since the origin will be based on the base URL instead of the data:
279 // URL used for the navigation.
280 // TODO(https://crbug.com/1198406): Save committed origin in
281 // FrameNavigationEntry for this case too.
Rakina Zata Amniafd3c6582021-11-30 06:19:17282 if (request && request->IsLoadDataWithBaseURL())
Anton Bikineevf62d1bf2021-05-15 17:56:07283 return absl::nullopt;
Rakina Zata Amni3a1c0ec2021-04-15 03:35:12284
Anton Bikineevf62d1bf2021-05-15 17:56:07285 return absl::make_optional(params.origin);
Nasko Oskov03912102019-01-11 00:21:32286}
287
Camille Lamy5193caa2018-10-12 11:59:42288bool IsValidURLForNavigation(bool is_main_frame,
289 const GURL& virtual_url,
290 const GURL& dest_url) {
291 // Don't attempt to navigate if the virtual URL is non-empty and invalid.
292 if (is_main_frame && !virtual_url.is_valid() && !virtual_url.is_empty()) {
293 LOG(WARNING) << "Refusing to load for invalid virtual URL: "
294 << virtual_url.possibly_invalid_spec();
295 return false;
296 }
297
298 // Don't attempt to navigate to non-empty invalid URLs.
299 if (!dest_url.is_valid() && !dest_url.is_empty()) {
300 LOG(WARNING) << "Refusing to load invalid URL: "
301 << dest_url.possibly_invalid_spec();
302 return false;
303 }
304
305 // The renderer will reject IPC messages with URLs longer than
306 // this limit, so don't attempt to navigate with a longer URL.
307 if (dest_url.spec().size() > url::kMaxURLChars) {
308 LOG(WARNING) << "Refusing to load URL as it exceeds " << url::kMaxURLChars
309 << " characters.";
310 return false;
311 }
312
Aaron Colwell33109c592020-04-21 21:31:19313 // Reject renderer debug URLs because they should have been handled before
314 // we get to this point. This check handles renderer debug URLs
315 // that are inside a view-source: URL (e.g. view-source:chrome://kill) and
316 // provides defense-in-depth if a renderer debug URL manages to get here via
317 // some other path. We want to reject the navigation here so it doesn't
318 // violate assumptions in downstream code.
Gyuyoung Kim107c2a02021-04-13 01:49:30319 if (blink::IsRendererDebugURL(dest_url)) {
Aaron Colwell33109c592020-04-21 21:31:19320 LOG(WARNING) << "Refusing to load renderer debug URL: "
321 << dest_url.possibly_invalid_spec();
322 return false;
323 }
324
Camille Lamy5193caa2018-10-12 11:59:42325 return true;
326}
327
Mikel Astizba9cf2fd2017-12-17 10:38:10328// See replaced_navigation_entry_data.h for details: this information is meant
329// to ensure |*output_entry| keeps track of its original URL (landing page in
330// case of server redirects) as it gets replaced (e.g. history.replaceState()),
331// without overwriting it later, for main frames.
332void CopyReplacedNavigationEntryDataIfPreviouslyEmpty(
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57333 NavigationEntryImpl* replaced_entry,
Mikel Astizba9cf2fd2017-12-17 10:38:10334 NavigationEntryImpl* output_entry) {
Rakina Zata Amniafd3c6582021-11-30 06:19:17335 if (output_entry->GetReplacedEntryData().has_value() ||
336 replaced_entry->IsInitialEntry()) {
Mikel Astizba9cf2fd2017-12-17 10:38:10337 return;
Rakina Zata Amniafd3c6582021-11-30 06:19:17338 }
Mikel Astizba9cf2fd2017-12-17 10:38:10339
340 ReplacedNavigationEntryData data;
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57341 data.first_committed_url = replaced_entry->GetURL();
342 data.first_timestamp = replaced_entry->GetTimestamp();
343 data.first_transition_type = replaced_entry->GetTransitionType();
Charlie Reisb55438f2019-01-08 01:54:29344 output_entry->set_replaced_entry_data(data);
Mikel Astizba9cf2fd2017-12-17 10:38:10345}
346
Minggang Wangb9f3fa92021-07-01 15:30:31347blink::mojom::NavigationType GetNavigationType(
348 const GURL& old_url,
349 const GURL& new_url,
350 ReloadType reload_type,
351 NavigationEntryImpl* entry,
352 const FrameNavigationEntry& frame_entry,
353 bool has_pending_cross_document_commit,
354 bool is_currently_error_page,
355 bool is_same_document_history_load) {
clamyea99ea12018-05-28 13:54:23356 // Reload navigations
357 switch (reload_type) {
358 case ReloadType::NORMAL:
Minggang Wangb9f3fa92021-07-01 15:30:31359 return blink::mojom::NavigationType::RELOAD;
clamyea99ea12018-05-28 13:54:23360 case ReloadType::BYPASSING_CACHE:
Minggang Wangb9f3fa92021-07-01 15:30:31361 return blink::mojom::NavigationType::RELOAD_BYPASSING_CACHE;
clamyea99ea12018-05-28 13:54:23362 case ReloadType::ORIGINAL_REQUEST_URL:
Minggang Wangb9f3fa92021-07-01 15:30:31363 return blink::mojom::NavigationType::RELOAD_ORIGINAL_REQUEST_URL;
clamyea99ea12018-05-28 13:54:23364 case ReloadType::NONE:
365 break; // Fall through to rest of function.
366 }
367
Lukasz Anforowicz6b75c0d2020-12-01 22:56:08368 if (entry->IsRestored()) {
Minggang Wangb9f3fa92021-07-01 15:30:31369 return entry->GetHasPostData()
370 ? blink::mojom::NavigationType::RESTORE_WITH_POST
371 : blink::mojom::NavigationType::RESTORE;
clamyea99ea12018-05-28 13:54:23372 }
373
danakjb952ef12021-01-14 19:58:49374 const bool can_be_same_document =
375 // A pending cross-document commit means this navigation will not occur in
376 // the current document, as that document would end up being replaced in
377 // the meantime.
378 !has_pending_cross_document_commit &&
379 // If the current document is an error page, we should always treat it as
380 // a different-document navigation so that we'll attempt to load the
381 // document we're navigating to (and not stay in the current error page).
382 !is_currently_error_page;
danakjd83d706d2020-11-25 22:11:12383
clamyea99ea12018-05-28 13:54:23384 // History navigations.
385 if (frame_entry.page_state().IsValid()) {
danakjd83d706d2020-11-25 22:11:12386 return can_be_same_document && is_same_document_history_load
Minggang Wangb9f3fa92021-07-01 15:30:31387 ? blink::mojom::NavigationType::HISTORY_SAME_DOCUMENT
388 : blink::mojom::NavigationType::HISTORY_DIFFERENT_DOCUMENT;
clamyea99ea12018-05-28 13:54:23389 }
390 DCHECK(!is_same_document_history_load);
391
392 // A same-document fragment-navigation happens when the only part of the url
393 // that is modified is after the '#' character.
394 //
395 // When modifying this condition, please take a look at:
danakjd83d706d2020-11-25 22:11:12396 // FrameLoader::ShouldPerformFragmentNavigation().
clamyea99ea12018-05-28 13:54:23397 //
398 // Note: this check is only valid for navigations that are not history
399 // navigations. For instance, if the history is: 'A#bar' -> 'B' -> 'A#foo', a
400 // history navigation from 'A#foo' to 'A#bar' is not a same-document
401 // navigation, but a different-document one. This is why history navigation
402 // are classified before this check.
Lei Zhang96031532019-10-10 19:05:47403 bool is_same_doc = new_url.has_ref() && old_url.EqualsIgnoringRef(new_url) &&
404 frame_entry.method() == "GET";
danakjd83d706d2020-11-25 22:11:12405
406 // The one case where we do the wrong thing here and incorrectly choose
407 // SAME_DOCUMENT is if the navigation is browser-initiated but the document in
408 // the renderer is a frameset. All frameset navigations should be
409 // DIFFERENT_DOCUMENT, even if their URLs match. A renderer-initiated
410 // navigation would do the right thing, as it would send it to the browser and
411 // all renderer-initiated navigations are DIFFERENT_DOCUMENT (they don't get
412 // into this method). But since we can't tell that case here for browser-
413 // initiated navigations, we have to get the renderer involved. In that case
414 // the navigation would be restarted due to the renderer spending a reply of
415 // mojom::CommitResult::RestartCrossDocument.
416
417 return can_be_same_document && is_same_doc
Minggang Wangb9f3fa92021-07-01 15:30:31418 ? blink::mojom::NavigationType::SAME_DOCUMENT
419 : blink::mojom::NavigationType::DIFFERENT_DOCUMENT;
clamyea99ea12018-05-28 13:54:23420}
421
Camille Lamy5193caa2018-10-12 11:59:42422// Adjusts the original input URL if needed, to get the URL to actually load and
423// the virtual URL, which may differ.
424void RewriteUrlForNavigation(const GURL& original_url,
425 BrowserContext* browser_context,
426 GURL* url_to_load,
427 GURL* virtual_url,
428 bool* reverse_on_redirect) {
Camille Lamy5193caa2018-10-12 11:59:42429 // Allow the browser URL handler to rewrite the URL. This will, for example,
430 // remove "view-source:" from the beginning of the URL to get the URL that
431 // will actually be loaded. This real URL won't be shown to the user, just
432 // used internally.
Lukasz Anforowicz7b078792020-10-20 17:04:31433 *url_to_load = *virtual_url = original_url;
Camille Lamy5193caa2018-10-12 11:59:42434 BrowserURLHandlerImpl::GetInstance()->RewriteURLIfNecessary(
435 url_to_load, browser_context, reverse_on_redirect);
436}
437
438#if DCHECK_IS_ON()
439// Helper sanity check function used in debug mode.
440void ValidateRequestMatchesEntry(NavigationRequest* request,
441 NavigationEntryImpl* entry) {
442 if (request->frame_tree_node()->IsMainFrame()) {
443 DCHECK_EQ(request->browser_initiated(), !entry->is_renderer_initiated());
444 DCHECK(ui::PageTransitionTypeIncludingQualifiersIs(
Minggang Wangb9f3fa92021-07-01 15:30:31445 ui::PageTransitionFromInt(request->common_params().transition),
446 entry->GetTransitionType()));
Camille Lamy5193caa2018-10-12 11:59:42447 }
Nasko Oskovc36327d2019-01-03 23:23:04448 DCHECK_EQ(request->commit_params().should_clear_history_list,
Camille Lamy5193caa2018-10-12 11:59:42449 entry->should_clear_history_list());
450 DCHECK_EQ(request->common_params().has_user_gesture,
451 entry->has_user_gesture());
452 DCHECK_EQ(request->common_params().base_url_for_data_url,
453 entry->GetBaseURLForDataURL());
Nasko Oskovc36327d2019-01-03 23:23:04454 DCHECK_EQ(request->commit_params().can_load_local_resources,
Camille Lamy5193caa2018-10-12 11:59:42455 entry->GetCanLoadLocalResources());
456 DCHECK_EQ(request->common_params().started_from_context_menu,
457 entry->has_started_from_context_menu());
458
459 FrameNavigationEntry* frame_entry =
460 entry->GetFrameEntry(request->frame_tree_node());
461 if (!frame_entry) {
462 NOTREACHED();
463 return;
464 }
465
Camille Lamy5193caa2018-10-12 11:59:42466 DCHECK_EQ(request->common_params().method, frame_entry->method());
467
Nasko Oskovc36327d2019-01-03 23:23:04468 size_t redirect_size = request->commit_params().redirects.size();
Camille Lamy5193caa2018-10-12 11:59:42469 if (redirect_size == frame_entry->redirect_chain().size()) {
470 for (size_t i = 0; i < redirect_size; ++i) {
Nasko Oskovc36327d2019-01-03 23:23:04471 DCHECK_EQ(request->commit_params().redirects[i],
Camille Lamy5193caa2018-10-12 11:59:42472 frame_entry->redirect_chain()[i]);
473 }
474 } else {
475 NOTREACHED();
476 }
477}
478#endif // DCHECK_IS_ON()
479
Dave Tapuska8bfd84c2019-03-26 20:47:16480// Returns whether the session history NavigationRequests in |navigations|
481// would stay within the subtree of the sandboxed iframe in
482// |sandbox_frame_tree_node_id|.
483bool DoesSandboxNavigationStayWithinSubtree(
484 int sandbox_frame_tree_node_id,
485 const std::vector<std::unique_ptr<NavigationRequest>>& navigations) {
486 for (auto& item : navigations) {
487 bool within_subtree = false;
488 // Check whether this NavigationRequest affects a frame within the
489 // sandboxed frame's subtree by walking up the tree looking for the
490 // sandboxed frame.
491 for (auto* frame = item->frame_tree_node(); frame;
Alexander Timin381e7e182020-04-28 19:04:03492 frame = FrameTreeNode::From(frame->parent())) {
Dave Tapuska8bfd84c2019-03-26 20:47:16493 if (frame->frame_tree_node_id() == sandbox_frame_tree_node_id) {
494 within_subtree = true;
495 break;
496 }
497 }
498 if (!within_subtree)
499 return false;
500 }
501 return true;
502}
503
[email protected]e9ba4472008-09-14 15:42:43504} // namespace
505
arthursonzogni66f711c2019-10-08 14:40:36506// NavigationControllerImpl::PendingEntryRef------------------------------------
507
508NavigationControllerImpl::PendingEntryRef::PendingEntryRef(
509 base::WeakPtr<NavigationControllerImpl> controller)
510 : controller_(controller) {}
511
512NavigationControllerImpl::PendingEntryRef::~PendingEntryRef() {
513 if (!controller_) // Can be null with interstitials.
514 return;
515
516 controller_->PendingEntryRefDeleted(this);
517}
518
[email protected]d202a7c2012-01-04 07:53:47519// NavigationControllerImpl ----------------------------------------------------
initial.commit09911bf2008-07-26 23:55:29520
[email protected]23a918b2014-07-15 09:51:36521const size_t kMaxEntryCountForTestingNotSet = static_cast<size_t>(-1);
[email protected]9b51970d2011-12-09 23:10:23522
[email protected]765b35502008-08-21 00:51:20523// static
[email protected]d202a7c2012-01-04 07:53:47524size_t NavigationControllerImpl::max_entry_count_for_testing_ =
[email protected]9b51970d2011-12-09 23:10:23525 kMaxEntryCountForTestingNotSet;
[email protected]765b35502008-08-21 00:51:20526
[email protected]e6fec472013-05-14 05:29:02527// Should Reload check for post data? The default is true, but is set to false
[email protected]cdcb1dee2012-01-04 00:46:20528// when testing.
529static bool g_check_for_repost = true;
initial.commit09911bf2008-07-26 23:55:29530
[email protected]71fde352011-12-29 03:29:56531// static
dcheng9bfa5162016-04-09 01:00:57532std::unique_ptr<NavigationEntry> NavigationController::CreateNavigationEntry(
533 const GURL& url,
Lukasz Anforowicz641234d52019-11-07 21:07:10534 Referrer referrer,
Anton Bikineevf62d1bf2021-05-15 17:56:07535 absl::optional<url::Origin> initiator_origin,
Lukasz Anforowicz641234d52019-11-07 21:07:10536 ui::PageTransition transition,
537 bool is_renderer_initiated,
538 const std::string& extra_headers,
539 BrowserContext* browser_context,
540 scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory) {
541 return NavigationControllerImpl::CreateNavigationEntry(
542 url, referrer, std::move(initiator_origin),
543 nullptr /* source_site_instance */, transition, is_renderer_initiated,
Hayato Ito303654c2021-06-30 09:07:54544 extra_headers, browser_context, std::move(blob_url_loader_factory));
Lukasz Anforowicz641234d52019-11-07 21:07:10545}
546
547// static
548std::unique_ptr<NavigationEntryImpl>
549NavigationControllerImpl::CreateNavigationEntry(
550 const GURL& url,
551 Referrer referrer,
Anton Bikineevf62d1bf2021-05-15 17:56:07552 absl::optional<url::Origin> initiator_origin,
Lukasz Anforowicz641234d52019-11-07 21:07:10553 SiteInstance* source_site_instance,
dcheng9bfa5162016-04-09 01:00:57554 ui::PageTransition transition,
555 bool is_renderer_initiated,
556 const std::string& extra_headers,
Marijn Kruisselbrink7a0d5e182018-05-24 22:55:09557 BrowserContext* browser_context,
Hayato Ito303654c2021-06-30 09:07:54558 scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory) {
Camille Lamy5193caa2018-10-12 11:59:42559 GURL url_to_load;
560 GURL virtual_url;
[email protected]71fde352011-12-29 03:29:56561 bool reverse_on_redirect = false;
Camille Lamy5193caa2018-10-12 11:59:42562 RewriteUrlForNavigation(url, browser_context, &url_to_load, &virtual_url,
563 &reverse_on_redirect);
[email protected]71fde352011-12-29 03:29:56564
Lukasz Anforowicz641234d52019-11-07 21:07:10565 // Let the NTP override the navigation params and pretend that this is a
566 // browser-initiated, bookmark-like navigation.
567 GetContentClient()->browser()->OverrideNavigationParams(
Scott Violetcf6ea7e2021-06-09 21:09:21568 source_site_instance, &transition, &is_renderer_initiated, &referrer,
569 &initiator_origin);
Lukasz Anforowicz641234d52019-11-07 21:07:10570
Patrick Monettef507e982019-06-19 20:18:06571 auto entry = std::make_unique<NavigationEntryImpl>(
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28572 nullptr, // The site instance for tabs is sent on navigation
573 // (WebContents::GetSiteInstance).
Jan Wilken Dörrieaace0cfef2021-03-11 22:01:58574 url_to_load, referrer, initiator_origin, std::u16string(), transition,
Rakina Zata Amniafd3c6582021-11-30 06:19:17575 is_renderer_initiated, blob_url_loader_factory,
576 /* is_initial_entry = */ false);
Camille Lamy5193caa2018-10-12 11:59:42577 entry->SetVirtualURL(virtual_url);
578 entry->set_user_typed_url(virtual_url);
[email protected]71fde352011-12-29 03:29:56579 entry->set_update_virtual_url_with_url(reverse_on_redirect);
580 entry->set_extra_headers(extra_headers);
Patrick Monettef507e982019-06-19 20:18:06581 return entry;
[email protected]71fde352011-12-29 03:29:56582}
583
[email protected]cdcb1dee2012-01-04 00:46:20584// static
585void NavigationController::DisablePromptOnRepost() {
586 g_check_for_repost = false;
587}
588
[email protected]c5b88d82012-10-06 17:03:33589base::Time NavigationControllerImpl::TimeSmoother::GetSmoothedTime(
590 base::Time t) {
591 // If |t| is between the water marks, we're in a run of duplicates
592 // or just getting out of it, so increase the high-water mark to get
593 // a time that probably hasn't been used before and return it.
594 if (low_water_mark_ <= t && t <= high_water_mark_) {
Peter Kastinge5a38ed2021-10-02 03:06:35595 high_water_mark_ += base::Microseconds(1);
[email protected]c5b88d82012-10-06 17:03:33596 return high_water_mark_;
597 }
598
599 // Otherwise, we're clear of the last duplicate run, so reset the
600 // water marks.
601 low_water_mark_ = high_water_mark_ = t;
602 return t;
603}
604
ckitagawa0faa5e42020-06-17 17:30:54605NavigationControllerImpl::ScopedShowRepostDialogForTesting::
606 ScopedShowRepostDialogForTesting()
607 : was_disallowed_(g_check_for_repost) {
608 g_check_for_repost = true;
609}
610
611NavigationControllerImpl::ScopedShowRepostDialogForTesting::
612 ~ScopedShowRepostDialogForTesting() {
613 g_check_for_repost = was_disallowed_;
614}
615
[email protected]d202a7c2012-01-04 07:53:47616NavigationControllerImpl::NavigationControllerImpl(
Carlos Caballero40b0efd2021-01-26 11:55:00617 BrowserContext* browser_context,
618 FrameTree& frame_tree,
619 NavigationControllerDelegate* delegate)
620 : frame_tree_(frame_tree),
621 browser_context_(browser_context),
[email protected]ec6c05f2013-10-23 18:41:57622 delegate_(delegate),
[email protected]69e797f2013-04-30 01:10:22623 ssl_manager_(this),
Lei Zhang96031532019-10-10 19:05:47624 get_timestamp_callback_(base::BindRepeating(&base::Time::Now)) {
[email protected]3d7474ff2011-07-27 17:47:37625 DCHECK(browser_context_);
initial.commit09911bf2008-07-26 23:55:29626}
627
[email protected]d202a7c2012-01-04 07:53:47628NavigationControllerImpl::~NavigationControllerImpl() {
arthursonzogni69a6a1b2019-09-17 09:23:00629 // The NavigationControllerImpl might be called inside its delegate
630 // destructor. Calling it is not valid anymore.
631 delegate_ = nullptr;
632 DiscardNonCommittedEntries();
initial.commit09911bf2008-07-26 23:55:29633}
634
Matt Falkenhagen548ed1562021-07-06 01:38:26635WebContents* NavigationControllerImpl::DeprecatedGetWebContents() {
636 return delegate_->DeprecatedGetWebContents();
[email protected]fbc5e5f92012-01-02 06:08:32637}
638
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57639BrowserContext* NavigationControllerImpl::GetBrowserContext() {
[email protected]a26023822011-12-29 00:23:55640 return browser_context_;
641}
642
[email protected]d202a7c2012-01-04 07:53:47643void NavigationControllerImpl::Restore(
[email protected]5e369672009-11-03 23:48:30644 int selected_navigation,
[email protected]2ca1ea662012-10-04 02:26:36645 RestoreType type,
dcheng9bfa5162016-04-09 01:00:57646 std::vector<std::unique_ptr<NavigationEntry>>* entries) {
[email protected]ce3fa3c2009-04-20 19:55:57647 // Verify that this controller is unused and that the input is valid.
Rakina Zata Amniafd3c6582021-11-30 06:19:17648 DCHECK_EQ(1, GetEntryCount());
649 DCHECK(GetLastCommittedEntry()->IsInitialEntry());
Lei Zhang96031532019-10-10 19:05:47650 DCHECK(!GetPendingEntry());
[email protected]ce3fa3c2009-04-20 19:55:57651 DCHECK(selected_navigation >= 0 &&
[email protected]03838e22011-06-06 15:27:14652 selected_navigation < static_cast<int>(entries->size()));
arthursonzogni5c4c202d2017-04-25 23:41:27653 DCHECK_EQ(-1, pending_entry_index_);
[email protected]ce3fa3c2009-04-20 19:55:57654
[email protected]ce3fa3c2009-04-20 19:55:57655 needs_reload_ = true;
Bo Liucdfa4b12018-11-06 00:21:44656 needs_reload_type_ = NeedsReloadType::kRestoreSession;
Rakina Zata Amniafd3c6582021-11-30 06:19:17657 entries_.clear();
avif16f85a72015-11-13 18:25:03658 entries_.reserve(entries->size());
659 for (auto& entry : *entries)
dcheng36b6aec92015-12-26 06:16:36660 entries_.push_back(
661 NavigationEntryImpl::FromNavigationEntry(std::move(entry)));
avif16f85a72015-11-13 18:25:03662
663 // At this point, the |entries| is full of empty scoped_ptrs, so it can be
664 // cleared out safely.
665 entries->clear();
[email protected]ce3fa3c2009-04-20 19:55:57666
667 // And finish the restore.
[email protected]2ca1ea662012-10-04 02:26:36668 FinishRestore(selected_navigation, type);
[email protected]ce3fa3c2009-04-20 19:55:57669}
670
toyoshim6142d96f2016-12-19 09:07:25671void NavigationControllerImpl::Reload(ReloadType reload_type,
672 bool check_for_repost) {
liaoyuke9168fba2017-03-10 19:20:28673 DCHECK_NE(ReloadType::NONE, reload_type);
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28674 NavigationEntryImpl* entry = nullptr;
[email protected]59167c22013-06-03 18:07:32675 int current_index = -1;
676
Carlos IL42b416592019-10-07 23:10:36677 if (entry_replaced_by_post_commit_error_) {
678 // If there is an entry that was replaced by a currently active post-commit
679 // error navigation, this can't be the initial navigation.
680 DCHECK(!IsInitialNavigation());
681 // If the current entry is a post commit error, we reload the entry it
682 // replaced instead. We leave the error entry in place until a commit
683 // replaces it, but the pending entry points to the original entry in the
684 // meantime. Note that NavigateToExistingPendingEntry is able to handle the
685 // case that pending_entry_ != entries_[pending_entry_index_].
686 entry = entry_replaced_by_post_commit_error_.get();
687 current_index = GetCurrentEntryIndex();
688 } else if (IsInitialNavigation() && pending_entry_) {
689 // If we are reloading the initial navigation, just use the current
690 // pending entry. Otherwise look up the current entry.
[email protected]59167c22013-06-03 18:07:32691 entry = pending_entry_;
692 // The pending entry might be in entries_ (e.g., after a Clone), so we
693 // should also update the current_index.
694 current_index = pending_entry_index_;
695 } else {
arthursonzogni69a6a1b2019-09-17 09:23:00696 DiscardNonCommittedEntries();
[email protected]59167c22013-06-03 18:07:32697 current_index = GetCurrentEntryIndex();
698 if (current_index != -1) {
creis3da03872015-02-20 21:12:32699 entry = GetEntryAtIndex(current_index);
[email protected]59167c22013-06-03 18:07:32700 }
[email protected]979a4bc2013-04-24 01:27:15701 }
[email protected]241db352013-04-22 18:04:05702
[email protected]59167c22013-06-03 18:07:32703 // If we are no where, then we can't reload. TODO(darin): We should add a
704 // CanReload method.
705 if (!entry)
706 return;
707
Takashi Toyoshimac7df3c22019-06-25 14:18:47708 // Set ReloadType for |entry|.
toyoshima63c2a62016-09-29 09:03:26709 entry->set_reload_type(reload_type);
710
Aran Gilman37d11632019-10-08 23:07:15711 if (g_check_for_repost && check_for_repost && entry->GetHasPostData()) {
[email protected]a3a1d142008-12-19 00:42:30712 // The user is asking to reload a page with POST data. Prompt to make sure
[email protected]b5bb35f2009-02-05 20:17:07713 // they really want to do this. If they do, the dialog will call us back
714 // with check_for_repost = false.
[email protected]ec6c05f2013-10-23 18:41:57715 delegate_->NotifyBeforeFormRepostWarningShow();
[email protected]965bb092010-04-09 11:59:02716
[email protected]106a0812010-03-18 00:15:12717 pending_reload_ = reload_type;
[email protected]ec6c05f2013-10-23 18:41:57718 delegate_->ActivateAndShowRepostFormWarningDialog();
Lei Zhang96031532019-10-10 19:05:47719 return;
initial.commit09911bf2008-07-26 23:55:29720 }
Lei Zhang96031532019-10-10 19:05:47721
722 if (!IsInitialNavigation())
723 DiscardNonCommittedEntries();
724
725 pending_entry_ = entry;
726 pending_entry_index_ = current_index;
727 pending_entry_->SetTransitionType(ui::PAGE_TRANSITION_RELOAD);
728
Nate Chapin45f620582021-09-30 17:45:43729 // location.reload() goes through BeginNavigation, so all reloads triggered
730 // via this codepath are browser initiated.
Lei Zhang96031532019-10-10 19:05:47731 NavigateToExistingPendingEntry(reload_type,
Nate Chapin45f620582021-09-30 17:45:43732 FrameTreeNode::kFrameTreeNodeInvalidId,
733 true /* is_browser_initiated */);
initial.commit09911bf2008-07-26 23:55:29734}
735
[email protected]d202a7c2012-01-04 07:53:47736void NavigationControllerImpl::CancelPendingReload() {
toyoshim0df1d3a2016-09-09 09:52:48737 DCHECK(pending_reload_ != ReloadType::NONE);
738 pending_reload_ = ReloadType::NONE;
[email protected]106a0812010-03-18 00:15:12739}
740
[email protected]d202a7c2012-01-04 07:53:47741void NavigationControllerImpl::ContinuePendingReload() {
toyoshim0df1d3a2016-09-09 09:52:48742 if (pending_reload_ == ReloadType::NONE) {
[email protected]106a0812010-03-18 00:15:12743 NOTREACHED();
744 } else {
toyoshim6142d96f2016-12-19 09:07:25745 Reload(pending_reload_, false);
toyoshim0df1d3a2016-09-09 09:52:48746 pending_reload_ = ReloadType::NONE;
[email protected]106a0812010-03-18 00:15:12747 }
748}
749
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57750bool NavigationControllerImpl::IsInitialNavigation() {
[email protected]27ba81c2012-08-21 17:04:09751 return is_initial_navigation_;
[email protected]c70f9b82010-04-21 07:31:11752}
753
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57754bool NavigationControllerImpl::IsInitialBlankNavigation() {
Rakina Zata Amniafd3c6582021-11-30 06:19:17755 return IsInitialNavigation() && GetEntryCount() == 1 &&
756 GetLastCommittedEntry()->IsInitialEntry() &&
757 GetLastCommittedEntry()->restore_type() == RestoreType::kNotRestored;
creis10a4ab72015-10-13 17:22:40758}
759
Aran Gilman37d11632019-10-08 23:07:15760NavigationEntryImpl* NavigationControllerImpl::GetEntryWithUniqueID(
761 int nav_entry_id) const {
avi254eff02015-07-01 08:27:58762 int index = GetEntryIndexWithUniqueID(nav_entry_id);
avif16f85a72015-11-13 18:25:03763 return (index != -1) ? entries_[index].get() : nullptr;
avi254eff02015-07-01 08:27:58764}
765
Adithya Srinivasan9b0c99c2021-08-10 15:19:45766NavigationEntryImpl*
767NavigationControllerImpl::GetEntryWithUniqueIDIncludingPending(
768 int nav_entry_id) const {
769 NavigationEntryImpl* entry = GetEntryWithUniqueID(nav_entry_id);
770 if (entry)
771 return entry;
772 return pending_entry_ && pending_entry_->GetUniqueID() == nav_entry_id
Keishi Hattori0e45c022021-11-27 09:25:52773 ? pending_entry_.get()
Adithya Srinivasan9b0c99c2021-08-10 15:19:45774 : nullptr;
775}
776
W. James MacLean1c40862c2020-04-27 21:05:57777void NavigationControllerImpl::RegisterExistingOriginToPreventOptInIsolation(
778 const url::Origin& origin) {
779 for (int i = 0; i < GetEntryCount(); i++) {
780 auto* entry = GetEntryAtIndex(i);
781 entry->RegisterExistingOriginToPreventOptInIsolation(origin);
782 }
783 if (entry_replaced_by_post_commit_error_) {
784 // It's possible we could come back to this entry if the error
785 // page/interstitial goes away.
786 entry_replaced_by_post_commit_error_
787 ->RegisterExistingOriginToPreventOptInIsolation(origin);
788 }
789 // TODO(wjmaclean): Register pending commit NavigationRequests rather than
790 // visiting pending_entry_, which lacks a committed origin. This will be done
791 // in https://chromium-review.googlesource.com/c/chromium/src/+/2136703.
792}
793
avi25764702015-06-23 15:43:37794void NavigationControllerImpl::SetPendingEntry(
dcheng9bfa5162016-04-09 01:00:57795 std::unique_ptr<NavigationEntryImpl> entry) {
arthursonzogni69a6a1b2019-09-17 09:23:00796 DiscardNonCommittedEntries();
avi25764702015-06-23 15:43:37797 pending_entry_ = entry.release();
arthursonzogni5c4c202d2017-04-25 23:41:27798 DCHECK_EQ(-1, pending_entry_index_);
[email protected]765b35502008-08-21 00:51:20799}
800
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57801NavigationEntryImpl* NavigationControllerImpl::GetActiveEntry() {
[email protected]cbab76d2008-10-13 22:42:47802 if (pending_entry_)
803 return pending_entry_;
804 return GetLastCommittedEntry();
[email protected]765b35502008-08-21 00:51:20805}
806
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57807NavigationEntryImpl* NavigationControllerImpl::GetVisibleEntry() {
[email protected]59167c22013-06-03 18:07:32808 // The pending entry is safe to return for new (non-history), browser-
809 // initiated navigations. Most renderer-initiated navigations should not
810 // show the pending entry, to prevent URL spoof attacks.
811 //
812 // We make an exception for renderer-initiated navigations in new tabs, as
813 // long as no other page has tried to access the initial empty document in
814 // the new tab. If another page modifies this blank page, a URL spoof is
815 // possible, so we must stop showing the pending entry.
[email protected]59167c22013-06-03 18:07:32816 bool safe_to_show_pending =
817 pending_entry_ &&
818 // Require a new navigation.
avi0dca04d2015-01-26 20:21:09819 pending_entry_index_ == -1 &&
[email protected]59167c22013-06-03 18:07:32820 // Require either browser-initiated or an unmodified new tab.
[email protected]aa62afd2014-04-22 19:22:46821 (!pending_entry_->is_renderer_initiated() || IsUnmodifiedBlankTab());
[email protected]59167c22013-06-03 18:07:32822
823 // Also allow showing the pending entry for history navigations in a new tab,
824 // such as Ctrl+Back. In this case, no existing page is visible and no one
825 // can script the new tab before it commits.
Aran Gilman37d11632019-10-08 23:07:15826 if (!safe_to_show_pending && pending_entry_ && pending_entry_index_ != -1 &&
827 IsInitialNavigation() && !pending_entry_->is_renderer_initiated())
[email protected]59167c22013-06-03 18:07:32828 safe_to_show_pending = true;
829
830 if (safe_to_show_pending)
[email protected]867e1f92011-08-30 19:01:19831 return pending_entry_;
832 return GetLastCommittedEntry();
833}
834
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57835int NavigationControllerImpl::GetCurrentEntryIndex() {
[email protected]765b35502008-08-21 00:51:20836 if (pending_entry_index_ != -1)
837 return pending_entry_index_;
838 return last_committed_entry_index_;
839}
840
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57841NavigationEntryImpl* NavigationControllerImpl::GetLastCommittedEntry() {
[email protected]765b35502008-08-21 00:51:20842 if (last_committed_entry_index_ == -1)
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28843 return nullptr;
avif16f85a72015-11-13 18:25:03844 return entries_[last_committed_entry_index_].get();
[email protected]765b35502008-08-21 00:51:20845}
846
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57847bool NavigationControllerImpl::CanViewSource() {
Jeremy Roman2d8dfe132021-07-06 20:51:26848 const std::string& mime_type =
849 frame_tree_.root()->current_frame_host()->GetPage().contents_mime_type();
Kinuko Yasuda74702f92017-07-31 03:27:53850 bool is_viewable_mime_type = blink::IsSupportedNonImageMimeType(mime_type) &&
851 !media::IsSupportedMediaMimeType(mime_type);
[email protected]6286a3792013-10-09 04:03:27852 NavigationEntry* visible_entry = GetVisibleEntry();
853 return visible_entry && !visible_entry->IsViewSourceMode() &&
Carlos ILd51e7702020-05-07 18:51:39854 is_viewable_mime_type;
[email protected]31682282010-01-15 18:05:16855}
856
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57857int NavigationControllerImpl::GetLastCommittedEntryIndex() {
arthursonzogni5c4c202d2017-04-25 23:41:27858 // The last committed entry index must always be less than the number of
Rakina Zata Amniafd3c6582021-11-30 06:19:17859 // entries.
arthursonzogni5c4c202d2017-04-25 23:41:27860 DCHECK_LT(last_committed_entry_index_, GetEntryCount());
[email protected]a26023822011-12-29 00:23:55861 return last_committed_entry_index_;
862}
863
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57864int NavigationControllerImpl::GetEntryCount() {
Rakina Zata Amniafd3c6582021-11-30 06:19:17865 DCHECK_GE(entries_.size(), 1u);
Carlos IL4dea8902020-05-26 15:14:29866 DCHECK_LE(entries_.size(), max_entry_count());
[email protected]a26023822011-12-29 00:23:55867 return static_cast<int>(entries_.size());
868}
869
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57870NavigationEntryImpl* NavigationControllerImpl::GetEntryAtIndex(int index) {
avi25764702015-06-23 15:43:37871 if (index < 0 || index >= GetEntryCount())
872 return nullptr;
873
avif16f85a72015-11-13 18:25:03874 return entries_[index].get();
[email protected]022af742011-12-28 18:37:25875}
876
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57877NavigationEntryImpl* NavigationControllerImpl::GetEntryAtOffset(int offset) {
avi057ce1492015-06-29 15:59:47878 return GetEntryAtIndex(GetIndexForOffset(offset));
[email protected]765b35502008-08-21 00:51:20879}
880
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57881int NavigationControllerImpl::GetIndexForOffset(int offset) {
[email protected]7bc2b032012-12-19 22:45:46882 return GetCurrentEntryIndex() + offset;
[email protected]9ba14052012-06-22 23:50:03883}
884
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57885bool NavigationControllerImpl::CanGoBack() {
Shivani Sharma298d12852019-01-22 20:04:03886 for (int index = GetIndexForOffset(-1); index >= 0; index--) {
887 if (!GetEntryAtIndex(index)->should_skip_on_back_forward_ui())
888 return true;
889 }
890 return false;
[email protected]765b35502008-08-21 00:51:20891}
892
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57893bool NavigationControllerImpl::CanGoForward() {
WangHui74286d52021-03-31 16:17:15894 for (int index = GetIndexForOffset(1); index < GetEntryCount(); index++) {
895 if (!GetEntryAtIndex(index)->should_skip_on_back_forward_ui())
896 return true;
897 }
898 return false;
[email protected]765b35502008-08-21 00:51:20899}
900
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57901bool NavigationControllerImpl::CanGoToOffset(int offset) {
[email protected]9ba14052012-06-22 23:50:03902 int index = GetIndexForOffset(offset);
903 return index >= 0 && index < GetEntryCount();
904}
905
Xiaohan Wang7f8052e02022-01-14 18:44:28906#if BUILDFLAG(IS_ANDROID)
WangHui74286d52021-03-31 16:17:15907bool NavigationControllerImpl::CanGoToOffsetWithSkipping(int offset) {
WangHui74286d52021-03-31 16:17:15908 if (offset == 0)
909 return true;
910 int increment = offset > 0 ? 1 : -1;
911 int non_skippable_entries = 0;
912 for (int index = GetIndexForOffset(increment);
913 index >= 0 && index < GetEntryCount(); index += increment) {
914 if (!GetEntryAtIndex(index)->should_skip_on_back_forward_ui())
915 non_skippable_entries++;
916
917 if (non_skippable_entries == std::abs(offset))
918 return true;
919 }
920 return false;
921}
922#endif
923
[email protected]d202a7c2012-01-04 07:53:47924void NavigationControllerImpl::GoBack() {
shivanisha55201872018-12-13 04:29:06925 int target_index = GetIndexForOffset(-1);
926
Elly Fong-Jones40ee8112021-06-23 19:10:52927 // Move the target index past the skippable entries.
Shivani Sharma298d12852019-01-22 20:04:03928 bool all_skippable_entries = true;
Elly Fong-Jones40ee8112021-06-23 19:10:52929 while (target_index >= 0) {
930 if (!GetEntryAtIndex(target_index)->should_skip_on_back_forward_ui()) {
Shivani Sharma298d12852019-01-22 20:04:03931 all_skippable_entries = false;
shivanisha55201872018-12-13 04:29:06932 break;
Shivani Sharma2d5b4b6b2019-01-08 16:07:16933 }
Elly Fong-Jones40ee8112021-06-23 19:10:52934 target_index--;
shivanisha55201872018-12-13 04:29:06935 }
Miyoung Shin1c565c912021-03-17 12:11:21936
Shivani Sharma298d12852019-01-22 20:04:03937 // Do nothing if all entries are skippable. Normally this path would not
938 // happen as consumers would have already checked it in CanGoBack but a lot of
939 // tests do not do that.
Elly Fong-Jonesccc6d1f2021-06-14 18:32:42940 if (all_skippable_entries)
Shivani Sharma298d12852019-01-22 20:04:03941 return;
shivanisha55201872018-12-13 04:29:06942
shivanisha55201872018-12-13 04:29:06943 GoToIndex(target_index);
[email protected]765b35502008-08-21 00:51:20944}
945
[email protected]d202a7c2012-01-04 07:53:47946void NavigationControllerImpl::GoForward() {
shivanisha55201872018-12-13 04:29:06947 int target_index = GetIndexForOffset(1);
948
Shivani Sharma2d5b4b6b2019-01-08 16:07:16949 // Note that at least one entry (the last one) will be non-skippable since
950 // entries are marked skippable only when they add another entry because of
951 // redirect or pushState.
Elly Fong-Jones40ee8112021-06-23 19:10:52952 while (target_index < static_cast<int>(entries_.size())) {
953 if (!GetEntryAtIndex(target_index)->should_skip_on_back_forward_ui())
shivanisha55201872018-12-13 04:29:06954 break;
Elly Fong-Jones40ee8112021-06-23 19:10:52955 target_index++;
shivanisha55201872018-12-13 04:29:06956 }
shivanisha55201872018-12-13 04:29:06957 GoToIndex(target_index);
[email protected]765b35502008-08-21 00:51:20958}
959
[email protected]d202a7c2012-01-04 07:53:47960void NavigationControllerImpl::GoToIndex(int index) {
Nate Chapin45f620582021-09-30 17:45:43961 GoToIndex(index, FrameTreeNode::kFrameTreeNodeInvalidId,
962 true /* is_browser_initiated */);
Dave Tapuska8bfd84c2019-03-26 20:47:16963}
964
965void NavigationControllerImpl::GoToIndex(int index,
Nate Chapin45f620582021-09-30 17:45:43966 int sandbox_frame_tree_node_id,
967 bool is_browser_initiated) {
968 DCHECK(sandbox_frame_tree_node_id == FrameTreeNode::kFrameTreeNodeInvalidId ||
969 !is_browser_initiated);
sunjian30574a62017-03-21 21:39:44970 TRACE_EVENT0("browser,navigation,benchmark",
971 "NavigationControllerImpl::GoToIndex");
[email protected]765b35502008-08-21 00:51:20972 if (index < 0 || index >= static_cast<int>(entries_.size())) {
973 NOTREACHED();
974 return;
975 }
976
[email protected]cbab76d2008-10-13 22:42:47977 DiscardNonCommittedEntries();
[email protected]765b35502008-08-21 00:51:20978
arthursonzogni5c4c202d2017-04-25 23:41:27979 DCHECK_EQ(nullptr, pending_entry_);
980 DCHECK_EQ(-1, pending_entry_index_);
981 pending_entry_ = entries_[index].get();
[email protected]765b35502008-08-21 00:51:20982 pending_entry_index_ = index;
arthursonzogni5c4c202d2017-04-25 23:41:27983 pending_entry_->SetTransitionType(ui::PageTransitionFromInt(
984 pending_entry_->GetTransitionType() | ui::PAGE_TRANSITION_FORWARD_BACK));
Nate Chapin45f620582021-09-30 17:45:43985 NavigateToExistingPendingEntry(ReloadType::NONE, sandbox_frame_tree_node_id,
986 is_browser_initiated);
[email protected]765b35502008-08-21 00:51:20987}
988
[email protected]d202a7c2012-01-04 07:53:47989void NavigationControllerImpl::GoToOffset(int offset) {
toyoshim3af4d502016-03-30 12:38:12990 // Note: This is actually reached in unit tests.
[email protected]9ba14052012-06-22 23:50:03991 if (!CanGoToOffset(offset))
[email protected]765b35502008-08-21 00:51:20992 return;
993
[email protected]9ba14052012-06-22 23:50:03994 GoToIndex(GetIndexForOffset(offset));
[email protected]765b35502008-08-21 00:51:20995}
996
Nate Chapin45f620582021-09-30 17:45:43997void NavigationControllerImpl::GoToOffsetFromRenderer(int offset) {
998 // Note: This is actually reached in unit tests.
999 if (!CanGoToOffset(offset))
1000 return;
1001
1002 GoToIndex(GetIndexForOffset(offset), FrameTreeNode::kFrameTreeNodeInvalidId,
1003 false /* is_browser_initiated */);
1004}
1005
Xiaohan Wang7f8052e02022-01-14 18:44:281006#if BUILDFLAG(IS_ANDROID)
WangHui74286d52021-03-31 16:17:151007void NavigationControllerImpl::GoToOffsetWithSkipping(int offset) {
1008 // Note: This is actually reached in unit tests.
1009 if (!CanGoToOffsetWithSkipping(offset))
1010 return;
1011
Elly Fong-Jonesccc6d1f2021-06-14 18:32:421012 if (offset == 0) {
WangHui74286d52021-03-31 16:17:151013 GoToIndex(GetIndexForOffset(offset));
1014 return;
1015 }
1016 int increment = offset > 0 ? 1 : -1;
1017 // Find the offset without counting skippable entries.
1018 int target_index = GetIndexForOffset(increment);
1019 int non_skippable_entries = 0;
1020 for (int index = target_index; index >= 0 && index < GetEntryCount();
1021 index += increment) {
1022 if (!GetEntryAtIndex(index)->should_skip_on_back_forward_ui())
1023 non_skippable_entries++;
1024
1025 if (non_skippable_entries == std::abs(offset)) {
1026 target_index = index;
1027 break;
1028 }
1029 }
1030
1031 GoToIndex(target_index);
1032}
1033#endif
1034
[email protected]41374f12013-07-24 02:49:281035bool NavigationControllerImpl::RemoveEntryAtIndex(int index) {
Aran Gilman37d11632019-10-08 23:07:151036 if (index == last_committed_entry_index_ || index == pending_entry_index_)
[email protected]41374f12013-07-24 02:49:281037 return false;
[email protected]6a13a6c2011-12-20 21:47:121038
[email protected]43032342011-03-21 14:10:311039 RemoveEntryAtIndexInternal(index);
[email protected]41374f12013-07-24 02:49:281040 return true;
[email protected]cbab76d2008-10-13 22:42:471041}
1042
Michael Thiessen9b14d512019-09-23 21:19:471043void NavigationControllerImpl::PruneForwardEntries() {
1044 DiscardNonCommittedEntries();
1045 int remove_start_index = last_committed_entry_index_ + 1;
Lei Zhang96031532019-10-10 19:05:471046 int num_removed = static_cast<int>(entries_.size()) - remove_start_index;
Michael Thiessen9b14d512019-09-23 21:19:471047 if (num_removed <= 0)
1048 return;
1049 entries_.erase(entries_.begin() + remove_start_index, entries_.end());
1050 NotifyPrunedEntries(this, remove_start_index /* start index */,
1051 num_removed /* count */);
1052}
1053
Aran Gilman37d11632019-10-08 23:07:151054void NavigationControllerImpl::UpdateVirtualURLToURL(NavigationEntryImpl* entry,
1055 const GURL& new_url) {
[email protected]38178a42009-12-17 18:58:321056 GURL new_virtual_url(new_url);
[email protected]825b1662012-03-12 19:07:311057 if (BrowserURLHandlerImpl::GetInstance()->ReverseURLRewrite(
[email protected]36fc0392011-12-25 03:59:511058 &new_virtual_url, entry->GetVirtualURL(), browser_context_)) {
1059 entry->SetVirtualURL(new_virtual_url);
[email protected]38178a42009-12-17 18:58:321060 }
1061}
1062
Harkiran Bolariaba823e42021-05-21 18:30:361063base::WeakPtr<NavigationHandle> NavigationControllerImpl::LoadURL(
1064 const GURL& url,
1065 const Referrer& referrer,
1066 ui::PageTransition transition,
1067 const std::string& extra_headers) {
[email protected]cf002332012-08-14 19:17:471068 LoadURLParams params(url);
1069 params.referrer = referrer;
1070 params.transition_type = transition;
1071 params.extra_headers = extra_headers;
Harkiran Bolariaba823e42021-05-21 18:30:361072 return LoadURLWithParams(params);
[email protected]cf002332012-08-14 19:17:471073}
1074
Harkiran Bolariaba823e42021-05-21 18:30:361075base::WeakPtr<NavigationHandle> NavigationControllerImpl::LoadURLWithParams(
1076 const LoadURLParams& params) {
Lukasz Anforowicz435bcb582019-07-12 20:50:061077 if (params.is_renderer_initiated)
1078 DCHECK(params.initiator_origin.has_value());
1079
naskob8744d22014-08-28 17:07:431080 TRACE_EVENT1("browser,navigation",
Aran Gilman37d11632019-10-08 23:07:151081 "NavigationControllerImpl::LoadURLWithParams", "url",
1082 params.url.possibly_invalid_spec());
Ian Vollick9dda0522019-09-11 02:24:291083 bool is_explicit_navigation =
1084 GetContentClient()->browser()->IsExplicitNavigation(
1085 params.transition_type);
1086 if (HandleDebugURL(params.url, params.transition_type,
1087 is_explicit_navigation)) {
[email protected]47752982014-07-29 08:01:431088 // If Telemetry is running, allow the URL load to proceed as if it's
1089 // unhandled, otherwise Telemetry can't tell if Navigation completed.
avi83883c82014-12-23 00:08:491090 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]47752982014-07-29 08:01:431091 cc::switches::kEnableGpuBenchmarking))
Harkiran Bolariaba823e42021-05-21 18:30:361092 return nullptr;
[email protected]47752982014-07-29 08:01:431093 }
[email protected]8bf1048012012-02-08 01:22:181094
[email protected]cf002332012-08-14 19:17:471095 // Checks based on params.load_type.
1096 switch (params.load_type) {
1097 case LOAD_TYPE_DEFAULT:
lukasza477a5a22016-06-16 18:28:431098 case LOAD_TYPE_HTTP_POST:
[email protected]cf002332012-08-14 19:17:471099 break;
1100 case LOAD_TYPE_DATA:
[email protected]cca6f392014-05-28 21:32:261101 if (!params.url.SchemeIs(url::kDataScheme)) {
[email protected]cf002332012-08-14 19:17:471102 NOTREACHED() << "Data load must use data scheme.";
Harkiran Bolariaba823e42021-05-21 18:30:361103 return nullptr;
[email protected]cf002332012-08-14 19:17:471104 }
1105 break;
Lukasz Anforowiczbb0cfd5e2017-12-14 22:39:461106 }
[email protected]e47ae9472011-10-13 19:48:341107
[email protected]e47ae9472011-10-13 19:48:341108 // The user initiated a load, we don't need to reload anymore.
1109 needs_reload_ = false;
1110
Harkiran Bolariaba823e42021-05-21 18:30:361111 return NavigateWithoutEntry(params);
[email protected]132e281a2012-07-31 18:32:441112}
1113
Mohamed Abdelhalim833de902019-09-16 17:41:451114bool NavigationControllerImpl::PendingEntryMatchesRequest(
1115 NavigationRequest* request) const {
creisb4dc9332016-03-14 21:39:191116 return pending_entry_ &&
Mohamed Abdelhalim833de902019-09-16 17:41:451117 pending_entry_->GetUniqueID() == request->nav_entry_id();
creisb4dc9332016-03-14 21:39:191118}
1119
[email protected]d202a7c2012-01-04 07:53:471120bool NavigationControllerImpl::RendererDidNavigate(
creis3da03872015-02-20 21:12:321121 RenderFrameHostImpl* rfh,
arthursonzogni73fe3212020-11-17 13:24:071122 const mojom::DidCommitProvisionalLoadParams& params,
peary21b0f797b2016-09-28 17:28:331123 LoadCommittedDetails* details,
Eugene But712f03d2018-05-22 16:03:441124 bool is_same_document_navigation,
Nate Chapinc7019dd7d2021-06-25 18:29:251125 bool was_on_initial_empty_document,
Shivani Sharmaffb32b82019-04-09 16:58:471126 bool previous_document_was_activated,
Camille Lamy10aafcd32018-12-05 15:48:131127 NavigationRequest* navigation_request) {
1128 DCHECK(navigation_request);
shivanigithubf405bf0d2021-11-05 17:58:331129 if (ShouldMaintainTrivialSessionHistory(rfh->frame_tree_node()) &&
1130 GetLastCommittedEntry()) {
Takashi Toyoshimaa9f66802021-08-18 02:40:171131 // Ensure that this navigation does not add a navigation entry, since
1132 // ShouldMaintainTrivialSessionHistory() means we should not add an entry
1133 // beyond the last committed one. Therefore, `should_replace_current_entry`
1134 // should be set, which replaces the current entry, or this should be a
1135 // reload, which does not create a new entry.
1136 DCHECK(params.should_replace_current_entry ||
1137 navigation_request->GetReloadType() != ReloadType::NONE);
1138 }
[email protected]cd2e15742013-03-08 04:08:311139 is_initial_navigation_ = false;
1140
[email protected]0e8db942008-09-24 21:21:481141 // Save the previous state before we clobber it.
aelias100c9192017-01-13 00:01:431142 bool overriding_user_agent_changed = false;
[email protected]0e8db942008-09-24 21:21:481143 if (GetLastCommittedEntry()) {
Carlos IL42b416592019-10-07 23:10:361144 if (entry_replaced_by_post_commit_error_) {
1145 if (is_same_document_navigation) {
1146 // Same document navigations should not be possible on error pages and
1147 // would leave the controller in a weird state. Kill the renderer if
1148 // that happens.
1149 bad_message::ReceivedBadMessage(
1150 rfh->GetProcess(), bad_message::NC_SAME_DOCUMENT_POST_COMMIT_ERROR);
1151 }
1152 // Any commit while a post-commit error page is showing should put the
1153 // original entry back, replacing the error page's entry. This includes
1154 // reloads, where the original entry was used as the pending entry and
1155 // should now be at the correct index at commit time.
1156 entries_[last_committed_entry_index_] =
1157 std::move(entry_replaced_by_post_commit_error_);
1158 }
Fergal Daly8e33cf62020-12-12 01:06:071159 details->previous_main_frame_url = GetLastCommittedEntry()->GetURL();
[email protected]a26023822011-12-29 00:23:551160 details->previous_entry_index = GetLastCommittedEntryIndex();
aelias100c9192017-01-13 00:01:431161 if (pending_entry_ &&
1162 pending_entry_->GetIsOverridingUserAgent() !=
1163 GetLastCommittedEntry()->GetIsOverridingUserAgent())
1164 overriding_user_agent_changed = true;
Xiaohan Wang7f8052e02022-01-14 18:44:281165#if BUILDFLAG(IS_ANDROID)
Shu Yang5756fa422021-11-05 23:02:541166 // TODO(crbug.com/1266277): Clean up the logic of setting
1167 // |overriding_user_agent_changed| post-launch.
Shu Yang9eabbb902021-11-17 00:45:031168 if (base::FeatureList::IsEnabled(features::kRequestDesktopSiteExceptions)) {
Shu Yang5756fa422021-11-05 23:02:541169 // Must honor user agent overrides in the |navigation_request|, such as
1170 // from things like RequestDesktopSiteWebContentsObserverAndroid. As a
1171 // result, besides comparing |pending_entry_|'s user agent against
1172 // LastCommittedEntry's, also need to compare |navigation_request|'s user
1173 // agent against LastCommittedEntry's.
1174 if (navigation_request->is_overriding_user_agent() !=
1175 GetLastCommittedEntry()->GetIsOverridingUserAgent()) {
1176 overriding_user_agent_changed = true;
1177 }
1178 }
Xiaohan Wang7f8052e02022-01-14 18:44:281179#endif // BUILDFLAG(IS_ANDROID)
[email protected]0e8db942008-09-24 21:21:481180 } else {
Gang Wu325f03f42021-02-25 20:00:461181 // GetLastCommittedEntry() is null, so this is the first entry.
Fergal Daly8e33cf62020-12-12 01:06:071182 details->previous_main_frame_url = GURL();
[email protected]0e8db942008-09-24 21:21:481183 details->previous_entry_index = -1;
Gang Wu325f03f42021-02-25 20:00:461184 if (pending_entry_ && pending_entry_->GetIsOverridingUserAgent()) {
1185 // Default setting is NOT override the user agent, so overriding the user
1186 // agent in first entry should be considered as user agent changed as
1187 // well.
1188 overriding_user_agent_changed = true;
1189 }
Xiaohan Wang7f8052e02022-01-14 18:44:281190#if BUILDFLAG(IS_ANDROID)
Shu Yang5756fa422021-11-05 23:02:541191 // TODO(crbug.com/1266277): Clean up the logic of setting
1192 // |overriding_user_agent_changed| post-launch.
Shu Yang9eabbb902021-11-17 00:45:031193 if (base::FeatureList::IsEnabled(features::kRequestDesktopSiteExceptions)) {
Shu Yang5756fa422021-11-05 23:02:541194 // Must honor user agent overrides in the |navigation_request|, such as
1195 // from things like RequestDesktopSiteWebContentsObserverAndroid. As a
1196 // result, besides checking |pending_entry_|'s user agent, also need to
1197 // check |navigation_request|'s.
1198 if (navigation_request->is_overriding_user_agent()) {
1199 overriding_user_agent_changed = true;
1200 }
1201 }
Xiaohan Wang7f8052e02022-01-14 18:44:281202#endif // BUILDFLAG(IS_ANDROID)
[email protected]0e8db942008-09-24 21:21:481203 }
[email protected]ecd9d8702008-08-28 22:10:171204
Dave Tapuskaa2ab4f252021-07-08 21:31:281205 bool is_main_frame_navigation = !rfh->GetParent();
1206
Alexander Timind2f2e4f22019-04-02 20:04:531207 // TODO(altimin, crbug.com/933147): Remove this logic after we are done with
1208 // implementing back-forward cache.
Dave Tapuskaa2ab4f252021-07-08 21:31:281209 // For primary frame tree navigations, choose an appropriate
1210 // BackForwardCacheMetrics to be associated with the NavigationEntry, by
1211 // either creating a new object or reusing the previous one depending on
1212 // whether it's a main frame navigation or not.
1213 scoped_refptr<BackForwardCacheMetrics> back_forward_cache_metrics;
1214 if (navigation_request->frame_tree_node()->frame_tree()->type() ==
1215 FrameTree::Type::kPrimary) {
1216 back_forward_cache_metrics =
1217 BackForwardCacheMetrics::CreateOrReuseBackForwardCacheMetrics(
1218 GetLastCommittedEntry(), is_main_frame_navigation,
1219 params.document_sequence_number);
1220 }
Alexander Timind2f2e4f22019-04-02 20:04:531221 // Notify the last active entry that we have navigated away.
Dave Tapuskaa2ab4f252021-07-08 21:31:281222 if (is_main_frame_navigation && !is_same_document_navigation) {
Alexander Timind2f2e4f22019-04-02 20:04:531223 if (NavigationEntryImpl* navigation_entry = GetLastCommittedEntry()) {
1224 if (auto* metrics = navigation_entry->back_forward_cache_metrics()) {
Hajime Hoshic7606502021-04-14 02:42:161225 metrics->MainFrameDidNavigateAwayFromDocument(rfh, navigation_request);
Alexander Timind2f2e4f22019-04-02 20:04:531226 }
1227 }
1228 }
1229
fdegans9caf66a2015-07-30 21:10:421230 // If there is a pending entry at this point, it should have a SiteInstance,
1231 // except for restored entries.
jam48cea9082017-02-15 06:13:291232 bool was_restored = false;
toyoshim0df1d3a2016-09-09 09:52:481233 DCHECK(pending_entry_index_ == -1 || pending_entry_->site_instance() ||
Lukasz Anforowicz6b75c0d2020-12-01 22:56:081234 pending_entry_->IsRestored());
1235 if (pending_entry_ && pending_entry_->IsRestored()) {
Lukasz Anforowicz0de0f452020-12-02 19:57:151236 pending_entry_->set_restore_type(RestoreType::kNotRestored);
jam48cea9082017-02-15 06:13:291237 was_restored = true;
toyoshim0df1d3a2016-09-09 09:52:481238 }
[email protected]e9ba4472008-09-14 15:42:431239
Nasko Oskovaee2f862018-06-15 00:05:521240 // If this is a navigation to a matching pending_entry_ and the SiteInstance
1241 // has changed, this must be treated as a new navigation with replacement.
1242 // Set the replacement bit here and ClassifyNavigation will identify this
Charlie Reisc0f17d2d2021-01-12 18:52:491243 // case and return NEW_ENTRY.
Nasko Oskovaee2f862018-06-15 00:05:521244 if (!rfh->GetParent() && pending_entry_ &&
Rakina Zata Amnif6950d552020-11-24 03:26:101245 pending_entry_->GetUniqueID() ==
1246 navigation_request->commit_params().nav_entry_id &&
Nasko Oskovaee2f862018-06-15 00:05:521247 pending_entry_->site_instance() &&
1248 pending_entry_->site_instance() != rfh->GetSiteInstance()) {
1249 DCHECK_NE(-1, pending_entry_index_);
1250 // TODO(nasko,creis): Instead of setting this value here, set
1251 // should_replace_current_entry on the parameters we send to the
1252 // renderer process as part of CommitNavigation. The renderer should
1253 // in turn send it back here as part of |params| and it can be just
1254 // enforced and renderer process terminated on mismatch.
1255 details->did_replace_entry = true;
1256 } else {
1257 // The renderer tells us whether the navigation replaces the current entry.
1258 details->did_replace_entry = params.should_replace_current_entry;
1259 }
[email protected]bcd904482012-02-01 01:54:221260
[email protected]e9ba4472008-09-14 15:42:431261 // Do navigation-type specific actions. These will make and commit an entry.
Rakina Zata Amnia4e27222021-12-22 01:05:001262 details->type = ClassifyNavigation(rfh, params, navigation_request, details);
Rakina Zata Amniddf10502022-01-15 02:56:551263 if (GetLastCommittedEntry()->IsInitialEntry()) {
1264 if (rfh->GetParent()) {
1265 // Subframe navigation on initial NavigationEntry must not append a new
1266 // NavigationEntry (i.e. should not be classified as NEW_SUBFRAME). This
1267 // means every subframe navigation that happens while we're on the initial
1268 // NavigationEntry will always reuse the existing NavigationEntry and
1269 // just update the corresponding FrameNavigationEntry.
1270 DCHECK_EQ(details->type, NAVIGATION_TYPE_AUTO_SUBFRAME);
1271 } else if (details->type == NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY) {
1272 // This is a navigation that modifies the initial NavigationEntry, either
1273 // for a replacement or a reload. The initial NavigationEntry should
1274 // retain its "initial NavigationEntry" status in this case.
1275 details->should_stay_as_initial_entry = true;
1276 }
1277 }
1278 DCHECK(!details->should_stay_as_initial_entry ||
1279 GetLastCommittedEntry()->IsInitialEntry());
[email protected]4bf3522c2010-08-19 21:00:201280
eugenebutee08663a2017-04-27 17:43:121281 // is_same_document must be computed before the entry gets committed.
Eugene But712f03d2018-05-22 16:03:441282 details->is_same_document = is_same_document_navigation;
[email protected]b9d4dfdc2013-08-08 00:25:121283
Lucas Furukawa Gadanie3f7e792021-04-22 17:56:071284 details->is_prerender_activation =
1285 navigation_request->IsPrerenderedPageActivation();
1286
Peter Boströmd7592132019-01-30 04:50:311287 // Make sure we do not discard the pending entry for a different ongoing
1288 // navigation when a same document commit comes in unexpectedly from the
1289 // renderer. Limit this to a very narrow set of conditions to avoid risks to
1290 // other navigation types. See https://crbug.com/900036.
1291 // TODO(crbug.com/926009): Handle history.pushState() as well.
Yoshisato Yanagisawa2ccba602021-11-17 08:24:061292 bool keep_pending_entry =
1293 is_same_document_navigation &&
1294 details->type == NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY &&
1295 pending_entry_ && !PendingEntryMatchesRequest(navigation_request);
Peter Boströmd7592132019-01-30 04:50:311296
[email protected]0e8db942008-09-24 21:21:481297 switch (details->type) {
Yoshisato Yanagisawa2ccba602021-11-17 08:24:061298 case NAVIGATION_TYPE_MAIN_FRAME_NEW_ENTRY:
Charlie Reisc0f17d2d2021-01-12 18:52:491299 RendererDidNavigateToNewEntry(
shivanisha41f04c52018-12-12 15:52:051300 rfh, params, details->is_same_document, details->did_replace_entry,
Rakina Zata Amnia4e27222021-12-22 01:05:001301 previous_document_was_activated, navigation_request, details);
[email protected]e9ba4472008-09-14 15:42:431302 break;
Yoshisato Yanagisawa2ccba602021-11-17 08:24:061303 case NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY:
Charlie Reisc0f17d2d2021-01-12 18:52:491304 RendererDidNavigateToExistingEntry(rfh, params, details->is_same_document,
1305 was_restored, navigation_request,
Rakina Zata Amnia4e27222021-12-22 01:05:001306 keep_pending_entry, details);
[email protected]e9ba4472008-09-14 15:42:431307 break;
[email protected]8ff00d72012-10-23 19:12:211308 case NAVIGATION_TYPE_NEW_SUBFRAME:
Shivani Sharmaffb32b82019-04-09 16:58:471309 RendererDidNavigateNewSubframe(
1310 rfh, params, details->is_same_document, details->did_replace_entry,
Rakina Zata Amnia4e27222021-12-22 01:05:001311 previous_document_was_activated, navigation_request, details);
[email protected]e9ba4472008-09-14 15:42:431312 break;
[email protected]8ff00d72012-10-23 19:12:211313 case NAVIGATION_TYPE_AUTO_SUBFRAME:
Antonio Sartori78a749f2020-11-30 12:03:391314 if (!RendererDidNavigateAutoSubframe(
Nate Chapinc7019dd7d2021-06-25 18:29:251315 rfh, params, details->is_same_document,
Rakina Zata Amnia4e27222021-12-22 01:05:001316 was_on_initial_empty_document, navigation_request, details)) {
creisce0ef3572017-01-26 17:53:081317 // We don't send a notification about auto-subframe PageState during
1318 // UpdateStateForFrame, since it looks like nothing has changed. Send
1319 // it here at commit time instead.
1320 NotifyEntryChanged(GetLastCommittedEntry());
[email protected]e9ba4472008-09-14 15:42:431321 return false;
creis59d5a47cb2016-08-24 23:57:191322 }
[email protected]e9ba4472008-09-14 15:42:431323 break;
Aran Gilman37d11632019-10-08 23:07:151324 case NAVIGATION_TYPE_UNKNOWN:
[email protected]e9ba4472008-09-14 15:42:431325 NOTREACHED();
Aran Gilman37d11632019-10-08 23:07:151326 break;
[email protected]765b35502008-08-21 00:51:201327 }
1328
[email protected]688aa65c62012-09-28 04:32:221329 // At this point, we know that the navigation has just completed, so
1330 // record the time.
1331 //
1332 // TODO(akalin): Use "sane time" as described in
Adam Langley4463fb832018-01-28 22:42:261333 // https://www.chromium.org/developers/design-documents/sane-time .
[email protected]c5b88d82012-10-06 17:03:331334 base::Time timestamp =
1335 time_smoother_.GetSmoothedTime(get_timestamp_callback_.Run());
1336 DVLOG(1) << "Navigation finished at (smoothed) timestamp "
danakjf26536bf2020-09-10 00:46:131337 << timestamp.ToDeltaSinceWindowsEpoch().InMicroseconds();
[email protected]688aa65c62012-09-28 04:32:221338
Peter Boströmd7592132019-01-30 04:50:311339 // If we aren't keeping the pending entry, there shouldn't be one at this
1340 // point. Clear it again in case any error cases above forgot to do so.
1341 // TODO(pbos): Consider a CHECK here that verifies that the pending entry has
1342 // been cleared instead of protecting against it.
1343 if (!keep_pending_entry)
Rakina Zata Amniddf10502022-01-15 02:56:551344 DiscardNonCommittedEntriesWithCommitDetails(details);
[email protected]f233e4232013-02-23 00:55:141345
[email protected]e9ba4472008-09-14 15:42:431346 // All committed entries should have nonempty content state so WebKit doesn't
1347 // get confused when we go back to them (see the function for details).
creis0cade2e2017-02-28 06:37:471348 DCHECK(params.page_state.IsValid()) << "Shouldn't see an empty PageState.";
creis3da03872015-02-20 21:12:321349 NavigationEntryImpl* active_entry = GetLastCommittedEntry();
[email protected]688aa65c62012-09-28 04:32:221350 active_entry->SetTimestamp(timestamp);
[email protected]f49737b32013-08-28 07:51:441351 active_entry->SetHttpStatusCode(params.http_status_code);
Alexander Timind2f2e4f22019-04-02 20:04:531352 // TODO(altimin, crbug.com/933147): Remove this logic after we are done with
1353 // implementing back-forward cache.
Dave Tapuskaa2ab4f252021-07-08 21:31:281354 if (back_forward_cache_metrics &&
1355 !active_entry->back_forward_cache_metrics()) {
Alexander Timind2f2e4f22019-04-02 20:04:531356 active_entry->set_back_forward_cache_metrics(
1357 std::move(back_forward_cache_metrics));
1358 }
Dave Tapuskaa2ab4f252021-07-08 21:31:281359
1360 // `back_forward_cache_metrics()` may return null as we do not record
1361 // back-forward cache metrics for navigations in non-primary frame trees.
1362 if (active_entry->back_forward_cache_metrics()) {
1363 active_entry->back_forward_cache_metrics()->DidCommitNavigation(
1364 navigation_request,
1365 back_forward_cache_.IsAllowed(navigation_request->GetURL()));
1366 }
naskoc7533512016-05-06 17:01:121367
Charles Reisc0507202017-09-21 00:40:021368 // Grab the corresponding FrameNavigationEntry for a few updates, but only if
1369 // the SiteInstance matches (to avoid updating the wrong entry by mistake).
1370 // A mismatch can occur if the renderer lies or due to a unique name collision
1371 // after a race with an OOPIF (see https://crbug.com/616820).
naskoc7533512016-05-06 17:01:121372 FrameNavigationEntry* frame_entry =
1373 active_entry->GetFrameEntry(rfh->frame_tree_node());
Charles Reisc0507202017-09-21 00:40:021374 if (frame_entry && frame_entry->site_instance() != rfh->GetSiteInstance())
1375 frame_entry = nullptr;
Charles Reisf44482022017-10-13 21:15:031376 // Make sure we've updated the PageState in one of the helper methods.
creisce0ef3572017-01-26 17:53:081377 // TODO(creis): Remove the "if" once https://crbug.com/522193 is fixed.
1378 if (frame_entry) {
Charles Reisf44482022017-10-13 21:15:031379 DCHECK(params.page_state == frame_entry->page_state());
Nasko Oskovbbcfc0002019-11-20 20:03:201380
1381 // Remember the bindings the renderer process has at this point, so that
1382 // we do not grant this entry additional bindings if we come back to it.
1383 frame_entry->SetBindings(rfh->GetEnabledBindings());
creis4e2ecb72015-06-20 00:46:301384 }
[email protected]132e281a2012-07-31 18:32:441385
[email protected]97d8f0d2013-10-29 16:49:211386 // Once it is committed, we no longer need to track several pieces of state on
1387 // the entry.
naskoc7533512016-05-06 17:01:121388 active_entry->ResetForCommit(frame_entry);
[email protected]60d6cca2013-04-30 08:47:131389
[email protected]49bd30e62011-03-22 20:12:591390 // The active entry's SiteInstance should match our SiteInstance.
[email protected]a1b99262013-12-27 21:56:221391 // TODO(creis): This check won't pass for subframes until we create entries
1392 // for subframe navigations.
avi39c1edd32015-06-04 20:06:001393 if (!rfh->GetParent())
creis77c9aa32015-09-25 19:59:421394 CHECK_EQ(active_entry->site_instance(), rfh->GetSiteInstance());
[email protected]49bd30e62011-03-22 20:12:591395
[email protected]e9ba4472008-09-14 15:42:431396 // Now prep the rest of the details for the notification and broadcast.
[email protected]0f38dc4552011-02-25 11:24:001397 details->entry = active_entry;
avi39c1edd32015-06-04 20:06:001398 details->is_main_frame = !rfh->GetParent();
[email protected]2e39d2e2009-02-19 18:41:311399 details->http_status_code = params.http_status_code;
estarka5635c42015-07-14 00:06:531400
arthursonzogni7ddc6542021-04-09 09:16:501401 active_entry->SetIsOverridingUserAgent(
1402 navigation_request->is_overriding_user_agent());
Scott Violetc36f7462020-05-06 23:13:031403
[email protected]93f230e02011-06-01 14:40:001404 NotifyNavigationEntryCommitted(details);
initial.commit09911bf2008-07-26 23:55:291405
aelias100c9192017-01-13 00:01:431406 if (overriding_user_agent_changed)
1407 delegate_->UpdateOverridingUserAgent();
1408
creis03b48002015-11-04 00:54:561409 // Update the nav_entry_id for each RenderFrameHost in the tree, so that each
1410 // one knows the latest NavigationEntry it is showing (whether it has
1411 // committed anything in this navigation or not). This allows things like
1412 // state and title updates from RenderFrames to apply to the latest relevant
1413 // NavigationEntry.
dcheng57e39e22016-01-21 00:25:381414 int nav_entry_id = active_entry->GetUniqueID();
Carlos Caballero40b0efd2021-01-26 11:55:001415 for (FrameTreeNode* node : frame_tree_.Nodes())
dcheng57e39e22016-01-21 00:25:381416 node->current_frame_host()->set_nav_entry_id(nav_entry_id);
Hayato Ito2c8c08d02021-06-23 03:38:431417
1418 if (navigation_request->IsPrerenderedPageActivation()) {
1419 BroadcastHistoryOffsetAndLength();
1420 // TODO(crbug.com/1222893): Broadcasting happens after the prerendered page
1421 // is activated. As a result, a "prerenderingchange" event listener sees the
1422 // history.length which is not updated yet. We should guarantee that
1423 // history's length and offset should be updated before a
1424 // "prerenderingchange" event listener runs. One possible approach is to use
1425 // the same IPC which "prerenderingchange" uses, and propagate history's
1426 // length and offset together with that.
1427 }
1428
[email protected]e9ba4472008-09-14 15:42:431429 return true;
initial.commit09911bf2008-07-26 23:55:291430}
1431
[email protected]8ff00d72012-10-23 19:12:211432NavigationType NavigationControllerImpl::ClassifyNavigation(
creis3da03872015-02-20 21:12:321433 RenderFrameHostImpl* rfh,
Rakina Zata Amnif6950d552020-11-24 03:26:101434 const mojom::DidCommitProvisionalLoadParams& params,
Rakina Zata Amnia4e27222021-12-22 01:05:001435 NavigationRequest* navigation_request,
1436 LoadCommittedDetails* details) {
1437 if (GetLastCommittedEntry()->IsInitialEntry() &&
1438 navigation_request->is_synchronous_renderer_commit() &&
1439 !navigation_request->IsSameDocument() && !rfh->GetParent() &&
1440 params.should_replace_current_entry) {
Rakina Zata Amniddf10502022-01-15 02:56:551441 // This is a synchronous about:blank navigation on the main frame, which
1442 // used to not create a NavigationEntry when we have no NavigationEntry on
1443 // FrameTree creation. We now have the initial NavigationEntry and are on
1444 // the initial NavigationEntry. To preserve old behavior, we should still
1445 // keep the "initial" status for the new NavigationEntry that we will create
1446 // for this navigation, so that subframe navigations under the synchronously
1447 // committed about:blank document will never append new NavigationEntry, and
1448 // instead will just reuse the initial NavigationEntry and modify the
1449 // corresponding FrameNavigationEntries. See also https://crbug.com/1277414.
1450 details->should_stay_as_initial_entry = true;
Rakina Zata Amnia4e27222021-12-22 01:05:001451 }
1452
Piotr Tworekbad51282020-09-30 19:17:591453 TraceReturnReason<tracing_category::kNavigation> trace_return(
Nasko Oskovae49e292020-08-13 02:08:511454 "ClassifyNavigation");
Rakina Zata Amniafd3c6582021-11-30 06:19:171455 DCHECK(GetLastCommittedEntry());
Rakina Zata Amniddf10502022-01-15 02:56:551456 if (rfh->GetParent() && GetLastCommittedEntry()->IsInitialEntry()) {
Rakina Zata Amnia4e27222021-12-22 01:05:001457 // This is a subframe navigation on the initial empty document, which used
Rakina Zata Amniddf10502022-01-15 02:56:551458 // to not have a NavigationEntry to attach to. Now it can attach to the
1459 // initial NavigationEntry, and we must ensure that its NavigationEntry will
1460 // keep the "initial NavigationEntry" status and won't append a new
1461 // NavigationEntry (it should always do replacement instead).
Rakina Zata Amnia4e27222021-12-22 01:05:001462 // See also https://crbug.com/1277414.
Rakina Zata Amniddf10502022-01-15 02:56:551463 details->should_stay_as_initial_entry = true;
Rakina Zata Amnia4e27222021-12-22 01:05:001464 }
Nasko Oskovae49e292020-08-13 02:08:511465
avi7c6f35e2015-05-08 17:52:381466 if (params.did_create_new_entry) {
Rakina Zata Amniafd3c6582021-11-30 06:19:171467 // A new entry for either the main frame or a subframe.
avi39c1edd32015-06-04 20:06:001468 if (!rfh->GetParent()) {
Charlie Reisc0f17d2d2021-01-12 18:52:491469 trace_return.set_return_reason("new entry, no parent, new entry");
Yoshisato Yanagisawa2ccba602021-11-17 08:24:061470 return NAVIGATION_TYPE_MAIN_FRAME_NEW_ENTRY;
avi7c6f35e2015-05-08 17:52:381471 }
1472
Rakina Zata Amniafd3c6582021-11-30 06:19:171473 // Subframe navigation.
Nasko Oskovae49e292020-08-13 02:08:511474 trace_return.set_return_reason("new entry, new subframe");
avi7c6f35e2015-05-08 17:52:381475 return NAVIGATION_TYPE_NEW_SUBFRAME;
1476 }
1477
Charlie Reisc0f17d2d2021-01-12 18:52:491478 // We only clear the session history in tests when navigating to a new entry.
avi7c6f35e2015-05-08 17:52:381479 DCHECK(!params.history_list_was_cleared);
1480
avi39c1edd32015-06-04 20:06:001481 if (rfh->GetParent()) {
avi7c6f35e2015-05-08 17:52:381482 // All manual subframes would be did_create_new_entry and handled above, so
1483 // we know this is auto.
Rakina Zata Amniafd3c6582021-11-30 06:19:171484 trace_return.set_return_reason("subframe, last commmited, auto subframe");
1485 return NAVIGATION_TYPE_AUTO_SUBFRAME;
avi7c6f35e2015-05-08 17:52:381486 }
1487
Rakina Zata Amnif6950d552020-11-24 03:26:101488 const int nav_entry_id = navigation_request->commit_params().nav_entry_id;
1489 if (nav_entry_id == 0) {
avi7c6f35e2015-05-08 17:52:381490 // This is a renderer-initiated navigation (nav_entry_id == 0), but didn't
1491 // create a new page.
1492
Hayato Ito2ae49442021-07-02 02:59:251493 // This main frame navigation is not a history navigation (since
1494 // nav_entry_id is 0), but didn't create a new entry. So this must be a
1495 // reload or a replacement navigation, which will modify the existing entry.
1496 //
Nasko Oskov332593c2018-08-16 17:21:341497 // TODO(nasko): With error page isolation, reloading an existing session
1498 // history entry can result in change of SiteInstance. Check for such a case
Charlie Reisc0f17d2d2021-01-12 18:52:491499 // here and classify it as NEW_ENTRY, as such navigations should be treated
Nasko Oskov332593c2018-08-16 17:21:341500 // as new with replacement.
Nasko Oskovae49e292020-08-13 02:08:511501 trace_return.set_return_reason(
Charlie Reisc0f17d2d2021-01-12 18:52:491502 "nav entry 0, last committed, existing entry");
Yoshisato Yanagisawa2ccba602021-11-17 08:24:061503 return NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY;
avi7c6f35e2015-05-08 17:52:381504 }
1505
Rakina Zata Amnif6950d552020-11-24 03:26:101506 if (pending_entry_ && pending_entry_->GetUniqueID() == nav_entry_id) {
Nasko Oskovaee2f862018-06-15 00:05:521507 // If the SiteInstance of the |pending_entry_| does not match the
1508 // SiteInstance that got committed, treat this as a new navigation with
1509 // replacement. This can happen if back/forward/reload encounters a server
1510 // redirect to a different site or an isolated error page gets successfully
1511 // reloaded into a different SiteInstance.
1512 if (pending_entry_->site_instance() &&
1513 pending_entry_->site_instance() != rfh->GetSiteInstance()) {
Charlie Reisc0f17d2d2021-01-12 18:52:491514 trace_return.set_return_reason("pending matching nav entry, new entry");
Yoshisato Yanagisawa2ccba602021-11-17 08:24:061515 return NAVIGATION_TYPE_MAIN_FRAME_NEW_ENTRY;
Nasko Oskovaee2f862018-06-15 00:05:521516 }
creis77c9aa32015-09-25 19:59:421517
Nasko Oskovaee2f862018-06-15 00:05:521518 if (pending_entry_index_ == -1) {
1519 // In this case, we have a pending entry for a load of a new URL but Blink
1520 // didn't do a new navigation (params.did_create_new_entry). First check
1521 // to make sure Blink didn't treat a new cross-process navigation as
1522 // inert, and thus set params.did_create_new_entry to false. In that case,
Charlie Reis7e2cb6d2021-01-26 01:27:161523 // we must treat it as NEW rather than the converted reload case below,
1524 // since the new SiteInstance doesn't match the last committed entry.
Nasko Oskovaee2f862018-06-15 00:05:521525 if (!GetLastCommittedEntry() ||
1526 GetLastCommittedEntry()->site_instance() != rfh->GetSiteInstance()) {
Charlie Reis7e2cb6d2021-01-26 01:27:161527 trace_return.set_return_reason("new pending, new entry");
Yoshisato Yanagisawa2ccba602021-11-17 08:24:061528 return NAVIGATION_TYPE_MAIN_FRAME_NEW_ENTRY;
Nasko Oskovaee2f862018-06-15 00:05:521529 }
1530
1531 // Otherwise, this happens when you press enter in the URL bar to reload.
Charlie Reis7e2cb6d2021-01-26 01:27:161532 // We will create a pending entry, but NavigateWithoutEntry will convert
1533 // it to a reload since it's the same page and not create a new entry for
1534 // it. (The user doesn't want to have a new back/forward entry when they
1535 // do this.) Therefore we want to just ignore the pending entry and go
1536 // back to where we were (the "existing entry").
1537 trace_return.set_return_reason("new pending, existing (same) entry");
Yoshisato Yanagisawa2ccba602021-11-17 08:24:061538 return NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY;
Nasko Oskovaee2f862018-06-15 00:05:521539 }
avi7c6f35e2015-05-08 17:52:381540 }
1541
creis26d22632017-04-21 20:23:561542 // Everything below here is assumed to be an existing entry, but if there is
1543 // no last committed entry, we must consider it a new navigation instead.
Nasko Oskovae49e292020-08-13 02:08:511544 if (!GetLastCommittedEntry()) {
Charlie Reisc0f17d2d2021-01-12 18:52:491545 trace_return.set_return_reason("no last committed, new entry");
Yoshisato Yanagisawa2ccba602021-11-17 08:24:061546 return NAVIGATION_TYPE_MAIN_FRAME_NEW_ENTRY;
Nasko Oskovae49e292020-08-13 02:08:511547 }
creis26d22632017-04-21 20:23:561548
Rakina Zata Amni153d5702021-09-13 22:48:001549 if (navigation_request->commit_params().intended_as_new_entry) {
avi7c6f35e2015-05-08 17:52:381550 // This was intended to be a navigation to a new entry but the pending entry
Charlie Reisc0f17d2d2021-01-12 18:52:491551 // got cleared in the meanwhile. Classify as EXISTING_ENTRY because we may
1552 // or may not have a pending entry.
Charlie Reis7e2cb6d2021-01-26 01:27:161553 trace_return.set_return_reason("intended as new entry, existing entry");
Yoshisato Yanagisawa2ccba602021-11-17 08:24:061554 return NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY;
avi7c6f35e2015-05-08 17:52:381555 }
1556
Rakina Zata Amni3a1c0ec2021-04-15 03:35:121557 if (navigation_request->DidEncounterError() &&
1558 failed_pending_entry_id_ != 0 &&
Rakina Zata Amnif6950d552020-11-24 03:26:101559 nav_entry_id == failed_pending_entry_id_) {
avi7c6f35e2015-05-08 17:52:381560 // If the renderer was going to a new pending entry that got cleared because
1561 // of an error, this is the case of the user trying to retry a failed load
Charlie Reisc0f17d2d2021-01-12 18:52:491562 // by pressing return. Classify as EXISTING_ENTRY because we probably don't
avi7c6f35e2015-05-08 17:52:381563 // have a pending entry.
Nasko Oskovae49e292020-08-13 02:08:511564 trace_return.set_return_reason(
Charlie Reisc0f17d2d2021-01-12 18:52:491565 "unreachable, matching pending, existing entry");
Yoshisato Yanagisawa2ccba602021-11-17 08:24:061566 return NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY;
avi7c6f35e2015-05-08 17:52:381567 }
1568
Charlie Reisc0f17d2d2021-01-12 18:52:491569 // Now we know that the notification is for an existing entry; find it.
Rakina Zata Amnif6950d552020-11-24 03:26:101570 int existing_entry_index = GetEntryIndexWithUniqueID(nav_entry_id);
Nasko Oskovae49e292020-08-13 02:08:511571 trace_return.traced_value()->SetInteger("existing_entry_index",
1572 existing_entry_index);
avi7c6f35e2015-05-08 17:52:381573 if (existing_entry_index == -1) {
avi5cad4912015-06-19 05:25:441574 // The renderer has committed a navigation to an entry that no longer
1575 // exists. Because the renderer is showing that page, resurrect that entry.
Charlie Reisc0f17d2d2021-01-12 18:52:491576 trace_return.set_return_reason("existing entry -1, new entry");
Yoshisato Yanagisawa2ccba602021-11-17 08:24:061577 return NAVIGATION_TYPE_MAIN_FRAME_NEW_ENTRY;
avi7c6f35e2015-05-08 17:52:381578 }
1579
avi7c6f35e2015-05-08 17:52:381580 // Since we weeded out "new" navigations above, we know this is an existing
1581 // (back/forward) navigation.
Charlie Reisc0f17d2d2021-01-12 18:52:491582 trace_return.set_return_reason("default return, existing entry");
Yoshisato Yanagisawa2ccba602021-11-17 08:24:061583 return NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY;
avi7c6f35e2015-05-08 17:52:381584}
1585
Rakina Zata Amni3460d382021-10-29 00:43:371586void NavigationControllerImpl::UpdateNavigationEntryDetails(
1587 NavigationEntryImpl* entry,
1588 RenderFrameHostImpl* rfh,
1589 const mojom::DidCommitProvisionalLoadParams& params,
1590 NavigationRequest* request,
1591 NavigationEntryImpl::UpdatePolicy update_policy,
Rakina Zata Amnia4e27222021-12-22 01:05:001592 bool is_new_entry,
1593 LoadCommittedDetails* commit_details) {
Rakina Zata Amni3460d382021-10-29 00:43:371594 // Update the FrameNavigationEntry.
Rakina Zata Amniafd3c6582021-11-30 06:19:171595
1596 std::vector<GURL> redirects;
Rakina Zata Amni3460d382021-10-29 00:43:371597 entry->AddOrUpdateFrameEntry(
1598 rfh->frame_tree_node(), update_policy, params.item_sequence_number,
1599 params.document_sequence_number, params.app_history_key,
1600 rfh->GetSiteInstance(), nullptr, params.url,
1601 GetCommittedOriginForFrameEntry(params, request),
Rakina Zata Amniafd3c6582021-11-30 06:19:171602 Referrer(*params.referrer),
1603 request ? request->common_params().initiator_origin : params.origin,
1604 request ? request->GetRedirectChain() : redirects, params.page_state,
1605 params.method, params.post_id, nullptr /* blob_url_loader_factory */,
1606 (request && request->web_bundle_navigation_info())
Rakina Zata Amni3460d382021-10-29 00:43:371607 ? request->web_bundle_navigation_info()->Clone()
1608 : nullptr,
Rakina Zata Amniafd3c6582021-11-30 06:19:171609 (request ? request->GetSubresourceWebBundleNavigationInfo() : nullptr),
Rakina Zata Amni3460d382021-10-29 00:43:371610 ComputePolicyContainerPoliciesForFrameEntry(
Rakina Zata Amniafd3c6582021-11-30 06:19:171611 rfh, request && request->IsSameDocument(),
1612 request ? request->common_params().url : params.url));
Rakina Zata Amni3460d382021-10-29 00:43:371613
1614 if (rfh->GetParent()) {
1615 // Only modify the NavigationEntry for main frame navigations.
1616 return;
1617 }
1618 if (entry->update_virtual_url_with_url())
1619 UpdateVirtualURLToURL(entry, params.url);
1620 // Don't use the page type from the pending entry. Some interstitial page
1621 // may have set the type to interstitial. Once we commit, however, the page
1622 // type must always be normal or error.
Rakina Zata Amniafd3c6582021-11-30 06:19:171623 entry->set_page_type((request && request->DidEncounterError())
1624 ? PAGE_TYPE_ERROR
1625 : PAGE_TYPE_NORMAL);
Rakina Zata Amnia4e27222021-12-22 01:05:001626 if (commit_details) {
Rakina Zata Amniddf10502022-01-15 02:56:551627 // Retain the "initial NavigationEntry" status if needed.
1628 entry->set_is_initial_entry(commit_details->should_stay_as_initial_entry);
Rakina Zata Amnia4e27222021-12-22 01:05:001629 }
Rakina Zata Amniddf10502022-01-15 02:56:551630
Rakina Zata Amni3460d382021-10-29 00:43:371631 if (is_new_entry) {
1632 // Some properties of the NavigationEntry are only set when the entry is
1633 // new (we aren't reusing it).
1634 entry->SetTransitionType(params.transition);
Rakina Zata Amniafd3c6582021-11-30 06:19:171635 entry->SetOriginalRequestURL(request ? request->GetOriginalRequestURL()
1636 : GURL::EmptyGURL());
Rakina Zata Amni3460d382021-10-29 00:43:371637 DCHECK_EQ(rfh->is_overriding_user_agent(), params.is_overriding_user_agent);
1638 entry->SetIsOverridingUserAgent(params.is_overriding_user_agent);
1639 } else {
1640 // We are reusing the NavigationEntry. The site instance will normally be
1641 // the same except for a few cases:
1642 // 1) session restore, when no site instance will be assigned or
1643 // 2) redirect, when the site instance is reset.
1644 DCHECK(!entry->site_instance() || !entry->GetRedirectChain().empty() ||
1645 entry->site_instance() == rfh->GetSiteInstance());
1646 }
1647}
1648
Rakina Zata Amniafd3c6582021-11-30 06:19:171649void NavigationControllerImpl::CreateInitialEntry() {
1650 DCHECK_EQ(entries_.size(), 0u);
1651 RenderFrameHostImpl* rfh = frame_tree_.root()->current_frame_host();
1652 auto params = mojom::DidCommitProvisionalLoadParams::New();
1653 // The initial NavigationEntry's URL is the empty URL. This preserves the old
1654 // behavior of WebContent's GetLastCommittedURL() and GetVisibleURL() from
1655 // before we have initial NavigationEntries.
1656 params->url = GURL::EmptyGURL();
1657 params->http_status_code = 0;
1658 params->url_is_unreachable = false;
1659 params->method = "GET";
1660 params->should_replace_current_entry = false;
1661 params->post_id = -1;
1662 params->embedding_token = base::UnguessableToken::Create();
1663 params->navigation_token = base::UnguessableToken::Create();
1664 params->did_create_new_entry = true;
1665 params->origin = rfh->GetLastCommittedOrigin();
1666 params->should_update_history = true;
1667 params->item_sequence_number = 0;
1668 params->document_sequence_number = 0;
1669 bool is_in_fenced_frame_tree = rfh->frame_tree_node()->IsInFencedFrameTree();
1670 params->transition = is_in_fenced_frame_tree
1671 ? ui::PAGE_TRANSITION_AUTO_SUBFRAME
1672 : ui::PAGE_TRANSITION_LINK;
1673 params->referrer = blink::mojom::Referrer::New();
1674
1675 // Create and insert the initial NavigationEntry.
1676 auto new_entry = std::make_unique<NavigationEntryImpl>(
1677 rfh->GetSiteInstance(), params->url, Referrer(*params->referrer),
1678 rfh->GetLastCommittedOrigin(), std::u16string() /* title */,
1679 ui::PAGE_TRANSITION_TYPED, false /* renderer_initiated */,
1680 nullptr /* blob_url_loader_factory */, true /* is_initial_entry */);
1681 UpdateNavigationEntryDetails(
1682 new_entry.get(), rfh, *params, nullptr /* request */,
Rakina Zata Amnia4e27222021-12-22 01:05:001683 NavigationEntryImpl::UpdatePolicy::kUpdate, true /* is_new_entry */,
1684 nullptr /* commit_details */);
Rakina Zata Amniafd3c6582021-11-30 06:19:171685
1686 InsertOrReplaceEntry(std::move(new_entry), false /* replace_entry */,
1687 false /* was_post_commit_error */,
Rakina Zata Amnia4e27222021-12-22 01:05:001688 is_in_fenced_frame_tree, nullptr /* commit_details */);
Rakina Zata Amniafd3c6582021-11-30 06:19:171689}
1690
Charlie Reisc0f17d2d2021-01-12 18:52:491691void NavigationControllerImpl::RendererDidNavigateToNewEntry(
creis3da03872015-02-20 21:12:321692 RenderFrameHostImpl* rfh,
arthursonzogni73fe3212020-11-17 13:24:071693 const mojom::DidCommitProvisionalLoadParams& params,
eugenebut604866f2017-05-10 21:35:361694 bool is_same_document,
clamy3bf35e3c2016-11-10 15:59:441695 bool replace_entry,
Shivani Sharmaffb32b82019-04-09 16:58:471696 bool previous_document_was_activated,
Rakina Zata Amnia4e27222021-12-22 01:05:001697 NavigationRequest* request,
1698 LoadCommittedDetails* commit_details) {
dcheng9bfa5162016-04-09 01:00:571699 std::unique_ptr<NavigationEntryImpl> new_entry;
Anton Bikineevf62d1bf2021-05-15 17:56:071700 const absl::optional<url::Origin>& initiator_origin =
Mohamed Abdelhalim833de902019-09-16 17:41:451701 request->common_params().initiator_origin;
Lukasz Anforowicz435bcb582019-07-12 20:50:061702
creisf49dfc92016-07-26 17:05:181703 // First check if this is an in-page navigation. If so, clone the current
1704 // entry instead of looking at the pending entry, because the pending entry
1705 // does not have any subframe history items.
eugenebut604866f2017-05-10 21:35:361706 if (is_same_document && GetLastCommittedEntry()) {
Patrick Monette50e8bd82019-06-13 22:40:451707 auto frame_entry = base::MakeRefCounted<FrameNavigationEntry>(
Charles Reisd2a509f2017-09-27 23:47:481708 rfh->frame_tree_node()->unique_name(), params.item_sequence_number,
Nate Chapinfbfe5af2021-06-10 17:22:081709 params.document_sequence_number, params.app_history_key,
1710 rfh->GetSiteInstance(), nullptr, params.url,
1711 GetCommittedOriginForFrameEntry(params, request),
Rakina Zata Amni82fafba2021-03-11 07:07:091712 Referrer(*params.referrer), initiator_origin,
1713 request->GetRedirectChain(), params.page_state, params.method,
1714 params.post_id, nullptr /* blob_url_loader_factory */,
Antonio Sartori78a749f2020-11-30 12:03:391715 nullptr /* web_bundle_navigation_info */,
Kunihiko Sakamoto346a74e2021-03-10 08:57:481716 request->GetSubresourceWebBundleNavigationInfo(),
Antonio Sartori78a749f2020-11-30 12:03:391717 // We will set the document policies later in this function.
Titouan Rigoudy6ec70402021-02-02 15:42:191718 nullptr /* policy_container_policies */);
Charles Reisf44482022017-10-13 21:15:031719
creisf49dfc92016-07-26 17:05:181720 new_entry = GetLastCommittedEntry()->CloneAndReplace(
Harkiran Bolaria081c5c22021-09-13 08:44:531721 frame_entry, true, request->frame_tree_node(), frame_tree_.root());
Mike West800532c2021-10-14 09:26:521722 if (new_entry->GetURL().DeprecatedGetOriginAsURL() !=
1723 params.url.DeprecatedGetOriginAsURL()) {
jama78746e2017-02-22 17:21:571724 // TODO(jam): we had one report of this with a URL that was redirecting to
1725 // only tildes. Until we understand that better, don't copy the cert in
1726 // this case.
1727 new_entry->GetSSL() = SSLStatus();
jama78746e2017-02-22 17:21:571728 }
creisf49dfc92016-07-26 17:05:181729
Patrick Monette50e8bd82019-06-13 22:40:451730 // It is expected that |frame_entry| is now owned by |new_entry|. This means
1731 // that |frame_entry| should now have a reference count of exactly 2: one
1732 // due to the local variable |frame_entry|, and another due to |new_entry|
1733 // also retaining one. This should never fail, because it's the main frame.
1734 CHECK(!frame_entry->HasOneRef() && frame_entry->HasAtLeastOneRef());
creisf49dfc92016-07-26 17:05:181735 }
1736
Harkiran Bolaria59290d62021-03-17 01:53:011737 // If this is an activation navigation from a prerendered page, transfer the
1738 // new entry from an entry already created and stored in the
1739 // NavigationRequest. |new_entry| will not have been set prior to this as
1740 // |is_same_document| is mutually exclusive with
1741 // |IsPrerenderedPageActivation|.
1742 if (request->IsPrerenderedPageActivation()) {
1743 DCHECK(!is_same_document);
1744 DCHECK(!new_entry);
1745 new_entry = request->TakePrerenderNavigationEntry();
1746 DCHECK(new_entry);
1747 }
1748
Charlie Reisc0f17d2d2021-01-12 18:52:491749 // Only make a copy of the pending entry if it is appropriate for the new
1750 // document that just loaded. Verify this by checking if the entry corresponds
Mohamed Abdelhalim833de902019-09-16 17:41:451751 // to the given NavigationRequest. Additionally, coarsely check that:
csharrison9a9142bc42016-03-01 17:24:041752 // 1. The SiteInstance hasn't been assigned to something else.
1753 // 2. The pending entry was intended as a new entry, rather than being a
1754 // history navigation that was interrupted by an unrelated,
1755 // renderer-initiated navigation.
1756 // TODO(csharrison): Investigate whether we can remove some of the coarser
1757 // checks.
Mohamed Abdelhalim833de902019-09-16 17:41:451758 if (!new_entry && PendingEntryMatchesRequest(request) &&
1759 pending_entry_index_ == -1 &&
[email protected]6dd86ab2013-02-27 00:30:341760 (!pending_entry_->site_instance() ||
[email protected]27dd82fd2014-03-03 22:11:431761 pending_entry_->site_instance() == rfh->GetSiteInstance())) {
creisef4a0cb2015-03-12 19:14:351762 new_entry = pending_entry_->Clone();
[email protected]e9ba4472008-09-14 15:42:431763
Camille Lamy62b826012019-02-26 09:15:471764 new_entry->GetSSL() =
Mohamed Abdelhalim833de902019-09-16 17:41:451765 SSLStatus(request->GetSSLInfo().value_or(net::SSLInfo()));
creisf49dfc92016-07-26 17:05:181766 }
1767
Charlie Reisc0f17d2d2021-01-12 18:52:491768 // For cross-document commits with no matching pending entry, create a new
1769 // entry.
creisf49dfc92016-07-26 17:05:181770 if (!new_entry) {
Lukasz Anforowicz435bcb582019-07-12 20:50:061771 new_entry = std::make_unique<NavigationEntryImpl>(
arthursonzogni73fe3212020-11-17 13:24:071772 rfh->GetSiteInstance(), params.url, Referrer(*params.referrer),
1773 initiator_origin,
Jan Wilken Dörrieaace0cfef2021-03-11 22:01:581774 std::u16string(), // title
Mohamed Abdelhalim833de902019-09-16 17:41:451775 params.transition, request->IsRendererInitiated(),
Rakina Zata Amniafd3c6582021-11-30 06:19:171776 nullptr, // blob_url_loader_factory
1777 false); // is_initial_entry
[email protected]f8f93eb2012-09-25 03:06:241778
1779 // Find out whether the new entry needs to update its virtual URL on URL
1780 // change and set up the entry accordingly. This is needed to correctly
1781 // update the virtual URL when replaceState is called after a pushState.
1782 GURL url = params.url;
1783 bool needs_update = false;
Charlie Reisc0f17d2d2021-01-12 18:52:491784 // When navigating to a new entry, give the browser URL handler a chance to
[email protected]f1eb87a2011-05-06 17:49:411785 // update the virtual URL based on the new URL. For example, this is needed
1786 // to show chrome://bookmarks/#1 when the bookmarks webui extension changes
1787 // the URL.
Rakina Zata Amni3460d382021-10-29 00:43:371788 BrowserURLHandlerImpl::GetInstance()->RewriteURLIfNecessary(
1789 &url, browser_context_, &needs_update);
1790 new_entry->set_update_virtual_url_with_url(needs_update);
1791
Camille Lamy62b826012019-02-26 09:15:471792 new_entry->GetSSL() =
Mohamed Abdelhalim833de902019-09-16 17:41:451793 SSLStatus(request->GetSSLInfo().value_or(net::SSLInfo()));
[email protected]e9ba4472008-09-14 15:42:431794 }
1795
Harkiran Bolaria59290d62021-03-17 01:53:011796 // TODO(crbug.com/1179428) - determine which parts of the entry need to be set
1797 // for prerendered contents, if any. This is because prerendering/activation
1798 // technically won't be creating a new document. Unlike BFCache, prerendering
1799 // creates a new NavigationEntry rather than using an existing one.
1800 if (!request->IsPrerenderedPageActivation()) {
Rakina Zata Amni3460d382021-10-29 00:43:371801 UpdateNavigationEntryDetails(new_entry.get(), rfh, params, request,
1802 NavigationEntryImpl::UpdatePolicy::kUpdate,
Rakina Zata Amnia4e27222021-12-22 01:05:001803 true /* is_new_entry */, commit_details);
creis8b5cd4c2015-06-19 00:11:081804
Harkiran Bolaria59290d62021-03-17 01:53:011805 // history.pushState() is classified as a navigation to a new page, but sets
1806 // is_same_document to true. In this case, we already have the title and
1807 // favicon available, so set them immediately.
1808 if (is_same_document && GetLastCommittedEntry()) {
1809 new_entry->SetTitle(GetLastCommittedEntry()->GetTitle());
1810 new_entry->GetFavicon() = GetLastCommittedEntry()->GetFavicon();
1811 }
[email protected]3a868f212014-08-09 10:41:191812 }
[email protected]ff64b3e2014-05-31 04:07:331813
[email protected]60d6cca2013-04-30 08:47:131814 DCHECK(!params.history_list_was_cleared || !replace_entry);
1815 // The browser requested to clear the session history when it initiated the
1816 // navigation. Now we know that the renderer has updated its state accordingly
1817 // and it is safe to also clear the browser side history.
1818 if (params.history_list_was_cleared) {
Rakina Zata Amniddf10502022-01-15 02:56:551819 DiscardNonCommittedEntriesWithCommitDetails(commit_details);
[email protected]60d6cca2013-04-30 08:47:131820 entries_.clear();
1821 last_committed_entry_index_ = -1;
1822 }
1823
Nasko Oskovaee2f862018-06-15 00:05:521824 // If this is a new navigation with replacement and there is a
1825 // pending_entry_ which matches the navigation reported by the renderer
1826 // process, then it should be the one replaced, so update the
1827 // last_committed_entry_index_ to use it.
1828 if (replace_entry && pending_entry_index_ != -1 &&
Rakina Zata Amnif6950d552020-11-24 03:26:101829 pending_entry_->GetUniqueID() == request->commit_params().nav_entry_id) {
Nasko Oskovaee2f862018-06-15 00:05:521830 last_committed_entry_index_ = pending_entry_index_;
1831 }
1832
Alexander Timine3ec4192020-04-20 16:39:401833 SetShouldSkipOnBackForwardUIIfNeeded(
shivanigithube92c33da2020-09-14 13:01:411834 replace_entry, previous_document_was_activated,
Alexander Timine3ec4192020-04-20 16:39:401835 request->IsRendererInitiated(), request->GetPreviousPageUkmSourceId());
shivanisha41f04c52018-12-12 15:52:051836
Carlos IL42b416592019-10-07 23:10:361837 InsertOrReplaceEntry(std::move(new_entry), replace_entry,
Dave Tapuska87696ae2021-11-18 18:48:311838 !request->post_commit_error_page_html().empty(),
Rakina Zata Amnia4e27222021-12-22 01:05:001839 rfh->frame_tree_node()->IsInFencedFrameTree(),
1840 commit_details);
[email protected]e9ba4472008-09-14 15:42:431841}
1842
Charlie Reisc0f17d2d2021-01-12 18:52:491843void NavigationControllerImpl::RendererDidNavigateToExistingEntry(
creis3da03872015-02-20 21:12:321844 RenderFrameHostImpl* rfh,
arthursonzogni73fe3212020-11-17 13:24:071845 const mojom::DidCommitProvisionalLoadParams& params,
eugenebut604866f2017-05-10 21:35:361846 bool is_same_document,
jam48cea9082017-02-15 06:13:291847 bool was_restored,
Mohamed Abdelhalim833de902019-09-16 17:41:451848 NavigationRequest* request,
Rakina Zata Amnia4e27222021-12-22 01:05:001849 bool keep_pending_entry,
1850 LoadCommittedDetails* commit_details) {
creis26d22632017-04-21 20:23:561851 DCHECK(GetLastCommittedEntry()) << "ClassifyNavigation should guarantee "
1852 << "that a last committed entry exists.";
1853
[email protected]e9ba4472008-09-14 15:42:431854 // We should only get here for main frame navigations.
avi39c1edd32015-06-04 20:06:001855 DCHECK(!rfh->GetParent());
[email protected]e9ba4472008-09-14 15:42:431856
Charlie Reis7e2cb6d2021-01-26 01:27:161857 NavigationEntryImpl* entry = nullptr;
Rakina Zata Amni153d5702021-09-13 22:48:001858 if (request->commit_params().intended_as_new_entry) {
Charlie Reis7e2cb6d2021-01-26 01:27:161859 // We're guaranteed to have a last committed entry if intended_as_new_entry
1860 // is true.
avicbdc4c12015-07-01 16:07:111861 entry = GetLastCommittedEntry();
Charlie Reis7e2cb6d2021-01-26 01:27:161862 DCHECK(entry);
1863
1864 // If the NavigationRequest matches a new pending entry and is classified as
1865 // EXISTING_ENTRY, then it is a navigation to the same URL that was
1866 // converted to a reload, such as a user pressing enter in the omnibox.
1867 if (pending_entry_ && pending_entry_index_ == -1 &&
1868 pending_entry_->GetUniqueID() ==
1869 request->commit_params().nav_entry_id) {
1870 // Note: The pending entry will usually have a real ReloadType here, but
1871 // it can still be ReloadType::NONE in cases that
1872 // ShouldTreatNavigationAsReload returns false (e.g., POST, view-source).
1873
1874 // If we classified this correctly, the SiteInstance should not have
1875 // changed.
1876 CHECK_EQ(entry->site_instance(), rfh->GetSiteInstance());
1877
1878 // For converted reloads, we assign the entry's unique ID to be that of
1879 // the new one. Since this is always the result of a user action, we want
1880 // to dismiss infobars, etc. like a regular user-initiated navigation.
1881 entry->set_unique_id(pending_entry_->GetUniqueID());
1882
1883 // The extra headers may have changed due to reloading with different
1884 // headers.
1885 entry->set_extra_headers(pending_entry_->extra_headers());
1886 }
1887 // Otherwise, this was intended as a new entry but the pending entry was
1888 // lost in the meantime and no new entry was created. We are stuck at the
1889 // last committed entry.
1890
1891 // Even if this is a converted reload from pressing enter in the omnibox,
1892 // the server could redirect, requiring an update to the SSL status. If this
1893 // is a same document navigation, though, there's no SSLStatus in the
Mohamed Abdelhalim833de902019-09-16 17:41:451894 // NavigationRequest so don't overwrite the existing entry's SSLStatus.
Charlie Reis7e2cb6d2021-01-26 01:27:161895 if (!is_same_document) {
Camille Lamy62b826012019-02-26 09:15:471896 entry->GetSSL() =
Mohamed Abdelhalim833de902019-09-16 17:41:451897 SSLStatus(request->GetSSLInfo().value_or(net::SSLInfo()));
Charlie Reis7e2cb6d2021-01-26 01:27:161898 }
Rakina Zata Amnif6950d552020-11-24 03:26:101899 } else if (const int nav_entry_id = request->commit_params().nav_entry_id) {
avicbdc4c12015-07-01 16:07:111900 // This is a browser-initiated navigation (back/forward/reload).
Rakina Zata Amnif6950d552020-11-24 03:26:101901 entry = GetEntryWithUniqueID(nav_entry_id);
jamd208b902016-09-01 16:58:161902
eugenebut604866f2017-05-10 21:35:361903 if (is_same_document) {
Mohamed Abdelhalim833de902019-09-16 17:41:451904 // There's no SSLStatus in the NavigationRequest for same document
eugenebut604866f2017-05-10 21:35:361905 // navigations, so normally we leave |entry|'s SSLStatus as is. However if
1906 // this was a restored same document navigation entry, then it won't have
1907 // an SSLStatus. So we need to copy over the SSLStatus from the entry that
1908 // navigated it.
jam48cea9082017-02-15 06:13:291909 NavigationEntryImpl* last_entry = GetLastCommittedEntry();
Mike West800532c2021-10-14 09:26:521910 if (entry->GetURL().DeprecatedGetOriginAsURL() ==
1911 last_entry->GetURL().DeprecatedGetOriginAsURL() &&
jam48cea9082017-02-15 06:13:291912 last_entry->GetSSL().initialized && !entry->GetSSL().initialized &&
1913 was_restored) {
1914 entry->GetSSL() = last_entry->GetSSL();
1915 }
1916 } else {
Mohamed Abdelhalim833de902019-09-16 17:41:451917 // In rapid back/forward navigations |request| sometimes won't have a cert
1918 // (http://crbug.com/727892). So we use the request's cert if it exists,
John Abd-El-Malek3f247082017-12-07 19:02:191919 // otherwise we only reuse the existing cert if the origins match.
Mohamed Abdelhalim833de902019-09-16 17:41:451920 if (request->GetSSLInfo().has_value() &&
1921 request->GetSSLInfo()->is_valid()) {
1922 entry->GetSSL() = SSLStatus(*(request->GetSSLInfo()));
Mike West800532c2021-10-14 09:26:521923 } else if (entry->GetURL().DeprecatedGetOriginAsURL() !=
1924 request->GetURL().DeprecatedGetOriginAsURL()) {
John Abd-El-Malek3f247082017-12-07 19:02:191925 entry->GetSSL() = SSLStatus();
1926 }
jam48cea9082017-02-15 06:13:291927 }
avicbdc4c12015-07-01 16:07:111928 } else {
1929 // This is renderer-initiated. The only kinds of renderer-initated
Rakina Zata Amni557afb92021-07-17 04:39:571930 // navigations that are EXISTING_ENTRY are same-document navigations that
1931 // result in replacement (e.g. history.replaceState(), location.replace(),
1932 // forced replacements for trivial session history contexts). For these
1933 // cases, we reuse the last committed entry.
avicbdc4c12015-07-01 16:07:111934 entry = GetLastCommittedEntry();
jam0576b132016-09-07 05:13:101935
Mikel Astizba9cf2fd2017-12-17 10:38:101936 // TODO(crbug.com/751023): Set page transition type to PAGE_TRANSITION_LINK
1937 // to avoid misleading interpretations (e.g. URLs paired with
1938 // PAGE_TRANSITION_TYPED that haven't actually been typed) as well as to fix
1939 // the inconsistency with what we report to observers (PAGE_TRANSITION_LINK
1940 // | PAGE_TRANSITION_CLIENT_REDIRECT).
1941
Lucas Furukawa Gadani5553a1582019-01-08 18:55:571942 CopyReplacedNavigationEntryDataIfPreviouslyEmpty(entry, entry);
Mikel Astizba9cf2fd2017-12-17 10:38:101943
eugenebut604866f2017-05-10 21:35:361944 // If this is a same document navigation, then there's no SSLStatus in the
Mohamed Abdelhalim833de902019-09-16 17:41:451945 // NavigationRequest so don't overwrite the existing entry's SSLStatus.
eugenebut604866f2017-05-10 21:35:361946 if (!is_same_document)
Camille Lamy62b826012019-02-26 09:15:471947 entry->GetSSL() =
Mohamed Abdelhalim833de902019-09-16 17:41:451948 SSLStatus(request->GetSSLInfo().value_or(net::SSLInfo()));
avicbdc4c12015-07-01 16:07:111949 }
1950 DCHECK(entry);
[email protected]e9ba4472008-09-14 15:42:431951
Rakina Zata Amni3460d382021-10-29 00:43:371952 UpdateNavigationEntryDetails(entry, rfh, params, request,
1953 NavigationEntryImpl::UpdatePolicy::kUpdate,
Rakina Zata Amnia4e27222021-12-22 01:05:001954 false /* is_new_entry */, commit_details);
creis22a7b4c2016-04-28 07:20:301955
[email protected]5ccd4dc2012-10-24 02:28:141956 // The redirected to page should not inherit the favicon from the previous
1957 // page.
eugenebut604866f2017-05-10 21:35:361958 if (ui::PageTransitionIsRedirect(params.transition) && !is_same_document)
[email protected]91a4ff82012-10-29 20:29:481959 entry->GetFavicon() = FaviconStatus();
[email protected]5ccd4dc2012-10-24 02:28:141960
Peter Boströmd7592132019-01-30 04:50:311961 // We should also usually discard the pending entry if it corresponds to a
1962 // different navigation, since that one is now likely canceled. In rare
1963 // cases, we leave the pending entry for another navigation in place when we
1964 // know it is still ongoing, to avoid a flicker in the omnibox (see
1965 // https://crbug.com/900036).
[email protected]e9ba4472008-09-14 15:42:431966 //
1967 // Note that we need to use the "internal" version since we don't want to
1968 // actually change any other state, just kill the pointer.
Peter Boströmd7592132019-01-30 04:50:311969 if (!keep_pending_entry)
Rakina Zata Amnia4e27222021-12-22 01:05:001970 DiscardNonCommittedEntriesWithCommitDetails(commit_details);
[email protected]40bcc302009-03-02 20:50:391971
Carlos IL4dea8902020-05-26 15:14:291972 // Update the last committed index to reflect the committed entry.
avicbdc4c12015-07-01 16:07:111973 last_committed_entry_index_ = GetIndexOfEntry(entry);
[email protected]e9ba4472008-09-14 15:42:431974}
1975
[email protected]d202a7c2012-01-04 07:53:471976void NavigationControllerImpl::RendererDidNavigateNewSubframe(
creis3da03872015-02-20 21:12:321977 RenderFrameHostImpl* rfh,
arthursonzogni73fe3212020-11-17 13:24:071978 const mojom::DidCommitProvisionalLoadParams& params,
eugenebut604866f2017-05-10 21:35:361979 bool is_same_document,
Shivani Sharmaffb32b82019-04-09 16:58:471980 bool replace_entry,
1981 bool previous_document_was_activated,
Rakina Zata Amnia4e27222021-12-22 01:05:001982 NavigationRequest* request,
1983 LoadCommittedDetails* commit_details) {
avi25f5f9e2015-07-17 20:08:261984 DCHECK(ui::PageTransitionCoreTypeIs(params.transition,
1985 ui::PAGE_TRANSITION_MANUAL_SUBFRAME));
Rakina Zata Amniddf10502022-01-15 02:56:551986 // The NEW_SUBFRAME path should never result in an initial NavigationEntry.
1987 DCHECK(!commit_details->should_stay_as_initial_entry);
[email protected]09b8f82f2009-06-16 20:22:111988
[email protected]e9ba4472008-09-14 15:42:431989 // Manual subframe navigations just get the current entry cloned so the user
1990 // can go back or forward to it. The actual subframe information will be
1991 // stored in the page state for each of those entries. This happens out of
1992 // band with the actual navigations.
[email protected]4c27ba82008-09-24 16:49:091993 DCHECK(GetLastCommittedEntry()) << "ClassifyNavigation should guarantee "
1994 << "that a last committed entry exists.";
creis96fc55082015-06-13 06:42:381995
Mikel Astizba9cf2fd2017-12-17 10:38:101996 // The DCHECK below documents the fact that we don't know of any situation
1997 // where |replace_entry| is true for subframe navigations. This simplifies
1998 // reasoning about the replacement struct for subframes (see
1999 // CopyReplacedNavigationEntryDataIfPreviouslyEmpty()).
2000 DCHECK(!replace_entry);
2001
Patrick Monette50e8bd82019-06-13 22:40:452002 // This FrameNavigationEntry might not end up being used in the
2003 // CloneAndReplace() call below, if a spot can't be found for it in the tree.
Anton Bikineevf62d1bf2021-05-15 17:56:072004 const absl::optional<url::Origin>& initiator_origin =
Mohamed Abdelhalim833de902019-09-16 17:41:452005 request->common_params().initiator_origin;
Patrick Monette50e8bd82019-06-13 22:40:452006 auto frame_entry = base::MakeRefCounted<FrameNavigationEntry>(
Charles Reisd2a509f2017-09-27 23:47:482007 rfh->frame_tree_node()->unique_name(), params.item_sequence_number,
Nate Chapinfbfe5af2021-06-10 17:22:082008 params.document_sequence_number, params.app_history_key,
2009 rfh->GetSiteInstance(), nullptr, params.url,
2010 GetCommittedOriginForFrameEntry(params, request),
Rakina Zata Amni82fafba2021-03-11 07:07:092011 Referrer(*params.referrer), initiator_origin, request->GetRedirectChain(),
arthursonzogni73fe3212020-11-17 13:24:072012 params.page_state, params.method, params.post_id,
2013 nullptr /* blob_url_loader_factory */,
Tsuyoshi Horo0c605782020-05-27 00:21:032014 request->web_bundle_navigation_info()
2015 ? request->web_bundle_navigation_info()->Clone()
Antonio Sartori78a749f2020-11-30 12:03:392016 : nullptr,
Kunihiko Sakamoto346a74e2021-03-10 08:57:482017 request->GetSubresourceWebBundleNavigationInfo(),
Titouan Rigoudy6ec70402021-02-02 15:42:192018 ComputePolicyContainerPoliciesForFrameEntry(rfh, is_same_document,
Rakina Zata Amniafd3c6582021-11-30 06:19:172019 request->GetURL()));
Charles Reisf44482022017-10-13 21:15:032020
creisce0ef3572017-01-26 17:53:082021 std::unique_ptr<NavigationEntryImpl> new_entry =
2022 GetLastCommittedEntry()->CloneAndReplace(
Patrick Monette50e8bd82019-06-13 22:40:452023 std::move(frame_entry), is_same_document, rfh->frame_tree_node(),
Carlos Caballero40b0efd2021-01-26 11:55:002024 frame_tree_.root());
creise062d542015-08-25 02:01:552025
Alexander Timine3ec4192020-04-20 16:39:402026 SetShouldSkipOnBackForwardUIIfNeeded(
shivanigithube92c33da2020-09-14 13:01:412027 replace_entry, previous_document_was_activated,
Alexander Timine3ec4192020-04-20 16:39:402028 request->IsRendererInitiated(), request->GetPreviousPageUkmSourceId());
Shivani Sharmaffb32b82019-04-09 16:58:472029
creisce0ef3572017-01-26 17:53:082030 // TODO(creis): Update this to add the frame_entry if we can't find the one
Patrick Monette50e8bd82019-06-13 22:40:452031 // to replace, which can happen due to a unique name change. See
2032 // https://crbug.com/607205. For now, the call to CloneAndReplace() will
2033 // delete the |frame_entry| when the function exits if it doesn't get used.
creis96fc55082015-06-13 06:42:382034
Dave Tapuska87696ae2021-11-18 18:48:312035 InsertOrReplaceEntry(std::move(new_entry), replace_entry, false,
Rakina Zata Amnia4e27222021-12-22 01:05:002036 rfh->frame_tree_node()->IsInFencedFrameTree(),
2037 commit_details);
[email protected]e9ba4472008-09-14 15:42:432038}
2039
[email protected]d202a7c2012-01-04 07:53:472040bool NavigationControllerImpl::RendererDidNavigateAutoSubframe(
creis3da03872015-02-20 21:12:322041 RenderFrameHostImpl* rfh,
arthursonzogni73fe3212020-11-17 13:24:072042 const mojom::DidCommitProvisionalLoadParams& params,
Antonio Sartori78a749f2020-11-30 12:03:392043 bool is_same_document,
Nate Chapinc7019dd7d2021-06-25 18:29:252044 bool was_on_initial_empty_document,
Rakina Zata Amnia4e27222021-12-22 01:05:002045 NavigationRequest* request,
2046 LoadCommittedDetails* commit_details) {
avi9f07a0c2015-02-18 22:51:292047 DCHECK(ui::PageTransitionCoreTypeIs(params.transition,
2048 ui::PAGE_TRANSITION_AUTO_SUBFRAME));
2049
[email protected]e9ba4472008-09-14 15:42:432050 // We're guaranteed to have a previously committed entry, and we now need to
2051 // handle navigation inside of a subframe in it without creating a new entry.
2052 DCHECK(GetLastCommittedEntry());
2053
creis913c63ce2016-07-16 19:52:522054 // For newly created subframes, we don't need to send a commit notification.
2055 // This is only necessary for history navigations in subframes.
2056 bool send_commit_notification = false;
2057
Rakina Zata Amnif6950d552020-11-24 03:26:102058 // If |nav_entry_id| is non-zero and matches an existing entry, this
2059 // is a history navigation. Update the last committed index accordingly. If
2060 // we don't recognize the |nav_entry_id|, it might be a recently
2061 // pruned entry. We'll handle it below.
2062 if (const int nav_entry_id = request->commit_params().nav_entry_id) {
2063 int entry_index = GetEntryIndexWithUniqueID(nav_entry_id);
creis3cdc3b02015-05-29 23:00:472064 if (entry_index != -1 && entry_index != last_committed_entry_index_) {
avi98405c22015-05-21 20:47:062065 // Make sure that a subframe commit isn't changing the main frame's
2066 // origin. Otherwise the renderer process may be confused, leading to a
2067 // URL spoof. We can't check the path since that may change
2068 // (https://crbug.com/373041).
creis37988b92016-06-10 18:03:572069 // TODO(creis): For now, restrict this check to HTTP(S) origins, because
2070 // about:blank, file, and unique origins are more subtle to get right.
Charlie Reis95fbca442021-05-21 21:38:242071 // We should use checks similar to RenderFrameHostImpl's
2072 // CanCommitUrlAndOrigin on the main frame during subframe commits.
2073 // See https://crbug.com/1209092.
creis37988b92016-06-10 18:03:572074 const GURL& dest_top_url = GetEntryAtIndex(entry_index)->GetURL();
2075 const GURL& current_top_url = GetLastCommittedEntry()->GetURL();
2076 if (current_top_url.SchemeIsHTTPOrHTTPS() &&
2077 dest_top_url.SchemeIsHTTPOrHTTPS() &&
Mike West800532c2021-10-14 09:26:522078 current_top_url.DeprecatedGetOriginAsURL() !=
2079 dest_top_url.DeprecatedGetOriginAsURL()) {
creisfb6eeb62016-05-10 19:01:512080 bad_message::ReceivedBadMessage(rfh->GetProcess(),
2081 bad_message::NC_AUTO_SUBFRAME);
avi98405c22015-05-21 20:47:062082 }
creis3cdc3b02015-05-29 23:00:472083
creis913c63ce2016-07-16 19:52:522084 // We only need to discard the pending entry in this history navigation
2085 // case. For newly created subframes, there was no pending entry.
avi98405c22015-05-21 20:47:062086 last_committed_entry_index_ = entry_index;
Rakina Zata Amnia4e27222021-12-22 01:05:002087 DiscardNonCommittedEntriesWithCommitDetails(commit_details);
creis913c63ce2016-07-16 19:52:522088
2089 // History navigations should send a commit notification.
2090 send_commit_notification = true;
avi98405c22015-05-21 20:47:062091 }
[email protected]e9ba4472008-09-14 15:42:432092 }
[email protected]f233e4232013-02-23 00:55:142093
creisce0ef3572017-01-26 17:53:082094 // This may be a "new auto" case where we add a new FrameNavigationEntry, or
2095 // it may be a "history auto" case where we update an existing one.
2096 NavigationEntryImpl* last_committed = GetLastCommittedEntry();
Nate Chapin9f169072021-06-09 19:32:372097
2098 // We may want to update |last_committed|'s FrameNavigationEntry (if one
2099 // exists), or we may want to clobber it and create a new one. We update in
2100 // cases where the corresponding FrameNavigationEntry is conceptually similar
2101 // to the document described by the commit params: same-document
2102 // navigations, history traversal to an existing entry, and reloads (including
2103 // a "soft reload" where we navigate to the same url without flagging it as a
2104 // reload). But in the case of a different document that is not logically
2105 // related to the committed FrameNavigationEntry's document (cross-document,
2106 // not same url, not a reload, not a history traversal), we replace rather
2107 // than update.
Nate Chapinc7019dd7d2021-06-25 18:29:252108 //
Nate Chapin9f169072021-06-09 19:32:372109 // In the case where we update, the FrameNavigationEntry will potentially be
2110 // shared across multiple NavigationEntries, and any updates will be reflected
2111 // in all of those NavigationEntries. In the replace case, any existing
2112 // sharing with other NavigationEntries will stop.
Nate Chapinc7019dd7d2021-06-25 18:29:252113 //
2114 // When navigating away from the initial empty document, we also update rather
2115 // than replace. Either update or replace will overwrite the initial empty
2116 // document state for |last_committed|, but if the FrameNavigationEntry for
2117 // the initial empty document is shared across multiple NavigationEntries (due
2118 // to a navigation in another frame), we want to make sure we overwrite the
2119 // initial empty document state everywhere this FrameNavigationEntry is used,
2120 // which is accompished by updating the existing FrameNavigationEntry.
Nate Chapin9f169072021-06-09 19:32:372121 FrameNavigationEntry* last_committed_frame_entry =
2122 last_committed->GetFrameEntry(rfh->frame_tree_node());
2123 NavigationEntryImpl::UpdatePolicy update_policy =
2124 NavigationEntryImpl::UpdatePolicy::kUpdate;
2125 if (request->common_params().navigation_type ==
Minggang Wangb9f3fa92021-07-01 15:30:312126 blink::mojom::NavigationType::DIFFERENT_DOCUMENT &&
Nate Chapin9f169072021-06-09 19:32:372127 last_committed_frame_entry &&
Nate Chapinc7019dd7d2021-06-25 18:29:252128 last_committed_frame_entry->url() != params.url &&
2129 !was_on_initial_empty_document) {
Nate Chapin9f169072021-06-09 19:32:372130 update_policy = NavigationEntryImpl::UpdatePolicy::kReplace;
2131 }
2132
Rakina Zata Amni3460d382021-10-29 00:43:372133 UpdateNavigationEntryDetails(last_committed, rfh, params, request,
Rakina Zata Amnia4e27222021-12-22 01:05:002134 update_policy, false /* is_new_entry */,
2135 commit_details);
creis625a0c7d2015-03-24 23:17:122136
creis913c63ce2016-07-16 19:52:522137 return send_commit_notification;
[email protected]e9ba4472008-09-14 15:42:432138}
2139
[email protected]d202a7c2012-01-04 07:53:472140int NavigationControllerImpl::GetIndexOfEntry(
[email protected]10f417c52011-12-28 21:04:232141 const NavigationEntryImpl* entry) const {
avif16f85a72015-11-13 18:25:032142 for (size_t i = 0; i < entries_.size(); ++i) {
2143 if (entries_[i].get() == entry)
2144 return i;
2145 }
2146 return -1;
[email protected]765b35502008-08-21 00:51:202147}
2148
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572149void NavigationControllerImpl::CopyStateFrom(NavigationController* temp,
Francois Dorayeaace782017-06-21 16:37:242150 bool needs_reload) {
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572151 NavigationControllerImpl* source =
2152 static_cast<NavigationControllerImpl*>(temp);
[email protected]ce3fa3c2009-04-20 19:55:572153 // Verify that we look new.
Rakina Zata Amniafd3c6582021-11-30 06:19:172154 DCHECK_EQ(1, GetEntryCount());
2155 DCHECK(GetLastCommittedEntry()->IsInitialEntry());
Lei Zhang96031532019-10-10 19:05:472156 DCHECK(!GetPendingEntry());
Rakina Zata Amniafd3c6582021-11-30 06:19:172157 entries_.clear();
[email protected]ce3fa3c2009-04-20 19:55:572158
Rakina Zata Amniafd3c6582021-11-30 06:19:172159 if (source->GetEntryCount() == 0) {
2160 NOTREACHED();
2161 return;
2162 }
[email protected]ce3fa3c2009-04-20 19:55:572163
Francois Dorayeaace782017-06-21 16:37:242164 needs_reload_ = needs_reload;
Bo Liucdfa4b12018-11-06 00:21:442165 needs_reload_type_ = NeedsReloadType::kCopyStateFrom;
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572166 InsertEntriesFrom(source, source->GetEntryCount());
[email protected]ce3fa3c2009-04-20 19:55:572167
Fergal Dalya1d569972021-03-16 03:24:532168 for (auto& it : source->session_storage_namespace_map_) {
[email protected]fdac6ade2013-07-20 01:06:302169 SessionStorageNamespaceImpl* source_namespace =
Fergal Dalya1d569972021-03-16 03:24:532170 static_cast<SessionStorageNamespaceImpl*>(it.second.get());
2171 session_storage_namespace_map_[it.first] = source_namespace->Clone();
Aaron Colwellb731a0ae2021-03-19 19:14:472172 OnStoragePartitionIdAdded(it.first);
[email protected]fdac6ade2013-07-20 01:06:302173 }
[email protected]4e6419c2010-01-15 04:50:342174
Lukasz Anforowicz0de0f452020-12-02 19:57:152175 FinishRestore(source->last_committed_entry_index_, RestoreType::kRestored);
[email protected]ce3fa3c2009-04-20 19:55:572176}
2177
Aran Gilman37d11632019-10-08 23:07:152178void NavigationControllerImpl::CopyStateFromAndPrune(NavigationController* temp,
2179 bool replace_entry) {
[email protected]474f8512013-05-31 22:31:162180 // It is up to callers to check the invariants before calling this.
[email protected]79368982013-11-13 01:11:012181 CHECK(CanPruneAllButLastCommitted());
[email protected]474f8512013-05-31 22:31:162182
[email protected]d202a7c2012-01-04 07:53:472183 NavigationControllerImpl* source =
2184 static_cast<NavigationControllerImpl*>(temp);
[email protected]e1cd5452010-08-26 18:03:252185
avi2b177592014-12-10 02:08:022186 // Remove all the entries leaving the last committed entry.
[email protected]79368982013-11-13 01:11:012187 PruneAllButLastCommittedInternal();
[email protected]e1cd5452010-08-26 18:03:252188
[email protected]474f8512013-05-31 22:31:162189 // We now have one entry, possibly with a new pending entry. Ensure that
2190 // adding the entries from source won't put us over the limit.
2191 DCHECK_EQ(1, GetEntryCount());
[email protected]e78a6852013-12-13 08:08:572192 if (!replace_entry)
Shivani Sharmad8c8d652019-02-13 17:27:572193 source->PruneOldestSkippableEntryIfFull();
[email protected]944822b2012-03-02 20:57:252194
Carlos IL4dea8902020-05-26 15:14:292195 // Insert the entries from source. Ignore any pending entry, since it has not
2196 // committed in source.
[email protected]474f8512013-05-31 22:31:162197 int max_source_index = source->last_committed_entry_index_;
Rakina Zata Amniafd3c6582021-11-30 06:19:172198 DCHECK_NE(max_source_index, -1);
2199 max_source_index++;
[email protected]e78a6852013-12-13 08:08:572200
2201 // Ignore the source's current entry if merging with replacement.
2202 // TODO(davidben): This should preserve entries forward of the current
2203 // too. http://crbug.com/317872
2204 if (replace_entry && max_source_index > 0)
2205 max_source_index--;
2206
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572207 InsertEntriesFrom(source, max_source_index);
[email protected]e1cd5452010-08-26 18:03:252208
2209 // Adjust indices such that the last entry and pending are at the end now.
[email protected]a26023822011-12-29 00:23:552210 last_committed_entry_index_ = GetEntryCount() - 1;
[email protected]796931a92011-08-10 01:32:142211
Hayato Ito2c8c08d02021-06-23 03:38:432212 BroadcastHistoryOffsetAndLength();
[email protected]e1cd5452010-08-26 18:03:252213}
2214
[email protected]79368982013-11-13 01:11:012215bool NavigationControllerImpl::CanPruneAllButLastCommitted() {
[email protected]474f8512013-05-31 22:31:162216 // If there is no last committed entry, we cannot prune. Even if there is a
2217 // pending entry, it may not commit, leaving this WebContents blank, despite
2218 // possibly giving it new entries via CopyStateFromAndPrune.
2219 if (last_committed_entry_index_ == -1)
2220 return false;
[email protected]9350602e2013-02-26 23:27:442221
[email protected]474f8512013-05-31 22:31:162222 // We cannot prune if there is a pending entry at an existing entry index.
2223 // It may not commit, so we have to keep the last committed entry, and thus
2224 // there is no sensible place to keep the pending entry. It is ok to have
2225 // a new pending entry, which can optionally commit as a new navigation.
2226 if (pending_entry_index_ != -1)
2227 return false;
2228
[email protected]474f8512013-05-31 22:31:162229 return true;
2230}
2231
[email protected]79368982013-11-13 01:11:012232void NavigationControllerImpl::PruneAllButLastCommitted() {
2233 PruneAllButLastCommittedInternal();
[email protected]474f8512013-05-31 22:31:162234
avi2b177592014-12-10 02:08:022235 DCHECK_EQ(0, last_committed_entry_index_);
2236 DCHECK_EQ(1, GetEntryCount());
[email protected]9350602e2013-02-26 23:27:442237
Hayato Ito2c8c08d02021-06-23 03:38:432238 BroadcastHistoryOffsetAndLength();
[email protected]9350602e2013-02-26 23:27:442239}
2240
[email protected]79368982013-11-13 01:11:012241void NavigationControllerImpl::PruneAllButLastCommittedInternal() {
[email protected]474f8512013-05-31 22:31:162242 // It is up to callers to check the invariants before calling this.
[email protected]79368982013-11-13 01:11:012243 CHECK(CanPruneAllButLastCommitted());
[email protected]97b6c4f2010-09-27 19:31:262244
[email protected]474f8512013-05-31 22:31:162245 // Erase all entries but the last committed entry. There may still be a
2246 // new pending entry after this.
2247 entries_.erase(entries_.begin(),
2248 entries_.begin() + last_committed_entry_index_);
2249 entries_.erase(entries_.begin() + 1, entries_.end());
2250 last_committed_entry_index_ = 0;
[email protected]97b6c4f2010-09-27 19:31:262251}
2252
Christian Dullweber1af31e62018-02-22 11:49:482253void NavigationControllerImpl::DeleteNavigationEntries(
2254 const DeletionPredicate& deletionPredicate) {
2255 // It is up to callers to check the invariants before calling this.
2256 CHECK(CanPruneAllButLastCommitted());
2257 std::vector<int> delete_indices;
2258 for (size_t i = 0; i < entries_.size(); i++) {
2259 if (i != static_cast<size_t>(last_committed_entry_index_) &&
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572260 deletionPredicate.Run(entries_[i].get())) {
Christian Dullweber1af31e62018-02-22 11:49:482261 delete_indices.push_back(i);
2262 }
2263 }
2264 if (delete_indices.empty())
2265 return;
2266
2267 if (delete_indices.size() == GetEntryCount() - 1U) {
2268 PruneAllButLastCommitted();
2269 } else {
2270 // Do the deletion in reverse to preserve indices.
2271 for (auto it = delete_indices.rbegin(); it != delete_indices.rend(); ++it) {
2272 RemoveEntryAtIndex(*it);
2273 }
Hayato Ito2c8c08d02021-06-23 03:38:432274 BroadcastHistoryOffsetAndLength();
Christian Dullweber1af31e62018-02-22 11:49:482275 }
2276 delegate()->NotifyNavigationEntriesDeleted();
2277}
2278
Shivani Sharma883f5f32019-02-12 18:20:012279bool NavigationControllerImpl::IsEntryMarkedToBeSkipped(int index) {
2280 auto* entry = GetEntryAtIndex(index);
2281 return entry && entry->should_skip_on_back_forward_ui();
2282}
2283
Carlos Caballero35ce710c2019-09-19 10:59:452284BackForwardCacheImpl& NavigationControllerImpl::GetBackForwardCache() {
2285 return back_forward_cache_;
2286}
2287
clamy987a3752018-05-03 17:36:262288void NavigationControllerImpl::DiscardPendingEntry(bool was_failure) {
2289 // It is not safe to call DiscardPendingEntry while NavigateToEntry is in
2290 // progress, since this will cause a use-after-free. (We only allow this
2291 // when the tab is being destroyed for shutdown, since it won't return to
2292 // NavigateToEntry in that case.) http://crbug.com/347742.
Takashi Toyoshimaea534ef22021-07-21 03:27:592293 CHECK(!in_navigate_to_pending_entry_ || frame_tree_.IsBeingDestroyed());
clamy987a3752018-05-03 17:36:262294
2295 if (was_failure && pending_entry_) {
2296 failed_pending_entry_id_ = pending_entry_->GetUniqueID();
2297 } else {
2298 failed_pending_entry_id_ = 0;
2299 }
2300
2301 if (pending_entry_) {
2302 if (pending_entry_index_ == -1)
2303 delete pending_entry_;
2304 pending_entry_index_ = -1;
2305 pending_entry_ = nullptr;
2306 }
arthursonzogni66f711c2019-10-08 14:40:362307
2308 // Ensure any refs to the current pending entry are ignored if they get
2309 // deleted, by clearing the set of known refs. All future pending entries will
2310 // only be affected by new refs.
2311 pending_entry_refs_.clear();
clamy987a3752018-05-03 17:36:262312}
2313
2314void NavigationControllerImpl::SetPendingNavigationSSLError(bool error) {
2315 if (pending_entry_)
2316 pending_entry_->set_ssl_error(error);
2317}
2318
Xiaohan Wang7f8052e02022-01-14 18:44:282319#if BUILDFLAG(IS_ANDROID)
Camille Lamy5193caa2018-10-12 11:59:422320// static
2321bool NavigationControllerImpl::ValidateDataURLAsString(
2322 const scoped_refptr<const base::RefCountedString>& data_url_as_string) {
2323 if (!data_url_as_string)
2324 return false;
2325
2326 if (data_url_as_string->size() > kMaxLengthOfDataURLString)
2327 return false;
2328
2329 // The number of characters that is enough for validating a data: URI.
2330 // From the GURL's POV, the only important part here is scheme, it doesn't
2331 // check the actual content. Thus we can take only the prefix of the url, to
2332 // avoid unneeded copying of a potentially long string.
2333 const size_t kDataUriPrefixMaxLen = 64;
2334 GURL data_url(
2335 std::string(data_url_as_string->front_as<char>(),
2336 std::min(data_url_as_string->size(), kDataUriPrefixMaxLen)));
2337 if (!data_url.is_valid() || !data_url.SchemeIs(url::kDataScheme))
2338 return false;
2339
2340 return true;
2341}
2342#endif
2343
Shivani Sharma194877032019-03-07 17:52:472344void NavigationControllerImpl::NotifyUserActivation() {
2345 // When a user activation occurs, ensure that all adjacent entries for the
2346 // same document clear their skippable bit, so that the history manipulation
2347 // intervention does not apply to them.
2348 auto* last_committed_entry = GetLastCommittedEntry();
2349 if (!last_committed_entry)
2350 return;
Shivani Sharma194877032019-03-07 17:52:472351
shivanigithub99368382021-06-16 18:33:372352 if (base::FeatureList::IsEnabled(
2353 features::kDebugHistoryInterventionNoUserActivation)) {
2354 return;
2355 }
2356
Shivani Sharmac4cc8922019-04-18 03:11:172357 SetSkippableForSameDocumentEntries(GetLastCommittedEntryIndex(), false);
Shivani Sharma194877032019-03-07 17:52:472358}
2359
clamy987a3752018-05-03 17:36:262360bool NavigationControllerImpl::StartHistoryNavigationInNewSubframe(
2361 RenderFrameHostImpl* render_frame_host,
Julie Jeongeun Kimed2e5ba72019-09-12 10:14:172362 mojo::PendingAssociatedRemote<mojom::NavigationClient>* navigation_client) {
clamy987a3752018-05-03 17:36:262363 NavigationEntryImpl* entry =
2364 GetEntryWithUniqueID(render_frame_host->nav_entry_id());
2365 if (!entry)
2366 return false;
2367
2368 FrameNavigationEntry* frame_entry =
2369 entry->GetFrameEntry(render_frame_host->frame_tree_node());
2370 if (!frame_entry)
2371 return false;
2372
Nate Chapin45f620582021-09-30 17:45:432373 // |is_browser_initiated| is false here because a navigation in a new subframe
2374 // always begins with renderer action (i.e., an HTML element being inserted
2375 // into the DOM), so it is always renderer-initiated.
Camille Lamy5193caa2018-10-12 11:59:422376 std::unique_ptr<NavigationRequest> request = CreateNavigationRequestFromEntry(
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572377 render_frame_host->frame_tree_node(), entry, frame_entry,
clamyea99ea12018-05-28 13:54:232378 ReloadType::NONE, false /* is_same_document_history_load */,
Nate Chapin45f620582021-09-30 17:45:432379 true /* is_history_navigation_in_new_child */,
2380 false /* is_browser_initiated */);
clamyea99ea12018-05-28 13:54:232381
2382 if (!request)
2383 return false;
2384
arthursonzognif046d4a2019-12-12 19:08:102385 request->SetNavigationClient(std::move(*navigation_client));
Arthur Hemery06173ce2019-05-29 12:11:412386
Lukasz Anforowicz9ee83c272020-12-01 20:14:052387 render_frame_host->frame_tree_node()->navigator().Navigate(std::move(request),
2388 ReloadType::NONE);
clamyea99ea12018-05-28 13:54:232389
2390 return true;
clamy987a3752018-05-03 17:36:262391}
2392
Tsuyoshi Horo52fd08e2020-07-07 07:03:452393bool NavigationControllerImpl::ReloadFrame(FrameTreeNode* frame_tree_node) {
2394 NavigationEntryImpl* entry = GetEntryAtIndex(GetCurrentEntryIndex());
2395 if (!entry)
2396 return false;
2397 FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame_tree_node);
2398 if (!frame_entry)
2399 return false;
John Abd-El-Malek5b669132020-07-14 01:04:142400 ReloadType reload_type = ReloadType::NORMAL;
2401 entry->set_reload_type(reload_type);
Tsuyoshi Horo52fd08e2020-07-07 07:03:452402 std::unique_ptr<NavigationRequest> request = CreateNavigationRequestFromEntry(
John Abd-El-Malek5b669132020-07-14 01:04:142403 frame_tree_node, entry, frame_entry, reload_type,
Tsuyoshi Horo52fd08e2020-07-07 07:03:452404 false /* is_same_document_history_load */,
Nate Chapin45f620582021-09-30 17:45:432405 false /* is_history_navigation_in_new_child */,
2406 true /* is_browser_initiated */);
Tsuyoshi Horo52fd08e2020-07-07 07:03:452407 if (!request)
2408 return false;
Lukasz Anforowicz9ee83c272020-12-01 20:14:052409 frame_tree_node->navigator().Navigate(std::move(request), reload_type);
Tsuyoshi Horo52fd08e2020-07-07 07:03:452410 return true;
2411}
2412
Dave Tapuska8bfd84c2019-03-26 20:47:162413void NavigationControllerImpl::GoToOffsetInSandboxedFrame(
2414 int offset,
2415 int sandbox_frame_tree_node_id) {
2416 if (!CanGoToOffset(offset))
2417 return;
Nate Chapin45f620582021-09-30 17:45:432418 GoToIndex(GetIndexForOffset(offset), sandbox_frame_tree_node_id,
2419 false /* is_browser_initiated */);
Dave Tapuska8bfd84c2019-03-26 20:47:162420}
2421
clamy987a3752018-05-03 17:36:262422void NavigationControllerImpl::NavigateFromFrameProxy(
2423 RenderFrameHostImpl* render_frame_host,
2424 const GURL& url,
Chris Hamilton83272dc2021-02-23 00:24:022425 const blink::LocalFrameToken* initiator_frame_token,
Antonio Sartori9a82f6f32020-12-14 09:22:452426 int initiator_process_id,
Anton Bikineevf62d1bf2021-05-15 17:56:072427 const absl::optional<url::Origin>& initiator_origin,
clamy987a3752018-05-03 17:36:262428 bool is_renderer_initiated,
2429 SiteInstance* source_site_instance,
2430 const Referrer& referrer,
2431 ui::PageTransition page_transition,
2432 bool should_replace_current_entry,
Yeunjoo Choi3df791a2021-02-17 07:07:252433 blink::NavigationDownloadPolicy download_policy,
clamy987a3752018-05-03 17:36:262434 const std::string& method,
2435 scoped_refptr<network::ResourceRequestBody> post_body,
Marijn Kruisselbrink7a0d5e182018-05-24 22:55:092436 const std::string& extra_headers,
Antonio Sartori2f763d9d2021-04-21 10:04:142437 network::mojom::SourceLocationPtr source_location,
John Delaney50425f82020-04-07 16:26:212438 scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory,
Anton Bikineevf62d1bf2021-05-15 17:56:072439 const absl::optional<blink::Impression>& impression) {
Lukasz Anforowicz63f3b9432019-05-30 05:42:582440 if (is_renderer_initiated)
2441 DCHECK(initiator_origin.has_value());
2442
clamy987a3752018-05-03 17:36:262443 FrameTreeNode* node = render_frame_host->frame_tree_node();
Nasko Oskov18006bc2018-12-06 02:53:582444
clamy987a3752018-05-03 17:36:262445 // Create a NavigationEntry for the transfer, without making it the pending
2446 // entry. Subframe transfers should have a clone of the last committed entry
2447 // with a FrameNavigationEntry for the target frame. Main frame transfers
2448 // should have a new NavigationEntry.
2449 // TODO(creis): Make this unnecessary by creating (and validating) the params
2450 // directly, passing them to the destination RenderFrameHost. See
2451 // https://crbug.com/536906.
2452 std::unique_ptr<NavigationEntryImpl> entry;
Harkiran Bolariae1b5158b2021-09-16 19:03:262453 if (!render_frame_host->is_main_frame()) {
clamy987a3752018-05-03 17:36:262454 // Subframe case: create FrameNavigationEntry.
Rakina Zata Amniafd3c6582021-11-30 06:19:172455 CHECK(GetLastCommittedEntry());
2456 entry = GetLastCommittedEntry()->Clone();
2457 entry->set_extra_headers(extra_headers);
2458 // TODO(arthursonzogni): What about |is_renderer_initiated|?
2459 // Renderer-initiated navigation that target a remote frame are currently
2460 // classified as browser-initiated when this one has already navigated.
2461 // See https://crbug.com/722251.
Nate Chapin9f169072021-06-09 19:32:372462 // The UpdatePolicy doesn't matter here. |entry| is only used as a parameter
2463 // to CreateNavigationRequestFromLoadParams(), so while kReplace might
2464 // remove child FrameNavigationEntries (e.g., if this is a cross-process
2465 // same-document navigation), they will still be present in the
2466 // committed NavigationEntry that will be referenced to construct the new
2467 // FrameNavigationEntry tree when this navigation commits.
clamy987a3752018-05-03 17:36:262468 entry->AddOrUpdateFrameEntry(
Nate Chapinfbfe5af2021-06-10 17:22:082469 node, NavigationEntryImpl::UpdatePolicy::kReplace, -1, -1, "", nullptr,
Nasko Oskov18006bc2018-12-06 02:53:582470 static_cast<SiteInstanceImpl*>(source_site_instance), url,
Anton Bikineevf62d1bf2021-05-15 17:56:072471 absl::nullopt /* commit_origin */, referrer, initiator_origin,
Miyoung Shin5d77f72072020-10-09 15:14:202472 std::vector<GURL>(), blink::PageState(), method, -1,
Antonio Sartori78a749f2020-11-30 12:03:392473 blob_url_loader_factory, nullptr /* web_bundle_navigation_info */,
Kunihiko Sakamoto346a74e2021-03-10 08:57:482474 nullptr /* subresource_web_bundle_navigation_info */,
Antonio Sartori79d549d2021-02-18 12:59:542475 nullptr /* policy_container_policies */);
clamy987a3752018-05-03 17:36:262476 } else {
2477 // Main frame case.
2478 entry = NavigationEntryImpl::FromNavigationEntry(CreateNavigationEntry(
Lukasz Anforowicz641234d52019-11-07 21:07:102479 url, referrer, initiator_origin, source_site_instance, page_transition,
2480 is_renderer_initiated, extra_headers, browser_context_,
Hayato Ito303654c2021-06-30 09:07:542481 blob_url_loader_factory));
clamy987a3752018-05-03 17:36:262482 entry->root_node()->frame_entry->set_source_site_instance(
2483 static_cast<SiteInstanceImpl*>(source_site_instance));
2484 entry->root_node()->frame_entry->set_method(method);
2485 }
clamy987a3752018-05-03 17:36:262486
Camille Lamy5193caa2018-10-12 11:59:422487 bool override_user_agent = false;
clamy987a3752018-05-03 17:36:262488 if (GetLastCommittedEntry() &&
2489 GetLastCommittedEntry()->GetIsOverridingUserAgent()) {
2490 entry->SetIsOverridingUserAgent(true);
Camille Lamy5193caa2018-10-12 11:59:422491 override_user_agent = true;
clamy987a3752018-05-03 17:36:262492 }
2493 // TODO(creis): Set user gesture and intent received timestamp on Android.
2494
2495 // We may not have successfully added the FrameNavigationEntry to |entry|
2496 // above (per https://crbug.com/608402), in which case we create it from
2497 // scratch. This works because we do not depend on |frame_entry| being inside
2498 // |entry| during NavigateToEntry. This will go away when we shortcut this
2499 // further in https://crbug.com/536906.
2500 scoped_refptr<FrameNavigationEntry> frame_entry(entry->GetFrameEntry(node));
2501 if (!frame_entry) {
Patrick Monette50e8bd82019-06-13 22:40:452502 frame_entry = base::MakeRefCounted<FrameNavigationEntry>(
Nate Chapinfbfe5af2021-06-10 17:22:082503 node->unique_name(), -1, -1, "", nullptr,
Nasko Oskov18006bc2018-12-06 02:53:582504 static_cast<SiteInstanceImpl*>(source_site_instance), url,
Anton Bikineevf62d1bf2021-05-15 17:56:072505 absl::nullopt /* origin */, referrer, initiator_origin,
Rakina Zata Amni3a1c0ec2021-04-15 03:35:122506 std::vector<GURL>(), blink::PageState(), method, -1,
2507 blob_url_loader_factory, nullptr /* web_bundle_navigation_info */,
Kunihiko Sakamoto346a74e2021-03-10 08:57:482508 nullptr /* subresource_web_bundle_navigation_info */,
Titouan Rigoudy6ec70402021-02-02 15:42:192509 nullptr /* policy_container_policies */);
clamy987a3752018-05-03 17:36:262510 }
2511
Camille Lamy5193caa2018-10-12 11:59:422512 LoadURLParams params(url);
Chris Hamilton83272dc2021-02-23 00:24:022513 params.initiator_frame_token = base::OptionalFromPtr(initiator_frame_token);
Antonio Sartori9a82f6f32020-12-14 09:22:452514 params.initiator_process_id = initiator_process_id;
Nasko Oskov93e7c55c2018-12-19 01:59:292515 params.initiator_origin = initiator_origin;
Camille Lamy5193caa2018-10-12 11:59:422516 params.source_site_instance = source_site_instance;
2517 params.load_type = method == "POST" ? LOAD_TYPE_HTTP_POST : LOAD_TYPE_DEFAULT;
2518 params.transition_type = page_transition;
Dominic Farolino226226af2019-06-25 00:58:032519 params.frame_tree_node_id = node->frame_tree_node_id();
Camille Lamy5193caa2018-10-12 11:59:422520 params.referrer = referrer;
2521 /* params.redirect_chain: skip */
2522 params.extra_headers = extra_headers;
2523 params.is_renderer_initiated = is_renderer_initiated;
2524 params.override_user_agent = UA_OVERRIDE_INHERIT;
2525 /* params.base_url_for_data_url: skip */
2526 /* params.virtual_url_for_data_url: skip */
2527 /* params.data_url_as_string: skip */
2528 params.post_data = post_body;
2529 params.can_load_local_resources = false;
Kevin McNeee60e76b2019-11-27 20:01:582530 /* params.should_replace_current_entry: skip */
Camille Lamy5193caa2018-10-12 11:59:422531 /* params.frame_name: skip */
2532 // TODO(clamy): See if user gesture should be propagated to this function.
2533 params.has_user_gesture = false;
2534 params.should_clear_history_list = false;
2535 params.started_from_context_menu = false;
2536 /* params.navigation_ui_data: skip */
2537 /* params.input_start: skip */
Minggang Wangf59db47b2021-06-16 01:56:222538 params.was_activated = blink::mojom::WasActivatedOption::kUnknown;
Robert Ogden011a8082019-01-23 19:04:542539 /* params.reload_type: skip */
John Delaney50425f82020-04-07 16:26:212540 params.impression = impression;
Antonio Sartori6984c742021-08-26 08:03:412541 params.download_policy = std::move(download_policy);
Camille Lamy5193caa2018-10-12 11:59:422542
2543 std::unique_ptr<NavigationRequest> request =
2544 CreateNavigationRequestFromLoadParams(
Dominic Farolino226226af2019-06-25 00:58:032545 node, params, override_user_agent, should_replace_current_entry,
Antonio Sartori2f763d9d2021-04-21 10:04:142546 false /* has_user_gesture */, std::move(source_location),
Antonio Sartori6984c742021-08-26 08:03:412547 ReloadType::NONE, entry.get(), frame_entry.get());
clamyea99ea12018-05-28 13:54:232548
2549 if (!request)
2550 return;
2551
Arthur Hemery948742762019-09-18 10:06:242552 // At this stage we are proceeding with this navigation. If this was renderer
2553 // initiated with user gesture, we need to make sure we clear up potential
2554 // remains of a cancelled browser initiated navigation to avoid URL spoofs.
2555 DiscardNonCommittedEntries();
2556
Lukasz Anforowicz9ee83c272020-12-01 20:14:052557 node->navigator().Navigate(std::move(request), ReloadType::NONE);
clamy987a3752018-05-03 17:36:262558}
2559
[email protected]d1198fd2012-08-13 22:50:192560void NavigationControllerImpl::SetSessionStorageNamespace(
Aaron Colwellf3b316e2021-03-11 20:17:052561 const StoragePartitionId& partition_id,
[email protected]8ff00d72012-10-23 19:12:212562 SessionStorageNamespace* session_storage_namespace) {
[email protected]d1198fd2012-08-13 22:50:192563 if (!session_storage_namespace)
2564 return;
2565
2566 // We can't overwrite an existing SessionStorage without violating spec.
2567 // Attempts to do so may give a tab access to another tab's session storage
2568 // so die hard on an error.
Aran Gilman37d11632019-10-08 23:07:152569 bool successful_insert =
2570 session_storage_namespace_map_
Aaron Colwellf3b316e2021-03-11 20:17:052571 .insert(std::make_pair(partition_id,
2572 static_cast<SessionStorageNamespaceImpl*>(
2573 session_storage_namespace)))
[email protected]fdac6ade2013-07-20 01:06:302574 .second;
2575 CHECK(successful_insert) << "Cannot replace existing SessionStorageNamespace";
Aaron Colwellb731a0ae2021-03-19 19:14:472576 OnStoragePartitionIdAdded(partition_id);
[email protected]d1198fd2012-08-13 22:50:192577}
2578
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572579bool NavigationControllerImpl::IsUnmodifiedBlankTab() {
Rakina Zata Amniafd3c6582021-11-30 06:19:172580 return IsInitialNavigation() && GetLastCommittedEntry()->IsInitialEntry() &&
Carlos Caballeroede6f8c2021-01-28 11:01:502581 !frame_tree_.has_accessed_initial_main_document();
[email protected]aa62afd2014-04-22 19:22:462582}
2583
Aran Gilman37d11632019-10-08 23:07:152584SessionStorageNamespace* NavigationControllerImpl::GetSessionStorageNamespace(
Aaron Colwell78b4bde2021-03-16 16:16:092585 const SiteInfo& site_info) {
2586 // TODO(acolwell): Remove partition_id logic once we have successfully
2587 // migrated the implementation to be a StoragePartitionConfig. At that point
2588 // |site_info| can be replaced with a StoragePartitionConfig.
2589 const StoragePartitionId partition_id =
2590 site_info.GetStoragePartitionId(browser_context_);
2591 const StoragePartitionConfig partition_config =
Robbie McElrath7d4bd852021-07-24 04:02:192592 site_info.storage_partition_config();
[email protected]d1198fd2012-08-13 22:50:192593
[email protected]fdac6ade2013-07-20 01:06:302594 StoragePartition* partition =
Lukasz Anforowiczb9a969a2021-04-29 15:26:252595 browser_context_->GetStoragePartition(partition_config);
michaelnbacbcbd2016-02-09 00:32:032596 DOMStorageContextWrapper* context_wrapper =
2597 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
2598
2599 SessionStorageNamespaceMap::const_iterator it =
2600 session_storage_namespace_map_.find(partition_id);
2601 if (it != session_storage_namespace_map_.end()) {
2602 // Ensure that this namespace actually belongs to this partition.
Aran Gilman37d11632019-10-08 23:07:152603 DCHECK(static_cast<SessionStorageNamespaceImpl*>(it->second.get())
2604 ->IsFromContext(context_wrapper));
Aaron Colwellb731a0ae2021-03-19 19:14:472605
2606 // Verify that the config we generated now matches the one that
2607 // was generated when the namespace was added to the map.
Aaron Colwellb731a0ae2021-03-19 19:14:472608 if (partition_config != it->first.config()) {
2609 LogStoragePartitionIdCrashKeys(it->first, partition_id);
2610 }
Sharon Yangd4f48792021-06-30 17:02:532611 CHECK_EQ(partition_config, it->first.config());
Aaron Colwellb731a0ae2021-03-19 19:14:472612
michaelnbacbcbd2016-02-09 00:32:032613 return it->second.get();
2614 }
2615
2616 // Create one if no one has accessed session storage for this partition yet.
Daniel Murphy31bbb8b12018-02-07 21:44:102617 scoped_refptr<SessionStorageNamespaceImpl> session_storage_namespace =
2618 SessionStorageNamespaceImpl::Create(context_wrapper);
2619 SessionStorageNamespaceImpl* session_storage_namespace_ptr =
2620 session_storage_namespace.get();
2621 session_storage_namespace_map_[partition_id] =
2622 std::move(session_storage_namespace);
Aaron Colwellb731a0ae2021-03-19 19:14:472623 OnStoragePartitionIdAdded(partition_id);
[email protected]fdac6ade2013-07-20 01:06:302624
Daniel Murphy31bbb8b12018-02-07 21:44:102625 return session_storage_namespace_ptr;
[email protected]fdac6ade2013-07-20 01:06:302626}
2627
2628SessionStorageNamespace*
2629NavigationControllerImpl::GetDefaultSessionStorageNamespace() {
Robbie McElrath7d4bd852021-07-24 04:02:192630 return GetSessionStorageNamespace(SiteInfo(GetBrowserContext()));
[email protected]fdac6ade2013-07-20 01:06:302631}
2632
2633const SessionStorageNamespaceMap&
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572634NavigationControllerImpl::GetSessionStorageNamespaceMap() {
[email protected]fdac6ade2013-07-20 01:06:302635 return session_storage_namespace_map_;
[email protected]a26023822011-12-29 00:23:552636}
[email protected]d202a7c2012-01-04 07:53:472637
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572638bool NavigationControllerImpl::NeedsReload() {
[email protected]71fde352011-12-29 03:29:562639 return needs_reload_;
2640}
[email protected]a26023822011-12-29 00:23:552641
[email protected]46bb5e9c2013-10-03 22:16:472642void NavigationControllerImpl::SetNeedsReload() {
Alex Moshchuk7b4f0652019-05-30 18:54:412643 SetNeedsReload(NeedsReloadType::kRequestedByClient);
2644}
2645
2646void NavigationControllerImpl::SetNeedsReload(NeedsReloadType type) {
[email protected]46bb5e9c2013-10-03 22:16:472647 needs_reload_ = true;
Alex Moshchuk7b4f0652019-05-30 18:54:412648 needs_reload_type_ = type;
jaekyunc8cefa82015-01-09 20:14:542649
2650 if (last_committed_entry_index_ != -1) {
2651 entries_[last_committed_entry_index_]->SetTransitionType(
2652 ui::PAGE_TRANSITION_RELOAD);
2653 }
[email protected]46bb5e9c2013-10-03 22:16:472654}
2655
[email protected]d202a7c2012-01-04 07:53:472656void NavigationControllerImpl::RemoveEntryAtIndexInternal(int index) {
Kevin McNee05164772019-09-03 17:24:572657 DCHECK_LT(index, GetEntryCount());
2658 DCHECK_NE(index, last_committed_entry_index_);
[email protected]43032342011-03-21 14:10:312659 DiscardNonCommittedEntries();
2660
2661 entries_.erase(entries_.begin() + index);
[email protected]6a13a6c2011-12-20 21:47:122662 if (last_committed_entry_index_ > index)
[email protected]43032342011-03-21 14:10:312663 last_committed_entry_index_--;
2664}
2665
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572666NavigationEntryImpl* NavigationControllerImpl::GetPendingEntry() {
arthursonzogni5c4c202d2017-04-25 23:41:272667 // If there is no pending_entry_, there should be no pending_entry_index_.
2668 DCHECK(pending_entry_ || pending_entry_index_ == -1);
2669
2670 // If there is a pending_entry_index_, then pending_entry_ must be the entry
Carlos IL42b416592019-10-07 23:10:362671 // at that index. An exception is while a reload of a post commit error page
2672 // is ongoing; in that case pending entry will point to the entry replaced
2673 // by the error.
arthursonzogni5c4c202d2017-04-25 23:41:272674 DCHECK(pending_entry_index_ == -1 ||
Carlos IL42b416592019-10-07 23:10:362675 pending_entry_ == GetEntryAtIndex(pending_entry_index_) ||
2676 pending_entry_ == entry_replaced_by_post_commit_error_.get());
arthursonzogni5c4c202d2017-04-25 23:41:272677
[email protected]022af742011-12-28 18:37:252678 return pending_entry_;
2679}
2680
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572681int NavigationControllerImpl::GetPendingEntryIndex() {
arthursonzogni5c4c202d2017-04-25 23:41:272682 // The pending entry index must always be less than the number of entries.
arthursonzogni5c4c202d2017-04-25 23:41:272683 DCHECK_LT(pending_entry_index_, GetEntryCount());
[email protected]a26023822011-12-29 00:23:552684 return pending_entry_index_;
2685}
2686
avi25764702015-06-23 15:43:372687void NavigationControllerImpl::InsertOrReplaceEntry(
dcheng9bfa5162016-04-09 01:00:572688 std::unique_ptr<NavigationEntryImpl> entry,
Carlos IL42b416592019-10-07 23:10:362689 bool replace,
Dave Tapuska87696ae2021-11-18 18:48:312690 bool was_post_commit_error,
Rakina Zata Amnia4e27222021-12-22 01:05:002691 bool in_fenced_frame_tree,
2692 LoadCommittedDetails* commit_details) {
Dave Tapuska87696ae2021-11-18 18:48:312693 // Fenced frame trees should always have `ui::PAGE_TRANSITION_AUTO_SUBFRAME`
2694 // set because:
2695 // 1) They don't influence the history of the outer page.
2696 // 2) They are always replace only navigation (there is always only one entry
2697 // in their history stack).
2698 // 3) Are not top level navigations and appear similar to iframes.
2699 // Navigations of the fenced frame might create a new NavigationEntry, which
2700 // will call this function. Non fenced frame navigations will never have
2701 // `ui::PAGE_TRANSITION_AUTO_SUBFRAME` because they won't call
2702 // InsertOrReplaceEntry.
2703 DCHECK_EQ(in_fenced_frame_tree,
2704 ui::PageTransitionCoreTypeIs(entry->GetTransitionType(),
2705 ui::PAGE_TRANSITION_AUTO_SUBFRAME));
[email protected]765b35502008-08-21 00:51:202706
avi5cad4912015-06-19 05:25:442707 // If the pending_entry_index_ is -1, the navigation was to a new page, and we
2708 // need to keep continuity with the pending entry, so copy the pending entry's
2709 // unique ID to the committed entry. If the pending_entry_index_ isn't -1,
2710 // then the renderer navigated on its own, independent of the pending entry,
2711 // so don't copy anything.
2712 if (pending_entry_ && pending_entry_index_ == -1)
2713 entry->set_unique_id(pending_entry_->GetUniqueID());
[email protected]765b35502008-08-21 00:51:202714
Rakina Zata Amnia4e27222021-12-22 01:05:002715 DiscardNonCommittedEntriesWithCommitDetails(commit_details);
[email protected]765b35502008-08-21 00:51:202716
creisee17e932015-07-17 17:56:222717 // When replacing, don't prune the forward history.
Carlos IL42b416592019-10-07 23:10:362718 if ((replace || was_post_commit_error) && entries_.size() > 0) {
Mikel Astizba9cf2fd2017-12-17 10:38:102719 CopyReplacedNavigationEntryDataIfPreviouslyEmpty(
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572720 entries_[last_committed_entry_index_].get(), entry.get());
Carlos IL42b416592019-10-07 23:10:362721 // If the new entry is a post-commit error page, we store the current last
2722 // committed entry to the side so that we can put it back when navigating
2723 // away from the error.
2724 if (was_post_commit_error) {
2725 DCHECK(!entry_replaced_by_post_commit_error_);
2726 entry_replaced_by_post_commit_error_ =
2727 std::move(entries_[last_committed_entry_index_]);
2728 }
dcheng36b6aec92015-12-26 06:16:362729 entries_[last_committed_entry_index_] = std::move(entry);
creisee17e932015-07-17 17:56:222730 return;
2731 }
[email protected]765b35502008-08-21 00:51:202732
creis37979a62015-08-04 19:48:182733 // We shouldn't see replace == true when there's no committed entries.
2734 DCHECK(!replace);
2735
Michael Thiessen9b14d512019-09-23 21:19:472736 PruneForwardEntries();
[email protected]765b35502008-08-21 00:51:202737
Shivani Sharmad8c8d652019-02-13 17:27:572738 PruneOldestSkippableEntryIfFull();
[email protected]765b35502008-08-21 00:51:202739
dcheng36b6aec92015-12-26 06:16:362740 entries_.push_back(std::move(entry));
[email protected]765b35502008-08-21 00:51:202741 last_committed_entry_index_ = static_cast<int>(entries_.size()) - 1;
initial.commit09911bf2008-07-26 23:55:292742}
2743
Shivani Sharmad8c8d652019-02-13 17:27:572744void NavigationControllerImpl::PruneOldestSkippableEntryIfFull() {
Shivani Sharma2d5b4b6b2019-01-08 16:07:162745 if (entries_.size() < max_entry_count())
2746 return;
2747
2748 DCHECK_EQ(max_entry_count(), entries_.size());
2749 DCHECK_GT(last_committed_entry_index_, 0);
Shivani Sharmad8c8d652019-02-13 17:27:572750 CHECK_EQ(pending_entry_index_, -1);
2751
2752 int index = 0;
Elly Fong-Jonesccc6d1f2021-06-14 18:32:422753 // Retrieve the oldest skippable entry.
2754 for (; index < GetEntryCount(); index++) {
2755 if (GetEntryAtIndex(index)->should_skip_on_back_forward_ui())
2756 break;
Shivani Sharmad8c8d652019-02-13 17:27:572757 }
2758
2759 // If there is no skippable entry or if it is the last committed entry then
2760 // fall back to pruning the oldest entry. It is not safe to prune the last
2761 // committed entry.
2762 if (index == GetEntryCount() || index == last_committed_entry_index_)
2763 index = 0;
2764
2765 bool should_succeed = RemoveEntryAtIndex(index);
2766 DCHECK_EQ(true, should_succeed);
2767
2768 NotifyPrunedEntries(this, index, 1);
[email protected]944822b2012-03-02 20:57:252769}
2770
clamy3cb9bea92018-07-10 12:42:022771void NavigationControllerImpl::NavigateToExistingPendingEntry(
Dave Tapuska8bfd84c2019-03-26 20:47:162772 ReloadType reload_type,
Nate Chapin45f620582021-09-30 17:45:432773 int sandboxed_source_frame_tree_node_id,
2774 bool is_browser_initiated) {
Alexander Timin3a92df72019-09-20 11:59:502775 TRACE_EVENT0("navigation",
2776 "NavigationControllerImpl::NavigateToExistingPendingEntry");
arthursonzogni5c4c202d2017-04-25 23:41:272777 DCHECK(pending_entry_);
clamy3cb9bea92018-07-10 12:42:022778 DCHECK(IsInitialNavigation() || pending_entry_index_ != -1);
Carlos IL42b416592019-10-07 23:10:362779 if (pending_entry_index_ != -1) {
2780 // The pending entry may not be in entries_ if a post-commit error page is
2781 // showing.
2782 DCHECK(pending_entry_ == entries_[pending_entry_index_].get() ||
2783 pending_entry_ == entry_replaced_by_post_commit_error_.get());
2784 }
Gyuyoung Kim107c2a02021-04-13 01:49:302785 DCHECK(!blink::IsRendererDebugURL(pending_entry_->GetURL()));
Alex Moshchuk3a4e77a2020-05-29 21:32:572786 bool is_forced_reload = needs_reload_;
[email protected]72097fd02010-01-21 23:36:012787 needs_reload_ = false;
Carlos Caballero40b0efd2021-01-26 11:55:002788 FrameTreeNode* root = frame_tree_.root();
Arthur Sonzogni620cec62018-12-13 13:08:572789 int nav_entry_id = pending_entry_->GetUniqueID();
2790
[email protected]83c2e232011-10-07 21:36:462791 // If we were navigating to a slow-to-commit page, and the user performs
2792 // a session history navigation to the last committed page, RenderViewHost
2793 // will force the throbber to start, but WebKit will essentially ignore the
2794 // navigation, and won't send a message to stop the throbber. To prevent this
2795 // from happening, we drop the navigation here and stop the slow-to-commit
2796 // page from loading (which would normally happen during the navigation).
clamy3cb9bea92018-07-10 12:42:022797 if (pending_entry_index_ == last_committed_entry_index_ &&
Lukasz Anforowicz6b75c0d2020-12-01 22:56:082798 !pending_entry_->IsRestored() &&
arthursonzogni5c4c202d2017-04-25 23:41:272799 pending_entry_->GetTransitionType() & ui::PAGE_TRANSITION_FORWARD_BACK) {
Takashi Toyoshimabf549472021-07-01 07:47:202800 frame_tree_.StopLoading();
[email protected]6a13a6c2011-12-20 21:47:122801
[email protected]83c2e232011-10-07 21:36:462802 DiscardNonCommittedEntries();
2803 return;
2804 }
2805
creisce0ef3572017-01-26 17:53:082806 // Compare FrameNavigationEntries to see which frames in the tree need to be
2807 // navigated.
clamy3cb9bea92018-07-10 12:42:022808 std::vector<std::unique_ptr<NavigationRequest>> same_document_loads;
2809 std::vector<std::unique_ptr<NavigationRequest>> different_document_loads;
Nate Chapin45f620582021-09-30 17:45:432810 FindFramesToNavigate(root, reload_type, is_browser_initiated,
2811 &same_document_loads, &different_document_loads);
creis4e2ecb72015-06-20 00:46:302812
2813 if (same_document_loads.empty() && different_document_loads.empty()) {
Alex Moshchuk3a4e77a2020-05-29 21:32:572814 // We were unable to match any frames to navigate. This can happen if a
2815 // history navigation targets a subframe that no longer exists
2816 // (https://crbug.com/705550). In this case, we need to update the current
2817 // history entry to the pending one but keep the main document loaded. We
2818 // also need to ensure that observers are informed about the updated
2819 // current history entry (e.g., for greying out back/forward buttons), and
2820 // that renderer processes update their history offsets. The easiest way
2821 // to do all that is to schedule a "redundant" same-document navigation in
2822 // the main frame.
2823 //
2824 // Note that we don't want to remove this history entry, as it might still
2825 // be valid later, since a frame that it's targeting may be recreated.
2826 //
2827 // TODO(alexmos, creis): This behavior isn't ideal, as the user would
2828 // need to repeat history navigations until finding the one that works.
2829 // Consider changing this behavior to keep looking for the first valid
2830 // history entry that finds frames to navigate.
clamy3cb9bea92018-07-10 12:42:022831 std::unique_ptr<NavigationRequest> navigation_request =
Camille Lamy5193caa2018-10-12 11:59:422832 CreateNavigationRequestFromEntry(
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572833 root, pending_entry_, pending_entry_->GetFrameEntry(root),
Alex Moshchuk3a4e77a2020-05-29 21:32:572834 ReloadType::NONE /* reload_type */,
2835 true /* is_same_document_history_load */,
Nate Chapin45f620582021-09-30 17:45:432836 false /* is_history_navigation_in_new_child */,
2837 is_browser_initiated);
clamy3cb9bea92018-07-10 12:42:022838 if (!navigation_request) {
Alex Moshchuk3a4e77a2020-05-29 21:32:572839 // If this navigation cannot start, delete the pending NavigationEntry.
clamy3cb9bea92018-07-10 12:42:022840 DiscardPendingEntry(false);
2841 return;
2842 }
Alex Moshchuk3a4e77a2020-05-29 21:32:572843 same_document_loads.push_back(std::move(navigation_request));
2844
2845 // Sanity check that we never take this branch for any kinds of reloads,
2846 // as those should've queued a different-document load in the main frame.
2847 DCHECK(!is_forced_reload);
2848 DCHECK_EQ(reload_type, ReloadType::NONE);
creis4e2ecb72015-06-20 00:46:302849 }
2850
Dave Tapuska8bfd84c2019-03-26 20:47:162851 // If |sandboxed_source_frame_node_id| is valid, then track whether this
2852 // navigation affects any frame outside the frame's subtree.
2853 if (sandboxed_source_frame_tree_node_id !=
2854 FrameTreeNode::kFrameTreeNodeInvalidId) {
2855 bool navigates_inside_tree =
2856 DoesSandboxNavigationStayWithinSubtree(
2857 sandboxed_source_frame_tree_node_id, same_document_loads) &&
2858 DoesSandboxNavigationStayWithinSubtree(
2859 sandboxed_source_frame_tree_node_id, different_document_loads);
Dave Tapuska716ed3af2019-09-23 18:45:502860 // Count the navigations as web use counters so we can determine
Dave Tapuska8bfd84c2019-03-26 20:47:162861 // the number of pages that trigger this.
2862 FrameTreeNode* sandbox_source_frame_tree_node =
2863 FrameTreeNode::GloballyFindByID(sandboxed_source_frame_tree_node_id);
2864 if (sandbox_source_frame_tree_node) {
2865 GetContentClient()->browser()->LogWebFeatureForCurrentPage(
2866 sandbox_source_frame_tree_node->current_frame_host(),
2867 navigates_inside_tree
2868 ? blink::mojom::WebFeature::kSandboxBackForwardStaysWithinSubtree
2869 : blink::mojom::WebFeature::
2870 kSandboxBackForwardAffectsFramesOutsideSubtree);
2871 }
Dave Tapuska855c1e12019-08-23 20:45:522872
2873 // If the navigation occurred outside the tree discard it because
2874 // the sandboxed frame didn't have permission to navigate outside
2875 // its tree. If it is possible that the navigation is both inside and
2876 // outside the frame tree and we discard it entirely because we don't
2877 // want to end up in a history state that didn't exist before.
2878 if (base::FeatureList::IsEnabled(
2879 features::kHistoryPreventSandboxedNavigation) &&
2880 !navigates_inside_tree) {
2881 DiscardPendingEntry(false);
2882 return;
2883 }
Dave Tapuska8bfd84c2019-03-26 20:47:162884 }
2885
Carlos Caballero539a421c2020-07-06 10:25:572886 // BackForwardCache:
2887 // Navigate immediately if the document is in the BackForwardCache.
2888 if (back_forward_cache_.GetEntry(nav_entry_id)) {
2889 TRACE_EVENT0("navigation", "BackForwardCache_CreateNavigationRequest");
2890 DCHECK_EQ(reload_type, ReloadType::NONE);
2891 auto navigation_request = CreateNavigationRequestFromEntry(
2892 root, pending_entry_, pending_entry_->GetFrameEntry(root),
2893 ReloadType::NONE, false /* is_same_document_history_load */,
Nate Chapin45f620582021-09-30 17:45:432894 false /* is_history_navigation_in_new_child */, is_browser_initiated);
Lukasz Anforowicz9ee83c272020-12-01 20:14:052895 root->navigator().Navigate(std::move(navigation_request), ReloadType::NONE);
Carlos Caballero539a421c2020-07-06 10:25:572896
2897 return;
2898 }
2899
2900 // History navigation might try to reuse a specific BrowsingInstance, already
2901 // used by a page in the cache. To avoid having two different main frames that
2902 // live in the same BrowsingInstance, evict the all pages with this
2903 // BrowsingInstance from the cache.
2904 //
2905 // For example, take the following scenario:
2906 //
2907 // A1 = Some page on a.com
2908 // A2 = Some other page on a.com
2909 // B3 = An uncacheable page on b.com
2910 //
2911 // Then the following navigations occur:
2912 // A1->A2->B3->A1
2913 // On the navigation from B3 to A1, A2 will remain in the cache (B3 doesn't
2914 // take its place) and A1 will be created in the same BrowsingInstance (and
2915 // SiteInstance), as A2.
2916 //
2917 // If we didn't do anything, both A1 and A2 would remain alive in the same
2918 // BrowsingInstance/SiteInstance, which is unsupported by
2919 // RenderFrameHostManager::CommitPending(). To avoid this conundrum, we evict
2920 // A2 from the cache.
2921 if (pending_entry_->site_instance()) {
2922 back_forward_cache_.EvictFramesInRelatedSiteInstances(
2923 pending_entry_->site_instance());
2924 }
2925
clamy3cb9bea92018-07-10 12:42:022926 // This call does not support re-entrancy. See http://crbug.com/347742.
2927 CHECK(!in_navigate_to_pending_entry_);
2928 in_navigate_to_pending_entry_ = true;
creis4e2ecb72015-06-20 00:46:302929
arthursonzogni66f711c2019-10-08 14:40:362930 // It is not possible to delete the pending NavigationEntry while navigating
2931 // to it. Grab a reference to delay potential deletion until the end of this
2932 // function.
2933 std::unique_ptr<PendingEntryRef> pending_entry_ref = ReferencePendingEntry();
2934
creis4e2ecb72015-06-20 00:46:302935 // Send all the same document frame loads before the different document loads.
clamy3cb9bea92018-07-10 12:42:022936 for (auto& item : same_document_loads) {
2937 FrameTreeNode* frame = item->frame_tree_node();
Lukasz Anforowicz9ee83c272020-12-01 20:14:052938 frame->navigator().Navigate(std::move(item), reload_type);
creis4e2ecb72015-06-20 00:46:302939 }
clamy3cb9bea92018-07-10 12:42:022940 for (auto& item : different_document_loads) {
2941 FrameTreeNode* frame = item->frame_tree_node();
Lukasz Anforowicz9ee83c272020-12-01 20:14:052942 frame->navigator().Navigate(std::move(item), reload_type);
creis4e2ecb72015-06-20 00:46:302943 }
clamy3cb9bea92018-07-10 12:42:022944
2945 in_navigate_to_pending_entry_ = false;
creis4e2ecb72015-06-20 00:46:302946}
2947
Alex Moshchuk3a4e77a2020-05-29 21:32:572948NavigationControllerImpl::HistoryNavigationAction
2949NavigationControllerImpl::DetermineActionForHistoryNavigation(
creis4e2ecb72015-06-20 00:46:302950 FrameTreeNode* frame,
Alex Moshchuk3a4e77a2020-05-29 21:32:572951 ReloadType reload_type) {
Sreeja Kamishetty8eacabb2021-03-09 11:45:422952 RenderFrameHostImpl* render_frame_host = frame->current_frame_host();
Sreeja Kamishettydb8e2892021-03-10 09:30:582953 // Only active and prerendered documents are allowed to navigate in their
2954 // frame.
Sreeja Kamishetty8eacabb2021-03-09 11:45:422955 if (render_frame_host->lifecycle_state() !=
Sreeja Kamishetty299329ad2021-03-25 14:06:012956 RenderFrameHostImpl::LifecycleStateImpl::kPrerendering) {
Sreeja Kamishettydb8e2892021-03-10 09:30:582957 // - If the document is in pending deletion, the browser already committed
2958 // to destroying this RenderFrameHost. See https://crbug.com/930278.
2959 // - If the document is in back-forward cache, it's not allowed to navigate
2960 // as it should remain frozen. Ignore the request and evict the document
2961 // from back-forward cache.
Sreeja Kamishetty8eacabb2021-03-09 11:45:422962 //
Sreeja Kamishettydb8e2892021-03-10 09:30:582963 // If the document is inactive, there's no need to recurse into subframes,
Sreeja Kamishetty8eacabb2021-03-09 11:45:422964 // which should all be inactive as well.
Fergal Daly1336ac642021-09-14 15:13:112965 if (frame->current_frame_host()->IsInactiveAndDisallowActivation(
2966 DisallowActivationReasonId::kDetermineActionForHistoryNavigation)) {
Sreeja Kamishetty8eacabb2021-03-09 11:45:422967 return HistoryNavigationAction::kStopLooking;
Fergal Daly1336ac642021-09-14 15:13:112968 }
Sreeja Kamishetty8eacabb2021-03-09 11:45:422969 }
arthursonzogni03f76152019-02-12 10:35:202970
Alex Moshchuk3a4e77a2020-05-29 21:32:572971 // If there's no last committed entry, there is no previous history entry to
2972 // compare against, so fall back to a different-document load. Note that we
2973 // should only reach this case for the root frame and not descend further
2974 // into subframes.
2975 if (!GetLastCommittedEntry()) {
2976 DCHECK(frame->IsMainFrame());
2977 return HistoryNavigationAction::kDifferentDocument;
2978 }
2979
2980 // Reloads should result in a different-document load. Note that reloads may
2981 // also happen via the |needs_reload_| mechanism where the reload_type is
2982 // NONE, so detect this by comparing whether we're going to the same
2983 // entry that we're currently on. Similarly to above, only main frames
2984 // should reach this. Note that subframes support reloads, but that's done
2985 // via a different path that doesn't involve FindFramesToNavigate (see
2986 // RenderFrameHost::Reload()).
2987 if (reload_type != ReloadType::NONE ||
2988 pending_entry_index_ == last_committed_entry_index_) {
2989 DCHECK(frame->IsMainFrame());
2990 return HistoryNavigationAction::kDifferentDocument;
2991 }
2992
Alex Moshchuk47d1a4bd2020-06-01 22:15:342993 // If there is no new FrameNavigationEntry for the frame, ignore the
2994 // load. For example, this may happen when going back to an entry before a
2995 // frame was created. Suppose we commit a same-document navigation that also
2996 // results in adding a new subframe somewhere in the tree. If we go back,
2997 // the new subframe will be missing a FrameNavigationEntry in the previous
2998 // NavigationEntry, but we shouldn't delete or change what's loaded in
2999 // it.
3000 //
Alex Moshchuke65c39272020-06-03 17:55:373001 // Note that in this case, there is no need to keep looking for navigations
3002 // in subframes, which would be missing FrameNavigationEntries as well.
3003 //
Alex Moshchuk47d1a4bd2020-06-01 22:15:343004 // It's important to check this before checking |old_item| below, since both
3005 // might be null, and in that case we still shouldn't change what's loaded in
3006 // this frame. Note that scheduling any loads assumes that |new_item| is
3007 // non-null. See https://crbug.com/1088354.
3008 FrameNavigationEntry* new_item = pending_entry_->GetFrameEntry(frame);
3009 if (!new_item)
Alex Moshchuke65c39272020-06-03 17:55:373010 return HistoryNavigationAction::kStopLooking;
Alex Moshchuk47d1a4bd2020-06-01 22:15:343011
Alex Moshchuk3a4e77a2020-05-29 21:32:573012 // If there is no old FrameNavigationEntry, schedule a different-document
3013 // load.
3014 //
creis225a7432016-06-03 22:56:273015 // TODO(creis): Store the last committed FrameNavigationEntry to use here,
3016 // rather than assuming the NavigationEntry has up to date info on subframes.
creis4e2ecb72015-06-20 00:46:303017 FrameNavigationEntry* old_item =
3018 GetLastCommittedEntry()->GetFrameEntry(frame);
Alex Moshchuk3a4e77a2020-05-29 21:32:573019 if (!old_item)
3020 return HistoryNavigationAction::kDifferentDocument;
3021
Alex Moshchuk3a4e77a2020-05-29 21:32:573022 // If the new item is not in the same SiteInstance, schedule a
3023 // different-document load. Newly restored items may not have a SiteInstance
3024 // yet, in which case it will be assigned on first commit.
3025 if (new_item->site_instance() &&
3026 new_item->site_instance() != old_item->site_instance())
3027 return HistoryNavigationAction::kDifferentDocument;
3028
3029 // Schedule a different-document load if the current RenderFrameHost is not
danakj25c436d2021-04-01 16:35:313030 // live. This case can happen for Ctrl+Back or after a renderer crash. Note
3031 // that we do this even if the history navigation would not be modifying this
3032 // frame were it live.
3033 if (!frame->current_frame_host()->IsRenderFrameLive())
Alex Moshchuk3a4e77a2020-05-29 21:32:573034 return HistoryNavigationAction::kDifferentDocument;
3035
3036 if (new_item->item_sequence_number() != old_item->item_sequence_number()) {
danakj25c436d2021-04-01 16:35:313037 // Starting a navigation after a crash early-promotes the speculative
3038 // RenderFrameHost. Then we have a RenderFrameHost with no document in it
3039 // committed yet, so we can not possibly perform a same-document history
3040 // navigation. The frame would need to be reloaded with a cross-document
3041 // navigation.
3042 if (!frame->current_frame_host()->has_committed_any_navigation())
3043 return HistoryNavigationAction::kDifferentDocument;
3044
creis54131692016-08-12 18:32:253045 // Same document loads happen if the previous item has the same document
danakjb952ef12021-01-14 19:58:493046 // sequence number but different item sequence number.
3047 if (new_item->document_sequence_number() ==
3048 old_item->document_sequence_number()) {
Alex Moshchuk3a4e77a2020-05-29 21:32:573049 return HistoryNavigationAction::kSameDocument;
danakjb952ef12021-01-14 19:58:493050 }
avib48cb312016-05-05 21:35:003051
Alex Moshchuk3a4e77a2020-05-29 21:32:573052 // Otherwise, if both item and document sequence numbers differ, this
3053 // should be a different document load.
3054 return HistoryNavigationAction::kDifferentDocument;
3055 }
3056
3057 // If the item sequence numbers match, there is no need to navigate this
Alex Moshchuke65c39272020-06-03 17:55:373058 // frame. Keep looking for navigations in this frame's children.
Alex Moshchuk3a4e77a2020-05-29 21:32:573059 DCHECK_EQ(new_item->document_sequence_number(),
3060 old_item->document_sequence_number());
Alex Moshchuke65c39272020-06-03 17:55:373061 return HistoryNavigationAction::kKeepLooking;
Alex Moshchuk3a4e77a2020-05-29 21:32:573062}
3063
3064void NavigationControllerImpl::FindFramesToNavigate(
3065 FrameTreeNode* frame,
3066 ReloadType reload_type,
Nate Chapin45f620582021-09-30 17:45:433067 bool is_browser_initiated,
Alex Moshchuk3a4e77a2020-05-29 21:32:573068 std::vector<std::unique_ptr<NavigationRequest>>* same_document_loads,
3069 std::vector<std::unique_ptr<NavigationRequest>>* different_document_loads) {
3070 DCHECK(pending_entry_);
3071 FrameNavigationEntry* new_item = pending_entry_->GetFrameEntry(frame);
3072
3073 auto action = DetermineActionForHistoryNavigation(frame, reload_type);
3074
3075 if (action == HistoryNavigationAction::kSameDocument) {
3076 std::unique_ptr<NavigationRequest> navigation_request =
3077 CreateNavigationRequestFromEntry(
3078 frame, pending_entry_, new_item, reload_type,
3079 true /* is_same_document_history_load */,
Nate Chapin45f620582021-09-30 17:45:433080 false /* is_history_navigation_in_new_child */,
3081 is_browser_initiated);
Alex Moshchuk3a4e77a2020-05-29 21:32:573082 if (navigation_request) {
3083 // Only add the request if was properly created. It's possible for the
3084 // creation to fail in certain cases, e.g. when the URL is invalid.
3085 same_document_loads->push_back(std::move(navigation_request));
creis4e2ecb72015-06-20 00:46:303086 }
Alex Moshchuk3a4e77a2020-05-29 21:32:573087 } else if (action == HistoryNavigationAction::kDifferentDocument) {
Lei Zhang96031532019-10-10 19:05:473088 std::unique_ptr<NavigationRequest> navigation_request =
3089 CreateNavigationRequestFromEntry(
3090 frame, pending_entry_, new_item, reload_type,
3091 false /* is_same_document_history_load */,
Nate Chapin45f620582021-09-30 17:45:433092 false /* is_history_navigation_in_new_child */,
3093 is_browser_initiated);
Lei Zhang96031532019-10-10 19:05:473094 if (navigation_request) {
3095 // Only add the request if was properly created. It's possible for the
3096 // creation to fail in certain cases, e.g. when the URL is invalid.
3097 different_document_loads->push_back(std::move(navigation_request));
3098 }
3099 // For a different document, the subframes will be destroyed, so there's
3100 // no need to consider them.
3101 return;
Alex Moshchuke65c39272020-06-03 17:55:373102 } else if (action == HistoryNavigationAction::kStopLooking) {
3103 return;
creis4e2ecb72015-06-20 00:46:303104 }
3105
3106 for (size_t i = 0; i < frame->child_count(); i++) {
Nate Chapin45f620582021-09-30 17:45:433107 FindFramesToNavigate(frame->child_at(i), reload_type, is_browser_initiated,
3108 same_document_loads, different_document_loads);
creis4e2ecb72015-06-20 00:46:303109 }
3110}
3111
Harkiran Bolariaba823e42021-05-21 18:30:363112base::WeakPtr<NavigationHandle> NavigationControllerImpl::NavigateWithoutEntry(
clamy21718cc22018-06-13 13:34:243113 const LoadURLParams& params) {
3114 // Find the appropriate FrameTreeNode.
3115 FrameTreeNode* node = nullptr;
3116 if (params.frame_tree_node_id != RenderFrameHost::kNoFrameTreeNodeId ||
3117 !params.frame_name.empty()) {
3118 node = params.frame_tree_node_id != RenderFrameHost::kNoFrameTreeNodeId
Carlos Caballero40b0efd2021-01-26 11:55:003119 ? frame_tree_.FindByID(params.frame_tree_node_id)
3120 : frame_tree_.FindByName(params.frame_name);
Hayato Ito7a80db42021-07-05 06:18:543121 DCHECK(!node || node->frame_tree() == &frame_tree_);
clamy21718cc22018-06-13 13:34:243122 }
3123
3124 // If no FrameTreeNode was specified, navigate the main frame.
3125 if (!node)
Carlos Caballero40b0efd2021-01-26 11:55:003126 node = frame_tree_.root();
clamy21718cc22018-06-13 13:34:243127
Camille Lamy5193caa2018-10-12 11:59:423128 // Compute overrides to the LoadURLParams for |override_user_agent|,
3129 // |should_replace_current_entry| and |has_user_gesture| that will be used
3130 // both in the creation of the NavigationEntry and the NavigationRequest.
3131 // Ideally, the LoadURLParams themselves would be updated, but since they are
3132 // passed as a const reference, this is not possible.
3133 // TODO(clamy): When we only create a NavigationRequest, move this to
3134 // CreateNavigationRequestFromLoadURLParams.
3135 bool override_user_agent = ShouldOverrideUserAgent(params.override_user_agent,
3136 GetLastCommittedEntry());
3137
3138 // Don't allow an entry replacement if there is no entry to replace.
3139 // http://crbug.com/457149
Hayato Ito7a80db42021-07-05 06:18:543140 //
3141 // If there is an entry, an entry replacement must happen if the current
3142 // browsing context should maintain a trivial session history.
shivanigithubf405bf0d2021-11-05 17:58:333143 bool should_replace_current_entry =
3144 (params.should_replace_current_entry ||
3145 ShouldMaintainTrivialSessionHistory(node)) &&
3146 entries_.size();
Camille Lamy5193caa2018-10-12 11:59:423147
clamy21718cc22018-06-13 13:34:243148 // Javascript URLs should not create NavigationEntries. All other navigations
3149 // do, including navigations to chrome renderer debug URLs.
clamy21718cc22018-06-13 13:34:243150 if (!params.url.SchemeIs(url::kJavaScriptScheme)) {
Scott Violet5ae6c42e2020-10-28 02:47:373151 std::unique_ptr<NavigationEntryImpl> entry =
3152 CreateNavigationEntryFromLoadParams(node, params, override_user_agent,
3153 should_replace_current_entry,
3154 params.has_user_gesture);
clamy21718cc22018-06-13 13:34:243155 DiscardPendingEntry(false);
3156 SetPendingEntry(std::move(entry));
3157 }
3158
3159 // Renderer-debug URLs are sent to the renderer process immediately for
3160 // processing and don't need to create a NavigationRequest.
3161 // Note: this includes navigations to JavaScript URLs, which are considered
3162 // renderer-debug URLs.
3163 // Note: we intentionally leave the pending entry in place for renderer debug
3164 // URLs, unlike the cases below where we clear it if the navigation doesn't
3165 // proceed.
Gyuyoung Kim107c2a02021-04-13 01:49:303166 if (blink::IsRendererDebugURL(params.url)) {
Oleg Davydov2cc0167b2019-02-05 14:32:483167 // Renderer-debug URLs won't go through NavigationThrottlers so we have to
3168 // check them explicitly. See bug 913334.
Aaron Colwelle1908d982020-06-26 22:08:153169 if (GetContentClient()->browser()->ShouldBlockRendererDebugURL(
Oleg Davydov2cc0167b2019-02-05 14:32:483170 params.url, browser_context_)) {
3171 DiscardPendingEntry(false);
Harkiran Bolariaba823e42021-05-21 18:30:363172 return nullptr;
Oleg Davydov2cc0167b2019-02-05 14:32:483173 }
3174
clamy21718cc22018-06-13 13:34:243175 HandleRendererDebugURL(node, params.url);
Harkiran Bolariaba823e42021-05-21 18:30:363176 return nullptr;
clamy21718cc22018-06-13 13:34:243177 }
3178
Antonio Sartori78a749f2020-11-30 12:03:393179 DCHECK(pending_entry_);
3180
clamy21718cc22018-06-13 13:34:243181 // Convert navigations to the current URL to a reload.
3182 // TODO(clamy): We should be using FrameTreeNode::IsMainFrame here instead of
3183 // relying on the frame tree node id from LoadURLParams. Unfortunately,
3184 // DevTools sometimes issues navigations to main frames that they do not
3185 // expect to see treated as reload, and it only works because they pass a
3186 // FrameTreeNode id in their LoadURLParams. Change this once they no longer do
3187 // that. See https://crbug.com/850926.
Robert Ogden011a8082019-01-23 19:04:543188 ReloadType reload_type = params.reload_type;
3189 if (reload_type == ReloadType::NONE &&
3190 ShouldTreatNavigationAsReload(
Fergal Daly766177d2020-07-07 07:54:043191 node, params.url, pending_entry_->GetVirtualURL(),
clamy21718cc22018-06-13 13:34:243192 params.base_url_for_data_url, params.transition_type,
clamy21718cc22018-06-13 13:34:243193 params.load_type ==
3194 NavigationController::LOAD_TYPE_HTTP_POST /* is_post */,
Hayato Ito7a80db42021-07-05 06:18:543195 should_replace_current_entry, GetLastCommittedEntry())) {
clamy21718cc22018-06-13 13:34:243196 reload_type = ReloadType::NORMAL;
Alexander Timinb70f67382020-12-10 00:03:473197 pending_entry_->set_reload_type(reload_type);
Antonio Sartori78a749f2020-11-30 12:03:393198
3199 // If this is a reload of an existing FrameNavigationEntry and we had a
3200 // policy container for it, then we should copy it into the pending entry,
3201 // so that it is copied to the navigation request in
3202 // CreateNavigationRequestFromLoadParams later.
3203 if (GetLastCommittedEntry()) {
3204 FrameNavigationEntry* previous_frame_entry =
3205 GetLastCommittedEntry()->GetFrameEntry(node);
Titouan Rigoudy6ec70402021-02-02 15:42:193206 if (previous_frame_entry &&
3207 previous_frame_entry->policy_container_policies()) {
3208 pending_entry_->GetFrameEntry(node)->set_policy_container_policies(
Antonio Sartori5d09b30f2021-03-02 09:27:163209 previous_frame_entry->policy_container_policies()->Clone());
Antonio Sartori78a749f2020-11-30 12:03:393210 }
3211 }
3212 }
3213
3214 // If this navigation is an "Enter-in-omnibox" with the initial about:blank
Rakina Zata Amniafd3c6582021-11-30 06:19:173215 // document, then we should copy the document polices from RenderFrameHost's
3216 // PolicyContainerHost. The NavigationRequest will create a new
3217 // PolicyContainerHost with the document policies from the |pending_entry_|,
3218 // and that PolicyContainerHost will be put in the final RenderFrameHost for
3219 // the navigation. This way, we ensure that we keep enforcing the right
3220 // policies on the initial empty document after the reload.
3221 if (GetLastCommittedEntry()->IsInitialEntry() && params.url.IsAboutBlank()) {
Antonio Sartori78a749f2020-11-30 12:03:393222 if (node->current_frame_host() &&
3223 node->current_frame_host()->policy_container_host()) {
Titouan Rigoudy6ec70402021-02-02 15:42:193224 pending_entry_->GetFrameEntry(node)->set_policy_container_policies(
Antonio Sartori5d09b30f2021-03-02 09:27:163225 node->current_frame_host()
3226 ->policy_container_host()
3227 ->policies()
3228 .Clone());
Antonio Sartori78a749f2020-11-30 12:03:393229 }
clamy21718cc22018-06-13 13:34:243230 }
3231
3232 // navigation_ui_data should only be present for main frame navigations.
3233 DCHECK(node->IsMainFrame() || !params.navigation_ui_data);
3234
Camille Lamy5193caa2018-10-12 11:59:423235 std::unique_ptr<NavigationRequest> request =
3236 CreateNavigationRequestFromLoadParams(
3237 node, params, override_user_agent, should_replace_current_entry,
Antonio Sartori2f763d9d2021-04-21 10:04:143238 params.has_user_gesture, network::mojom::SourceLocation::New(),
Antonio Sartori6984c742021-08-26 08:03:413239 reload_type, pending_entry_, pending_entry_->GetFrameEntry(node));
clamy21718cc22018-06-13 13:34:243240
3241 // If the navigation couldn't start, return immediately and discard the
3242 // pending NavigationEntry.
3243 if (!request) {
3244 DiscardPendingEntry(false);
Harkiran Bolariaba823e42021-05-21 18:30:363245 return nullptr;
clamy21718cc22018-06-13 13:34:243246 }
3247
Camille Lamy5193caa2018-10-12 11:59:423248#if DCHECK_IS_ON()
3249 // Safety check that NavigationRequest and NavigationEntry match.
3250 ValidateRequestMatchesEntry(request.get(), pending_entry_);
3251#endif
3252
clamy21718cc22018-06-13 13:34:243253 // This call does not support re-entrancy. See http://crbug.com/347742.
3254 CHECK(!in_navigate_to_pending_entry_);
3255 in_navigate_to_pending_entry_ = true;
3256
arthursonzogni66f711c2019-10-08 14:40:363257 // It is not possible to delete the pending NavigationEntry while navigating
3258 // to it. Grab a reference to delay potential deletion until the end of this
3259 // function.
3260 std::unique_ptr<PendingEntryRef> pending_entry_ref = ReferencePendingEntry();
3261
Harkiran Bolariaba823e42021-05-21 18:30:363262 base::WeakPtr<NavigationHandle> created_navigation_handle(
3263 request->GetWeakPtr());
Lukasz Anforowicz9ee83c272020-12-01 20:14:053264 node->navigator().Navigate(std::move(request), reload_type);
clamy21718cc22018-06-13 13:34:243265
3266 in_navigate_to_pending_entry_ = false;
Harkiran Bolariaba823e42021-05-21 18:30:363267 return created_navigation_handle;
clamy21718cc22018-06-13 13:34:243268}
3269
clamyea99ea12018-05-28 13:54:233270void NavigationControllerImpl::HandleRendererDebugURL(
3271 FrameTreeNode* frame_tree_node,
3272 const GURL& url) {
3273 if (!frame_tree_node->current_frame_host()->IsRenderFrameLive()) {
clamy21718cc22018-06-13 13:34:243274 // Any renderer-side debug URLs or javascript: URLs should be ignored if
3275 // the renderer process is not live, unless it is the initial navigation
3276 // of the tab.
clamyea99ea12018-05-28 13:54:233277 if (!IsInitialNavigation()) {
3278 DiscardNonCommittedEntries();
3279 return;
3280 }
Fergal Dalyecd3b0202020-06-25 01:57:373281 // The current frame is always a main frame. If IsInitialNavigation() is
3282 // true then there have been no navigations and any frames of this tab must
3283 // be in the same renderer process. If that has crashed then the only frame
3284 // that can be revived is the main frame.
3285 frame_tree_node->render_manager()
3286 ->InitializeMainRenderFrameForImmediateUse();
clamyea99ea12018-05-28 13:54:233287 }
3288 frame_tree_node->current_frame_host()->HandleRendererDebugURL(url);
3289}
3290
clamy21718cc22018-06-13 13:34:243291std::unique_ptr<NavigationEntryImpl>
3292NavigationControllerImpl::CreateNavigationEntryFromLoadParams(
3293 FrameTreeNode* node,
Camille Lamy5193caa2018-10-12 11:59:423294 const LoadURLParams& params,
3295 bool override_user_agent,
3296 bool should_replace_current_entry,
3297 bool has_user_gesture) {
Marijn Kruisselbrink0c87e6e2018-06-22 22:57:393298 // Browser initiated navigations might not have a blob_url_loader_factory set
3299 // in params even if the navigation is to a blob URL. If that happens, lookup
3300 // the correct url loader factory to use here.
3301 auto blob_url_loader_factory = params.blob_url_loader_factory;
Kinuko Yasuda7d925ea22019-08-01 10:08:483302 if (!blob_url_loader_factory && params.url.SchemeIsBlob()) {
Marijn Kruisselbrink8ffda442020-09-03 18:29:473303 // Resolve the blob URL in the storage partition associated with the target
3304 // frame. This is the storage partition the URL will be loaded in, and only
3305 // URLs that can be resolved by it should be able to access its data.
Marijn Kruisselbrink0c87e6e2018-06-22 22:57:393306 blob_url_loader_factory = ChromeBlobStorageContext::URLLoaderFactoryForUrl(
Marijn Kruisselbrink8ffda442020-09-03 18:29:473307 node->current_frame_host()->GetStoragePartition(), params.url);
Marijn Kruisselbrink0c87e6e2018-06-22 22:57:393308 }
3309
clamy21718cc22018-06-13 13:34:243310 std::unique_ptr<NavigationEntryImpl> entry;
Tommy C. Li03eee77a2019-02-05 02:07:443311 // extra_headers in params are \n separated; navigation entries want \r\n.
3312 std::string extra_headers_crlf;
3313 base::ReplaceChars(params.extra_headers, "\n", "\r\n", &extra_headers_crlf);
clamy21718cc22018-06-13 13:34:243314
3315 // For subframes, create a pending entry with a corresponding frame entry.
3316 if (!node->IsMainFrame()) {
Rakina Zata Amniafd3c6582021-11-30 06:19:173317 CHECK(GetLastCommittedEntry());
3318 entry = GetLastCommittedEntry()->Clone();
clamy21718cc22018-06-13 13:34:243319 entry->AddOrUpdateFrameEntry(
Nate Chapinfbfe5af2021-06-10 17:22:083320 node, NavigationEntryImpl::UpdatePolicy::kReplace, -1, -1, "", nullptr,
clamy21718cc22018-06-13 13:34:243321 static_cast<SiteInstanceImpl*>(params.source_site_instance.get()),
Anton Bikineevf62d1bf2021-05-15 17:56:073322 params.url, absl::nullopt, params.referrer, params.initiator_origin,
Miyoung Shin5d77f72072020-10-09 15:14:203323 params.redirect_chain, blink::PageState(), "GET", -1,
Antonio Sartori78a749f2020-11-30 12:03:393324 blob_url_loader_factory, nullptr /* web_bundle_navigation_info */,
Kunihiko Sakamoto346a74e2021-03-10 08:57:483325 nullptr /* subresource_web_bundle_navigation_info */,
Antonio Sartori78a749f2020-11-30 12:03:393326 // If in NavigateWithoutEntry we later determine that this navigation is
Charlie Reis7e2cb6d2021-01-26 01:27:163327 // a conversion of a new navigation into a reload, we will set the right
3328 // document policies there.
Titouan Rigoudy6ec70402021-02-02 15:42:193329 nullptr /* policy_container_policies */);
clamy21718cc22018-06-13 13:34:243330 } else {
3331 // Otherwise, create a pending entry for the main frame.
clamy21718cc22018-06-13 13:34:243332 entry = NavigationEntryImpl::FromNavigationEntry(CreateNavigationEntry(
Lukasz Anforowicz435bcb582019-07-12 20:50:063333 params.url, params.referrer, params.initiator_origin,
Lukasz Anforowicz641234d52019-11-07 21:07:103334 params.source_site_instance.get(), params.transition_type,
3335 params.is_renderer_initiated, extra_headers_crlf, browser_context_,
Hayato Ito303654c2021-06-30 09:07:543336 blob_url_loader_factory));
clamy21718cc22018-06-13 13:34:243337 entry->set_source_site_instance(
3338 static_cast<SiteInstanceImpl*>(params.source_site_instance.get()));
3339 entry->SetRedirectChain(params.redirect_chain);
3340 }
3341
3342 // Set the FTN ID (only used in non-site-per-process, for tests).
3343 entry->set_frame_tree_node_id(node->frame_tree_node_id());
clamy21718cc22018-06-13 13:34:243344 entry->set_should_clear_history_list(params.should_clear_history_list);
Camille Lamy5193caa2018-10-12 11:59:423345 entry->SetIsOverridingUserAgent(override_user_agent);
3346 entry->set_has_user_gesture(has_user_gesture);
Robert Ogden011a8082019-01-23 19:04:543347 entry->set_reload_type(params.reload_type);
clamy21718cc22018-06-13 13:34:243348
clamy21718cc22018-06-13 13:34:243349 switch (params.load_type) {
3350 case LOAD_TYPE_DEFAULT:
3351 break;
3352 case LOAD_TYPE_HTTP_POST:
3353 entry->SetHasPostData(true);
3354 entry->SetPostData(params.post_data);
3355 break;
3356 case LOAD_TYPE_DATA:
3357 entry->SetBaseURLForDataURL(params.base_url_for_data_url);
3358 entry->SetVirtualURL(params.virtual_url_for_data_url);
Xiaohan Wang7f8052e02022-01-14 18:44:283359#if BUILDFLAG(IS_ANDROID)
clamy21718cc22018-06-13 13:34:243360 entry->SetDataURLAsString(params.data_url_as_string);
3361#endif
3362 entry->SetCanLoadLocalResources(params.can_load_local_resources);
3363 break;
clamy21718cc22018-06-13 13:34:243364 }
3365
3366 // TODO(clamy): NavigationEntry is meant for information that will be kept
3367 // after the navigation ended and therefore is not appropriate for
3368 // started_from_context_menu. Move started_from_context_menu to
3369 // NavigationUIData.
3370 entry->set_started_from_context_menu(params.started_from_context_menu);
3371
3372 return entry;
3373}
3374
clamyea99ea12018-05-28 13:54:233375std::unique_ptr<NavigationRequest>
Camille Lamy5193caa2018-10-12 11:59:423376NavigationControllerImpl::CreateNavigationRequestFromLoadParams(
3377 FrameTreeNode* node,
3378 const LoadURLParams& params,
3379 bool override_user_agent,
3380 bool should_replace_current_entry,
3381 bool has_user_gesture,
Antonio Sartori2f763d9d2021-04-21 10:04:143382 network::mojom::SourceLocationPtr source_location,
Camille Lamy5193caa2018-10-12 11:59:423383 ReloadType reload_type,
Lucas Furukawa Gadani5553a1582019-01-08 18:55:573384 NavigationEntryImpl* entry,
Scott Violetcf6ea7e2021-06-09 21:09:213385 FrameNavigationEntry* frame_entry) {
Lucas Furukawa Gadani5553a1582019-01-08 18:55:573386 DCHECK_EQ(-1, GetIndexOfEntry(entry));
Camille Lamyb9ed3c52018-11-19 15:34:283387 DCHECK(frame_entry);
Nasko Oskov3c2f9e252019-01-10 17:45:533388 // All renderer-initiated navigations must have an initiator_origin.
3389 DCHECK(!params.is_renderer_initiated || params.initiator_origin.has_value());
Camille Lamyff7c4822018-11-07 15:42:513390
Camille Lamy5193caa2018-10-12 11:59:423391 GURL url_to_load;
3392 GURL virtual_url;
Anton Bikineevf62d1bf2021-05-15 17:56:073393 absl::optional<url::Origin> origin_to_commit =
3394 frame_entry ? frame_entry->committed_origin() : absl::nullopt;
Nasko Oskov03912102019-01-11 00:21:323395
Camille Lamy2baa8022018-10-19 16:43:173396 // For main frames, rewrite the URL if necessary and compute the virtual URL
3397 // that should be shown in the address bar.
3398 if (node->IsMainFrame()) {
Lukasz Anforowiczb2eb19b12020-01-25 00:40:423399 bool ignored_reverse_on_redirect = false;
Camille Lamy2baa8022018-10-19 16:43:173400 RewriteUrlForNavigation(params.url, browser_context_, &url_to_load,
Lukasz Anforowiczb2eb19b12020-01-25 00:40:423401 &virtual_url, &ignored_reverse_on_redirect);
Camille Lamy5193caa2018-10-12 11:59:423402
Camille Lamy2baa8022018-10-19 16:43:173403 // For DATA loads, override the virtual URL.
3404 if (params.load_type == LOAD_TYPE_DATA)
3405 virtual_url = params.virtual_url_for_data_url;
Camille Lamy5193caa2018-10-12 11:59:423406
Camille Lamy2baa8022018-10-19 16:43:173407 if (virtual_url.is_empty())
3408 virtual_url = url_to_load;
3409
Lucas Furukawa Gadani5553a1582019-01-08 18:55:573410 CHECK(virtual_url == entry->GetVirtualURL());
Camille Lamyb9ed3c52018-11-19 15:34:283411
Aran Gilman249eb122019-12-02 23:32:463412 // This is a LOG and not a CHECK/DCHECK as URL rewrite has non-deterministic
3413 // behavior: it is possible for two calls to RewriteUrlForNavigation to
3414 // return different results, leading to a different URL in the
3415 // NavigationRequest and FrameEntry. This will be fixed once we remove the
3416 // pending NavigationEntry, as we'll only make one call to
3417 // RewriteUrlForNavigation.
3418 VLOG_IF(1, (url_to_load != frame_entry->url()))
3419 << "NavigationRequest and FrameEntry have different URLs: "
3420 << url_to_load << " vs " << frame_entry->url();
Camille Lamyb9ed3c52018-11-19 15:34:283421
Camille Lamy2baa8022018-10-19 16:43:173422 // TODO(clamy): In order to remove the pending NavigationEntry,
Lukasz Anforowiczb2eb19b12020-01-25 00:40:423423 // |virtual_url| and |ignored_reverse_on_redirect| should be stored in the
Camille Lamy2baa8022018-10-19 16:43:173424 // NavigationRequest.
3425 } else {
3426 url_to_load = params.url;
3427 virtual_url = params.url;
Camille Lamyf664f7622019-01-07 19:28:243428 CHECK(!frame_entry || url_to_load == frame_entry->url());
Camille Lamy2baa8022018-10-19 16:43:173429 }
Camille Lamy5193caa2018-10-12 11:59:423430
Ehsan Karamad44fc72112019-02-26 18:15:473431 if (node->render_manager()->is_attaching_inner_delegate()) {
3432 // Avoid starting any new navigations since this node is now preparing for
3433 // attaching an inner delegate.
3434 return nullptr;
Ehsan Karamaddd9a4142018-12-04 20:38:203435 }
Camille Lamy5193caa2018-10-12 11:59:423436
Camille Lamy5193caa2018-10-12 11:59:423437 if (!IsValidURLForNavigation(node->IsMainFrame(), virtual_url, url_to_load))
3438 return nullptr;
3439
Kunihiko Sakamoto346a74e2021-03-10 08:57:483440 if (!DoesURLMatchOriginForNavigation(
3441 url_to_load, origin_to_commit,
3442 frame_entry->subresource_web_bundle_navigation_info())) {
Nasko Oskov03912102019-01-11 00:21:323443 DCHECK(false) << " url:" << url_to_load
3444 << " origin:" << origin_to_commit.value();
3445 return nullptr;
3446 }
3447
Camille Lamy5193caa2018-10-12 11:59:423448 // Determine if Previews should be used for the navigation.
Hiroki Nakagawa41366152020-07-27 18:31:403449 blink::PreviewsState previews_state =
3450 blink::PreviewsTypes::PREVIEWS_UNSPECIFIED;
Camille Lamy5193caa2018-10-12 11:59:423451 if (!node->IsMainFrame()) {
3452 // For subframes, use the state of the top-level frame.
3453 previews_state = node->frame_tree()
3454 ->root()
3455 ->current_frame_host()
3456 ->last_navigation_previews_state();
3457 }
3458
Camille Lamy5193caa2018-10-12 11:59:423459 // This will be used to set the Navigation Timing API navigationStart
3460 // parameter for browser navigations in new tabs (intents, tabs opened through
3461 // "Open link in new tab"). If the navigation must wait on the current
3462 // RenderFrameHost to execute its BeforeUnload event, the navigation start
3463 // will be updated when the BeforeUnload ack is received.
3464 base::TimeTicks navigation_start = base::TimeTicks::Now();
3465
danakjd83d706d2020-11-25 22:11:123466 // Look for a pending commit that is to another document in this
3467 // FrameTreeNode. If one exists, then the last committed URL will not be the
3468 // current URL by the time this navigation commits.
3469 bool has_pending_cross_document_commit =
3470 node->render_manager()->HasPendingCommitForCrossDocumentNavigation();
Miyoung Shina2dd6a42021-10-07 12:19:213471 bool is_currently_error_page = node->current_frame_host()->IsErrorDocument();
danakjd83d706d2020-11-25 22:11:123472
Minggang Wangb9f3fa92021-07-01 15:30:313473 blink::mojom::NavigationType navigation_type = GetNavigationType(
danakjb952ef12021-01-14 19:58:493474 /*old_url=*/node->current_url(),
3475 /*new_url=*/url_to_load, reload_type, entry, *frame_entry,
3476 has_pending_cross_document_commit, is_currently_error_page,
3477 /*is_same_document_history_load=*/false);
Camille Lamy5193caa2018-10-12 11:59:423478
3479 // Create the NavigationParams based on |params|.
3480
Hiroki Nakagawa4ed61282021-06-18 05:37:233481 bool is_view_source_mode = entry->IsViewSourceMode();
3482 DCHECK_EQ(is_view_source_mode, virtual_url.SchemeIs(kViewSourceScheme));
Charlie Harrison8c113a32019-01-07 16:08:293483
Antonio Sartori6984c742021-08-26 08:03:413484 blink::NavigationDownloadPolicy download_policy = params.download_policy;
Hiroki Nakagawa4ed61282021-06-18 05:37:233485 // Update |download_policy| if the virtual URL is view-source.
Charlie Harrison8c113a32019-01-07 16:08:293486 if (is_view_source_mode)
Yeunjoo Choi3df791a2021-02-17 07:07:253487 download_policy.SetDisallowed(blink::NavigationDownloadType::kViewSource);
Charlie Harrison8c113a32019-01-07 16:08:293488
Minggang Wangb9f3fa92021-07-01 15:30:313489 blink::mojom::CommonNavigationParamsPtr common_params =
3490 blink::mojom::CommonNavigationParams::New(
Lucas Furukawa Gadanief8290a2019-07-29 20:27:513491 url_to_load, params.initiator_origin,
3492 blink::mojom::Referrer::New(params.referrer.url,
3493 params.referrer.policy),
Scott Violetcf6ea7e2021-06-09 21:09:213494 params.transition_type, navigation_type, download_policy,
Lucas Furukawa Gadanief8290a2019-07-29 20:27:513495 should_replace_current_entry, params.base_url_for_data_url,
Rakina Zata Amni8a1c6b32021-09-29 06:41:293496 previews_state, navigation_start,
Lucas Furukawa Gadanief8290a2019-07-29 20:27:513497 params.load_type == LOAD_TYPE_HTTP_POST ? "POST" : "GET",
Antonio Sartori2f763d9d2021-04-21 10:04:143498 params.post_data, std::move(source_location),
arthursonzogniaf7c62c52020-02-12 10:49:413499 params.started_from_context_menu, has_user_gesture,
Antonio Sartori636adba2021-03-09 12:15:273500 false /* has_text_fragment_token */,
3501 network::mojom::CSPDisposition::CHECK, std::vector<int>(),
3502 params.href_translate,
Lucas Furukawa Gadanief8290a2019-07-29 20:27:513503 false /* is_history_navigation_in_new_child_frame */,
Nan Lind91c8152021-10-21 16:22:373504 params.input_start, network::mojom::RequestDestination::kEmpty);
Camille Lamy5193caa2018-10-12 11:59:423505
Minggang Wangb9f3fa92021-07-01 15:30:313506 blink::mojom::CommitNavigationParamsPtr commit_params =
3507 blink::mojom::CommitNavigationParams::New(
Antonio Sartori3e8de6d2021-07-26 10:28:413508 frame_entry->committed_origin(),
3509 // The correct storage key will be computed before committing the
3510 // navigation.
3511 blink::StorageKey(), network::mojom::WebSandboxFlags(),
arthursonzognid5a8d0b2021-03-11 17:36:433512 override_user_agent, params.redirect_chain,
Lucas Furukawa Gadani81e294b2019-08-29 16:26:323513 std::vector<network::mojom::URLResponseHeadPtr>(),
Lucas Furukawa Gadania9c45682019-07-31 22:05:143514 std::vector<net::RedirectInfo>(),
3515 std::string() /* post_content_type */, common_params->url,
3516 common_params->method, params.can_load_local_resources,
Minggang Wangb9f3fa92021-07-01 15:30:313517 frame_entry->page_state().ToEncodedData(), entry->GetUniqueID(),
Lucas Furukawa Gadania9c45682019-07-31 22:05:143518 entry->GetSubframeUniqueNames(node), true /* intended_as_new_entry */,
3519 -1 /* pending_history_list_offset */,
3520 params.should_clear_history_list ? -1 : GetLastCommittedEntryIndex(),
3521 params.should_clear_history_list ? 0 : GetEntryCount(),
3522 false /* was_discarded */, is_view_source_mode,
Minggang Wangb9f3fa92021-07-01 15:30:313523 params.should_clear_history_list,
3524 blink::mojom::NavigationTiming::New(),
Minggang Wangf59db47b2021-06-16 01:56:223525 blink::mojom::WasActivatedOption::kUnknown,
Lucas Furukawa Gadania9c45682019-07-31 22:05:143526 base::UnguessableToken::Create() /* navigation_token */,
Minggang Wang7ee0c742021-06-16 16:16:513527 std::vector<blink::mojom::PrefetchedSignedExchangeInfoPtr>(),
Xiaohan Wang7f8052e02022-01-14 18:44:283528#if BUILDFLAG(IS_ANDROID)
Lucas Furukawa Gadania9c45682019-07-31 22:05:143529 std::string(), /* data_url_as_string */
3530#endif
arthursonzogni14379782020-05-15 09:09:273531 !params.is_renderer_initiated, /* is_browser_initiated */
Tsuyoshi Horoe86d7702019-11-29 01:52:473532 GURL() /* web_bundle_physical_url */,
Charlie Hu5ffc0152019-12-06 15:59:533533 GURL() /* base_url_override_for_web_bundle */,
Yue Ru Sun128804932020-09-30 22:19:173534 ukm::kInvalidSourceId /* document_ukm_source_id */,
Jiewei Qian0406fc02020-03-09 06:02:073535 node->pending_frame_policy(),
Domenic Denicola4778c35392020-06-25 21:25:163536 std::vector<std::string>() /* force_enabled_origin_trials */,
Domenic Denicola55701ee2021-01-14 00:18:333537 false /* origin_agent_cluster */,
Maks Orlovichc66745a2020-06-30 17:40:023538 std::vector<
Shuran Huanga055ce72020-07-23 14:13:213539 network::mojom::WebClientHintsType>() /* enabled_client_hints */,
Nate Chapind1fe3612021-04-16 20:45:573540 false /* is_cross_browsing_instance */, nullptr /* old_page_info */,
3541 -1 /* http_response_code */,
Minggang Wangb9f3fa92021-07-01 15:30:313542 std::vector<blink::mojom::
3543 AppHistoryEntryPtr>() /* app_history_back_entries */,
Nate Chapind1fe3612021-04-16 20:45:573544 std::vector<
Minggang Wangb9f3fa92021-07-01 15:30:313545 blink::mojom::
3546 AppHistoryEntryPtr>() /* app_history_forward_entries */,
Matt Menke4e209082021-11-09 04:59:313547 std::vector<GURL>() /* early_hints_preloaded_resources */,
Clark DuVall8ee487a22021-11-10 02:25:583548 absl::nullopt /* ad_auction_components */,
3549 // This timestamp will be populated when the commit IPC is sent.
Yifan Luoe1a2e05d2022-01-12 16:47:593550 base::TimeTicks() /* commit_sent */, false /* anonymous */);
Xiaohan Wang7f8052e02022-01-14 18:44:283551#if BUILDFLAG(IS_ANDROID)
Camille Lamy5193caa2018-10-12 11:59:423552 if (ValidateDataURLAsString(params.data_url_as_string)) {
Lucas Furukawa Gadania9c45682019-07-31 22:05:143553 commit_params->data_url_as_string = params.data_url_as_string->data();
Camille Lamy5193caa2018-10-12 11:59:423554 }
3555#endif
3556
Lucas Furukawa Gadania9c45682019-07-31 22:05:143557 commit_params->was_activated = params.was_activated;
Camille Lamy5193caa2018-10-12 11:59:423558
3559 // A form submission may happen here if the navigation is a renderer-initiated
3560 // form submission that took the OpenURL path.
3561 scoped_refptr<network::ResourceRequestBody> request_body = params.post_data;
3562
3563 // extra_headers in params are \n separated; NavigationRequests want \r\n.
3564 std::string extra_headers_crlf;
3565 base::ReplaceChars(params.extra_headers, "\n", "\r\n", &extra_headers_crlf);
Yao Xiaodc5ed102019-06-04 19:19:093566
3567 auto navigation_request = NavigationRequest::CreateBrowserInitiated(
Lucas Furukawa Gadania9c45682019-07-31 22:05:143568 node, std::move(common_params), std::move(commit_params),
Takashi Toyoshimae87b7be2021-01-22 11:51:083569 !params.is_renderer_initiated, params.was_opener_suppressed,
Antonio Sartori9a82f6f32020-12-14 09:22:453570 params.initiator_frame_token.has_value()
3571 ? &(params.initiator_frame_token.value())
3572 : nullptr,
3573 params.initiator_process_id, extra_headers_crlf, frame_entry, entry,
3574 request_body,
John Delaney50425f82020-04-07 16:26:213575 params.navigation_ui_data ? params.navigation_ui_data->Clone() : nullptr,
Daniel Hosseinianf0fbfb42021-09-08 02:20:473576 params.impression, params.is_pdf);
Yao Xiaodc5ed102019-06-04 19:19:093577 navigation_request->set_from_download_cross_origin_redirect(
3578 params.from_download_cross_origin_redirect);
3579 return navigation_request;
Camille Lamy5193caa2018-10-12 11:59:423580}
3581
3582std::unique_ptr<NavigationRequest>
3583NavigationControllerImpl::CreateNavigationRequestFromEntry(
clamyea99ea12018-05-28 13:54:233584 FrameTreeNode* frame_tree_node,
Lucas Furukawa Gadani5553a1582019-01-08 18:55:573585 NavigationEntryImpl* entry,
clamyea99ea12018-05-28 13:54:233586 FrameNavigationEntry* frame_entry,
3587 ReloadType reload_type,
3588 bool is_same_document_history_load,
Nate Chapin45f620582021-09-30 17:45:433589 bool is_history_navigation_in_new_child_frame,
3590 bool is_browser_initiated) {
Alex Moshchuk47d1a4bd2020-06-01 22:15:343591 DCHECK(frame_entry);
clamyea99ea12018-05-28 13:54:233592 GURL dest_url = frame_entry->url();
Rakina Zata Amniddf10502022-01-15 02:56:553593 if (entry->IsInitialEntry() && frame_tree_node->IsMainFrame() &&
3594 dest_url.is_empty()) {
3595 // The main frame of an initial NavigationEntry might have an empty URL.
3596 // Convert it to about:blank instead. This should only happen when the
3597 // initial NavigationEntry is reloaded.
Rakina Zata Amniafd3c6582021-11-30 06:19:173598 dest_url = GURL("about:blank");
3599 }
Anton Bikineevf62d1bf2021-05-15 17:56:073600 absl::optional<url::Origin> origin_to_commit =
Nasko Oskov03912102019-01-11 00:21:323601 frame_entry->committed_origin();
3602
clamyea99ea12018-05-28 13:54:233603 Referrer dest_referrer = frame_entry->referrer();
Ryan Sturmc4da1992018-07-17 16:59:013604 if (reload_type == ReloadType::ORIGINAL_REQUEST_URL &&
Lucas Furukawa Gadani5553a1582019-01-08 18:55:573605 entry->GetOriginalRequestURL().is_valid() && !entry->GetHasPostData()) {
clamyea99ea12018-05-28 13:54:233606 // We may have been redirected when navigating to the current URL.
3607 // Use the URL the user originally intended to visit as signaled by the
3608 // ReloadType, if it's valid and if a POST wasn't involved; the latter
Ryan Sturmc4da1992018-07-17 16:59:013609 // case avoids issues with sending data to the wrong page.
Lucas Furukawa Gadani5553a1582019-01-08 18:55:573610 dest_url = entry->GetOriginalRequestURL();
clamyea99ea12018-05-28 13:54:233611 dest_referrer = Referrer();
Nasko Oskov03912102019-01-11 00:21:323612 origin_to_commit.reset();
clamyea99ea12018-05-28 13:54:233613 }
3614
Ehsan Karamad44fc72112019-02-26 18:15:473615 if (frame_tree_node->render_manager()->is_attaching_inner_delegate()) {
3616 // Avoid starting any new navigations since this node is now preparing for
3617 // attaching an inner delegate.
3618 return nullptr;
Ehsan Karamaddd9a4142018-12-04 20:38:203619 }
3620
Camille Lamy5193caa2018-10-12 11:59:423621 if (!IsValidURLForNavigation(frame_tree_node->IsMainFrame(),
Lucas Furukawa Gadani5553a1582019-01-08 18:55:573622 entry->GetVirtualURL(), dest_url)) {
clamyea99ea12018-05-28 13:54:233623 return nullptr;
3624 }
3625
Kunihiko Sakamoto346a74e2021-03-10 08:57:483626 if (!DoesURLMatchOriginForNavigation(
3627 dest_url, origin_to_commit,
3628 frame_entry->subresource_web_bundle_navigation_info())) {
3629 DCHECK(false) << " url:" << dest_url
3630 << " origin:" << origin_to_commit.value();
Nasko Oskov03912102019-01-11 00:21:323631 return nullptr;
3632 }
3633
clamyea99ea12018-05-28 13:54:233634 // Determine if Previews should be used for the navigation.
Hiroki Nakagawa41366152020-07-27 18:31:403635 blink::PreviewsState previews_state =
3636 blink::PreviewsTypes::PREVIEWS_UNSPECIFIED;
clamyea99ea12018-05-28 13:54:233637 if (!frame_tree_node->IsMainFrame()) {
3638 // For subframes, use the state of the top-level frame.
3639 previews_state = frame_tree_node->frame_tree()
3640 ->root()
3641 ->current_frame_host()
3642 ->last_navigation_previews_state();
clamyea99ea12018-05-28 13:54:233643 }
3644
clamyea99ea12018-05-28 13:54:233645 // This will be used to set the Navigation Timing API navigationStart
3646 // parameter for browser navigations in new tabs (intents, tabs opened through
3647 // "Open link in new tab"). If the navigation must wait on the current
3648 // RenderFrameHost to execute its BeforeUnload event, the navigation start
3649 // will be updated when the BeforeUnload ack is received.
3650 base::TimeTicks navigation_start = base::TimeTicks::Now();
clamyea99ea12018-05-28 13:54:233651
danakjd83d706d2020-11-25 22:11:123652 // Look for a pending commit that is to another document in this
3653 // FrameTreeNode. If one exists, then the last committed URL will not be the
3654 // current URL by the time this navigation commits.
3655 bool has_pending_cross_document_commit =
3656 frame_tree_node->render_manager()
3657 ->HasPendingCommitForCrossDocumentNavigation();
danakjb952ef12021-01-14 19:58:493658 bool is_currently_error_page =
Miyoung Shina2dd6a42021-10-07 12:19:213659 frame_tree_node->current_frame_host()->IsErrorDocument();
danakjd83d706d2020-11-25 22:11:123660
Minggang Wangb9f3fa92021-07-01 15:30:313661 blink::mojom::NavigationType navigation_type = GetNavigationType(
danakjd83d706d2020-11-25 22:11:123662 /*old_url=*/frame_tree_node->current_url(),
3663 /*new_url=*/dest_url, reload_type, entry, *frame_entry,
danakjb952ef12021-01-14 19:58:493664 has_pending_cross_document_commit, is_currently_error_page,
3665 is_same_document_history_load);
Camille Lamy5193caa2018-10-12 11:59:423666
3667 // A form submission may happen here if the navigation is a
3668 // back/forward/reload navigation that does a form resubmission.
3669 scoped_refptr<network::ResourceRequestBody> request_body;
3670 std::string post_content_type;
3671 if (frame_entry->method() == "POST") {
3672 request_body = frame_entry->GetPostData(&post_content_type);
3673 // Might have a LF at end.
Peter Kastingb53b81912021-04-28 19:23:303674 post_content_type = std::string(
3675 base::TrimWhitespaceASCII(post_content_type, base::TRIM_ALL));
Camille Lamy5193caa2018-10-12 11:59:423676 }
3677
3678 // Create the NavigationParams based on |entry| and |frame_entry|.
Minggang Wangb9f3fa92021-07-01 15:30:313679 blink::mojom::CommonNavigationParamsPtr common_params =
Lucas Furukawa Gadanief8290a2019-07-29 20:27:513680 entry->ConstructCommonNavigationParams(
3681 *frame_entry, request_body, dest_url,
3682 blink::mojom::Referrer::New(dest_referrer.url, dest_referrer.policy),
3683 navigation_type, previews_state, navigation_start,
Charlie Hu5ffc0152019-12-06 15:59:533684 base::TimeTicks() /* input_start */);
Lucas Furukawa Gadanief8290a2019-07-29 20:27:513685 common_params->is_history_navigation_in_new_child_frame =
Arthur Hemerybee4a752019-05-29 10:50:553686 is_history_navigation_in_new_child_frame;
Camille Lamy5193caa2018-10-12 11:59:423687
3688 // TODO(clamy): |intended_as_new_entry| below should always be false once
3689 // Reload no longer leads to this being called for a pending NavigationEntry
3690 // of index -1.
Minggang Wangb9f3fa92021-07-01 15:30:313691 blink::mojom::CommitNavigationParamsPtr commit_params =
Lucas Furukawa Gadania9c45682019-07-31 22:05:143692 entry->ConstructCommitNavigationParams(
3693 *frame_entry, common_params->url, origin_to_commit,
3694 common_params->method, entry->GetSubframeUniqueNames(frame_tree_node),
3695 GetPendingEntryIndex() == -1 /* intended_as_new_entry */,
Charlie Hu5ffc0152019-12-06 15:59:533696 GetIndexOfEntry(entry), GetLastCommittedEntryIndex(), GetEntryCount(),
3697 frame_tree_node->pending_frame_policy());
Lucas Furukawa Gadania9c45682019-07-31 22:05:143698 commit_params->post_content_type = post_content_type;
Camille Lamy5193caa2018-10-12 11:59:423699
clamyea99ea12018-05-28 13:54:233700 return NavigationRequest::CreateBrowserInitiated(
Lucas Furukawa Gadania9c45682019-07-31 22:05:143701 frame_tree_node, std::move(common_params), std::move(commit_params),
Nate Chapin45f620582021-09-30 17:45:433702 is_browser_initiated, false /* was_opener_suppressed */,
Takashi Toyoshimae87b7be2021-01-22 11:51:083703 nullptr /* initiator_frame_token */,
Antonio Sartori9a82f6f32020-12-14 09:22:453704 ChildProcessHost::kInvalidUniqueID /* initiator_process_id */,
3705 entry->extra_headers(), frame_entry, entry, request_body,
Daniel Hosseinianf0fbfb42021-09-08 02:20:473706 nullptr /* navigation_ui_data */, absl::nullopt /* impression */,
3707 false /* is_pdf */);
clamyea99ea12018-05-28 13:54:233708}
3709
[email protected]d202a7c2012-01-04 07:53:473710void NavigationControllerImpl::NotifyNavigationEntryCommitted(
[email protected]8ff00d72012-10-23 19:12:213711 LoadCommittedDetails* details) {
[email protected]6286a3792013-10-09 04:03:273712 details->entry = GetLastCommittedEntry();
[email protected]df1af242009-05-01 00:11:403713
Takashi Toyoshimaea534ef22021-07-21 03:27:593714 // We need to notify the ssl_manager_ before the WebContents so the
[email protected]df1af242009-05-01 00:11:403715 // location bar will have up-to-date information about the security style
3716 // when it wants to draw. See http://crbug.com/11157
[email protected]b0f724c2013-09-05 04:21:133717 ssl_manager_.DidCommitProvisionalLoad(*details);
[email protected]df1af242009-05-01 00:11:403718
Rakina Zata Amnia4e27222021-12-22 01:05:003719 delegate_->NotifyNavigationStateChanged(
Rakina Zata Amniddf10502022-01-15 02:56:553720 (details && details->should_stay_as_initial_entry)
3721 ? INVALIDATE_TYPE_ALL_BUT_KEEPS_INITIAL_NAVIGATION_ENTRY_STATUS
3722 : INVALIDATE_TYPE_ALL_AND_REMOVES_INITIAL_NAVIGATION_ENTRY_STATUS);
[email protected]ec6c05f2013-10-23 18:41:573723 delegate_->NotifyNavigationEntryCommitted(*details);
[email protected]cbb1ef592013-06-05 19:49:463724
[email protected]b0f724c2013-09-05 04:21:133725 // TODO(avi): Remove. http://crbug.com/170921
3726 NotificationDetails notification_details =
3727 Details<LoadCommittedDetails>(details);
Aran Gilman37d11632019-10-08 23:07:153728 NotificationService::current()->Notify(NOTIFICATION_NAV_ENTRY_COMMITTED,
3729 Source<NavigationController>(this),
3730 notification_details);
initial.commit09911bf2008-07-26 23:55:293731}
3732
initial.commit09911bf2008-07-26 23:55:293733// static
[email protected]d202a7c2012-01-04 07:53:473734size_t NavigationControllerImpl::max_entry_count() {
[email protected]9b51970d2011-12-09 23:10:233735 if (max_entry_count_for_testing_ != kMaxEntryCountForTestingNotSet)
Aran Gilman37d11632019-10-08 23:07:153736 return max_entry_count_for_testing_;
Miyoung Shin1c565c912021-03-17 12:11:213737 return blink::kMaxSessionHistoryEntries;
[email protected]9b51970d2011-12-09 23:10:233738}
3739
[email protected]d202a7c2012-01-04 07:53:473740void NavigationControllerImpl::SetActive(bool is_active) {
[email protected]ee613922009-09-02 20:38:223741 if (is_active && needs_reload_)
3742 LoadIfNecessary();
initial.commit09911bf2008-07-26 23:55:293743}
3744
[email protected]d202a7c2012-01-04 07:53:473745void NavigationControllerImpl::LoadIfNecessary() {
initial.commit09911bf2008-07-26 23:55:293746 if (!needs_reload_)
3747 return;
3748
Bo Liucdfa4b12018-11-06 00:21:443749 UMA_HISTOGRAM_ENUMERATION("Navigation.LoadIfNecessaryType",
3750 needs_reload_type_);
3751
initial.commit09911bf2008-07-26 23:55:293752 // Calling Reload() results in ignoring state, and not loading.
3753 // Explicitly use NavigateToPendingEntry so that the renderer uses the
3754 // cached state.
avicc872d7242015-08-19 21:26:343755 if (pending_entry_) {
Dave Tapuska8bfd84c2019-03-26 20:47:163756 NavigateToExistingPendingEntry(ReloadType::NONE,
Nate Chapin45f620582021-09-30 17:45:433757 FrameTreeNode::kFrameTreeNodeInvalidId,
3758 true /* is_browser_initiated */);
avicc872d7242015-08-19 21:26:343759 } else if (last_committed_entry_index_ != -1) {
arthursonzogni5c4c202d2017-04-25 23:41:273760 pending_entry_ = entries_[last_committed_entry_index_].get();
avicc872d7242015-08-19 21:26:343761 pending_entry_index_ = last_committed_entry_index_;
Dave Tapuska8bfd84c2019-03-26 20:47:163762 NavigateToExistingPendingEntry(ReloadType::NONE,
Nate Chapin45f620582021-09-30 17:45:433763 FrameTreeNode::kFrameTreeNodeInvalidId,
3764 true /* is_browser_initiated */);
avicc872d7242015-08-19 21:26:343765 } else {
3766 // If there is something to reload, the successful reload will clear the
3767 // |needs_reload_| flag. Otherwise, just do it here.
3768 needs_reload_ = false;
3769 }
initial.commit09911bf2008-07-26 23:55:293770}
3771
Kevin McNeeccca6172021-10-19 17:11:143772base::WeakPtr<NavigationHandle>
3773NavigationControllerImpl::LoadPostCommitErrorPage(
Carlos IL42b416592019-10-07 23:10:363774 RenderFrameHost* render_frame_host,
3775 const GURL& url,
3776 const std::string& error_page_html,
3777 net::Error error) {
Rakina Zata Amni919b7922020-12-11 09:03:133778 RenderFrameHostImpl* rfhi =
3779 static_cast<RenderFrameHostImpl*>(render_frame_host);
Sreeja Kamishettydb8e2892021-03-10 09:30:583780
3781 // Only active documents can load post-commit error pages:
3782 // - If the document is in pending deletion, the browser already committed to
3783 // destroying this RenderFrameHost so ignore loading the error page.
3784 // - If the document is in back-forward cache, it's not allowed to navigate as
3785 // it should remain frozen. Ignore the request and evict the document from
3786 // back-forward cache.
3787 // - If the document is prerendering, it can navigate but when loading error
3788 // pages, cancel prerendering.
Fergal Daly1336ac642021-09-14 15:13:113789 if (rfhi->IsInactiveAndDisallowActivation(
3790 DisallowActivationReasonId::kLoadPostCommitErrorPage)) {
Kevin McNeeccca6172021-10-19 17:11:143791 return nullptr;
Fergal Daly1336ac642021-09-14 15:13:113792 }
Sreeja Kamishettydb8e2892021-03-10 09:30:583793
Rakina Zata Amni919b7922020-12-11 09:03:133794 FrameTreeNode* node = rfhi->frame_tree_node();
John Delaney131ad362019-08-08 21:57:413795
Minggang Wangb9f3fa92021-07-01 15:30:313796 blink::mojom::CommonNavigationParamsPtr common_params =
Minggang Wanga13c796e2021-07-02 05:54:433797 blink::CreateCommonNavigationParams();
Rakina Zata Amnid2da1542020-12-23 00:52:593798 // |url| might be empty, such as when LoadPostCommitErrorPage happens before
3799 // the frame actually committed (e.g. iframe with "src" set to a
3800 // slow-responding URL). We should rewrite the URL to about:blank in this
3801 // case, as the renderer will only think a page is an error page if it has a
3802 // non-empty unreachable URL.
Rakina Zata Amni919b7922020-12-11 09:03:133803 common_params->url = url.is_empty() ? GURL("about:blank") : url;
Minggang Wangb9f3fa92021-07-01 15:30:313804 blink::mojom::CommitNavigationParamsPtr commit_params =
Minggang Wanga13c796e2021-07-02 05:54:433805 blink::CreateCommitNavigationParams();
Antonio Sartori58591c892021-04-21 06:54:333806 commit_params->original_url = common_params->url;
John Delaney131ad362019-08-08 21:57:413807
arthursonzogni70ac7302020-05-28 08:49:053808 // Error pages have a fully permissive FramePolicy.
3809 // TODO(arthursonzogni): Consider providing the minimal capabilities to the
3810 // error pages.
3811 commit_params->frame_policy = blink::FramePolicy();
3812
John Delaney131ad362019-08-08 21:57:413813 std::unique_ptr<NavigationRequest> navigation_request =
3814 NavigationRequest::CreateBrowserInitiated(
3815 node, std::move(common_params), std::move(commit_params),
Takashi Toyoshimae87b7be2021-01-22 11:51:083816 true /* browser_initiated */, false /* was_opener_suppressed */,
Lingqi Chi82efa95e2020-12-29 05:31:193817 nullptr /* initiator_frame_token */,
Antonio Sartori9a82f6f32020-12-14 09:22:453818 ChildProcessHost::kInvalidUniqueID /* initiator_process_id */,
John Delaneyf43556d2020-05-04 23:19:063819 "" /* extra_headers */, nullptr /* frame_entry */,
3820 nullptr /* entry */, nullptr /* post_body */,
Daniel Hosseinianf0fbfb42021-09-08 02:20:473821 nullptr /* navigation_ui_data */, absl::nullopt /* impression */,
3822 false /* is_pdf */);
Carlos IL42b416592019-10-07 23:10:363823 navigation_request->set_post_commit_error_page_html(error_page_html);
John Delaney131ad362019-08-08 21:57:413824 navigation_request->set_net_error(error);
3825 node->CreatedNavigationRequest(std::move(navigation_request));
3826 DCHECK(node->navigation_request());
Kevin McNeeccca6172021-10-19 17:11:143827
3828 // Calling BeginNavigation may destroy the NavigationRequest.
3829 base::WeakPtr<NavigationRequest> created_navigation_request(
3830 node->navigation_request()->GetWeakPtr());
John Delaney131ad362019-08-08 21:57:413831 node->navigation_request()->BeginNavigation();
Kevin McNeeccca6172021-10-19 17:11:143832 return created_navigation_request;
John Delaney131ad362019-08-08 21:57:413833}
3834
Lucas Furukawa Gadani5553a1582019-01-08 18:55:573835void NavigationControllerImpl::NotifyEntryChanged(NavigationEntry* entry) {
[email protected]8ff00d72012-10-23 19:12:213836 EntryChangedDetails det;
[email protected]534e54b2008-08-13 15:40:093837 det.changed_entry = entry;
Aran Gilman37d11632019-10-08 23:07:153838 det.index = GetIndexOfEntry(NavigationEntryImpl::FromNavigationEntry(entry));
Sam McNally5c087a32017-08-25 01:46:143839 delegate_->NotifyNavigationEntryChanged(det);
initial.commit09911bf2008-07-26 23:55:293840}
3841
[email protected]d202a7c2012-01-04 07:53:473842void NavigationControllerImpl::FinishRestore(int selected_index,
[email protected]2ca1ea662012-10-04 02:26:363843 RestoreType type) {
[email protected]a26023822011-12-29 00:23:553844 DCHECK(selected_index >= 0 && selected_index < GetEntryCount());
[email protected]2ca1ea662012-10-04 02:26:363845 ConfigureEntriesForRestore(&entries_, type);
initial.commit09911bf2008-07-26 23:55:293846
initial.commit09911bf2008-07-26 23:55:293847 last_committed_entry_index_ = selected_index;
initial.commit09911bf2008-07-26 23:55:293848}
[email protected]765b35502008-08-21 00:51:203849
arthursonzogni69a6a1b2019-09-17 09:23:003850void NavigationControllerImpl::DiscardNonCommittedEntries() {
Rakina Zata Amnia4e27222021-12-22 01:05:003851 DiscardNonCommittedEntriesWithCommitDetails(nullptr /* commit_details */);
3852}
3853
3854void NavigationControllerImpl::DiscardNonCommittedEntriesWithCommitDetails(
3855 LoadCommittedDetails* commit_details) {
Michael Thiessen9b14d512019-09-23 21:19:473856 // Avoid sending a notification if there is nothing to discard.
Michael Thiessenc5676d22019-09-25 22:32:103857 // TODO(mthiesse): Temporarily checking failed_pending_entry_id_ to help
3858 // diagnose https://bugs.chromium.org/p/chromium/issues/detail?id=1007570.
Carlos IL4dea8902020-05-26 15:14:293859 if (!pending_entry_ && failed_pending_entry_id_ == 0) {
Michael Thiessen9b14d512019-09-23 21:19:473860 return;
Michael Thiessenc5676d22019-09-25 22:32:103861 }
avi45a72532015-04-07 21:01:453862 DiscardPendingEntry(false);
Rakina Zata Amniddf10502022-01-15 02:56:553863 if (delegate_) {
Rakina Zata Amnia4e27222021-12-22 01:05:003864 delegate_->NotifyNavigationStateChanged(
Rakina Zata Amniddf10502022-01-15 02:56:553865 (commit_details && commit_details->should_stay_as_initial_entry)
3866 ? INVALIDATE_TYPE_ALL_BUT_KEEPS_INITIAL_NAVIGATION_ENTRY_STATUS
3867 : INVALIDATE_TYPE_ALL_AND_REMOVES_INITIAL_NAVIGATION_ENTRY_STATUS);
3868 }
[email protected]b12eb222013-09-10 00:11:483869}
3870
avi7c6f35e2015-05-08 17:52:383871int NavigationControllerImpl::GetEntryIndexWithUniqueID(
3872 int nav_entry_id) const {
3873 for (int i = static_cast<int>(entries_.size()) - 1; i >= 0; --i) {
3874 if (entries_[i]->GetUniqueID() == nav_entry_id)
3875 return i;
3876 }
3877 return -1;
3878}
3879
[email protected]d202a7c2012-01-04 07:53:473880void NavigationControllerImpl::InsertEntriesFrom(
Lucas Furukawa Gadani5553a1582019-01-08 18:55:573881 NavigationControllerImpl* source,
[email protected]e1cd5452010-08-26 18:03:253882 int max_index) {
Lucas Furukawa Gadani5553a1582019-01-08 18:55:573883 DCHECK_LE(max_index, source->GetEntryCount());
Nate Chapin214a86a2021-06-21 20:35:573884 std::unique_ptr<NavigationEntryRestoreContextImpl> context =
3885 std::make_unique<NavigationEntryRestoreContextImpl>();
[email protected]e1cd5452010-08-26 18:03:253886 for (int i = 0; i < max_index; i++) {
Nate Chapin9f169072021-06-09 19:32:373887 // Normally, cloning a NavigationEntryImpl results in sharing
3888 // FrameNavigationEntries between the original and the clone. However, when
3889 // cloning from a different NavigationControllerImpl, we want to fork the
3890 // FrameNavigationEntries.
Nate Chapin9f169072021-06-09 19:32:373891 entries_.insert(entries_.begin() + i,
Nate Chapin214a86a2021-06-21 20:35:573892 source->entries_[i]->CloneWithoutSharing(context.get()));
[email protected]e1cd5452010-08-26 18:03:253893 }
Rakina Zata Amniafd3c6582021-11-30 06:19:173894 DCHECK_GE(entries_.size(), 1u);
arthursonzogni5c4c202d2017-04-25 23:41:273895 DCHECK(pending_entry_index_ == -1 ||
3896 pending_entry_ == GetEntryAtIndex(pending_entry_index_));
[email protected]e1cd5452010-08-26 18:03:253897}
[email protected]c5b88d82012-10-06 17:03:333898
3899void NavigationControllerImpl::SetGetTimestampCallbackForTest(
Makoto Shimazud2aa2202019-10-09 13:57:183900 const base::RepeatingCallback<base::Time()>& get_timestamp_callback) {
[email protected]c5b88d82012-10-06 17:03:333901 get_timestamp_callback_ = get_timestamp_callback;
3902}
[email protected]8ff00d72012-10-23 19:12:213903
Shivani Sharmaffb32b82019-04-09 16:58:473904// History manipulation intervention:
3905void NavigationControllerImpl::SetShouldSkipOnBackForwardUIIfNeeded(
Shivani Sharmaffb32b82019-04-09 16:58:473906 bool replace_entry,
3907 bool previous_document_was_activated,
Alexander Timine3ec4192020-04-20 16:39:403908 bool is_renderer_initiated,
3909 ukm::SourceId previous_page_load_ukm_source_id) {
Shivani Sharma712d5d72019-04-16 21:56:453910 // Note that for a subframe, previous_document_was_activated is true if the
3911 // gesture happened in any subframe (propagated to main frame) or in the main
3912 // frame itself.
Shivani Sharmaffb32b82019-04-09 16:58:473913 if (replace_entry || previous_document_was_activated ||
shivanigithubcceeacf2020-03-06 20:00:273914 !is_renderer_initiated) {
Shivani Sharmaffb32b82019-04-09 16:58:473915 return;
3916 }
3917 if (last_committed_entry_index_ == -1)
3918 return;
3919
Shivani Sharmac4cc8922019-04-18 03:11:173920 SetSkippableForSameDocumentEntries(last_committed_entry_index_, true);
Shivani Sharmaffb32b82019-04-09 16:58:473921
Alexander Timine3ec4192020-04-20 16:39:403922 // Log UKM with the URL we are navigating away from.
3923 ukm::builders::HistoryManipulationIntervention(
3924 previous_page_load_ukm_source_id)
3925 .Record(ukm::UkmRecorder::Get());
Shivani Sharmaffb32b82019-04-09 16:58:473926}
3927
Shivani Sharmac4cc8922019-04-18 03:11:173928void NavigationControllerImpl::SetSkippableForSameDocumentEntries(
3929 int reference_index,
3930 bool skippable) {
3931 auto* reference_entry = GetEntryAtIndex(reference_index);
3932 reference_entry->set_should_skip_on_back_forward_ui(skippable);
3933
3934 int64_t document_sequence_number =
3935 reference_entry->root_node()->frame_entry->document_sequence_number();
3936 for (int index = 0; index < GetEntryCount(); index++) {
3937 auto* entry = GetEntryAtIndex(index);
3938 if (entry->root_node()->frame_entry->document_sequence_number() ==
3939 document_sequence_number) {
3940 entry->set_should_skip_on_back_forward_ui(skippable);
3941 }
3942 }
3943}
3944
arthursonzogni66f711c2019-10-08 14:40:363945std::unique_ptr<NavigationControllerImpl::PendingEntryRef>
3946NavigationControllerImpl::ReferencePendingEntry() {
3947 DCHECK(pending_entry_);
3948 auto pending_entry_ref =
3949 std::make_unique<PendingEntryRef>(weak_factory_.GetWeakPtr());
3950 pending_entry_refs_.insert(pending_entry_ref.get());
3951 return pending_entry_ref;
3952}
3953
3954void NavigationControllerImpl::PendingEntryRefDeleted(PendingEntryRef* ref) {
3955 // Ignore refs that don't correspond to the current pending entry.
3956 auto it = pending_entry_refs_.find(ref);
3957 if (it == pending_entry_refs_.end())
3958 return;
3959 pending_entry_refs_.erase(it);
3960
3961 if (!pending_entry_refs_.empty())
3962 return;
3963
3964 // The pending entry may be deleted before the last PendingEntryRef.
3965 if (!pending_entry_)
3966 return;
3967
3968 // We usually clear the pending entry when the matching NavigationRequest
3969 // fails, so that an arbitrary URL isn't left visible above a committed page.
3970 //
3971 // However, we do preserve the pending entry in some cases, such as on the
3972 // initial navigation of an unmodified blank tab. We also allow the delegate
3973 // to say when it's safe to leave aborted URLs in the omnibox, to let the
3974 // user edit the URL and try again. This may be useful in cases that the
3975 // committed page cannot be attacker-controlled. In these cases, we still
3976 // allow the view to clear the pending entry and typed URL if the user
3977 // requests (e.g., hitting Escape with focus in the address bar).
3978 //
3979 // Do not leave the pending entry visible if it has an invalid URL, since this
3980 // might be formatted in an unexpected or unsafe way.
3981 // TODO(creis): Block navigations to invalid URLs in https://crbug.com/850824.
arthursonzogni66f711c2019-10-08 14:40:363982 bool should_preserve_entry =
3983 (pending_entry_ == GetVisibleEntry()) &&
3984 pending_entry_->GetURL().is_valid() &&
3985 (IsUnmodifiedBlankTab() || delegate_->ShouldPreserveAbortedURLs());
3986 if (should_preserve_entry)
3987 return;
3988
3989 DiscardPendingEntry(true);
3990 delegate_->NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
3991}
3992
Titouan Rigoudy6ec70402021-02-02 15:42:193993std::unique_ptr<PolicyContainerPolicies>
3994NavigationControllerImpl::ComputePolicyContainerPoliciesForFrameEntry(
Antonio Sartori78a749f2020-11-30 12:03:393995 RenderFrameHostImpl* rfh,
3996 bool is_same_document,
Rakina Zata Amniafd3c6582021-11-30 06:19:173997 const GURL& url) {
Antonio Sartori78a749f2020-11-30 12:03:393998 if (is_same_document) {
Rakina Zata Amniafd3c6582021-11-30 06:19:173999 CHECK(GetLastCommittedEntry());
Charlie Reis73e356242021-04-02 17:10:314000
Antonio Sartori78a749f2020-11-30 12:03:394001 FrameNavigationEntry* previous_frame_entry =
4002 GetLastCommittedEntry()->GetFrameEntry(rfh->frame_tree_node());
4003
4004 // TODO(https://crbug.com/608402): Remove this nullptr check when we can
4005 // ensure we always have a FrameNavigationEntry here.
4006 if (!previous_frame_entry)
4007 return nullptr;
4008
Titouan Rigoudy6ec70402021-02-02 15:42:194009 const PolicyContainerPolicies* previous_policies =
4010 previous_frame_entry->policy_container_policies();
Antonio Sartori78a749f2020-11-30 12:03:394011
Titouan Rigoudy6ec70402021-02-02 15:42:194012 if (!previous_policies)
Antonio Sartori78a749f2020-11-30 12:03:394013 return nullptr;
4014
4015 // Make a copy of the policy container for the new FrameNavigationEntry.
Antonio Sartori5d09b30f2021-03-02 09:27:164016 return previous_policies->Clone();
Antonio Sartori78a749f2020-11-30 12:03:394017 }
4018
Antonio Sartori4f5373792021-05-31 10:56:474019 return rfh->policy_container_host()->policies().Clone();
Antonio Sartori78a749f2020-11-30 12:03:394020}
4021
Hayato Ito2c8c08d02021-06-23 03:38:434022void NavigationControllerImpl::BroadcastHistoryOffsetAndLength() {
Carlos Caballeroede6f8c2021-01-28 11:01:504023 OPTIONAL_TRACE_EVENT2(
Hayato Ito2c8c08d02021-06-23 03:38:434024 "content", "NavigationControllerImpl::BroadcastHistoryOffsetAndLength",
4025 "history_offset", GetLastCommittedEntryIndex(), "history_length",
4026 GetEntryCount());
Carlos Caballeroede6f8c2021-01-28 11:01:504027
4028 auto callback = base::BindRepeating(
4029 [](int history_offset, int history_length, RenderViewHostImpl* rvh) {
4030 if (auto& broadcast = rvh->GetAssociatedPageBroadcast()) {
4031 broadcast->SetHistoryOffsetAndLength(history_offset, history_length);
4032 }
4033 },
Hayato Ito2c8c08d02021-06-23 03:38:434034 GetLastCommittedEntryIndex(), GetEntryCount());
Carlos Caballeroede6f8c2021-01-28 11:01:504035 frame_tree_.root()->render_manager()->ExecutePageBroadcastMethod(callback);
4036}
4037
4038void NavigationControllerImpl::DidAccessInitialMainDocument() {
4039 // We may have left a failed browser-initiated navigation in the address bar
4040 // to let the user edit it and try again. Clear it now that content might
4041 // show up underneath it.
4042 if (!frame_tree_.IsLoading() && GetPendingEntry())
4043 DiscardPendingEntry(false);
4044
4045 // Update the URL display.
4046 delegate_->NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
4047}
4048
4049void NavigationControllerImpl::UpdateStateForFrame(
4050 RenderFrameHostImpl* rfhi,
4051 const blink::PageState& page_state) {
Alexander Timinf785f342021-03-18 00:00:564052 OPTIONAL_TRACE_EVENT1("content",
4053 "NavigationControllerImpl::UpdateStateForFrame",
4054 "render_frame_host", rfhi);
Carlos Caballeroede6f8c2021-01-28 11:01:504055 // The state update affects the last NavigationEntry associated with the given
4056 // |render_frame_host|. This may not be the last committed NavigationEntry (as
4057 // in the case of an UpdateState from a frame being swapped out). We track
4058 // which entry this is in the RenderFrameHost's nav_entry_id.
4059 NavigationEntryImpl* entry = GetEntryWithUniqueID(rfhi->nav_entry_id());
4060 if (!entry)
4061 return;
4062
4063 FrameNavigationEntry* frame_entry =
4064 entry->GetFrameEntry(rfhi->frame_tree_node());
4065 if (!frame_entry)
4066 return;
4067
4068 // The SiteInstance might not match if we do a cross-process navigation with
4069 // replacement (e.g., auto-subframe), in which case the swap out of the old
4070 // RenderFrameHost runs in the background after the old FrameNavigationEntry
4071 // has already been replaced and destroyed.
4072 if (frame_entry->site_instance() != rfhi->GetSiteInstance())
4073 return;
4074
4075 if (page_state == frame_entry->page_state())
4076 return; // Nothing to update.
4077
4078 DCHECK(page_state.IsValid()) << "Shouldn't set an empty PageState.";
4079
4080 // The document_sequence_number and item_sequence_number recorded in the
4081 // FrameNavigationEntry should not differ from the one coming with the update,
4082 // since it must come from the same document. Do not update it if a difference
4083 // is detected, as this indicates that |frame_entry| is not the correct one.
4084 blink::ExplodedPageState exploded_state;
4085 if (!blink::DecodePageState(page_state.ToEncodedData(), &exploded_state))
4086 return;
4087
4088 if (exploded_state.top.document_sequence_number !=
4089 frame_entry->document_sequence_number() ||
4090 exploded_state.top.item_sequence_number !=
4091 frame_entry->item_sequence_number()) {
4092 return;
4093 }
4094
4095 frame_entry->SetPageState(page_state);
4096 NotifyEntryChanged(entry);
4097}
4098
Aaron Colwellb731a0ae2021-03-19 19:14:474099void NavigationControllerImpl::OnStoragePartitionIdAdded(
4100 const StoragePartitionId& partition_id) {
4101 auto it = partition_config_to_id_map_.insert(
4102 std::make_pair(partition_id.config(), partition_id));
4103 bool successful_insert = it.second;
Aaron Colwellb731a0ae2021-03-19 19:14:474104 if (!successful_insert) {
4105 LogStoragePartitionIdCrashKeys(it.first->second, partition_id);
4106 }
Sharon Yangd4f48792021-06-30 17:02:534107 CHECK(successful_insert);
Aaron Colwellb731a0ae2021-03-19 19:14:474108}
4109
4110void NavigationControllerImpl::LogStoragePartitionIdCrashKeys(
4111 const StoragePartitionId& original_partition_id,
4112 const StoragePartitionId& new_partition_id) {
4113 base::debug::SetCrashKeyString(
4114 base::debug::AllocateCrashKeyString("original_partition_id",
4115 base::debug::CrashKeySize::Size256),
4116 original_partition_id.ToString());
4117
4118 base::debug::SetCrashKeyString(
4119 base::debug::AllocateCrashKeyString("new_partition_id",
4120 base::debug::CrashKeySize::Size256),
4121 new_partition_id.ToString());
Aaron Colwellb731a0ae2021-03-19 19:14:474122}
4123
Minggang Wangb9f3fa92021-07-01 15:30:314124std::vector<blink::mojom::AppHistoryEntryPtr>
Nate Chapind1fe3612021-04-16 20:45:574125NavigationControllerImpl::PopulateSingleAppHistoryEntryVector(
4126 Direction direction,
4127 int entry_index,
4128 const url::Origin& pending_origin,
4129 FrameTreeNode* node,
4130 SiteInstance* site_instance,
4131 int64_t previous_item_sequence_number) {
Minggang Wangb9f3fa92021-07-01 15:30:314132 std::vector<blink::mojom::AppHistoryEntryPtr> entries;
Rakina Zata Amniafd3c6582021-11-30 06:19:174133 if (GetLastCommittedEntry()->IsInitialEntry()) {
4134 // Don't process the initial entry.
4135 DCHECK_EQ(GetEntryCount(), 1);
4136 return entries;
4137 }
Nate Chapind1fe3612021-04-16 20:45:574138 int offset = direction == Direction::kForward ? 1 : -1;
4139 for (int i = entry_index + offset; i >= 0 && i < GetEntryCount();
4140 i += offset) {
4141 FrameNavigationEntry* frame_entry = GetEntryAtIndex(i)->GetFrameEntry(node);
4142 if (!frame_entry || !frame_entry->committed_origin())
4143 break;
4144 if (site_instance != frame_entry->site_instance())
4145 break;
4146 if (!pending_origin.IsSameOriginWith(*frame_entry->committed_origin()))
4147 break;
4148 if (previous_item_sequence_number == frame_entry->item_sequence_number())
4149 continue;
4150 blink::ExplodedPageState exploded_page_state;
4151 if (blink::DecodePageState(frame_entry->page_state().ToEncodedData(),
4152 &exploded_page_state)) {
4153 blink::ExplodedFrameState frame_state = exploded_page_state.top;
Minggang Wangb9f3fa92021-07-01 15:30:314154 blink::mojom::AppHistoryEntryPtr entry =
4155 blink::mojom::AppHistoryEntry::New(
4156 frame_state.app_history_key.value_or(std::u16string()),
4157 frame_state.app_history_id.value_or(std::u16string()),
Nate Chapinab5c3a712021-11-18 22:17:094158 frame_state.url_string.value_or(std::u16string()),
4159 frame_state.item_sequence_number,
4160 frame_state.document_sequence_number,
4161 frame_state.app_history_state.value_or(std::u16string()));
Rakina Zata Amniafd3c6582021-11-30 06:19:174162
Nate Chapind1fe3612021-04-16 20:45:574163 DCHECK(pending_origin.CanBeDerivedFrom(GURL(entry->url)));
4164 entries.push_back(std::move(entry));
4165 previous_item_sequence_number = frame_entry->item_sequence_number();
4166 }
4167 }
4168 // If |entries| was constructed by iterating backwards from
4169 // |entry_index|, it's latest-at-the-front, but the renderer will want it
4170 // earliest-at-the-front. Reverse it.
4171 if (direction == Direction::kBack)
4172 std::reverse(entries.begin(), entries.end());
4173 return entries;
4174}
4175
4176void NavigationControllerImpl::PopulateAppHistoryEntryVectors(
4177 NavigationRequest* request) {
4178 url::Origin pending_origin =
4179 request->commit_params().origin_to_commit
4180 ? *request->commit_params().origin_to_commit
4181 : url::Origin::Create(request->common_params().url);
4182
4183 FrameTreeNode* node = request->frame_tree_node();
4184 scoped_refptr<SiteInstance> site_instance =
4185 request->GetRenderFrameHost()->GetSiteInstance();
4186
4187 // NOTE: |entry_index| is an estimate of the index where this entry will
4188 // commit, but it may be wrong in corner cases (e.g., if we are at the max
4189 // entry limit, the earliest entry will be dropped). This is ok because this
4190 // algorithm only uses |entry_index| to walk the entry list as it stands right
4191 // now, and it isn't saved for anything post-commit.
4192 int entry_index = GetPendingEntryIndex();
4193 bool will_create_new_entry = false;
4194 if (NavigationTypeUtils::IsReload(request->common_params().navigation_type) ||
4195 request->common_params().should_replace_current_entry) {
4196 entry_index = GetLastCommittedEntryIndex();
4197 } else if (entry_index == -1) {
4198 will_create_new_entry = true;
4199 entry_index = GetLastCommittedEntryIndex() + 1;
4200 }
4201
4202 int64_t pending_item_sequence_number = 0;
4203 if (auto* pending_entry = GetPendingEntry()) {
4204 if (auto* frame_entry = pending_entry->GetFrameEntry(node))
4205 pending_item_sequence_number = frame_entry->item_sequence_number();
4206 }
4207
4208 request->set_app_history_back_entries(PopulateSingleAppHistoryEntryVector(
4209 Direction::kBack, entry_index, pending_origin, node, site_instance.get(),
4210 pending_item_sequence_number));
4211
4212 // Don't populate forward entries if they will be truncated by a new entry.
4213 if (!will_create_new_entry) {
4214 request->set_app_history_forward_entries(
4215 PopulateSingleAppHistoryEntryVector(
4216 Direction::kForward, entry_index, pending_origin, node,
4217 site_instance.get(), pending_item_sequence_number));
4218 }
4219}
4220
Nate Chapinfbfe5af2021-06-10 17:22:084221NavigationControllerImpl::HistoryNavigationAction
4222NavigationControllerImpl::ShouldNavigateToEntryForAppHistoryKey(
4223 FrameNavigationEntry* current_entry,
4224 FrameNavigationEntry* target_entry,
4225 const std::string& app_history_key) {
4226 if (!target_entry || !target_entry->committed_origin())
4227 return HistoryNavigationAction::kStopLooking;
4228 if (current_entry->site_instance() != target_entry->site_instance())
4229 return HistoryNavigationAction::kStopLooking;
4230 if (!current_entry->committed_origin()->IsSameOriginWith(
4231 *target_entry->committed_origin())) {
4232 return HistoryNavigationAction::kStopLooking;
4233 }
4234
4235 // NOTE: We don't actually care between kSameDocument and
4236 // kDifferentDocument, so always use kDifferentDocument by convention.
4237 if (target_entry->app_history_key() == app_history_key)
4238 return HistoryNavigationAction::kDifferentDocument;
4239 return HistoryNavigationAction::kKeepLooking;
4240}
4241
4242void NavigationControllerImpl::NavigateToAppHistoryKey(FrameTreeNode* node,
4243 const std::string& key) {
4244 FrameNavigationEntry* current_entry =
4245 GetLastCommittedEntry()->GetFrameEntry(node);
4246 if (!current_entry)
4247 return;
4248
4249 // We want to find the nearest matching entry that is contiguously
4250 // same-instance and same-origin. Check back first, then forward.
4251 // TODO(japhet): Link spec here once it exists.
4252 for (int i = GetCurrentEntryIndex() - 1; i >= 0; i--) {
4253 auto result = ShouldNavigateToEntryForAppHistoryKey(
4254 current_entry, GetEntryAtIndex(i)->GetFrameEntry(node), key);
4255 if (result == HistoryNavigationAction::kStopLooking)
4256 break;
4257 if (result != HistoryNavigationAction::kKeepLooking) {
Nate Chapin2892b37c2021-10-08 17:33:114258 GoToIndex(i, FrameTreeNode::kFrameTreeNodeInvalidId,
4259 false /* is_browser_initiated*/);
Nate Chapinfbfe5af2021-06-10 17:22:084260 return;
4261 }
4262 }
4263 for (int i = GetCurrentEntryIndex() + 1; i < GetEntryCount(); i++) {
4264 auto result = ShouldNavigateToEntryForAppHistoryKey(
4265 current_entry, GetEntryAtIndex(i)->GetFrameEntry(node), key);
4266 if (result == HistoryNavigationAction::kStopLooking)
4267 break;
4268 if (result != HistoryNavigationAction::kKeepLooking) {
Nate Chapin2892b37c2021-10-08 17:33:114269 GoToIndex(i, FrameTreeNode::kFrameTreeNodeInvalidId,
4270 false /* is_browser_initiated*/);
Nate Chapinfbfe5af2021-06-10 17:22:084271 return;
4272 }
4273 }
4274}
4275
shivanigithubf405bf0d2021-11-05 17:58:334276bool NavigationControllerImpl::ShouldMaintainTrivialSessionHistory(
4277 const FrameTreeNode* frame_tree_node) const {
4278 // TODO(https://crbug.com/1197384): We may have to add portals in addition to
4279 // prerender and fenced frames. This should be kept in sync with
Hayato Ito7a80db42021-07-05 06:18:544280 // LocalFrame version, LocalFrame::ShouldMaintainTrivialSessionHistory.
shivanigithubf405bf0d2021-11-05 17:58:334281 return frame_tree_.is_prerendering() ||
4282 frame_tree_node->IsInFencedFrameTree();
Hayato Ito7a80db42021-07-05 06:18:544283}
4284
[email protected]8ff00d72012-10-23 19:12:214285} // namespace content