blob: 3a1a849f220911f7ae5214c802c2dcfd6953954d [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"
[email protected]348fbaac2013-06-11 06:31:5146#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:0047#include "base/strings/utf_string_conversions.h"
[email protected]a43858f2013-06-28 15:18:3748#include "base/time/time.h"
Carlos Caballero40b0efd2021-01-26 11:55:0049#include "base/trace_event/optional_trace_event.h"
Carlos Caballeroede6f8c2021-01-28 11:01:5050#include "base/trace_event/trace_conversion_helper.h"
ssid3e765612015-01-28 04:03:4251#include "base/trace_event/trace_event.h"
servolkf3955532015-05-16 00:01:5952#include "build/build_config.h"
[email protected]eabfe1912014-05-12 10:07:2853#include "cc/base/switches.h"
jamescookda2505812015-03-20 18:01:1854#include "content/browser/bad_message.h"
Marijn Kruisselbrink0c87e6e2018-06-22 22:57:3955#include "content/browser/blob_storage/chrome_blob_storage_context.h"
[email protected]825b1662012-03-12 19:07:3156#include "content/browser/browser_url_handler_impl.h"
[email protected]5f2aa722013-08-07 16:59:4157#include "content/browser/dom_storage/dom_storage_context_wrapper.h"
[email protected]1ea3c792012-04-17 01:25:0458#include "content/browser/dom_storage/session_storage_namespace_impl.h"
danakjc492bf82020-09-09 20:02:4459#include "content/browser/renderer_host/debug_urls.h"
60#include "content/browser/renderer_host/frame_tree.h"
Carlos Caballero40b0efd2021-01-26 11:55:0061#include "content/browser/renderer_host/frame_tree_node.h"
danakjc492bf82020-09-09 20:02:4462#include "content/browser/renderer_host/navigation_entry_impl.h"
63#include "content/browser/renderer_host/navigation_request.h"
64#include "content/browser/renderer_host/navigator.h"
65#include "content/browser/renderer_host/render_frame_host_delegate.h"
Carlos Caballero40b0efd2021-01-26 11:55:0066#include "content/browser/renderer_host/render_view_host_impl.h"
[email protected]b6583592012-01-25 19:52:3367#include "content/browser/site_instance_impl.h"
Tsuyoshi Horo37493af2019-11-21 23:43:1468#include "content/browser/web_package/web_bundle_navigation_info.h"
Camille Lamy5193caa2018-10-12 11:59:4269#include "content/common/content_constants_internal.h"
[email protected]37567b432014-02-12 01:12:2270#include "content/common/frame_messages.h"
Nasko Oskovae49e292020-08-13 02:08:5171#include "content/common/trace_utils.h"
[email protected]ccb797302011-12-15 16:55:1172#include "content/public/browser/browser_context.h"
[email protected]d1198fd2012-08-13 22:50:1973#include "content/public/browser/content_browser_client.h"
[email protected]d9083482012-01-06 00:38:4674#include "content/public/browser/invalidate_type.h"
[email protected]5b96836f2011-12-22 07:39:0075#include "content/public/browser/navigation_details.h"
[email protected]7f6f44c2011-12-14 13:23:3876#include "content/public/browser/notification_service.h"
[email protected]0d6e9bd2011-10-18 04:29:1677#include "content/public/browser/notification_types.h"
Lei Zhang96031532019-10-10 19:05:4778#include "content/public/browser/render_view_host.h"
[email protected]9677a3c2012-12-22 04:18:5879#include "content/public/browser/render_widget_host.h"
80#include "content/public/browser/render_widget_host_view.h"
Mikel Astizba9cf2fd2017-12-17 10:38:1081#include "content/public/browser/replaced_navigation_entry_data.h"
[email protected]4c3a23582012-08-18 08:54:3482#include "content/public/browser/storage_partition.h"
[email protected]d1198fd2012-08-13 22:50:1983#include "content/public/common/content_client.h"
[email protected]7f6f44c2011-12-14 13:23:3884#include "content/public/common/content_constants.h"
toyoshim86e34ec2016-02-25 08:56:1085#include "content/public/common/content_features.h"
Lei Zhang96031532019-10-10 19:05:4786#include "content/public/common/url_constants.h"
clamy7fced7b2017-11-16 19:52:4387#include "content/public/common/url_utils.h"
servolkf3955532015-05-16 00:01:5988#include "media/base/mime_util.h"
[email protected]a23de8572009-06-03 02:16:3289#include "net/base/escape.h"
Arthur Sonzogni620cec62018-12-13 13:08:5790#include "net/http/http_status_code.h"
Shivani Sharma93329102019-01-24 19:44:1891#include "services/metrics/public/cpp/ukm_builders.h"
92#include "services/metrics/public/cpp/ukm_recorder.h"
Yue Ru Sun128804932020-09-30 22:19:1793#include "services/metrics/public/cpp/ukm_source_id.h"
[email protected]9677a3c2012-12-22 04:18:5894#include "skia/ext/platform_canvas.h"
Marijn Kruisselbrink0c87e6e2018-06-22 22:57:3995#include "third_party/blink/public/common/blob/blob_utils.h"
Blink Reformata30d4232018-04-07 15:31:0696#include "third_party/blink/public/common/mime_util/mime_util.h"
Carlos Caballeroede6f8c2021-01-28 11:01:5097#include "third_party/blink/public/common/page_state/page_state_serialization.h"
[email protected]cca6f392014-05-28 21:32:2698#include "url/url_constants.h"
initial.commit09911bf2008-07-26 23:55:2999
[email protected]8ff00d72012-10-23 19:12:21100namespace content {
[email protected]e9ba4472008-09-14 15:42:43101namespace {
102
103// Invoked when entries have been pruned, or removed. For example, if the
104// current entries are [google, digg, yahoo], with the current entry google,
105// and the user types in cnet, then digg and yahoo are pruned.
[email protected]d202a7c2012-01-04 07:53:47106void NotifyPrunedEntries(NavigationControllerImpl* nav_controller,
Shivani Sharmab9c46de82019-02-08 16:54:50107 int index,
[email protected]c12bf1a12008-09-17 16:28:49108 int count) {
[email protected]8ff00d72012-10-23 19:12:21109 PrunedDetails details;
Shivani Sharmab9c46de82019-02-08 16:54:50110 details.index = index;
[email protected]c12bf1a12008-09-17 16:28:49111 details.count = count;
Sam McNally5c087a32017-08-25 01:46:14112 nav_controller->delegate()->NotifyNavigationListPruned(details);
[email protected]e9ba4472008-09-14 15:42:43113}
114
[email protected]e9ba4472008-09-14 15:42:43115// Configure all the NavigationEntries in entries for restore. This resets
116// the transition type to reload and makes sure the content state isn't empty.
117void ConfigureEntriesForRestore(
dcheng9bfa5162016-04-09 01:00:57118 std::vector<std::unique_ptr<NavigationEntryImpl>>* entries,
toyoshim0df1d3a2016-09-09 09:52:48119 RestoreType type) {
Lei Zhang96031532019-10-10 19:05:47120 for (auto& entry : *entries) {
[email protected]e9ba4472008-09-14 15:42:43121 // Use a transition type of reload so that we don't incorrectly increase
122 // the typed count.
Lei Zhang96031532019-10-10 19:05:47123 entry->SetTransitionType(ui::PAGE_TRANSITION_RELOAD);
124 entry->set_restore_type(type);
[email protected]e9ba4472008-09-14 15:42:43125 }
126}
127
[email protected]bf70edce2012-06-20 22:32:22128// Determines whether or not we should be carrying over a user agent override
129// between two NavigationEntries.
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57130bool ShouldKeepOverride(NavigationEntry* last_entry) {
[email protected]bf70edce2012-06-20 22:32:22131 return last_entry && last_entry->GetIsOverridingUserAgent();
132}
133
Camille Lamy5193caa2018-10-12 11:59:42134// Determines whether to override user agent for a navigation.
135bool ShouldOverrideUserAgent(
136 NavigationController::UserAgentOverrideOption override_user_agent,
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57137 NavigationEntry* last_committed_entry) {
Camille Lamy5193caa2018-10-12 11:59:42138 switch (override_user_agent) {
139 case NavigationController::UA_OVERRIDE_INHERIT:
140 return ShouldKeepOverride(last_committed_entry);
141 case NavigationController::UA_OVERRIDE_TRUE:
142 return true;
143 case NavigationController::UA_OVERRIDE_FALSE:
144 return false;
Camille Lamy5193caa2018-10-12 11:59:42145 }
146 NOTREACHED();
147 return false;
148}
149
clamy0a656e42018-02-06 18:18:28150// Returns true this navigation should be treated as a reload. For e.g.
151// navigating to the last committed url via the address bar or clicking on a
152// link which results in a navigation to the last committed or pending
153// navigation, etc.
Fergal Daly766177d2020-07-07 07:54:04154// |node| is the FrameTreeNode which is navigating. |url|, |virtual_url|,
155// |base_url_for_data_url|, |transition_type| correspond to the new navigation
156// (i.e. the pending NavigationEntry). |last_committed_entry| is the last
157// navigation that committed.
158bool ShouldTreatNavigationAsReload(FrameTreeNode* node,
159 const GURL& url,
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57160 const GURL& virtual_url,
161 const GURL& base_url_for_data_url,
162 ui::PageTransition transition_type,
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57163 bool is_post,
164 bool is_reload,
165 bool is_navigation_to_existing_entry,
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57166 NavigationEntryImpl* last_committed_entry) {
Fergal Daly766177d2020-07-07 07:54:04167 if (is_reload || is_navigation_to_existing_entry)
clamy0a656e42018-02-06 18:18:28168 return false;
clamy0a656e42018-02-06 18:18:28169 // Only convert to reload if at least one navigation committed.
170 if (!last_committed_entry)
ananta3bdd8ae2016-12-22 17:11:55171 return false;
172
arthursonzogni7a8243682017-12-14 16:41:42173 // Skip navigations initiated by external applications.
clamy0a656e42018-02-06 18:18:28174 if (transition_type & ui::PAGE_TRANSITION_FROM_API)
arthursonzogni7a8243682017-12-14 16:41:42175 return false;
176
ananta3bdd8ae2016-12-22 17:11:55177 // We treat (PAGE_TRANSITION_RELOAD | PAGE_TRANSITION_FROM_ADDRESS_BAR),
178 // PAGE_TRANSITION_TYPED or PAGE_TRANSITION_LINK transitions as navigations
179 // which should be treated as reloads.
clamy0a656e42018-02-06 18:18:28180 bool transition_type_can_be_converted = false;
181 if (ui::PageTransitionCoreTypeIs(transition_type,
182 ui::PAGE_TRANSITION_RELOAD) &&
183 (transition_type & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR)) {
184 transition_type_can_be_converted = true;
ananta3bdd8ae2016-12-22 17:11:55185 }
clamy0a656e42018-02-06 18:18:28186 if (ui::PageTransitionCoreTypeIs(transition_type,
ananta3bdd8ae2016-12-22 17:11:55187 ui::PAGE_TRANSITION_TYPED)) {
clamy0a656e42018-02-06 18:18:28188 transition_type_can_be_converted = true;
189 }
190 if (ui::PageTransitionCoreTypeIs(transition_type, ui::PAGE_TRANSITION_LINK))
191 transition_type_can_be_converted = true;
192 if (!transition_type_can_be_converted)
193 return false;
194
195 // This check is required for cases like view-source:, etc. Here the URL of
196 // the navigation entry would contain the url of the page, while the virtual
197 // URL contains the full URL including the view-source prefix.
198 if (virtual_url != last_committed_entry->GetVirtualURL())
199 return false;
200
Fergal Daly766177d2020-07-07 07:54:04201 // Check that the URLs match.
202 FrameNavigationEntry* frame_entry = last_committed_entry->GetFrameEntry(node);
203 // If there's no frame entry then by definition the URLs don't match.
204 if (!frame_entry)
205 return false;
206
207 if (url != frame_entry->url())
clamy0a656e42018-02-06 18:18:28208 return false;
209
210 // This check is required for Android WebView loadDataWithBaseURL. Apps
211 // can pass in anything in the base URL and we need to ensure that these
212 // match before classifying it as a reload.
213 if (url.SchemeIs(url::kDataScheme) && base_url_for_data_url.is_valid()) {
214 if (base_url_for_data_url != last_committed_entry->GetBaseURLForDataURL())
215 return false;
ananta3bdd8ae2016-12-22 17:11:55216 }
217
clamy0a656e42018-02-06 18:18:28218 // Skip entries with SSL errors.
219 if (last_committed_entry->ssl_error())
220 return false;
221
222 // Don't convert to a reload when the last navigation was a POST or the new
223 // navigation is a POST.
Fergal Daly766177d2020-07-07 07:54:04224 if (frame_entry->get_has_post_data() || is_post)
clamy0a656e42018-02-06 18:18:28225 return false;
226
227 return true;
ananta3bdd8ae2016-12-22 17:11:55228}
229
Nasko Oskov03912102019-01-11 00:21:32230bool DoesURLMatchOriginForNavigation(
231 const GURL& url,
232 const base::Optional<url::Origin>& origin) {
233 // If there is no origin supplied there is nothing to match. This can happen
234 // for navigations to a pending entry and therefore it should be allowed.
235 if (!origin)
236 return true;
237
238 return origin->CanBeDerivedFrom(url);
239}
240
241base::Optional<url::Origin> GetCommittedOriginForFrameEntry(
arthursonzogni73fe3212020-11-17 13:24:07242 const mojom::DidCommitProvisionalLoadParams& params) {
Nasko Oskov03912102019-01-11 00:21:32243 // Error pages commit in an opaque origin, yet have the real URL that resulted
244 // in an error as the |params.url|. Since successful reload of an error page
245 // should commit in the correct origin, setting the opaque origin on the
246 // FrameNavigationEntry will be incorrect.
247 if (params.url_is_unreachable)
248 return base::nullopt;
249
250 return base::make_optional(params.origin);
251}
252
Camille Lamy5193caa2018-10-12 11:59:42253bool IsValidURLForNavigation(bool is_main_frame,
254 const GURL& virtual_url,
255 const GURL& dest_url) {
256 // Don't attempt to navigate if the virtual URL is non-empty and invalid.
257 if (is_main_frame && !virtual_url.is_valid() && !virtual_url.is_empty()) {
258 LOG(WARNING) << "Refusing to load for invalid virtual URL: "
259 << virtual_url.possibly_invalid_spec();
260 return false;
261 }
262
263 // Don't attempt to navigate to non-empty invalid URLs.
264 if (!dest_url.is_valid() && !dest_url.is_empty()) {
265 LOG(WARNING) << "Refusing to load invalid URL: "
266 << dest_url.possibly_invalid_spec();
267 return false;
268 }
269
270 // The renderer will reject IPC messages with URLs longer than
271 // this limit, so don't attempt to navigate with a longer URL.
272 if (dest_url.spec().size() > url::kMaxURLChars) {
273 LOG(WARNING) << "Refusing to load URL as it exceeds " << url::kMaxURLChars
274 << " characters.";
275 return false;
276 }
277
Aaron Colwell33109c592020-04-21 21:31:19278 // Reject renderer debug URLs because they should have been handled before
279 // we get to this point. This check handles renderer debug URLs
280 // that are inside a view-source: URL (e.g. view-source:chrome://kill) and
281 // provides defense-in-depth if a renderer debug URL manages to get here via
282 // some other path. We want to reject the navigation here so it doesn't
283 // violate assumptions in downstream code.
284 if (IsRendererDebugURL(dest_url)) {
285 LOG(WARNING) << "Refusing to load renderer debug URL: "
286 << dest_url.possibly_invalid_spec();
287 return false;
288 }
289
Camille Lamy5193caa2018-10-12 11:59:42290 return true;
291}
292
Mikel Astizba9cf2fd2017-12-17 10:38:10293// See replaced_navigation_entry_data.h for details: this information is meant
294// to ensure |*output_entry| keeps track of its original URL (landing page in
295// case of server redirects) as it gets replaced (e.g. history.replaceState()),
296// without overwriting it later, for main frames.
297void CopyReplacedNavigationEntryDataIfPreviouslyEmpty(
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57298 NavigationEntryImpl* replaced_entry,
Mikel Astizba9cf2fd2017-12-17 10:38:10299 NavigationEntryImpl* output_entry) {
300 if (output_entry->GetReplacedEntryData().has_value())
301 return;
302
303 ReplacedNavigationEntryData data;
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57304 data.first_committed_url = replaced_entry->GetURL();
305 data.first_timestamp = replaced_entry->GetTimestamp();
306 data.first_transition_type = replaced_entry->GetTransitionType();
Charlie Reisb55438f2019-01-08 01:54:29307 output_entry->set_replaced_entry_data(data);
Mikel Astizba9cf2fd2017-12-17 10:38:10308}
309
Lucas Furukawa Gadanief8290a2019-07-29 20:27:51310mojom::NavigationType GetNavigationType(const GURL& old_url,
311 const GURL& new_url,
312 ReloadType reload_type,
313 NavigationEntryImpl* entry,
314 const FrameNavigationEntry& frame_entry,
danakjd83d706d2020-11-25 22:11:12315 bool has_pending_cross_document_commit,
danakjb952ef12021-01-14 19:58:49316 bool is_currently_error_page,
Lucas Furukawa Gadanief8290a2019-07-29 20:27:51317 bool is_same_document_history_load) {
clamyea99ea12018-05-28 13:54:23318 // Reload navigations
319 switch (reload_type) {
320 case ReloadType::NORMAL:
Lucas Furukawa Gadanief8290a2019-07-29 20:27:51321 return mojom::NavigationType::RELOAD;
clamyea99ea12018-05-28 13:54:23322 case ReloadType::BYPASSING_CACHE:
Lucas Furukawa Gadanief8290a2019-07-29 20:27:51323 return mojom::NavigationType::RELOAD_BYPASSING_CACHE;
clamyea99ea12018-05-28 13:54:23324 case ReloadType::ORIGINAL_REQUEST_URL:
Lucas Furukawa Gadanief8290a2019-07-29 20:27:51325 return mojom::NavigationType::RELOAD_ORIGINAL_REQUEST_URL;
clamyea99ea12018-05-28 13:54:23326 case ReloadType::NONE:
327 break; // Fall through to rest of function.
328 }
329
Lukasz Anforowicz6b75c0d2020-12-01 22:56:08330 if (entry->IsRestored()) {
Lei Zhang96031532019-10-10 19:05:47331 return entry->GetHasPostData() ? mojom::NavigationType::RESTORE_WITH_POST
332 : mojom::NavigationType::RESTORE;
clamyea99ea12018-05-28 13:54:23333 }
334
danakjb952ef12021-01-14 19:58:49335 const bool can_be_same_document =
336 // A pending cross-document commit means this navigation will not occur in
337 // the current document, as that document would end up being replaced in
338 // the meantime.
339 !has_pending_cross_document_commit &&
340 // If the current document is an error page, we should always treat it as
341 // a different-document navigation so that we'll attempt to load the
342 // document we're navigating to (and not stay in the current error page).
343 !is_currently_error_page;
danakjd83d706d2020-11-25 22:11:12344
clamyea99ea12018-05-28 13:54:23345 // History navigations.
346 if (frame_entry.page_state().IsValid()) {
danakjd83d706d2020-11-25 22:11:12347 return can_be_same_document && is_same_document_history_load
Lei Zhang96031532019-10-10 19:05:47348 ? mojom::NavigationType::HISTORY_SAME_DOCUMENT
349 : mojom::NavigationType::HISTORY_DIFFERENT_DOCUMENT;
clamyea99ea12018-05-28 13:54:23350 }
351 DCHECK(!is_same_document_history_load);
352
353 // A same-document fragment-navigation happens when the only part of the url
354 // that is modified is after the '#' character.
355 //
356 // When modifying this condition, please take a look at:
danakjd83d706d2020-11-25 22:11:12357 // FrameLoader::ShouldPerformFragmentNavigation().
clamyea99ea12018-05-28 13:54:23358 //
359 // Note: this check is only valid for navigations that are not history
360 // navigations. For instance, if the history is: 'A#bar' -> 'B' -> 'A#foo', a
361 // history navigation from 'A#foo' to 'A#bar' is not a same-document
362 // navigation, but a different-document one. This is why history navigation
363 // are classified before this check.
Lei Zhang96031532019-10-10 19:05:47364 bool is_same_doc = new_url.has_ref() && old_url.EqualsIgnoringRef(new_url) &&
365 frame_entry.method() == "GET";
danakjd83d706d2020-11-25 22:11:12366
367 // The one case where we do the wrong thing here and incorrectly choose
368 // SAME_DOCUMENT is if the navigation is browser-initiated but the document in
369 // the renderer is a frameset. All frameset navigations should be
370 // DIFFERENT_DOCUMENT, even if their URLs match. A renderer-initiated
371 // navigation would do the right thing, as it would send it to the browser and
372 // all renderer-initiated navigations are DIFFERENT_DOCUMENT (they don't get
373 // into this method). But since we can't tell that case here for browser-
374 // initiated navigations, we have to get the renderer involved. In that case
375 // the navigation would be restarted due to the renderer spending a reply of
376 // mojom::CommitResult::RestartCrossDocument.
377
378 return can_be_same_document && is_same_doc
379 ? mojom::NavigationType::SAME_DOCUMENT
380 : mojom::NavigationType::DIFFERENT_DOCUMENT;
clamyea99ea12018-05-28 13:54:23381}
382
Camille Lamy5193caa2018-10-12 11:59:42383// Adjusts the original input URL if needed, to get the URL to actually load and
384// the virtual URL, which may differ.
385void RewriteUrlForNavigation(const GURL& original_url,
386 BrowserContext* browser_context,
387 GURL* url_to_load,
388 GURL* virtual_url,
389 bool* reverse_on_redirect) {
Camille Lamy5193caa2018-10-12 11:59:42390 // Allow the browser URL handler to rewrite the URL. This will, for example,
391 // remove "view-source:" from the beginning of the URL to get the URL that
392 // will actually be loaded. This real URL won't be shown to the user, just
393 // used internally.
Lukasz Anforowicz7b078792020-10-20 17:04:31394 *url_to_load = *virtual_url = original_url;
Camille Lamy5193caa2018-10-12 11:59:42395 BrowserURLHandlerImpl::GetInstance()->RewriteURLIfNecessary(
396 url_to_load, browser_context, reverse_on_redirect);
397}
398
399#if DCHECK_IS_ON()
400// Helper sanity check function used in debug mode.
401void ValidateRequestMatchesEntry(NavigationRequest* request,
402 NavigationEntryImpl* entry) {
403 if (request->frame_tree_node()->IsMainFrame()) {
404 DCHECK_EQ(request->browser_initiated(), !entry->is_renderer_initiated());
405 DCHECK(ui::PageTransitionTypeIncludingQualifiersIs(
406 request->common_params().transition, entry->GetTransitionType()));
407 }
408 DCHECK_EQ(request->common_params().should_replace_current_entry,
409 entry->should_replace_entry());
Nasko Oskovc36327d2019-01-03 23:23:04410 DCHECK_EQ(request->commit_params().should_clear_history_list,
Camille Lamy5193caa2018-10-12 11:59:42411 entry->should_clear_history_list());
412 DCHECK_EQ(request->common_params().has_user_gesture,
413 entry->has_user_gesture());
414 DCHECK_EQ(request->common_params().base_url_for_data_url,
415 entry->GetBaseURLForDataURL());
Nasko Oskovc36327d2019-01-03 23:23:04416 DCHECK_EQ(request->commit_params().can_load_local_resources,
Camille Lamy5193caa2018-10-12 11:59:42417 entry->GetCanLoadLocalResources());
418 DCHECK_EQ(request->common_params().started_from_context_menu,
419 entry->has_started_from_context_menu());
420
421 FrameNavigationEntry* frame_entry =
422 entry->GetFrameEntry(request->frame_tree_node());
423 if (!frame_entry) {
424 NOTREACHED();
425 return;
426 }
427
Camille Lamy5193caa2018-10-12 11:59:42428 DCHECK_EQ(request->common_params().method, frame_entry->method());
429
Nasko Oskovc36327d2019-01-03 23:23:04430 size_t redirect_size = request->commit_params().redirects.size();
Camille Lamy5193caa2018-10-12 11:59:42431 if (redirect_size == frame_entry->redirect_chain().size()) {
432 for (size_t i = 0; i < redirect_size; ++i) {
Nasko Oskovc36327d2019-01-03 23:23:04433 DCHECK_EQ(request->commit_params().redirects[i],
Camille Lamy5193caa2018-10-12 11:59:42434 frame_entry->redirect_chain()[i]);
435 }
436 } else {
437 NOTREACHED();
438 }
439}
440#endif // DCHECK_IS_ON()
441
Dave Tapuska8bfd84c2019-03-26 20:47:16442// Returns whether the session history NavigationRequests in |navigations|
443// would stay within the subtree of the sandboxed iframe in
444// |sandbox_frame_tree_node_id|.
445bool DoesSandboxNavigationStayWithinSubtree(
446 int sandbox_frame_tree_node_id,
447 const std::vector<std::unique_ptr<NavigationRequest>>& navigations) {
448 for (auto& item : navigations) {
449 bool within_subtree = false;
450 // Check whether this NavigationRequest affects a frame within the
451 // sandboxed frame's subtree by walking up the tree looking for the
452 // sandboxed frame.
453 for (auto* frame = item->frame_tree_node(); frame;
Alexander Timin381e7e182020-04-28 19:04:03454 frame = FrameTreeNode::From(frame->parent())) {
Dave Tapuska8bfd84c2019-03-26 20:47:16455 if (frame->frame_tree_node_id() == sandbox_frame_tree_node_id) {
456 within_subtree = true;
457 break;
458 }
459 }
460 if (!within_subtree)
461 return false;
462 }
463 return true;
464}
465
Titouan Rigoudy6ec70402021-02-02 15:42:19466bool ShouldStorePolicyContainerPoliciesInFrameNavigationEntry(
Antonio Sartori78a749f2020-11-30 12:03:39467 const NavigationRequest* request) {
468 // For local schemes we need to store the policy container in the
469 // FrameNavigationEntry, so that we can reload it in case of history
470 // navigation.
471 //
472 // TODO(https://crbug.com/1146361 and https://crbug.com/1146362): blob: and
473 // filesystem: should be removed from this list when we have properly
474 // implemented storing their policy container in the respective store.
475 return (request->common_params().url.SchemeIs(url::kAboutScheme) ||
476 request->common_params().url.SchemeIs(url::kDataScheme) ||
477 request->common_params().url.SchemeIsBlob() ||
478 request->common_params().url.SchemeIsFileSystem());
479}
480
[email protected]e9ba4472008-09-14 15:42:43481} // namespace
482
arthursonzogni66f711c2019-10-08 14:40:36483// NavigationControllerImpl::PendingEntryRef------------------------------------
484
485NavigationControllerImpl::PendingEntryRef::PendingEntryRef(
486 base::WeakPtr<NavigationControllerImpl> controller)
487 : controller_(controller) {}
488
489NavigationControllerImpl::PendingEntryRef::~PendingEntryRef() {
490 if (!controller_) // Can be null with interstitials.
491 return;
492
493 controller_->PendingEntryRefDeleted(this);
494}
495
[email protected]d202a7c2012-01-04 07:53:47496// NavigationControllerImpl ----------------------------------------------------
initial.commit09911bf2008-07-26 23:55:29497
[email protected]23a918b2014-07-15 09:51:36498const size_t kMaxEntryCountForTestingNotSet = static_cast<size_t>(-1);
[email protected]9b51970d2011-12-09 23:10:23499
[email protected]765b35502008-08-21 00:51:20500// static
[email protected]d202a7c2012-01-04 07:53:47501size_t NavigationControllerImpl::max_entry_count_for_testing_ =
[email protected]9b51970d2011-12-09 23:10:23502 kMaxEntryCountForTestingNotSet;
[email protected]765b35502008-08-21 00:51:20503
[email protected]e6fec472013-05-14 05:29:02504// Should Reload check for post data? The default is true, but is set to false
[email protected]cdcb1dee2012-01-04 00:46:20505// when testing.
506static bool g_check_for_repost = true;
initial.commit09911bf2008-07-26 23:55:29507
[email protected]71fde352011-12-29 03:29:56508// static
dcheng9bfa5162016-04-09 01:00:57509std::unique_ptr<NavigationEntry> NavigationController::CreateNavigationEntry(
510 const GURL& url,
Lukasz Anforowicz641234d52019-11-07 21:07:10511 Referrer referrer,
512 base::Optional<url::Origin> initiator_origin,
513 ui::PageTransition transition,
514 bool is_renderer_initiated,
515 const std::string& extra_headers,
516 BrowserContext* browser_context,
517 scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory) {
518 return NavigationControllerImpl::CreateNavigationEntry(
519 url, referrer, std::move(initiator_origin),
520 nullptr /* source_site_instance */, transition, is_renderer_initiated,
Rakina Zata Amni66992a82020-06-24 03:57:52521 extra_headers, browser_context, std::move(blob_url_loader_factory),
Scott Violet5ae6c42e2020-10-28 02:47:37522 false /* should_replace_entry */, nullptr /* web_contents */);
Lukasz Anforowicz641234d52019-11-07 21:07:10523}
524
525// static
526std::unique_ptr<NavigationEntryImpl>
527NavigationControllerImpl::CreateNavigationEntry(
528 const GURL& url,
529 Referrer referrer,
530 base::Optional<url::Origin> initiator_origin,
531 SiteInstance* source_site_instance,
dcheng9bfa5162016-04-09 01:00:57532 ui::PageTransition transition,
533 bool is_renderer_initiated,
534 const std::string& extra_headers,
Marijn Kruisselbrink7a0d5e182018-05-24 22:55:09535 BrowserContext* browser_context,
Rakina Zata Amni66992a82020-06-24 03:57:52536 scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory,
Scott Violet5ae6c42e2020-10-28 02:47:37537 bool should_replace_entry,
538 WebContents* web_contents) {
Camille Lamy5193caa2018-10-12 11:59:42539 GURL url_to_load;
540 GURL virtual_url;
[email protected]71fde352011-12-29 03:29:56541 bool reverse_on_redirect = false;
Camille Lamy5193caa2018-10-12 11:59:42542 RewriteUrlForNavigation(url, browser_context, &url_to_load, &virtual_url,
543 &reverse_on_redirect);
[email protected]71fde352011-12-29 03:29:56544
Lukasz Anforowicz641234d52019-11-07 21:07:10545 // Let the NTP override the navigation params and pretend that this is a
546 // browser-initiated, bookmark-like navigation.
547 GetContentClient()->browser()->OverrideNavigationParams(
Scott Violet5ae6c42e2020-10-28 02:47:37548 web_contents, source_site_instance, &transition, &is_renderer_initiated,
549 &referrer, &initiator_origin);
Lukasz Anforowicz641234d52019-11-07 21:07:10550
Patrick Monettef507e982019-06-19 20:18:06551 auto entry = std::make_unique<NavigationEntryImpl>(
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28552 nullptr, // The site instance for tabs is sent on navigation
553 // (WebContents::GetSiteInstance).
Lukasz Anforowicz435bcb582019-07-12 20:50:06554 url_to_load, referrer, initiator_origin, base::string16(), transition,
Camille Lamy5193caa2018-10-12 11:59:42555 is_renderer_initiated, blob_url_loader_factory);
556 entry->SetVirtualURL(virtual_url);
557 entry->set_user_typed_url(virtual_url);
[email protected]71fde352011-12-29 03:29:56558 entry->set_update_virtual_url_with_url(reverse_on_redirect);
559 entry->set_extra_headers(extra_headers);
Rakina Zata Amni66992a82020-06-24 03:57:52560 entry->set_should_replace_entry(should_replace_entry);
Patrick Monettef507e982019-06-19 20:18:06561 return entry;
[email protected]71fde352011-12-29 03:29:56562}
563
[email protected]cdcb1dee2012-01-04 00:46:20564// static
565void NavigationController::DisablePromptOnRepost() {
566 g_check_for_repost = false;
567}
568
[email protected]c5b88d82012-10-06 17:03:33569base::Time NavigationControllerImpl::TimeSmoother::GetSmoothedTime(
570 base::Time t) {
571 // If |t| is between the water marks, we're in a run of duplicates
572 // or just getting out of it, so increase the high-water mark to get
573 // a time that probably hasn't been used before and return it.
574 if (low_water_mark_ <= t && t <= high_water_mark_) {
575 high_water_mark_ += base::TimeDelta::FromMicroseconds(1);
576 return high_water_mark_;
577 }
578
579 // Otherwise, we're clear of the last duplicate run, so reset the
580 // water marks.
581 low_water_mark_ = high_water_mark_ = t;
582 return t;
583}
584
ckitagawa0faa5e42020-06-17 17:30:54585NavigationControllerImpl::ScopedShowRepostDialogForTesting::
586 ScopedShowRepostDialogForTesting()
587 : was_disallowed_(g_check_for_repost) {
588 g_check_for_repost = true;
589}
590
591NavigationControllerImpl::ScopedShowRepostDialogForTesting::
592 ~ScopedShowRepostDialogForTesting() {
593 g_check_for_repost = was_disallowed_;
594}
595
[email protected]d202a7c2012-01-04 07:53:47596NavigationControllerImpl::NavigationControllerImpl(
Carlos Caballero40b0efd2021-01-26 11:55:00597 BrowserContext* browser_context,
598 FrameTree& frame_tree,
599 NavigationControllerDelegate* delegate)
600 : frame_tree_(frame_tree),
601 browser_context_(browser_context),
[email protected]ec6c05f2013-10-23 18:41:57602 delegate_(delegate),
[email protected]69e797f2013-04-30 01:10:22603 ssl_manager_(this),
Lei Zhang96031532019-10-10 19:05:47604 get_timestamp_callback_(base::BindRepeating(&base::Time::Now)) {
[email protected]3d7474ff2011-07-27 17:47:37605 DCHECK(browser_context_);
initial.commit09911bf2008-07-26 23:55:29606}
607
[email protected]d202a7c2012-01-04 07:53:47608NavigationControllerImpl::~NavigationControllerImpl() {
arthursonzogni69a6a1b2019-09-17 09:23:00609 // The NavigationControllerImpl might be called inside its delegate
610 // destructor. Calling it is not valid anymore.
611 delegate_ = nullptr;
612 DiscardNonCommittedEntries();
initial.commit09911bf2008-07-26 23:55:29613}
614
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57615WebContents* NavigationControllerImpl::GetWebContents() {
[email protected]ec6c05f2013-10-23 18:41:57616 return delegate_->GetWebContents();
[email protected]fbc5e5f92012-01-02 06:08:32617}
618
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57619BrowserContext* NavigationControllerImpl::GetBrowserContext() {
[email protected]a26023822011-12-29 00:23:55620 return browser_context_;
621}
622
[email protected]d202a7c2012-01-04 07:53:47623void NavigationControllerImpl::Restore(
[email protected]5e369672009-11-03 23:48:30624 int selected_navigation,
[email protected]2ca1ea662012-10-04 02:26:36625 RestoreType type,
dcheng9bfa5162016-04-09 01:00:57626 std::vector<std::unique_ptr<NavigationEntry>>* entries) {
[email protected]ce3fa3c2009-04-20 19:55:57627 // Verify that this controller is unused and that the input is valid.
Lei Zhang96031532019-10-10 19:05:47628 DCHECK_EQ(0, GetEntryCount());
629 DCHECK(!GetPendingEntry());
[email protected]ce3fa3c2009-04-20 19:55:57630 DCHECK(selected_navigation >= 0 &&
[email protected]03838e22011-06-06 15:27:14631 selected_navigation < static_cast<int>(entries->size()));
arthursonzogni5c4c202d2017-04-25 23:41:27632 DCHECK_EQ(-1, pending_entry_index_);
[email protected]ce3fa3c2009-04-20 19:55:57633
[email protected]ce3fa3c2009-04-20 19:55:57634 needs_reload_ = true;
Bo Liucdfa4b12018-11-06 00:21:44635 needs_reload_type_ = NeedsReloadType::kRestoreSession;
avif16f85a72015-11-13 18:25:03636 entries_.reserve(entries->size());
637 for (auto& entry : *entries)
dcheng36b6aec92015-12-26 06:16:36638 entries_.push_back(
639 NavigationEntryImpl::FromNavigationEntry(std::move(entry)));
avif16f85a72015-11-13 18:25:03640
641 // At this point, the |entries| is full of empty scoped_ptrs, so it can be
642 // cleared out safely.
643 entries->clear();
[email protected]ce3fa3c2009-04-20 19:55:57644
645 // And finish the restore.
[email protected]2ca1ea662012-10-04 02:26:36646 FinishRestore(selected_navigation, type);
[email protected]ce3fa3c2009-04-20 19:55:57647}
648
toyoshim6142d96f2016-12-19 09:07:25649void NavigationControllerImpl::Reload(ReloadType reload_type,
650 bool check_for_repost) {
liaoyuke9168fba2017-03-10 19:20:28651 DCHECK_NE(ReloadType::NONE, reload_type);
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28652 NavigationEntryImpl* entry = nullptr;
[email protected]59167c22013-06-03 18:07:32653 int current_index = -1;
654
Carlos IL42b416592019-10-07 23:10:36655 if (entry_replaced_by_post_commit_error_) {
656 // If there is an entry that was replaced by a currently active post-commit
657 // error navigation, this can't be the initial navigation.
658 DCHECK(!IsInitialNavigation());
659 // If the current entry is a post commit error, we reload the entry it
660 // replaced instead. We leave the error entry in place until a commit
661 // replaces it, but the pending entry points to the original entry in the
662 // meantime. Note that NavigateToExistingPendingEntry is able to handle the
663 // case that pending_entry_ != entries_[pending_entry_index_].
664 entry = entry_replaced_by_post_commit_error_.get();
665 current_index = GetCurrentEntryIndex();
666 } else if (IsInitialNavigation() && pending_entry_) {
667 // If we are reloading the initial navigation, just use the current
668 // pending entry. Otherwise look up the current entry.
[email protected]59167c22013-06-03 18:07:32669 entry = pending_entry_;
670 // The pending entry might be in entries_ (e.g., after a Clone), so we
671 // should also update the current_index.
672 current_index = pending_entry_index_;
673 } else {
arthursonzogni69a6a1b2019-09-17 09:23:00674 DiscardNonCommittedEntries();
[email protected]59167c22013-06-03 18:07:32675 current_index = GetCurrentEntryIndex();
676 if (current_index != -1) {
creis3da03872015-02-20 21:12:32677 entry = GetEntryAtIndex(current_index);
[email protected]59167c22013-06-03 18:07:32678 }
[email protected]979a4bc2013-04-24 01:27:15679 }
[email protected]241db352013-04-22 18:04:05680
[email protected]59167c22013-06-03 18:07:32681 // If we are no where, then we can't reload. TODO(darin): We should add a
682 // CanReload method.
683 if (!entry)
684 return;
685
Takashi Toyoshimac7df3c22019-06-25 14:18:47686 // Set ReloadType for |entry|.
toyoshima63c2a62016-09-29 09:03:26687 entry->set_reload_type(reload_type);
688
Aran Gilman37d11632019-10-08 23:07:15689 if (g_check_for_repost && check_for_repost && entry->GetHasPostData()) {
[email protected]a3a1d142008-12-19 00:42:30690 // The user is asking to reload a page with POST data. Prompt to make sure
[email protected]b5bb35f2009-02-05 20:17:07691 // they really want to do this. If they do, the dialog will call us back
692 // with check_for_repost = false.
[email protected]ec6c05f2013-10-23 18:41:57693 delegate_->NotifyBeforeFormRepostWarningShow();
[email protected]965bb092010-04-09 11:59:02694
[email protected]106a0812010-03-18 00:15:12695 pending_reload_ = reload_type;
[email protected]ec6c05f2013-10-23 18:41:57696 delegate_->ActivateAndShowRepostFormWarningDialog();
Lei Zhang96031532019-10-10 19:05:47697 return;
initial.commit09911bf2008-07-26 23:55:29698 }
Lei Zhang96031532019-10-10 19:05:47699
700 if (!IsInitialNavigation())
701 DiscardNonCommittedEntries();
702
703 pending_entry_ = entry;
704 pending_entry_index_ = current_index;
705 pending_entry_->SetTransitionType(ui::PAGE_TRANSITION_RELOAD);
706
707 NavigateToExistingPendingEntry(reload_type,
708 FrameTreeNode::kFrameTreeNodeInvalidId);
initial.commit09911bf2008-07-26 23:55:29709}
710
[email protected]d202a7c2012-01-04 07:53:47711void NavigationControllerImpl::CancelPendingReload() {
toyoshim0df1d3a2016-09-09 09:52:48712 DCHECK(pending_reload_ != ReloadType::NONE);
713 pending_reload_ = ReloadType::NONE;
[email protected]106a0812010-03-18 00:15:12714}
715
[email protected]d202a7c2012-01-04 07:53:47716void NavigationControllerImpl::ContinuePendingReload() {
toyoshim0df1d3a2016-09-09 09:52:48717 if (pending_reload_ == ReloadType::NONE) {
[email protected]106a0812010-03-18 00:15:12718 NOTREACHED();
719 } else {
toyoshim6142d96f2016-12-19 09:07:25720 Reload(pending_reload_, false);
toyoshim0df1d3a2016-09-09 09:52:48721 pending_reload_ = ReloadType::NONE;
[email protected]106a0812010-03-18 00:15:12722 }
723}
724
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57725bool NavigationControllerImpl::IsInitialNavigation() {
[email protected]27ba81c2012-08-21 17:04:09726 return is_initial_navigation_;
[email protected]c70f9b82010-04-21 07:31:11727}
728
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57729bool NavigationControllerImpl::IsInitialBlankNavigation() {
creis10a4ab72015-10-13 17:22:40730 // TODO(creis): Once we create a NavigationEntry for the initial blank page,
toyoshim0df1d3a2016-09-09 09:52:48731 // we'll need to check for entry count 1 and restore_type NONE (to exclude
732 // the cloned tab case).
creis10a4ab72015-10-13 17:22:40733 return IsInitialNavigation() && GetEntryCount() == 0;
734}
735
Aran Gilman37d11632019-10-08 23:07:15736NavigationEntryImpl* NavigationControllerImpl::GetEntryWithUniqueID(
737 int nav_entry_id) const {
avi254eff02015-07-01 08:27:58738 int index = GetEntryIndexWithUniqueID(nav_entry_id);
avif16f85a72015-11-13 18:25:03739 return (index != -1) ? entries_[index].get() : nullptr;
avi254eff02015-07-01 08:27:58740}
741
W. James MacLean1c40862c2020-04-27 21:05:57742void NavigationControllerImpl::RegisterExistingOriginToPreventOptInIsolation(
743 const url::Origin& origin) {
744 for (int i = 0; i < GetEntryCount(); i++) {
745 auto* entry = GetEntryAtIndex(i);
746 entry->RegisterExistingOriginToPreventOptInIsolation(origin);
747 }
748 if (entry_replaced_by_post_commit_error_) {
749 // It's possible we could come back to this entry if the error
750 // page/interstitial goes away.
751 entry_replaced_by_post_commit_error_
752 ->RegisterExistingOriginToPreventOptInIsolation(origin);
753 }
754 // TODO(wjmaclean): Register pending commit NavigationRequests rather than
755 // visiting pending_entry_, which lacks a committed origin. This will be done
756 // in https://chromium-review.googlesource.com/c/chromium/src/+/2136703.
757}
758
avi25764702015-06-23 15:43:37759void NavigationControllerImpl::SetPendingEntry(
dcheng9bfa5162016-04-09 01:00:57760 std::unique_ptr<NavigationEntryImpl> entry) {
arthursonzogni69a6a1b2019-09-17 09:23:00761 DiscardNonCommittedEntries();
avi25764702015-06-23 15:43:37762 pending_entry_ = entry.release();
arthursonzogni5c4c202d2017-04-25 23:41:27763 DCHECK_EQ(-1, pending_entry_index_);
[email protected]8ff00d72012-10-23 19:12:21764 NotificationService::current()->Notify(
Aran Gilman37d11632019-10-08 23:07:15765 NOTIFICATION_NAV_ENTRY_PENDING, Source<NavigationController>(this),
avi25764702015-06-23 15:43:37766 Details<NavigationEntry>(pending_entry_));
[email protected]765b35502008-08-21 00:51:20767}
768
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57769NavigationEntryImpl* NavigationControllerImpl::GetActiveEntry() {
[email protected]cbab76d2008-10-13 22:42:47770 if (pending_entry_)
771 return pending_entry_;
772 return GetLastCommittedEntry();
[email protected]765b35502008-08-21 00:51:20773}
774
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57775NavigationEntryImpl* NavigationControllerImpl::GetVisibleEntry() {
[email protected]59167c22013-06-03 18:07:32776 // The pending entry is safe to return for new (non-history), browser-
777 // initiated navigations. Most renderer-initiated navigations should not
778 // show the pending entry, to prevent URL spoof attacks.
779 //
780 // We make an exception for renderer-initiated navigations in new tabs, as
781 // long as no other page has tried to access the initial empty document in
782 // the new tab. If another page modifies this blank page, a URL spoof is
783 // possible, so we must stop showing the pending entry.
[email protected]59167c22013-06-03 18:07:32784 bool safe_to_show_pending =
785 pending_entry_ &&
786 // Require a new navigation.
avi0dca04d2015-01-26 20:21:09787 pending_entry_index_ == -1 &&
[email protected]59167c22013-06-03 18:07:32788 // Require either browser-initiated or an unmodified new tab.
[email protected]aa62afd2014-04-22 19:22:46789 (!pending_entry_->is_renderer_initiated() || IsUnmodifiedBlankTab());
[email protected]59167c22013-06-03 18:07:32790
791 // Also allow showing the pending entry for history navigations in a new tab,
792 // such as Ctrl+Back. In this case, no existing page is visible and no one
793 // can script the new tab before it commits.
Aran Gilman37d11632019-10-08 23:07:15794 if (!safe_to_show_pending && pending_entry_ && pending_entry_index_ != -1 &&
795 IsInitialNavigation() && !pending_entry_->is_renderer_initiated())
[email protected]59167c22013-06-03 18:07:32796 safe_to_show_pending = true;
797
798 if (safe_to_show_pending)
[email protected]867e1f92011-08-30 19:01:19799 return pending_entry_;
800 return GetLastCommittedEntry();
801}
802
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57803int NavigationControllerImpl::GetCurrentEntryIndex() {
[email protected]765b35502008-08-21 00:51:20804 if (pending_entry_index_ != -1)
805 return pending_entry_index_;
806 return last_committed_entry_index_;
807}
808
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57809NavigationEntryImpl* NavigationControllerImpl::GetLastCommittedEntry() {
[email protected]765b35502008-08-21 00:51:20810 if (last_committed_entry_index_ == -1)
Ivan Kotenkov2c0d2bb32017-11-01 15:41:28811 return nullptr;
avif16f85a72015-11-13 18:25:03812 return entries_[last_committed_entry_index_].get();
[email protected]765b35502008-08-21 00:51:20813}
814
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57815bool NavigationControllerImpl::CanViewSource() {
Carlos Caballeroede6f8c2021-01-28 11:01:50816 const std::string& mime_type = frame_tree_.root()
Alex Moshchuk2e470ea2021-02-03 06:46:34817 ->current_frame_host()
818 ->render_view_host()
Carlos Caballeroede6f8c2021-01-28 11:01:50819 ->contents_mime_type();
Kinuko Yasuda74702f92017-07-31 03:27:53820 bool is_viewable_mime_type = blink::IsSupportedNonImageMimeType(mime_type) &&
821 !media::IsSupportedMediaMimeType(mime_type);
[email protected]6286a3792013-10-09 04:03:27822 NavigationEntry* visible_entry = GetVisibleEntry();
823 return visible_entry && !visible_entry->IsViewSourceMode() &&
Carlos ILd51e7702020-05-07 18:51:39824 is_viewable_mime_type;
[email protected]31682282010-01-15 18:05:16825}
826
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57827int NavigationControllerImpl::GetLastCommittedEntryIndex() {
arthursonzogni5c4c202d2017-04-25 23:41:27828 // The last committed entry index must always be less than the number of
Carlos IL4dea8902020-05-26 15:14:29829 // entries. If there are no entries, it must be -1.
arthursonzogni5c4c202d2017-04-25 23:41:27830 DCHECK_LT(last_committed_entry_index_, GetEntryCount());
831 DCHECK(GetEntryCount() || last_committed_entry_index_ == -1);
[email protected]a26023822011-12-29 00:23:55832 return last_committed_entry_index_;
833}
834
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57835int NavigationControllerImpl::GetEntryCount() {
Carlos IL4dea8902020-05-26 15:14:29836 DCHECK_LE(entries_.size(), max_entry_count());
[email protected]a26023822011-12-29 00:23:55837 return static_cast<int>(entries_.size());
838}
839
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57840NavigationEntryImpl* NavigationControllerImpl::GetEntryAtIndex(int index) {
avi25764702015-06-23 15:43:37841 if (index < 0 || index >= GetEntryCount())
842 return nullptr;
843
avif16f85a72015-11-13 18:25:03844 return entries_[index].get();
[email protected]022af742011-12-28 18:37:25845}
846
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57847NavigationEntryImpl* NavigationControllerImpl::GetEntryAtOffset(int offset) {
avi057ce1492015-06-29 15:59:47848 return GetEntryAtIndex(GetIndexForOffset(offset));
[email protected]765b35502008-08-21 00:51:20849}
850
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57851int NavigationControllerImpl::GetIndexForOffset(int offset) {
[email protected]7bc2b032012-12-19 22:45:46852 return GetCurrentEntryIndex() + offset;
[email protected]9ba14052012-06-22 23:50:03853}
854
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57855bool NavigationControllerImpl::CanGoBack() {
Shivani Sharma298d12852019-01-22 20:04:03856 if (!base::FeatureList::IsEnabled(features::kHistoryManipulationIntervention))
857 return CanGoToOffset(-1);
858
859 for (int index = GetIndexForOffset(-1); index >= 0; index--) {
860 if (!GetEntryAtIndex(index)->should_skip_on_back_forward_ui())
861 return true;
862 }
863 return false;
[email protected]765b35502008-08-21 00:51:20864}
865
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57866bool NavigationControllerImpl::CanGoForward() {
avi56e40c92015-08-27 00:11:22867 return CanGoToOffset(1);
[email protected]765b35502008-08-21 00:51:20868}
869
Lucas Furukawa Gadani5553a1582019-01-08 18:55:57870bool NavigationControllerImpl::CanGoToOffset(int offset) {
[email protected]9ba14052012-06-22 23:50:03871 int index = GetIndexForOffset(offset);
872 return index >= 0 && index < GetEntryCount();
873}
874
[email protected]d202a7c2012-01-04 07:53:47875void NavigationControllerImpl::GoBack() {
shivanisha55201872018-12-13 04:29:06876 int target_index = GetIndexForOffset(-1);
877
878 // Log metrics for the number of entries that are eligible for skipping on
Shivani Sharma2d5b4b6b2019-01-08 16:07:16879 // back button and move the target index past the skippable entries, if
880 // history intervention is enabled.
shivanisha55201872018-12-13 04:29:06881 int count_entries_skipped = 0;
Shivani Sharma298d12852019-01-22 20:04:03882 bool all_skippable_entries = true;
Aran Gilman37d11632019-10-08 23:07:15883 bool history_intervention_enabled =
884 base::FeatureList::IsEnabled(features::kHistoryManipulationIntervention);
shivanisha55201872018-12-13 04:29:06885 for (int index = target_index; index >= 0; index--) {
Shivani Sharma2d5b4b6b2019-01-08 16:07:16886 if (GetEntryAtIndex(index)->should_skip_on_back_forward_ui()) {
shivanisha55201872018-12-13 04:29:06887 count_entries_skipped++;
Shivani Sharma2d5b4b6b2019-01-08 16:07:16888 } else {
889 if (history_intervention_enabled)
890 target_index = index;
Shivani Sharma298d12852019-01-22 20:04:03891 all_skippable_entries = false;
shivanisha55201872018-12-13 04:29:06892 break;
Shivani Sharma2d5b4b6b2019-01-08 16:07:16893 }
shivanisha55201872018-12-13 04:29:06894 }
895 UMA_HISTOGRAM_ENUMERATION("Navigation.BackForward.BackTargetSkipped",
896 count_entries_skipped, kMaxSessionHistoryEntries);
Shivani Sharma298d12852019-01-22 20:04:03897 UMA_HISTOGRAM_BOOLEAN("Navigation.BackForward.AllBackTargetsSkippable",
898 all_skippable_entries);
899
900 // Do nothing if all entries are skippable. Normally this path would not
901 // happen as consumers would have already checked it in CanGoBack but a lot of
902 // tests do not do that.
903 if (history_intervention_enabled && all_skippable_entries)
904 return;
shivanisha55201872018-12-13 04:29:06905
shivanisha55201872018-12-13 04:29:06906 GoToIndex(target_index);
[email protected]765b35502008-08-21 00:51:20907}
908
[email protected]d202a7c2012-01-04 07:53:47909void NavigationControllerImpl::GoForward() {
shivanisha55201872018-12-13 04:29:06910 int target_index = GetIndexForOffset(1);
911
912 // Log metrics for the number of entries that are eligible for skipping on
Shivani Sharma2d5b4b6b2019-01-08 16:07:16913 // forward button and move the target index past the skippable entries, if
914 // history intervention is enabled.
915 // Note that at least one entry (the last one) will be non-skippable since
916 // entries are marked skippable only when they add another entry because of
917 // redirect or pushState.
shivanisha55201872018-12-13 04:29:06918 int count_entries_skipped = 0;
Aran Gilman37d11632019-10-08 23:07:15919 bool history_intervention_enabled =
920 base::FeatureList::IsEnabled(features::kHistoryManipulationIntervention);
shivanisha55201872018-12-13 04:29:06921 for (size_t index = target_index; index < entries_.size(); index++) {
Shivani Sharma2d5b4b6b2019-01-08 16:07:16922 if (GetEntryAtIndex(index)->should_skip_on_back_forward_ui()) {
shivanisha55201872018-12-13 04:29:06923 count_entries_skipped++;
Shivani Sharma2d5b4b6b2019-01-08 16:07:16924 } else {
925 if (history_intervention_enabled)
926 target_index = index;
shivanisha55201872018-12-13 04:29:06927 break;
Shivani Sharma2d5b4b6b2019-01-08 16:07:16928 }
shivanisha55201872018-12-13 04:29:06929 }
930 UMA_HISTOGRAM_ENUMERATION("Navigation.BackForward.ForwardTargetSkipped",
931 count_entries_skipped, kMaxSessionHistoryEntries);
932
shivanisha55201872018-12-13 04:29:06933 GoToIndex(target_index);
[email protected]765b35502008-08-21 00:51:20934}
935
[email protected]d202a7c2012-01-04 07:53:47936void NavigationControllerImpl::GoToIndex(int index) {
Dave Tapuska8bfd84c2019-03-26 20:47:16937 GoToIndex(index, FrameTreeNode::kFrameTreeNodeInvalidId);
938}
939
940void NavigationControllerImpl::GoToIndex(int index,
941 int sandbox_frame_tree_node_id) {
sunjian30574a62017-03-21 21:39:44942 TRACE_EVENT0("browser,navigation,benchmark",
943 "NavigationControllerImpl::GoToIndex");
[email protected]765b35502008-08-21 00:51:20944 if (index < 0 || index >= static_cast<int>(entries_.size())) {
945 NOTREACHED();
946 return;
947 }
948
[email protected]cbab76d2008-10-13 22:42:47949 DiscardNonCommittedEntries();
[email protected]765b35502008-08-21 00:51:20950
arthursonzogni5c4c202d2017-04-25 23:41:27951 DCHECK_EQ(nullptr, pending_entry_);
952 DCHECK_EQ(-1, pending_entry_index_);
953 pending_entry_ = entries_[index].get();
[email protected]765b35502008-08-21 00:51:20954 pending_entry_index_ = index;
arthursonzogni5c4c202d2017-04-25 23:41:27955 pending_entry_->SetTransitionType(ui::PageTransitionFromInt(
956 pending_entry_->GetTransitionType() | ui::PAGE_TRANSITION_FORWARD_BACK));
Dave Tapuska8bfd84c2019-03-26 20:47:16957 NavigateToExistingPendingEntry(ReloadType::NONE, sandbox_frame_tree_node_id);
[email protected]765b35502008-08-21 00:51:20958}
959
[email protected]d202a7c2012-01-04 07:53:47960void NavigationControllerImpl::GoToOffset(int offset) {
toyoshim3af4d502016-03-30 12:38:12961 // Note: This is actually reached in unit tests.
[email protected]9ba14052012-06-22 23:50:03962 if (!CanGoToOffset(offset))
[email protected]765b35502008-08-21 00:51:20963 return;
964
[email protected]9ba14052012-06-22 23:50:03965 GoToIndex(GetIndexForOffset(offset));
[email protected]765b35502008-08-21 00:51:20966}
967
[email protected]41374f12013-07-24 02:49:28968bool NavigationControllerImpl::RemoveEntryAtIndex(int index) {
Aran Gilman37d11632019-10-08 23:07:15969 if (index == last_committed_entry_index_ || index == pending_entry_index_)
[email protected]41374f12013-07-24 02:49:28970 return false;
[email protected]6a13a6c2011-12-20 21:47:12971
[email protected]43032342011-03-21 14:10:31972 RemoveEntryAtIndexInternal(index);
[email protected]41374f12013-07-24 02:49:28973 return true;
[email protected]cbab76d2008-10-13 22:42:47974}
975
Michael Thiessen9b14d512019-09-23 21:19:47976void NavigationControllerImpl::PruneForwardEntries() {
977 DiscardNonCommittedEntries();
978 int remove_start_index = last_committed_entry_index_ + 1;
Lei Zhang96031532019-10-10 19:05:47979 int num_removed = static_cast<int>(entries_.size()) - remove_start_index;
Michael Thiessen9b14d512019-09-23 21:19:47980 if (num_removed <= 0)
981 return;
982 entries_.erase(entries_.begin() + remove_start_index, entries_.end());
983 NotifyPrunedEntries(this, remove_start_index /* start index */,
984 num_removed /* count */);
985}
986
Aran Gilman37d11632019-10-08 23:07:15987void NavigationControllerImpl::UpdateVirtualURLToURL(NavigationEntryImpl* entry,
988 const GURL& new_url) {
[email protected]38178a42009-12-17 18:58:32989 GURL new_virtual_url(new_url);
[email protected]825b1662012-03-12 19:07:31990 if (BrowserURLHandlerImpl::GetInstance()->ReverseURLRewrite(
[email protected]36fc0392011-12-25 03:59:51991 &new_virtual_url, entry->GetVirtualURL(), browser_context_)) {
992 entry->SetVirtualURL(new_virtual_url);
[email protected]38178a42009-12-17 18:58:32993 }
994}
995
Aran Gilman37d11632019-10-08 23:07:15996void NavigationControllerImpl::LoadURL(const GURL& url,
997 const Referrer& referrer,
998 ui::PageTransition transition,
999 const std::string& extra_headers) {
[email protected]cf002332012-08-14 19:17:471000 LoadURLParams params(url);
1001 params.referrer = referrer;
1002 params.transition_type = transition;
1003 params.extra_headers = extra_headers;
1004 LoadURLWithParams(params);
1005}
1006
1007void NavigationControllerImpl::LoadURLWithParams(const LoadURLParams& params) {
Lukasz Anforowicz435bcb582019-07-12 20:50:061008 if (params.is_renderer_initiated)
1009 DCHECK(params.initiator_origin.has_value());
1010
naskob8744d22014-08-28 17:07:431011 TRACE_EVENT1("browser,navigation",
Aran Gilman37d11632019-10-08 23:07:151012 "NavigationControllerImpl::LoadURLWithParams", "url",
1013 params.url.possibly_invalid_spec());
Ian Vollick9dda0522019-09-11 02:24:291014 bool is_explicit_navigation =
1015 GetContentClient()->browser()->IsExplicitNavigation(
1016 params.transition_type);
1017 if (HandleDebugURL(params.url, params.transition_type,
1018 is_explicit_navigation)) {
[email protected]47752982014-07-29 08:01:431019 // If Telemetry is running, allow the URL load to proceed as if it's
1020 // unhandled, otherwise Telemetry can't tell if Navigation completed.
avi83883c82014-12-23 00:08:491021 if (!base::CommandLine::ForCurrentProcess()->HasSwitch(
[email protected]47752982014-07-29 08:01:431022 cc::switches::kEnableGpuBenchmarking))
1023 return;
1024 }
[email protected]8bf1048012012-02-08 01:22:181025
[email protected]cf002332012-08-14 19:17:471026 // Checks based on params.load_type.
1027 switch (params.load_type) {
1028 case LOAD_TYPE_DEFAULT:
lukasza477a5a22016-06-16 18:28:431029 case LOAD_TYPE_HTTP_POST:
[email protected]cf002332012-08-14 19:17:471030 break;
1031 case LOAD_TYPE_DATA:
[email protected]cca6f392014-05-28 21:32:261032 if (!params.url.SchemeIs(url::kDataScheme)) {
[email protected]cf002332012-08-14 19:17:471033 NOTREACHED() << "Data load must use data scheme.";
1034 return;
1035 }
1036 break;
Lukasz Anforowiczbb0cfd5e2017-12-14 22:39:461037 }
[email protected]e47ae9472011-10-13 19:48:341038
[email protected]e47ae9472011-10-13 19:48:341039 // The user initiated a load, we don't need to reload anymore.
1040 needs_reload_ = false;
1041
clamy21718cc22018-06-13 13:34:241042 NavigateWithoutEntry(params);
[email protected]132e281a2012-07-31 18:32:441043}
1044
Mohamed Abdelhalim833de902019-09-16 17:41:451045bool NavigationControllerImpl::PendingEntryMatchesRequest(
1046 NavigationRequest* request) const {
creisb4dc9332016-03-14 21:39:191047 return pending_entry_ &&
Mohamed Abdelhalim833de902019-09-16 17:41:451048 pending_entry_->GetUniqueID() == request->nav_entry_id();
creisb4dc9332016-03-14 21:39:191049}
1050
[email protected]d202a7c2012-01-04 07:53:471051bool NavigationControllerImpl::RendererDidNavigate(
creis3da03872015-02-20 21:12:321052 RenderFrameHostImpl* rfh,
arthursonzogni73fe3212020-11-17 13:24:071053 const mojom::DidCommitProvisionalLoadParams& params,
peary21b0f797b2016-09-28 17:28:331054 LoadCommittedDetails* details,
Eugene But712f03d2018-05-22 16:03:441055 bool is_same_document_navigation,
Shivani Sharmaffb32b82019-04-09 16:58:471056 bool previous_document_was_activated,
Camille Lamy10aafcd32018-12-05 15:48:131057 NavigationRequest* navigation_request) {
1058 DCHECK(navigation_request);
[email protected]cd2e15742013-03-08 04:08:311059 is_initial_navigation_ = false;
1060
[email protected]0e8db942008-09-24 21:21:481061 // Save the previous state before we clobber it.
aelias100c9192017-01-13 00:01:431062 bool overriding_user_agent_changed = false;
[email protected]0e8db942008-09-24 21:21:481063 if (GetLastCommittedEntry()) {
Carlos IL42b416592019-10-07 23:10:361064 if (entry_replaced_by_post_commit_error_) {
1065 if (is_same_document_navigation) {
1066 // Same document navigations should not be possible on error pages and
1067 // would leave the controller in a weird state. Kill the renderer if
1068 // that happens.
1069 bad_message::ReceivedBadMessage(
1070 rfh->GetProcess(), bad_message::NC_SAME_DOCUMENT_POST_COMMIT_ERROR);
1071 }
1072 // Any commit while a post-commit error page is showing should put the
1073 // original entry back, replacing the error page's entry. This includes
1074 // reloads, where the original entry was used as the pending entry and
1075 // should now be at the correct index at commit time.
1076 entries_[last_committed_entry_index_] =
1077 std::move(entry_replaced_by_post_commit_error_);
1078 }
Fergal Daly8e33cf62020-12-12 01:06:071079 details->previous_main_frame_url = GetLastCommittedEntry()->GetURL();
[email protected]a26023822011-12-29 00:23:551080 details->previous_entry_index = GetLastCommittedEntryIndex();
aelias100c9192017-01-13 00:01:431081 if (pending_entry_ &&
1082 pending_entry_->GetIsOverridingUserAgent() !=
1083 GetLastCommittedEntry()->GetIsOverridingUserAgent())
1084 overriding_user_agent_changed = true;
[email protected]0e8db942008-09-24 21:21:481085 } else {
Gang Wu325f03f42021-02-25 20:00:461086 // GetLastCommittedEntry() is null, so this is the first entry.
Fergal Daly8e33cf62020-12-12 01:06:071087 details->previous_main_frame_url = GURL();
[email protected]0e8db942008-09-24 21:21:481088 details->previous_entry_index = -1;
Gang Wu325f03f42021-02-25 20:00:461089 if (pending_entry_ && pending_entry_->GetIsOverridingUserAgent()) {
1090 // Default setting is NOT override the user agent, so overriding the user
1091 // agent in first entry should be considered as user agent changed as
1092 // well.
1093 overriding_user_agent_changed = true;
1094 }
[email protected]0e8db942008-09-24 21:21:481095 }
[email protected]ecd9d8702008-08-28 22:10:171096
Alexander Timind2f2e4f22019-04-02 20:04:531097 // TODO(altimin, crbug.com/933147): Remove this logic after we are done with
1098 // implementing back-forward cache.
1099
1100 // Create a new metrics object or reuse the previous one depending on whether
1101 // it's a main frame navigation or not.
1102 scoped_refptr<BackForwardCacheMetrics> back_forward_cache_metrics =
1103 BackForwardCacheMetrics::CreateOrReuseBackForwardCacheMetrics(
1104 GetLastCommittedEntry(), !rfh->GetParent(),
1105 params.document_sequence_number);
1106 // Notify the last active entry that we have navigated away.
1107 if (!rfh->GetParent() && !is_same_document_navigation) {
1108 if (NavigationEntryImpl* navigation_entry = GetLastCommittedEntry()) {
1109 if (auto* metrics = navigation_entry->back_forward_cache_metrics()) {
Alexander Timinde527cd2019-12-02 09:41:121110 metrics->MainFrameDidNavigateAwayFromDocument(rfh, details,
1111 navigation_request);
Alexander Timind2f2e4f22019-04-02 20:04:531112 }
1113 }
1114 }
1115
fdegans9caf66a2015-07-30 21:10:421116 // If there is a pending entry at this point, it should have a SiteInstance,
1117 // except for restored entries.
jam48cea9082017-02-15 06:13:291118 bool was_restored = false;
toyoshim0df1d3a2016-09-09 09:52:481119 DCHECK(pending_entry_index_ == -1 || pending_entry_->site_instance() ||
Lukasz Anforowicz6b75c0d2020-12-01 22:56:081120 pending_entry_->IsRestored());
1121 if (pending_entry_ && pending_entry_->IsRestored()) {
Lukasz Anforowicz0de0f452020-12-02 19:57:151122 pending_entry_->set_restore_type(RestoreType::kNotRestored);
jam48cea9082017-02-15 06:13:291123 was_restored = true;
toyoshim0df1d3a2016-09-09 09:52:481124 }
[email protected]e9ba4472008-09-14 15:42:431125
Nasko Oskovaee2f862018-06-15 00:05:521126 // If this is a navigation to a matching pending_entry_ and the SiteInstance
1127 // has changed, this must be treated as a new navigation with replacement.
1128 // Set the replacement bit here and ClassifyNavigation will identify this
Charlie Reisc0f17d2d2021-01-12 18:52:491129 // case and return NEW_ENTRY.
Nasko Oskovaee2f862018-06-15 00:05:521130 if (!rfh->GetParent() && pending_entry_ &&
Rakina Zata Amnif6950d552020-11-24 03:26:101131 pending_entry_->GetUniqueID() ==
1132 navigation_request->commit_params().nav_entry_id &&
Nasko Oskovaee2f862018-06-15 00:05:521133 pending_entry_->site_instance() &&
1134 pending_entry_->site_instance() != rfh->GetSiteInstance()) {
1135 DCHECK_NE(-1, pending_entry_index_);
1136 // TODO(nasko,creis): Instead of setting this value here, set
1137 // should_replace_current_entry on the parameters we send to the
1138 // renderer process as part of CommitNavigation. The renderer should
1139 // in turn send it back here as part of |params| and it can be just
1140 // enforced and renderer process terminated on mismatch.
1141 details->did_replace_entry = true;
1142 } else {
1143 // The renderer tells us whether the navigation replaces the current entry.
1144 details->did_replace_entry = params.should_replace_current_entry;
1145 }
[email protected]bcd904482012-02-01 01:54:221146
[email protected]e9ba4472008-09-14 15:42:431147 // Do navigation-type specific actions. These will make and commit an entry.
Rakina Zata Amnif6950d552020-11-24 03:26:101148 details->type = ClassifyNavigation(rfh, params, navigation_request);
[email protected]4bf3522c2010-08-19 21:00:201149
eugenebutee08663a2017-04-27 17:43:121150 // is_same_document must be computed before the entry gets committed.
Eugene But712f03d2018-05-22 16:03:441151 details->is_same_document = is_same_document_navigation;
[email protected]b9d4dfdc2013-08-08 00:25:121152
Peter Boströmd7592132019-01-30 04:50:311153 // Make sure we do not discard the pending entry for a different ongoing
1154 // navigation when a same document commit comes in unexpectedly from the
1155 // renderer. Limit this to a very narrow set of conditions to avoid risks to
1156 // other navigation types. See https://crbug.com/900036.
1157 // TODO(crbug.com/926009): Handle history.pushState() as well.
1158 bool keep_pending_entry = is_same_document_navigation &&
Charlie Reisc0f17d2d2021-01-12 18:52:491159 details->type == NAVIGATION_TYPE_EXISTING_ENTRY &&
Peter Boströmd7592132019-01-30 04:50:311160 pending_entry_ &&
Mohamed Abdelhalim833de902019-09-16 17:41:451161 !PendingEntryMatchesRequest(navigation_request);
Peter Boströmd7592132019-01-30 04:50:311162
[email protected]0e8db942008-09-24 21:21:481163 switch (details->type) {
Charlie Reisc0f17d2d2021-01-12 18:52:491164 case NAVIGATION_TYPE_NEW_ENTRY:
1165 RendererDidNavigateToNewEntry(
shivanisha41f04c52018-12-12 15:52:051166 rfh, params, details->is_same_document, details->did_replace_entry,
Mohamed Abdelhalim833de902019-09-16 17:41:451167 previous_document_was_activated, navigation_request);
[email protected]e9ba4472008-09-14 15:42:431168 break;
Charlie Reisc0f17d2d2021-01-12 18:52:491169 case NAVIGATION_TYPE_EXISTING_ENTRY:
1170 RendererDidNavigateToExistingEntry(rfh, params, details->is_same_document,
1171 was_restored, navigation_request,
1172 keep_pending_entry);
[email protected]e9ba4472008-09-14 15:42:431173 break;
[email protected]8ff00d72012-10-23 19:12:211174 case NAVIGATION_TYPE_NEW_SUBFRAME:
Shivani Sharmaffb32b82019-04-09 16:58:471175 RendererDidNavigateNewSubframe(
1176 rfh, params, details->is_same_document, details->did_replace_entry,
Mohamed Abdelhalim833de902019-09-16 17:41:451177 previous_document_was_activated, navigation_request);
[email protected]e9ba4472008-09-14 15:42:431178 break;
[email protected]8ff00d72012-10-23 19:12:211179 case NAVIGATION_TYPE_AUTO_SUBFRAME:
Antonio Sartori78a749f2020-11-30 12:03:391180 if (!RendererDidNavigateAutoSubframe(
1181 rfh, params, details->is_same_document, navigation_request)) {
creisce0ef3572017-01-26 17:53:081182 // We don't send a notification about auto-subframe PageState during
1183 // UpdateStateForFrame, since it looks like nothing has changed. Send
1184 // it here at commit time instead.
1185 NotifyEntryChanged(GetLastCommittedEntry());
[email protected]e9ba4472008-09-14 15:42:431186 return false;
creis59d5a47cb2016-08-24 23:57:191187 }
[email protected]e9ba4472008-09-14 15:42:431188 break;
[email protected]8ff00d72012-10-23 19:12:211189 case NAVIGATION_TYPE_NAV_IGNORE:
[email protected]20d1c992011-04-12 21:17:491190 // If a pending navigation was in progress, this canceled it. We should
1191 // discard it and make sure it is removed from the URL bar. After that,
1192 // there is nothing we can do with this navigation, so we just return to
[email protected]e9ba4472008-09-14 15:42:431193 // the caller that nothing has happened.
arthursonzogni69a6a1b2019-09-17 09:23:001194 if (pending_entry_)
[email protected]20d1c992011-04-12 21:17:491195 DiscardNonCommittedEntries();
[email protected]e9ba4472008-09-14 15:42:431196 return false;
Aran Gilman37d11632019-10-08 23:07:151197 case NAVIGATION_TYPE_UNKNOWN:
[email protected]e9ba4472008-09-14 15:42:431198 NOTREACHED();
Aran Gilman37d11632019-10-08 23:07:151199 break;
[email protected]765b35502008-08-21 00:51:201200 }
1201
[email protected]688aa65c62012-09-28 04:32:221202 // At this point, we know that the navigation has just completed, so
1203 // record the time.
1204 //
1205 // TODO(akalin): Use "sane time" as described in
Adam Langley4463fb832018-01-28 22:42:261206 // https://www.chromium.org/developers/design-documents/sane-time .
[email protected]c5b88d82012-10-06 17:03:331207 base::Time timestamp =
1208 time_smoother_.GetSmoothedTime(get_timestamp_callback_.Run());
1209 DVLOG(1) << "Navigation finished at (smoothed) timestamp "
danakjf26536bf2020-09-10 00:46:131210 << timestamp.ToDeltaSinceWindowsEpoch().InMicroseconds();
[email protected]688aa65c62012-09-28 04:32:221211
Peter Boströmd7592132019-01-30 04:50:311212 // If we aren't keeping the pending entry, there shouldn't be one at this
1213 // point. Clear it again in case any error cases above forgot to do so.
1214 // TODO(pbos): Consider a CHECK here that verifies that the pending entry has
1215 // been cleared instead of protecting against it.
1216 if (!keep_pending_entry)
arthursonzogni69a6a1b2019-09-17 09:23:001217 DiscardNonCommittedEntries();
[email protected]f233e4232013-02-23 00:55:141218
[email protected]e9ba4472008-09-14 15:42:431219 // All committed entries should have nonempty content state so WebKit doesn't
1220 // get confused when we go back to them (see the function for details).
creis0cade2e2017-02-28 06:37:471221 DCHECK(params.page_state.IsValid()) << "Shouldn't see an empty PageState.";
creis3da03872015-02-20 21:12:321222 NavigationEntryImpl* active_entry = GetLastCommittedEntry();
[email protected]688aa65c62012-09-28 04:32:221223 active_entry->SetTimestamp(timestamp);
[email protected]f49737b32013-08-28 07:51:441224 active_entry->SetHttpStatusCode(params.http_status_code);
Alexander Timind2f2e4f22019-04-02 20:04:531225 // TODO(altimin, crbug.com/933147): Remove this logic after we are done with
1226 // implementing back-forward cache.
1227 if (!active_entry->back_forward_cache_metrics()) {
1228 active_entry->set_back_forward_cache_metrics(
1229 std::move(back_forward_cache_metrics));
1230 }
1231 active_entry->back_forward_cache_metrics()->DidCommitNavigation(
Hajime Hoshi446206e2019-10-18 18:36:251232 navigation_request,
1233 back_forward_cache_.IsAllowed(navigation_request->GetURL()));
naskoc7533512016-05-06 17:01:121234
Charles Reisc0507202017-09-21 00:40:021235 // Grab the corresponding FrameNavigationEntry for a few updates, but only if
1236 // the SiteInstance matches (to avoid updating the wrong entry by mistake).
1237 // A mismatch can occur if the renderer lies or due to a unique name collision
1238 // after a race with an OOPIF (see https://crbug.com/616820).
naskoc7533512016-05-06 17:01:121239 FrameNavigationEntry* frame_entry =
1240 active_entry->GetFrameEntry(rfh->frame_tree_node());
Charles Reisc0507202017-09-21 00:40:021241 if (frame_entry && frame_entry->site_instance() != rfh->GetSiteInstance())
1242 frame_entry = nullptr;
Charles Reisf44482022017-10-13 21:15:031243 // Make sure we've updated the PageState in one of the helper methods.
creisce0ef3572017-01-26 17:53:081244 // TODO(creis): Remove the "if" once https://crbug.com/522193 is fixed.
1245 if (frame_entry) {
Charles Reisf44482022017-10-13 21:15:031246 DCHECK(params.page_state == frame_entry->page_state());
Nasko Oskovbbcfc0002019-11-20 20:03:201247
1248 // Remember the bindings the renderer process has at this point, so that
1249 // we do not grant this entry additional bindings if we come back to it.
1250 frame_entry->SetBindings(rfh->GetEnabledBindings());
creis4e2ecb72015-06-20 00:46:301251 }
[email protected]132e281a2012-07-31 18:32:441252
[email protected]97d8f0d2013-10-29 16:49:211253 // Once it is committed, we no longer need to track several pieces of state on
1254 // the entry.
naskoc7533512016-05-06 17:01:121255 active_entry->ResetForCommit(frame_entry);
[email protected]60d6cca2013-04-30 08:47:131256
[email protected]49bd30e62011-03-22 20:12:591257 // The active entry's SiteInstance should match our SiteInstance.
[email protected]a1b99262013-12-27 21:56:221258 // TODO(creis): This check won't pass for subframes until we create entries
1259 // for subframe navigations.
avi39c1edd32015-06-04 20:06:001260 if (!rfh->GetParent())
creis77c9aa32015-09-25 19:59:421261 CHECK_EQ(active_entry->site_instance(), rfh->GetSiteInstance());
[email protected]49bd30e62011-03-22 20:12:591262
[email protected]e9ba4472008-09-14 15:42:431263 // Now prep the rest of the details for the notification and broadcast.
[email protected]0f38dc4552011-02-25 11:24:001264 details->entry = active_entry;
avi39c1edd32015-06-04 20:06:001265 details->is_main_frame = !rfh->GetParent();
[email protected]2e39d2e2009-02-19 18:41:311266 details->http_status_code = params.http_status_code;
estarka5635c42015-07-14 00:06:531267
Scott Violetc36f7462020-05-06 23:13:031268 // If the NavigationRequest was created without a NavigationEntry and
1269 // SetIsOverridingUserAgent() was called, it needs to be applied to the
1270 // NavigationEntry now.
1271 if (!navigation_request->nav_entry_id() &&
1272 navigation_request->was_set_overriding_user_agent_called()) {
1273 active_entry->SetIsOverridingUserAgent(
1274 navigation_request->entry_overrides_ua());
1275 }
1276
[email protected]93f230e02011-06-01 14:40:001277 NotifyNavigationEntryCommitted(details);
initial.commit09911bf2008-07-26 23:55:291278
John Abd-El-Malek380d3c5922017-09-08 00:20:311279 if (active_entry->GetURL().SchemeIs(url::kHttpsScheme) && !rfh->GetParent() &&
Mohamed Abdelhalim833de902019-09-16 17:41:451280 navigation_request->GetNetErrorCode() == net::OK) {
John Abd-El-Malek969cdd94e2017-07-10 22:18:161281 UMA_HISTOGRAM_BOOLEAN("Navigation.SecureSchemeHasSSLStatus",
1282 !!active_entry->GetSSL().certificate);
1283 }
1284
aelias100c9192017-01-13 00:01:431285 if (overriding_user_agent_changed)
1286 delegate_->UpdateOverridingUserAgent();
1287
creis03b48002015-11-04 00:54:561288 // Update the nav_entry_id for each RenderFrameHost in the tree, so that each
1289 // one knows the latest NavigationEntry it is showing (whether it has
1290 // committed anything in this navigation or not). This allows things like
1291 // state and title updates from RenderFrames to apply to the latest relevant
1292 // NavigationEntry.
dcheng57e39e22016-01-21 00:25:381293 int nav_entry_id = active_entry->GetUniqueID();
Carlos Caballero40b0efd2021-01-26 11:55:001294 for (FrameTreeNode* node : frame_tree_.Nodes())
dcheng57e39e22016-01-21 00:25:381295 node->current_frame_host()->set_nav_entry_id(nav_entry_id);
[email protected]e9ba4472008-09-14 15:42:431296 return true;
initial.commit09911bf2008-07-26 23:55:291297}
1298
[email protected]8ff00d72012-10-23 19:12:211299NavigationType NavigationControllerImpl::ClassifyNavigation(
creis3da03872015-02-20 21:12:321300 RenderFrameHostImpl* rfh,
Rakina Zata Amnif6950d552020-11-24 03:26:101301 const mojom::DidCommitProvisionalLoadParams& params,
1302 NavigationRequest* navigation_request) {
Piotr Tworekbad51282020-09-30 19:17:591303 TraceReturnReason<tracing_category::kNavigation> trace_return(
Nasko Oskovae49e292020-08-13 02:08:511304 "ClassifyNavigation");
1305
avi7c6f35e2015-05-08 17:52:381306 if (params.did_create_new_entry) {
Charlie Reisc0f17d2d2021-01-12 18:52:491307 // A new entry. We may or may not have a corresponding pending entry, and
avi7c6f35e2015-05-08 17:52:381308 // this may or may not be the main frame.
avi39c1edd32015-06-04 20:06:001309 if (!rfh->GetParent()) {
Charlie Reisc0f17d2d2021-01-12 18:52:491310 trace_return.set_return_reason("new entry, no parent, new entry");
1311 return NAVIGATION_TYPE_NEW_ENTRY;
avi7c6f35e2015-05-08 17:52:381312 }
1313
1314 // When this is a new subframe navigation, we should have a committed page
1315 // in which it's a subframe. This may not be the case when an iframe is
1316 // navigated on a popup navigated to about:blank (the iframe would be
1317 // written into the popup by script on the main page). For these cases,
1318 // there isn't any navigation stuff we can do, so just ignore it.
Nasko Oskovae49e292020-08-13 02:08:511319 if (!GetLastCommittedEntry()) {
1320 trace_return.set_return_reason("new entry, no last committed, ignore");
avi7c6f35e2015-05-08 17:52:381321 return NAVIGATION_TYPE_NAV_IGNORE;
Nasko Oskovae49e292020-08-13 02:08:511322 }
avi7c6f35e2015-05-08 17:52:381323
1324 // Valid subframe navigation.
Nasko Oskovae49e292020-08-13 02:08:511325 trace_return.set_return_reason("new entry, new subframe");
avi7c6f35e2015-05-08 17:52:381326 return NAVIGATION_TYPE_NEW_SUBFRAME;
1327 }
1328
Charlie Reisc0f17d2d2021-01-12 18:52:491329 // We only clear the session history in tests when navigating to a new entry.
avi7c6f35e2015-05-08 17:52:381330 DCHECK(!params.history_list_was_cleared);
1331
avi39c1edd32015-06-04 20:06:001332 if (rfh->GetParent()) {
avi7c6f35e2015-05-08 17:52:381333 // All manual subframes would be did_create_new_entry and handled above, so
1334 // we know this is auto.
Nasko Oskovae49e292020-08-13 02:08:511335 if (GetLastCommittedEntry()) {
1336 trace_return.set_return_reason("subframe, last commmited, auto subframe");
avi7c6f35e2015-05-08 17:52:381337 return NAVIGATION_TYPE_AUTO_SUBFRAME;
Nasko Oskovae49e292020-08-13 02:08:511338 }
Lei Zhang96031532019-10-10 19:05:471339
1340 // We ignore subframes created in non-committed pages; we'd appreciate if
1341 // people stopped doing that.
Nasko Oskovae49e292020-08-13 02:08:511342 trace_return.set_return_reason("subframe, no last commmited, ignore");
Lei Zhang96031532019-10-10 19:05:471343 return NAVIGATION_TYPE_NAV_IGNORE;
avi7c6f35e2015-05-08 17:52:381344 }
1345
Rakina Zata Amnif6950d552020-11-24 03:26:101346 const int nav_entry_id = navigation_request->commit_params().nav_entry_id;
1347 if (nav_entry_id == 0) {
avi7c6f35e2015-05-08 17:52:381348 // This is a renderer-initiated navigation (nav_entry_id == 0), but didn't
1349 // create a new page.
1350
1351 // Just like above in the did_create_new_entry case, it's possible to
1352 // scribble onto an uncommitted page. Again, there isn't any navigation
1353 // stuff that we can do, so ignore it here as well.
avi3a5b8f32015-05-28 17:50:231354 NavigationEntry* last_committed = GetLastCommittedEntry();
Nasko Oskovae49e292020-08-13 02:08:511355 if (!last_committed) {
1356 trace_return.set_return_reason("nav entry 0, no last committed, ignore");
avi7c6f35e2015-05-08 17:52:381357 return NAVIGATION_TYPE_NAV_IGNORE;
Nasko Oskovae49e292020-08-13 02:08:511358 }
avi7c6f35e2015-05-08 17:52:381359
Charles Reis1378111f2017-11-08 21:44:061360 // This is history.replaceState() or history.reload().
Nasko Oskov332593c2018-08-16 17:21:341361 // TODO(nasko): With error page isolation, reloading an existing session
1362 // history entry can result in change of SiteInstance. Check for such a case
Charlie Reisc0f17d2d2021-01-12 18:52:491363 // here and classify it as NEW_ENTRY, as such navigations should be treated
Nasko Oskov332593c2018-08-16 17:21:341364 // as new with replacement.
Nasko Oskovae49e292020-08-13 02:08:511365 trace_return.set_return_reason(
Charlie Reisc0f17d2d2021-01-12 18:52:491366 "nav entry 0, last committed, existing entry");
1367 return NAVIGATION_TYPE_EXISTING_ENTRY;
avi7c6f35e2015-05-08 17:52:381368 }
1369
Rakina Zata Amnif6950d552020-11-24 03:26:101370 if (pending_entry_ && pending_entry_->GetUniqueID() == nav_entry_id) {
Nasko Oskovaee2f862018-06-15 00:05:521371 // If the SiteInstance of the |pending_entry_| does not match the
1372 // SiteInstance that got committed, treat this as a new navigation with
1373 // replacement. This can happen if back/forward/reload encounters a server
1374 // redirect to a different site or an isolated error page gets successfully
1375 // reloaded into a different SiteInstance.
1376 if (pending_entry_->site_instance() &&
1377 pending_entry_->site_instance() != rfh->GetSiteInstance()) {
Charlie Reisc0f17d2d2021-01-12 18:52:491378 trace_return.set_return_reason("pending matching nav entry, new entry");
1379 return NAVIGATION_TYPE_NEW_ENTRY;
Nasko Oskovaee2f862018-06-15 00:05:521380 }
creis77c9aa32015-09-25 19:59:421381
Nasko Oskovaee2f862018-06-15 00:05:521382 if (pending_entry_index_ == -1) {
1383 // In this case, we have a pending entry for a load of a new URL but Blink
1384 // didn't do a new navigation (params.did_create_new_entry). First check
1385 // to make sure Blink didn't treat a new cross-process navigation as
1386 // inert, and thus set params.did_create_new_entry to false. In that case,
Charlie Reis7e2cb6d2021-01-26 01:27:161387 // we must treat it as NEW rather than the converted reload case below,
1388 // since the new SiteInstance doesn't match the last committed entry.
Nasko Oskovaee2f862018-06-15 00:05:521389 if (!GetLastCommittedEntry() ||
1390 GetLastCommittedEntry()->site_instance() != rfh->GetSiteInstance()) {
Charlie Reis7e2cb6d2021-01-26 01:27:161391 trace_return.set_return_reason("new pending, new entry");
Charlie Reisc0f17d2d2021-01-12 18:52:491392 return NAVIGATION_TYPE_NEW_ENTRY;
Nasko Oskovaee2f862018-06-15 00:05:521393 }
1394
1395 // Otherwise, this happens when you press enter in the URL bar to reload.
Charlie Reis7e2cb6d2021-01-26 01:27:161396 // We will create a pending entry, but NavigateWithoutEntry will convert
1397 // it to a reload since it's the same page and not create a new entry for
1398 // it. (The user doesn't want to have a new back/forward entry when they
1399 // do this.) Therefore we want to just ignore the pending entry and go
1400 // back to where we were (the "existing entry").
1401 trace_return.set_return_reason("new pending, existing (same) entry");
1402 return NAVIGATION_TYPE_EXISTING_ENTRY;
Nasko Oskovaee2f862018-06-15 00:05:521403 }
avi7c6f35e2015-05-08 17:52:381404 }
1405
creis26d22632017-04-21 20:23:561406 // Everything below here is assumed to be an existing entry, but if there is
1407 // no last committed entry, we must consider it a new navigation instead.
Nasko Oskovae49e292020-08-13 02:08:511408 if (!GetLastCommittedEntry()) {
Charlie Reisc0f17d2d2021-01-12 18:52:491409 trace_return.set_return_reason("no last committed, new entry");
1410 return NAVIGATION_TYPE_NEW_ENTRY;
Nasko Oskovae49e292020-08-13 02:08:511411 }
creis26d22632017-04-21 20:23:561412
avi7c6f35e2015-05-08 17:52:381413 if (params.intended_as_new_entry) {
1414 // This was intended to be a navigation to a new entry but the pending entry
Charlie Reisc0f17d2d2021-01-12 18:52:491415 // got cleared in the meanwhile. Classify as EXISTING_ENTRY because we may
1416 // or may not have a pending entry.
Charlie Reis7e2cb6d2021-01-26 01:27:161417 trace_return.set_return_reason("intended as new entry, existing entry");
Charlie Reisc0f17d2d2021-01-12 18:52:491418 return NAVIGATION_TYPE_EXISTING_ENTRY;
avi7c6f35e2015-05-08 17:52:381419 }
1420
1421 if (params.url_is_unreachable && failed_pending_entry_id_ != 0 &&
Rakina Zata Amnif6950d552020-11-24 03:26:101422 nav_entry_id == failed_pending_entry_id_) {
avi7c6f35e2015-05-08 17:52:381423 // If the renderer was going to a new pending entry that got cleared because
1424 // of an error, this is the case of the user trying to retry a failed load
Charlie Reisc0f17d2d2021-01-12 18:52:491425 // by pressing return. Classify as EXISTING_ENTRY because we probably don't
avi7c6f35e2015-05-08 17:52:381426 // have a pending entry.
Nasko Oskovae49e292020-08-13 02:08:511427 trace_return.set_return_reason(
Charlie Reisc0f17d2d2021-01-12 18:52:491428 "unreachable, matching pending, existing entry");
1429 return NAVIGATION_TYPE_EXISTING_ENTRY;
avi7c6f35e2015-05-08 17:52:381430 }
1431
Charlie Reisc0f17d2d2021-01-12 18:52:491432 // Now we know that the notification is for an existing entry; find it.
Rakina Zata Amnif6950d552020-11-24 03:26:101433 int existing_entry_index = GetEntryIndexWithUniqueID(nav_entry_id);
Nasko Oskovae49e292020-08-13 02:08:511434 trace_return.traced_value()->SetInteger("existing_entry_index",
1435 existing_entry_index);
avi7c6f35e2015-05-08 17:52:381436 if (existing_entry_index == -1) {
avi5cad4912015-06-19 05:25:441437 // The renderer has committed a navigation to an entry that no longer
1438 // exists. Because the renderer is showing that page, resurrect that entry.
Charlie Reisc0f17d2d2021-01-12 18:52:491439 trace_return.set_return_reason("existing entry -1, new entry");
1440 return NAVIGATION_TYPE_NEW_ENTRY;
avi7c6f35e2015-05-08 17:52:381441 }
1442
avi7c6f35e2015-05-08 17:52:381443 // Since we weeded out "new" navigations above, we know this is an existing
1444 // (back/forward) navigation.
Charlie Reisc0f17d2d2021-01-12 18:52:491445 trace_return.set_return_reason("default return, existing entry");
1446 return NAVIGATION_TYPE_EXISTING_ENTRY;
avi7c6f35e2015-05-08 17:52:381447}
1448
Charlie Reisc0f17d2d2021-01-12 18:52:491449void NavigationControllerImpl::RendererDidNavigateToNewEntry(
creis3da03872015-02-20 21:12:321450 RenderFrameHostImpl* rfh,
arthursonzogni73fe3212020-11-17 13:24:071451 const mojom::DidCommitProvisionalLoadParams& params,
eugenebut604866f2017-05-10 21:35:361452 bool is_same_document,
clamy3bf35e3c2016-11-10 15:59:441453 bool replace_entry,
Shivani Sharmaffb32b82019-04-09 16:58:471454 bool previous_document_was_activated,
Mohamed Abdelhalim833de902019-09-16 17:41:451455 NavigationRequest* request) {
dcheng9bfa5162016-04-09 01:00:571456 std::unique_ptr<NavigationEntryImpl> new_entry;
creisf49dfc92016-07-26 17:05:181457 bool update_virtual_url = false;
1458
Lukasz Anforowicz435bcb582019-07-12 20:50:061459 const base::Optional<url::Origin>& initiator_origin =
Mohamed Abdelhalim833de902019-09-16 17:41:451460 request->common_params().initiator_origin;
Lukasz Anforowicz435bcb582019-07-12 20:50:061461
creisf49dfc92016-07-26 17:05:181462 // First check if this is an in-page navigation. If so, clone the current
1463 // entry instead of looking at the pending entry, because the pending entry
1464 // does not have any subframe history items.
eugenebut604866f2017-05-10 21:35:361465 if (is_same_document && GetLastCommittedEntry()) {
Patrick Monette50e8bd82019-06-13 22:40:451466 auto frame_entry = base::MakeRefCounted<FrameNavigationEntry>(
Charles Reisd2a509f2017-09-27 23:47:481467 rfh->frame_tree_node()->unique_name(), params.item_sequence_number,
creisf49dfc92016-07-26 17:05:181468 params.document_sequence_number, rfh->GetSiteInstance(), nullptr,
Nasko Oskov03912102019-01-11 00:21:321469 params.url, (params.url_is_unreachable) ? nullptr : &params.origin,
arthursonzogni73fe3212020-11-17 13:24:071470 Referrer(*params.referrer), initiator_origin, params.redirects,
1471 params.page_state, params.method, params.post_id,
1472 nullptr /* blob_url_loader_factory */,
Antonio Sartori78a749f2020-11-30 12:03:391473 nullptr /* web_bundle_navigation_info */,
1474 // We will set the document policies later in this function.
Titouan Rigoudy6ec70402021-02-02 15:42:191475 nullptr /* policy_container_policies */);
Charles Reisf44482022017-10-13 21:15:031476
creisf49dfc92016-07-26 17:05:181477 new_entry = GetLastCommittedEntry()->CloneAndReplace(
Carlos Caballero40b0efd2021-01-26 11:55:001478 frame_entry, true, rfh->frame_tree_node(), frame_tree_.root());
jama78746e2017-02-22 17:21:571479 if (new_entry->GetURL().GetOrigin() != params.url.GetOrigin()) {
1480 // TODO(jam): we had one report of this with a URL that was redirecting to
1481 // only tildes. Until we understand that better, don't copy the cert in
1482 // this case.
1483 new_entry->GetSSL() = SSLStatus();
John Abd-El-Malek9cd697e2017-07-12 21:53:141484
John Abd-El-Malek380d3c5922017-09-08 00:20:311485 if (params.url.SchemeIs(url::kHttpsScheme) && !rfh->GetParent() &&
Mohamed Abdelhalim833de902019-09-16 17:41:451486 request->GetNetErrorCode() == net::OK) {
John Abd-El-Malek9cd697e2017-07-12 21:53:141487 UMA_HISTOGRAM_BOOLEAN(
1488 "Navigation.SecureSchemeHasSSLStatus.NewPageInPageOriginMismatch",
1489 !!new_entry->GetSSL().certificate);
1490 }
jama78746e2017-02-22 17:21:571491 }
creisf49dfc92016-07-26 17:05:181492
Patrick Monette50e8bd82019-06-13 22:40:451493 // It is expected that |frame_entry| is now owned by |new_entry|. This means
1494 // that |frame_entry| should now have a reference count of exactly 2: one
1495 // due to the local variable |frame_entry|, and another due to |new_entry|
1496 // also retaining one. This should never fail, because it's the main frame.
1497 CHECK(!frame_entry->HasOneRef() && frame_entry->HasAtLeastOneRef());
creisf49dfc92016-07-26 17:05:181498
1499 update_virtual_url = new_entry->update_virtual_url_with_url();
John Abd-El-Malek9cd697e2017-07-12 21:53:141500
John Abd-El-Malek380d3c5922017-09-08 00:20:311501 if (params.url.SchemeIs(url::kHttpsScheme) && !rfh->GetParent() &&
Mohamed Abdelhalim833de902019-09-16 17:41:451502 request->GetNetErrorCode() == net::OK) {
John Abd-El-Malek9cd697e2017-07-12 21:53:141503 UMA_HISTOGRAM_BOOLEAN("Navigation.SecureSchemeHasSSLStatus.NewPageInPage",
1504 !!new_entry->GetSSL().certificate);
1505 }
creisf49dfc92016-07-26 17:05:181506 }
1507
Charlie Reisc0f17d2d2021-01-12 18:52:491508 // Only make a copy of the pending entry if it is appropriate for the new
1509 // document that just loaded. Verify this by checking if the entry corresponds
Mohamed Abdelhalim833de902019-09-16 17:41:451510 // to the given NavigationRequest. Additionally, coarsely check that:
csharrison9a9142bc42016-03-01 17:24:041511 // 1. The SiteInstance hasn't been assigned to something else.
1512 // 2. The pending entry was intended as a new entry, rather than being a
1513 // history navigation that was interrupted by an unrelated,
1514 // renderer-initiated navigation.
1515 // TODO(csharrison): Investigate whether we can remove some of the coarser
1516 // checks.
Mohamed Abdelhalim833de902019-09-16 17:41:451517 if (!new_entry && PendingEntryMatchesRequest(request) &&
1518 pending_entry_index_ == -1 &&
[email protected]6dd86ab2013-02-27 00:30:341519 (!pending_entry_->site_instance() ||
[email protected]27dd82fd2014-03-03 22:11:431520 pending_entry_->site_instance() == rfh->GetSiteInstance())) {
creisef4a0cb2015-03-12 19:14:351521 new_entry = pending_entry_->Clone();
[email protected]e9ba4472008-09-14 15:42:431522
[email protected]f1eb87a2011-05-06 17:49:411523 update_virtual_url = new_entry->update_virtual_url_with_url();
Camille Lamy62b826012019-02-26 09:15:471524 new_entry->GetSSL() =
Mohamed Abdelhalim833de902019-09-16 17:41:451525 SSLStatus(request->GetSSLInfo().value_or(net::SSLInfo()));
John Abd-El-Malek9cd697e2017-07-12 21:53:141526
John Abd-El-Malek380d3c5922017-09-08 00:20:311527 if (params.url.SchemeIs(url::kHttpsScheme) && !rfh->GetParent() &&
Mohamed Abdelhalim833de902019-09-16 17:41:451528 request->GetNetErrorCode() == net::OK) {
John Abd-El-Malek9cd697e2017-07-12 21:53:141529 UMA_HISTOGRAM_BOOLEAN(
1530 "Navigation.SecureSchemeHasSSLStatus.NewPagePendingEntryMatches",
1531 !!new_entry->GetSSL().certificate);
1532 }
creisf49dfc92016-07-26 17:05:181533 }
1534
Charlie Reisc0f17d2d2021-01-12 18:52:491535 // For cross-document commits with no matching pending entry, create a new
1536 // entry.
creisf49dfc92016-07-26 17:05:181537 if (!new_entry) {
Lukasz Anforowicz435bcb582019-07-12 20:50:061538 new_entry = std::make_unique<NavigationEntryImpl>(
arthursonzogni73fe3212020-11-17 13:24:071539 rfh->GetSiteInstance(), params.url, Referrer(*params.referrer),
1540 initiator_origin,
Lukasz Anforowicz435bcb582019-07-12 20:50:061541 base::string16(), // title
Mohamed Abdelhalim833de902019-09-16 17:41:451542 params.transition, request->IsRendererInitiated(),
Lukasz Anforowicz435bcb582019-07-12 20:50:061543 nullptr); // blob_url_loader_factory
[email protected]f8f93eb2012-09-25 03:06:241544
1545 // Find out whether the new entry needs to update its virtual URL on URL
1546 // change and set up the entry accordingly. This is needed to correctly
1547 // update the virtual URL when replaceState is called after a pushState.
1548 GURL url = params.url;
1549 bool needs_update = false;
[email protected]47752982014-07-29 08:01:431550 BrowserURLHandlerImpl::GetInstance()->RewriteURLIfNecessary(
1551 &url, browser_context_, &needs_update);
[email protected]f8f93eb2012-09-25 03:06:241552 new_entry->set_update_virtual_url_with_url(needs_update);
1553
Charlie Reisc0f17d2d2021-01-12 18:52:491554 // When navigating to a new entry, give the browser URL handler a chance to
[email protected]f1eb87a2011-05-06 17:49:411555 // update the virtual URL based on the new URL. For example, this is needed
1556 // to show chrome://bookmarks/#1 when the bookmarks webui extension changes
1557 // the URL.
[email protected]f8f93eb2012-09-25 03:06:241558 update_virtual_url = needs_update;
Camille Lamy62b826012019-02-26 09:15:471559 new_entry->GetSSL() =
Mohamed Abdelhalim833de902019-09-16 17:41:451560 SSLStatus(request->GetSSLInfo().value_or(net::SSLInfo()));
John Abd-El-Malek9cd697e2017-07-12 21:53:141561
John Abd-El-Malek380d3c5922017-09-08 00:20:311562 if (params.url.SchemeIs(url::kHttpsScheme) && !rfh->GetParent() &&
Mohamed Abdelhalim833de902019-09-16 17:41:451563 request->GetNetErrorCode() == net::OK) {
John Abd-El-Malek9cd697e2017-07-12 21:53:141564 UMA_HISTOGRAM_BOOLEAN(
1565 "Navigation.SecureSchemeHasSSLStatus.NewPageNoMatchingEntry",
1566 !!new_entry->GetSSL().certificate);
1567 }
[email protected]e9ba4472008-09-14 15:42:431568 }
1569
wjmaclean7431bb22015-02-19 14:53:431570 // Don't use the page type from the pending entry. Some interstitial page
1571 // may have set the type to interstitial. Once we commit, however, the page
1572 // type must always be normal or error.
1573 new_entry->set_page_type(params.url_is_unreachable ? PAGE_TYPE_ERROR
1574 : PAGE_TYPE_NORMAL);
[email protected]ad23a092011-12-28 07:02:041575 new_entry->SetURL(params.url);
[email protected]f1eb87a2011-05-06 17:49:411576 if (update_virtual_url)
avi25764702015-06-23 15:43:371577 UpdateVirtualURLToURL(new_entry.get(), params.url);
arthursonzogni73fe3212020-11-17 13:24:071578 new_entry->SetReferrer(Referrer(*params.referrer));
[email protected]022af742011-12-28 18:37:251579 new_entry->SetTransitionType(params.transition);
[email protected]b6583592012-01-25 19:52:331580 new_entry->set_site_instance(
[email protected]27dd82fd2014-03-03 22:11:431581 static_cast<SiteInstanceImpl*>(rfh->GetSiteInstance()));
Rakina Zata Amni6345d2f2021-02-12 04:07:571582 new_entry->SetOriginalRequestURL(request->GetOriginalRequestURL());
Rakina Zata Amnib597d632020-12-01 00:56:001583
1584 if (!is_same_document) {
1585 DCHECK_EQ(request->IsOverridingUserAgent() && !rfh->GetParent(),
1586 params.is_overriding_user_agent);
1587 } else {
1588 DCHECK_EQ(rfh->is_overriding_user_agent(), params.is_overriding_user_agent);
1589 }
[email protected]bf70edce2012-06-20 22:32:221590 new_entry->SetIsOverridingUserAgent(params.is_overriding_user_agent);
[email protected]e9ba4472008-09-14 15:42:431591
creis8b5cd4c2015-06-19 00:11:081592 // Update the FrameNavigationEntry for new main frame commits.
1593 FrameNavigationEntry* frame_entry =
1594 new_entry->GetFrameEntry(rfh->frame_tree_node());
Charles Reisd2a509f2017-09-27 23:47:481595 frame_entry->set_frame_unique_name(rfh->frame_tree_node()->unique_name());
creis8b5cd4c2015-06-19 00:11:081596 frame_entry->set_item_sequence_number(params.item_sequence_number);
1597 frame_entry->set_document_sequence_number(params.document_sequence_number);
Charles Reisf44482022017-10-13 21:15:031598 frame_entry->set_redirect_chain(params.redirects);
1599 frame_entry->SetPageState(params.page_state);
clamy432acb22016-04-15 19:41:431600 frame_entry->set_method(params.method);
1601 frame_entry->set_post_id(params.post_id);
Titouan Rigoudy6ec70402021-02-02 15:42:191602 frame_entry->set_policy_container_policies(
1603 ComputePolicyContainerPoliciesForFrameEntry(rfh, is_same_document,
1604 request));
Antonio Sartori78a749f2020-11-30 12:03:391605
Nasko Oskov03912102019-01-11 00:21:321606 if (!params.url_is_unreachable)
1607 frame_entry->set_committed_origin(params.origin);
Tsuyoshi Horob7b033e2020-03-09 15:23:311608 if (request->web_bundle_navigation_info()) {
1609 frame_entry->set_web_bundle_navigation_info(
1610 request->web_bundle_navigation_info()->Clone());
1611 }
creis8b5cd4c2015-06-19 00:11:081612
eugenebut604866f2017-05-10 21:35:361613 // history.pushState() is classified as a navigation to a new page, but sets
1614 // is_same_document to true. In this case, we already have the title and
creisf49dfc92016-07-26 17:05:181615 // favicon available, so set them immediately.
eugenebut604866f2017-05-10 21:35:361616 if (is_same_document && GetLastCommittedEntry()) {
[email protected]ff64b3e2014-05-31 04:07:331617 new_entry->SetTitle(GetLastCommittedEntry()->GetTitle());
[email protected]3a868f212014-08-09 10:41:191618 new_entry->GetFavicon() = GetLastCommittedEntry()->GetFavicon();
1619 }
[email protected]ff64b3e2014-05-31 04:07:331620
[email protected]60d6cca2013-04-30 08:47:131621 DCHECK(!params.history_list_was_cleared || !replace_entry);
1622 // The browser requested to clear the session history when it initiated the
1623 // navigation. Now we know that the renderer has updated its state accordingly
1624 // and it is safe to also clear the browser side history.
1625 if (params.history_list_was_cleared) {
arthursonzogni69a6a1b2019-09-17 09:23:001626 DiscardNonCommittedEntries();
[email protected]60d6cca2013-04-30 08:47:131627 entries_.clear();
1628 last_committed_entry_index_ = -1;
1629 }
1630
Nasko Oskovaee2f862018-06-15 00:05:521631 // If this is a new navigation with replacement and there is a
1632 // pending_entry_ which matches the navigation reported by the renderer
1633 // process, then it should be the one replaced, so update the
1634 // last_committed_entry_index_ to use it.
1635 if (replace_entry && pending_entry_index_ != -1 &&
Rakina Zata Amnif6950d552020-11-24 03:26:101636 pending_entry_->GetUniqueID() == request->commit_params().nav_entry_id) {
Nasko Oskovaee2f862018-06-15 00:05:521637 last_committed_entry_index_ = pending_entry_index_;
1638 }
1639
Alexander Timine3ec4192020-04-20 16:39:401640 SetShouldSkipOnBackForwardUIIfNeeded(
shivanigithube92c33da2020-09-14 13:01:411641 replace_entry, previous_document_was_activated,
Alexander Timine3ec4192020-04-20 16:39:401642 request->IsRendererInitiated(), request->GetPreviousPageUkmSourceId());
shivanisha41f04c52018-12-12 15:52:051643
Carlos IL42b416592019-10-07 23:10:361644 InsertOrReplaceEntry(std::move(new_entry), replace_entry,
1645 !request->post_commit_error_page_html().empty());
[email protected]e9ba4472008-09-14 15:42:431646}
1647
Charlie Reisc0f17d2d2021-01-12 18:52:491648void NavigationControllerImpl::RendererDidNavigateToExistingEntry(
creis3da03872015-02-20 21:12:321649 RenderFrameHostImpl* rfh,
arthursonzogni73fe3212020-11-17 13:24:071650 const mojom::DidCommitProvisionalLoadParams& params,
eugenebut604866f2017-05-10 21:35:361651 bool is_same_document,
jam48cea9082017-02-15 06:13:291652 bool was_restored,
Mohamed Abdelhalim833de902019-09-16 17:41:451653 NavigationRequest* request,
Peter Boströmd7592132019-01-30 04:50:311654 bool keep_pending_entry) {
creis26d22632017-04-21 20:23:561655 DCHECK(GetLastCommittedEntry()) << "ClassifyNavigation should guarantee "
1656 << "that a last committed entry exists.";
1657
[email protected]e9ba4472008-09-14 15:42:431658 // We should only get here for main frame navigations.
avi39c1edd32015-06-04 20:06:001659 DCHECK(!rfh->GetParent());
[email protected]e9ba4472008-09-14 15:42:431660
Charlie Reis7e2cb6d2021-01-26 01:27:161661 NavigationEntryImpl* entry = nullptr;
avicbdc4c12015-07-01 16:07:111662 if (params.intended_as_new_entry) {
Charlie Reis7e2cb6d2021-01-26 01:27:161663 // We're guaranteed to have a last committed entry if intended_as_new_entry
1664 // is true.
avicbdc4c12015-07-01 16:07:111665 entry = GetLastCommittedEntry();
Charlie Reis7e2cb6d2021-01-26 01:27:161666 DCHECK(entry);
1667
1668 // If the NavigationRequest matches a new pending entry and is classified as
1669 // EXISTING_ENTRY, then it is a navigation to the same URL that was
1670 // converted to a reload, such as a user pressing enter in the omnibox.
1671 if (pending_entry_ && pending_entry_index_ == -1 &&
1672 pending_entry_->GetUniqueID() ==
1673 request->commit_params().nav_entry_id) {
1674 // Note: The pending entry will usually have a real ReloadType here, but
1675 // it can still be ReloadType::NONE in cases that
1676 // ShouldTreatNavigationAsReload returns false (e.g., POST, view-source).
1677
1678 // If we classified this correctly, the SiteInstance should not have
1679 // changed.
1680 CHECK_EQ(entry->site_instance(), rfh->GetSiteInstance());
1681
1682 // For converted reloads, we assign the entry's unique ID to be that of
1683 // the new one. Since this is always the result of a user action, we want
1684 // to dismiss infobars, etc. like a regular user-initiated navigation.
1685 entry->set_unique_id(pending_entry_->GetUniqueID());
1686
1687 // The extra headers may have changed due to reloading with different
1688 // headers.
1689 entry->set_extra_headers(pending_entry_->extra_headers());
1690 }
1691 // Otherwise, this was intended as a new entry but the pending entry was
1692 // lost in the meantime and no new entry was created. We are stuck at the
1693 // last committed entry.
1694
1695 // Even if this is a converted reload from pressing enter in the omnibox,
1696 // the server could redirect, requiring an update to the SSL status. If this
1697 // is a same document navigation, though, there's no SSLStatus in the
Mohamed Abdelhalim833de902019-09-16 17:41:451698 // NavigationRequest so don't overwrite the existing entry's SSLStatus.
Charlie Reis7e2cb6d2021-01-26 01:27:161699 if (!is_same_document) {
Camille Lamy62b826012019-02-26 09:15:471700 entry->GetSSL() =
Mohamed Abdelhalim833de902019-09-16 17:41:451701 SSLStatus(request->GetSSLInfo().value_or(net::SSLInfo()));
Charlie Reis7e2cb6d2021-01-26 01:27:161702 }
John Abd-El-Malek9cd697e2017-07-12 21:53:141703
Charlie Reis7e2cb6d2021-01-26 01:27:161704 if (params.url.SchemeIs(url::kHttpsScheme) &&
Mohamed Abdelhalim833de902019-09-16 17:41:451705 request->GetNetErrorCode() == net::OK) {
John Abd-El-Malek9cd697e2017-07-12 21:53:141706 bool has_cert = !!entry->GetSSL().certificate;
1707 if (is_same_document) {
1708 UMA_HISTOGRAM_BOOLEAN(
1709 "Navigation.SecureSchemeHasSSLStatus."
1710 "ExistingPageSameDocumentIntendedAsNew",
1711 has_cert);
1712 } else {
1713 UMA_HISTOGRAM_BOOLEAN(
1714 "Navigation.SecureSchemeHasSSLStatus."
1715 "ExistingPageDifferentDocumentIntendedAsNew",
1716 has_cert);
1717 }
1718 }
Rakina Zata Amnif6950d552020-11-24 03:26:101719 } else if (const int nav_entry_id = request->commit_params().nav_entry_id) {
avicbdc4c12015-07-01 16:07:111720 // This is a browser-initiated navigation (back/forward/reload).
Rakina Zata Amnif6950d552020-11-24 03:26:101721 entry = GetEntryWithUniqueID(nav_entry_id);
jamd208b902016-09-01 16:58:161722
eugenebut604866f2017-05-10 21:35:361723 if (is_same_document) {
Mohamed Abdelhalim833de902019-09-16 17:41:451724 // There's no SSLStatus in the NavigationRequest for same document
eugenebut604866f2017-05-10 21:35:361725 // navigations, so normally we leave |entry|'s SSLStatus as is. However if
1726 // this was a restored same document navigation entry, then it won't have
1727 // an SSLStatus. So we need to copy over the SSLStatus from the entry that
1728 // navigated it.
jam48cea9082017-02-15 06:13:291729 NavigationEntryImpl* last_entry = GetLastCommittedEntry();
1730 if (entry->GetURL().GetOrigin() == last_entry->GetURL().GetOrigin() &&
1731 last_entry->GetSSL().initialized && !entry->GetSSL().initialized &&
1732 was_restored) {
1733 entry->GetSSL() = last_entry->GetSSL();
1734 }
1735 } else {
Mohamed Abdelhalim833de902019-09-16 17:41:451736 // In rapid back/forward navigations |request| sometimes won't have a cert
1737 // (http://crbug.com/727892). So we use the request's cert if it exists,
John Abd-El-Malek3f247082017-12-07 19:02:191738 // otherwise we only reuse the existing cert if the origins match.
Mohamed Abdelhalim833de902019-09-16 17:41:451739 if (request->GetSSLInfo().has_value() &&
1740 request->GetSSLInfo()->is_valid()) {
1741 entry->GetSSL() = SSLStatus(*(request->GetSSLInfo()));
1742 } else if (entry->GetURL().GetOrigin() != request->GetURL().GetOrigin()) {
John Abd-El-Malek3f247082017-12-07 19:02:191743 entry->GetSSL() = SSLStatus();
1744 }
jam48cea9082017-02-15 06:13:291745 }
John Abd-El-Malek9cd697e2017-07-12 21:53:141746
John Abd-El-Malek380d3c5922017-09-08 00:20:311747 if (params.url.SchemeIs(url::kHttpsScheme) && !rfh->GetParent() &&
Mohamed Abdelhalim833de902019-09-16 17:41:451748 request->GetNetErrorCode() == net::OK) {
John Abd-El-Malek9cd697e2017-07-12 21:53:141749 bool has_cert = !!entry->GetSSL().certificate;
1750 if (is_same_document && was_restored) {
1751 UMA_HISTOGRAM_BOOLEAN(
1752 "Navigation.SecureSchemeHasSSLStatus."
1753 "ExistingPageSameDocumentRestoredBrowserInitiated",
1754 has_cert);
1755 } else if (is_same_document && !was_restored) {
1756 UMA_HISTOGRAM_BOOLEAN(
1757 "Navigation.SecureSchemeHasSSLStatus."
1758 "ExistingPageSameDocumentBrowserInitiated",
1759 has_cert);
1760 } else if (!is_same_document && was_restored) {
1761 UMA_HISTOGRAM_BOOLEAN(
1762 "Navigation.SecureSchemeHasSSLStatus."
1763 "ExistingPageRestoredBrowserInitiated",
1764 has_cert);
1765 } else {
1766 UMA_HISTOGRAM_BOOLEAN(
1767 "Navigation.SecureSchemeHasSSLStatus.ExistingPageBrowserInitiated",
1768 has_cert);
1769 }
1770 }
avicbdc4c12015-07-01 16:07:111771 } else {
1772 // This is renderer-initiated. The only kinds of renderer-initated
Charlie Reisc0f17d2d2021-01-12 18:52:491773 // navigations that are EXISTING_ENTRY are reloads and history.replaceState,
avicbdc4c12015-07-01 16:07:111774 // which land us at the last committed entry.
1775 entry = GetLastCommittedEntry();
jam0576b132016-09-07 05:13:101776
Mikel Astizba9cf2fd2017-12-17 10:38:101777 // TODO(crbug.com/751023): Set page transition type to PAGE_TRANSITION_LINK
1778 // to avoid misleading interpretations (e.g. URLs paired with
1779 // PAGE_TRANSITION_TYPED that haven't actually been typed) as well as to fix
1780 // the inconsistency with what we report to observers (PAGE_TRANSITION_LINK
1781 // | PAGE_TRANSITION_CLIENT_REDIRECT).
1782
Lucas Furukawa Gadani5553a1582019-01-08 18:55:571783 CopyReplacedNavigationEntryDataIfPreviouslyEmpty(entry, entry);
Mikel Astizba9cf2fd2017-12-17 10:38:101784
eugenebut604866f2017-05-10 21:35:361785 // If this is a same document navigation, then there's no SSLStatus in the
Mohamed Abdelhalim833de902019-09-16 17:41:451786 // NavigationRequest so don't overwrite the existing entry's SSLStatus.
eugenebut604866f2017-05-10 21:35:361787 if (!is_same_document)
Camille Lamy62b826012019-02-26 09:15:471788 entry->GetSSL() =
Mohamed Abdelhalim833de902019-09-16 17:41:451789 SSLStatus(request->GetSSLInfo().value_or(net::SSLInfo()));
John Abd-El-Malek9cd697e2017-07-12 21:53:141790
John Abd-El-Malek380d3c5922017-09-08 00:20:311791 if (params.url.SchemeIs(url::kHttpsScheme) && !rfh->GetParent() &&
Mohamed Abdelhalim833de902019-09-16 17:41:451792 request->GetNetErrorCode() == net::OK) {
John Abd-El-Malek9cd697e2017-07-12 21:53:141793 bool has_cert = !!entry->GetSSL().certificate;
1794 if (is_same_document) {
1795 UMA_HISTOGRAM_BOOLEAN(
1796 "Navigation.SecureSchemeHasSSLStatus."
1797 "ExistingPageSameDocumentRendererInitiated",
1798 has_cert);
1799 } else {
1800 UMA_HISTOGRAM_BOOLEAN(
1801 "Navigation.SecureSchemeHasSSLStatus."
1802 "ExistingPageDifferentDocumentRendererInitiated",
1803 has_cert);
1804 }
1805 }
avicbdc4c12015-07-01 16:07:111806 }
1807 DCHECK(entry);
[email protected]e9ba4472008-09-14 15:42:431808
[email protected]5ccd4dc2012-10-24 02:28:141809 // The URL may have changed due to redirects.
wjmaclean7431bb22015-02-19 14:53:431810 entry->set_page_type(params.url_is_unreachable ? PAGE_TYPE_ERROR
1811 : PAGE_TYPE_NORMAL);
[email protected]ad23a092011-12-28 07:02:041812 entry->SetURL(params.url);
arthursonzogni73fe3212020-11-17 13:24:071813 entry->SetReferrer(Referrer(*params.referrer));
[email protected]38178a42009-12-17 18:58:321814 if (entry->update_virtual_url_with_url())
1815 UpdateVirtualURLToURL(entry, params.url);
[email protected]5ccd4dc2012-10-24 02:28:141816
jam015ba062017-01-06 21:17:001817 // The site instance will normally be the same except
1818 // 1) session restore, when no site instance will be assigned or
1819 // 2) redirect, when the site instance is reset.
Lei Zhang96031532019-10-10 19:05:471820 DCHECK(!entry->site_instance() || !entry->GetRedirectChain().empty() ||
naskoaf182192016-08-11 02:12:011821 entry->site_instance() == rfh->GetSiteInstance());
clamy432acb22016-04-15 19:41:431822
naskoaf182192016-08-11 02:12:011823 // Update the existing FrameNavigationEntry to ensure all of its members
1824 // reflect the parameters coming from the renderer process.
Lukasz Anforowicz435bcb582019-07-12 20:50:061825 const base::Optional<url::Origin>& initiator_origin =
Mohamed Abdelhalim833de902019-09-16 17:41:451826 request->common_params().initiator_origin;
naskoaf182192016-08-11 02:12:011827 entry->AddOrUpdateFrameEntry(
1828 rfh->frame_tree_node(), params.item_sequence_number,
1829 params.document_sequence_number, rfh->GetSiteInstance(), nullptr,
arthursonzogni73fe3212020-11-17 13:24:071830 params.url, GetCommittedOriginForFrameEntry(params),
1831 Referrer(*params.referrer), initiator_origin, params.redirects,
1832 params.page_state, params.method, params.post_id,
1833 nullptr /* blob_url_loader_factory */,
Tsuyoshi Horo0c605782020-05-27 00:21:031834 request->web_bundle_navigation_info()
1835 ? request->web_bundle_navigation_info()->Clone()
Antonio Sartori78a749f2020-11-30 12:03:391836 : nullptr,
Titouan Rigoudy6ec70402021-02-02 15:42:191837 ComputePolicyContainerPoliciesForFrameEntry(rfh, is_same_document,
1838 request));
creis22a7b4c2016-04-28 07:20:301839
[email protected]5ccd4dc2012-10-24 02:28:141840 // The redirected to page should not inherit the favicon from the previous
1841 // page.
eugenebut604866f2017-05-10 21:35:361842 if (ui::PageTransitionIsRedirect(params.transition) && !is_same_document)
[email protected]91a4ff82012-10-29 20:29:481843 entry->GetFavicon() = FaviconStatus();
[email protected]5ccd4dc2012-10-24 02:28:141844
Peter Boströmd7592132019-01-30 04:50:311845 // We should also usually discard the pending entry if it corresponds to a
1846 // different navigation, since that one is now likely canceled. In rare
1847 // cases, we leave the pending entry for another navigation in place when we
1848 // know it is still ongoing, to avoid a flicker in the omnibox (see
1849 // https://crbug.com/900036).
[email protected]e9ba4472008-09-14 15:42:431850 //
1851 // Note that we need to use the "internal" version since we don't want to
1852 // actually change any other state, just kill the pointer.
Peter Boströmd7592132019-01-30 04:50:311853 if (!keep_pending_entry)
arthursonzogni69a6a1b2019-09-17 09:23:001854 DiscardNonCommittedEntries();
[email protected]40bcc302009-03-02 20:50:391855
Carlos IL4dea8902020-05-26 15:14:291856 // Update the last committed index to reflect the committed entry.
avicbdc4c12015-07-01 16:07:111857 last_committed_entry_index_ = GetIndexOfEntry(entry);
[email protected]e9ba4472008-09-14 15:42:431858}
1859
[email protected]d202a7c2012-01-04 07:53:471860void NavigationControllerImpl::RendererDidNavigateNewSubframe(
creis3da03872015-02-20 21:12:321861 RenderFrameHostImpl* rfh,
arthursonzogni73fe3212020-11-17 13:24:071862 const mojom::DidCommitProvisionalLoadParams& params,
eugenebut604866f2017-05-10 21:35:361863 bool is_same_document,
Shivani Sharmaffb32b82019-04-09 16:58:471864 bool replace_entry,
1865 bool previous_document_was_activated,
Mohamed Abdelhalim833de902019-09-16 17:41:451866 NavigationRequest* request) {
avi25f5f9e2015-07-17 20:08:261867 DCHECK(ui::PageTransitionCoreTypeIs(params.transition,
1868 ui::PAGE_TRANSITION_MANUAL_SUBFRAME));
[email protected]09b8f82f2009-06-16 20:22:111869
[email protected]e9ba4472008-09-14 15:42:431870 // Manual subframe navigations just get the current entry cloned so the user
1871 // can go back or forward to it. The actual subframe information will be
1872 // stored in the page state for each of those entries. This happens out of
1873 // band with the actual navigations.
[email protected]4c27ba82008-09-24 16:49:091874 DCHECK(GetLastCommittedEntry()) << "ClassifyNavigation should guarantee "
1875 << "that a last committed entry exists.";
creis96fc55082015-06-13 06:42:381876
Mikel Astizba9cf2fd2017-12-17 10:38:101877 // The DCHECK below documents the fact that we don't know of any situation
1878 // where |replace_entry| is true for subframe navigations. This simplifies
1879 // reasoning about the replacement struct for subframes (see
1880 // CopyReplacedNavigationEntryDataIfPreviouslyEmpty()).
1881 DCHECK(!replace_entry);
1882
Patrick Monette50e8bd82019-06-13 22:40:451883 // This FrameNavigationEntry might not end up being used in the
1884 // CloneAndReplace() call below, if a spot can't be found for it in the tree.
Lukasz Anforowicz435bcb582019-07-12 20:50:061885 const base::Optional<url::Origin>& initiator_origin =
Mohamed Abdelhalim833de902019-09-16 17:41:451886 request->common_params().initiator_origin;
Patrick Monette50e8bd82019-06-13 22:40:451887 auto frame_entry = base::MakeRefCounted<FrameNavigationEntry>(
Charles Reisd2a509f2017-09-27 23:47:481888 rfh->frame_tree_node()->unique_name(), params.item_sequence_number,
creisce0ef3572017-01-26 17:53:081889 params.document_sequence_number, rfh->GetSiteInstance(), nullptr,
Nasko Oskov03912102019-01-11 00:21:321890 params.url, (params.url_is_unreachable) ? nullptr : &params.origin,
arthursonzogni73fe3212020-11-17 13:24:071891 Referrer(*params.referrer), initiator_origin, params.redirects,
1892 params.page_state, params.method, params.post_id,
1893 nullptr /* blob_url_loader_factory */,
Tsuyoshi Horo0c605782020-05-27 00:21:031894 request->web_bundle_navigation_info()
1895 ? request->web_bundle_navigation_info()->Clone()
Antonio Sartori78a749f2020-11-30 12:03:391896 : nullptr,
Titouan Rigoudy6ec70402021-02-02 15:42:191897 ComputePolicyContainerPoliciesForFrameEntry(rfh, is_same_document,
1898 request));
Charles Reisf44482022017-10-13 21:15:031899
creisce0ef3572017-01-26 17:53:081900 std::unique_ptr<NavigationEntryImpl> new_entry =
1901 GetLastCommittedEntry()->CloneAndReplace(
Patrick Monette50e8bd82019-06-13 22:40:451902 std::move(frame_entry), is_same_document, rfh->frame_tree_node(),
Carlos Caballero40b0efd2021-01-26 11:55:001903 frame_tree_.root());
creise062d542015-08-25 02:01:551904
Alexander Timine3ec4192020-04-20 16:39:401905 SetShouldSkipOnBackForwardUIIfNeeded(
shivanigithube92c33da2020-09-14 13:01:411906 replace_entry, previous_document_was_activated,
Alexander Timine3ec4192020-04-20 16:39:401907 request->IsRendererInitiated(), request->GetPreviousPageUkmSourceId());
Shivani Sharmaffb32b82019-04-09 16:58:471908
creisce0ef3572017-01-26 17:53:081909 // TODO(creis): Update this to add the frame_entry if we can't find the one
Patrick Monette50e8bd82019-06-13 22:40:451910 // to replace, which can happen due to a unique name change. See
1911 // https://crbug.com/607205. For now, the call to CloneAndReplace() will
1912 // delete the |frame_entry| when the function exits if it doesn't get used.
creis96fc55082015-06-13 06:42:381913
Carlos IL42b416592019-10-07 23:10:361914 InsertOrReplaceEntry(std::move(new_entry), replace_entry, false);
[email protected]e9ba4472008-09-14 15:42:431915}
1916
[email protected]d202a7c2012-01-04 07:53:471917bool NavigationControllerImpl::RendererDidNavigateAutoSubframe(
creis3da03872015-02-20 21:12:321918 RenderFrameHostImpl* rfh,
arthursonzogni73fe3212020-11-17 13:24:071919 const mojom::DidCommitProvisionalLoadParams& params,
Antonio Sartori78a749f2020-11-30 12:03:391920 bool is_same_document,
Mohamed Abdelhalim833de902019-09-16 17:41:451921 NavigationRequest* request) {
avi9f07a0c2015-02-18 22:51:291922 DCHECK(ui::PageTransitionCoreTypeIs(params.transition,
1923 ui::PAGE_TRANSITION_AUTO_SUBFRAME));
1924
[email protected]e9ba4472008-09-14 15:42:431925 // We're guaranteed to have a previously committed entry, and we now need to
1926 // handle navigation inside of a subframe in it without creating a new entry.
1927 DCHECK(GetLastCommittedEntry());
1928
creis913c63ce2016-07-16 19:52:521929 // For newly created subframes, we don't need to send a commit notification.
1930 // This is only necessary for history navigations in subframes.
1931 bool send_commit_notification = false;
1932
Rakina Zata Amnif6950d552020-11-24 03:26:101933 // If |nav_entry_id| is non-zero and matches an existing entry, this
1934 // is a history navigation. Update the last committed index accordingly. If
1935 // we don't recognize the |nav_entry_id|, it might be a recently
1936 // pruned entry. We'll handle it below.
1937 if (const int nav_entry_id = request->commit_params().nav_entry_id) {
1938 int entry_index = GetEntryIndexWithUniqueID(nav_entry_id);
creis3cdc3b02015-05-29 23:00:471939 if (entry_index != -1 && entry_index != last_committed_entry_index_) {
avi98405c22015-05-21 20:47:061940 // Make sure that a subframe commit isn't changing the main frame's
1941 // origin. Otherwise the renderer process may be confused, leading to a
1942 // URL spoof. We can't check the path since that may change
1943 // (https://crbug.com/373041).
creis37988b92016-06-10 18:03:571944 // TODO(creis): For now, restrict this check to HTTP(S) origins, because
1945 // about:blank, file, and unique origins are more subtle to get right.
Eugene But9fb98d12018-05-22 18:28:331946 // We'll abstract out the relevant checks from IsURLSameDocumentNavigation
1947 // and share them here. See https://crbug.com/618104.
creis37988b92016-06-10 18:03:571948 const GURL& dest_top_url = GetEntryAtIndex(entry_index)->GetURL();
1949 const GURL& current_top_url = GetLastCommittedEntry()->GetURL();
1950 if (current_top_url.SchemeIsHTTPOrHTTPS() &&
1951 dest_top_url.SchemeIsHTTPOrHTTPS() &&
1952 current_top_url.GetOrigin() != dest_top_url.GetOrigin()) {
creisfb6eeb62016-05-10 19:01:511953 bad_message::ReceivedBadMessage(rfh->GetProcess(),
1954 bad_message::NC_AUTO_SUBFRAME);
avi98405c22015-05-21 20:47:061955 }
creis3cdc3b02015-05-29 23:00:471956
creis913c63ce2016-07-16 19:52:521957 // We only need to discard the pending entry in this history navigation
1958 // case. For newly created subframes, there was no pending entry.
avi98405c22015-05-21 20:47:061959 last_committed_entry_index_ = entry_index;
arthursonzogni69a6a1b2019-09-17 09:23:001960 DiscardNonCommittedEntries();
creis913c63ce2016-07-16 19:52:521961
1962 // History navigations should send a commit notification.
1963 send_commit_notification = true;
avi98405c22015-05-21 20:47:061964 }
[email protected]e9ba4472008-09-14 15:42:431965 }
[email protected]f233e4232013-02-23 00:55:141966
creisce0ef3572017-01-26 17:53:081967 // This may be a "new auto" case where we add a new FrameNavigationEntry, or
1968 // it may be a "history auto" case where we update an existing one.
1969 NavigationEntryImpl* last_committed = GetLastCommittedEntry();
Lukasz Anforowicz435bcb582019-07-12 20:50:061970 const base::Optional<url::Origin>& initiator_origin =
Mohamed Abdelhalim833de902019-09-16 17:41:451971 request->common_params().initiator_origin;
creisce0ef3572017-01-26 17:53:081972 last_committed->AddOrUpdateFrameEntry(
1973 rfh->frame_tree_node(), params.item_sequence_number,
1974 params.document_sequence_number, rfh->GetSiteInstance(), nullptr,
arthursonzogni73fe3212020-11-17 13:24:071975 params.url, GetCommittedOriginForFrameEntry(params),
1976 Referrer(*params.referrer), initiator_origin, params.redirects,
1977 params.page_state, params.method, params.post_id,
1978 nullptr /* blob_url_loader_factory */,
Tsuyoshi Horo0c605782020-05-27 00:21:031979 request->web_bundle_navigation_info()
1980 ? request->web_bundle_navigation_info()->Clone()
Antonio Sartori78a749f2020-11-30 12:03:391981 : nullptr,
Titouan Rigoudy6ec70402021-02-02 15:42:191982 ComputePolicyContainerPoliciesForFrameEntry(rfh, is_same_document,
1983 request));
creis625a0c7d2015-03-24 23:17:121984
creis913c63ce2016-07-16 19:52:521985 return send_commit_notification;
[email protected]e9ba4472008-09-14 15:42:431986}
1987
[email protected]d202a7c2012-01-04 07:53:471988int NavigationControllerImpl::GetIndexOfEntry(
[email protected]10f417c52011-12-28 21:04:231989 const NavigationEntryImpl* entry) const {
avif16f85a72015-11-13 18:25:031990 for (size_t i = 0; i < entries_.size(); ++i) {
1991 if (entries_[i].get() == entry)
1992 return i;
1993 }
1994 return -1;
[email protected]765b35502008-08-21 00:51:201995}
1996
Eugene But7cc259d2017-10-09 23:52:491997// There are two general cases where a navigation is "same-document":
avidb7d1d22015-06-08 21:21:501998// 1. A fragment navigation, in which the url is kept the same except for the
1999// reference fragment.
2000// 2. A history API navigation (pushState and replaceState). This case is
Eugene But7cc259d2017-10-09 23:52:492001// always same-document, but the urls are not guaranteed to match excluding
2002// the fragment. The relevant spec allows pushState/replaceState to any URL
2003// on the same origin.
avidb7d1d22015-06-08 21:21:502004// However, due to reloads, even identical urls are *not* guaranteed to be
Eugene But7cc259d2017-10-09 23:52:492005// same-document navigations, we have to trust the renderer almost entirely.
avidb7d1d22015-06-08 21:21:502006// The one thing we do know is that cross-origin navigations will *never* be
Eugene But7cc259d2017-10-09 23:52:492007// same-document. Therefore, trust the renderer if the URLs are on the same
2008// origin, and assume the renderer is malicious if a cross-origin navigation
2009// claims to be same-document.
creisf164daa2016-06-07 00:17:052010//
2011// TODO(creis): Clean up and simplify the about:blank and origin checks below,
2012// which are likely redundant with each other. Be careful about data URLs vs
2013// about:blank, both of which are unique origins and thus not considered equal.
Eugene But7cc259d2017-10-09 23:52:492014bool NavigationControllerImpl::IsURLSameDocumentNavigation(
[email protected]b9d4dfdc2013-08-08 00:25:122015 const GURL& url,
creisf164daa2016-06-07 00:17:052016 const url::Origin& origin,
Eugene But7cc259d2017-10-09 23:52:492017 bool renderer_says_same_document,
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572018 RenderFrameHost* rfh) {
creis225a7432016-06-03 22:56:272019 RenderFrameHostImpl* rfhi = static_cast<RenderFrameHostImpl*>(rfh);
avidb7d1d22015-06-08 21:21:502020 GURL last_committed_url;
2021 if (rfh->GetParent()) {
creis225a7432016-06-03 22:56:272022 // Use the FrameTreeNode's current_url and not rfh->GetLastCommittedURL(),
2023 // which might be empty in a new RenderFrameHost after a process swap.
2024 // Here, we care about the last committed URL in the FrameTreeNode,
2025 // regardless of which process it is in.
2026 last_committed_url = rfhi->frame_tree_node()->current_url();
avidb7d1d22015-06-08 21:21:502027 } else {
2028 NavigationEntry* last_committed = GetLastCommittedEntry();
2029 // There must be a last-committed entry to compare URLs to. TODO(avi): When
2030 // might Blink say that a navigation is in-page yet there be no last-
2031 // committed entry?
2032 if (!last_committed)
2033 return false;
2034 last_committed_url = last_committed->GetURL();
2035 }
2036
Gyuyoung Kim1ac4ca782020-09-11 03:32:512037 auto prefs = rfhi->GetOrCreateWebPreferences();
creis225a7432016-06-03 22:56:272038 const url::Origin& committed_origin =
2039 rfhi->frame_tree_node()->current_origin();
avidb7d1d22015-06-08 21:21:502040 bool is_same_origin = last_committed_url.is_empty() ||
2041 // TODO(japhet): We should only permit navigations
2042 // originating from about:blank to be in-page if the
2043 // about:blank is the first document that frame loaded.
2044 // We don't have sufficient information to identify
2045 // that case at the moment, so always allow about:blank
2046 // for now.
csharrisona3bd0b32016-10-19 18:40:482047 last_committed_url == url::kAboutBlankURL ||
avidb7d1d22015-06-08 21:21:502048 last_committed_url.GetOrigin() == url.GetOrigin() ||
creisf164daa2016-06-07 00:17:052049 committed_origin == origin ||
avidb7d1d22015-06-08 21:21:502050 !prefs.web_security_enabled ||
2051 (prefs.allow_universal_access_from_file_urls &&
creisdc004e02015-11-20 21:28:472052 committed_origin.scheme() == url::kFileScheme);
Eugene But7cc259d2017-10-09 23:52:492053 if (!is_same_origin && renderer_says_same_document) {
avidb7d1d22015-06-08 21:21:502054 bad_message::ReceivedBadMessage(rfh->GetProcess(),
2055 bad_message::NC_IN_PAGE_NAVIGATION);
2056 }
Eugene But7cc259d2017-10-09 23:52:492057 return is_same_origin && renderer_says_same_document;
[email protected]e9ba4472008-09-14 15:42:432058}
2059
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572060void NavigationControllerImpl::CopyStateFrom(NavigationController* temp,
Francois Dorayeaace782017-06-21 16:37:242061 bool needs_reload) {
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572062 NavigationControllerImpl* source =
2063 static_cast<NavigationControllerImpl*>(temp);
[email protected]ce3fa3c2009-04-20 19:55:572064 // Verify that we look new.
Lei Zhang96031532019-10-10 19:05:472065 DCHECK_EQ(0, GetEntryCount());
2066 DCHECK(!GetPendingEntry());
[email protected]ce3fa3c2009-04-20 19:55:572067
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572068 if (source->GetEntryCount() == 0)
[email protected]ce3fa3c2009-04-20 19:55:572069 return; // Nothing new to do.
2070
Francois Dorayeaace782017-06-21 16:37:242071 needs_reload_ = needs_reload;
Bo Liucdfa4b12018-11-06 00:21:442072 needs_reload_type_ = NeedsReloadType::kCopyStateFrom;
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572073 InsertEntriesFrom(source, source->GetEntryCount());
[email protected]ce3fa3c2009-04-20 19:55:572074
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572075 for (auto it = source->session_storage_namespace_map_.begin();
2076 it != source->session_storage_namespace_map_.end(); ++it) {
[email protected]fdac6ade2013-07-20 01:06:302077 SessionStorageNamespaceImpl* source_namespace =
2078 static_cast<SessionStorageNamespaceImpl*>(it->second.get());
2079 session_storage_namespace_map_[it->first] = source_namespace->Clone();
2080 }
[email protected]4e6419c2010-01-15 04:50:342081
Lukasz Anforowicz0de0f452020-12-02 19:57:152082 FinishRestore(source->last_committed_entry_index_, RestoreType::kRestored);
[email protected]ce3fa3c2009-04-20 19:55:572083}
2084
Aran Gilman37d11632019-10-08 23:07:152085void NavigationControllerImpl::CopyStateFromAndPrune(NavigationController* temp,
2086 bool replace_entry) {
[email protected]474f8512013-05-31 22:31:162087 // It is up to callers to check the invariants before calling this.
[email protected]79368982013-11-13 01:11:012088 CHECK(CanPruneAllButLastCommitted());
[email protected]474f8512013-05-31 22:31:162089
[email protected]d202a7c2012-01-04 07:53:472090 NavigationControllerImpl* source =
2091 static_cast<NavigationControllerImpl*>(temp);
[email protected]e1cd5452010-08-26 18:03:252092
avi2b177592014-12-10 02:08:022093 // Remove all the entries leaving the last committed entry.
[email protected]79368982013-11-13 01:11:012094 PruneAllButLastCommittedInternal();
[email protected]e1cd5452010-08-26 18:03:252095
[email protected]474f8512013-05-31 22:31:162096 // We now have one entry, possibly with a new pending entry. Ensure that
2097 // adding the entries from source won't put us over the limit.
2098 DCHECK_EQ(1, GetEntryCount());
[email protected]e78a6852013-12-13 08:08:572099 if (!replace_entry)
Shivani Sharmad8c8d652019-02-13 17:27:572100 source->PruneOldestSkippableEntryIfFull();
[email protected]944822b2012-03-02 20:57:252101
Carlos IL4dea8902020-05-26 15:14:292102 // Insert the entries from source. Ignore any pending entry, since it has not
2103 // committed in source.
[email protected]474f8512013-05-31 22:31:162104 int max_source_index = source->last_committed_entry_index_;
[email protected]e1cd5452010-08-26 18:03:252105 if (max_source_index == -1)
[email protected]a26023822011-12-29 00:23:552106 max_source_index = source->GetEntryCount();
[email protected]e1cd5452010-08-26 18:03:252107 else
2108 max_source_index++;
[email protected]e78a6852013-12-13 08:08:572109
2110 // Ignore the source's current entry if merging with replacement.
2111 // TODO(davidben): This should preserve entries forward of the current
2112 // too. http://crbug.com/317872
2113 if (replace_entry && max_source_index > 0)
2114 max_source_index--;
2115
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572116 InsertEntriesFrom(source, max_source_index);
[email protected]e1cd5452010-08-26 18:03:252117
2118 // Adjust indices such that the last entry and pending are at the end now.
[email protected]a26023822011-12-29 00:23:552119 last_committed_entry_index_ = GetEntryCount() - 1;
[email protected]796931a92011-08-10 01:32:142120
Carlos Caballeroede6f8c2021-01-28 11:01:502121 SetHistoryOffsetAndLength(last_committed_entry_index_, GetEntryCount());
[email protected]e1cd5452010-08-26 18:03:252122}
2123
[email protected]79368982013-11-13 01:11:012124bool NavigationControllerImpl::CanPruneAllButLastCommitted() {
[email protected]474f8512013-05-31 22:31:162125 // If there is no last committed entry, we cannot prune. Even if there is a
2126 // pending entry, it may not commit, leaving this WebContents blank, despite
2127 // possibly giving it new entries via CopyStateFromAndPrune.
2128 if (last_committed_entry_index_ == -1)
2129 return false;
[email protected]9350602e2013-02-26 23:27:442130
[email protected]474f8512013-05-31 22:31:162131 // We cannot prune if there is a pending entry at an existing entry index.
2132 // It may not commit, so we have to keep the last committed entry, and thus
2133 // there is no sensible place to keep the pending entry. It is ok to have
2134 // a new pending entry, which can optionally commit as a new navigation.
2135 if (pending_entry_index_ != -1)
2136 return false;
2137
[email protected]474f8512013-05-31 22:31:162138 return true;
2139}
2140
[email protected]79368982013-11-13 01:11:012141void NavigationControllerImpl::PruneAllButLastCommitted() {
2142 PruneAllButLastCommittedInternal();
[email protected]474f8512013-05-31 22:31:162143
avi2b177592014-12-10 02:08:022144 DCHECK_EQ(0, last_committed_entry_index_);
2145 DCHECK_EQ(1, GetEntryCount());
[email protected]9350602e2013-02-26 23:27:442146
Carlos Caballeroede6f8c2021-01-28 11:01:502147 SetHistoryOffsetAndLength(last_committed_entry_index_, GetEntryCount());
[email protected]9350602e2013-02-26 23:27:442148}
2149
[email protected]79368982013-11-13 01:11:012150void NavigationControllerImpl::PruneAllButLastCommittedInternal() {
[email protected]474f8512013-05-31 22:31:162151 // It is up to callers to check the invariants before calling this.
[email protected]79368982013-11-13 01:11:012152 CHECK(CanPruneAllButLastCommitted());
[email protected]97b6c4f2010-09-27 19:31:262153
[email protected]474f8512013-05-31 22:31:162154 // Erase all entries but the last committed entry. There may still be a
2155 // new pending entry after this.
2156 entries_.erase(entries_.begin(),
2157 entries_.begin() + last_committed_entry_index_);
2158 entries_.erase(entries_.begin() + 1, entries_.end());
2159 last_committed_entry_index_ = 0;
[email protected]97b6c4f2010-09-27 19:31:262160}
2161
Christian Dullweber1af31e62018-02-22 11:49:482162void NavigationControllerImpl::DeleteNavigationEntries(
2163 const DeletionPredicate& deletionPredicate) {
2164 // It is up to callers to check the invariants before calling this.
2165 CHECK(CanPruneAllButLastCommitted());
2166 std::vector<int> delete_indices;
2167 for (size_t i = 0; i < entries_.size(); i++) {
2168 if (i != static_cast<size_t>(last_committed_entry_index_) &&
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572169 deletionPredicate.Run(entries_[i].get())) {
Christian Dullweber1af31e62018-02-22 11:49:482170 delete_indices.push_back(i);
2171 }
2172 }
2173 if (delete_indices.empty())
2174 return;
2175
2176 if (delete_indices.size() == GetEntryCount() - 1U) {
2177 PruneAllButLastCommitted();
2178 } else {
2179 // Do the deletion in reverse to preserve indices.
2180 for (auto it = delete_indices.rbegin(); it != delete_indices.rend(); ++it) {
2181 RemoveEntryAtIndex(*it);
2182 }
Carlos Caballeroede6f8c2021-01-28 11:01:502183 SetHistoryOffsetAndLength(last_committed_entry_index_, GetEntryCount());
Christian Dullweber1af31e62018-02-22 11:49:482184 }
2185 delegate()->NotifyNavigationEntriesDeleted();
2186}
2187
Shivani Sharma883f5f32019-02-12 18:20:012188bool NavigationControllerImpl::IsEntryMarkedToBeSkipped(int index) {
2189 auto* entry = GetEntryAtIndex(index);
2190 return entry && entry->should_skip_on_back_forward_ui();
2191}
2192
Carlos Caballero35ce710c2019-09-19 10:59:452193BackForwardCacheImpl& NavigationControllerImpl::GetBackForwardCache() {
2194 return back_forward_cache_;
2195}
2196
clamy987a3752018-05-03 17:36:262197void NavigationControllerImpl::DiscardPendingEntry(bool was_failure) {
2198 // It is not safe to call DiscardPendingEntry while NavigateToEntry is in
2199 // progress, since this will cause a use-after-free. (We only allow this
2200 // when the tab is being destroyed for shutdown, since it won't return to
2201 // NavigateToEntry in that case.) http://crbug.com/347742.
2202 CHECK(!in_navigate_to_pending_entry_ || delegate_->IsBeingDestroyed());
2203
2204 if (was_failure && pending_entry_) {
2205 failed_pending_entry_id_ = pending_entry_->GetUniqueID();
2206 } else {
2207 failed_pending_entry_id_ = 0;
2208 }
2209
2210 if (pending_entry_) {
2211 if (pending_entry_index_ == -1)
2212 delete pending_entry_;
2213 pending_entry_index_ = -1;
2214 pending_entry_ = nullptr;
2215 }
arthursonzogni66f711c2019-10-08 14:40:362216
2217 // Ensure any refs to the current pending entry are ignored if they get
2218 // deleted, by clearing the set of known refs. All future pending entries will
2219 // only be affected by new refs.
2220 pending_entry_refs_.clear();
clamy987a3752018-05-03 17:36:262221}
2222
2223void NavigationControllerImpl::SetPendingNavigationSSLError(bool error) {
2224 if (pending_entry_)
2225 pending_entry_->set_ssl_error(error);
2226}
2227
Camille Lamy5193caa2018-10-12 11:59:422228#if defined(OS_ANDROID)
2229// static
2230bool NavigationControllerImpl::ValidateDataURLAsString(
2231 const scoped_refptr<const base::RefCountedString>& data_url_as_string) {
2232 if (!data_url_as_string)
2233 return false;
2234
2235 if (data_url_as_string->size() > kMaxLengthOfDataURLString)
2236 return false;
2237
2238 // The number of characters that is enough for validating a data: URI.
2239 // From the GURL's POV, the only important part here is scheme, it doesn't
2240 // check the actual content. Thus we can take only the prefix of the url, to
2241 // avoid unneeded copying of a potentially long string.
2242 const size_t kDataUriPrefixMaxLen = 64;
2243 GURL data_url(
2244 std::string(data_url_as_string->front_as<char>(),
2245 std::min(data_url_as_string->size(), kDataUriPrefixMaxLen)));
2246 if (!data_url.is_valid() || !data_url.SchemeIs(url::kDataScheme))
2247 return false;
2248
2249 return true;
2250}
2251#endif
2252
Shivani Sharma194877032019-03-07 17:52:472253void NavigationControllerImpl::NotifyUserActivation() {
2254 // When a user activation occurs, ensure that all adjacent entries for the
2255 // same document clear their skippable bit, so that the history manipulation
2256 // intervention does not apply to them.
Shivani Sharmaffb32b82019-04-09 16:58:472257 // TODO(crbug.com/949279) in case it becomes necessary for resetting based on
2258 // which frame created an entry and which frame has the user gesture.
Shivani Sharma194877032019-03-07 17:52:472259 auto* last_committed_entry = GetLastCommittedEntry();
2260 if (!last_committed_entry)
2261 return;
Shivani Sharma194877032019-03-07 17:52:472262
Shivani Sharmac4cc8922019-04-18 03:11:172263 SetSkippableForSameDocumentEntries(GetLastCommittedEntryIndex(), false);
Shivani Sharma194877032019-03-07 17:52:472264}
2265
clamy987a3752018-05-03 17:36:262266bool NavigationControllerImpl::StartHistoryNavigationInNewSubframe(
2267 RenderFrameHostImpl* render_frame_host,
Julie Jeongeun Kimed2e5ba72019-09-12 10:14:172268 mojo::PendingAssociatedRemote<mojom::NavigationClient>* navigation_client) {
clamy987a3752018-05-03 17:36:262269 NavigationEntryImpl* entry =
2270 GetEntryWithUniqueID(render_frame_host->nav_entry_id());
2271 if (!entry)
2272 return false;
2273
2274 FrameNavigationEntry* frame_entry =
2275 entry->GetFrameEntry(render_frame_host->frame_tree_node());
2276 if (!frame_entry)
2277 return false;
2278
Camille Lamy5193caa2018-10-12 11:59:422279 std::unique_ptr<NavigationRequest> request = CreateNavigationRequestFromEntry(
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572280 render_frame_host->frame_tree_node(), entry, frame_entry,
clamyea99ea12018-05-28 13:54:232281 ReloadType::NONE, false /* is_same_document_history_load */,
Camille Lamy5193caa2018-10-12 11:59:422282 true /* is_history_navigation_in_new_child */);
clamyea99ea12018-05-28 13:54:232283
2284 if (!request)
2285 return false;
2286
arthursonzognif046d4a2019-12-12 19:08:102287 request->SetNavigationClient(std::move(*navigation_client));
Arthur Hemery06173ce2019-05-29 12:11:412288
Lukasz Anforowicz9ee83c272020-12-01 20:14:052289 render_frame_host->frame_tree_node()->navigator().Navigate(std::move(request),
2290 ReloadType::NONE);
clamyea99ea12018-05-28 13:54:232291
2292 return true;
clamy987a3752018-05-03 17:36:262293}
2294
Tsuyoshi Horo52fd08e2020-07-07 07:03:452295bool NavigationControllerImpl::ReloadFrame(FrameTreeNode* frame_tree_node) {
2296 NavigationEntryImpl* entry = GetEntryAtIndex(GetCurrentEntryIndex());
2297 if (!entry)
2298 return false;
2299 FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame_tree_node);
2300 if (!frame_entry)
2301 return false;
John Abd-El-Malek5b669132020-07-14 01:04:142302 ReloadType reload_type = ReloadType::NORMAL;
2303 entry->set_reload_type(reload_type);
Tsuyoshi Horo52fd08e2020-07-07 07:03:452304 std::unique_ptr<NavigationRequest> request = CreateNavigationRequestFromEntry(
John Abd-El-Malek5b669132020-07-14 01:04:142305 frame_tree_node, entry, frame_entry, reload_type,
Tsuyoshi Horo52fd08e2020-07-07 07:03:452306 false /* is_same_document_history_load */,
2307 false /* is_history_navigation_in_new_child */);
2308 if (!request)
2309 return false;
Lukasz Anforowicz9ee83c272020-12-01 20:14:052310 frame_tree_node->navigator().Navigate(std::move(request), reload_type);
Tsuyoshi Horo52fd08e2020-07-07 07:03:452311 return true;
2312}
2313
Dave Tapuska8bfd84c2019-03-26 20:47:162314void NavigationControllerImpl::GoToOffsetInSandboxedFrame(
2315 int offset,
2316 int sandbox_frame_tree_node_id) {
2317 if (!CanGoToOffset(offset))
2318 return;
2319 GoToIndex(GetIndexForOffset(offset), sandbox_frame_tree_node_id);
2320}
2321
clamy987a3752018-05-03 17:36:262322void NavigationControllerImpl::NavigateFromFrameProxy(
2323 RenderFrameHostImpl* render_frame_host,
2324 const GURL& url,
Chris Hamilton83272dc2021-02-23 00:24:022325 const blink::LocalFrameToken* initiator_frame_token,
Antonio Sartori9a82f6f32020-12-14 09:22:452326 int initiator_process_id,
Lukasz Anforowicz63f3b9432019-05-30 05:42:582327 const base::Optional<url::Origin>& initiator_origin,
clamy987a3752018-05-03 17:36:262328 bool is_renderer_initiated,
2329 SiteInstance* source_site_instance,
2330 const Referrer& referrer,
2331 ui::PageTransition page_transition,
2332 bool should_replace_current_entry,
Yeunjoo Choi3df791a2021-02-17 07:07:252333 blink::NavigationDownloadPolicy download_policy,
clamy987a3752018-05-03 17:36:262334 const std::string& method,
2335 scoped_refptr<network::ResourceRequestBody> post_body,
Marijn Kruisselbrink7a0d5e182018-05-24 22:55:092336 const std::string& extra_headers,
John Delaney50425f82020-04-07 16:26:212337 scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory,
Gyuyoung Kim38e63632021-01-14 13:11:392338 const base::Optional<blink::Impression>& impression) {
Lukasz Anforowicz63f3b9432019-05-30 05:42:582339 if (is_renderer_initiated)
2340 DCHECK(initiator_origin.has_value());
2341
clamy987a3752018-05-03 17:36:262342 FrameTreeNode* node = render_frame_host->frame_tree_node();
Nasko Oskov18006bc2018-12-06 02:53:582343
Rakina Zata Amni66992a82020-06-24 03:57:522344 // Don't allow an entry replacement if there is no entry to replace.
2345 // http://crbug.com/457149
2346 if (GetEntryCount() == 0)
2347 should_replace_current_entry = false;
2348
clamy987a3752018-05-03 17:36:262349 // Create a NavigationEntry for the transfer, without making it the pending
2350 // entry. Subframe transfers should have a clone of the last committed entry
2351 // with a FrameNavigationEntry for the target frame. Main frame transfers
2352 // should have a new NavigationEntry.
2353 // TODO(creis): Make this unnecessary by creating (and validating) the params
2354 // directly, passing them to the destination RenderFrameHost. See
2355 // https://crbug.com/536906.
2356 std::unique_ptr<NavigationEntryImpl> entry;
2357 if (!node->IsMainFrame()) {
2358 // Subframe case: create FrameNavigationEntry.
2359 if (GetLastCommittedEntry()) {
2360 entry = GetLastCommittedEntry()->Clone();
2361 entry->set_extra_headers(extra_headers);
2362 // TODO(arthursonzogni): What about |is_renderer_initiated|?
2363 // Renderer-initiated navigation that target a remote frame are currently
2364 // classified as browser-initiated when this one has already navigated.
2365 // See https://crbug.com/722251.
2366 } else {
2367 // If there's no last committed entry, create an entry for about:blank
2368 // with a subframe entry for our destination.
2369 // TODO(creis): Ensure this case can't exist in https://crbug.com/524208.
2370 entry = NavigationEntryImpl::FromNavigationEntry(CreateNavigationEntry(
Lukasz Anforowicz435bcb582019-07-12 20:50:062371 GURL(url::kAboutBlankURL), referrer, initiator_origin,
Lukasz Anforowicz641234d52019-11-07 21:07:102372 source_site_instance, page_transition, is_renderer_initiated,
2373 extra_headers, browser_context_,
Scott Violet5ae6c42e2020-10-28 02:47:372374 nullptr /* blob_url_loader_factory */, should_replace_current_entry,
2375 GetWebContents()));
2376 // CreateNavigationEntry() may have changed the transition type.
2377 page_transition = entry->GetTransitionType();
clamy987a3752018-05-03 17:36:262378 }
clamy987a3752018-05-03 17:36:262379 entry->AddOrUpdateFrameEntry(
2380 node, -1, -1, nullptr,
Nasko Oskov18006bc2018-12-06 02:53:582381 static_cast<SiteInstanceImpl*>(source_site_instance), url,
Lukasz Anforowicz435bcb582019-07-12 20:50:062382 base::nullopt /* commit_origin */, referrer, initiator_origin,
Miyoung Shin5d77f72072020-10-09 15:14:202383 std::vector<GURL>(), blink::PageState(), method, -1,
Antonio Sartori78a749f2020-11-30 12:03:392384 blob_url_loader_factory, nullptr /* web_bundle_navigation_info */,
Antonio Sartori79d549d2021-02-18 12:59:542385 nullptr /* policy_container_policies */);
clamy987a3752018-05-03 17:36:262386 } else {
2387 // Main frame case.
2388 entry = NavigationEntryImpl::FromNavigationEntry(CreateNavigationEntry(
Lukasz Anforowicz641234d52019-11-07 21:07:102389 url, referrer, initiator_origin, source_site_instance, page_transition,
2390 is_renderer_initiated, extra_headers, browser_context_,
Scott Violet5ae6c42e2020-10-28 02:47:372391 blob_url_loader_factory, should_replace_current_entry,
2392 GetWebContents()));
2393 // CreateNavigationEntry() may have changed the transition type.
2394 page_transition = entry->GetTransitionType();
clamy987a3752018-05-03 17:36:262395 entry->root_node()->frame_entry->set_source_site_instance(
2396 static_cast<SiteInstanceImpl*>(source_site_instance));
2397 entry->root_node()->frame_entry->set_method(method);
2398 }
clamy987a3752018-05-03 17:36:262399
Camille Lamy5193caa2018-10-12 11:59:422400 bool override_user_agent = false;
clamy987a3752018-05-03 17:36:262401 if (GetLastCommittedEntry() &&
2402 GetLastCommittedEntry()->GetIsOverridingUserAgent()) {
2403 entry->SetIsOverridingUserAgent(true);
Camille Lamy5193caa2018-10-12 11:59:422404 override_user_agent = true;
clamy987a3752018-05-03 17:36:262405 }
2406 // TODO(creis): Set user gesture and intent received timestamp on Android.
2407
2408 // We may not have successfully added the FrameNavigationEntry to |entry|
2409 // above (per https://crbug.com/608402), in which case we create it from
2410 // scratch. This works because we do not depend on |frame_entry| being inside
2411 // |entry| during NavigateToEntry. This will go away when we shortcut this
2412 // further in https://crbug.com/536906.
2413 scoped_refptr<FrameNavigationEntry> frame_entry(entry->GetFrameEntry(node));
2414 if (!frame_entry) {
Patrick Monette50e8bd82019-06-13 22:40:452415 frame_entry = base::MakeRefCounted<FrameNavigationEntry>(
clamy987a3752018-05-03 17:36:262416 node->unique_name(), -1, -1, nullptr,
Nasko Oskov18006bc2018-12-06 02:53:582417 static_cast<SiteInstanceImpl*>(source_site_instance), url,
Lukasz Anforowicz435bcb582019-07-12 20:50:062418 nullptr /* origin */, referrer, initiator_origin, std::vector<GURL>(),
Miyoung Shin5d77f72072020-10-09 15:14:202419 blink::PageState(), method, -1, blob_url_loader_factory,
Antonio Sartori78a749f2020-11-30 12:03:392420 nullptr /* web_bundle_navigation_info */,
Titouan Rigoudy6ec70402021-02-02 15:42:192421 nullptr /* policy_container_policies */);
clamy987a3752018-05-03 17:36:262422 }
2423
Camille Lamy5193caa2018-10-12 11:59:422424 LoadURLParams params(url);
Chris Hamilton83272dc2021-02-23 00:24:022425 params.initiator_frame_token = base::OptionalFromPtr(initiator_frame_token);
Antonio Sartori9a82f6f32020-12-14 09:22:452426 params.initiator_process_id = initiator_process_id;
Nasko Oskov93e7c55c2018-12-19 01:59:292427 params.initiator_origin = initiator_origin;
Camille Lamy5193caa2018-10-12 11:59:422428 params.source_site_instance = source_site_instance;
2429 params.load_type = method == "POST" ? LOAD_TYPE_HTTP_POST : LOAD_TYPE_DEFAULT;
2430 params.transition_type = page_transition;
Dominic Farolino226226af2019-06-25 00:58:032431 params.frame_tree_node_id = node->frame_tree_node_id();
Camille Lamy5193caa2018-10-12 11:59:422432 params.referrer = referrer;
2433 /* params.redirect_chain: skip */
2434 params.extra_headers = extra_headers;
2435 params.is_renderer_initiated = is_renderer_initiated;
2436 params.override_user_agent = UA_OVERRIDE_INHERIT;
2437 /* params.base_url_for_data_url: skip */
2438 /* params.virtual_url_for_data_url: skip */
2439 /* params.data_url_as_string: skip */
2440 params.post_data = post_body;
2441 params.can_load_local_resources = false;
Kevin McNeee60e76b2019-11-27 20:01:582442 /* params.should_replace_current_entry: skip */
Camille Lamy5193caa2018-10-12 11:59:422443 /* params.frame_name: skip */
2444 // TODO(clamy): See if user gesture should be propagated to this function.
2445 params.has_user_gesture = false;
2446 params.should_clear_history_list = false;
2447 params.started_from_context_menu = false;
2448 /* params.navigation_ui_data: skip */
2449 /* params.input_start: skip */
Lucas Furukawa Gadania9c45682019-07-31 22:05:142450 params.was_activated = mojom::WasActivatedOption::kUnknown;
Robert Ogden011a8082019-01-23 19:04:542451 /* params.reload_type: skip */
John Delaney50425f82020-04-07 16:26:212452 params.impression = impression;
Camille Lamy5193caa2018-10-12 11:59:422453
2454 std::unique_ptr<NavigationRequest> request =
2455 CreateNavigationRequestFromLoadParams(
Dominic Farolino226226af2019-06-25 00:58:032456 node, params, override_user_agent, should_replace_current_entry,
2457 false /* has_user_gesture */, download_policy, ReloadType::NONE,
Scott Violet5ae6c42e2020-10-28 02:47:372458 entry.get(), frame_entry.get(), params.transition_type);
clamyea99ea12018-05-28 13:54:232459
2460 if (!request)
2461 return;
2462
Arthur Hemery948742762019-09-18 10:06:242463 // At this stage we are proceeding with this navigation. If this was renderer
2464 // initiated with user gesture, we need to make sure we clear up potential
2465 // remains of a cancelled browser initiated navigation to avoid URL spoofs.
2466 DiscardNonCommittedEntries();
2467
Lukasz Anforowicz9ee83c272020-12-01 20:14:052468 node->navigator().Navigate(std::move(request), ReloadType::NONE);
clamy987a3752018-05-03 17:36:262469}
2470
[email protected]d1198fd2012-08-13 22:50:192471void NavigationControllerImpl::SetSessionStorageNamespace(
[email protected]fdac6ade2013-07-20 01:06:302472 const std::string& partition_id,
[email protected]8ff00d72012-10-23 19:12:212473 SessionStorageNamespace* session_storage_namespace) {
[email protected]d1198fd2012-08-13 22:50:192474 if (!session_storage_namespace)
2475 return;
2476
2477 // We can't overwrite an existing SessionStorage without violating spec.
2478 // Attempts to do so may give a tab access to another tab's session storage
2479 // so die hard on an error.
Aran Gilman37d11632019-10-08 23:07:152480 bool successful_insert =
2481 session_storage_namespace_map_
2482 .insert(
2483 make_pair(partition_id, static_cast<SessionStorageNamespaceImpl*>(
2484 session_storage_namespace)))
[email protected]fdac6ade2013-07-20 01:06:302485 .second;
2486 CHECK(successful_insert) << "Cannot replace existing SessionStorageNamespace";
[email protected]d1198fd2012-08-13 22:50:192487}
2488
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572489bool NavigationControllerImpl::IsUnmodifiedBlankTab() {
Aran Gilman37d11632019-10-08 23:07:152490 return IsInitialNavigation() && !GetLastCommittedEntry() &&
Carlos Caballeroede6f8c2021-01-28 11:01:502491 !frame_tree_.has_accessed_initial_main_document();
[email protected]aa62afd2014-04-22 19:22:462492}
2493
Aran Gilman37d11632019-10-08 23:07:152494SessionStorageNamespace* NavigationControllerImpl::GetSessionStorageNamespace(
2495 SiteInstance* instance) {
[email protected]fdac6ade2013-07-20 01:06:302496 std::string partition_id;
2497 if (instance) {
2498 // TODO(ajwong): When GetDefaultSessionStorageNamespace() goes away, remove
danakjf26536bf2020-09-10 00:46:132499 // this if statement so |instance| must not be null.
Aaron Colwelld223f232021-03-02 21:28:592500 partition_id =
2501 static_cast<SiteInstanceImpl*>(instance)->GetStoragePartitionId();
[email protected]fdac6ade2013-07-20 01:06:302502 }
[email protected]d1198fd2012-08-13 22:50:192503
[email protected]fdac6ade2013-07-20 01:06:302504 // TODO(ajwong): Should this use the |partition_id| directly rather than
2505 // re-lookup via |instance|? http://crbug.com/142685
2506 StoragePartition* partition =
michaelnbacbcbd2016-02-09 00:32:032507 BrowserContext::GetStoragePartition(browser_context_, instance);
2508 DOMStorageContextWrapper* context_wrapper =
2509 static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext());
2510
2511 SessionStorageNamespaceMap::const_iterator it =
2512 session_storage_namespace_map_.find(partition_id);
2513 if (it != session_storage_namespace_map_.end()) {
2514 // Ensure that this namespace actually belongs to this partition.
Aran Gilman37d11632019-10-08 23:07:152515 DCHECK(static_cast<SessionStorageNamespaceImpl*>(it->second.get())
2516 ->IsFromContext(context_wrapper));
michaelnbacbcbd2016-02-09 00:32:032517 return it->second.get();
2518 }
2519
2520 // Create one if no one has accessed session storage for this partition yet.
Daniel Murphy31bbb8b12018-02-07 21:44:102521 scoped_refptr<SessionStorageNamespaceImpl> session_storage_namespace =
2522 SessionStorageNamespaceImpl::Create(context_wrapper);
2523 SessionStorageNamespaceImpl* session_storage_namespace_ptr =
2524 session_storage_namespace.get();
2525 session_storage_namespace_map_[partition_id] =
2526 std::move(session_storage_namespace);
[email protected]fdac6ade2013-07-20 01:06:302527
Daniel Murphy31bbb8b12018-02-07 21:44:102528 return session_storage_namespace_ptr;
[email protected]fdac6ade2013-07-20 01:06:302529}
2530
2531SessionStorageNamespace*
2532NavigationControllerImpl::GetDefaultSessionStorageNamespace() {
2533 // TODO(ajwong): Remove if statement in GetSessionStorageNamespace().
Ivan Kotenkov2c0d2bb32017-11-01 15:41:282534 return GetSessionStorageNamespace(nullptr);
[email protected]fdac6ade2013-07-20 01:06:302535}
2536
2537const SessionStorageNamespaceMap&
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572538NavigationControllerImpl::GetSessionStorageNamespaceMap() {
[email protected]fdac6ade2013-07-20 01:06:302539 return session_storage_namespace_map_;
[email protected]a26023822011-12-29 00:23:552540}
[email protected]d202a7c2012-01-04 07:53:472541
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572542bool NavigationControllerImpl::NeedsReload() {
[email protected]71fde352011-12-29 03:29:562543 return needs_reload_;
2544}
[email protected]a26023822011-12-29 00:23:552545
[email protected]46bb5e9c2013-10-03 22:16:472546void NavigationControllerImpl::SetNeedsReload() {
Alex Moshchuk7b4f0652019-05-30 18:54:412547 SetNeedsReload(NeedsReloadType::kRequestedByClient);
2548}
2549
2550void NavigationControllerImpl::SetNeedsReload(NeedsReloadType type) {
[email protected]46bb5e9c2013-10-03 22:16:472551 needs_reload_ = true;
Alex Moshchuk7b4f0652019-05-30 18:54:412552 needs_reload_type_ = type;
jaekyunc8cefa82015-01-09 20:14:542553
2554 if (last_committed_entry_index_ != -1) {
2555 entries_[last_committed_entry_index_]->SetTransitionType(
2556 ui::PAGE_TRANSITION_RELOAD);
2557 }
[email protected]46bb5e9c2013-10-03 22:16:472558}
2559
[email protected]d202a7c2012-01-04 07:53:472560void NavigationControllerImpl::RemoveEntryAtIndexInternal(int index) {
Kevin McNee05164772019-09-03 17:24:572561 DCHECK_LT(index, GetEntryCount());
2562 DCHECK_NE(index, last_committed_entry_index_);
[email protected]43032342011-03-21 14:10:312563 DiscardNonCommittedEntries();
2564
2565 entries_.erase(entries_.begin() + index);
[email protected]6a13a6c2011-12-20 21:47:122566 if (last_committed_entry_index_ > index)
[email protected]43032342011-03-21 14:10:312567 last_committed_entry_index_--;
2568}
2569
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572570NavigationEntryImpl* NavigationControllerImpl::GetPendingEntry() {
arthursonzogni5c4c202d2017-04-25 23:41:272571 // If there is no pending_entry_, there should be no pending_entry_index_.
2572 DCHECK(pending_entry_ || pending_entry_index_ == -1);
2573
2574 // If there is a pending_entry_index_, then pending_entry_ must be the entry
Carlos IL42b416592019-10-07 23:10:362575 // at that index. An exception is while a reload of a post commit error page
2576 // is ongoing; in that case pending entry will point to the entry replaced
2577 // by the error.
arthursonzogni5c4c202d2017-04-25 23:41:272578 DCHECK(pending_entry_index_ == -1 ||
Carlos IL42b416592019-10-07 23:10:362579 pending_entry_ == GetEntryAtIndex(pending_entry_index_) ||
2580 pending_entry_ == entry_replaced_by_post_commit_error_.get());
arthursonzogni5c4c202d2017-04-25 23:41:272581
[email protected]022af742011-12-28 18:37:252582 return pending_entry_;
2583}
2584
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572585int NavigationControllerImpl::GetPendingEntryIndex() {
arthursonzogni5c4c202d2017-04-25 23:41:272586 // The pending entry index must always be less than the number of entries.
2587 // If there are no entries, it must be exactly -1.
2588 DCHECK_LT(pending_entry_index_, GetEntryCount());
2589 DCHECK(GetEntryCount() != 0 || pending_entry_index_ == -1);
[email protected]a26023822011-12-29 00:23:552590 return pending_entry_index_;
2591}
2592
avi25764702015-06-23 15:43:372593void NavigationControllerImpl::InsertOrReplaceEntry(
dcheng9bfa5162016-04-09 01:00:572594 std::unique_ptr<NavigationEntryImpl> entry,
Carlos IL42b416592019-10-07 23:10:362595 bool replace,
2596 bool was_post_commit_error) {
mastiz7eddb5f72016-06-23 09:52:452597 DCHECK(!ui::PageTransitionCoreTypeIs(entry->GetTransitionType(),
2598 ui::PAGE_TRANSITION_AUTO_SUBFRAME));
[email protected]765b35502008-08-21 00:51:202599
avi5cad4912015-06-19 05:25:442600 // If the pending_entry_index_ is -1, the navigation was to a new page, and we
2601 // need to keep continuity with the pending entry, so copy the pending entry's
2602 // unique ID to the committed entry. If the pending_entry_index_ isn't -1,
2603 // then the renderer navigated on its own, independent of the pending entry,
2604 // so don't copy anything.
2605 if (pending_entry_ && pending_entry_index_ == -1)
2606 entry->set_unique_id(pending_entry_->GetUniqueID());
[email protected]765b35502008-08-21 00:51:202607
arthursonzogni69a6a1b2019-09-17 09:23:002608 DiscardNonCommittedEntries();
[email protected]765b35502008-08-21 00:51:202609
creisee17e932015-07-17 17:56:222610 // When replacing, don't prune the forward history.
Carlos IL42b416592019-10-07 23:10:362611 if ((replace || was_post_commit_error) && entries_.size() > 0) {
Mikel Astizba9cf2fd2017-12-17 10:38:102612 CopyReplacedNavigationEntryDataIfPreviouslyEmpty(
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572613 entries_[last_committed_entry_index_].get(), entry.get());
Carlos IL42b416592019-10-07 23:10:362614 // If the new entry is a post-commit error page, we store the current last
2615 // committed entry to the side so that we can put it back when navigating
2616 // away from the error.
2617 if (was_post_commit_error) {
2618 DCHECK(!entry_replaced_by_post_commit_error_);
2619 entry_replaced_by_post_commit_error_ =
2620 std::move(entries_[last_committed_entry_index_]);
2621 }
dcheng36b6aec92015-12-26 06:16:362622 entries_[last_committed_entry_index_] = std::move(entry);
creisee17e932015-07-17 17:56:222623 return;
2624 }
[email protected]765b35502008-08-21 00:51:202625
creis37979a62015-08-04 19:48:182626 // We shouldn't see replace == true when there's no committed entries.
2627 DCHECK(!replace);
2628
Michael Thiessen9b14d512019-09-23 21:19:472629 PruneForwardEntries();
[email protected]765b35502008-08-21 00:51:202630
Shivani Sharmad8c8d652019-02-13 17:27:572631 PruneOldestSkippableEntryIfFull();
[email protected]765b35502008-08-21 00:51:202632
dcheng36b6aec92015-12-26 06:16:362633 entries_.push_back(std::move(entry));
[email protected]765b35502008-08-21 00:51:202634 last_committed_entry_index_ = static_cast<int>(entries_.size()) - 1;
initial.commit09911bf2008-07-26 23:55:292635}
2636
Shivani Sharmad8c8d652019-02-13 17:27:572637void NavigationControllerImpl::PruneOldestSkippableEntryIfFull() {
Shivani Sharma2d5b4b6b2019-01-08 16:07:162638 if (entries_.size() < max_entry_count())
2639 return;
2640
2641 DCHECK_EQ(max_entry_count(), entries_.size());
2642 DCHECK_GT(last_committed_entry_index_, 0);
Shivani Sharmad8c8d652019-02-13 17:27:572643 CHECK_EQ(pending_entry_index_, -1);
2644
2645 int index = 0;
2646 if (base::FeatureList::IsEnabled(
2647 features::kHistoryManipulationIntervention)) {
2648 // Retrieve the oldest skippable entry.
2649 for (; index < GetEntryCount(); index++) {
2650 if (GetEntryAtIndex(index)->should_skip_on_back_forward_ui())
2651 break;
2652 }
2653 }
2654
2655 // If there is no skippable entry or if it is the last committed entry then
2656 // fall back to pruning the oldest entry. It is not safe to prune the last
2657 // committed entry.
2658 if (index == GetEntryCount() || index == last_committed_entry_index_)
2659 index = 0;
2660
2661 bool should_succeed = RemoveEntryAtIndex(index);
2662 DCHECK_EQ(true, should_succeed);
2663
2664 NotifyPrunedEntries(this, index, 1);
[email protected]944822b2012-03-02 20:57:252665}
2666
clamy3cb9bea92018-07-10 12:42:022667void NavigationControllerImpl::NavigateToExistingPendingEntry(
Dave Tapuska8bfd84c2019-03-26 20:47:162668 ReloadType reload_type,
2669 int sandboxed_source_frame_tree_node_id) {
Alexander Timin3a92df72019-09-20 11:59:502670 TRACE_EVENT0("navigation",
2671 "NavigationControllerImpl::NavigateToExistingPendingEntry");
arthursonzogni5c4c202d2017-04-25 23:41:272672 DCHECK(pending_entry_);
clamy3cb9bea92018-07-10 12:42:022673 DCHECK(IsInitialNavigation() || pending_entry_index_ != -1);
Carlos IL42b416592019-10-07 23:10:362674 if (pending_entry_index_ != -1) {
2675 // The pending entry may not be in entries_ if a post-commit error page is
2676 // showing.
2677 DCHECK(pending_entry_ == entries_[pending_entry_index_].get() ||
2678 pending_entry_ == entry_replaced_by_post_commit_error_.get());
2679 }
clamy3cb9bea92018-07-10 12:42:022680 DCHECK(!IsRendererDebugURL(pending_entry_->GetURL()));
Alex Moshchuk3a4e77a2020-05-29 21:32:572681 bool is_forced_reload = needs_reload_;
[email protected]72097fd02010-01-21 23:36:012682 needs_reload_ = false;
Carlos Caballero40b0efd2021-01-26 11:55:002683 FrameTreeNode* root = frame_tree_.root();
Arthur Sonzogni620cec62018-12-13 13:08:572684 int nav_entry_id = pending_entry_->GetUniqueID();
2685
[email protected]83c2e232011-10-07 21:36:462686 // If we were navigating to a slow-to-commit page, and the user performs
2687 // a session history navigation to the last committed page, RenderViewHost
2688 // will force the throbber to start, but WebKit will essentially ignore the
2689 // navigation, and won't send a message to stop the throbber. To prevent this
2690 // from happening, we drop the navigation here and stop the slow-to-commit
2691 // page from loading (which would normally happen during the navigation).
clamy3cb9bea92018-07-10 12:42:022692 if (pending_entry_index_ == last_committed_entry_index_ &&
Lukasz Anforowicz6b75c0d2020-12-01 22:56:082693 !pending_entry_->IsRestored() &&
arthursonzogni5c4c202d2017-04-25 23:41:272694 pending_entry_->GetTransitionType() & ui::PAGE_TRANSITION_FORWARD_BACK) {
[email protected]ec6c05f2013-10-23 18:41:572695 delegate_->Stop();
[email protected]6a13a6c2011-12-20 21:47:122696
[email protected]83c2e232011-10-07 21:36:462697 DiscardNonCommittedEntries();
2698 return;
2699 }
2700
creisce0ef3572017-01-26 17:53:082701 // Compare FrameNavigationEntries to see which frames in the tree need to be
2702 // navigated.
clamy3cb9bea92018-07-10 12:42:022703 std::vector<std::unique_ptr<NavigationRequest>> same_document_loads;
2704 std::vector<std::unique_ptr<NavigationRequest>> different_document_loads;
Alex Moshchuk3a4e77a2020-05-29 21:32:572705 FindFramesToNavigate(root, reload_type, &same_document_loads,
2706 &different_document_loads);
creis4e2ecb72015-06-20 00:46:302707
2708 if (same_document_loads.empty() && different_document_loads.empty()) {
Alex Moshchuk3a4e77a2020-05-29 21:32:572709 // We were unable to match any frames to navigate. This can happen if a
2710 // history navigation targets a subframe that no longer exists
2711 // (https://crbug.com/705550). In this case, we need to update the current
2712 // history entry to the pending one but keep the main document loaded. We
2713 // also need to ensure that observers are informed about the updated
2714 // current history entry (e.g., for greying out back/forward buttons), and
2715 // that renderer processes update their history offsets. The easiest way
2716 // to do all that is to schedule a "redundant" same-document navigation in
2717 // the main frame.
2718 //
2719 // Note that we don't want to remove this history entry, as it might still
2720 // be valid later, since a frame that it's targeting may be recreated.
2721 //
2722 // TODO(alexmos, creis): This behavior isn't ideal, as the user would
2723 // need to repeat history navigations until finding the one that works.
2724 // Consider changing this behavior to keep looking for the first valid
2725 // history entry that finds frames to navigate.
clamy3cb9bea92018-07-10 12:42:022726 std::unique_ptr<NavigationRequest> navigation_request =
Camille Lamy5193caa2018-10-12 11:59:422727 CreateNavigationRequestFromEntry(
Lucas Furukawa Gadani5553a1582019-01-08 18:55:572728 root, pending_entry_, pending_entry_->GetFrameEntry(root),
Alex Moshchuk3a4e77a2020-05-29 21:32:572729 ReloadType::NONE /* reload_type */,
2730 true /* is_same_document_history_load */,
Camille Lamy5193caa2018-10-12 11:59:422731 false /* is_history_navigation_in_new_child */);
clamy3cb9bea92018-07-10 12:42:022732 if (!navigation_request) {
Alex Moshchuk3a4e77a2020-05-29 21:32:572733 // If this navigation cannot start, delete the pending NavigationEntry.
clamy3cb9bea92018-07-10 12:42:022734 DiscardPendingEntry(false);
2735 return;
2736 }
Alex Moshchuk3a4e77a2020-05-29 21:32:572737 same_document_loads.push_back(std::move(navigation_request));
2738
2739 // Sanity check that we never take this branch for any kinds of reloads,
2740 // as those should've queued a different-document load in the main frame.
2741 DCHECK(!is_forced_reload);
2742 DCHECK_EQ(reload_type, ReloadType::NONE);
creis4e2ecb72015-06-20 00:46:302743 }
2744
Dave Tapuska8bfd84c2019-03-26 20:47:162745 // If |sandboxed_source_frame_node_id| is valid, then track whether this
2746 // navigation affects any frame outside the frame's subtree.
2747 if (sandboxed_source_frame_tree_node_id !=
2748 FrameTreeNode::kFrameTreeNodeInvalidId) {
2749 bool navigates_inside_tree =
2750 DoesSandboxNavigationStayWithinSubtree(
2751 sandboxed_source_frame_tree_node_id, same_document_loads) &&
2752 DoesSandboxNavigationStayWithinSubtree(
2753 sandboxed_source_frame_tree_node_id, different_document_loads);
Dave Tapuska716ed3af2019-09-23 18:45:502754 // Count the navigations as web use counters so we can determine
Dave Tapuska8bfd84c2019-03-26 20:47:162755 // the number of pages that trigger this.
2756 FrameTreeNode* sandbox_source_frame_tree_node =
2757 FrameTreeNode::GloballyFindByID(sandboxed_source_frame_tree_node_id);
2758 if (sandbox_source_frame_tree_node) {
2759 GetContentClient()->browser()->LogWebFeatureForCurrentPage(
2760 sandbox_source_frame_tree_node->current_frame_host(),
2761 navigates_inside_tree
2762 ? blink::mojom::WebFeature::kSandboxBackForwardStaysWithinSubtree
2763 : blink::mojom::WebFeature::
2764 kSandboxBackForwardAffectsFramesOutsideSubtree);
2765 }
Dave Tapuska855c1e12019-08-23 20:45:522766
2767 // If the navigation occurred outside the tree discard it because
2768 // the sandboxed frame didn't have permission to navigate outside
2769 // its tree. If it is possible that the navigation is both inside and
2770 // outside the frame tree and we discard it entirely because we don't
2771 // want to end up in a history state that didn't exist before.
2772 if (base::FeatureList::IsEnabled(
2773 features::kHistoryPreventSandboxedNavigation) &&
2774 !navigates_inside_tree) {
2775 DiscardPendingEntry(false);
2776 return;
2777 }
Dave Tapuska8bfd84c2019-03-26 20:47:162778 }
2779
Carlos Caballero539a421c2020-07-06 10:25:572780 // BackForwardCache:
2781 // Navigate immediately if the document is in the BackForwardCache.
2782 if (back_forward_cache_.GetEntry(nav_entry_id)) {
2783 TRACE_EVENT0("navigation", "BackForwardCache_CreateNavigationRequest");
2784 DCHECK_EQ(reload_type, ReloadType::NONE);
2785 auto navigation_request = CreateNavigationRequestFromEntry(
2786 root, pending_entry_, pending_entry_->GetFrameEntry(root),
2787 ReloadType::NONE, false /* is_same_document_history_load */,
2788 false /* is_history_navigation_in_new_child */);
Lukasz Anforowicz9ee83c272020-12-01 20:14:052789 root->navigator().Navigate(std::move(navigation_request), ReloadType::NONE);
Carlos Caballero539a421c2020-07-06 10:25:572790
2791 return;
2792 }
2793
2794 // History navigation might try to reuse a specific BrowsingInstance, already
2795 // used by a page in the cache. To avoid having two different main frames that
2796 // live in the same BrowsingInstance, evict the all pages with this
2797 // BrowsingInstance from the cache.
2798 //
2799 // For example, take the following scenario:
2800 //
2801 // A1 = Some page on a.com
2802 // A2 = Some other page on a.com
2803 // B3 = An uncacheable page on b.com
2804 //
2805 // Then the following navigations occur:
2806 // A1->A2->B3->A1
2807 // On the navigation from B3 to A1, A2 will remain in the cache (B3 doesn't
2808 // take its place) and A1 will be created in the same BrowsingInstance (and
2809 // SiteInstance), as A2.
2810 //
2811 // If we didn't do anything, both A1 and A2 would remain alive in the same
2812 // BrowsingInstance/SiteInstance, which is unsupported by
2813 // RenderFrameHostManager::CommitPending(). To avoid this conundrum, we evict
2814 // A2 from the cache.
2815 if (pending_entry_->site_instance()) {
2816 back_forward_cache_.EvictFramesInRelatedSiteInstances(
2817 pending_entry_->site_instance());
2818 }
2819
clamy3cb9bea92018-07-10 12:42:022820 // This call does not support re-entrancy. See http://crbug.com/347742.
2821 CHECK(!in_navigate_to_pending_entry_);
2822 in_navigate_to_pending_entry_ = true;
creis4e2ecb72015-06-20 00:46:302823
arthursonzogni66f711c2019-10-08 14:40:362824 // It is not possible to delete the pending NavigationEntry while navigating
2825 // to it. Grab a reference to delay potential deletion until the end of this
2826 // function.
2827 std::unique_ptr<PendingEntryRef> pending_entry_ref = ReferencePendingEntry();
2828
creis4e2ecb72015-06-20 00:46:302829 // Send all the same document frame loads before the different document loads.
clamy3cb9bea92018-07-10 12:42:022830 for (auto& item : same_document_loads) {
2831 FrameTreeNode* frame = item->frame_tree_node();
Lukasz Anforowicz9ee83c272020-12-01 20:14:052832 frame->navigator().Navigate(std::move(item), reload_type);
creis4e2ecb72015-06-20 00:46:302833 }
clamy3cb9bea92018-07-10 12:42:022834 for (auto& item : different_document_loads) {
2835 FrameTreeNode* frame = item->frame_tree_node();
Lukasz Anforowicz9ee83c272020-12-01 20:14:052836 frame->navigator().Navigate(std::move(item), reload_type);
creis4e2ecb72015-06-20 00:46:302837 }
clamy3cb9bea92018-07-10 12:42:022838
2839 in_navigate_to_pending_entry_ = false;
creis4e2ecb72015-06-20 00:46:302840}
2841
Alex Moshchuk3a4e77a2020-05-29 21:32:572842NavigationControllerImpl::HistoryNavigationAction
2843NavigationControllerImpl::DetermineActionForHistoryNavigation(
creis4e2ecb72015-06-20 00:46:302844 FrameTreeNode* frame,
Alex Moshchuk3a4e77a2020-05-29 21:32:572845 ReloadType reload_type) {
Sreeja Kamishetty8eacabb2021-03-09 11:45:422846 RenderFrameHostImpl* render_frame_host = frame->current_frame_host();
2847 // Only active and prerendered frames can navigate.
2848 if (render_frame_host->lifecycle_state() !=
2849 RenderFrameHostImpl::LifecycleState::kPrerendering) {
2850 // - If the frame is in pending deletion, the browser already committed to
2851 // destroying this RenderFrameHost. See https://crbug.com/930278.
2852 // - If the frame is in back-forward cache, it's not allowed to navigate as
2853 // it should remain frozen. Ignore the request and evict the document from
2854 // back-forward cache.
2855 //
2856 // If the frame is inactive, there's no need to recurse into subframes,
2857 // which should all be inactive as well.
2858 if (render_frame_host->IsInactiveAndDisallowReactivation())
2859 return HistoryNavigationAction::kStopLooking;
2860 }
arthursonzogni03f76152019-02-12 10:35:202861
Alex Moshchuk3a4e77a2020-05-29 21:32:572862 // If there's no last committed entry, there is no previous history entry to
2863 // compare against, so fall back to a different-document load. Note that we
2864 // should only reach this case for the root frame and not descend further
2865 // into subframes.
2866 if (!GetLastCommittedEntry()) {
2867 DCHECK(frame->IsMainFrame());
2868 return HistoryNavigationAction::kDifferentDocument;
2869 }
2870
2871 // Reloads should result in a different-document load. Note that reloads may
2872 // also happen via the |needs_reload_| mechanism where the reload_type is
2873 // NONE, so detect this by comparing whether we're going to the same
2874 // entry that we're currently on. Similarly to above, only main frames
2875 // should reach this. Note that subframes support reloads, but that's done
2876 // via a different path that doesn't involve FindFramesToNavigate (see
2877 // RenderFrameHost::Reload()).
2878 if (reload_type != ReloadType::NONE ||
2879 pending_entry_index_ == last_committed_entry_index_) {
2880 DCHECK(frame->IsMainFrame());
2881 return HistoryNavigationAction::kDifferentDocument;
2882 }
2883
Alex Moshchuk47d1a4bd2020-06-01 22:15:342884 // If there is no new FrameNavigationEntry for the frame, ignore the
2885 // load. For example, this may happen when going back to an entry before a
2886 // frame was created. Suppose we commit a same-document navigation that also
2887 // results in adding a new subframe somewhere in the tree. If we go back,
2888 // the new subframe will be missing a FrameNavigationEntry in the previous
2889 // NavigationEntry, but we shouldn't delete or change what's loaded in
2890 // it.
2891 //
Alex Moshchuke65c39272020-06-03 17:55:372892 // Note that in this case, there is no need to keep looking for navigations
2893 // in subframes, which would be missing FrameNavigationEntries as well.
2894 //
Alex Moshchuk47d1a4bd2020-06-01 22:15:342895 // It's important to check this before checking |old_item| below, since both
2896 // might be null, and in that case we still shouldn't change what's loaded in
2897 // this frame. Note that scheduling any loads assumes that |new_item| is
2898 // non-null. See https://crbug.com/1088354.
2899 FrameNavigationEntry* new_item = pending_entry_->GetFrameEntry(frame);
2900 if (!new_item)
Alex Moshchuke65c39272020-06-03 17:55:372901 return HistoryNavigationAction::kStopLooking;
Alex Moshchuk47d1a4bd2020-06-01 22:15:342902
Alex Moshchuk3a4e77a2020-05-29 21:32:572903 // If there is no old FrameNavigationEntry, schedule a different-document
2904 // load.
2905 //
creis225a7432016-06-03 22:56:272906 // TODO(creis): Store the last committed FrameNavigationEntry to use here,
2907 // rather than assuming the NavigationEntry has up to date info on subframes.
Alex Moshchuk3a4e77a2020-05-29 21:32:572908 // Note that this may require sharing FrameNavigationEntries between
2909 // NavigationEntries (https://crbug.com/373041) as a prerequisite, since
2910 // otherwise the stored FrameNavigationEntry might get stale (e.g., after
2911 // subframe navigations, or in the case where we don't find any frames to
2912 // navigate and ignore a back/forward navigation while moving to a different
2913 // NavigationEntry, as in https://crbug.com/705550).
creis4e2ecb72015-06-20 00:46:302914 FrameNavigationEntry* old_item =
2915 GetLastCommittedEntry()->GetFrameEntry(frame);
Alex Moshchuk3a4e77a2020-05-29 21:32:572916 if (!old_item)
2917 return HistoryNavigationAction::kDifferentDocument;
2918
Alex Moshchuk3a4e77a2020-05-29 21:32:572919 // If the new item is not in the same SiteInstance, schedule a
2920 // different-document load. Newly restored items may not have a SiteInstance
2921 // yet, in which case it will be assigned on first commit.
2922 if (new_item->site_instance() &&
2923 new_item->site_instance() != old_item->site_instance())
2924 return HistoryNavigationAction::kDifferentDocument;
2925
2926 // Schedule a different-document load if the current RenderFrameHost is not
danakj84be86a2021-02-18 20:42:492927 // live or has no committed document in the renderer. This case can happen for
2928 // Ctrl+Back or after a renderer crash, or simply by going Back while the
2929 // reload after a crash is still in flight. Starting a navigation after a
2930 // crash early-promotes the speculative RenderFrameHost. At that point this
2931 // history has not updated to reflect this change until it commits, and
2932 // performing a same document navigation would be invalid since there is no
2933 // document committed to be navigated.
2934 if (!frame->current_frame_host()->has_committed_any_navigation())
Alex Moshchuk3a4e77a2020-05-29 21:32:572935 return HistoryNavigationAction::kDifferentDocument;
2936
2937 if (new_item->item_sequence_number() != old_item->item_sequence_number()) {
creis54131692016-08-12 18:32:252938 // Same document loads happen if the previous item has the same document
danakjb952ef12021-01-14 19:58:492939 // sequence number but different item sequence number.
2940 if (new_item->document_sequence_number() ==
2941 old_item->document_sequence_number()) {
Alex Moshchuk3a4e77a2020-05-29 21:32:572942 return HistoryNavigationAction::kSameDocument;
danakjb952ef12021-01-14 19:58:492943 }
avib48cb312016-05-05 21:35:002944
Alex Moshchuk3a4e77a2020-05-29 21:32:572945 // Otherwise, if both item and document sequence numbers differ, this
2946 // should be a different document load.
2947 return HistoryNavigationAction::kDifferentDocument;
2948 }
2949
2950 // If the item sequence numbers match, there is no need to navigate this
Alex Moshchuke65c39272020-06-03 17:55:372951 // frame. Keep looking for navigations in this frame's children.
Alex Moshchuk3a4e77a2020-05-29 21:32:572952 DCHECK_EQ(new_item->document_sequence_number(),
2953 old_item->document_sequence_number());
Alex Moshchuke65c39272020-06-03 17:55:372954 return HistoryNavigationAction::kKeepLooking;
Alex Moshchuk3a4e77a2020-05-29 21:32:572955}
2956
2957void NavigationControllerImpl::FindFramesToNavigate(
2958 FrameTreeNode* frame,
2959 ReloadType reload_type,
2960 std::vector<std::unique_ptr<NavigationRequest>>* same_document_loads,
2961 std::vector<std::unique_ptr<NavigationRequest>>* different_document_loads) {
2962 DCHECK(pending_entry_);
2963 FrameNavigationEntry* new_item = pending_entry_->GetFrameEntry(frame);
2964
2965 auto action = DetermineActionForHistoryNavigation(frame, reload_type);
2966
2967 if (action == HistoryNavigationAction::kSameDocument) {
2968 std::unique_ptr<NavigationRequest> navigation_request =
2969 CreateNavigationRequestFromEntry(
2970 frame, pending_entry_, new_item, reload_type,
2971 true /* is_same_document_history_load */,
2972 false /* is_history_navigation_in_new_child */);
2973 if (navigation_request) {
2974 // Only add the request if was properly created. It's possible for the
2975 // creation to fail in certain cases, e.g. when the URL is invalid.
2976 same_document_loads->push_back(std::move(navigation_request));
creis4e2ecb72015-06-20 00:46:302977 }
Lei Zhang96031532019-10-10 19:05:472978
Alex Moshchuk3a4e77a2020-05-29 21:32:572979 // TODO(avi, creis): This is a bug; we should not return here. Rather, we
2980 // should continue on and navigate all child frames which have also
2981 // changed. This bug is the cause of <https://crbug.com/542299>, which is
2982 // a NC_IN_PAGE_NAVIGATION renderer kill.
2983 //
2984 // However, this bug is a bandaid over a deeper and worse problem. Doing a
2985 // pushState immediately after loading a subframe is a race, one that no
2986 // web page author expects. If we fix this bug, many large websites break.
2987 // For example, see <https://crbug.com/598043> and the spec discussion at
2988 // <https://github.com/whatwg/html/issues/1191>.
2989 //
2990 // For now, we accept this bug, and hope to resolve the race in a
2991 // different way that will one day allow us to fix this.
2992 return;
2993 } else if (action == HistoryNavigationAction::kDifferentDocument) {
Lei Zhang96031532019-10-10 19:05:472994 std::unique_ptr<NavigationRequest> navigation_request =
2995 CreateNavigationRequestFromEntry(
2996 frame, pending_entry_, new_item, reload_type,
2997 false /* is_same_document_history_load */,
2998 false /* is_history_navigation_in_new_child */);
2999 if (navigation_request) {
3000 // Only add the request if was properly created. It's possible for the
3001 // creation to fail in certain cases, e.g. when the URL is invalid.
3002 different_document_loads->push_back(std::move(navigation_request));
3003 }
3004 // For a different document, the subframes will be destroyed, so there's
3005 // no need to consider them.
3006 return;
Alex Moshchuke65c39272020-06-03 17:55:373007 } else if (action == HistoryNavigationAction::kStopLooking) {
3008 return;
creis4e2ecb72015-06-20 00:46:303009 }
3010
3011 for (size_t i = 0; i < frame->child_count(); i++) {
clamy3cb9bea92018-07-10 12:42:023012 FindFramesToNavigate(frame->child_at(i), reload_type, same_document_loads,
creis4e2ecb72015-06-20 00:46:303013 different_document_loads);
3014 }
3015}
3016
clamy21718cc22018-06-13 13:34:243017void NavigationControllerImpl::NavigateWithoutEntry(
3018 const LoadURLParams& params) {
3019 // Find the appropriate FrameTreeNode.
3020 FrameTreeNode* node = nullptr;
3021 if (params.frame_tree_node_id != RenderFrameHost::kNoFrameTreeNodeId ||
3022 !params.frame_name.empty()) {
3023 node = params.frame_tree_node_id != RenderFrameHost::kNoFrameTreeNodeId
Carlos Caballero40b0efd2021-01-26 11:55:003024 ? frame_tree_.FindByID(params.frame_tree_node_id)
3025 : frame_tree_.FindByName(params.frame_name);
clamy21718cc22018-06-13 13:34:243026 }
3027
3028 // If no FrameTreeNode was specified, navigate the main frame.
3029 if (!node)
Carlos Caballero40b0efd2021-01-26 11:55:003030 node = frame_tree_.root();
clamy21718cc22018-06-13 13:34:243031
Camille Lamy5193caa2018-10-12 11:59:423032 // Compute overrides to the LoadURLParams for |override_user_agent|,
3033 // |should_replace_current_entry| and |has_user_gesture| that will be used
3034 // both in the creation of the NavigationEntry and the NavigationRequest.
3035 // Ideally, the LoadURLParams themselves would be updated, but since they are
3036 // passed as a const reference, this is not possible.
3037 // TODO(clamy): When we only create a NavigationRequest, move this to
3038 // CreateNavigationRequestFromLoadURLParams.
3039 bool override_user_agent = ShouldOverrideUserAgent(params.override_user_agent,
3040 GetLastCommittedEntry());
3041
3042 // Don't allow an entry replacement if there is no entry to replace.
3043 // http://crbug.com/457149
3044 bool should_replace_current_entry =
3045 params.should_replace_current_entry && entries_.size();
3046
Scott Violet5ae6c42e2020-10-28 02:47:373047 ui::PageTransition transition_type = params.transition_type;
3048
clamy21718cc22018-06-13 13:34:243049 // Javascript URLs should not create NavigationEntries. All other navigations
3050 // do, including navigations to chrome renderer debug URLs.
clamy21718cc22018-06-13 13:34:243051 if (!params.url.SchemeIs(url::kJavaScriptScheme)) {
Scott Violet5ae6c42e2020-10-28 02:47:373052 std::unique_ptr<NavigationEntryImpl> entry =
3053 CreateNavigationEntryFromLoadParams(node, params, override_user_agent,
3054 should_replace_current_entry,
3055 params.has_user_gesture);
3056 // CreateNavigationEntryFromLoadParams() may modify the transition type.
3057 transition_type = entry->GetTransitionType();
clamy21718cc22018-06-13 13:34:243058 DiscardPendingEntry(false);
3059 SetPendingEntry(std::move(entry));
3060 }
3061
3062 // Renderer-debug URLs are sent to the renderer process immediately for
3063 // processing and don't need to create a NavigationRequest.
3064 // Note: this includes navigations to JavaScript URLs, which are considered
3065 // renderer-debug URLs.
3066 // Note: we intentionally leave the pending entry in place for renderer debug
3067 // URLs, unlike the cases below where we clear it if the navigation doesn't
3068 // proceed.
3069 if (IsRendererDebugURL(params.url)) {
Oleg Davydov2cc0167b2019-02-05 14:32:483070 // Renderer-debug URLs won't go through NavigationThrottlers so we have to
3071 // check them explicitly. See bug 913334.
Aaron Colwelle1908d982020-06-26 22:08:153072 if (GetContentClient()->browser()->ShouldBlockRendererDebugURL(
Oleg Davydov2cc0167b2019-02-05 14:32:483073 params.url, browser_context_)) {
3074 DiscardPendingEntry(false);
3075 return;
3076 }
3077
clamy21718cc22018-06-13 13:34:243078 HandleRendererDebugURL(node, params.url);
3079 return;
3080 }
3081
Antonio Sartori78a749f2020-11-30 12:03:393082 DCHECK(pending_entry_);
3083
clamy21718cc22018-06-13 13:34:243084 // Convert navigations to the current URL to a reload.
3085 // TODO(clamy): We should be using FrameTreeNode::IsMainFrame here instead of
3086 // relying on the frame tree node id from LoadURLParams. Unfortunately,
3087 // DevTools sometimes issues navigations to main frames that they do not
3088 // expect to see treated as reload, and it only works because they pass a
3089 // FrameTreeNode id in their LoadURLParams. Change this once they no longer do
3090 // that. See https://crbug.com/850926.
Robert Ogden011a8082019-01-23 19:04:543091 ReloadType reload_type = params.reload_type;
3092 if (reload_type == ReloadType::NONE &&
3093 ShouldTreatNavigationAsReload(
Fergal Daly766177d2020-07-07 07:54:043094 node, params.url, pending_entry_->GetVirtualURL(),
clamy21718cc22018-06-13 13:34:243095 params.base_url_for_data_url, params.transition_type,
clamy21718cc22018-06-13 13:34:243096 params.load_type ==
3097 NavigationController::LOAD_TYPE_HTTP_POST /* is_post */,
3098 false /* is_reload */, false /* is_navigation_to_existing_entry */,
clamy21718cc22018-06-13 13:34:243099 GetLastCommittedEntry())) {
3100 reload_type = ReloadType::NORMAL;
Alexander Timinb70f67382020-12-10 00:03:473101 pending_entry_->set_reload_type(reload_type);
Antonio Sartori78a749f2020-11-30 12:03:393102
3103 // If this is a reload of an existing FrameNavigationEntry and we had a
3104 // policy container for it, then we should copy it into the pending entry,
3105 // so that it is copied to the navigation request in
3106 // CreateNavigationRequestFromLoadParams later.
3107 if (GetLastCommittedEntry()) {
3108 FrameNavigationEntry* previous_frame_entry =
3109 GetLastCommittedEntry()->GetFrameEntry(node);
Titouan Rigoudy6ec70402021-02-02 15:42:193110 if (previous_frame_entry &&
3111 previous_frame_entry->policy_container_policies()) {
3112 pending_entry_->GetFrameEntry(node)->set_policy_container_policies(
Antonio Sartori5d09b30f2021-03-02 09:27:163113 previous_frame_entry->policy_container_policies()->Clone());
Antonio Sartori78a749f2020-11-30 12:03:393114 }
3115 }
3116 }
3117
3118 // If this navigation is an "Enter-in-omnibox" with the initial about:blank
3119 // document (so no last commit), then we should copy the document polices from
3120 // RenderFrameHost's PolicyContainerHost. The NavigationRequest will create a
3121 // new PolicyContainerHost with the document policies from the
3122 // |pending_entry_|, and that PolicyContainerHost will be put in the final
3123 // RenderFrameHost for the navigation. This way, we ensure that we keep
3124 // enforcing the right policies on the initial empty document after the
3125 // reload.
3126 if (!GetLastCommittedEntry() && params.url.IsAboutBlank()) {
3127 if (node->current_frame_host() &&
3128 node->current_frame_host()->policy_container_host()) {
Titouan Rigoudy6ec70402021-02-02 15:42:193129 pending_entry_->GetFrameEntry(node)->set_policy_container_policies(
Antonio Sartori5d09b30f2021-03-02 09:27:163130 node->current_frame_host()
3131 ->policy_container_host()
3132 ->policies()
3133 .Clone());
Antonio Sartori78a749f2020-11-30 12:03:393134 }
clamy21718cc22018-06-13 13:34:243135 }
3136
3137 // navigation_ui_data should only be present for main frame navigations.
3138 DCHECK(node->IsMainFrame() || !params.navigation_ui_data);
3139
Camille Lamy5193caa2018-10-12 11:59:423140 std::unique_ptr<NavigationRequest> request =
3141 CreateNavigationRequestFromLoadParams(
3142 node, params, override_user_agent, should_replace_current_entry,
Yeunjoo Choi3df791a2021-02-17 07:07:253143 params.has_user_gesture, blink::NavigationDownloadPolicy(),
3144 reload_type, pending_entry_, pending_entry_->GetFrameEntry(node),
3145 transition_type);
clamy21718cc22018-06-13 13:34:243146
3147 // If the navigation couldn't start, return immediately and discard the
3148 // pending NavigationEntry.
3149 if (!request) {
3150 DiscardPendingEntry(false);
3151 return;
3152 }
3153
Camille Lamy5193caa2018-10-12 11:59:423154#if DCHECK_IS_ON()
3155 // Safety check that NavigationRequest and NavigationEntry match.
3156 ValidateRequestMatchesEntry(request.get(), pending_entry_);
3157#endif
3158
clamy21718cc22018-06-13 13:34:243159 // This call does not support re-entrancy. See http://crbug.com/347742.
3160 CHECK(!in_navigate_to_pending_entry_);
3161 in_navigate_to_pending_entry_ = true;
3162
arthursonzogni66f711c2019-10-08 14:40:363163 // It is not possible to delete the pending NavigationEntry while navigating
3164 // to it. Grab a reference to delay potential deletion until the end of this
3165 // function.
3166 std::unique_ptr<PendingEntryRef> pending_entry_ref = ReferencePendingEntry();
3167
Lukasz Anforowicz9ee83c272020-12-01 20:14:053168 node->navigator().Navigate(std::move(request), reload_type);
clamy21718cc22018-06-13 13:34:243169
3170 in_navigate_to_pending_entry_ = false;
3171}
3172
clamyea99ea12018-05-28 13:54:233173void NavigationControllerImpl::HandleRendererDebugURL(
3174 FrameTreeNode* frame_tree_node,
3175 const GURL& url) {
3176 if (!frame_tree_node->current_frame_host()->IsRenderFrameLive()) {
clamy21718cc22018-06-13 13:34:243177 // Any renderer-side debug URLs or javascript: URLs should be ignored if
3178 // the renderer process is not live, unless it is the initial navigation
3179 // of the tab.
clamyea99ea12018-05-28 13:54:233180 if (!IsInitialNavigation()) {
3181 DiscardNonCommittedEntries();
3182 return;
3183 }
Fergal Dalyecd3b0202020-06-25 01:57:373184 // The current frame is always a main frame. If IsInitialNavigation() is
3185 // true then there have been no navigations and any frames of this tab must
3186 // be in the same renderer process. If that has crashed then the only frame
3187 // that can be revived is the main frame.
3188 frame_tree_node->render_manager()
3189 ->InitializeMainRenderFrameForImmediateUse();
clamyea99ea12018-05-28 13:54:233190 }
3191 frame_tree_node->current_frame_host()->HandleRendererDebugURL(url);
3192}
3193
clamy21718cc22018-06-13 13:34:243194std::unique_ptr<NavigationEntryImpl>
3195NavigationControllerImpl::CreateNavigationEntryFromLoadParams(
3196 FrameTreeNode* node,
Camille Lamy5193caa2018-10-12 11:59:423197 const LoadURLParams& params,
3198 bool override_user_agent,
3199 bool should_replace_current_entry,
3200 bool has_user_gesture) {
Marijn Kruisselbrink0c87e6e2018-06-22 22:57:393201 // Browser initiated navigations might not have a blob_url_loader_factory set
3202 // in params even if the navigation is to a blob URL. If that happens, lookup
3203 // the correct url loader factory to use here.
3204 auto blob_url_loader_factory = params.blob_url_loader_factory;
Kinuko Yasuda7d925ea22019-08-01 10:08:483205 if (!blob_url_loader_factory && params.url.SchemeIsBlob()) {
Marijn Kruisselbrink8ffda442020-09-03 18:29:473206 // Resolve the blob URL in the storage partition associated with the target
3207 // frame. This is the storage partition the URL will be loaded in, and only
3208 // URLs that can be resolved by it should be able to access its data.
Marijn Kruisselbrink0c87e6e2018-06-22 22:57:393209 blob_url_loader_factory = ChromeBlobStorageContext::URLLoaderFactoryForUrl(
Marijn Kruisselbrink8ffda442020-09-03 18:29:473210 node->current_frame_host()->GetStoragePartition(), params.url);
Marijn Kruisselbrink0c87e6e2018-06-22 22:57:393211 }
3212
clamy21718cc22018-06-13 13:34:243213 std::unique_ptr<NavigationEntryImpl> entry;
Tommy C. Li03eee77a2019-02-05 02:07:443214 // extra_headers in params are \n separated; navigation entries want \r\n.
3215 std::string extra_headers_crlf;
3216 base::ReplaceChars(params.extra_headers, "\n", "\r\n", &extra_headers_crlf);
clamy21718cc22018-06-13 13:34:243217
3218 // For subframes, create a pending entry with a corresponding frame entry.
3219 if (!node->IsMainFrame()) {
Tommy C. Li03eee77a2019-02-05 02:07:443220 if (GetLastCommittedEntry()) {
3221 // Create an identical NavigationEntry with a new FrameNavigationEntry for
3222 // the target subframe.
3223 entry = GetLastCommittedEntry()->Clone();
3224 } else {
3225 // If there's no last committed entry, create an entry for about:blank
3226 // with a subframe entry for our destination.
3227 // TODO(creis): Ensure this case can't exist in https://crbug.com/524208.
3228 entry = NavigationEntryImpl::FromNavigationEntry(CreateNavigationEntry(
Lukasz Anforowicz435bcb582019-07-12 20:50:063229 GURL(url::kAboutBlankURL), params.referrer, params.initiator_origin,
Lukasz Anforowicz641234d52019-11-07 21:07:103230 params.source_site_instance.get(), params.transition_type,
3231 params.is_renderer_initiated, extra_headers_crlf, browser_context_,
Scott Violet5ae6c42e2020-10-28 02:47:373232 blob_url_loader_factory, should_replace_current_entry,
3233 GetWebContents()));
Tommy C. Li03eee77a2019-02-05 02:07:443234 }
Nasko Oskov18006bc2018-12-06 02:53:583235
clamy21718cc22018-06-13 13:34:243236 entry->AddOrUpdateFrameEntry(
3237 node, -1, -1, nullptr,
3238 static_cast<SiteInstanceImpl*>(params.source_site_instance.get()),
Lukasz Anforowicz435bcb582019-07-12 20:50:063239 params.url, base::nullopt, params.referrer, params.initiator_origin,
Miyoung Shin5d77f72072020-10-09 15:14:203240 params.redirect_chain, blink::PageState(), "GET", -1,
Antonio Sartori78a749f2020-11-30 12:03:393241 blob_url_loader_factory, nullptr /* web_bundle_navigation_info */,
3242 // If in NavigateWithoutEntry we later determine that this navigation is
Charlie Reis7e2cb6d2021-01-26 01:27:163243 // a conversion of a new navigation into a reload, we will set the right
3244 // document policies there.
Titouan Rigoudy6ec70402021-02-02 15:42:193245 nullptr /* policy_container_policies */);
clamy21718cc22018-06-13 13:34:243246 } else {
3247 // Otherwise, create a pending entry for the main frame.
clamy21718cc22018-06-13 13:34:243248 entry = NavigationEntryImpl::FromNavigationEntry(CreateNavigationEntry(
Lukasz Anforowicz435bcb582019-07-12 20:50:063249 params.url, params.referrer, params.initiator_origin,
Lukasz Anforowicz641234d52019-11-07 21:07:103250 params.source_site_instance.get(), params.transition_type,
3251 params.is_renderer_initiated, extra_headers_crlf, browser_context_,
Scott Violet5ae6c42e2020-10-28 02:47:373252 blob_url_loader_factory, should_replace_current_entry,
3253 GetWebContents()));
clamy21718cc22018-06-13 13:34:243254 entry->set_source_site_instance(
3255 static_cast<SiteInstanceImpl*>(params.source_site_instance.get()));
3256 entry->SetRedirectChain(params.redirect_chain);
3257 }
3258
3259 // Set the FTN ID (only used in non-site-per-process, for tests).
3260 entry->set_frame_tree_node_id(node->frame_tree_node_id());
clamy21718cc22018-06-13 13:34:243261 entry->set_should_clear_history_list(params.should_clear_history_list);
Camille Lamy5193caa2018-10-12 11:59:423262 entry->SetIsOverridingUserAgent(override_user_agent);
3263 entry->set_has_user_gesture(has_user_gesture);
Robert Ogden011a8082019-01-23 19:04:543264 entry->set_reload_type(params.reload_type);
clamy21718cc22018-06-13 13:34:243265
clamy21718cc22018-06-13 13:34:243266 switch (params.load_type) {
3267 case LOAD_TYPE_DEFAULT:
3268 break;
3269 case LOAD_TYPE_HTTP_POST:
3270 entry->SetHasPostData(true);
3271 entry->SetPostData(params.post_data);
3272 break;
3273 case LOAD_TYPE_DATA:
3274 entry->SetBaseURLForDataURL(params.base_url_for_data_url);
3275 entry->SetVirtualURL(params.virtual_url_for_data_url);
3276#if defined(OS_ANDROID)
3277 entry->SetDataURLAsString(params.data_url_as_string);
3278#endif
3279 entry->SetCanLoadLocalResources(params.can_load_local_resources);
3280 break;
clamy21718cc22018-06-13 13:34:243281 }
3282
3283 // TODO(clamy): NavigationEntry is meant for information that will be kept
3284 // after the navigation ended and therefore is not appropriate for
3285 // started_from_context_menu. Move started_from_context_menu to
3286 // NavigationUIData.
3287 entry->set_started_from_context_menu(params.started_from_context_menu);
3288
3289 return entry;
3290}
3291
clamyea99ea12018-05-28 13:54:233292std::unique_ptr<NavigationRequest>
Camille Lamy5193caa2018-10-12 11:59:423293NavigationControllerImpl::CreateNavigationRequestFromLoadParams(
3294 FrameTreeNode* node,
3295 const LoadURLParams& params,
3296 bool override_user_agent,
3297 bool should_replace_current_entry,
3298 bool has_user_gesture,
Yeunjoo Choi3df791a2021-02-17 07:07:253299 blink::NavigationDownloadPolicy download_policy,
Camille Lamy5193caa2018-10-12 11:59:423300 ReloadType reload_type,
Lucas Furukawa Gadani5553a1582019-01-08 18:55:573301 NavigationEntryImpl* entry,
Scott Violet5ae6c42e2020-10-28 02:47:373302 FrameNavigationEntry* frame_entry,
3303 ui::PageTransition transition_type) {
Lucas Furukawa Gadani5553a1582019-01-08 18:55:573304 DCHECK_EQ(-1, GetIndexOfEntry(entry));
Camille Lamyb9ed3c52018-11-19 15:34:283305 DCHECK(frame_entry);
Nasko Oskov3c2f9e252019-01-10 17:45:533306 // All renderer-initiated navigations must have an initiator_origin.
3307 DCHECK(!params.is_renderer_initiated || params.initiator_origin.has_value());
Camille Lamyff7c4822018-11-07 15:42:513308
Camille Lamy5193caa2018-10-12 11:59:423309 GURL url_to_load;
3310 GURL virtual_url;
Nasko Oskov03912102019-01-11 00:21:323311 base::Optional<url::Origin> origin_to_commit =
3312 frame_entry ? frame_entry->committed_origin() : base::nullopt;
3313
Camille Lamy2baa8022018-10-19 16:43:173314 // For main frames, rewrite the URL if necessary and compute the virtual URL
3315 // that should be shown in the address bar.
3316 if (node->IsMainFrame()) {
Lukasz Anforowiczb2eb19b12020-01-25 00:40:423317 bool ignored_reverse_on_redirect = false;
Camille Lamy2baa8022018-10-19 16:43:173318 RewriteUrlForNavigation(params.url, browser_context_, &url_to_load,
Lukasz Anforowiczb2eb19b12020-01-25 00:40:423319 &virtual_url, &ignored_reverse_on_redirect);
Camille Lamy5193caa2018-10-12 11:59:423320
Camille Lamy2baa8022018-10-19 16:43:173321 // For DATA loads, override the virtual URL.
3322 if (params.load_type == LOAD_TYPE_DATA)
3323 virtual_url = params.virtual_url_for_data_url;
Camille Lamy5193caa2018-10-12 11:59:423324
Camille Lamy2baa8022018-10-19 16:43:173325 if (virtual_url.is_empty())
3326 virtual_url = url_to_load;
3327
Lucas Furukawa Gadani5553a1582019-01-08 18:55:573328 CHECK(virtual_url == entry->GetVirtualURL());
Camille Lamyb9ed3c52018-11-19 15:34:283329
Aran Gilman249eb122019-12-02 23:32:463330 // This is a LOG and not a CHECK/DCHECK as URL rewrite has non-deterministic
3331 // behavior: it is possible for two calls to RewriteUrlForNavigation to
3332 // return different results, leading to a different URL in the
3333 // NavigationRequest and FrameEntry. This will be fixed once we remove the
3334 // pending NavigationEntry, as we'll only make one call to
3335 // RewriteUrlForNavigation.
3336 VLOG_IF(1, (url_to_load != frame_entry->url()))
3337 << "NavigationRequest and FrameEntry have different URLs: "
3338 << url_to_load << " vs " << frame_entry->url();
Camille Lamyb9ed3c52018-11-19 15:34:283339
Camille Lamy2baa8022018-10-19 16:43:173340 // TODO(clamy): In order to remove the pending NavigationEntry,
Lukasz Anforowiczb2eb19b12020-01-25 00:40:423341 // |virtual_url| and |ignored_reverse_on_redirect| should be stored in the
Camille Lamy2baa8022018-10-19 16:43:173342 // NavigationRequest.
3343 } else {
3344 url_to_load = params.url;
3345 virtual_url = params.url;
Camille Lamyf664f7622019-01-07 19:28:243346 CHECK(!frame_entry || url_to_load == frame_entry->url());
Camille Lamy2baa8022018-10-19 16:43:173347 }
Camille Lamy5193caa2018-10-12 11:59:423348
Ehsan Karamad44fc72112019-02-26 18:15:473349 if (node->render_manager()->is_attaching_inner_delegate()) {
3350 // Avoid starting any new navigations since this node is now preparing for
3351 // attaching an inner delegate.
3352 return nullptr;
Ehsan Karamaddd9a4142018-12-04 20:38:203353 }
Camille Lamy5193caa2018-10-12 11:59:423354
Camille Lamy5193caa2018-10-12 11:59:423355 if (!IsValidURLForNavigation(node->IsMainFrame(), virtual_url, url_to_load))
3356 return nullptr;
3357
Nasko Oskov03912102019-01-11 00:21:323358 if (!DoesURLMatchOriginForNavigation(url_to_load, origin_to_commit)) {
3359 DCHECK(false) << " url:" << url_to_load
3360 << " origin:" << origin_to_commit.value();
3361 return nullptr;
3362 }
3363
Camille Lamy5193caa2018-10-12 11:59:423364 // Determine if Previews should be used for the navigation.
Hiroki Nakagawa41366152020-07-27 18:31:403365 blink::PreviewsState previews_state =
3366 blink::PreviewsTypes::PREVIEWS_UNSPECIFIED;
Camille Lamy5193caa2018-10-12 11:59:423367 if (!node->IsMainFrame()) {
3368 // For subframes, use the state of the top-level frame.
3369 previews_state = node->frame_tree()
3370 ->root()
3371 ->current_frame_host()
3372 ->last_navigation_previews_state();
3373 }
3374
Camille Lamy5193caa2018-10-12 11:59:423375 // This will be used to set the Navigation Timing API navigationStart
3376 // parameter for browser navigations in new tabs (intents, tabs opened through
3377 // "Open link in new tab"). If the navigation must wait on the current
3378 // RenderFrameHost to execute its BeforeUnload event, the navigation start
3379 // will be updated when the BeforeUnload ack is received.
3380 base::TimeTicks navigation_start = base::TimeTicks::Now();
3381
danakjd83d706d2020-11-25 22:11:123382 // Look for a pending commit that is to another document in this
3383 // FrameTreeNode. If one exists, then the last committed URL will not be the
3384 // current URL by the time this navigation commits.
3385 bool has_pending_cross_document_commit =
3386 node->render_manager()->HasPendingCommitForCrossDocumentNavigation();
danakjb952ef12021-01-14 19:58:493387 bool is_currently_error_page = node->current_frame_host()->is_error_page();
danakjd83d706d2020-11-25 22:11:123388
danakjb952ef12021-01-14 19:58:493389 mojom::NavigationType navigation_type = GetNavigationType(
3390 /*old_url=*/node->current_url(),
3391 /*new_url=*/url_to_load, reload_type, entry, *frame_entry,
3392 has_pending_cross_document_commit, is_currently_error_page,
3393 /*is_same_document_history_load=*/false);
Camille Lamy5193caa2018-10-12 11:59:423394
3395 // Create the NavigationParams based on |params|.
3396
3397 bool is_view_source_mode = virtual_url.SchemeIs(kViewSourceScheme);
Charlie Harrison8c113a32019-01-07 16:08:293398
3399 // Update |download_policy| if the virtual URL is view-source. Why do this
3400 // now? Possibly the URL could be rewritten to a view-source via some URL
3401 // handler.
3402 if (is_view_source_mode)
Yeunjoo Choi3df791a2021-02-17 07:07:253403 download_policy.SetDisallowed(blink::NavigationDownloadType::kViewSource);
Charlie Harrison8c113a32019-01-07 16:08:293404
Camille Lamy5193caa2018-10-12 11:59:423405 const GURL& history_url_for_data_url =
3406 params.base_url_for_data_url.is_empty() ? GURL() : virtual_url;
Scott Violet5ae6c42e2020-10-28 02:47:373407 // Don't use |params.transition_type| as calling code may supply a different
3408 // value.
Lucas Furukawa Gadanief8290a2019-07-29 20:27:513409 mojom::CommonNavigationParamsPtr common_params =
3410 mojom::CommonNavigationParams::New(
3411 url_to_load, params.initiator_origin,
3412 blink::mojom::Referrer::New(params.referrer.url,
3413 params.referrer.policy),
Scott Violet5ae6c42e2020-10-28 02:47:373414 transition_type, navigation_type, download_policy,
Lucas Furukawa Gadanief8290a2019-07-29 20:27:513415 should_replace_current_entry, params.base_url_for_data_url,
3416 history_url_for_data_url, previews_state, navigation_start,
3417 params.load_type == LOAD_TYPE_HTTP_POST ? "POST" : "GET",
arthursonzogniaf7c62c52020-02-12 10:49:413418 params.post_data, network::mojom::SourceLocation::New(),
3419 params.started_from_context_menu, has_user_gesture,
Antonio Sartori636adba2021-03-09 12:15:273420 false /* has_text_fragment_token */,
3421 network::mojom::CSPDisposition::CHECK, std::vector<int>(),
3422 params.href_translate,
Lucas Furukawa Gadanief8290a2019-07-29 20:27:513423 false /* is_history_navigation_in_new_child_frame */,
Charlie Hu5ffc0152019-12-06 15:59:533424 params.input_start);
Camille Lamy5193caa2018-10-12 11:59:423425
Lucas Furukawa Gadania9c45682019-07-31 22:05:143426 mojom::CommitNavigationParamsPtr commit_params =
3427 mojom::CommitNavigationParams::New(
Arthur Sonzogni367718c2021-01-25 20:55:393428 frame_entry->committed_origin(), override_user_agent,
3429 params.redirect_chain,
Lucas Furukawa Gadani81e294b2019-08-29 16:26:323430 std::vector<network::mojom::URLResponseHeadPtr>(),
Lucas Furukawa Gadania9c45682019-07-31 22:05:143431 std::vector<net::RedirectInfo>(),
3432 std::string() /* post_content_type */, common_params->url,
3433 common_params->method, params.can_load_local_resources,
3434 frame_entry->page_state(), entry->GetUniqueID(),
3435 entry->GetSubframeUniqueNames(node), true /* intended_as_new_entry */,
3436 -1 /* pending_history_list_offset */,
3437 params.should_clear_history_list ? -1 : GetLastCommittedEntryIndex(),
3438 params.should_clear_history_list ? 0 : GetEntryCount(),
3439 false /* was_discarded */, is_view_source_mode,
3440 params.should_clear_history_list, mojom::NavigationTiming::New(),
3441 base::nullopt /* appcache_host_id */,
3442 mojom::WasActivatedOption::kUnknown,
3443 base::UnguessableToken::Create() /* navigation_token */,
Lucas Furukawa Gadani97ea6382019-08-07 19:14:513444 std::vector<mojom::PrefetchedSignedExchangeInfoPtr>(),
Lucas Furukawa Gadania9c45682019-07-31 22:05:143445#if defined(OS_ANDROID)
3446 std::string(), /* data_url_as_string */
3447#endif
arthursonzogni14379782020-05-15 09:09:273448 !params.is_renderer_initiated, /* is_browser_initiated */
Sreeja Kamishetty46f762c2021-02-05 07:52:463449 node->frame_tree()->is_prerendering() /* is_prerendering */,
Tsuyoshi Horoe86d7702019-11-29 01:52:473450 GURL() /* web_bundle_physical_url */,
Charlie Hu5ffc0152019-12-06 15:59:533451 GURL() /* base_url_override_for_web_bundle */,
Yue Ru Sun128804932020-09-30 22:19:173452 ukm::kInvalidSourceId /* document_ukm_source_id */,
Jiewei Qian0406fc02020-03-09 06:02:073453 node->pending_frame_policy(),
Domenic Denicola4778c35392020-06-25 21:25:163454 std::vector<std::string>() /* force_enabled_origin_trials */,
Domenic Denicola55701ee2021-01-14 00:18:333455 false /* origin_agent_cluster */,
Maks Orlovichc66745a2020-06-30 17:40:023456 std::vector<
Shuran Huanga055ce72020-07-23 14:13:213457 network::mojom::WebClientHintsType>() /* enabled_client_hints */,
Antonio Sartori1e09fd7b2020-08-10 14:16:173458 false /* is_cross_browsing_instance */,
Rakina Zata Amni60858132020-08-19 10:33:483459 std::vector<std::string>() /* forced_content_security_policies */,
Rakina Zata Amniba3eecb2020-11-02 10:12:283460 nullptr /* old_page_info */, -1 /* http_response_code */);
Camille Lamy5193caa2018-10-12 11:59:423461#if defined(OS_ANDROID)
3462 if (ValidateDataURLAsString(params.data_url_as_string)) {
Lucas Furukawa Gadania9c45682019-07-31 22:05:143463 commit_params->data_url_as_string = params.data_url_as_string->data();
Camille Lamy5193caa2018-10-12 11:59:423464 }
3465#endif
3466
Lucas Furukawa Gadania9c45682019-07-31 22:05:143467 commit_params->was_activated = params.was_activated;
Camille Lamy5193caa2018-10-12 11:59:423468
3469 // A form submission may happen here if the navigation is a renderer-initiated
3470 // form submission that took the OpenURL path.
3471 scoped_refptr<network::ResourceRequestBody> request_body = params.post_data;
3472
3473 // extra_headers in params are \n separated; NavigationRequests want \r\n.
3474 std::string extra_headers_crlf;
3475 base::ReplaceChars(params.extra_headers, "\n", "\r\n", &extra_headers_crlf);
Yao Xiaodc5ed102019-06-04 19:19:093476
3477 auto navigation_request = NavigationRequest::CreateBrowserInitiated(
Lucas Furukawa Gadania9c45682019-07-31 22:05:143478 node, std::move(common_params), std::move(commit_params),
Takashi Toyoshimae87b7be2021-01-22 11:51:083479 !params.is_renderer_initiated, params.was_opener_suppressed,
Antonio Sartori9a82f6f32020-12-14 09:22:453480 params.initiator_frame_token.has_value()
3481 ? &(params.initiator_frame_token.value())
3482 : nullptr,
3483 params.initiator_process_id, extra_headers_crlf, frame_entry, entry,
3484 request_body,
John Delaney50425f82020-04-07 16:26:213485 params.navigation_ui_data ? params.navigation_ui_data->Clone() : nullptr,
3486 params.impression);
Yao Xiaodc5ed102019-06-04 19:19:093487 navigation_request->set_from_download_cross_origin_redirect(
3488 params.from_download_cross_origin_redirect);
3489 return navigation_request;
Camille Lamy5193caa2018-10-12 11:59:423490}
3491
3492std::unique_ptr<NavigationRequest>
3493NavigationControllerImpl::CreateNavigationRequestFromEntry(
clamyea99ea12018-05-28 13:54:233494 FrameTreeNode* frame_tree_node,
Lucas Furukawa Gadani5553a1582019-01-08 18:55:573495 NavigationEntryImpl* entry,
clamyea99ea12018-05-28 13:54:233496 FrameNavigationEntry* frame_entry,
3497 ReloadType reload_type,
3498 bool is_same_document_history_load,
Arthur Hemerybee4a752019-05-29 10:50:553499 bool is_history_navigation_in_new_child_frame) {
Alex Moshchuk47d1a4bd2020-06-01 22:15:343500 DCHECK(frame_entry);
clamyea99ea12018-05-28 13:54:233501 GURL dest_url = frame_entry->url();
Nasko Oskov03912102019-01-11 00:21:323502 base::Optional<url::Origin> origin_to_commit =
3503 frame_entry->committed_origin();
3504
clamyea99ea12018-05-28 13:54:233505 Referrer dest_referrer = frame_entry->referrer();
Ryan Sturmc4da1992018-07-17 16:59:013506 if (reload_type == ReloadType::ORIGINAL_REQUEST_URL &&
Lucas Furukawa Gadani5553a1582019-01-08 18:55:573507 entry->GetOriginalRequestURL().is_valid() && !entry->GetHasPostData()) {
clamyea99ea12018-05-28 13:54:233508 // We may have been redirected when navigating to the current URL.
3509 // Use the URL the user originally intended to visit as signaled by the
3510 // ReloadType, if it's valid and if a POST wasn't involved; the latter
Ryan Sturmc4da1992018-07-17 16:59:013511 // case avoids issues with sending data to the wrong page.
Lucas Furukawa Gadani5553a1582019-01-08 18:55:573512 dest_url = entry->GetOriginalRequestURL();
clamyea99ea12018-05-28 13:54:233513 dest_referrer = Referrer();
Nasko Oskov03912102019-01-11 00:21:323514 origin_to_commit.reset();
clamyea99ea12018-05-28 13:54:233515 }
3516
Ehsan Karamad44fc72112019-02-26 18:15:473517 if (frame_tree_node->render_manager()->is_attaching_inner_delegate()) {
3518 // Avoid starting any new navigations since this node is now preparing for
3519 // attaching an inner delegate.
3520 return nullptr;
Ehsan Karamaddd9a4142018-12-04 20:38:203521 }
3522
Camille Lamy5193caa2018-10-12 11:59:423523 if (!IsValidURLForNavigation(frame_tree_node->IsMainFrame(),
Lucas Furukawa Gadani5553a1582019-01-08 18:55:573524 entry->GetVirtualURL(), dest_url)) {
clamyea99ea12018-05-28 13:54:233525 return nullptr;
3526 }
3527
Nasko Oskov03912102019-01-11 00:21:323528 if (!DoesURLMatchOriginForNavigation(dest_url, origin_to_commit)) {
Kunihiko Sakamoto873601c52021-02-24 05:46:073529 if (!frame_tree_node->IsMainFrame() && dest_url.SchemeIs(url::kUrnScheme)) {
3530 NOTIMPLEMENTED()
3531 << "History navigation to urn:uuid resource in WebBundle is not"
3532 "implemented. See crbug.com/1180697";
3533 } else {
3534 DCHECK(false) << " url:" << dest_url
3535 << " origin:" << origin_to_commit.value();
3536 }
Nasko Oskov03912102019-01-11 00:21:323537 return nullptr;
3538 }
3539
clamyea99ea12018-05-28 13:54:233540 // Determine if Previews should be used for the navigation.
Hiroki Nakagawa41366152020-07-27 18:31:403541 blink::PreviewsState previews_state =
3542 blink::PreviewsTypes::PREVIEWS_UNSPECIFIED;
clamyea99ea12018-05-28 13:54:233543 if (!frame_tree_node->IsMainFrame()) {
3544 // For subframes, use the state of the top-level frame.
3545 previews_state = frame_tree_node->frame_tree()
3546 ->root()
3547 ->current_frame_host()
3548 ->last_navigation_previews_state();
clamyea99ea12018-05-28 13:54:233549 }
3550
clamyea99ea12018-05-28 13:54:233551 // This will be used to set the Navigation Timing API navigationStart
3552 // parameter for browser navigations in new tabs (intents, tabs opened through
3553 // "Open link in new tab"). If the navigation must wait on the current
3554 // RenderFrameHost to execute its BeforeUnload event, the navigation start
3555 // will be updated when the BeforeUnload ack is received.
3556 base::TimeTicks navigation_start = base::TimeTicks::Now();
clamyea99ea12018-05-28 13:54:233557
danakjd83d706d2020-11-25 22:11:123558 // Look for a pending commit that is to another document in this
3559 // FrameTreeNode. If one exists, then the last committed URL will not be the
3560 // current URL by the time this navigation commits.
3561 bool has_pending_cross_document_commit =
3562 frame_tree_node->render_manager()
3563 ->HasPendingCommitForCrossDocumentNavigation();
danakjb952ef12021-01-14 19:58:493564 bool is_currently_error_page =
3565 frame_tree_node->current_frame_host()->is_error_page();
danakjd83d706d2020-11-25 22:11:123566
Lucas Furukawa Gadanief8290a2019-07-29 20:27:513567 mojom::NavigationType navigation_type = GetNavigationType(
danakjd83d706d2020-11-25 22:11:123568 /*old_url=*/frame_tree_node->current_url(),
3569 /*new_url=*/dest_url, reload_type, entry, *frame_entry,
danakjb952ef12021-01-14 19:58:493570 has_pending_cross_document_commit, is_currently_error_page,
3571 is_same_document_history_load);
Camille Lamy5193caa2018-10-12 11:59:423572
3573 // A form submission may happen here if the navigation is a
3574 // back/forward/reload navigation that does a form resubmission.
3575 scoped_refptr<network::ResourceRequestBody> request_body;
3576 std::string post_content_type;
3577 if (frame_entry->method() == "POST") {
3578 request_body = frame_entry->GetPostData(&post_content_type);
3579 // Might have a LF at end.
3580 post_content_type =
3581 base::TrimWhitespaceASCII(post_content_type, base::TRIM_ALL)
3582 .as_string();
3583 }
3584
3585 // Create the NavigationParams based on |entry| and |frame_entry|.
Lucas Furukawa Gadanief8290a2019-07-29 20:27:513586 mojom::CommonNavigationParamsPtr common_params =
3587 entry->ConstructCommonNavigationParams(
3588 *frame_entry, request_body, dest_url,
3589 blink::mojom::Referrer::New(dest_referrer.url, dest_referrer.policy),
3590 navigation_type, previews_state, navigation_start,
Charlie Hu5ffc0152019-12-06 15:59:533591 base::TimeTicks() /* input_start */);
Lucas Furukawa Gadanief8290a2019-07-29 20:27:513592 common_params->is_history_navigation_in_new_child_frame =
Arthur Hemerybee4a752019-05-29 10:50:553593 is_history_navigation_in_new_child_frame;
Camille Lamy5193caa2018-10-12 11:59:423594
3595 // TODO(clamy): |intended_as_new_entry| below should always be false once
3596 // Reload no longer leads to this being called for a pending NavigationEntry
3597 // of index -1.
Lucas Furukawa Gadania9c45682019-07-31 22:05:143598 mojom::CommitNavigationParamsPtr commit_params =
3599 entry->ConstructCommitNavigationParams(
3600 *frame_entry, common_params->url, origin_to_commit,
3601 common_params->method, entry->GetSubframeUniqueNames(frame_tree_node),
3602 GetPendingEntryIndex() == -1 /* intended_as_new_entry */,
Charlie Hu5ffc0152019-12-06 15:59:533603 GetIndexOfEntry(entry), GetLastCommittedEntryIndex(), GetEntryCount(),
3604 frame_tree_node->pending_frame_policy());
Lucas Furukawa Gadania9c45682019-07-31 22:05:143605 commit_params->post_content_type = post_content_type;
Camille Lamy5193caa2018-10-12 11:59:423606
clamyea99ea12018-05-28 13:54:233607 return NavigationRequest::CreateBrowserInitiated(
Lucas Furukawa Gadania9c45682019-07-31 22:05:143608 frame_tree_node, std::move(common_params), std::move(commit_params),
Takashi Toyoshimae87b7be2021-01-22 11:51:083609 !entry->is_renderer_initiated(), false /* was_opener_suppressed */,
3610 nullptr /* initiator_frame_token */,
Antonio Sartori9a82f6f32020-12-14 09:22:453611 ChildProcessHost::kInvalidUniqueID /* initiator_process_id */,
3612 entry->extra_headers(), frame_entry, entry, request_body,
3613 nullptr /* navigation_ui_data */, base::nullopt /* impression */);
clamyea99ea12018-05-28 13:54:233614}
3615
[email protected]d202a7c2012-01-04 07:53:473616void NavigationControllerImpl::NotifyNavigationEntryCommitted(
[email protected]8ff00d72012-10-23 19:12:213617 LoadCommittedDetails* details) {
[email protected]6286a3792013-10-09 04:03:273618 details->entry = GetLastCommittedEntry();
[email protected]df1af242009-05-01 00:11:403619
[email protected]2db9bd72012-04-13 20:20:563620 // We need to notify the ssl_manager_ before the web_contents_ so the
[email protected]df1af242009-05-01 00:11:403621 // location bar will have up-to-date information about the security style
3622 // when it wants to draw. See http://crbug.com/11157
[email protected]b0f724c2013-09-05 04:21:133623 ssl_manager_.DidCommitProvisionalLoad(*details);
[email protected]df1af242009-05-01 00:11:403624
[email protected]7f924832014-08-09 05:57:223625 delegate_->NotifyNavigationStateChanged(INVALIDATE_TYPE_ALL);
[email protected]ec6c05f2013-10-23 18:41:573626 delegate_->NotifyNavigationEntryCommitted(*details);
[email protected]cbb1ef592013-06-05 19:49:463627
[email protected]b0f724c2013-09-05 04:21:133628 // TODO(avi): Remove. http://crbug.com/170921
3629 NotificationDetails notification_details =
3630 Details<LoadCommittedDetails>(details);
Aran Gilman37d11632019-10-08 23:07:153631 NotificationService::current()->Notify(NOTIFICATION_NAV_ENTRY_COMMITTED,
3632 Source<NavigationController>(this),
3633 notification_details);
initial.commit09911bf2008-07-26 23:55:293634}
3635
initial.commit09911bf2008-07-26 23:55:293636// static
[email protected]d202a7c2012-01-04 07:53:473637size_t NavigationControllerImpl::max_entry_count() {
[email protected]9b51970d2011-12-09 23:10:233638 if (max_entry_count_for_testing_ != kMaxEntryCountForTestingNotSet)
Aran Gilman37d11632019-10-08 23:07:153639 return max_entry_count_for_testing_;
[email protected]8ff00d72012-10-23 19:12:213640 return kMaxSessionHistoryEntries;
[email protected]9b51970d2011-12-09 23:10:233641}
3642
[email protected]d202a7c2012-01-04 07:53:473643void NavigationControllerImpl::SetActive(bool is_active) {
[email protected]ee613922009-09-02 20:38:223644 if (is_active && needs_reload_)
3645 LoadIfNecessary();
initial.commit09911bf2008-07-26 23:55:293646}
3647
[email protected]d202a7c2012-01-04 07:53:473648void NavigationControllerImpl::LoadIfNecessary() {
initial.commit09911bf2008-07-26 23:55:293649 if (!needs_reload_)
3650 return;
3651
Bo Liucdfa4b12018-11-06 00:21:443652 UMA_HISTOGRAM_ENUMERATION("Navigation.LoadIfNecessaryType",
3653 needs_reload_type_);
3654
initial.commit09911bf2008-07-26 23:55:293655 // Calling Reload() results in ignoring state, and not loading.
3656 // Explicitly use NavigateToPendingEntry so that the renderer uses the
3657 // cached state.
avicc872d7242015-08-19 21:26:343658 if (pending_entry_) {
Dave Tapuska8bfd84c2019-03-26 20:47:163659 NavigateToExistingPendingEntry(ReloadType::NONE,
3660 FrameTreeNode::kFrameTreeNodeInvalidId);
avicc872d7242015-08-19 21:26:343661 } else if (last_committed_entry_index_ != -1) {
arthursonzogni5c4c202d2017-04-25 23:41:273662 pending_entry_ = entries_[last_committed_entry_index_].get();
avicc872d7242015-08-19 21:26:343663 pending_entry_index_ = last_committed_entry_index_;
Dave Tapuska8bfd84c2019-03-26 20:47:163664 NavigateToExistingPendingEntry(ReloadType::NONE,
3665 FrameTreeNode::kFrameTreeNodeInvalidId);
avicc872d7242015-08-19 21:26:343666 } else {
3667 // If there is something to reload, the successful reload will clear the
3668 // |needs_reload_| flag. Otherwise, just do it here.
3669 needs_reload_ = false;
3670 }
initial.commit09911bf2008-07-26 23:55:293671}
3672
Carlos IL42b416592019-10-07 23:10:363673void NavigationControllerImpl::LoadPostCommitErrorPage(
3674 RenderFrameHost* render_frame_host,
3675 const GURL& url,
3676 const std::string& error_page_html,
3677 net::Error error) {
Sreeja Kamishetty0be2ac52020-05-28 01:47:463678 // Only active frames can load post-commit error pages:
3679 // - If the frame is in pending deletion, the browser already committed to
3680 // destroying this RenderFrameHost so ignore loading the error page.
3681 // - If the frame is in back-forward cache, it's not allowed to navigate as it
3682 // should remain frozen. Ignore the request and evict the document from
3683 // back-forward cache.
3684 if (static_cast<RenderFrameHostImpl*>(render_frame_host)
3685 ->IsInactiveAndDisallowReactivation()) {
John Delaney56f73332019-11-04 19:39:253686 return;
Sreeja Kamishetty0be2ac52020-05-28 01:47:463687 }
Rakina Zata Amni919b7922020-12-11 09:03:133688 RenderFrameHostImpl* rfhi =
3689 static_cast<RenderFrameHostImpl*>(render_frame_host);
3690 FrameTreeNode* node = rfhi->frame_tree_node();
John Delaney131ad362019-08-08 21:57:413691
3692 mojom::CommonNavigationParamsPtr common_params =
3693 CreateCommonNavigationParams();
Rakina Zata Amnid2da1542020-12-23 00:52:593694 // |url| might be empty, such as when LoadPostCommitErrorPage happens before
3695 // the frame actually committed (e.g. iframe with "src" set to a
3696 // slow-responding URL). We should rewrite the URL to about:blank in this
3697 // case, as the renderer will only think a page is an error page if it has a
3698 // non-empty unreachable URL.
Rakina Zata Amni919b7922020-12-11 09:03:133699 common_params->url = url.is_empty() ? GURL("about:blank") : url;
John Delaney131ad362019-08-08 21:57:413700 mojom::CommitNavigationParamsPtr commit_params =
3701 CreateCommitNavigationParams();
3702
arthursonzogni70ac7302020-05-28 08:49:053703 // Error pages have a fully permissive FramePolicy.
3704 // TODO(arthursonzogni): Consider providing the minimal capabilities to the
3705 // error pages.
3706 commit_params->frame_policy = blink::FramePolicy();
3707
John Delaney131ad362019-08-08 21:57:413708 std::unique_ptr<NavigationRequest> navigation_request =
3709 NavigationRequest::CreateBrowserInitiated(
3710 node, std::move(common_params), std::move(commit_params),
Takashi Toyoshimae87b7be2021-01-22 11:51:083711 true /* browser_initiated */, false /* was_opener_suppressed */,
Lingqi Chi82efa95e2020-12-29 05:31:193712 nullptr /* initiator_frame_token */,
Antonio Sartori9a82f6f32020-12-14 09:22:453713 ChildProcessHost::kInvalidUniqueID /* initiator_process_id */,
John Delaneyf43556d2020-05-04 23:19:063714 "" /* extra_headers */, nullptr /* frame_entry */,
3715 nullptr /* entry */, nullptr /* post_body */,
3716 nullptr /* navigation_ui_data */, base::nullopt /* impression */);
Carlos IL42b416592019-10-07 23:10:363717 navigation_request->set_post_commit_error_page_html(error_page_html);
John Delaney131ad362019-08-08 21:57:413718 navigation_request->set_net_error(error);
3719 node->CreatedNavigationRequest(std::move(navigation_request));
3720 DCHECK(node->navigation_request());
3721 node->navigation_request()->BeginNavigation();
3722}
3723
Lucas Furukawa Gadani5553a1582019-01-08 18:55:573724void NavigationControllerImpl::NotifyEntryChanged(NavigationEntry* entry) {
[email protected]8ff00d72012-10-23 19:12:213725 EntryChangedDetails det;
[email protected]534e54b2008-08-13 15:40:093726 det.changed_entry = entry;
Aran Gilman37d11632019-10-08 23:07:153727 det.index = GetIndexOfEntry(NavigationEntryImpl::FromNavigationEntry(entry));
Sam McNally5c087a32017-08-25 01:46:143728 delegate_->NotifyNavigationEntryChanged(det);
initial.commit09911bf2008-07-26 23:55:293729}
3730
[email protected]d202a7c2012-01-04 07:53:473731void NavigationControllerImpl::FinishRestore(int selected_index,
[email protected]2ca1ea662012-10-04 02:26:363732 RestoreType type) {
[email protected]a26023822011-12-29 00:23:553733 DCHECK(selected_index >= 0 && selected_index < GetEntryCount());
[email protected]2ca1ea662012-10-04 02:26:363734 ConfigureEntriesForRestore(&entries_, type);
initial.commit09911bf2008-07-26 23:55:293735
initial.commit09911bf2008-07-26 23:55:293736 last_committed_entry_index_ = selected_index;
initial.commit09911bf2008-07-26 23:55:293737}
[email protected]765b35502008-08-21 00:51:203738
arthursonzogni69a6a1b2019-09-17 09:23:003739void NavigationControllerImpl::DiscardNonCommittedEntries() {
Michael Thiessen9b14d512019-09-23 21:19:473740 // Avoid sending a notification if there is nothing to discard.
Michael Thiessenc5676d22019-09-25 22:32:103741 // TODO(mthiesse): Temporarily checking failed_pending_entry_id_ to help
3742 // diagnose https://bugs.chromium.org/p/chromium/issues/detail?id=1007570.
Carlos IL4dea8902020-05-26 15:14:293743 if (!pending_entry_ && failed_pending_entry_id_ == 0) {
Michael Thiessen9b14d512019-09-23 21:19:473744 return;
Michael Thiessenc5676d22019-09-25 22:32:103745 }
avi45a72532015-04-07 21:01:453746 DiscardPendingEntry(false);
arthursonzogni69a6a1b2019-09-17 09:23:003747 if (delegate_)
3748 delegate_->NotifyNavigationStateChanged(INVALIDATE_TYPE_ALL);
[email protected]b12eb222013-09-10 00:11:483749}
3750
avi7c6f35e2015-05-08 17:52:383751int NavigationControllerImpl::GetEntryIndexWithUniqueID(
3752 int nav_entry_id) const {
3753 for (int i = static_cast<int>(entries_.size()) - 1; i >= 0; --i) {
3754 if (entries_[i]->GetUniqueID() == nav_entry_id)
3755 return i;
3756 }
3757 return -1;
3758}
3759
[email protected]d202a7c2012-01-04 07:53:473760void NavigationControllerImpl::InsertEntriesFrom(
Lucas Furukawa Gadani5553a1582019-01-08 18:55:573761 NavigationControllerImpl* source,
[email protected]e1cd5452010-08-26 18:03:253762 int max_index) {
Lucas Furukawa Gadani5553a1582019-01-08 18:55:573763 DCHECK_LE(max_index, source->GetEntryCount());
[email protected]e1cd5452010-08-26 18:03:253764 for (int i = 0; i < max_index; i++) {
Nasko Oskov923ca482020-12-04 21:20:463765 // TODO(creis): Once we start sharing FrameNavigationEntries between
3766 // NavigationEntries, it will not be safe to share them with another tab.
3767 // Must have a version of Clone that recreates them.
3768 entries_.insert(entries_.begin() + i, source->entries_[i]->Clone());
[email protected]e1cd5452010-08-26 18:03:253769 }
arthursonzogni5c4c202d2017-04-25 23:41:273770 DCHECK(pending_entry_index_ == -1 ||
3771 pending_entry_ == GetEntryAtIndex(pending_entry_index_));
[email protected]e1cd5452010-08-26 18:03:253772}
[email protected]c5b88d82012-10-06 17:03:333773
3774void NavigationControllerImpl::SetGetTimestampCallbackForTest(
Makoto Shimazud2aa2202019-10-09 13:57:183775 const base::RepeatingCallback<base::Time()>& get_timestamp_callback) {
[email protected]c5b88d82012-10-06 17:03:333776 get_timestamp_callback_ = get_timestamp_callback;
3777}
[email protected]8ff00d72012-10-23 19:12:213778
Shivani Sharmaffb32b82019-04-09 16:58:473779// History manipulation intervention:
3780void NavigationControllerImpl::SetShouldSkipOnBackForwardUIIfNeeded(
Shivani Sharmaffb32b82019-04-09 16:58:473781 bool replace_entry,
3782 bool previous_document_was_activated,
Alexander Timine3ec4192020-04-20 16:39:403783 bool is_renderer_initiated,
3784 ukm::SourceId previous_page_load_ukm_source_id) {
Shivani Sharma712d5d72019-04-16 21:56:453785 // Note that for a subframe, previous_document_was_activated is true if the
3786 // gesture happened in any subframe (propagated to main frame) or in the main
3787 // frame itself.
Shivani Sharmaffb32b82019-04-09 16:58:473788 if (replace_entry || previous_document_was_activated ||
shivanigithubcceeacf2020-03-06 20:00:273789 !is_renderer_initiated) {
Shivani Sharmaffb32b82019-04-09 16:58:473790 if (last_committed_entry_index_ != -1) {
shivanigithube92c33da2020-09-14 13:01:413791 // This histogram always counts when navigating away from an entry,
3792 // irrespective of whether the skippable flag was changed or not, and
3793 // whether this entry is being reused or not.
Shivani Sharmaffb32b82019-04-09 16:58:473794 UMA_HISTOGRAM_BOOLEAN(
shivanigithube92c33da2020-09-14 13:01:413795 "Navigation.BackForward.SetShouldSkipOnBackForwardUI",
3796 GetEntryAtIndex(last_committed_entry_index_)
3797 ->should_skip_on_back_forward_ui());
Shivani Sharmaffb32b82019-04-09 16:58:473798 }
3799 return;
3800 }
3801 if (last_committed_entry_index_ == -1)
3802 return;
3803
Shivani Sharmac4cc8922019-04-18 03:11:173804 SetSkippableForSameDocumentEntries(last_committed_entry_index_, true);
Shivani Sharmaffb32b82019-04-09 16:58:473805 UMA_HISTOGRAM_BOOLEAN("Navigation.BackForward.SetShouldSkipOnBackForwardUI",
3806 true);
3807
Alexander Timine3ec4192020-04-20 16:39:403808 // Log UKM with the URL we are navigating away from.
3809 ukm::builders::HistoryManipulationIntervention(
3810 previous_page_load_ukm_source_id)
3811 .Record(ukm::UkmRecorder::Get());
Shivani Sharmaffb32b82019-04-09 16:58:473812}
3813
Shivani Sharmac4cc8922019-04-18 03:11:173814void NavigationControllerImpl::SetSkippableForSameDocumentEntries(
3815 int reference_index,
3816 bool skippable) {
3817 auto* reference_entry = GetEntryAtIndex(reference_index);
3818 reference_entry->set_should_skip_on_back_forward_ui(skippable);
3819
3820 int64_t document_sequence_number =
3821 reference_entry->root_node()->frame_entry->document_sequence_number();
3822 for (int index = 0; index < GetEntryCount(); index++) {
3823 auto* entry = GetEntryAtIndex(index);
3824 if (entry->root_node()->frame_entry->document_sequence_number() ==
3825 document_sequence_number) {
3826 entry->set_should_skip_on_back_forward_ui(skippable);
3827 }
3828 }
3829}
3830
arthursonzogni66f711c2019-10-08 14:40:363831std::unique_ptr<NavigationControllerImpl::PendingEntryRef>
3832NavigationControllerImpl::ReferencePendingEntry() {
3833 DCHECK(pending_entry_);
3834 auto pending_entry_ref =
3835 std::make_unique<PendingEntryRef>(weak_factory_.GetWeakPtr());
3836 pending_entry_refs_.insert(pending_entry_ref.get());
3837 return pending_entry_ref;
3838}
3839
3840void NavigationControllerImpl::PendingEntryRefDeleted(PendingEntryRef* ref) {
3841 // Ignore refs that don't correspond to the current pending entry.
3842 auto it = pending_entry_refs_.find(ref);
3843 if (it == pending_entry_refs_.end())
3844 return;
3845 pending_entry_refs_.erase(it);
3846
3847 if (!pending_entry_refs_.empty())
3848 return;
3849
3850 // The pending entry may be deleted before the last PendingEntryRef.
3851 if (!pending_entry_)
3852 return;
3853
3854 // We usually clear the pending entry when the matching NavigationRequest
3855 // fails, so that an arbitrary URL isn't left visible above a committed page.
3856 //
3857 // However, we do preserve the pending entry in some cases, such as on the
3858 // initial navigation of an unmodified blank tab. We also allow the delegate
3859 // to say when it's safe to leave aborted URLs in the omnibox, to let the
3860 // user edit the URL and try again. This may be useful in cases that the
3861 // committed page cannot be attacker-controlled. In these cases, we still
3862 // allow the view to clear the pending entry and typed URL if the user
3863 // requests (e.g., hitting Escape with focus in the address bar).
3864 //
3865 // Do not leave the pending entry visible if it has an invalid URL, since this
3866 // might be formatted in an unexpected or unsafe way.
3867 // TODO(creis): Block navigations to invalid URLs in https://crbug.com/850824.
arthursonzogni66f711c2019-10-08 14:40:363868 bool should_preserve_entry =
3869 (pending_entry_ == GetVisibleEntry()) &&
3870 pending_entry_->GetURL().is_valid() &&
3871 (IsUnmodifiedBlankTab() || delegate_->ShouldPreserveAbortedURLs());
3872 if (should_preserve_entry)
3873 return;
3874
3875 DiscardPendingEntry(true);
3876 delegate_->NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
3877}
3878
Titouan Rigoudy6ec70402021-02-02 15:42:193879std::unique_ptr<PolicyContainerPolicies>
3880NavigationControllerImpl::ComputePolicyContainerPoliciesForFrameEntry(
Antonio Sartori78a749f2020-11-30 12:03:393881 RenderFrameHostImpl* rfh,
3882 bool is_same_document,
3883 NavigationRequest* request) {
Titouan Rigoudy6ec70402021-02-02 15:42:193884 if (!ShouldStorePolicyContainerPoliciesInFrameNavigationEntry(request))
Antonio Sartori78a749f2020-11-30 12:03:393885 return nullptr;
3886
3887 if (is_same_document) {
3888 FrameNavigationEntry* previous_frame_entry =
3889 GetLastCommittedEntry()->GetFrameEntry(rfh->frame_tree_node());
3890
3891 // TODO(https://crbug.com/608402): Remove this nullptr check when we can
3892 // ensure we always have a FrameNavigationEntry here.
3893 if (!previous_frame_entry)
3894 return nullptr;
3895
Titouan Rigoudy6ec70402021-02-02 15:42:193896 const PolicyContainerPolicies* previous_policies =
3897 previous_frame_entry->policy_container_policies();
Antonio Sartori78a749f2020-11-30 12:03:393898
Titouan Rigoudy6ec70402021-02-02 15:42:193899 if (!previous_policies)
Antonio Sartori78a749f2020-11-30 12:03:393900 return nullptr;
3901
3902 // Make a copy of the policy container for the new FrameNavigationEntry.
Antonio Sartori5d09b30f2021-03-02 09:27:163903 return previous_policies->Clone();
Antonio Sartori78a749f2020-11-30 12:03:393904 }
3905
3906 if (!request->IsWaitingToCommit()) {
3907 // This is the initial, "fake" navigation to about:blank. The
3908 // NavigationRequest contains a dummy policy container, while the
3909 // RenderFrameHost already inherited the policy container from the
3910 // creator, so let's take the policies from there.
Antonio Sartori5d09b30f2021-03-02 09:27:163911 return rfh->policy_container_host()->policies().Clone();
Antonio Sartori78a749f2020-11-30 12:03:393912 }
3913
3914 // Take the policy container from the request since we did not move it
3915 // into the RFH yet.
Antonio Sartori5d09b30f2021-03-02 09:27:163916 return request->GetPolicyContainerPolicies().Clone();
Antonio Sartori78a749f2020-11-30 12:03:393917}
3918
Carlos Caballeroede6f8c2021-01-28 11:01:503919void NavigationControllerImpl::SetHistoryOffsetAndLength(int history_offset,
3920 int history_length) {
3921 OPTIONAL_TRACE_EVENT2(
3922 "content", "NavigationControllerImpl::SetHistoryOffsetAndLength",
3923 "history_offset", history_offset, "history_length", history_length);
3924
3925 auto callback = base::BindRepeating(
3926 [](int history_offset, int history_length, RenderViewHostImpl* rvh) {
3927 if (auto& broadcast = rvh->GetAssociatedPageBroadcast()) {
3928 broadcast->SetHistoryOffsetAndLength(history_offset, history_length);
3929 }
3930 },
3931 history_offset, history_length);
3932 frame_tree_.root()->render_manager()->ExecutePageBroadcastMethod(callback);
3933}
3934
3935void NavigationControllerImpl::DidAccessInitialMainDocument() {
3936 // We may have left a failed browser-initiated navigation in the address bar
3937 // to let the user edit it and try again. Clear it now that content might
3938 // show up underneath it.
3939 if (!frame_tree_.IsLoading() && GetPendingEntry())
3940 DiscardPendingEntry(false);
3941
3942 // Update the URL display.
3943 delegate_->NotifyNavigationStateChanged(INVALIDATE_TYPE_URL);
3944}
3945
3946void NavigationControllerImpl::UpdateStateForFrame(
3947 RenderFrameHostImpl* rfhi,
3948 const blink::PageState& page_state) {
3949 OPTIONAL_TRACE_EVENT1(
3950 "content", "NavigationControllerImpl::UpdateStateForFrame",
3951 "render_frame_host", base::trace_event::ToTracedValue(rfhi));
3952 // The state update affects the last NavigationEntry associated with the given
3953 // |render_frame_host|. This may not be the last committed NavigationEntry (as
3954 // in the case of an UpdateState from a frame being swapped out). We track
3955 // which entry this is in the RenderFrameHost's nav_entry_id.
3956 NavigationEntryImpl* entry = GetEntryWithUniqueID(rfhi->nav_entry_id());
3957 if (!entry)
3958 return;
3959
3960 FrameNavigationEntry* frame_entry =
3961 entry->GetFrameEntry(rfhi->frame_tree_node());
3962 if (!frame_entry)
3963 return;
3964
3965 // The SiteInstance might not match if we do a cross-process navigation with
3966 // replacement (e.g., auto-subframe), in which case the swap out of the old
3967 // RenderFrameHost runs in the background after the old FrameNavigationEntry
3968 // has already been replaced and destroyed.
3969 if (frame_entry->site_instance() != rfhi->GetSiteInstance())
3970 return;
3971
3972 if (page_state == frame_entry->page_state())
3973 return; // Nothing to update.
3974
3975 DCHECK(page_state.IsValid()) << "Shouldn't set an empty PageState.";
3976
3977 // The document_sequence_number and item_sequence_number recorded in the
3978 // FrameNavigationEntry should not differ from the one coming with the update,
3979 // since it must come from the same document. Do not update it if a difference
3980 // is detected, as this indicates that |frame_entry| is not the correct one.
3981 blink::ExplodedPageState exploded_state;
3982 if (!blink::DecodePageState(page_state.ToEncodedData(), &exploded_state))
3983 return;
3984
3985 if (exploded_state.top.document_sequence_number !=
3986 frame_entry->document_sequence_number() ||
3987 exploded_state.top.item_sequence_number !=
3988 frame_entry->item_sequence_number()) {
3989 return;
3990 }
3991
3992 frame_entry->SetPageState(page_state);
3993 NotifyEntryChanged(entry);
3994}
3995
[email protected]8ff00d72012-10-23 19:12:213996} // namespace content