Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 5 | /* |
| 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 | |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 36 | #include "content/browser/renderer_host/navigation_controller_impl.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 37 | |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 38 | #include <algorithm> |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame] | 39 | #include <utility> |
| 40 | |
[email protected] | c5b88d8 | 2012-10-06 17:03:33 | [diff] [blame] | 41 | #include "base/bind.h" |
[email protected] | eabfe191 | 2014-05-12 10:07:28 | [diff] [blame] | 42 | #include "base/command_line.h" |
Ayu Ishii | 2f82585 | 2022-03-08 19:47:38 | [diff] [blame] | 43 | #include "base/containers/adapters.h" |
Rakina Zata Amni | 627360d | 2022-02-24 00:53:40 | [diff] [blame] | 44 | #include "base/debug/dump_without_crashing.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 45 | #include "base/logging.h" |
asvitkine | 3033081 | 2016-08-30 04:01:08 | [diff] [blame] | 46 | #include "base/metrics/histogram_macros.h" |
Charlie Reis | 23c26da | 2022-01-29 00:57:47 | [diff] [blame] | 47 | #include "base/numerics/safe_conversions.h" |
Ryan Hamilton | 7f3bd3d | 2022-04-23 00:07:39 | [diff] [blame] | 48 | #include "base/strings/escape.h" |
Peter Kasting | b53b8191 | 2021-04-28 19:23:30 | [diff] [blame] | 49 | #include "base/strings/string_piece.h" |
[email protected] | 348fbaac | 2013-06-11 06:31:51 | [diff] [blame] | 50 | #include "base/strings/string_util.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 51 | #include "base/strings/utf_string_conversions.h" |
[email protected] | a43858f | 2013-06-28 15:18:37 | [diff] [blame] | 52 | #include "base/time/time.h" |
Carlos Caballero | 40b0efd | 2021-01-26 11:55:00 | [diff] [blame] | 53 | #include "base/trace_event/optional_trace_event.h" |
Carlos Caballero | ede6f8c | 2021-01-28 11:01:50 | [diff] [blame] | 54 | #include "base/trace_event/trace_conversion_helper.h" |
ssid | 3e76561 | 2015-01-28 04:03:42 | [diff] [blame] | 55 | #include "base/trace_event/trace_event.h" |
Daniel Cheng | abb00686 | 2022-09-09 22:39:08 | [diff] [blame] | 56 | #include "base/types/optional_util.h" |
servolk | f395553 | 2015-05-16 00:01:59 | [diff] [blame] | 57 | #include "build/build_config.h" |
[email protected] | eabfe191 | 2014-05-12 10:07:28 | [diff] [blame] | 58 | #include "cc/base/switches.h" |
jamescook | da250581 | 2015-03-20 18:01:18 | [diff] [blame] | 59 | #include "content/browser/bad_message.h" |
Marijn Kruisselbrink | 0c87e6e | 2018-06-22 22:57:39 | [diff] [blame] | 60 | #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
[email protected] | 825b166 | 2012-03-12 19:07:31 | [diff] [blame] | 61 | #include "content/browser/browser_url_handler_impl.h" |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 62 | #include "content/browser/dom_storage/dom_storage_context_wrapper.h" |
[email protected] | 1ea3c79 | 2012-04-17 01:25:04 | [diff] [blame] | 63 | #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 64 | #include "content/browser/renderer_host/debug_urls.h" |
| 65 | #include "content/browser/renderer_host/frame_tree.h" |
Carlos Caballero | 40b0efd | 2021-01-26 11:55:00 | [diff] [blame] | 66 | #include "content/browser/renderer_host/frame_tree_node.h" |
Chris Bookholt | 27faf8d | 2022-01-20 01:03:33 | [diff] [blame] | 67 | #include "content/browser/renderer_host/navigation_controller_delegate.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 68 | #include "content/browser/renderer_host/navigation_entry_impl.h" |
Nate Chapin | 214a86a | 2021-06-21 20:35:57 | [diff] [blame] | 69 | #include "content/browser/renderer_host/navigation_entry_restore_context_impl.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 70 | #include "content/browser/renderer_host/navigation_request.h" |
| 71 | #include "content/browser/renderer_host/navigator.h" |
| 72 | #include "content/browser/renderer_host/render_frame_host_delegate.h" |
Carlos Caballero | 40b0efd | 2021-01-26 11:55:00 | [diff] [blame] | 73 | #include "content/browser/renderer_host/render_view_host_impl.h" |
Sharon Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 74 | #include "content/browser/site_info.h" |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 75 | #include "content/browser/site_instance_impl.h" |
Kunihiko Sakamoto | 346a74e | 2021-03-10 08:57:48 | [diff] [blame] | 76 | #include "content/browser/web_package/subresource_web_bundle_navigation_info.h" |
Tsuyoshi Horo | 37493af | 2019-11-21 23:43:14 | [diff] [blame] | 77 | #include "content/browser/web_package/web_bundle_navigation_info.h" |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 78 | #include "content/common/content_constants_internal.h" |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 79 | #include "content/common/navigation_params_utils.h" |
Nasko Oskov | ae49e29 | 2020-08-13 02:08:51 | [diff] [blame] | 80 | #include "content/common/trace_utils.h" |
[email protected] | ccb79730 | 2011-12-15 16:55:11 | [diff] [blame] | 81 | #include "content/public/browser/browser_context.h" |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 82 | #include "content/public/browser/content_browser_client.h" |
Fergal Daly | 1336ac64 | 2021-09-14 15:13:11 | [diff] [blame] | 83 | #include "content/public/browser/disallow_activation_reason.h" |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 84 | #include "content/public/browser/invalidate_type.h" |
[email protected] | 5b96836f | 2011-12-22 07:39:00 | [diff] [blame] | 85 | #include "content/public/browser/navigation_details.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 86 | #include "content/public/browser/notification_service.h" |
[email protected] | 0d6e9bd | 2011-10-18 04:29:16 | [diff] [blame] | 87 | #include "content/public/browser/notification_types.h" |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 88 | #include "content/public/browser/render_view_host.h" |
[email protected] | 9677a3c | 2012-12-22 04:18:58 | [diff] [blame] | 89 | #include "content/public/browser/render_widget_host.h" |
| 90 | #include "content/public/browser/render_widget_host_view.h" |
Mikel Astiz | ba9cf2fd | 2017-12-17 10:38:10 | [diff] [blame] | 91 | #include "content/public/browser/replaced_navigation_entry_data.h" |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 92 | #include "content/public/browser/storage_partition.h" |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 93 | #include "content/public/common/content_client.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 94 | #include "content/public/common/content_constants.h" |
toyoshim | 86e34ec | 2016-02-25 08:56:10 | [diff] [blame] | 95 | #include "content/public/common/content_features.h" |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 96 | #include "content/public/common/url_constants.h" |
clamy | 7fced7b | 2017-11-16 19:52:43 | [diff] [blame] | 97 | #include "content/public/common/url_utils.h" |
servolk | f395553 | 2015-05-16 00:01:59 | [diff] [blame] | 98 | #include "media/base/mime_util.h" |
Arthur Sonzogni | 620cec6 | 2018-12-13 13:08:57 | [diff] [blame] | 99 | #include "net/http/http_status_code.h" |
Shivani Sharma | 9332910 | 2019-01-24 19:44:18 | [diff] [blame] | 100 | #include "services/metrics/public/cpp/ukm_builders.h" |
| 101 | #include "services/metrics/public/cpp/ukm_recorder.h" |
Yue Ru Sun | 12880493 | 2020-09-30 22:19:17 | [diff] [blame] | 102 | #include "services/metrics/public/cpp/ukm_source_id.h" |
Nan Lin | d91c815 | 2021-10-21 16:22:37 | [diff] [blame] | 103 | #include "services/network/public/mojom/fetch_api.mojom.h" |
William Liu | 2c82547 | 2022-10-31 12:01:44 | [diff] [blame] | 104 | #include "services/network/public/mojom/url_response_head.mojom-shared.h" |
[email protected] | 9677a3c | 2012-12-22 04:18:58 | [diff] [blame] | 105 | #include "skia/ext/platform_canvas.h" |
Marijn Kruisselbrink | 0c87e6e | 2018-06-22 22:57:39 | [diff] [blame] | 106 | #include "third_party/blink/public/common/blob/blob_utils.h" |
Gyuyoung Kim | 107c2a0 | 2021-04-13 01:49:30 | [diff] [blame] | 107 | #include "third_party/blink/public/common/chrome_debug_urls.h" |
Miyoung Shin | 1c565c91 | 2021-03-17 12:11:21 | [diff] [blame] | 108 | #include "third_party/blink/public/common/history/session_history_constants.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 109 | #include "third_party/blink/public/common/mime_util/mime_util.h" |
Minggang Wang | a13c796e | 2021-07-02 05:54:43 | [diff] [blame] | 110 | #include "third_party/blink/public/common/navigation/navigation_params.h" |
Carlos Caballero | ede6f8c | 2021-01-28 11:01:50 | [diff] [blame] | 111 | #include "third_party/blink/public/common/page_state/page_state_serialization.h" |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 112 | #include "third_party/blink/public/mojom/navigation/navigation_params.mojom.h" |
Minggang Wang | 7ee0c74 | 2021-06-16 16:16:51 | [diff] [blame] | 113 | #include "third_party/blink/public/mojom/navigation/prefetched_signed_exchange_info.mojom.h" |
[email protected] | cca6f39 | 2014-05-28 21:32:26 | [diff] [blame] | 114 | #include "url/url_constants.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 115 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 116 | namespace content { |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 117 | namespace { |
| 118 | |
| 119 | // Invoked when entries have been pruned, or removed. For example, if the |
| 120 | // current entries are [google, digg, yahoo], with the current entry google, |
| 121 | // and the user types in cnet, then digg and yahoo are pruned. |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 122 | void NotifyPrunedEntries(NavigationControllerImpl* nav_controller, |
Shivani Sharma | b9c46de8 | 2019-02-08 16:54:50 | [diff] [blame] | 123 | int index, |
[email protected] | c12bf1a1 | 2008-09-17 16:28:49 | [diff] [blame] | 124 | int count) { |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 125 | PrunedDetails details; |
Shivani Sharma | b9c46de8 | 2019-02-08 16:54:50 | [diff] [blame] | 126 | details.index = index; |
[email protected] | c12bf1a1 | 2008-09-17 16:28:49 | [diff] [blame] | 127 | details.count = count; |
Sam McNally | 5c087a3 | 2017-08-25 01:46:14 | [diff] [blame] | 128 | nav_controller->delegate()->NotifyNavigationListPruned(details); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 129 | } |
| 130 | |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 131 | // Configure all the NavigationEntries in entries for restore. This resets |
| 132 | // the transition type to reload and makes sure the content state isn't empty. |
| 133 | void ConfigureEntriesForRestore( |
dcheng | 9bfa516 | 2016-04-09 01:00:57 | [diff] [blame] | 134 | std::vector<std::unique_ptr<NavigationEntryImpl>>* entries, |
toyoshim | 0df1d3a | 2016-09-09 09:52:48 | [diff] [blame] | 135 | RestoreType type) { |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 136 | for (auto& entry : *entries) { |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 137 | // Use a transition type of reload so that we don't incorrectly increase |
| 138 | // the typed count. |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 139 | entry->SetTransitionType(ui::PAGE_TRANSITION_RELOAD); |
| 140 | entry->set_restore_type(type); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 141 | } |
| 142 | } |
| 143 | |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 144 | // Determines whether or not we should be carrying over a user agent override |
| 145 | // between two NavigationEntries. |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 146 | bool ShouldKeepOverride(NavigationEntry* last_entry) { |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 147 | return last_entry && last_entry->GetIsOverridingUserAgent(); |
| 148 | } |
| 149 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 150 | // Determines whether to override user agent for a navigation. |
| 151 | bool ShouldOverrideUserAgent( |
| 152 | NavigationController::UserAgentOverrideOption override_user_agent, |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 153 | NavigationEntry* last_committed_entry) { |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 154 | switch (override_user_agent) { |
| 155 | case NavigationController::UA_OVERRIDE_INHERIT: |
| 156 | return ShouldKeepOverride(last_committed_entry); |
| 157 | case NavigationController::UA_OVERRIDE_TRUE: |
| 158 | return true; |
| 159 | case NavigationController::UA_OVERRIDE_FALSE: |
| 160 | return false; |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 161 | } |
| 162 | NOTREACHED(); |
| 163 | return false; |
| 164 | } |
| 165 | |
Rakina Zata Amni | 312822d7 | 2021-06-04 16:13:37 | [diff] [blame] | 166 | // Returns true if this navigation should be treated as a reload. For e.g. |
clamy | 0a656e4 | 2018-02-06 18:18:28 | [diff] [blame] | 167 | // navigating to the last committed url via the address bar or clicking on a |
Rakina Zata Amni | 312822d7 | 2021-06-04 16:13:37 | [diff] [blame] | 168 | // link which results in a navigation to the last committed URL (but wasn't |
| 169 | // converted to do a replacement navigation in the renderer), etc. |
Fergal Daly | 766177d | 2020-07-07 07:54:04 | [diff] [blame] | 170 | // |node| is the FrameTreeNode which is navigating. |url|, |virtual_url|, |
| 171 | // |base_url_for_data_url|, |transition_type| correspond to the new navigation |
| 172 | // (i.e. the pending NavigationEntry). |last_committed_entry| is the last |
| 173 | // navigation that committed. |
| 174 | bool ShouldTreatNavigationAsReload(FrameTreeNode* node, |
| 175 | const GURL& url, |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 176 | const GURL& virtual_url, |
| 177 | const GURL& base_url_for_data_url, |
| 178 | ui::PageTransition transition_type, |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 179 | bool is_post, |
Rakina Zata Amni | 312822d7 | 2021-06-04 16:13:37 | [diff] [blame] | 180 | bool should_replace_current_entry, |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 181 | NavigationEntryImpl* last_committed_entry) { |
Rakina Zata Amni | 312822d7 | 2021-06-04 16:13:37 | [diff] [blame] | 182 | // Navigations intended to do a replacement shouldn't be converted to do a |
| 183 | // reload. |
| 184 | if (should_replace_current_entry) |
clamy | 0a656e4 | 2018-02-06 18:18:28 | [diff] [blame] | 185 | return false; |
clamy | 0a656e4 | 2018-02-06 18:18:28 | [diff] [blame] | 186 | // Only convert to reload if at least one navigation committed. |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 187 | if (!last_committed_entry || last_committed_entry->IsInitialEntry()) |
ananta | 3bdd8ae | 2016-12-22 17:11:55 | [diff] [blame] | 188 | return false; |
| 189 | |
arthursonzogni | 7a824368 | 2017-12-14 16:41:42 | [diff] [blame] | 190 | // Skip navigations initiated by external applications. |
clamy | 0a656e4 | 2018-02-06 18:18:28 | [diff] [blame] | 191 | if (transition_type & ui::PAGE_TRANSITION_FROM_API) |
arthursonzogni | 7a824368 | 2017-12-14 16:41:42 | [diff] [blame] | 192 | return false; |
| 193 | |
ananta | 3bdd8ae | 2016-12-22 17:11:55 | [diff] [blame] | 194 | // We treat (PAGE_TRANSITION_RELOAD | PAGE_TRANSITION_FROM_ADDRESS_BAR), |
| 195 | // PAGE_TRANSITION_TYPED or PAGE_TRANSITION_LINK transitions as navigations |
| 196 | // which should be treated as reloads. |
clamy | 0a656e4 | 2018-02-06 18:18:28 | [diff] [blame] | 197 | bool transition_type_can_be_converted = false; |
| 198 | if (ui::PageTransitionCoreTypeIs(transition_type, |
| 199 | ui::PAGE_TRANSITION_RELOAD) && |
| 200 | (transition_type & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR)) { |
| 201 | transition_type_can_be_converted = true; |
ananta | 3bdd8ae | 2016-12-22 17:11:55 | [diff] [blame] | 202 | } |
clamy | 0a656e4 | 2018-02-06 18:18:28 | [diff] [blame] | 203 | if (ui::PageTransitionCoreTypeIs(transition_type, |
ananta | 3bdd8ae | 2016-12-22 17:11:55 | [diff] [blame] | 204 | ui::PAGE_TRANSITION_TYPED)) { |
clamy | 0a656e4 | 2018-02-06 18:18:28 | [diff] [blame] | 205 | transition_type_can_be_converted = true; |
| 206 | } |
| 207 | if (ui::PageTransitionCoreTypeIs(transition_type, ui::PAGE_TRANSITION_LINK)) |
| 208 | transition_type_can_be_converted = true; |
| 209 | if (!transition_type_can_be_converted) |
| 210 | return false; |
| 211 | |
| 212 | // This check is required for cases like view-source:, etc. Here the URL of |
| 213 | // the navigation entry would contain the url of the page, while the virtual |
| 214 | // URL contains the full URL including the view-source prefix. |
| 215 | if (virtual_url != last_committed_entry->GetVirtualURL()) |
| 216 | return false; |
| 217 | |
Fergal Daly | 766177d | 2020-07-07 07:54:04 | [diff] [blame] | 218 | // Check that the URLs match. |
| 219 | FrameNavigationEntry* frame_entry = last_committed_entry->GetFrameEntry(node); |
| 220 | // If there's no frame entry then by definition the URLs don't match. |
| 221 | if (!frame_entry) |
| 222 | return false; |
| 223 | |
| 224 | if (url != frame_entry->url()) |
clamy | 0a656e4 | 2018-02-06 18:18:28 | [diff] [blame] | 225 | return false; |
| 226 | |
| 227 | // This check is required for Android WebView loadDataWithBaseURL. Apps |
| 228 | // can pass in anything in the base URL and we need to ensure that these |
| 229 | // match before classifying it as a reload. |
| 230 | if (url.SchemeIs(url::kDataScheme) && base_url_for_data_url.is_valid()) { |
| 231 | if (base_url_for_data_url != last_committed_entry->GetBaseURLForDataURL()) |
| 232 | return false; |
ananta | 3bdd8ae | 2016-12-22 17:11:55 | [diff] [blame] | 233 | } |
| 234 | |
clamy | 0a656e4 | 2018-02-06 18:18:28 | [diff] [blame] | 235 | // Skip entries with SSL errors. |
| 236 | if (last_committed_entry->ssl_error()) |
| 237 | return false; |
| 238 | |
| 239 | // Don't convert to a reload when the last navigation was a POST or the new |
| 240 | // navigation is a POST. |
Fergal Daly | 766177d | 2020-07-07 07:54:04 | [diff] [blame] | 241 | if (frame_entry->get_has_post_data() || is_post) |
clamy | 0a656e4 | 2018-02-06 18:18:28 | [diff] [blame] | 242 | return false; |
| 243 | |
| 244 | return true; |
ananta | 3bdd8ae | 2016-12-22 17:11:55 | [diff] [blame] | 245 | } |
| 246 | |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 247 | absl::optional<url::Origin> GetCommittedOriginForFrameEntry( |
Rakina Zata Amni | 3a1c0ec | 2021-04-15 03:35:12 | [diff] [blame] | 248 | const mojom::DidCommitProvisionalLoadParams& params, |
| 249 | NavigationRequest* request) { |
Nasko Oskov | 0391210 | 2019-01-11 00:21:32 | [diff] [blame] | 250 | // Error pages commit in an opaque origin, yet have the real URL that resulted |
| 251 | // in an error as the |params.url|. Since successful reload of an error page |
| 252 | // should commit in the correct origin, setting the opaque origin on the |
| 253 | // FrameNavigationEntry will be incorrect. |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 254 | if (request && request->DidEncounterError()) |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 255 | return absl::nullopt; |
Nasko Oskov | 0391210 | 2019-01-11 00:21:32 | [diff] [blame] | 256 | |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 257 | return absl::make_optional(params.origin); |
Nasko Oskov | 0391210 | 2019-01-11 00:21:32 | [diff] [blame] | 258 | } |
| 259 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 260 | bool IsValidURLForNavigation(bool is_main_frame, |
| 261 | const GURL& virtual_url, |
| 262 | const GURL& dest_url) { |
| 263 | // Don't attempt to navigate if the virtual URL is non-empty and invalid. |
| 264 | if (is_main_frame && !virtual_url.is_valid() && !virtual_url.is_empty()) { |
| 265 | LOG(WARNING) << "Refusing to load for invalid virtual URL: " |
| 266 | << virtual_url.possibly_invalid_spec(); |
| 267 | return false; |
| 268 | } |
| 269 | |
| 270 | // Don't attempt to navigate to non-empty invalid URLs. |
| 271 | if (!dest_url.is_valid() && !dest_url.is_empty()) { |
| 272 | LOG(WARNING) << "Refusing to load invalid URL: " |
| 273 | << dest_url.possibly_invalid_spec(); |
| 274 | return false; |
| 275 | } |
| 276 | |
| 277 | // The renderer will reject IPC messages with URLs longer than |
| 278 | // this limit, so don't attempt to navigate with a longer URL. |
| 279 | if (dest_url.spec().size() > url::kMaxURLChars) { |
| 280 | LOG(WARNING) << "Refusing to load URL as it exceeds " << url::kMaxURLChars |
| 281 | << " characters."; |
| 282 | return false; |
| 283 | } |
| 284 | |
Aaron Colwell | 33109c59 | 2020-04-21 21:31:19 | [diff] [blame] | 285 | // Reject renderer debug URLs because they should have been handled before |
| 286 | // we get to this point. This check handles renderer debug URLs |
| 287 | // that are inside a view-source: URL (e.g. view-source:chrome://kill) and |
| 288 | // provides defense-in-depth if a renderer debug URL manages to get here via |
| 289 | // some other path. We want to reject the navigation here so it doesn't |
| 290 | // violate assumptions in downstream code. |
Gyuyoung Kim | 107c2a0 | 2021-04-13 01:49:30 | [diff] [blame] | 291 | if (blink::IsRendererDebugURL(dest_url)) { |
Aaron Colwell | 33109c59 | 2020-04-21 21:31:19 | [diff] [blame] | 292 | LOG(WARNING) << "Refusing to load renderer debug URL: " |
| 293 | << dest_url.possibly_invalid_spec(); |
| 294 | return false; |
| 295 | } |
| 296 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 297 | return true; |
| 298 | } |
| 299 | |
Mikel Astiz | ba9cf2fd | 2017-12-17 10:38:10 | [diff] [blame] | 300 | // See replaced_navigation_entry_data.h for details: this information is meant |
| 301 | // to ensure |*output_entry| keeps track of its original URL (landing page in |
| 302 | // case of server redirects) as it gets replaced (e.g. history.replaceState()), |
| 303 | // without overwriting it later, for main frames. |
| 304 | void CopyReplacedNavigationEntryDataIfPreviouslyEmpty( |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 305 | NavigationEntryImpl* replaced_entry, |
Mikel Astiz | ba9cf2fd | 2017-12-17 10:38:10 | [diff] [blame] | 306 | NavigationEntryImpl* output_entry) { |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 307 | if (output_entry->GetReplacedEntryData().has_value() || |
| 308 | replaced_entry->IsInitialEntry()) { |
Mikel Astiz | ba9cf2fd | 2017-12-17 10:38:10 | [diff] [blame] | 309 | return; |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 310 | } |
Mikel Astiz | ba9cf2fd | 2017-12-17 10:38:10 | [diff] [blame] | 311 | |
| 312 | ReplacedNavigationEntryData data; |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 313 | data.first_committed_url = replaced_entry->GetURL(); |
| 314 | data.first_timestamp = replaced_entry->GetTimestamp(); |
| 315 | data.first_transition_type = replaced_entry->GetTransitionType(); |
Charlie Reis | b55438f | 2019-01-08 01:54:29 | [diff] [blame] | 316 | output_entry->set_replaced_entry_data(data); |
Mikel Astiz | ba9cf2fd | 2017-12-17 10:38:10 | [diff] [blame] | 317 | } |
| 318 | |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 319 | blink::mojom::NavigationType GetNavigationType( |
| 320 | const GURL& old_url, |
| 321 | const GURL& new_url, |
| 322 | ReloadType reload_type, |
| 323 | NavigationEntryImpl* entry, |
| 324 | const FrameNavigationEntry& frame_entry, |
| 325 | bool has_pending_cross_document_commit, |
| 326 | bool is_currently_error_page, |
Garrett Tanzer | 405f340 | 2022-07-21 20:12:49 | [diff] [blame] | 327 | bool is_same_document_history_load, |
Garrett Tanzer | 267c2b8 | 2022-07-26 16:53:13 | [diff] [blame] | 328 | bool is_embedder_initiated_fenced_frame_navigation, |
Garrett Tanzer | 405f340 | 2022-07-21 20:12:49 | [diff] [blame] | 329 | bool is_unfenced_top_navigation) { |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 330 | // Reload navigations |
| 331 | switch (reload_type) { |
| 332 | case ReloadType::NORMAL: |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 333 | return blink::mojom::NavigationType::RELOAD; |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 334 | case ReloadType::BYPASSING_CACHE: |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 335 | return blink::mojom::NavigationType::RELOAD_BYPASSING_CACHE; |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 336 | case ReloadType::ORIGINAL_REQUEST_URL: |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 337 | return blink::mojom::NavigationType::RELOAD_ORIGINAL_REQUEST_URL; |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 338 | case ReloadType::NONE: |
| 339 | break; // Fall through to rest of function. |
| 340 | } |
| 341 | |
Lukasz Anforowicz | 6b75c0d | 2020-12-01 22:56:08 | [diff] [blame] | 342 | if (entry->IsRestored()) { |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 343 | return entry->GetHasPostData() |
| 344 | ? blink::mojom::NavigationType::RESTORE_WITH_POST |
| 345 | : blink::mojom::NavigationType::RESTORE; |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 346 | } |
| 347 | |
danakj | b952ef1 | 2021-01-14 19:58:49 | [diff] [blame] | 348 | const bool can_be_same_document = |
| 349 | // A pending cross-document commit means this navigation will not occur in |
| 350 | // the current document, as that document would end up being replaced in |
| 351 | // the meantime. |
| 352 | !has_pending_cross_document_commit && |
| 353 | // If the current document is an error page, we should always treat it as |
| 354 | // a different-document navigation so that we'll attempt to load the |
| 355 | // document we're navigating to (and not stay in the current error page). |
Garrett Tanzer | 405f340 | 2022-07-21 20:12:49 | [diff] [blame] | 356 | !is_currently_error_page && |
Garrett Tanzer | 267c2b8 | 2022-07-26 16:53:13 | [diff] [blame] | 357 | // If the navigation is an embedder-initiated navigation of a fenced |
| 358 | // frame root (i.e. enters a fenced frame tree from outside), |
| 359 | // same-document navigations should be disabled because we don't want to |
| 360 | // allow information to be joined across multiple embedder-initiated |
| 361 | // fenced frame navigations (which may contain separate cross-site data). |
| 362 | !is_embedder_initiated_fenced_frame_navigation && |
Garrett Tanzer | 405f340 | 2022-07-21 20:12:49 | [diff] [blame] | 363 | // If the navigation is to _unfencedTop (i.e. escapes a fenced frame), |
| 364 | // same-document navigations should be disabled because we want to force |
| 365 | // the creation of a new browsing context group. |
| 366 | !is_unfenced_top_navigation; |
danakj | d83d706d | 2020-11-25 22:11:12 | [diff] [blame] | 367 | |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 368 | // History navigations. |
| 369 | if (frame_entry.page_state().IsValid()) { |
danakj | d83d706d | 2020-11-25 22:11:12 | [diff] [blame] | 370 | return can_be_same_document && is_same_document_history_load |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 371 | ? blink::mojom::NavigationType::HISTORY_SAME_DOCUMENT |
| 372 | : blink::mojom::NavigationType::HISTORY_DIFFERENT_DOCUMENT; |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 373 | } |
| 374 | DCHECK(!is_same_document_history_load); |
| 375 | |
| 376 | // A same-document fragment-navigation happens when the only part of the url |
| 377 | // that is modified is after the '#' character. |
| 378 | // |
| 379 | // When modifying this condition, please take a look at: |
danakj | d83d706d | 2020-11-25 22:11:12 | [diff] [blame] | 380 | // FrameLoader::ShouldPerformFragmentNavigation(). |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 381 | // |
| 382 | // Note: this check is only valid for navigations that are not history |
| 383 | // navigations. For instance, if the history is: 'A#bar' -> 'B' -> 'A#foo', a |
| 384 | // history navigation from 'A#foo' to 'A#bar' is not a same-document |
| 385 | // navigation, but a different-document one. This is why history navigation |
| 386 | // are classified before this check. |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 387 | bool is_same_doc = new_url.has_ref() && old_url.EqualsIgnoringRef(new_url) && |
| 388 | frame_entry.method() == "GET"; |
danakj | d83d706d | 2020-11-25 22:11:12 | [diff] [blame] | 389 | |
| 390 | // The one case where we do the wrong thing here and incorrectly choose |
| 391 | // SAME_DOCUMENT is if the navigation is browser-initiated but the document in |
| 392 | // the renderer is a frameset. All frameset navigations should be |
| 393 | // DIFFERENT_DOCUMENT, even if their URLs match. A renderer-initiated |
| 394 | // navigation would do the right thing, as it would send it to the browser and |
| 395 | // all renderer-initiated navigations are DIFFERENT_DOCUMENT (they don't get |
| 396 | // into this method). But since we can't tell that case here for browser- |
| 397 | // initiated navigations, we have to get the renderer involved. In that case |
| 398 | // the navigation would be restarted due to the renderer spending a reply of |
| 399 | // mojom::CommitResult::RestartCrossDocument. |
| 400 | |
| 401 | return can_be_same_document && is_same_doc |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 402 | ? blink::mojom::NavigationType::SAME_DOCUMENT |
| 403 | : blink::mojom::NavigationType::DIFFERENT_DOCUMENT; |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 404 | } |
| 405 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 406 | // Adjusts the original input URL if needed, to get the URL to actually load and |
| 407 | // the virtual URL, which may differ. |
| 408 | void RewriteUrlForNavigation(const GURL& original_url, |
| 409 | BrowserContext* browser_context, |
| 410 | GURL* url_to_load, |
| 411 | GURL* virtual_url, |
| 412 | bool* reverse_on_redirect) { |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 413 | // Allow the browser URL handler to rewrite the URL. This will, for example, |
| 414 | // remove "view-source:" from the beginning of the URL to get the URL that |
| 415 | // will actually be loaded. This real URL won't be shown to the user, just |
| 416 | // used internally. |
Lukasz Anforowicz | 7b07879 | 2020-10-20 17:04:31 | [diff] [blame] | 417 | *url_to_load = *virtual_url = original_url; |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 418 | BrowserURLHandlerImpl::GetInstance()->RewriteURLIfNecessary( |
| 419 | url_to_load, browser_context, reverse_on_redirect); |
| 420 | } |
| 421 | |
| 422 | #if DCHECK_IS_ON() |
| 423 | // Helper sanity check function used in debug mode. |
| 424 | void ValidateRequestMatchesEntry(NavigationRequest* request, |
| 425 | NavigationEntryImpl* entry) { |
| 426 | if (request->frame_tree_node()->IsMainFrame()) { |
| 427 | DCHECK_EQ(request->browser_initiated(), !entry->is_renderer_initiated()); |
| 428 | DCHECK(ui::PageTransitionTypeIncludingQualifiersIs( |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 429 | ui::PageTransitionFromInt(request->common_params().transition), |
| 430 | entry->GetTransitionType())); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 431 | } |
Nasko Oskov | c36327d | 2019-01-03 23:23:04 | [diff] [blame] | 432 | DCHECK_EQ(request->commit_params().should_clear_history_list, |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 433 | entry->should_clear_history_list()); |
| 434 | DCHECK_EQ(request->common_params().has_user_gesture, |
| 435 | entry->has_user_gesture()); |
| 436 | DCHECK_EQ(request->common_params().base_url_for_data_url, |
| 437 | entry->GetBaseURLForDataURL()); |
Nasko Oskov | c36327d | 2019-01-03 23:23:04 | [diff] [blame] | 438 | DCHECK_EQ(request->commit_params().can_load_local_resources, |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 439 | entry->GetCanLoadLocalResources()); |
| 440 | DCHECK_EQ(request->common_params().started_from_context_menu, |
| 441 | entry->has_started_from_context_menu()); |
| 442 | |
| 443 | FrameNavigationEntry* frame_entry = |
| 444 | entry->GetFrameEntry(request->frame_tree_node()); |
| 445 | if (!frame_entry) { |
| 446 | NOTREACHED(); |
| 447 | return; |
| 448 | } |
| 449 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 450 | DCHECK_EQ(request->common_params().method, frame_entry->method()); |
| 451 | |
Nasko Oskov | c36327d | 2019-01-03 23:23:04 | [diff] [blame] | 452 | size_t redirect_size = request->commit_params().redirects.size(); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 453 | if (redirect_size == frame_entry->redirect_chain().size()) { |
| 454 | for (size_t i = 0; i < redirect_size; ++i) { |
Nasko Oskov | c36327d | 2019-01-03 23:23:04 | [diff] [blame] | 455 | DCHECK_EQ(request->commit_params().redirects[i], |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 456 | frame_entry->redirect_chain()[i]); |
| 457 | } |
| 458 | } else { |
| 459 | NOTREACHED(); |
| 460 | } |
| 461 | } |
| 462 | #endif // DCHECK_IS_ON() |
| 463 | |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 464 | // Returns whether the session history NavigationRequests in |navigations| |
Nate Chapin | bf682fa3 | 2022-09-26 22:41:20 | [diff] [blame] | 465 | // would stay within the subtree of |sandboxed_initiator_rfh|. |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 466 | bool DoesSandboxNavigationStayWithinSubtree( |
Nate Chapin | bf682fa3 | 2022-09-26 22:41:20 | [diff] [blame] | 467 | RenderFrameHostImpl* sandboxed_initiator_rfh, |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 468 | const std::vector<std::unique_ptr<NavigationRequest>>& navigations) { |
Nate Chapin | bf682fa3 | 2022-09-26 22:41:20 | [diff] [blame] | 469 | DCHECK(sandboxed_initiator_rfh); |
| 470 | DCHECK(sandboxed_initiator_rfh->IsSandboxed( |
| 471 | network::mojom::WebSandboxFlags::kTopNavigation)); |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 472 | for (auto& item : navigations) { |
| 473 | bool within_subtree = false; |
| 474 | // Check whether this NavigationRequest affects a frame within the |
| 475 | // sandboxed frame's subtree by walking up the tree looking for the |
| 476 | // sandboxed frame. |
| 477 | for (auto* frame = item->frame_tree_node(); frame; |
Alexander Timin | 381e7e18 | 2020-04-28 19:04:03 | [diff] [blame] | 478 | frame = FrameTreeNode::From(frame->parent())) { |
Nate Chapin | bf682fa3 | 2022-09-26 22:41:20 | [diff] [blame] | 479 | if (frame == sandboxed_initiator_rfh->frame_tree_node()) { |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 480 | within_subtree = true; |
| 481 | break; |
| 482 | } |
| 483 | } |
| 484 | if (!within_subtree) |
| 485 | return false; |
| 486 | } |
| 487 | return true; |
| 488 | } |
| 489 | |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 490 | } // namespace |
| 491 | |
arthursonzogni | 66f711c | 2019-10-08 14:40:36 | [diff] [blame] | 492 | // NavigationControllerImpl::PendingEntryRef------------------------------------ |
| 493 | |
| 494 | NavigationControllerImpl::PendingEntryRef::PendingEntryRef( |
| 495 | base::WeakPtr<NavigationControllerImpl> controller) |
| 496 | : controller_(controller) {} |
| 497 | |
| 498 | NavigationControllerImpl::PendingEntryRef::~PendingEntryRef() { |
| 499 | if (!controller_) // Can be null with interstitials. |
| 500 | return; |
| 501 | |
| 502 | controller_->PendingEntryRefDeleted(this); |
| 503 | } |
| 504 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 505 | // NavigationControllerImpl ---------------------------------------------------- |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 506 | |
[email protected] | 23a918b | 2014-07-15 09:51:36 | [diff] [blame] | 507 | const size_t kMaxEntryCountForTestingNotSet = static_cast<size_t>(-1); |
[email protected] | 9b51970d | 2011-12-09 23:10:23 | [diff] [blame] | 508 | |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 509 | // static |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 510 | size_t NavigationControllerImpl::max_entry_count_for_testing_ = |
[email protected] | 9b51970d | 2011-12-09 23:10:23 | [diff] [blame] | 511 | kMaxEntryCountForTestingNotSet; |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 512 | |
[email protected] | e6fec47 | 2013-05-14 05:29:02 | [diff] [blame] | 513 | // Should Reload check for post data? The default is true, but is set to false |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 514 | // when testing. |
| 515 | static bool g_check_for_repost = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 516 | |
[email protected] | 71fde35 | 2011-12-29 03:29:56 | [diff] [blame] | 517 | // static |
dcheng | 9bfa516 | 2016-04-09 01:00:57 | [diff] [blame] | 518 | std::unique_ptr<NavigationEntry> NavigationController::CreateNavigationEntry( |
| 519 | const GURL& url, |
Lukasz Anforowicz | 641234d5 | 2019-11-07 21:07:10 | [diff] [blame] | 520 | Referrer referrer, |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 521 | absl::optional<url::Origin> initiator_origin, |
Lukasz Anforowicz | 641234d5 | 2019-11-07 21:07:10 | [diff] [blame] | 522 | ui::PageTransition transition, |
| 523 | bool is_renderer_initiated, |
| 524 | const std::string& extra_headers, |
| 525 | BrowserContext* browser_context, |
| 526 | scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory) { |
| 527 | return NavigationControllerImpl::CreateNavigationEntry( |
| 528 | url, referrer, std::move(initiator_origin), |
| 529 | nullptr /* source_site_instance */, transition, is_renderer_initiated, |
Julie Jeongeun Kim | 5b9aff7 | 2022-05-02 02:10:17 | [diff] [blame] | 530 | extra_headers, browser_context, std::move(blob_url_loader_factory), |
| 531 | true /* rewrite_virtual_urls */); |
Lukasz Anforowicz | 641234d5 | 2019-11-07 21:07:10 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | // static |
| 535 | std::unique_ptr<NavigationEntryImpl> |
| 536 | NavigationControllerImpl::CreateNavigationEntry( |
| 537 | const GURL& url, |
| 538 | Referrer referrer, |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 539 | absl::optional<url::Origin> initiator_origin, |
Lukasz Anforowicz | 641234d5 | 2019-11-07 21:07:10 | [diff] [blame] | 540 | SiteInstance* source_site_instance, |
dcheng | 9bfa516 | 2016-04-09 01:00:57 | [diff] [blame] | 541 | ui::PageTransition transition, |
| 542 | bool is_renderer_initiated, |
| 543 | const std::string& extra_headers, |
Marijn Kruisselbrink | 7a0d5e18 | 2018-05-24 22:55:09 | [diff] [blame] | 544 | BrowserContext* browser_context, |
Julie Jeongeun Kim | 5b9aff7 | 2022-05-02 02:10:17 | [diff] [blame] | 545 | scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory, |
| 546 | bool rewrite_virtual_urls) { |
| 547 | GURL url_to_load = url; |
| 548 | GURL virtual_url = url; |
[email protected] | 71fde35 | 2011-12-29 03:29:56 | [diff] [blame] | 549 | bool reverse_on_redirect = false; |
Julie Jeongeun Kim | 5b9aff7 | 2022-05-02 02:10:17 | [diff] [blame] | 550 | if (rewrite_virtual_urls) { |
| 551 | RewriteUrlForNavigation(url, browser_context, &url_to_load, &virtual_url, |
| 552 | &reverse_on_redirect); |
| 553 | } |
Lukasz Anforowicz | 641234d5 | 2019-11-07 21:07:10 | [diff] [blame] | 554 | // Let the NTP override the navigation params and pretend that this is a |
| 555 | // browser-initiated, bookmark-like navigation. |
| 556 | GetContentClient()->browser()->OverrideNavigationParams( |
Scott Violet | cf6ea7e | 2021-06-09 21:09:21 | [diff] [blame] | 557 | source_site_instance, &transition, &is_renderer_initiated, &referrer, |
| 558 | &initiator_origin); |
Lukasz Anforowicz | 641234d5 | 2019-11-07 21:07:10 | [diff] [blame] | 559 | |
Patrick Monette | f507e98 | 2019-06-19 20:18:06 | [diff] [blame] | 560 | auto entry = std::make_unique<NavigationEntryImpl>( |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 561 | nullptr, // The site instance for tabs is sent on navigation |
| 562 | // (WebContents::GetSiteInstance). |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 563 | url_to_load, referrer, initiator_origin, std::u16string(), transition, |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 564 | is_renderer_initiated, blob_url_loader_factory, |
| 565 | /* is_initial_entry = */ false); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 566 | entry->SetVirtualURL(virtual_url); |
| 567 | entry->set_user_typed_url(virtual_url); |
[email protected] | 71fde35 | 2011-12-29 03:29:56 | [diff] [blame] | 568 | entry->set_update_virtual_url_with_url(reverse_on_redirect); |
| 569 | entry->set_extra_headers(extra_headers); |
Patrick Monette | f507e98 | 2019-06-19 20:18:06 | [diff] [blame] | 570 | return entry; |
[email protected] | 71fde35 | 2011-12-29 03:29:56 | [diff] [blame] | 571 | } |
| 572 | |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 573 | // static |
| 574 | void NavigationController::DisablePromptOnRepost() { |
| 575 | g_check_for_repost = false; |
| 576 | } |
| 577 | |
[email protected] | c5b88d8 | 2012-10-06 17:03:33 | [diff] [blame] | 578 | base::Time NavigationControllerImpl::TimeSmoother::GetSmoothedTime( |
| 579 | base::Time t) { |
| 580 | // If |t| is between the water marks, we're in a run of duplicates |
| 581 | // or just getting out of it, so increase the high-water mark to get |
| 582 | // a time that probably hasn't been used before and return it. |
| 583 | if (low_water_mark_ <= t && t <= high_water_mark_) { |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 584 | high_water_mark_ += base::Microseconds(1); |
[email protected] | c5b88d8 | 2012-10-06 17:03:33 | [diff] [blame] | 585 | return high_water_mark_; |
| 586 | } |
| 587 | |
| 588 | // Otherwise, we're clear of the last duplicate run, so reset the |
| 589 | // water marks. |
| 590 | low_water_mark_ = high_water_mark_ = t; |
| 591 | return t; |
| 592 | } |
| 593 | |
ckitagawa | 0faa5e4 | 2020-06-17 17:30:54 | [diff] [blame] | 594 | NavigationControllerImpl::ScopedShowRepostDialogForTesting:: |
| 595 | ScopedShowRepostDialogForTesting() |
| 596 | : was_disallowed_(g_check_for_repost) { |
| 597 | g_check_for_repost = true; |
| 598 | } |
| 599 | |
| 600 | NavigationControllerImpl::ScopedShowRepostDialogForTesting:: |
| 601 | ~ScopedShowRepostDialogForTesting() { |
| 602 | g_check_for_repost = was_disallowed_; |
| 603 | } |
| 604 | |
Nate Chapin | 9eb16be7 | 2022-09-23 22:54:31 | [diff] [blame] | 605 | NavigationControllerImpl::RemovedEntriesTracker::RemovedEntriesTracker( |
| 606 | base::SafeRef<NavigationControllerImpl> controller) |
| 607 | : controller_(controller) { |
| 608 | for (FrameTreeNode* frame_tree_node : controller_->frame_tree().Nodes()) { |
| 609 | names_to_nodes_.insert({frame_tree_node->unique_name(), frame_tree_node}); |
| 610 | frame_tree_node_id_to_keys_.insert( |
| 611 | {frame_tree_node->frame_tree_node_id(), std::set<std::string>()}); |
| 612 | if (auto* frame_entry = frame_tree_node->current_frame_host() |
| 613 | ->last_committed_frame_entry()) { |
| 614 | frame_tree_node_id_to_doc_seq_nos_.insert( |
| 615 | {frame_tree_node->frame_tree_node_id(), |
| 616 | frame_entry->document_sequence_number()}); |
| 617 | } |
| 618 | } |
| 619 | PopulateKeySet(Direction::kBack); |
| 620 | PopulateKeySet(Direction::kForward); |
| 621 | } |
| 622 | |
| 623 | void NavigationControllerImpl::RemovedEntriesTracker::PopulateKeySet( |
| 624 | Direction direction) { |
| 625 | // Keep track of which FrameTreeNodes may still have relevant API keys in |
| 626 | // additional FrameNavigationEntries. |
| 627 | std::set<FrameTreeNode*> nodes_to_process; |
| 628 | for (FrameTreeNode* node : controller_->frame_tree().Nodes()) { |
| 629 | nodes_to_process.insert(node); |
| 630 | } |
| 631 | |
| 632 | const int offset = direction == Direction::kForward ? 1 : -1; |
| 633 | const int start = direction == Direction::kForward |
| 634 | ? controller_->GetLastCommittedEntryIndex() |
| 635 | : controller_->GetLastCommittedEntryIndex() - 1; |
| 636 | for (int i = start; |
| 637 | i >= 0 && i < controller_->GetEntryCount() && !nodes_to_process.empty(); |
| 638 | i += offset) { |
| 639 | std::set<FrameTreeNode*> nodes_to_continue_processing; |
| 640 | |
| 641 | NavigationEntryImpl* entry = controller_->GetEntryAtIndex(i); |
| 642 | entry->ForEachFrameEntry([this, &nodes_to_process, |
| 643 | &nodes_to_continue_processing, |
| 644 | &entry](FrameNavigationEntry* frame_entry) { |
| 645 | // Find the |node| that matches |frame_entry|, if any. |
| 646 | FrameTreeNode* node = nullptr; |
| 647 | if (frame_entry == entry->root_node()->frame_entry) { |
| 648 | node = controller_->frame_tree().root(); |
| 649 | } else { |
| 650 | auto it = names_to_nodes_.find(frame_entry->frame_unique_name()); |
| 651 | if (it == names_to_nodes_.end()) |
| 652 | return; |
| 653 | node = it->second; |
| 654 | } |
| 655 | |
| 656 | // Skip this node if a previous step determine there are no longer |
| 657 | // relevant navigation API keys in this direction. |
| 658 | if (nodes_to_process.find(node) == nodes_to_process.end()) |
| 659 | return; |
| 660 | |
| 661 | // Stop processing |node| if we reach a point where it's cross-origin. |
| 662 | // See also PopulateSingleNavigationApiHistoryEntryVector(). |
| 663 | url::Origin frame_entry_origin = |
| 664 | frame_entry->committed_origin().value_or(url::Origin::Resolve( |
| 665 | frame_entry->url(), |
| 666 | frame_entry->initiator_origin().value_or(url::Origin()))); |
| 667 | if (!node->current_origin().IsSameOriginWith(frame_entry_origin)) |
| 668 | return; |
| 669 | |
| 670 | frame_tree_node_id_to_keys_[node->frame_tree_node_id()].insert( |
| 671 | frame_entry->navigation_api_key()); |
| 672 | // Mark |node| as needing more processing for the next entry. |
| 673 | nodes_to_continue_processing.insert(node); |
| 674 | |
| 675 | // Check whether |node| went cross-document. If so, its children are |
| 676 | // no longer the same conceptual iframe as the current one, and |
| 677 | // should no longer be processed. This check is intentionally done |
| 678 | // after processing the current |node|, which may still have relevant |
| 679 | // discarded API keys. |
| 680 | if (frame_entry->document_sequence_number() != |
| 681 | frame_tree_node_id_to_doc_seq_nos_[node->frame_tree_node_id()]) { |
| 682 | for (auto* descendant : node->frame_tree()->SubtreeNodes(node)) |
| 683 | nodes_to_process.erase(descendant); |
| 684 | } |
| 685 | }); |
| 686 | |
| 687 | nodes_to_process.swap(nodes_to_continue_processing); |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | NavigationControllerImpl::RemovedEntriesTracker::~RemovedEntriesTracker() { |
| 692 | std::set<std::string> all_keys; |
| 693 | // Find all remaining navigation API keys after some entries have been |
| 694 | // removed. |
| 695 | for (auto& entry : controller_->entries_) { |
| 696 | entry->ForEachFrameEntry([&all_keys](FrameNavigationEntry* frame_entry) { |
| 697 | all_keys.insert(frame_entry->navigation_api_key()); |
| 698 | }); |
| 699 | } |
| 700 | |
| 701 | // Notify each frame in the renderer of any disposed navigation API keys. |
| 702 | for (auto& id_to_keys : frame_tree_node_id_to_keys_) { |
| 703 | std::vector<std::string> disposed_keys; |
| 704 | for (const auto& key : id_to_keys.second) { |
| 705 | if (all_keys.find(key) == all_keys.end()) |
| 706 | disposed_keys.push_back(key); |
| 707 | } |
| 708 | if (disposed_keys.empty()) |
| 709 | continue; |
| 710 | |
| 711 | FrameTreeNode* node = controller_->frame_tree().FindByID(id_to_keys.first); |
| 712 | auto& frame = node->current_frame_host()->GetAssociatedLocalFrame(); |
| 713 | frame->NotifyNavigationApiOfDisposedEntries(disposed_keys); |
| 714 | } |
| 715 | } |
| 716 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 717 | NavigationControllerImpl::NavigationControllerImpl( |
Carlos Caballero | 40b0efd | 2021-01-26 11:55:00 | [diff] [blame] | 718 | BrowserContext* browser_context, |
| 719 | FrameTree& frame_tree, |
| 720 | NavigationControllerDelegate* delegate) |
| 721 | : frame_tree_(frame_tree), |
| 722 | browser_context_(browser_context), |
[email protected] | ec6c05f | 2013-10-23 18:41:57 | [diff] [blame] | 723 | delegate_(delegate), |
[email protected] | 69e797f | 2013-04-30 01:10:22 | [diff] [blame] | 724 | ssl_manager_(this), |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 725 | get_timestamp_callback_(base::BindRepeating(&base::Time::Now)) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 726 | DCHECK(browser_context_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 727 | } |
| 728 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 729 | NavigationControllerImpl::~NavigationControllerImpl() { |
arthursonzogni | 69a6a1b | 2019-09-17 09:23:00 | [diff] [blame] | 730 | // The NavigationControllerImpl might be called inside its delegate |
| 731 | // destructor. Calling it is not valid anymore. |
| 732 | delegate_ = nullptr; |
| 733 | DiscardNonCommittedEntries(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 734 | } |
| 735 | |
Matt Falkenhagen | 548ed156 | 2021-07-06 01:38:26 | [diff] [blame] | 736 | WebContents* NavigationControllerImpl::DeprecatedGetWebContents() { |
| 737 | return delegate_->DeprecatedGetWebContents(); |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 738 | } |
| 739 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 740 | BrowserContext* NavigationControllerImpl::GetBrowserContext() { |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 741 | return browser_context_; |
| 742 | } |
| 743 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 744 | void NavigationControllerImpl::Restore( |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 745 | int selected_navigation, |
[email protected] | 2ca1ea66 | 2012-10-04 02:26:36 | [diff] [blame] | 746 | RestoreType type, |
dcheng | 9bfa516 | 2016-04-09 01:00:57 | [diff] [blame] | 747 | std::vector<std::unique_ptr<NavigationEntry>>* entries) { |
Charlie Reis | 23c26da | 2022-01-29 00:57:47 | [diff] [blame] | 748 | // Note that it's possible for `entries_` to contain multiple entries at this |
| 749 | // point, as Restore() might be called on a NavigationController that is |
| 750 | // already used (e.g. due to WebView's restoreState() API), not only for fresh |
| 751 | // NavigationControllers. These entries are not cleared to preserve legacy |
| 752 | // behavior and also because `pending_entry_` might point to one of the |
| 753 | // pre-existing entries. An exception for this is when `entries_` contains |
| 754 | // only the initial NavigationEntry, which must be removed. |
| 755 | |
| 756 | // Do not proceed if selected_navigation will be out of bounds for the updated |
| 757 | // entries_ list, since it will be assigned to last_committed_entry_index_ and |
| 758 | // used to index entries_. |
| 759 | // TODO(https://crbug.com/1287624): Consider also returning early if entries |
| 760 | // is empty, since there should be no work to do (rather than marking the |
| 761 | // existing entries as needing reload). Also consider returning early if the |
| 762 | // selected index is -1, which represents a no-committed-entry state. |
| 763 | if (selected_navigation < -1 || |
| 764 | selected_navigation >= |
| 765 | base::checked_cast<int>(entries->size() + entries_.size())) { |
| 766 | return; |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 767 | } |
Charlie Reis | 23c26da | 2022-01-29 00:57:47 | [diff] [blame] | 768 | |
| 769 | if (blink::features::IsInitialNavigationEntryEnabled()) { |
| 770 | // In InitialNavigationEntry mode, there will always be at least one entry. |
| 771 | if (selected_navigation == -1) |
| 772 | selected_navigation = 0; |
| 773 | |
| 774 | if (GetLastCommittedEntry()->IsInitialEntry() && entries->size() > 0) { |
| 775 | // If we are on the initial NavigationEntry, it must be the only entry in |
| 776 | // the list. Since it's impossible to do a history navigation to the |
| 777 | // initial NavigationEntry, `pending_entry_index_` must be -1 (but |
| 778 | // `pending_entry` might be set for a new non-history navigation). |
| 779 | // Note that we should not clear `entries_` if `entries` is empty (when |
| 780 | // InitialNavigationEntry mode is enabled), since that would leave us |
| 781 | // without any NavigationEntry. |
| 782 | CHECK_EQ(1, GetEntryCount()); |
| 783 | CHECK_EQ(-1, pending_entry_index_); |
| 784 | entries_.clear(); |
| 785 | } |
| 786 | } |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 787 | |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 788 | needs_reload_ = true; |
Bo Liu | cdfa4b1 | 2018-11-06 00:21:44 | [diff] [blame] | 789 | needs_reload_type_ = NeedsReloadType::kRestoreSession; |
avi | f16f85a7 | 2015-11-13 18:25:03 | [diff] [blame] | 790 | entries_.reserve(entries->size()); |
Charlie Reis | 23c26da | 2022-01-29 00:57:47 | [diff] [blame] | 791 | for (auto& entry : *entries) { |
Rakina Zata Amni | 996ee41 | 2022-02-17 04:51:43 | [diff] [blame] | 792 | if (entry->GetURL().is_empty()) { |
| 793 | // We're trying to restore an entry with an empty URL (e.g. from |
Rakina Zata Amni | 2729a51 | 2022-03-16 05:54:01 | [diff] [blame] | 794 | // persisting the initial NavigationEntry [which is no longer possible but |
| 795 | // some old persisted sessions might still contain it] or when the |
| 796 | // serializer failed to write the URL because it's too long). Trying to |
| 797 | // restore and navigate to an entry with an empty URL will result in |
| 798 | // crashes, so change the URL to about:blank. See also |
| 799 | // https://crbug.com/1240138 and https://crbug.com/1299335. |
Rakina Zata Amni | 996ee41 | 2022-02-17 04:51:43 | [diff] [blame] | 800 | entry->SetURL(GURL(url::kAboutBlankURL)); |
| 801 | } |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame] | 802 | entries_.push_back( |
| 803 | NavigationEntryImpl::FromNavigationEntry(std::move(entry))); |
Charlie Reis | 23c26da | 2022-01-29 00:57:47 | [diff] [blame] | 804 | } |
avi | f16f85a7 | 2015-11-13 18:25:03 | [diff] [blame] | 805 | |
| 806 | // At this point, the |entries| is full of empty scoped_ptrs, so it can be |
| 807 | // cleared out safely. |
| 808 | entries->clear(); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 809 | |
| 810 | // And finish the restore. |
[email protected] | 2ca1ea66 | 2012-10-04 02:26:36 | [diff] [blame] | 811 | FinishRestore(selected_navigation, type); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 812 | } |
| 813 | |
toyoshim | 6142d96f | 2016-12-19 09:07:25 | [diff] [blame] | 814 | void NavigationControllerImpl::Reload(ReloadType reload_type, |
| 815 | bool check_for_repost) { |
Rakina Zata Amni | d605d46 | 2022-06-01 10:17:03 | [diff] [blame] | 816 | SCOPED_CRASH_KEY_NUMBER("nav_reentrancy_caller1", "Reload_type", |
| 817 | (int)reload_type); |
| 818 | SCOPED_CRASH_KEY_BOOL("nav_reentrancy_caller1", "Reload_check", |
| 819 | check_for_repost); |
liaoyuke | 9168fba | 2017-03-10 19:20:28 | [diff] [blame] | 820 | DCHECK_NE(ReloadType::NONE, reload_type); |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 821 | NavigationEntryImpl* entry = nullptr; |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 822 | int current_index = -1; |
| 823 | |
Carlos IL | 42b41659 | 2019-10-07 23:10:36 | [diff] [blame] | 824 | if (entry_replaced_by_post_commit_error_) { |
| 825 | // If there is an entry that was replaced by a currently active post-commit |
| 826 | // error navigation, this can't be the initial navigation. |
| 827 | DCHECK(!IsInitialNavigation()); |
| 828 | // If the current entry is a post commit error, we reload the entry it |
| 829 | // replaced instead. We leave the error entry in place until a commit |
| 830 | // replaces it, but the pending entry points to the original entry in the |
| 831 | // meantime. Note that NavigateToExistingPendingEntry is able to handle the |
| 832 | // case that pending_entry_ != entries_[pending_entry_index_]. |
| 833 | entry = entry_replaced_by_post_commit_error_.get(); |
| 834 | current_index = GetCurrentEntryIndex(); |
| 835 | } else if (IsInitialNavigation() && pending_entry_) { |
| 836 | // If we are reloading the initial navigation, just use the current |
| 837 | // pending entry. Otherwise look up the current entry. |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 838 | entry = pending_entry_; |
| 839 | // The pending entry might be in entries_ (e.g., after a Clone), so we |
| 840 | // should also update the current_index. |
| 841 | current_index = pending_entry_index_; |
| 842 | } else { |
arthursonzogni | 69a6a1b | 2019-09-17 09:23:00 | [diff] [blame] | 843 | DiscardNonCommittedEntries(); |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 844 | current_index = GetCurrentEntryIndex(); |
| 845 | if (current_index != -1) { |
creis | 3da0387 | 2015-02-20 21:12:32 | [diff] [blame] | 846 | entry = GetEntryAtIndex(current_index); |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 847 | } |
[email protected] | 979a4bc | 2013-04-24 01:27:15 | [diff] [blame] | 848 | } |
[email protected] | 241db35 | 2013-04-22 18:04:05 | [diff] [blame] | 849 | |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 850 | // If we are no where, then we can't reload. TODO(darin): We should add a |
| 851 | // CanReload method. |
| 852 | if (!entry) |
| 853 | return; |
| 854 | |
Rakina Zata Amni | f297a80 | 2022-01-18 03:53:43 | [diff] [blame] | 855 | if (entry->IsInitialEntryNotForSynchronousAboutBlank()) { |
| 856 | // We should never navigate to an existing initial NavigationEntry that is |
| 857 | // the initial NavigationEntry for the initial empty document that hasn't |
| 858 | // been overridden by the synchronous about:blank commit, to preserve |
| 859 | // legacy behavior where trying to reload when the main frame is on the |
| 860 | // initial empty document won't result in a navigation. See also |
| 861 | // https://crbug.com/1277414. |
| 862 | return; |
| 863 | } |
| 864 | |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 865 | if (g_check_for_repost && check_for_repost && entry->GetHasPostData()) { |
[email protected] | a3a1d14 | 2008-12-19 00:42:30 | [diff] [blame] | 866 | // The user is asking to reload a page with POST data. Prompt to make sure |
[email protected] | b5bb35f | 2009-02-05 20:17:07 | [diff] [blame] | 867 | // they really want to do this. If they do, the dialog will call us back |
| 868 | // with check_for_repost = false. |
[email protected] | ec6c05f | 2013-10-23 18:41:57 | [diff] [blame] | 869 | delegate_->NotifyBeforeFormRepostWarningShow(); |
[email protected] | 965bb09 | 2010-04-09 11:59:02 | [diff] [blame] | 870 | |
[email protected] | 106a081 | 2010-03-18 00:15:12 | [diff] [blame] | 871 | pending_reload_ = reload_type; |
[email protected] | ec6c05f | 2013-10-23 18:41:57 | [diff] [blame] | 872 | delegate_->ActivateAndShowRepostFormWarningDialog(); |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 873 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 874 | } |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 875 | |
Wang Hui | a25efabc | 2022-09-24 17:27:22 | [diff] [blame] | 876 | // Set ReloadType for |entry|. |
| 877 | entry->set_reload_type(reload_type); |
| 878 | |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 879 | if (!IsInitialNavigation()) |
| 880 | DiscardNonCommittedEntries(); |
| 881 | |
| 882 | pending_entry_ = entry; |
| 883 | pending_entry_index_ = current_index; |
| 884 | pending_entry_->SetTransitionType(ui::PAGE_TRANSITION_RELOAD); |
| 885 | |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 886 | // location.reload() goes through BeginNavigation, so all reloads triggered |
| 887 | // via this codepath are browser initiated. |
Nate Chapin | bf682fa3 | 2022-09-26 22:41:20 | [diff] [blame] | 888 | NavigateToExistingPendingEntry(reload_type, nullptr /* initiator_frame */, |
| 889 | nullptr /* navigation_api_key */); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 890 | } |
| 891 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 892 | void NavigationControllerImpl::CancelPendingReload() { |
toyoshim | 0df1d3a | 2016-09-09 09:52:48 | [diff] [blame] | 893 | pending_reload_ = ReloadType::NONE; |
[email protected] | 106a081 | 2010-03-18 00:15:12 | [diff] [blame] | 894 | } |
| 895 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 896 | void NavigationControllerImpl::ContinuePendingReload() { |
Wang Hui | 96ab101 | 2022-10-11 02:05:49 | [diff] [blame] | 897 | // If the pending reload type has been cleared by another navigation |
| 898 | // committing, then do not proceed to reload after a form repost dialog. |
toyoshim | 0df1d3a | 2016-09-09 09:52:48 | [diff] [blame] | 899 | if (pending_reload_ == ReloadType::NONE) { |
Wang Hui | 96ab101 | 2022-10-11 02:05:49 | [diff] [blame] | 900 | return; |
[email protected] | 106a081 | 2010-03-18 00:15:12 | [diff] [blame] | 901 | } |
Wang Hui | 96ab101 | 2022-10-11 02:05:49 | [diff] [blame] | 902 | Reload(pending_reload_, false); |
| 903 | pending_reload_ = ReloadType::NONE; |
[email protected] | 106a081 | 2010-03-18 00:15:12 | [diff] [blame] | 904 | } |
| 905 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 906 | bool NavigationControllerImpl::IsInitialNavigation() { |
[email protected] | 27ba81c | 2012-08-21 17:04:09 | [diff] [blame] | 907 | return is_initial_navigation_; |
[email protected] | c70f9b8 | 2010-04-21 07:31:11 | [diff] [blame] | 908 | } |
| 909 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 910 | bool NavigationControllerImpl::IsInitialBlankNavigation() { |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 911 | if (blink::features::IsInitialNavigationEntryEnabled()) { |
| 912 | // Check that we're on the initial NavigationEntry and that this is not a |
| 913 | // cloned tab. |
| 914 | return IsInitialNavigation() && GetEntryCount() == 1 && |
| 915 | GetLastCommittedEntry()->IsInitialEntry() && |
| 916 | GetLastCommittedEntry()->restore_type() == RestoreType::kNotRestored; |
| 917 | } else { |
| 918 | return IsInitialNavigation() && GetEntryCount() == 0; |
| 919 | } |
creis | 10a4ab7 | 2015-10-13 17:22:40 | [diff] [blame] | 920 | } |
| 921 | |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 922 | NavigationEntryImpl* NavigationControllerImpl::GetEntryWithUniqueID( |
| 923 | int nav_entry_id) const { |
avi | 254eff0 | 2015-07-01 08:27:58 | [diff] [blame] | 924 | int index = GetEntryIndexWithUniqueID(nav_entry_id); |
avi | f16f85a7 | 2015-11-13 18:25:03 | [diff] [blame] | 925 | return (index != -1) ? entries_[index].get() : nullptr; |
avi | 254eff0 | 2015-07-01 08:27:58 | [diff] [blame] | 926 | } |
| 927 | |
Adithya Srinivasan | 9b0c99c | 2021-08-10 15:19:45 | [diff] [blame] | 928 | NavigationEntryImpl* |
| 929 | NavigationControllerImpl::GetEntryWithUniqueIDIncludingPending( |
| 930 | int nav_entry_id) const { |
| 931 | NavigationEntryImpl* entry = GetEntryWithUniqueID(nav_entry_id); |
| 932 | if (entry) |
| 933 | return entry; |
| 934 | return pending_entry_ && pending_entry_->GetUniqueID() == nav_entry_id |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 935 | ? pending_entry_.get() |
Adithya Srinivasan | 9b0c99c | 2021-08-10 15:19:45 | [diff] [blame] | 936 | : nullptr; |
| 937 | } |
| 938 | |
W. James MacLean | c07dc41b | 2022-07-25 18:52:16 | [diff] [blame] | 939 | void NavigationControllerImpl::RegisterExistingOriginAsHavingDefaultIsolation( |
W. James MacLean | 1c40862c | 2020-04-27 21:05:57 | [diff] [blame] | 940 | const url::Origin& origin) { |
| 941 | for (int i = 0; i < GetEntryCount(); i++) { |
| 942 | auto* entry = GetEntryAtIndex(i); |
W. James MacLean | c07dc41b | 2022-07-25 18:52:16 | [diff] [blame] | 943 | entry->RegisterExistingOriginAsHavingDefaultIsolation(origin); |
W. James MacLean | 1c40862c | 2020-04-27 21:05:57 | [diff] [blame] | 944 | } |
| 945 | if (entry_replaced_by_post_commit_error_) { |
| 946 | // It's possible we could come back to this entry if the error |
| 947 | // page/interstitial goes away. |
| 948 | entry_replaced_by_post_commit_error_ |
W. James MacLean | c07dc41b | 2022-07-25 18:52:16 | [diff] [blame] | 949 | ->RegisterExistingOriginAsHavingDefaultIsolation(origin); |
W. James MacLean | 1c40862c | 2020-04-27 21:05:57 | [diff] [blame] | 950 | } |
W. James MacLean | 1c40862c | 2020-04-27 21:05:57 | [diff] [blame] | 951 | } |
| 952 | |
avi | 2576470 | 2015-06-23 15:43:37 | [diff] [blame] | 953 | void NavigationControllerImpl::SetPendingEntry( |
dcheng | 9bfa516 | 2016-04-09 01:00:57 | [diff] [blame] | 954 | std::unique_ptr<NavigationEntryImpl> entry) { |
arthursonzogni | 69a6a1b | 2019-09-17 09:23:00 | [diff] [blame] | 955 | DiscardNonCommittedEntries(); |
avi | 2576470 | 2015-06-23 15:43:37 | [diff] [blame] | 956 | pending_entry_ = entry.release(); |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 957 | DCHECK_EQ(-1, pending_entry_index_); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 958 | } |
| 959 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 960 | NavigationEntryImpl* NavigationControllerImpl::GetActiveEntry() { |
[email protected] | cbab76d | 2008-10-13 22:42:47 | [diff] [blame] | 961 | if (pending_entry_) |
| 962 | return pending_entry_; |
| 963 | return GetLastCommittedEntry(); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 964 | } |
| 965 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 966 | NavigationEntryImpl* NavigationControllerImpl::GetVisibleEntry() { |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 967 | // The pending entry is safe to return for new (non-history), browser- |
| 968 | // initiated navigations. Most renderer-initiated navigations should not |
| 969 | // show the pending entry, to prevent URL spoof attacks. |
| 970 | // |
| 971 | // We make an exception for renderer-initiated navigations in new tabs, as |
| 972 | // long as no other page has tried to access the initial empty document in |
| 973 | // the new tab. If another page modifies this blank page, a URL spoof is |
| 974 | // possible, so we must stop showing the pending entry. |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 975 | bool safe_to_show_pending = |
| 976 | pending_entry_ && |
| 977 | // Require a new navigation. |
avi | 0dca04d | 2015-01-26 20:21:09 | [diff] [blame] | 978 | pending_entry_index_ == -1 && |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 979 | // Require either browser-initiated or an unmodified new tab. |
[email protected] | aa62afd | 2014-04-22 19:22:46 | [diff] [blame] | 980 | (!pending_entry_->is_renderer_initiated() || IsUnmodifiedBlankTab()); |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 981 | |
| 982 | // Also allow showing the pending entry for history navigations in a new tab, |
| 983 | // such as Ctrl+Back. In this case, no existing page is visible and no one |
| 984 | // can script the new tab before it commits. |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 985 | if (!safe_to_show_pending && pending_entry_ && pending_entry_index_ != -1 && |
| 986 | IsInitialNavigation() && !pending_entry_->is_renderer_initiated()) |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 987 | safe_to_show_pending = true; |
| 988 | |
| 989 | if (safe_to_show_pending) |
[email protected] | 867e1f9 | 2011-08-30 19:01:19 | [diff] [blame] | 990 | return pending_entry_; |
| 991 | return GetLastCommittedEntry(); |
| 992 | } |
| 993 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 994 | int NavigationControllerImpl::GetCurrentEntryIndex() { |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 995 | if (pending_entry_index_ != -1) |
| 996 | return pending_entry_index_; |
| 997 | return last_committed_entry_index_; |
| 998 | } |
| 999 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 1000 | NavigationEntryImpl* NavigationControllerImpl::GetLastCommittedEntry() { |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 1001 | if (last_committed_entry_index_ == -1) { |
| 1002 | // The last committed entry must always exist when InitialNavigationEntry |
| 1003 | // is enabled. TODO(https://crbug.com/524208): Remove this case and all |
| 1004 | // related nullchecks entirely. |
| 1005 | DCHECK(!blink::features::IsInitialNavigationEntryEnabled()); |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 1006 | return nullptr; |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 1007 | } |
avi | f16f85a7 | 2015-11-13 18:25:03 | [diff] [blame] | 1008 | return entries_[last_committed_entry_index_].get(); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 1009 | } |
| 1010 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 1011 | bool NavigationControllerImpl::CanViewSource() { |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 1012 | const std::string& mime_type = |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 1013 | frame_tree_->root()->current_frame_host()->GetPage().contents_mime_type(); |
Kinuko Yasuda | 74702f9 | 2017-07-31 03:27:53 | [diff] [blame] | 1014 | bool is_viewable_mime_type = blink::IsSupportedNonImageMimeType(mime_type) && |
| 1015 | !media::IsSupportedMediaMimeType(mime_type); |
[email protected] | 6286a379 | 2013-10-09 04:03:27 | [diff] [blame] | 1016 | NavigationEntry* visible_entry = GetVisibleEntry(); |
| 1017 | return visible_entry && !visible_entry->IsViewSourceMode() && |
Carlos IL | d51e770 | 2020-05-07 18:51:39 | [diff] [blame] | 1018 | is_viewable_mime_type; |
[email protected] | 3168228 | 2010-01-15 18:05:16 | [diff] [blame] | 1019 | } |
| 1020 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 1021 | int NavigationControllerImpl::GetLastCommittedEntryIndex() { |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 1022 | // The last committed entry index must always be less than the number of |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 1023 | // entries. If there are no entries, it must be -1. |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 1024 | DCHECK_LT(last_committed_entry_index_, GetEntryCount()); |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 1025 | DCHECK(GetEntryCount() || last_committed_entry_index_ == -1); |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 1026 | return last_committed_entry_index_; |
| 1027 | } |
| 1028 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 1029 | int NavigationControllerImpl::GetEntryCount() { |
Carlos IL | 4dea890 | 2020-05-26 15:14:29 | [diff] [blame] | 1030 | DCHECK_LE(entries_.size(), max_entry_count()); |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 1031 | return static_cast<int>(entries_.size()); |
| 1032 | } |
| 1033 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 1034 | NavigationEntryImpl* NavigationControllerImpl::GetEntryAtIndex(int index) { |
avi | 2576470 | 2015-06-23 15:43:37 | [diff] [blame] | 1035 | if (index < 0 || index >= GetEntryCount()) |
| 1036 | return nullptr; |
| 1037 | |
avi | f16f85a7 | 2015-11-13 18:25:03 | [diff] [blame] | 1038 | return entries_[index].get(); |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 1039 | } |
| 1040 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 1041 | NavigationEntryImpl* NavigationControllerImpl::GetEntryAtOffset(int offset) { |
avi | 057ce149 | 2015-06-29 15:59:47 | [diff] [blame] | 1042 | return GetEntryAtIndex(GetIndexForOffset(offset)); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 1043 | } |
| 1044 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 1045 | int NavigationControllerImpl::GetIndexForOffset(int offset) { |
[email protected] | 7bc2b03 | 2012-12-19 22:45:46 | [diff] [blame] | 1046 | return GetCurrentEntryIndex() + offset; |
[email protected] | 9ba1405 | 2012-06-22 23:50:03 | [diff] [blame] | 1047 | } |
| 1048 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 1049 | bool NavigationControllerImpl::CanGoBack() { |
Shivani Sharma | 298d1285 | 2019-01-22 20:04:03 | [diff] [blame] | 1050 | for (int index = GetIndexForOffset(-1); index >= 0; index--) { |
| 1051 | if (!GetEntryAtIndex(index)->should_skip_on_back_forward_ui()) |
| 1052 | return true; |
| 1053 | } |
| 1054 | return false; |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 1055 | } |
| 1056 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 1057 | bool NavigationControllerImpl::CanGoForward() { |
WangHui | 74286d5 | 2021-03-31 16:17:15 | [diff] [blame] | 1058 | for (int index = GetIndexForOffset(1); index < GetEntryCount(); index++) { |
| 1059 | if (!GetEntryAtIndex(index)->should_skip_on_back_forward_ui()) |
| 1060 | return true; |
| 1061 | } |
| 1062 | return false; |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 1063 | } |
| 1064 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 1065 | bool NavigationControllerImpl::CanGoToOffset(int offset) { |
[email protected] | 9ba1405 | 2012-06-22 23:50:03 | [diff] [blame] | 1066 | int index = GetIndexForOffset(offset); |
| 1067 | return index >= 0 && index < GetEntryCount(); |
| 1068 | } |
| 1069 | |
Xiaohan Wang | 7f8052e0 | 2022-01-14 18:44:28 | [diff] [blame] | 1070 | #if BUILDFLAG(IS_ANDROID) |
WangHui | 74286d5 | 2021-03-31 16:17:15 | [diff] [blame] | 1071 | bool NavigationControllerImpl::CanGoToOffsetWithSkipping(int offset) { |
WangHui | 74286d5 | 2021-03-31 16:17:15 | [diff] [blame] | 1072 | if (offset == 0) |
| 1073 | return true; |
| 1074 | int increment = offset > 0 ? 1 : -1; |
| 1075 | int non_skippable_entries = 0; |
| 1076 | for (int index = GetIndexForOffset(increment); |
| 1077 | index >= 0 && index < GetEntryCount(); index += increment) { |
| 1078 | if (!GetEntryAtIndex(index)->should_skip_on_back_forward_ui()) |
| 1079 | non_skippable_entries++; |
| 1080 | |
| 1081 | if (non_skippable_entries == std::abs(offset)) |
| 1082 | return true; |
| 1083 | } |
| 1084 | return false; |
| 1085 | } |
| 1086 | #endif |
| 1087 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 1088 | void NavigationControllerImpl::GoBack() { |
shivanisha | 5520187 | 2018-12-13 04:29:06 | [diff] [blame] | 1089 | int target_index = GetIndexForOffset(-1); |
| 1090 | |
Elly Fong-Jones | 40ee811 | 2021-06-23 19:10:52 | [diff] [blame] | 1091 | // Move the target index past the skippable entries. |
Shivani Sharma | 298d1285 | 2019-01-22 20:04:03 | [diff] [blame] | 1092 | bool all_skippable_entries = true; |
Elly Fong-Jones | 40ee811 | 2021-06-23 19:10:52 | [diff] [blame] | 1093 | while (target_index >= 0) { |
| 1094 | if (!GetEntryAtIndex(target_index)->should_skip_on_back_forward_ui()) { |
Shivani Sharma | 298d1285 | 2019-01-22 20:04:03 | [diff] [blame] | 1095 | all_skippable_entries = false; |
shivanisha | 5520187 | 2018-12-13 04:29:06 | [diff] [blame] | 1096 | break; |
Shivani Sharma | 2d5b4b6b | 2019-01-08 16:07:16 | [diff] [blame] | 1097 | } |
Elly Fong-Jones | 40ee811 | 2021-06-23 19:10:52 | [diff] [blame] | 1098 | target_index--; |
shivanisha | 5520187 | 2018-12-13 04:29:06 | [diff] [blame] | 1099 | } |
Miyoung Shin | 1c565c91 | 2021-03-17 12:11:21 | [diff] [blame] | 1100 | |
Shivani Sharma | 298d1285 | 2019-01-22 20:04:03 | [diff] [blame] | 1101 | // Do nothing if all entries are skippable. Normally this path would not |
| 1102 | // happen as consumers would have already checked it in CanGoBack but a lot of |
| 1103 | // tests do not do that. |
Elly Fong-Jones | ccc6d1f | 2021-06-14 18:32:42 | [diff] [blame] | 1104 | if (all_skippable_entries) |
Shivani Sharma | 298d1285 | 2019-01-22 20:04:03 | [diff] [blame] | 1105 | return; |
shivanisha | 5520187 | 2018-12-13 04:29:06 | [diff] [blame] | 1106 | |
shivanisha | 5520187 | 2018-12-13 04:29:06 | [diff] [blame] | 1107 | GoToIndex(target_index); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 1108 | } |
| 1109 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 1110 | void NavigationControllerImpl::GoForward() { |
shivanisha | 5520187 | 2018-12-13 04:29:06 | [diff] [blame] | 1111 | int target_index = GetIndexForOffset(1); |
| 1112 | |
Shivani Sharma | 2d5b4b6b | 2019-01-08 16:07:16 | [diff] [blame] | 1113 | // Note that at least one entry (the last one) will be non-skippable since |
| 1114 | // entries are marked skippable only when they add another entry because of |
| 1115 | // redirect or pushState. |
Elly Fong-Jones | 40ee811 | 2021-06-23 19:10:52 | [diff] [blame] | 1116 | while (target_index < static_cast<int>(entries_.size())) { |
| 1117 | if (!GetEntryAtIndex(target_index)->should_skip_on_back_forward_ui()) |
shivanisha | 5520187 | 2018-12-13 04:29:06 | [diff] [blame] | 1118 | break; |
Elly Fong-Jones | 40ee811 | 2021-06-23 19:10:52 | [diff] [blame] | 1119 | target_index++; |
shivanisha | 5520187 | 2018-12-13 04:29:06 | [diff] [blame] | 1120 | } |
shivanisha | 5520187 | 2018-12-13 04:29:06 | [diff] [blame] | 1121 | GoToIndex(target_index); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 1122 | } |
| 1123 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 1124 | void NavigationControllerImpl::GoToIndex(int index) { |
Nate Chapin | bf682fa3 | 2022-09-26 22:41:20 | [diff] [blame] | 1125 | GoToIndex(index, nullptr /* initiator_frame */, |
| 1126 | nullptr /* navigation_api_key */); |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 1127 | } |
| 1128 | |
Nate Chapin | bf682fa3 | 2022-09-26 22:41:20 | [diff] [blame] | 1129 | void NavigationControllerImpl::GoToIndex( |
| 1130 | int index, |
| 1131 | RenderFrameHostImpl* initiator_rfh, |
| 1132 | const std::string* navigation_api_key) { |
Rakina Zata Amni | d605d46 | 2022-06-01 10:17:03 | [diff] [blame] | 1133 | SCOPED_CRASH_KEY_NUMBER("nav_reentrancy_caller1", "GoToIndex_index", index); |
sunjian | 30574a6 | 2017-03-21 21:39:44 | [diff] [blame] | 1134 | TRACE_EVENT0("browser,navigation,benchmark", |
| 1135 | "NavigationControllerImpl::GoToIndex"); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 1136 | if (index < 0 || index >= static_cast<int>(entries_.size())) { |
| 1137 | NOTREACHED(); |
| 1138 | return; |
| 1139 | } |
| 1140 | |
Rakina Zata Amni | f297a80 | 2022-01-18 03:53:43 | [diff] [blame] | 1141 | if (entries_[index]->IsInitialEntryNotForSynchronousAboutBlank()) { |
| 1142 | // We should never navigate to an existing initial NavigationEntry that is |
| 1143 | // the initial NavigationEntry for the initial empty document that hasn't |
| 1144 | // been overridden by the synchronous about:blank commit, to preserve |
| 1145 | // legacy behavior where trying to reload when the main frame is on the |
| 1146 | // initial empty document won't result in a navigation. See also |
| 1147 | // https://crbug.com/1277414. |
| 1148 | return; |
| 1149 | } |
| 1150 | |
[email protected] | cbab76d | 2008-10-13 22:42:47 | [diff] [blame] | 1151 | DiscardNonCommittedEntries(); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 1152 | |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 1153 | DCHECK_EQ(nullptr, pending_entry_); |
| 1154 | DCHECK_EQ(-1, pending_entry_index_); |
Rakina Zata Amni | f297a80 | 2022-01-18 03:53:43 | [diff] [blame] | 1155 | |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 1156 | pending_entry_ = entries_[index].get(); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 1157 | pending_entry_index_ = index; |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 1158 | pending_entry_->SetTransitionType(ui::PageTransitionFromInt( |
| 1159 | pending_entry_->GetTransitionType() | ui::PAGE_TRANSITION_FORWARD_BACK)); |
Nate Chapin | bf682fa3 | 2022-09-26 22:41:20 | [diff] [blame] | 1160 | NavigateToExistingPendingEntry(ReloadType::NONE, initiator_rfh, |
| 1161 | navigation_api_key); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 1162 | } |
| 1163 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 1164 | void NavigationControllerImpl::GoToOffset(int offset) { |
toyoshim | 3af4d50 | 2016-03-30 12:38:12 | [diff] [blame] | 1165 | // Note: This is actually reached in unit tests. |
[email protected] | 9ba1405 | 2012-06-22 23:50:03 | [diff] [blame] | 1166 | if (!CanGoToOffset(offset)) |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 1167 | return; |
| 1168 | |
[email protected] | 9ba1405 | 2012-06-22 23:50:03 | [diff] [blame] | 1169 | GoToIndex(GetIndexForOffset(offset)); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 1170 | } |
| 1171 | |
Nate Chapin | bf682fa3 | 2022-09-26 22:41:20 | [diff] [blame] | 1172 | void NavigationControllerImpl::GoToOffsetFromRenderer( |
| 1173 | int offset, |
| 1174 | RenderFrameHostImpl* initiator_rfh) { |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 1175 | // Note: This is actually reached in unit tests. |
| 1176 | if (!CanGoToOffset(offset)) |
| 1177 | return; |
| 1178 | |
Nate Chapin | bf682fa3 | 2022-09-26 22:41:20 | [diff] [blame] | 1179 | GoToIndex(GetIndexForOffset(offset), initiator_rfh, |
| 1180 | nullptr /* navigation_api_key */); |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 1181 | } |
| 1182 | |
Xiaohan Wang | 7f8052e0 | 2022-01-14 18:44:28 | [diff] [blame] | 1183 | #if BUILDFLAG(IS_ANDROID) |
WangHui | 74286d5 | 2021-03-31 16:17:15 | [diff] [blame] | 1184 | void NavigationControllerImpl::GoToOffsetWithSkipping(int offset) { |
| 1185 | // Note: This is actually reached in unit tests. |
| 1186 | if (!CanGoToOffsetWithSkipping(offset)) |
| 1187 | return; |
| 1188 | |
Elly Fong-Jones | ccc6d1f | 2021-06-14 18:32:42 | [diff] [blame] | 1189 | if (offset == 0) { |
WangHui | 74286d5 | 2021-03-31 16:17:15 | [diff] [blame] | 1190 | GoToIndex(GetIndexForOffset(offset)); |
| 1191 | return; |
| 1192 | } |
| 1193 | int increment = offset > 0 ? 1 : -1; |
| 1194 | // Find the offset without counting skippable entries. |
| 1195 | int target_index = GetIndexForOffset(increment); |
| 1196 | int non_skippable_entries = 0; |
| 1197 | for (int index = target_index; index >= 0 && index < GetEntryCount(); |
| 1198 | index += increment) { |
| 1199 | if (!GetEntryAtIndex(index)->should_skip_on_back_forward_ui()) |
| 1200 | non_skippable_entries++; |
| 1201 | |
| 1202 | if (non_skippable_entries == std::abs(offset)) { |
| 1203 | target_index = index; |
| 1204 | break; |
| 1205 | } |
| 1206 | } |
| 1207 | |
| 1208 | GoToIndex(target_index); |
| 1209 | } |
| 1210 | #endif |
| 1211 | |
[email protected] | 41374f1 | 2013-07-24 02:49:28 | [diff] [blame] | 1212 | bool NavigationControllerImpl::RemoveEntryAtIndex(int index) { |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 1213 | if (index == last_committed_entry_index_ || index == pending_entry_index_) |
[email protected] | 41374f1 | 2013-07-24 02:49:28 | [diff] [blame] | 1214 | return false; |
[email protected] | 6a13a6c | 2011-12-20 21:47:12 | [diff] [blame] | 1215 | |
[email protected] | 4303234 | 2011-03-21 14:10:31 | [diff] [blame] | 1216 | RemoveEntryAtIndexInternal(index); |
[email protected] | 41374f1 | 2013-07-24 02:49:28 | [diff] [blame] | 1217 | return true; |
[email protected] | cbab76d | 2008-10-13 22:42:47 | [diff] [blame] | 1218 | } |
| 1219 | |
Michael Thiessen | 9b14d51 | 2019-09-23 21:19:47 | [diff] [blame] | 1220 | void NavigationControllerImpl::PruneForwardEntries() { |
| 1221 | DiscardNonCommittedEntries(); |
| 1222 | int remove_start_index = last_committed_entry_index_ + 1; |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 1223 | int num_removed = static_cast<int>(entries_.size()) - remove_start_index; |
Michael Thiessen | 9b14d51 | 2019-09-23 21:19:47 | [diff] [blame] | 1224 | if (num_removed <= 0) |
| 1225 | return; |
Nate Chapin | 9eb16be7 | 2022-09-23 22:54:31 | [diff] [blame] | 1226 | RemovedEntriesTracker tracker(weak_factory_.GetSafeRef()); |
Michael Thiessen | 9b14d51 | 2019-09-23 21:19:47 | [diff] [blame] | 1227 | entries_.erase(entries_.begin() + remove_start_index, entries_.end()); |
| 1228 | NotifyPrunedEntries(this, remove_start_index /* start index */, |
| 1229 | num_removed /* count */); |
| 1230 | } |
| 1231 | |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 1232 | void NavigationControllerImpl::UpdateVirtualURLToURL(NavigationEntryImpl* entry, |
| 1233 | const GURL& new_url) { |
[email protected] | 38178a4 | 2009-12-17 18:58:32 | [diff] [blame] | 1234 | GURL new_virtual_url(new_url); |
[email protected] | 825b166 | 2012-03-12 19:07:31 | [diff] [blame] | 1235 | if (BrowserURLHandlerImpl::GetInstance()->ReverseURLRewrite( |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1236 | &new_virtual_url, entry->GetVirtualURL(), browser_context_)) { |
| 1237 | entry->SetVirtualURL(new_virtual_url); |
[email protected] | 38178a4 | 2009-12-17 18:58:32 | [diff] [blame] | 1238 | } |
| 1239 | } |
| 1240 | |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 1241 | base::WeakPtr<NavigationHandle> NavigationControllerImpl::LoadURL( |
| 1242 | const GURL& url, |
| 1243 | const Referrer& referrer, |
| 1244 | ui::PageTransition transition, |
| 1245 | const std::string& extra_headers) { |
[email protected] | cf00233 | 2012-08-14 19:17:47 | [diff] [blame] | 1246 | LoadURLParams params(url); |
| 1247 | params.referrer = referrer; |
| 1248 | params.transition_type = transition; |
| 1249 | params.extra_headers = extra_headers; |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 1250 | return LoadURLWithParams(params); |
[email protected] | cf00233 | 2012-08-14 19:17:47 | [diff] [blame] | 1251 | } |
| 1252 | |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 1253 | base::WeakPtr<NavigationHandle> NavigationControllerImpl::LoadURLWithParams( |
| 1254 | const LoadURLParams& params) { |
Lukasz Anforowicz | 435bcb58 | 2019-07-12 20:50:06 | [diff] [blame] | 1255 | if (params.is_renderer_initiated) |
| 1256 | DCHECK(params.initiator_origin.has_value()); |
| 1257 | |
nasko | b8744d2 | 2014-08-28 17:07:43 | [diff] [blame] | 1258 | TRACE_EVENT1("browser,navigation", |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 1259 | "NavigationControllerImpl::LoadURLWithParams", "url", |
| 1260 | params.url.possibly_invalid_spec()); |
Ian Vollick | 9dda052 | 2019-09-11 02:24:29 | [diff] [blame] | 1261 | bool is_explicit_navigation = |
| 1262 | GetContentClient()->browser()->IsExplicitNavigation( |
| 1263 | params.transition_type); |
| 1264 | if (HandleDebugURL(params.url, params.transition_type, |
| 1265 | is_explicit_navigation)) { |
[email protected] | 4775298 | 2014-07-29 08:01:43 | [diff] [blame] | 1266 | // If Telemetry is running, allow the URL load to proceed as if it's |
| 1267 | // unhandled, otherwise Telemetry can't tell if Navigation completed. |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 1268 | if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
[email protected] | 4775298 | 2014-07-29 08:01:43 | [diff] [blame] | 1269 | cc::switches::kEnableGpuBenchmarking)) |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 1270 | return nullptr; |
[email protected] | 4775298 | 2014-07-29 08:01:43 | [diff] [blame] | 1271 | } |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 1272 | |
[email protected] | cf00233 | 2012-08-14 19:17:47 | [diff] [blame] | 1273 | // Checks based on params.load_type. |
| 1274 | switch (params.load_type) { |
| 1275 | case LOAD_TYPE_DEFAULT: |
lukasza | 477a5a2 | 2016-06-16 18:28:43 | [diff] [blame] | 1276 | case LOAD_TYPE_HTTP_POST: |
[email protected] | cf00233 | 2012-08-14 19:17:47 | [diff] [blame] | 1277 | break; |
| 1278 | case LOAD_TYPE_DATA: |
[email protected] | cca6f39 | 2014-05-28 21:32:26 | [diff] [blame] | 1279 | if (!params.url.SchemeIs(url::kDataScheme)) { |
[email protected] | cf00233 | 2012-08-14 19:17:47 | [diff] [blame] | 1280 | NOTREACHED() << "Data load must use data scheme."; |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 1281 | return nullptr; |
[email protected] | cf00233 | 2012-08-14 19:17:47 | [diff] [blame] | 1282 | } |
| 1283 | break; |
Lukasz Anforowicz | bb0cfd5e | 2017-12-14 22:39:46 | [diff] [blame] | 1284 | } |
[email protected] | e47ae947 | 2011-10-13 19:48:34 | [diff] [blame] | 1285 | |
[email protected] | e47ae947 | 2011-10-13 19:48:34 | [diff] [blame] | 1286 | // The user initiated a load, we don't need to reload anymore. |
| 1287 | needs_reload_ = false; |
| 1288 | |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 1289 | return NavigateWithoutEntry(params); |
[email protected] | 132e281a | 2012-07-31 18:32:44 | [diff] [blame] | 1290 | } |
| 1291 | |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 1292 | bool NavigationControllerImpl::PendingEntryMatchesRequest( |
| 1293 | NavigationRequest* request) const { |
creis | b4dc933 | 2016-03-14 21:39:19 | [diff] [blame] | 1294 | return pending_entry_ && |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 1295 | pending_entry_->GetUniqueID() == request->nav_entry_id(); |
creis | b4dc933 | 2016-03-14 21:39:19 | [diff] [blame] | 1296 | } |
| 1297 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 1298 | bool NavigationControllerImpl::RendererDidNavigate( |
creis | 3da0387 | 2015-02-20 21:12:32 | [diff] [blame] | 1299 | RenderFrameHostImpl* rfh, |
arthursonzogni | 73fe321 | 2020-11-17 13:24:07 | [diff] [blame] | 1300 | const mojom::DidCommitProvisionalLoadParams& params, |
peary2 | 1b0f797b | 2016-09-28 17:28:33 | [diff] [blame] | 1301 | LoadCommittedDetails* details, |
Eugene But | 712f03d | 2018-05-22 16:03:44 | [diff] [blame] | 1302 | bool is_same_document_navigation, |
Nate Chapin | c7019dd7d | 2021-06-25 18:29:25 | [diff] [blame] | 1303 | bool was_on_initial_empty_document, |
Shivani Sharma | ffb32b8 | 2019-04-09 16:58:47 | [diff] [blame] | 1304 | bool previous_document_was_activated, |
Camille Lamy | 10aafcd3 | 2018-12-05 15:48:13 | [diff] [blame] | 1305 | NavigationRequest* navigation_request) { |
| 1306 | DCHECK(navigation_request); |
Chris Bookholt | 27faf8d | 2022-01-20 01:03:33 | [diff] [blame] | 1307 | |
| 1308 | // Note: validation checks and renderer kills due to invalid commit messages |
| 1309 | // must happen before getting here, in |
| 1310 | // RenderFrameHostImpl::ValidateDidCommitParams. By the time we get here, some |
| 1311 | // effects of the navigation have already occurred. |
| 1312 | |
[email protected] | cd2e1574 | 2013-03-08 04:08:31 | [diff] [blame] | 1313 | is_initial_navigation_ = false; |
| 1314 | |
Wang Hui | 96ab101 | 2022-10-11 02:05:49 | [diff] [blame] | 1315 | // Any pending request to repost a form submission is no longer valid, since a |
| 1316 | // different NavigationEntry is committing. |
| 1317 | pending_reload_ = ReloadType::NONE; |
| 1318 | |
[email protected] | 0e8db94 | 2008-09-24 21:21:48 | [diff] [blame] | 1319 | // Save the previous state before we clobber it. |
aelias | 100c919 | 2017-01-13 00:01:43 | [diff] [blame] | 1320 | bool overriding_user_agent_changed = false; |
[email protected] | 0e8db94 | 2008-09-24 21:21:48 | [diff] [blame] | 1321 | if (GetLastCommittedEntry()) { |
Carlos IL | 42b41659 | 2019-10-07 23:10:36 | [diff] [blame] | 1322 | if (entry_replaced_by_post_commit_error_) { |
Chris Bookholt | 27faf8d | 2022-01-20 01:03:33 | [diff] [blame] | 1323 | // Same document navigation events with a post-commit error should already |
| 1324 | // be blocked by RenderFrameHostImpl::ValidateDidCommitParams() before |
| 1325 | // reaching here. |
| 1326 | CHECK(!is_same_document_navigation); |
| 1327 | |
Carlos IL | 42b41659 | 2019-10-07 23:10:36 | [diff] [blame] | 1328 | // Any commit while a post-commit error page is showing should put the |
| 1329 | // original entry back, replacing the error page's entry. This includes |
| 1330 | // reloads, where the original entry was used as the pending entry and |
| 1331 | // should now be at the correct index at commit time. |
| 1332 | entries_[last_committed_entry_index_] = |
| 1333 | std::move(entry_replaced_by_post_commit_error_); |
| 1334 | } |
Fergal Daly | 8e33cf6 | 2020-12-12 01:06:07 | [diff] [blame] | 1335 | details->previous_main_frame_url = GetLastCommittedEntry()->GetURL(); |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 1336 | details->previous_entry_index = GetLastCommittedEntryIndex(); |
Charlie Reis | f8cde71 | 2022-10-20 16:25:09 | [diff] [blame] | 1337 | if (PendingEntryMatchesRequest(navigation_request) && |
aelias | 100c919 | 2017-01-13 00:01:43 | [diff] [blame] | 1338 | pending_entry_->GetIsOverridingUserAgent() != |
Charlie Reis | f8cde71 | 2022-10-20 16:25:09 | [diff] [blame] | 1339 | GetLastCommittedEntry()->GetIsOverridingUserAgent()) { |
aelias | 100c919 | 2017-01-13 00:01:43 | [diff] [blame] | 1340 | overriding_user_agent_changed = true; |
Charlie Reis | f8cde71 | 2022-10-20 16:25:09 | [diff] [blame] | 1341 | } |
Xiaohan Wang | 7f8052e0 | 2022-01-14 18:44:28 | [diff] [blame] | 1342 | #if BUILDFLAG(IS_ANDROID) |
Shu Yang | 5756fa42 | 2021-11-05 23:02:54 | [diff] [blame] | 1343 | // TODO(crbug.com/1266277): Clean up the logic of setting |
| 1344 | // |overriding_user_agent_changed| post-launch. |
Shu Yang | d7cb6214 | 2022-08-04 21:08:16 | [diff] [blame] | 1345 | if (base::FeatureList::IsEnabled(features::kRequestDesktopSiteExceptions) || |
| 1346 | base::FeatureList::IsEnabled(features::kRequestDesktopSiteAdditions)) { |
Shu Yang | 5756fa42 | 2021-11-05 23:02:54 | [diff] [blame] | 1347 | // Must honor user agent overrides in the |navigation_request|, such as |
| 1348 | // from things like RequestDesktopSiteWebContentsObserverAndroid. As a |
| 1349 | // result, besides comparing |pending_entry_|'s user agent against |
| 1350 | // LastCommittedEntry's, also need to compare |navigation_request|'s user |
| 1351 | // agent against LastCommittedEntry's. |
| 1352 | if (navigation_request->is_overriding_user_agent() != |
| 1353 | GetLastCommittedEntry()->GetIsOverridingUserAgent()) { |
| 1354 | overriding_user_agent_changed = true; |
| 1355 | } |
| 1356 | } |
Xiaohan Wang | 7f8052e0 | 2022-01-14 18:44:28 | [diff] [blame] | 1357 | #endif // BUILDFLAG(IS_ANDROID) |
[email protected] | 0e8db94 | 2008-09-24 21:21:48 | [diff] [blame] | 1358 | } else { |
Gang Wu | 325f03f4 | 2021-02-25 20:00:46 | [diff] [blame] | 1359 | // GetLastCommittedEntry() is null, so this is the first entry. |
Fergal Daly | 8e33cf6 | 2020-12-12 01:06:07 | [diff] [blame] | 1360 | details->previous_main_frame_url = GURL(); |
[email protected] | 0e8db94 | 2008-09-24 21:21:48 | [diff] [blame] | 1361 | details->previous_entry_index = -1; |
Charlie Reis | f8cde71 | 2022-10-20 16:25:09 | [diff] [blame] | 1362 | if (PendingEntryMatchesRequest(navigation_request) && |
| 1363 | pending_entry_->GetIsOverridingUserAgent()) { |
Gang Wu | 325f03f4 | 2021-02-25 20:00:46 | [diff] [blame] | 1364 | // Default setting is NOT override the user agent, so overriding the user |
| 1365 | // agent in first entry should be considered as user agent changed as |
| 1366 | // well. |
| 1367 | overriding_user_agent_changed = true; |
| 1368 | } |
Xiaohan Wang | 7f8052e0 | 2022-01-14 18:44:28 | [diff] [blame] | 1369 | #if BUILDFLAG(IS_ANDROID) |
Shu Yang | 5756fa42 | 2021-11-05 23:02:54 | [diff] [blame] | 1370 | // TODO(crbug.com/1266277): Clean up the logic of setting |
| 1371 | // |overriding_user_agent_changed| post-launch. |
Shu Yang | d7cb6214 | 2022-08-04 21:08:16 | [diff] [blame] | 1372 | if (base::FeatureList::IsEnabled(features::kRequestDesktopSiteExceptions) || |
| 1373 | base::FeatureList::IsEnabled(features::kRequestDesktopSiteAdditions)) { |
Shu Yang | 5756fa42 | 2021-11-05 23:02:54 | [diff] [blame] | 1374 | // Must honor user agent overrides in the |navigation_request|, such as |
| 1375 | // from things like RequestDesktopSiteWebContentsObserverAndroid. As a |
| 1376 | // result, besides checking |pending_entry_|'s user agent, also need to |
| 1377 | // check |navigation_request|'s. |
| 1378 | if (navigation_request->is_overriding_user_agent()) { |
| 1379 | overriding_user_agent_changed = true; |
| 1380 | } |
| 1381 | } |
Xiaohan Wang | 7f8052e0 | 2022-01-14 18:44:28 | [diff] [blame] | 1382 | #endif // BUILDFLAG(IS_ANDROID) |
[email protected] | 0e8db94 | 2008-09-24 21:21:48 | [diff] [blame] | 1383 | } |
[email protected] | ecd9d870 | 2008-08-28 22:10:17 | [diff] [blame] | 1384 | |
Dave Tapuska | a2ab4f25 | 2021-07-08 21:31:28 | [diff] [blame] | 1385 | bool is_main_frame_navigation = !rfh->GetParent(); |
| 1386 | |
Alexander Timin | d2f2e4f2 | 2019-04-02 20:04:53 | [diff] [blame] | 1387 | // TODO(altimin, crbug.com/933147): Remove this logic after we are done with |
| 1388 | // implementing back-forward cache. |
Dave Tapuska | a2ab4f25 | 2021-07-08 21:31:28 | [diff] [blame] | 1389 | // For primary frame tree navigations, choose an appropriate |
Rakina Zata Amni | 63b5e809 | 2022-05-20 11:25:14 | [diff] [blame] | 1390 | // BackForwardCacheMetrics to be associated with the new navigation's |
| 1391 | // NavigationEntry, by either creating a new object or reusing the previous |
| 1392 | // entry's one. |
Dave Tapuska | a2ab4f25 | 2021-07-08 21:31:28 | [diff] [blame] | 1393 | scoped_refptr<BackForwardCacheMetrics> back_forward_cache_metrics; |
| 1394 | if (navigation_request->frame_tree_node()->frame_tree()->type() == |
| 1395 | FrameTree::Type::kPrimary) { |
Rakina Zata Amni | 63b5e809 | 2022-05-20 11:25:14 | [diff] [blame] | 1396 | back_forward_cache_metrics = BackForwardCacheMetrics:: |
| 1397 | CreateOrReuseBackForwardCacheMetricsForNavigation( |
Dave Tapuska | a2ab4f25 | 2021-07-08 21:31:28 | [diff] [blame] | 1398 | GetLastCommittedEntry(), is_main_frame_navigation, |
| 1399 | params.document_sequence_number); |
| 1400 | } |
Alexander Timin | d2f2e4f2 | 2019-04-02 20:04:53 | [diff] [blame] | 1401 | // Notify the last active entry that we have navigated away. |
Dave Tapuska | a2ab4f25 | 2021-07-08 21:31:28 | [diff] [blame] | 1402 | if (is_main_frame_navigation && !is_same_document_navigation) { |
Alexander Timin | d2f2e4f2 | 2019-04-02 20:04:53 | [diff] [blame] | 1403 | if (NavigationEntryImpl* navigation_entry = GetLastCommittedEntry()) { |
| 1404 | if (auto* metrics = navigation_entry->back_forward_cache_metrics()) { |
Rakina Zata Amni | 63b5e809 | 2022-05-20 11:25:14 | [diff] [blame] | 1405 | metrics->MainFrameDidNavigateAwayFromDocument(); |
Alexander Timin | d2f2e4f2 | 2019-04-02 20:04:53 | [diff] [blame] | 1406 | } |
| 1407 | } |
| 1408 | } |
| 1409 | |
Charlie Reis | f8cde71 | 2022-10-20 16:25:09 | [diff] [blame] | 1410 | // The renderer tells us whether the navigation replaces the current entry. |
| 1411 | // (See below for a case where we might override that.) |
| 1412 | details->did_replace_entry = params.should_replace_current_entry; |
| 1413 | |
fdegans | 9caf66a | 2015-07-30 21:10:42 | [diff] [blame] | 1414 | // If there is a pending entry at this point, it should have a SiteInstance, |
Charlie Reis | c4155af | 2022-10-19 15:33:11 | [diff] [blame] | 1415 | // except for restored entries. This should be true even if the current commit |
| 1416 | // is not related to the pending entry. |
jam | 48cea908 | 2017-02-15 06:13:29 | [diff] [blame] | 1417 | bool was_restored = false; |
toyoshim | 0df1d3a | 2016-09-09 09:52:48 | [diff] [blame] | 1418 | DCHECK(pending_entry_index_ == -1 || pending_entry_->site_instance() || |
Lukasz Anforowicz | 6b75c0d | 2020-12-01 22:56:08 | [diff] [blame] | 1419 | pending_entry_->IsRestored()); |
Charlie Reis | c4155af | 2022-10-19 15:33:11 | [diff] [blame] | 1420 | |
| 1421 | // Only make changes based on the pending entry if the NavigationRequest |
| 1422 | // matches it. Otherwise, the pending entry may be for a different request |
| 1423 | // (e.g., if a slow history navigation is pending while an auto-subframe |
| 1424 | // commit occurs). |
| 1425 | if (PendingEntryMatchesRequest(navigation_request)) { |
| 1426 | // It is no longer necessary to consider the pending entry as restored. |
| 1427 | if (pending_entry_->IsRestored()) { |
| 1428 | pending_entry_->set_restore_type(RestoreType::kNotRestored); |
| 1429 | was_restored = true; |
| 1430 | } |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1431 | |
Charlie Reis | f8cde71 | 2022-10-20 16:25:09 | [diff] [blame] | 1432 | // If the SiteInstance has changed from the matching pending entry, this |
| 1433 | // must be treated as a new navigation with replacement. Set the replacement |
| 1434 | // bit here and ClassifyNavigation will identify this case and return |
| 1435 | // NEW_ENTRY. |
| 1436 | if (!rfh->GetParent() && pending_entry_->site_instance() && |
| 1437 | pending_entry_->site_instance() != rfh->GetSiteInstance()) { |
| 1438 | DCHECK_NE(-1, pending_entry_index_); |
| 1439 | // TODO(nasko,creis): Instead of setting this value here, set |
| 1440 | // should_replace_current_entry on the parameters we send to the |
| 1441 | // renderer process as part of CommitNavigation. The renderer should |
| 1442 | // in turn send it back here as part of |params| and it can be just |
| 1443 | // enforced and renderer process terminated on mismatch. |
| 1444 | details->did_replace_entry = true; |
| 1445 | } |
Nasko Oskov | aee2f86 | 2018-06-15 00:05:52 | [diff] [blame] | 1446 | } |
[email protected] | bcd90448 | 2012-02-01 01:54:22 | [diff] [blame] | 1447 | |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1448 | // Do navigation-type specific actions. These will make and commit an entry. |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 1449 | details->type = ClassifyNavigation(rfh, params, navigation_request); |
shivanigithub | 189833f | 2022-04-27 18:08:45 | [diff] [blame] | 1450 | |
| 1451 | if (ShouldMaintainTrivialSessionHistory(rfh->frame_tree_node()) && |
| 1452 | GetLastCommittedEntry()) { |
| 1453 | // Ensure that this navigation does not add a navigation entry, since |
| 1454 | // ShouldMaintainTrivialSessionHistory() means we should not add an entry |
| 1455 | // beyond the last committed one. Therefore, `should_replace_current_entry` |
| 1456 | // should be set, which replaces the current entry, or this should be a |
| 1457 | // reload, which does not create a new entry. |
| 1458 | // In shadowDOM fenced frames, on a history/tab-restore navigation, any |
| 1459 | // navigation that is restored will not be creating a new entry anyways, so |
| 1460 | // exclude that case by checking NAVIGATION_TYPE_AUTO_SUBFRAME. |
| 1461 | // TODO(crbug.com/1319919): Consider adjusting the dcheck for more cases as |
| 1462 | // pointed out in the issue. |
| 1463 | DCHECK(params.should_replace_current_entry || |
| 1464 | navigation_request->GetReloadType() != ReloadType::NONE || |
| 1465 | details->type == NAVIGATION_TYPE_AUTO_SUBFRAME); |
| 1466 | } |
| 1467 | |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 1468 | if (GetLastCommittedEntry() && GetLastCommittedEntry()->IsInitialEntry()) { |
Rakina Zata Amni | ddf1050 | 2022-01-15 02:56:55 | [diff] [blame] | 1469 | if (rfh->GetParent()) { |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 1470 | // This is a subframe navigation on the initial empty document, which used |
| 1471 | // to not have a NavigationEntry to attach to. Now it can attach to the |
| 1472 | // initial NavigationEntry, and we must ensure that its NavigationEntry |
| 1473 | // will keep the "initial NavigationEntry" status and won't append a new |
| 1474 | // NavigationEntry (it should always do replacement instead). |
| 1475 | // See also https://crbug.com/1277414. |
| 1476 | details->should_stay_as_initial_entry = true; |
Rakina Zata Amni | ddf1050 | 2022-01-15 02:56:55 | [diff] [blame] | 1477 | // Subframe navigation on initial NavigationEntry must not append a new |
| 1478 | // NavigationEntry (i.e. should not be classified as NEW_SUBFRAME). This |
| 1479 | // means every subframe navigation that happens while we're on the initial |
| 1480 | // NavigationEntry will always reuse the existing NavigationEntry and |
| 1481 | // just update the corresponding FrameNavigationEntry. |
| 1482 | DCHECK_EQ(details->type, NAVIGATION_TYPE_AUTO_SUBFRAME); |
| 1483 | } else if (details->type == NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY) { |
| 1484 | // This is a navigation that modifies the initial NavigationEntry, either |
| 1485 | // for a replacement or a reload. The initial NavigationEntry should |
| 1486 | // retain its "initial NavigationEntry" status in this case. |
| 1487 | details->should_stay_as_initial_entry = true; |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 1488 | } else if (navigation_request->is_synchronous_renderer_commit() && |
| 1489 | !navigation_request->IsSameDocument() && !rfh->GetParent() && |
| 1490 | params.should_replace_current_entry) { |
| 1491 | // This is a synchronous about:blank navigation on the main frame, which |
| 1492 | // used to not create a NavigationEntry when we have no NavigationEntry on |
| 1493 | // FrameTree creation. We now have the initial NavigationEntry and are on |
| 1494 | // the initial NavigationEntry. To preserve old behavior, we should still |
| 1495 | // keep the "initial" status for the new NavigationEntry that we will |
| 1496 | // create for this navigation, so that subframe navigations under the |
| 1497 | // synchronously committed about:blank document will never append new |
| 1498 | // NavigationEntry, and instead will just reuse the initial |
| 1499 | // NavigationEntry and modify the corresponding FrameNavigationEntries. |
| 1500 | // See also https://crbug.com/1277414. |
| 1501 | details->should_stay_as_initial_entry = true; |
Rakina Zata Amni | ddf1050 | 2022-01-15 02:56:55 | [diff] [blame] | 1502 | } |
| 1503 | } |
| 1504 | DCHECK(!details->should_stay_as_initial_entry || |
| 1505 | GetLastCommittedEntry()->IsInitialEntry()); |
[email protected] | 4bf3522c | 2010-08-19 21:00:20 | [diff] [blame] | 1506 | |
eugenebut | ee08663a | 2017-04-27 17:43:12 | [diff] [blame] | 1507 | // is_same_document must be computed before the entry gets committed. |
Eugene But | 712f03d | 2018-05-22 16:03:44 | [diff] [blame] | 1508 | details->is_same_document = is_same_document_navigation; |
[email protected] | b9d4dfdc | 2013-08-08 00:25:12 | [diff] [blame] | 1509 | |
Lucas Furukawa Gadani | e3f7e79 | 2021-04-22 17:56:07 | [diff] [blame] | 1510 | details->is_prerender_activation = |
| 1511 | navigation_request->IsPrerenderedPageActivation(); |
Robert Lin | 540dbd1 | 2022-04-28 22:07:24 | [diff] [blame] | 1512 | details->is_in_active_page = navigation_request->GetRenderFrameHost() |
| 1513 | ->GetOutermostMainFrame() |
| 1514 | ->IsInPrimaryMainFrame(); |
Lucas Furukawa Gadani | e3f7e79 | 2021-04-22 17:56:07 | [diff] [blame] | 1515 | |
Peter Boström | d759213 | 2019-01-30 04:50:31 | [diff] [blame] | 1516 | // Make sure we do not discard the pending entry for a different ongoing |
| 1517 | // navigation when a same document commit comes in unexpectedly from the |
| 1518 | // renderer. Limit this to a very narrow set of conditions to avoid risks to |
| 1519 | // other navigation types. See https://crbug.com/900036. |
| 1520 | // TODO(crbug.com/926009): Handle history.pushState() as well. |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1521 | bool keep_pending_entry = |
| 1522 | is_same_document_navigation && |
| 1523 | details->type == NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY && |
| 1524 | pending_entry_ && !PendingEntryMatchesRequest(navigation_request); |
Peter Boström | d759213 | 2019-01-30 04:50:31 | [diff] [blame] | 1525 | |
[email protected] | 0e8db94 | 2008-09-24 21:21:48 | [diff] [blame] | 1526 | switch (details->type) { |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1527 | case NAVIGATION_TYPE_MAIN_FRAME_NEW_ENTRY: |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1528 | RendererDidNavigateToNewEntry( |
shivanisha | 41f04c5 | 2018-12-12 15:52:05 | [diff] [blame] | 1529 | rfh, params, details->is_same_document, details->did_replace_entry, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 1530 | previous_document_was_activated, navigation_request, details); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1531 | break; |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1532 | case NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY: |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1533 | RendererDidNavigateToExistingEntry(rfh, params, details->is_same_document, |
| 1534 | was_restored, navigation_request, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 1535 | keep_pending_entry, details); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1536 | break; |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1537 | case NAVIGATION_TYPE_NEW_SUBFRAME: |
Shivani Sharma | ffb32b8 | 2019-04-09 16:58:47 | [diff] [blame] | 1538 | RendererDidNavigateNewSubframe( |
| 1539 | rfh, params, details->is_same_document, details->did_replace_entry, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 1540 | previous_document_was_activated, navigation_request, details); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1541 | break; |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1542 | case NAVIGATION_TYPE_AUTO_SUBFRAME: |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 1543 | if (!RendererDidNavigateAutoSubframe( |
Nate Chapin | c7019dd7d | 2021-06-25 18:29:25 | [diff] [blame] | 1544 | rfh, params, details->is_same_document, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 1545 | was_on_initial_empty_document, navigation_request, details)) { |
creis | ce0ef357 | 2017-01-26 17:53:08 | [diff] [blame] | 1546 | // We don't send a notification about auto-subframe PageState during |
| 1547 | // UpdateStateForFrame, since it looks like nothing has changed. Send |
| 1548 | // it here at commit time instead. |
| 1549 | NotifyEntryChanged(GetLastCommittedEntry()); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1550 | return false; |
creis | 59d5a47cb | 2016-08-24 23:57:19 | [diff] [blame] | 1551 | } |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1552 | break; |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 1553 | case NAVIGATION_TYPE_NAV_IGNORE: |
| 1554 | // If a pending navigation was in progress, this canceled it. We should |
| 1555 | // discard it and make sure it is removed from the URL bar. After that, |
| 1556 | // there is nothing we can do with this navigation, so we just return to |
| 1557 | // the caller that nothing has happened. |
| 1558 | if (pending_entry_) |
| 1559 | DiscardNonCommittedEntries(); |
| 1560 | return false; |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 1561 | case NAVIGATION_TYPE_UNKNOWN: |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1562 | NOTREACHED(); |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 1563 | break; |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 1564 | } |
| 1565 | |
[email protected] | 688aa65c6 | 2012-09-28 04:32:22 | [diff] [blame] | 1566 | // At this point, we know that the navigation has just completed, so |
| 1567 | // record the time. |
| 1568 | // |
| 1569 | // TODO(akalin): Use "sane time" as described in |
Adam Langley | 4463fb83 | 2018-01-28 22:42:26 | [diff] [blame] | 1570 | // https://www.chromium.org/developers/design-documents/sane-time . |
[email protected] | c5b88d8 | 2012-10-06 17:03:33 | [diff] [blame] | 1571 | base::Time timestamp = |
| 1572 | time_smoother_.GetSmoothedTime(get_timestamp_callback_.Run()); |
| 1573 | DVLOG(1) << "Navigation finished at (smoothed) timestamp " |
danakj | f26536bf | 2020-09-10 00:46:13 | [diff] [blame] | 1574 | << timestamp.ToDeltaSinceWindowsEpoch().InMicroseconds(); |
[email protected] | 688aa65c6 | 2012-09-28 04:32:22 | [diff] [blame] | 1575 | |
Peter Boström | d759213 | 2019-01-30 04:50:31 | [diff] [blame] | 1576 | // If we aren't keeping the pending entry, there shouldn't be one at this |
| 1577 | // point. Clear it again in case any error cases above forgot to do so. |
| 1578 | // TODO(pbos): Consider a CHECK here that verifies that the pending entry has |
| 1579 | // been cleared instead of protecting against it. |
| 1580 | if (!keep_pending_entry) |
Rakina Zata Amni | ddf1050 | 2022-01-15 02:56:55 | [diff] [blame] | 1581 | DiscardNonCommittedEntriesWithCommitDetails(details); |
[email protected] | f233e423 | 2013-02-23 00:55:14 | [diff] [blame] | 1582 | |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1583 | // All committed entries should have nonempty content state so WebKit doesn't |
| 1584 | // get confused when we go back to them (see the function for details). |
creis | 0cade2e | 2017-02-28 06:37:47 | [diff] [blame] | 1585 | DCHECK(params.page_state.IsValid()) << "Shouldn't see an empty PageState."; |
creis | 3da0387 | 2015-02-20 21:12:32 | [diff] [blame] | 1586 | NavigationEntryImpl* active_entry = GetLastCommittedEntry(); |
[email protected] | 688aa65c6 | 2012-09-28 04:32:22 | [diff] [blame] | 1587 | active_entry->SetTimestamp(timestamp); |
[email protected] | f49737b3 | 2013-08-28 07:51:44 | [diff] [blame] | 1588 | active_entry->SetHttpStatusCode(params.http_status_code); |
Fergal Daly | 0686c0e | 2022-06-28 02:08:14 | [diff] [blame] | 1589 | |
Alexander Timin | d2f2e4f2 | 2019-04-02 20:04:53 | [diff] [blame] | 1590 | // TODO(altimin, crbug.com/933147): Remove this logic after we are done with |
| 1591 | // implementing back-forward cache. |
Dave Tapuska | a2ab4f25 | 2021-07-08 21:31:28 | [diff] [blame] | 1592 | if (back_forward_cache_metrics && |
| 1593 | !active_entry->back_forward_cache_metrics()) { |
Alexander Timin | d2f2e4f2 | 2019-04-02 20:04:53 | [diff] [blame] | 1594 | active_entry->set_back_forward_cache_metrics( |
| 1595 | std::move(back_forward_cache_metrics)); |
| 1596 | } |
Dave Tapuska | a2ab4f25 | 2021-07-08 21:31:28 | [diff] [blame] | 1597 | |
| 1598 | // `back_forward_cache_metrics()` may return null as we do not record |
| 1599 | // back-forward cache metrics for navigations in non-primary frame trees. |
| 1600 | if (active_entry->back_forward_cache_metrics()) { |
Fergal Daly | 0686c0e | 2022-06-28 02:08:14 | [diff] [blame] | 1601 | // TODO(https://crbug.com/1338089): Remove this. |
| 1602 | // These are both only available from details at this point, so we capture |
| 1603 | // them here. |
| 1604 | SCOPED_CRASH_KEY_NUMBER("BFCacheMismatch", "navigation_type", |
| 1605 | details->type); |
| 1606 | SCOPED_CRASH_KEY_BOOL("BFCacheMismatch", "did_replace", |
| 1607 | details->did_replace_entry); |
Dave Tapuska | a2ab4f25 | 2021-07-08 21:31:28 | [diff] [blame] | 1608 | active_entry->back_forward_cache_metrics()->DidCommitNavigation( |
| 1609 | navigation_request, |
| 1610 | back_forward_cache_.IsAllowed(navigation_request->GetURL())); |
| 1611 | } |
nasko | c753351 | 2016-05-06 17:01:12 | [diff] [blame] | 1612 | |
Charles Reis | c050720 | 2017-09-21 00:40:02 | [diff] [blame] | 1613 | // Grab the corresponding FrameNavigationEntry for a few updates, but only if |
| 1614 | // the SiteInstance matches (to avoid updating the wrong entry by mistake). |
| 1615 | // A mismatch can occur if the renderer lies or due to a unique name collision |
| 1616 | // after a race with an OOPIF (see https://crbug.com/616820). |
nasko | c753351 | 2016-05-06 17:01:12 | [diff] [blame] | 1617 | FrameNavigationEntry* frame_entry = |
| 1618 | active_entry->GetFrameEntry(rfh->frame_tree_node()); |
Charles Reis | c050720 | 2017-09-21 00:40:02 | [diff] [blame] | 1619 | if (frame_entry && frame_entry->site_instance() != rfh->GetSiteInstance()) |
| 1620 | frame_entry = nullptr; |
Charles Reis | f4448202 | 2017-10-13 21:15:03 | [diff] [blame] | 1621 | // Make sure we've updated the PageState in one of the helper methods. |
creis | ce0ef357 | 2017-01-26 17:53:08 | [diff] [blame] | 1622 | // TODO(creis): Remove the "if" once https://crbug.com/522193 is fixed. |
| 1623 | if (frame_entry) { |
Charles Reis | f4448202 | 2017-10-13 21:15:03 | [diff] [blame] | 1624 | DCHECK(params.page_state == frame_entry->page_state()); |
Nasko Oskov | bbcfc000 | 2019-11-20 20:03:20 | [diff] [blame] | 1625 | |
| 1626 | // Remember the bindings the renderer process has at this point, so that |
| 1627 | // we do not grant this entry additional bindings if we come back to it. |
| 1628 | frame_entry->SetBindings(rfh->GetEnabledBindings()); |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 1629 | } |
[email protected] | 132e281a | 2012-07-31 18:32:44 | [diff] [blame] | 1630 | |
[email protected] | 97d8f0d | 2013-10-29 16:49:21 | [diff] [blame] | 1631 | // Once it is committed, we no longer need to track several pieces of state on |
| 1632 | // the entry. |
nasko | c753351 | 2016-05-06 17:01:12 | [diff] [blame] | 1633 | active_entry->ResetForCommit(frame_entry); |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 1634 | |
[email protected] | 49bd30e6 | 2011-03-22 20:12:59 | [diff] [blame] | 1635 | // The active entry's SiteInstance should match our SiteInstance. |
[email protected] | a1b9926 | 2013-12-27 21:56:22 | [diff] [blame] | 1636 | // TODO(creis): This check won't pass for subframes until we create entries |
| 1637 | // for subframe navigations. |
avi | 39c1edd3 | 2015-06-04 20:06:00 | [diff] [blame] | 1638 | if (!rfh->GetParent()) |
creis | 77c9aa3 | 2015-09-25 19:59:42 | [diff] [blame] | 1639 | CHECK_EQ(active_entry->site_instance(), rfh->GetSiteInstance()); |
[email protected] | 49bd30e6 | 2011-03-22 20:12:59 | [diff] [blame] | 1640 | |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1641 | // Now prep the rest of the details for the notification and broadcast. |
[email protected] | 0f38dc455 | 2011-02-25 11:24:00 | [diff] [blame] | 1642 | details->entry = active_entry; |
avi | 39c1edd3 | 2015-06-04 20:06:00 | [diff] [blame] | 1643 | details->is_main_frame = !rfh->GetParent(); |
[email protected] | 2e39d2e | 2009-02-19 18:41:31 | [diff] [blame] | 1644 | details->http_status_code = params.http_status_code; |
estark | a5635c4 | 2015-07-14 00:06:53 | [diff] [blame] | 1645 | |
arthursonzogni | 7ddc654 | 2021-04-09 09:16:50 | [diff] [blame] | 1646 | active_entry->SetIsOverridingUserAgent( |
| 1647 | navigation_request->is_overriding_user_agent()); |
Scott Violet | c36f746 | 2020-05-06 23:13:03 | [diff] [blame] | 1648 | |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 1649 | NotifyNavigationEntryCommitted(details); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1650 | |
aelias | 100c919 | 2017-01-13 00:01:43 | [diff] [blame] | 1651 | if (overriding_user_agent_changed) |
| 1652 | delegate_->UpdateOverridingUserAgent(); |
| 1653 | |
creis | 03b4800 | 2015-11-04 00:54:56 | [diff] [blame] | 1654 | // Update the nav_entry_id for each RenderFrameHost in the tree, so that each |
| 1655 | // one knows the latest NavigationEntry it is showing (whether it has |
| 1656 | // committed anything in this navigation or not). This allows things like |
| 1657 | // state and title updates from RenderFrames to apply to the latest relevant |
| 1658 | // NavigationEntry. |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 1659 | int nav_entry_id = active_entry->GetUniqueID(); |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 1660 | for (FrameTreeNode* node : frame_tree_->Nodes()) |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 1661 | node->current_frame_host()->set_nav_entry_id(nav_entry_id); |
Hayato Ito | 2c8c08d0 | 2021-06-23 03:38:43 | [diff] [blame] | 1662 | |
| 1663 | if (navigation_request->IsPrerenderedPageActivation()) { |
| 1664 | BroadcastHistoryOffsetAndLength(); |
| 1665 | // TODO(crbug.com/1222893): Broadcasting happens after the prerendered page |
| 1666 | // is activated. As a result, a "prerenderingchange" event listener sees the |
| 1667 | // history.length which is not updated yet. We should guarantee that |
| 1668 | // history's length and offset should be updated before a |
| 1669 | // "prerenderingchange" event listener runs. One possible approach is to use |
| 1670 | // the same IPC which "prerenderingchange" uses, and propagate history's |
| 1671 | // length and offset together with that. |
| 1672 | } |
| 1673 | |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1674 | return true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1675 | } |
| 1676 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1677 | NavigationType NavigationControllerImpl::ClassifyNavigation( |
creis | 3da0387 | 2015-02-20 21:12:32 | [diff] [blame] | 1678 | RenderFrameHostImpl* rfh, |
Rakina Zata Amni | f6950d55 | 2020-11-24 03:26:10 | [diff] [blame] | 1679 | const mojom::DidCommitProvisionalLoadParams& params, |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 1680 | NavigationRequest* navigation_request) { |
Piotr Tworek | bad5128 | 2020-09-30 19:17:59 | [diff] [blame] | 1681 | TraceReturnReason<tracing_category::kNavigation> trace_return( |
Nasko Oskov | ae49e29 | 2020-08-13 02:08:51 | [diff] [blame] | 1682 | "ClassifyNavigation"); |
| 1683 | |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1684 | if (params.did_create_new_entry) { |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 1685 | // A new entry. We may or may not have a corresponding pending entry, and |
| 1686 | // this may or may not be the main frame. |
avi | 39c1edd3 | 2015-06-04 20:06:00 | [diff] [blame] | 1687 | if (!rfh->GetParent()) { |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1688 | trace_return.set_return_reason("new entry, no parent, new entry"); |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1689 | return NAVIGATION_TYPE_MAIN_FRAME_NEW_ENTRY; |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1690 | } |
| 1691 | |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 1692 | // When this is a new subframe navigation, we should have a committed page |
| 1693 | // in which it's a subframe. This may not be the case when an iframe is |
| 1694 | // navigated on a popup navigated to about:blank (the iframe would be |
| 1695 | // written into the popup by script on the main page). For these cases, |
| 1696 | // there isn't any navigation stuff we can do, so just ignore it. |
| 1697 | if (!GetLastCommittedEntry()) { |
| 1698 | trace_return.set_return_reason("new entry, no last committed, ignore"); |
| 1699 | return NAVIGATION_TYPE_NAV_IGNORE; |
| 1700 | } |
| 1701 | |
| 1702 | // Valid subframe navigation. |
Nasko Oskov | ae49e29 | 2020-08-13 02:08:51 | [diff] [blame] | 1703 | trace_return.set_return_reason("new entry, new subframe"); |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1704 | return NAVIGATION_TYPE_NEW_SUBFRAME; |
| 1705 | } |
| 1706 | |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1707 | // We only clear the session history in tests when navigating to a new entry. |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1708 | DCHECK(!params.history_list_was_cleared); |
| 1709 | |
avi | 39c1edd3 | 2015-06-04 20:06:00 | [diff] [blame] | 1710 | if (rfh->GetParent()) { |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1711 | // All manual subframes would be did_create_new_entry and handled above, so |
| 1712 | // we know this is auto. |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 1713 | if (GetLastCommittedEntry()) { |
| 1714 | trace_return.set_return_reason("subframe, last commmited, auto subframe"); |
| 1715 | return NAVIGATION_TYPE_AUTO_SUBFRAME; |
| 1716 | } |
| 1717 | |
| 1718 | // We ignore subframes created in non-committed pages; we'd appreciate if |
| 1719 | // people stopped doing that. |
| 1720 | trace_return.set_return_reason("subframe, no last commmited, ignore"); |
| 1721 | return NAVIGATION_TYPE_NAV_IGNORE; |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1722 | } |
| 1723 | |
Rakina Zata Amni | f6950d55 | 2020-11-24 03:26:10 | [diff] [blame] | 1724 | const int nav_entry_id = navigation_request->commit_params().nav_entry_id; |
| 1725 | if (nav_entry_id == 0) { |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1726 | // This is a renderer-initiated navigation (nav_entry_id == 0), but didn't |
| 1727 | // create a new page. |
| 1728 | |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 1729 | // Just like above in the did_create_new_entry case, it's possible to |
| 1730 | // scribble onto an uncommitted page. Again, there isn't any navigation |
| 1731 | // stuff that we can do, so ignore it here as well. |
| 1732 | NavigationEntry* last_committed = GetLastCommittedEntry(); |
| 1733 | if (!last_committed) { |
| 1734 | trace_return.set_return_reason("nav entry 0, no last committed, ignore"); |
| 1735 | return NAVIGATION_TYPE_NAV_IGNORE; |
| 1736 | } |
| 1737 | |
Hayato Ito | 2ae4944 | 2021-07-02 02:59:25 | [diff] [blame] | 1738 | // This main frame navigation is not a history navigation (since |
| 1739 | // nav_entry_id is 0), but didn't create a new entry. So this must be a |
| 1740 | // reload or a replacement navigation, which will modify the existing entry. |
| 1741 | // |
Nasko Oskov | 332593c | 2018-08-16 17:21:34 | [diff] [blame] | 1742 | // TODO(nasko): With error page isolation, reloading an existing session |
| 1743 | // history entry can result in change of SiteInstance. Check for such a case |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1744 | // here and classify it as NEW_ENTRY, as such navigations should be treated |
Nasko Oskov | 332593c | 2018-08-16 17:21:34 | [diff] [blame] | 1745 | // as new with replacement. |
Nasko Oskov | ae49e29 | 2020-08-13 02:08:51 | [diff] [blame] | 1746 | trace_return.set_return_reason( |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1747 | "nav entry 0, last committed, existing entry"); |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1748 | return NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY; |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1749 | } |
| 1750 | |
Charlie Reis | f8cde71 | 2022-10-20 16:25:09 | [diff] [blame] | 1751 | if (PendingEntryMatchesRequest(navigation_request)) { |
Nasko Oskov | aee2f86 | 2018-06-15 00:05:52 | [diff] [blame] | 1752 | // If the SiteInstance of the |pending_entry_| does not match the |
| 1753 | // SiteInstance that got committed, treat this as a new navigation with |
| 1754 | // replacement. This can happen if back/forward/reload encounters a server |
| 1755 | // redirect to a different site or an isolated error page gets successfully |
| 1756 | // reloaded into a different SiteInstance. |
| 1757 | if (pending_entry_->site_instance() && |
| 1758 | pending_entry_->site_instance() != rfh->GetSiteInstance()) { |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1759 | trace_return.set_return_reason("pending matching nav entry, new entry"); |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1760 | return NAVIGATION_TYPE_MAIN_FRAME_NEW_ENTRY; |
Nasko Oskov | aee2f86 | 2018-06-15 00:05:52 | [diff] [blame] | 1761 | } |
creis | 77c9aa3 | 2015-09-25 19:59:42 | [diff] [blame] | 1762 | |
Nasko Oskov | aee2f86 | 2018-06-15 00:05:52 | [diff] [blame] | 1763 | if (pending_entry_index_ == -1) { |
| 1764 | // In this case, we have a pending entry for a load of a new URL but Blink |
| 1765 | // didn't do a new navigation (params.did_create_new_entry). First check |
| 1766 | // to make sure Blink didn't treat a new cross-process navigation as |
| 1767 | // inert, and thus set params.did_create_new_entry to false. In that case, |
Charlie Reis | 7e2cb6d | 2021-01-26 01:27:16 | [diff] [blame] | 1768 | // we must treat it as NEW rather than the converted reload case below, |
| 1769 | // since the new SiteInstance doesn't match the last committed entry. |
Nasko Oskov | aee2f86 | 2018-06-15 00:05:52 | [diff] [blame] | 1770 | if (!GetLastCommittedEntry() || |
| 1771 | GetLastCommittedEntry()->site_instance() != rfh->GetSiteInstance()) { |
Charlie Reis | 7e2cb6d | 2021-01-26 01:27:16 | [diff] [blame] | 1772 | trace_return.set_return_reason("new pending, new entry"); |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1773 | return NAVIGATION_TYPE_MAIN_FRAME_NEW_ENTRY; |
Nasko Oskov | aee2f86 | 2018-06-15 00:05:52 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | // Otherwise, this happens when you press enter in the URL bar to reload. |
Charlie Reis | 7e2cb6d | 2021-01-26 01:27:16 | [diff] [blame] | 1777 | // We will create a pending entry, but NavigateWithoutEntry will convert |
| 1778 | // it to a reload since it's the same page and not create a new entry for |
| 1779 | // it. (The user doesn't want to have a new back/forward entry when they |
| 1780 | // do this.) Therefore we want to just ignore the pending entry and go |
| 1781 | // back to where we were (the "existing entry"). |
| 1782 | trace_return.set_return_reason("new pending, existing (same) entry"); |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1783 | return NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY; |
Nasko Oskov | aee2f86 | 2018-06-15 00:05:52 | [diff] [blame] | 1784 | } |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1785 | } |
| 1786 | |
creis | 26d2263 | 2017-04-21 20:23:56 | [diff] [blame] | 1787 | // Everything below here is assumed to be an existing entry, but if there is |
| 1788 | // no last committed entry, we must consider it a new navigation instead. |
Nasko Oskov | ae49e29 | 2020-08-13 02:08:51 | [diff] [blame] | 1789 | if (!GetLastCommittedEntry()) { |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1790 | trace_return.set_return_reason("no last committed, new entry"); |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1791 | return NAVIGATION_TYPE_MAIN_FRAME_NEW_ENTRY; |
Nasko Oskov | ae49e29 | 2020-08-13 02:08:51 | [diff] [blame] | 1792 | } |
creis | 26d2263 | 2017-04-21 20:23:56 | [diff] [blame] | 1793 | |
Rakina Zata Amni | 153d570 | 2021-09-13 22:48:00 | [diff] [blame] | 1794 | if (navigation_request->commit_params().intended_as_new_entry) { |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1795 | // This was intended to be a navigation to a new entry but the pending entry |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1796 | // got cleared in the meanwhile. Classify as EXISTING_ENTRY because we may |
| 1797 | // or may not have a pending entry. |
Charlie Reis | 7e2cb6d | 2021-01-26 01:27:16 | [diff] [blame] | 1798 | trace_return.set_return_reason("intended as new entry, existing entry"); |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1799 | return NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY; |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1800 | } |
| 1801 | |
Rakina Zata Amni | 3a1c0ec | 2021-04-15 03:35:12 | [diff] [blame] | 1802 | if (navigation_request->DidEncounterError() && |
| 1803 | failed_pending_entry_id_ != 0 && |
Rakina Zata Amni | f6950d55 | 2020-11-24 03:26:10 | [diff] [blame] | 1804 | nav_entry_id == failed_pending_entry_id_) { |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1805 | // If the renderer was going to a new pending entry that got cleared because |
| 1806 | // of an error, this is the case of the user trying to retry a failed load |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1807 | // by pressing return. Classify as EXISTING_ENTRY because we probably don't |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1808 | // have a pending entry. |
Nasko Oskov | ae49e29 | 2020-08-13 02:08:51 | [diff] [blame] | 1809 | trace_return.set_return_reason( |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1810 | "unreachable, matching pending, existing entry"); |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1811 | return NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY; |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1812 | } |
| 1813 | |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1814 | // Now we know that the notification is for an existing entry; find it. |
Rakina Zata Amni | f6950d55 | 2020-11-24 03:26:10 | [diff] [blame] | 1815 | int existing_entry_index = GetEntryIndexWithUniqueID(nav_entry_id); |
Nasko Oskov | ae49e29 | 2020-08-13 02:08:51 | [diff] [blame] | 1816 | trace_return.traced_value()->SetInteger("existing_entry_index", |
| 1817 | existing_entry_index); |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1818 | if (existing_entry_index == -1) { |
avi | 5cad491 | 2015-06-19 05:25:44 | [diff] [blame] | 1819 | // The renderer has committed a navigation to an entry that no longer |
| 1820 | // exists. Because the renderer is showing that page, resurrect that entry. |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1821 | trace_return.set_return_reason("existing entry -1, new entry"); |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1822 | return NAVIGATION_TYPE_MAIN_FRAME_NEW_ENTRY; |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1823 | } |
| 1824 | |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1825 | // Since we weeded out "new" navigations above, we know this is an existing |
| 1826 | // (back/forward) navigation. |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1827 | trace_return.set_return_reason("default return, existing entry"); |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1828 | return NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY; |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1829 | } |
| 1830 | |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 1831 | void NavigationControllerImpl::UpdateNavigationEntryDetails( |
| 1832 | NavigationEntryImpl* entry, |
| 1833 | RenderFrameHostImpl* rfh, |
| 1834 | const mojom::DidCommitProvisionalLoadParams& params, |
| 1835 | NavigationRequest* request, |
| 1836 | NavigationEntryImpl::UpdatePolicy update_policy, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 1837 | bool is_new_entry, |
| 1838 | LoadCommittedDetails* commit_details) { |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 1839 | // Update the FrameNavigationEntry. |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 1840 | std::vector<GURL> redirects; |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 1841 | entry->AddOrUpdateFrameEntry( |
| 1842 | rfh->frame_tree_node(), update_policy, params.item_sequence_number, |
Domenic Denicola | cc094fb | 2022-03-16 23:40:57 | [diff] [blame] | 1843 | params.document_sequence_number, params.navigation_api_key, |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 1844 | rfh->GetSiteInstance(), nullptr, params.url, |
| 1845 | GetCommittedOriginForFrameEntry(params, request), |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 1846 | Referrer(*params.referrer), |
| 1847 | request ? request->common_params().initiator_origin : params.origin, |
| 1848 | request ? request->GetRedirectChain() : redirects, params.page_state, |
| 1849 | params.method, params.post_id, nullptr /* blob_url_loader_factory */, |
| 1850 | (request && request->web_bundle_navigation_info()) |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 1851 | ? request->web_bundle_navigation_info()->Clone() |
| 1852 | : nullptr, |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 1853 | (request ? request->GetSubresourceWebBundleNavigationInfo() : nullptr), |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 1854 | ComputePolicyContainerPoliciesForFrameEntry( |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 1855 | rfh, request && request->IsSameDocument(), |
| 1856 | request ? request->common_params().url : params.url)); |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 1857 | |
| 1858 | if (rfh->GetParent()) { |
| 1859 | // Only modify the NavigationEntry for main frame navigations. |
| 1860 | return; |
| 1861 | } |
| 1862 | if (entry->update_virtual_url_with_url()) |
| 1863 | UpdateVirtualURLToURL(entry, params.url); |
| 1864 | // Don't use the page type from the pending entry. Some interstitial page |
| 1865 | // may have set the type to interstitial. Once we commit, however, the page |
| 1866 | // type must always be normal or error. |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 1867 | entry->set_page_type((request && request->DidEncounterError()) |
| 1868 | ? PAGE_TYPE_ERROR |
| 1869 | : PAGE_TYPE_NORMAL); |
Rakina Zata Amni | f297a80 | 2022-01-18 03:53:43 | [diff] [blame] | 1870 | if (commit_details && commit_details->should_stay_as_initial_entry) { |
| 1871 | // Retain the "initial NavigationEntry" status. |
| 1872 | if (request->IsSameDocument()) { |
| 1873 | // If this is for a same-document navigation, the NavigationEntry must be |
| 1874 | // reused and should already be marked as the initial NavigationEntry. |
| 1875 | DCHECK(entry->IsInitialEntry()); |
| 1876 | } else { |
| 1877 | // If this is for a cross-document navigation, it can be caused by a |
| 1878 | // renderer-initiated reload, or the synchronous about:blank commit. Mark |
| 1879 | // "for synchronous about:blank" in the latter case, and also when it is |
| 1880 | // reloading a "for synchronous about:blank" entry. Otherwise, the entry |
| 1881 | // is not for a synchronous about:blank commit. |
| 1882 | NavigationEntryImpl::InitialNavigationEntryState new_state = |
| 1883 | NavigationEntryImpl::InitialNavigationEntryState:: |
| 1884 | kInitialNotForSynchronousAboutBlank; |
| 1885 | if (entry->IsInitialEntryForSynchronousAboutBlank() || |
| 1886 | request->is_synchronous_renderer_commit()) { |
| 1887 | new_state = NavigationEntryImpl::InitialNavigationEntryState:: |
| 1888 | kInitialForSynchronousAboutBlank; |
| 1889 | } |
| 1890 | entry->set_initial_navigation_entry_state(new_state); |
| 1891 | } |
| 1892 | } else if (commit_details && !commit_details->should_stay_as_initial_entry) { |
| 1893 | // Remove the "initial NavigationEntry" status. |
| 1894 | entry->set_initial_navigation_entry_state( |
| 1895 | NavigationEntryImpl::InitialNavigationEntryState::kNonInitial); |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 1896 | } |
Rakina Zata Amni | ddf1050 | 2022-01-15 02:56:55 | [diff] [blame] | 1897 | |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 1898 | if (is_new_entry) { |
| 1899 | // Some properties of the NavigationEntry are only set when the entry is |
| 1900 | // new (we aren't reusing it). |
| 1901 | entry->SetTransitionType(params.transition); |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 1902 | entry->SetOriginalRequestURL(request ? request->GetOriginalRequestURL() |
| 1903 | : GURL::EmptyGURL()); |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 1904 | DCHECK_EQ(rfh->is_overriding_user_agent(), params.is_overriding_user_agent); |
| 1905 | entry->SetIsOverridingUserAgent(params.is_overriding_user_agent); |
| 1906 | } else { |
| 1907 | // We are reusing the NavigationEntry. The site instance will normally be |
| 1908 | // the same except for a few cases: |
| 1909 | // 1) session restore, when no site instance will be assigned or |
| 1910 | // 2) redirect, when the site instance is reset. |
| 1911 | DCHECK(!entry->site_instance() || !entry->GetRedirectChain().empty() || |
| 1912 | entry->site_instance() == rfh->GetSiteInstance()); |
| 1913 | } |
| 1914 | } |
| 1915 | |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 1916 | void NavigationControllerImpl::CreateInitialEntry() { |
| 1917 | DCHECK_EQ(entries_.size(), 0u); |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 1918 | RenderFrameHostImpl* rfh = frame_tree_->root()->current_frame_host(); |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 1919 | auto params = mojom::DidCommitProvisionalLoadParams::New(); |
| 1920 | // The initial NavigationEntry's URL is the empty URL. This preserves the old |
| 1921 | // behavior of WebContent's GetLastCommittedURL() and GetVisibleURL() from |
| 1922 | // before we have initial NavigationEntries. |
| 1923 | params->url = GURL::EmptyGURL(); |
| 1924 | params->http_status_code = 0; |
| 1925 | params->url_is_unreachable = false; |
| 1926 | params->method = "GET"; |
| 1927 | params->should_replace_current_entry = false; |
| 1928 | params->post_id = -1; |
| 1929 | params->embedding_token = base::UnguessableToken::Create(); |
| 1930 | params->navigation_token = base::UnguessableToken::Create(); |
| 1931 | params->did_create_new_entry = true; |
| 1932 | params->origin = rfh->GetLastCommittedOrigin(); |
| 1933 | params->should_update_history = true; |
| 1934 | params->item_sequence_number = 0; |
| 1935 | params->document_sequence_number = 0; |
Abhijeet Kandalkar | e26014a9 | 2022-10-13 04:21:15 | [diff] [blame] | 1936 | bool is_in_fenced_frame_tree = rfh->IsNestedWithinFencedFrame(); |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 1937 | params->transition = is_in_fenced_frame_tree |
| 1938 | ? ui::PAGE_TRANSITION_AUTO_SUBFRAME |
| 1939 | : ui::PAGE_TRANSITION_LINK; |
| 1940 | params->referrer = blink::mojom::Referrer::New(); |
| 1941 | |
| 1942 | // Create and insert the initial NavigationEntry. |
| 1943 | auto new_entry = std::make_unique<NavigationEntryImpl>( |
| 1944 | rfh->GetSiteInstance(), params->url, Referrer(*params->referrer), |
| 1945 | rfh->GetLastCommittedOrigin(), std::u16string() /* title */, |
| 1946 | ui::PAGE_TRANSITION_TYPED, false /* renderer_initiated */, |
| 1947 | nullptr /* blob_url_loader_factory */, true /* is_initial_entry */); |
| 1948 | UpdateNavigationEntryDetails( |
| 1949 | new_entry.get(), rfh, *params, nullptr /* request */, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 1950 | NavigationEntryImpl::UpdatePolicy::kUpdate, true /* is_new_entry */, |
| 1951 | nullptr /* commit_details */); |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 1952 | |
| 1953 | InsertOrReplaceEntry(std::move(new_entry), false /* replace_entry */, |
| 1954 | false /* was_post_commit_error */, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 1955 | is_in_fenced_frame_tree, nullptr /* commit_details */); |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 1956 | } |
| 1957 | |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1958 | void NavigationControllerImpl::RendererDidNavigateToNewEntry( |
creis | 3da0387 | 2015-02-20 21:12:32 | [diff] [blame] | 1959 | RenderFrameHostImpl* rfh, |
arthursonzogni | 73fe321 | 2020-11-17 13:24:07 | [diff] [blame] | 1960 | const mojom::DidCommitProvisionalLoadParams& params, |
eugenebut | 604866f | 2017-05-10 21:35:36 | [diff] [blame] | 1961 | bool is_same_document, |
clamy | 3bf35e3c | 2016-11-10 15:59:44 | [diff] [blame] | 1962 | bool replace_entry, |
Shivani Sharma | ffb32b8 | 2019-04-09 16:58:47 | [diff] [blame] | 1963 | bool previous_document_was_activated, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 1964 | NavigationRequest* request, |
| 1965 | LoadCommittedDetails* commit_details) { |
dcheng | 9bfa516 | 2016-04-09 01:00:57 | [diff] [blame] | 1966 | std::unique_ptr<NavigationEntryImpl> new_entry; |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 1967 | const absl::optional<url::Origin>& initiator_origin = |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 1968 | request->common_params().initiator_origin; |
Lukasz Anforowicz | 435bcb58 | 2019-07-12 20:50:06 | [diff] [blame] | 1969 | |
creis | f49dfc9 | 2016-07-26 17:05:18 | [diff] [blame] | 1970 | // First check if this is an in-page navigation. If so, clone the current |
| 1971 | // entry instead of looking at the pending entry, because the pending entry |
| 1972 | // does not have any subframe history items. |
eugenebut | 604866f | 2017-05-10 21:35:36 | [diff] [blame] | 1973 | if (is_same_document && GetLastCommittedEntry()) { |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 1974 | FrameNavigationEntry* previous_frame_entry = |
| 1975 | GetLastCommittedEntry()->GetFrameEntry(rfh->frame_tree_node()); |
Patrick Monette | 50e8bd8 | 2019-06-13 22:40:45 | [diff] [blame] | 1976 | auto frame_entry = base::MakeRefCounted<FrameNavigationEntry>( |
Charles Reis | d2a509f | 2017-09-27 23:47:48 | [diff] [blame] | 1977 | rfh->frame_tree_node()->unique_name(), params.item_sequence_number, |
Domenic Denicola | cc094fb | 2022-03-16 23:40:57 | [diff] [blame] | 1978 | params.document_sequence_number, params.navigation_api_key, |
Nate Chapin | fbfe5af | 2021-06-10 17:22:08 | [diff] [blame] | 1979 | rfh->GetSiteInstance(), nullptr, params.url, |
| 1980 | GetCommittedOriginForFrameEntry(params, request), |
Rakina Zata Amni | 82fafba | 2021-03-11 07:07:09 | [diff] [blame] | 1981 | Referrer(*params.referrer), initiator_origin, |
| 1982 | request->GetRedirectChain(), params.page_state, params.method, |
| 1983 | params.post_id, nullptr /* blob_url_loader_factory */, |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 1984 | nullptr /* web_bundle_navigation_info */, |
Kunihiko Sakamoto | 346a74e | 2021-03-10 08:57:48 | [diff] [blame] | 1985 | request->GetSubresourceWebBundleNavigationInfo(), |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 1986 | // We will set the document policies later in this function. |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 1987 | nullptr /* policy_container_policies */, |
Domenic Denicola | cc094fb | 2022-03-16 23:40:57 | [diff] [blame] | 1988 | // Try to preserve protect_url_in_navigation_api from the previous |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 1989 | // FrameNavigationEntry. |
| 1990 | previous_frame_entry && |
Domenic Denicola | cc094fb | 2022-03-16 23:40:57 | [diff] [blame] | 1991 | previous_frame_entry->protect_url_in_navigation_api()); |
Charles Reis | f4448202 | 2017-10-13 21:15:03 | [diff] [blame] | 1992 | |
creis | f49dfc9 | 2016-07-26 17:05:18 | [diff] [blame] | 1993 | new_entry = GetLastCommittedEntry()->CloneAndReplace( |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 1994 | frame_entry, true, request->frame_tree_node(), frame_tree_->root()); |
Mike West | 800532c | 2021-10-14 09:26:52 | [diff] [blame] | 1995 | if (new_entry->GetURL().DeprecatedGetOriginAsURL() != |
| 1996 | params.url.DeprecatedGetOriginAsURL()) { |
jam | a78746e | 2017-02-22 17:21:57 | [diff] [blame] | 1997 | // TODO(jam): we had one report of this with a URL that was redirecting to |
| 1998 | // only tildes. Until we understand that better, don't copy the cert in |
| 1999 | // this case. |
| 2000 | new_entry->GetSSL() = SSLStatus(); |
jam | a78746e | 2017-02-22 17:21:57 | [diff] [blame] | 2001 | } |
creis | f49dfc9 | 2016-07-26 17:05:18 | [diff] [blame] | 2002 | |
Patrick Monette | 50e8bd8 | 2019-06-13 22:40:45 | [diff] [blame] | 2003 | // It is expected that |frame_entry| is now owned by |new_entry|. This means |
| 2004 | // that |frame_entry| should now have a reference count of exactly 2: one |
| 2005 | // due to the local variable |frame_entry|, and another due to |new_entry| |
| 2006 | // also retaining one. This should never fail, because it's the main frame. |
| 2007 | CHECK(!frame_entry->HasOneRef() && frame_entry->HasAtLeastOneRef()); |
creis | f49dfc9 | 2016-07-26 17:05:18 | [diff] [blame] | 2008 | } |
| 2009 | |
Harkiran Bolaria | 59290d6 | 2021-03-17 01:53:01 | [diff] [blame] | 2010 | // If this is an activation navigation from a prerendered page, transfer the |
| 2011 | // new entry from an entry already created and stored in the |
| 2012 | // NavigationRequest. |new_entry| will not have been set prior to this as |
| 2013 | // |is_same_document| is mutually exclusive with |
| 2014 | // |IsPrerenderedPageActivation|. |
| 2015 | if (request->IsPrerenderedPageActivation()) { |
| 2016 | DCHECK(!is_same_document); |
| 2017 | DCHECK(!new_entry); |
| 2018 | new_entry = request->TakePrerenderNavigationEntry(); |
| 2019 | DCHECK(new_entry); |
| 2020 | } |
| 2021 | |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 2022 | // Only make a copy of the pending entry if it is appropriate for the new |
| 2023 | // document that just loaded. Verify this by checking if the entry corresponds |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 2024 | // to the given NavigationRequest. Additionally, coarsely check that: |
csharrison | 9a9142bc4 | 2016-03-01 17:24:04 | [diff] [blame] | 2025 | // 1. The SiteInstance hasn't been assigned to something else. |
| 2026 | // 2. The pending entry was intended as a new entry, rather than being a |
| 2027 | // history navigation that was interrupted by an unrelated, |
| 2028 | // renderer-initiated navigation. |
| 2029 | // TODO(csharrison): Investigate whether we can remove some of the coarser |
| 2030 | // checks. |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 2031 | if (!new_entry && PendingEntryMatchesRequest(request) && |
| 2032 | pending_entry_index_ == -1 && |
[email protected] | 6dd86ab | 2013-02-27 00:30:34 | [diff] [blame] | 2033 | (!pending_entry_->site_instance() || |
[email protected] | 27dd82fd | 2014-03-03 22:11:43 | [diff] [blame] | 2034 | pending_entry_->site_instance() == rfh->GetSiteInstance())) { |
creis | ef4a0cb | 2015-03-12 19:14:35 | [diff] [blame] | 2035 | new_entry = pending_entry_->Clone(); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 2036 | |
Camille Lamy | 62b82601 | 2019-02-26 09:15:47 | [diff] [blame] | 2037 | new_entry->GetSSL() = |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 2038 | SSLStatus(request->GetSSLInfo().value_or(net::SSLInfo())); |
creis | f49dfc9 | 2016-07-26 17:05:18 | [diff] [blame] | 2039 | } |
| 2040 | |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 2041 | // For cross-document commits with no matching pending entry, create a new |
| 2042 | // entry. |
creis | f49dfc9 | 2016-07-26 17:05:18 | [diff] [blame] | 2043 | if (!new_entry) { |
Lukasz Anforowicz | 435bcb58 | 2019-07-12 20:50:06 | [diff] [blame] | 2044 | new_entry = std::make_unique<NavigationEntryImpl>( |
arthursonzogni | 73fe321 | 2020-11-17 13:24:07 | [diff] [blame] | 2045 | rfh->GetSiteInstance(), params.url, Referrer(*params.referrer), |
| 2046 | initiator_origin, |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 2047 | std::u16string(), // title |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 2048 | params.transition, request->IsRendererInitiated(), |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 2049 | nullptr, // blob_url_loader_factory |
| 2050 | false); // is_initial_entry |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 2051 | |
| 2052 | // Find out whether the new entry needs to update its virtual URL on URL |
| 2053 | // change and set up the entry accordingly. This is needed to correctly |
| 2054 | // update the virtual URL when replaceState is called after a pushState. |
| 2055 | GURL url = params.url; |
| 2056 | bool needs_update = false; |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 2057 | // When navigating to a new entry, give the browser URL handler a chance to |
[email protected] | f1eb87a | 2011-05-06 17:49:41 | [diff] [blame] | 2058 | // update the virtual URL based on the new URL. For example, this is needed |
| 2059 | // to show chrome://bookmarks/#1 when the bookmarks webui extension changes |
| 2060 | // the URL. |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 2061 | BrowserURLHandlerImpl::GetInstance()->RewriteURLIfNecessary( |
| 2062 | &url, browser_context_, &needs_update); |
| 2063 | new_entry->set_update_virtual_url_with_url(needs_update); |
| 2064 | |
Camille Lamy | 62b82601 | 2019-02-26 09:15:47 | [diff] [blame] | 2065 | new_entry->GetSSL() = |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 2066 | SSLStatus(request->GetSSLInfo().value_or(net::SSLInfo())); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 2067 | } |
| 2068 | |
Harkiran Bolaria | 59290d6 | 2021-03-17 01:53:01 | [diff] [blame] | 2069 | // TODO(crbug.com/1179428) - determine which parts of the entry need to be set |
| 2070 | // for prerendered contents, if any. This is because prerendering/activation |
| 2071 | // technically won't be creating a new document. Unlike BFCache, prerendering |
| 2072 | // creates a new NavigationEntry rather than using an existing one. |
| 2073 | if (!request->IsPrerenderedPageActivation()) { |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 2074 | UpdateNavigationEntryDetails(new_entry.get(), rfh, params, request, |
| 2075 | NavigationEntryImpl::UpdatePolicy::kUpdate, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 2076 | true /* is_new_entry */, commit_details); |
creis | 8b5cd4c | 2015-06-19 00:11:08 | [diff] [blame] | 2077 | |
Harkiran Bolaria | 59290d6 | 2021-03-17 01:53:01 | [diff] [blame] | 2078 | // history.pushState() is classified as a navigation to a new page, but sets |
| 2079 | // is_same_document to true. In this case, we already have the title and |
| 2080 | // favicon available, so set them immediately. |
| 2081 | if (is_same_document && GetLastCommittedEntry()) { |
| 2082 | new_entry->SetTitle(GetLastCommittedEntry()->GetTitle()); |
| 2083 | new_entry->GetFavicon() = GetLastCommittedEntry()->GetFavicon(); |
| 2084 | } |
[email protected] | 3a868f21 | 2014-08-09 10:41:19 | [diff] [blame] | 2085 | } |
[email protected] | ff64b3e | 2014-05-31 04:07:33 | [diff] [blame] | 2086 | |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 2087 | DCHECK(!params.history_list_was_cleared || !replace_entry); |
| 2088 | // The browser requested to clear the session history when it initiated the |
| 2089 | // navigation. Now we know that the renderer has updated its state accordingly |
| 2090 | // and it is safe to also clear the browser side history. |
| 2091 | if (params.history_list_was_cleared) { |
Rakina Zata Amni | ddf1050 | 2022-01-15 02:56:55 | [diff] [blame] | 2092 | DiscardNonCommittedEntriesWithCommitDetails(commit_details); |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 2093 | entries_.clear(); |
| 2094 | last_committed_entry_index_ = -1; |
| 2095 | } |
| 2096 | |
Nasko Oskov | aee2f86 | 2018-06-15 00:05:52 | [diff] [blame] | 2097 | // If this is a new navigation with replacement and there is a |
| 2098 | // pending_entry_ which matches the navigation reported by the renderer |
| 2099 | // process, then it should be the one replaced, so update the |
| 2100 | // last_committed_entry_index_ to use it. |
| 2101 | if (replace_entry && pending_entry_index_ != -1 && |
Charlie Reis | f8cde71 | 2022-10-20 16:25:09 | [diff] [blame] | 2102 | PendingEntryMatchesRequest(request)) { |
Nasko Oskov | aee2f86 | 2018-06-15 00:05:52 | [diff] [blame] | 2103 | last_committed_entry_index_ = pending_entry_index_; |
| 2104 | } |
| 2105 | |
Alexander Timin | e3ec419 | 2020-04-20 16:39:40 | [diff] [blame] | 2106 | SetShouldSkipOnBackForwardUIIfNeeded( |
shivanigithub | e92c33da | 2020-09-14 13:01:41 | [diff] [blame] | 2107 | replace_entry, previous_document_was_activated, |
Alexander Timin | e3ec419 | 2020-04-20 16:39:40 | [diff] [blame] | 2108 | request->IsRendererInitiated(), request->GetPreviousPageUkmSourceId()); |
shivanisha | 41f04c5 | 2018-12-12 15:52:05 | [diff] [blame] | 2109 | |
Carlos IL | 42b41659 | 2019-10-07 23:10:36 | [diff] [blame] | 2110 | InsertOrReplaceEntry(std::move(new_entry), replace_entry, |
Dave Tapuska | 87696ae | 2021-11-18 18:48:31 | [diff] [blame] | 2111 | !request->post_commit_error_page_html().empty(), |
Abhijeet Kandalkar | e26014a9 | 2022-10-13 04:21:15 | [diff] [blame] | 2112 | rfh->IsNestedWithinFencedFrame(), commit_details); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 2113 | } |
| 2114 | |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 2115 | void NavigationControllerImpl::RendererDidNavigateToExistingEntry( |
creis | 3da0387 | 2015-02-20 21:12:32 | [diff] [blame] | 2116 | RenderFrameHostImpl* rfh, |
arthursonzogni | 73fe321 | 2020-11-17 13:24:07 | [diff] [blame] | 2117 | const mojom::DidCommitProvisionalLoadParams& params, |
eugenebut | 604866f | 2017-05-10 21:35:36 | [diff] [blame] | 2118 | bool is_same_document, |
jam | 48cea908 | 2017-02-15 06:13:29 | [diff] [blame] | 2119 | bool was_restored, |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 2120 | NavigationRequest* request, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 2121 | bool keep_pending_entry, |
| 2122 | LoadCommittedDetails* commit_details) { |
creis | 26d2263 | 2017-04-21 20:23:56 | [diff] [blame] | 2123 | DCHECK(GetLastCommittedEntry()) << "ClassifyNavigation should guarantee " |
| 2124 | << "that a last committed entry exists."; |
| 2125 | |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 2126 | // We should only get here for main frame navigations. |
avi | 39c1edd3 | 2015-06-04 20:06:00 | [diff] [blame] | 2127 | DCHECK(!rfh->GetParent()); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 2128 | |
Charlie Reis | 7e2cb6d | 2021-01-26 01:27:16 | [diff] [blame] | 2129 | NavigationEntryImpl* entry = nullptr; |
Rakina Zata Amni | 153d570 | 2021-09-13 22:48:00 | [diff] [blame] | 2130 | if (request->commit_params().intended_as_new_entry) { |
Charlie Reis | 7e2cb6d | 2021-01-26 01:27:16 | [diff] [blame] | 2131 | // We're guaranteed to have a last committed entry if intended_as_new_entry |
| 2132 | // is true. |
avi | cbdc4c1 | 2015-07-01 16:07:11 | [diff] [blame] | 2133 | entry = GetLastCommittedEntry(); |
Charlie Reis | 7e2cb6d | 2021-01-26 01:27:16 | [diff] [blame] | 2134 | DCHECK(entry); |
| 2135 | |
| 2136 | // If the NavigationRequest matches a new pending entry and is classified as |
| 2137 | // EXISTING_ENTRY, then it is a navigation to the same URL that was |
| 2138 | // converted to a reload, such as a user pressing enter in the omnibox. |
Charlie Reis | f8cde71 | 2022-10-20 16:25:09 | [diff] [blame] | 2139 | if (pending_entry_index_ == -1 && PendingEntryMatchesRequest(request)) { |
Charlie Reis | 7e2cb6d | 2021-01-26 01:27:16 | [diff] [blame] | 2140 | // Note: The pending entry will usually have a real ReloadType here, but |
| 2141 | // it can still be ReloadType::NONE in cases that |
| 2142 | // ShouldTreatNavigationAsReload returns false (e.g., POST, view-source). |
| 2143 | |
| 2144 | // If we classified this correctly, the SiteInstance should not have |
| 2145 | // changed. |
| 2146 | CHECK_EQ(entry->site_instance(), rfh->GetSiteInstance()); |
| 2147 | |
| 2148 | // For converted reloads, we assign the entry's unique ID to be that of |
| 2149 | // the new one. Since this is always the result of a user action, we want |
| 2150 | // to dismiss infobars, etc. like a regular user-initiated navigation. |
| 2151 | entry->set_unique_id(pending_entry_->GetUniqueID()); |
| 2152 | |
| 2153 | // The extra headers may have changed due to reloading with different |
| 2154 | // headers. |
| 2155 | entry->set_extra_headers(pending_entry_->extra_headers()); |
| 2156 | } |
| 2157 | // Otherwise, this was intended as a new entry but the pending entry was |
| 2158 | // lost in the meantime and no new entry was created. We are stuck at the |
| 2159 | // last committed entry. |
| 2160 | |
| 2161 | // Even if this is a converted reload from pressing enter in the omnibox, |
| 2162 | // the server could redirect, requiring an update to the SSL status. If this |
| 2163 | // is a same document navigation, though, there's no SSLStatus in the |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 2164 | // NavigationRequest so don't overwrite the existing entry's SSLStatus. |
Charlie Reis | 7e2cb6d | 2021-01-26 01:27:16 | [diff] [blame] | 2165 | if (!is_same_document) { |
Camille Lamy | 62b82601 | 2019-02-26 09:15:47 | [diff] [blame] | 2166 | entry->GetSSL() = |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 2167 | SSLStatus(request->GetSSLInfo().value_or(net::SSLInfo())); |
Charlie Reis | 7e2cb6d | 2021-01-26 01:27:16 | [diff] [blame] | 2168 | } |
Rakina Zata Amni | f6950d55 | 2020-11-24 03:26:10 | [diff] [blame] | 2169 | } else if (const int nav_entry_id = request->commit_params().nav_entry_id) { |
avi | cbdc4c1 | 2015-07-01 16:07:11 | [diff] [blame] | 2170 | // This is a browser-initiated navigation (back/forward/reload). |
Rakina Zata Amni | f6950d55 | 2020-11-24 03:26:10 | [diff] [blame] | 2171 | entry = GetEntryWithUniqueID(nav_entry_id); |
jam | d208b90 | 2016-09-01 16:58:16 | [diff] [blame] | 2172 | |
eugenebut | 604866f | 2017-05-10 21:35:36 | [diff] [blame] | 2173 | if (is_same_document) { |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 2174 | // There's no SSLStatus in the NavigationRequest for same document |
eugenebut | 604866f | 2017-05-10 21:35:36 | [diff] [blame] | 2175 | // navigations, so normally we leave |entry|'s SSLStatus as is. However if |
| 2176 | // this was a restored same document navigation entry, then it won't have |
| 2177 | // an SSLStatus. So we need to copy over the SSLStatus from the entry that |
| 2178 | // navigated it. |
jam | 48cea908 | 2017-02-15 06:13:29 | [diff] [blame] | 2179 | NavigationEntryImpl* last_entry = GetLastCommittedEntry(); |
Mike West | 800532c | 2021-10-14 09:26:52 | [diff] [blame] | 2180 | if (entry->GetURL().DeprecatedGetOriginAsURL() == |
| 2181 | last_entry->GetURL().DeprecatedGetOriginAsURL() && |
jam | 48cea908 | 2017-02-15 06:13:29 | [diff] [blame] | 2182 | last_entry->GetSSL().initialized && !entry->GetSSL().initialized && |
| 2183 | was_restored) { |
| 2184 | entry->GetSSL() = last_entry->GetSSL(); |
| 2185 | } |
| 2186 | } else { |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 2187 | // In rapid back/forward navigations |request| sometimes won't have a cert |
| 2188 | // (http://crbug.com/727892). So we use the request's cert if it exists, |
John Abd-El-Malek | 3f24708 | 2017-12-07 19:02:19 | [diff] [blame] | 2189 | // otherwise we only reuse the existing cert if the origins match. |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 2190 | if (request->GetSSLInfo().has_value() && |
| 2191 | request->GetSSLInfo()->is_valid()) { |
| 2192 | entry->GetSSL() = SSLStatus(*(request->GetSSLInfo())); |
Mike West | 800532c | 2021-10-14 09:26:52 | [diff] [blame] | 2193 | } else if (entry->GetURL().DeprecatedGetOriginAsURL() != |
| 2194 | request->GetURL().DeprecatedGetOriginAsURL()) { |
John Abd-El-Malek | 3f24708 | 2017-12-07 19:02:19 | [diff] [blame] | 2195 | entry->GetSSL() = SSLStatus(); |
| 2196 | } |
jam | 48cea908 | 2017-02-15 06:13:29 | [diff] [blame] | 2197 | } |
avi | cbdc4c1 | 2015-07-01 16:07:11 | [diff] [blame] | 2198 | } else { |
Feifei Wang | 2ab8ba6c | 2022-04-13 22:19:27 | [diff] [blame] | 2199 | // This is renderer-initiated. The only kinds of renderer-initiated |
Rakina Zata Amni | 557afb9 | 2021-07-17 04:39:57 | [diff] [blame] | 2200 | // navigations that are EXISTING_ENTRY are same-document navigations that |
| 2201 | // result in replacement (e.g. history.replaceState(), location.replace(), |
| 2202 | // forced replacements for trivial session history contexts). For these |
| 2203 | // cases, we reuse the last committed entry. |
avi | cbdc4c1 | 2015-07-01 16:07:11 | [diff] [blame] | 2204 | entry = GetLastCommittedEntry(); |
jam | 0576b13 | 2016-09-07 05:13:10 | [diff] [blame] | 2205 | |
Mikel Astiz | ba9cf2fd | 2017-12-17 10:38:10 | [diff] [blame] | 2206 | // TODO(crbug.com/751023): Set page transition type to PAGE_TRANSITION_LINK |
| 2207 | // to avoid misleading interpretations (e.g. URLs paired with |
| 2208 | // PAGE_TRANSITION_TYPED that haven't actually been typed) as well as to fix |
| 2209 | // the inconsistency with what we report to observers (PAGE_TRANSITION_LINK |
| 2210 | // | PAGE_TRANSITION_CLIENT_REDIRECT). |
| 2211 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2212 | CopyReplacedNavigationEntryDataIfPreviouslyEmpty(entry, entry); |
Mikel Astiz | ba9cf2fd | 2017-12-17 10:38:10 | [diff] [blame] | 2213 | |
eugenebut | 604866f | 2017-05-10 21:35:36 | [diff] [blame] | 2214 | // If this is a same document navigation, then there's no SSLStatus in the |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 2215 | // NavigationRequest so don't overwrite the existing entry's SSLStatus. |
eugenebut | 604866f | 2017-05-10 21:35:36 | [diff] [blame] | 2216 | if (!is_same_document) |
Camille Lamy | 62b82601 | 2019-02-26 09:15:47 | [diff] [blame] | 2217 | entry->GetSSL() = |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 2218 | SSLStatus(request->GetSSLInfo().value_or(net::SSLInfo())); |
avi | cbdc4c1 | 2015-07-01 16:07:11 | [diff] [blame] | 2219 | } |
| 2220 | DCHECK(entry); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 2221 | |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 2222 | UpdateNavigationEntryDetails(entry, rfh, params, request, |
| 2223 | NavigationEntryImpl::UpdatePolicy::kUpdate, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 2224 | false /* is_new_entry */, commit_details); |
creis | 22a7b4c | 2016-04-28 07:20:30 | [diff] [blame] | 2225 | |
[email protected] | 5ccd4dc | 2012-10-24 02:28:14 | [diff] [blame] | 2226 | // The redirected to page should not inherit the favicon from the previous |
| 2227 | // page. |
eugenebut | 604866f | 2017-05-10 21:35:36 | [diff] [blame] | 2228 | if (ui::PageTransitionIsRedirect(params.transition) && !is_same_document) |
[email protected] | 91a4ff8 | 2012-10-29 20:29:48 | [diff] [blame] | 2229 | entry->GetFavicon() = FaviconStatus(); |
[email protected] | 5ccd4dc | 2012-10-24 02:28:14 | [diff] [blame] | 2230 | |
Peter Boström | d759213 | 2019-01-30 04:50:31 | [diff] [blame] | 2231 | // We should also usually discard the pending entry if it corresponds to a |
| 2232 | // different navigation, since that one is now likely canceled. In rare |
| 2233 | // cases, we leave the pending entry for another navigation in place when we |
| 2234 | // know it is still ongoing, to avoid a flicker in the omnibox (see |
| 2235 | // https://crbug.com/900036). |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 2236 | // |
| 2237 | // Note that we need to use the "internal" version since we don't want to |
| 2238 | // actually change any other state, just kill the pointer. |
Peter Boström | d759213 | 2019-01-30 04:50:31 | [diff] [blame] | 2239 | if (!keep_pending_entry) |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 2240 | DiscardNonCommittedEntriesWithCommitDetails(commit_details); |
[email protected] | 40bcc30 | 2009-03-02 20:50:39 | [diff] [blame] | 2241 | |
Carlos IL | 4dea890 | 2020-05-26 15:14:29 | [diff] [blame] | 2242 | // Update the last committed index to reflect the committed entry. |
avi | cbdc4c1 | 2015-07-01 16:07:11 | [diff] [blame] | 2243 | last_committed_entry_index_ = GetIndexOfEntry(entry); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 2244 | } |
| 2245 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 2246 | void NavigationControllerImpl::RendererDidNavigateNewSubframe( |
creis | 3da0387 | 2015-02-20 21:12:32 | [diff] [blame] | 2247 | RenderFrameHostImpl* rfh, |
arthursonzogni | 73fe321 | 2020-11-17 13:24:07 | [diff] [blame] | 2248 | const mojom::DidCommitProvisionalLoadParams& params, |
eugenebut | 604866f | 2017-05-10 21:35:36 | [diff] [blame] | 2249 | bool is_same_document, |
Shivani Sharma | ffb32b8 | 2019-04-09 16:58:47 | [diff] [blame] | 2250 | bool replace_entry, |
| 2251 | bool previous_document_was_activated, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 2252 | NavigationRequest* request, |
| 2253 | LoadCommittedDetails* commit_details) { |
avi | 25f5f9e | 2015-07-17 20:08:26 | [diff] [blame] | 2254 | DCHECK(ui::PageTransitionCoreTypeIs(params.transition, |
| 2255 | ui::PAGE_TRANSITION_MANUAL_SUBFRAME)); |
Rakina Zata Amni | ddf1050 | 2022-01-15 02:56:55 | [diff] [blame] | 2256 | // The NEW_SUBFRAME path should never result in an initial NavigationEntry. |
| 2257 | DCHECK(!commit_details->should_stay_as_initial_entry); |
[email protected] | 09b8f82f | 2009-06-16 20:22:11 | [diff] [blame] | 2258 | |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 2259 | // Manual subframe navigations just get the current entry cloned so the user |
| 2260 | // can go back or forward to it. The actual subframe information will be |
| 2261 | // stored in the page state for each of those entries. This happens out of |
| 2262 | // band with the actual navigations. |
[email protected] | 4c27ba8 | 2008-09-24 16:49:09 | [diff] [blame] | 2263 | DCHECK(GetLastCommittedEntry()) << "ClassifyNavigation should guarantee " |
| 2264 | << "that a last committed entry exists."; |
creis | 96fc5508 | 2015-06-13 06:42:38 | [diff] [blame] | 2265 | |
Mikel Astiz | ba9cf2fd | 2017-12-17 10:38:10 | [diff] [blame] | 2266 | // The DCHECK below documents the fact that we don't know of any situation |
| 2267 | // where |replace_entry| is true for subframe navigations. This simplifies |
| 2268 | // reasoning about the replacement struct for subframes (see |
| 2269 | // CopyReplacedNavigationEntryDataIfPreviouslyEmpty()). |
| 2270 | DCHECK(!replace_entry); |
| 2271 | |
Patrick Monette | 50e8bd8 | 2019-06-13 22:40:45 | [diff] [blame] | 2272 | // This FrameNavigationEntry might not end up being used in the |
| 2273 | // CloneAndReplace() call below, if a spot can't be found for it in the tree. |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 2274 | const absl::optional<url::Origin>& initiator_origin = |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 2275 | request->common_params().initiator_origin; |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 2276 | std::unique_ptr<PolicyContainerPolicies> policy_container_policies = |
| 2277 | ComputePolicyContainerPoliciesForFrameEntry(rfh, is_same_document, |
| 2278 | request->GetURL()); |
Domenic Denicola | cc094fb | 2022-03-16 23:40:57 | [diff] [blame] | 2279 | bool protect_url_in_navigation_api = false; |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 2280 | if (is_same_document) { |
| 2281 | FrameNavigationEntry* previous_frame_entry = |
| 2282 | GetLastCommittedEntry()->GetFrameEntry(rfh->frame_tree_node()); |
Domenic Denicola | cc094fb | 2022-03-16 23:40:57 | [diff] [blame] | 2283 | // Try to preserve protect_url_in_navigation_api from the previous |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 2284 | // FrameNavigationEntry. |
Domenic Denicola | cc094fb | 2022-03-16 23:40:57 | [diff] [blame] | 2285 | protect_url_in_navigation_api = |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 2286 | previous_frame_entry && |
Domenic Denicola | cc094fb | 2022-03-16 23:40:57 | [diff] [blame] | 2287 | previous_frame_entry->protect_url_in_navigation_api(); |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 2288 | } else { |
Domenic Denicola | cc094fb | 2022-03-16 23:40:57 | [diff] [blame] | 2289 | protect_url_in_navigation_api = |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 2290 | policy_container_policies && |
Domenic Denicola | cc094fb | 2022-03-16 23:40:57 | [diff] [blame] | 2291 | ShouldProtectUrlInNavigationApi( |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 2292 | policy_container_policies->referrer_policy); |
| 2293 | } |
| 2294 | |
Patrick Monette | 50e8bd8 | 2019-06-13 22:40:45 | [diff] [blame] | 2295 | auto frame_entry = base::MakeRefCounted<FrameNavigationEntry>( |
Charles Reis | d2a509f | 2017-09-27 23:47:48 | [diff] [blame] | 2296 | rfh->frame_tree_node()->unique_name(), params.item_sequence_number, |
Domenic Denicola | cc094fb | 2022-03-16 23:40:57 | [diff] [blame] | 2297 | params.document_sequence_number, params.navigation_api_key, |
Nate Chapin | fbfe5af | 2021-06-10 17:22:08 | [diff] [blame] | 2298 | rfh->GetSiteInstance(), nullptr, params.url, |
| 2299 | GetCommittedOriginForFrameEntry(params, request), |
Rakina Zata Amni | 82fafba | 2021-03-11 07:07:09 | [diff] [blame] | 2300 | Referrer(*params.referrer), initiator_origin, request->GetRedirectChain(), |
arthursonzogni | 73fe321 | 2020-11-17 13:24:07 | [diff] [blame] | 2301 | params.page_state, params.method, params.post_id, |
| 2302 | nullptr /* blob_url_loader_factory */, |
Tsuyoshi Horo | 0c60578 | 2020-05-27 00:21:03 | [diff] [blame] | 2303 | request->web_bundle_navigation_info() |
| 2304 | ? request->web_bundle_navigation_info()->Clone() |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 2305 | : nullptr, |
Kunihiko Sakamoto | 346a74e | 2021-03-10 08:57:48 | [diff] [blame] | 2306 | request->GetSubresourceWebBundleNavigationInfo(), |
Domenic Denicola | cc094fb | 2022-03-16 23:40:57 | [diff] [blame] | 2307 | std::move(policy_container_policies), protect_url_in_navigation_api); |
Charles Reis | f4448202 | 2017-10-13 21:15:03 | [diff] [blame] | 2308 | |
creis | ce0ef357 | 2017-01-26 17:53:08 | [diff] [blame] | 2309 | std::unique_ptr<NavigationEntryImpl> new_entry = |
| 2310 | GetLastCommittedEntry()->CloneAndReplace( |
Patrick Monette | 50e8bd8 | 2019-06-13 22:40:45 | [diff] [blame] | 2311 | std::move(frame_entry), is_same_document, rfh->frame_tree_node(), |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 2312 | frame_tree_->root()); |
creis | e062d54 | 2015-08-25 02:01:55 | [diff] [blame] | 2313 | |
Alexander Timin | e3ec419 | 2020-04-20 16:39:40 | [diff] [blame] | 2314 | SetShouldSkipOnBackForwardUIIfNeeded( |
shivanigithub | e92c33da | 2020-09-14 13:01:41 | [diff] [blame] | 2315 | replace_entry, previous_document_was_activated, |
Alexander Timin | e3ec419 | 2020-04-20 16:39:40 | [diff] [blame] | 2316 | request->IsRendererInitiated(), request->GetPreviousPageUkmSourceId()); |
Shivani Sharma | ffb32b8 | 2019-04-09 16:58:47 | [diff] [blame] | 2317 | |
creis | ce0ef357 | 2017-01-26 17:53:08 | [diff] [blame] | 2318 | // TODO(creis): Update this to add the frame_entry if we can't find the one |
Patrick Monette | 50e8bd8 | 2019-06-13 22:40:45 | [diff] [blame] | 2319 | // to replace, which can happen due to a unique name change. See |
| 2320 | // https://crbug.com/607205. For now, the call to CloneAndReplace() will |
| 2321 | // delete the |frame_entry| when the function exits if it doesn't get used. |
creis | 96fc5508 | 2015-06-13 06:42:38 | [diff] [blame] | 2322 | |
Dave Tapuska | 87696ae | 2021-11-18 18:48:31 | [diff] [blame] | 2323 | InsertOrReplaceEntry(std::move(new_entry), replace_entry, false, |
Abhijeet Kandalkar | e26014a9 | 2022-10-13 04:21:15 | [diff] [blame] | 2324 | rfh->IsNestedWithinFencedFrame(), commit_details); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 2325 | } |
| 2326 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 2327 | bool NavigationControllerImpl::RendererDidNavigateAutoSubframe( |
creis | 3da0387 | 2015-02-20 21:12:32 | [diff] [blame] | 2328 | RenderFrameHostImpl* rfh, |
arthursonzogni | 73fe321 | 2020-11-17 13:24:07 | [diff] [blame] | 2329 | const mojom::DidCommitProvisionalLoadParams& params, |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 2330 | bool is_same_document, |
Nate Chapin | c7019dd7d | 2021-06-25 18:29:25 | [diff] [blame] | 2331 | bool was_on_initial_empty_document, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 2332 | NavigationRequest* request, |
| 2333 | LoadCommittedDetails* commit_details) { |
avi | 9f07a0c | 2015-02-18 22:51:29 | [diff] [blame] | 2334 | DCHECK(ui::PageTransitionCoreTypeIs(params.transition, |
| 2335 | ui::PAGE_TRANSITION_AUTO_SUBFRAME)); |
| 2336 | |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 2337 | // We're guaranteed to have a previously committed entry, and we now need to |
| 2338 | // handle navigation inside of a subframe in it without creating a new entry. |
| 2339 | DCHECK(GetLastCommittedEntry()); |
| 2340 | |
creis | 913c63ce | 2016-07-16 19:52:52 | [diff] [blame] | 2341 | // For newly created subframes, we don't need to send a commit notification. |
| 2342 | // This is only necessary for history navigations in subframes. |
| 2343 | bool send_commit_notification = false; |
| 2344 | |
Rakina Zata Amni | f6950d55 | 2020-11-24 03:26:10 | [diff] [blame] | 2345 | // If |nav_entry_id| is non-zero and matches an existing entry, this |
| 2346 | // is a history navigation. Update the last committed index accordingly. If |
| 2347 | // we don't recognize the |nav_entry_id|, it might be a recently |
| 2348 | // pruned entry. We'll handle it below. |
| 2349 | if (const int nav_entry_id = request->commit_params().nav_entry_id) { |
| 2350 | int entry_index = GetEntryIndexWithUniqueID(nav_entry_id); |
creis | 3cdc3b0 | 2015-05-29 23:00:47 | [diff] [blame] | 2351 | if (entry_index != -1 && entry_index != last_committed_entry_index_) { |
avi | 98405c2 | 2015-05-21 20:47:06 | [diff] [blame] | 2352 | // Make sure that a subframe commit isn't changing the main frame's |
| 2353 | // origin. Otherwise the renderer process may be confused, leading to a |
| 2354 | // URL spoof. We can't check the path since that may change |
| 2355 | // (https://crbug.com/373041). |
creis | 37988b9 | 2016-06-10 18:03:57 | [diff] [blame] | 2356 | // TODO(creis): For now, restrict this check to HTTP(S) origins, because |
| 2357 | // about:blank, file, and unique origins are more subtle to get right. |
Charlie Reis | 95fbca44 | 2021-05-21 21:38:24 | [diff] [blame] | 2358 | // We should use checks similar to RenderFrameHostImpl's |
| 2359 | // CanCommitUrlAndOrigin on the main frame during subframe commits. |
| 2360 | // See https://crbug.com/1209092. |
creis | 37988b9 | 2016-06-10 18:03:57 | [diff] [blame] | 2361 | const GURL& dest_top_url = GetEntryAtIndex(entry_index)->GetURL(); |
| 2362 | const GURL& current_top_url = GetLastCommittedEntry()->GetURL(); |
| 2363 | if (current_top_url.SchemeIsHTTPOrHTTPS() && |
| 2364 | dest_top_url.SchemeIsHTTPOrHTTPS() && |
Mike West | 800532c | 2021-10-14 09:26:52 | [diff] [blame] | 2365 | current_top_url.DeprecatedGetOriginAsURL() != |
| 2366 | dest_top_url.DeprecatedGetOriginAsURL()) { |
Chris Bookholt | 10f4b733 | 2022-02-14 18:25:44 | [diff] [blame] | 2367 | bad_message::ReceivedBadMessage(rfh->GetMainFrame()->GetProcess(), |
creis | fb6eeb6 | 2016-05-10 19:01:51 | [diff] [blame] | 2368 | bad_message::NC_AUTO_SUBFRAME); |
avi | 98405c2 | 2015-05-21 20:47:06 | [diff] [blame] | 2369 | } |
creis | 3cdc3b0 | 2015-05-29 23:00:47 | [diff] [blame] | 2370 | |
creis | 913c63ce | 2016-07-16 19:52:52 | [diff] [blame] | 2371 | // We only need to discard the pending entry in this history navigation |
| 2372 | // case. For newly created subframes, there was no pending entry. |
avi | 98405c2 | 2015-05-21 20:47:06 | [diff] [blame] | 2373 | last_committed_entry_index_ = entry_index; |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 2374 | DiscardNonCommittedEntriesWithCommitDetails(commit_details); |
creis | 913c63ce | 2016-07-16 19:52:52 | [diff] [blame] | 2375 | |
| 2376 | // History navigations should send a commit notification. |
| 2377 | send_commit_notification = true; |
avi | 98405c2 | 2015-05-21 20:47:06 | [diff] [blame] | 2378 | } |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 2379 | } |
[email protected] | f233e423 | 2013-02-23 00:55:14 | [diff] [blame] | 2380 | |
creis | ce0ef357 | 2017-01-26 17:53:08 | [diff] [blame] | 2381 | // This may be a "new auto" case where we add a new FrameNavigationEntry, or |
| 2382 | // it may be a "history auto" case where we update an existing one. |
| 2383 | NavigationEntryImpl* last_committed = GetLastCommittedEntry(); |
Nate Chapin | 9f16907 | 2021-06-09 19:32:37 | [diff] [blame] | 2384 | |
| 2385 | // We may want to update |last_committed|'s FrameNavigationEntry (if one |
| 2386 | // exists), or we may want to clobber it and create a new one. We update in |
| 2387 | // cases where the corresponding FrameNavigationEntry is conceptually similar |
| 2388 | // to the document described by the commit params: same-document |
| 2389 | // navigations, history traversal to an existing entry, and reloads (including |
| 2390 | // a "soft reload" where we navigate to the same url without flagging it as a |
| 2391 | // reload). But in the case of a different document that is not logically |
| 2392 | // related to the committed FrameNavigationEntry's document (cross-document, |
| 2393 | // not same url, not a reload, not a history traversal), we replace rather |
| 2394 | // than update. |
Nate Chapin | c7019dd7d | 2021-06-25 18:29:25 | [diff] [blame] | 2395 | // |
Nate Chapin | 9f16907 | 2021-06-09 19:32:37 | [diff] [blame] | 2396 | // In the case where we update, the FrameNavigationEntry will potentially be |
| 2397 | // shared across multiple NavigationEntries, and any updates will be reflected |
| 2398 | // in all of those NavigationEntries. In the replace case, any existing |
| 2399 | // sharing with other NavigationEntries will stop. |
Nate Chapin | c7019dd7d | 2021-06-25 18:29:25 | [diff] [blame] | 2400 | // |
| 2401 | // When navigating away from the initial empty document, we also update rather |
| 2402 | // than replace. Either update or replace will overwrite the initial empty |
| 2403 | // document state for |last_committed|, but if the FrameNavigationEntry for |
| 2404 | // the initial empty document is shared across multiple NavigationEntries (due |
| 2405 | // to a navigation in another frame), we want to make sure we overwrite the |
| 2406 | // initial empty document state everywhere this FrameNavigationEntry is used, |
| 2407 | // which is accompished by updating the existing FrameNavigationEntry. |
Nate Chapin | 9f16907 | 2021-06-09 19:32:37 | [diff] [blame] | 2408 | FrameNavigationEntry* last_committed_frame_entry = |
| 2409 | last_committed->GetFrameEntry(rfh->frame_tree_node()); |
| 2410 | NavigationEntryImpl::UpdatePolicy update_policy = |
| 2411 | NavigationEntryImpl::UpdatePolicy::kUpdate; |
| 2412 | if (request->common_params().navigation_type == |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 2413 | blink::mojom::NavigationType::DIFFERENT_DOCUMENT && |
Nate Chapin | 9f16907 | 2021-06-09 19:32:37 | [diff] [blame] | 2414 | last_committed_frame_entry && |
Nate Chapin | c7019dd7d | 2021-06-25 18:29:25 | [diff] [blame] | 2415 | last_committed_frame_entry->url() != params.url && |
| 2416 | !was_on_initial_empty_document) { |
Nate Chapin | 9f16907 | 2021-06-09 19:32:37 | [diff] [blame] | 2417 | update_policy = NavigationEntryImpl::UpdatePolicy::kReplace; |
| 2418 | } |
| 2419 | |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 2420 | UpdateNavigationEntryDetails(last_committed, rfh, params, request, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 2421 | update_policy, false /* is_new_entry */, |
| 2422 | commit_details); |
creis | 625a0c7d | 2015-03-24 23:17:12 | [diff] [blame] | 2423 | |
creis | 913c63ce | 2016-07-16 19:52:52 | [diff] [blame] | 2424 | return send_commit_notification; |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 2425 | } |
| 2426 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 2427 | int NavigationControllerImpl::GetIndexOfEntry( |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 2428 | const NavigationEntryImpl* entry) const { |
avi | f16f85a7 | 2015-11-13 18:25:03 | [diff] [blame] | 2429 | for (size_t i = 0; i < entries_.size(); ++i) { |
| 2430 | if (entries_[i].get() == entry) |
| 2431 | return i; |
| 2432 | } |
| 2433 | return -1; |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 2434 | } |
| 2435 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2436 | void NavigationControllerImpl::CopyStateFrom(NavigationController* temp, |
Francois Doray | eaace78 | 2017-06-21 16:37:24 | [diff] [blame] | 2437 | bool needs_reload) { |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2438 | NavigationControllerImpl* source = |
| 2439 | static_cast<NavigationControllerImpl*>(temp); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 2440 | // Verify that we look new. |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 2441 | if (blink::features::IsInitialNavigationEntryEnabled()) { |
| 2442 | DCHECK_EQ(1, GetEntryCount()); |
| 2443 | DCHECK(GetLastCommittedEntry()->IsInitialEntry()); |
| 2444 | } else { |
| 2445 | DCHECK_EQ(0, GetEntryCount()); |
| 2446 | } |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 2447 | DCHECK(!GetPendingEntry()); |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 2448 | entries_.clear(); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 2449 | |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 2450 | if (source->GetEntryCount() == 0) { |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 2451 | return; |
| 2452 | } |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 2453 | |
Francois Doray | eaace78 | 2017-06-21 16:37:24 | [diff] [blame] | 2454 | needs_reload_ = needs_reload; |
Bo Liu | cdfa4b1 | 2018-11-06 00:21:44 | [diff] [blame] | 2455 | needs_reload_type_ = NeedsReloadType::kCopyStateFrom; |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2456 | InsertEntriesFrom(source, source->GetEntryCount()); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 2457 | |
Fergal Daly | a1d56997 | 2021-03-16 03:24:53 | [diff] [blame] | 2458 | for (auto& it : source->session_storage_namespace_map_) { |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 2459 | SessionStorageNamespaceImpl* source_namespace = |
Fergal Daly | a1d56997 | 2021-03-16 03:24:53 | [diff] [blame] | 2460 | static_cast<SessionStorageNamespaceImpl*>(it.second.get()); |
| 2461 | session_storage_namespace_map_[it.first] = source_namespace->Clone(); |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 2462 | } |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 2463 | |
Lukasz Anforowicz | 0de0f45 | 2020-12-02 19:57:15 | [diff] [blame] | 2464 | FinishRestore(source->last_committed_entry_index_, RestoreType::kRestored); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 2465 | } |
| 2466 | |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 2467 | void NavigationControllerImpl::CopyStateFromAndPrune(NavigationController* temp, |
| 2468 | bool replace_entry) { |
[email protected] | 474f851 | 2013-05-31 22:31:16 | [diff] [blame] | 2469 | // It is up to callers to check the invariants before calling this. |
[email protected] | 7936898 | 2013-11-13 01:11:01 | [diff] [blame] | 2470 | CHECK(CanPruneAllButLastCommitted()); |
[email protected] | 474f851 | 2013-05-31 22:31:16 | [diff] [blame] | 2471 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 2472 | NavigationControllerImpl* source = |
| 2473 | static_cast<NavigationControllerImpl*>(temp); |
[email protected] | e1cd545 | 2010-08-26 18:03:25 | [diff] [blame] | 2474 | |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 2475 | // Remove all the entries leaving the last committed entry. |
[email protected] | 7936898 | 2013-11-13 01:11:01 | [diff] [blame] | 2476 | PruneAllButLastCommittedInternal(); |
[email protected] | e1cd545 | 2010-08-26 18:03:25 | [diff] [blame] | 2477 | |
[email protected] | 474f851 | 2013-05-31 22:31:16 | [diff] [blame] | 2478 | // We now have one entry, possibly with a new pending entry. Ensure that |
| 2479 | // adding the entries from source won't put us over the limit. |
| 2480 | DCHECK_EQ(1, GetEntryCount()); |
[email protected] | e78a685 | 2013-12-13 08:08:57 | [diff] [blame] | 2481 | if (!replace_entry) |
Shivani Sharma | d8c8d65 | 2019-02-13 17:27:57 | [diff] [blame] | 2482 | source->PruneOldestSkippableEntryIfFull(); |
[email protected] | 944822b | 2012-03-02 20:57:25 | [diff] [blame] | 2483 | |
Carlos IL | 4dea890 | 2020-05-26 15:14:29 | [diff] [blame] | 2484 | // Insert the entries from source. Ignore any pending entry, since it has not |
| 2485 | // committed in source. |
[email protected] | 474f851 | 2013-05-31 22:31:16 | [diff] [blame] | 2486 | int max_source_index = source->last_committed_entry_index_; |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 2487 | DCHECK_NE(max_source_index, -1); |
| 2488 | max_source_index++; |
[email protected] | e78a685 | 2013-12-13 08:08:57 | [diff] [blame] | 2489 | |
| 2490 | // Ignore the source's current entry if merging with replacement. |
| 2491 | // TODO(davidben): This should preserve entries forward of the current |
| 2492 | // too. http://crbug.com/317872 |
| 2493 | if (replace_entry && max_source_index > 0) |
| 2494 | max_source_index--; |
| 2495 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2496 | InsertEntriesFrom(source, max_source_index); |
[email protected] | e1cd545 | 2010-08-26 18:03:25 | [diff] [blame] | 2497 | |
| 2498 | // Adjust indices such that the last entry and pending are at the end now. |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 2499 | last_committed_entry_index_ = GetEntryCount() - 1; |
[email protected] | 796931a9 | 2011-08-10 01:32:14 | [diff] [blame] | 2500 | |
Hayato Ito | 2c8c08d0 | 2021-06-23 03:38:43 | [diff] [blame] | 2501 | BroadcastHistoryOffsetAndLength(); |
[email protected] | e1cd545 | 2010-08-26 18:03:25 | [diff] [blame] | 2502 | } |
| 2503 | |
[email protected] | 7936898 | 2013-11-13 01:11:01 | [diff] [blame] | 2504 | bool NavigationControllerImpl::CanPruneAllButLastCommitted() { |
[email protected] | 474f851 | 2013-05-31 22:31:16 | [diff] [blame] | 2505 | // If there is no last committed entry, we cannot prune. Even if there is a |
| 2506 | // pending entry, it may not commit, leaving this WebContents blank, despite |
| 2507 | // possibly giving it new entries via CopyStateFromAndPrune. |
| 2508 | if (last_committed_entry_index_ == -1) |
| 2509 | return false; |
[email protected] | 9350602e | 2013-02-26 23:27:44 | [diff] [blame] | 2510 | |
[email protected] | 474f851 | 2013-05-31 22:31:16 | [diff] [blame] | 2511 | // We cannot prune if there is a pending entry at an existing entry index. |
| 2512 | // It may not commit, so we have to keep the last committed entry, and thus |
| 2513 | // there is no sensible place to keep the pending entry. It is ok to have |
| 2514 | // a new pending entry, which can optionally commit as a new navigation. |
| 2515 | if (pending_entry_index_ != -1) |
| 2516 | return false; |
| 2517 | |
[email protected] | 474f851 | 2013-05-31 22:31:16 | [diff] [blame] | 2518 | return true; |
| 2519 | } |
| 2520 | |
[email protected] | 7936898 | 2013-11-13 01:11:01 | [diff] [blame] | 2521 | void NavigationControllerImpl::PruneAllButLastCommitted() { |
| 2522 | PruneAllButLastCommittedInternal(); |
[email protected] | 474f851 | 2013-05-31 22:31:16 | [diff] [blame] | 2523 | |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 2524 | DCHECK_EQ(0, last_committed_entry_index_); |
| 2525 | DCHECK_EQ(1, GetEntryCount()); |
[email protected] | 9350602e | 2013-02-26 23:27:44 | [diff] [blame] | 2526 | |
Hayato Ito | 2c8c08d0 | 2021-06-23 03:38:43 | [diff] [blame] | 2527 | BroadcastHistoryOffsetAndLength(); |
[email protected] | 9350602e | 2013-02-26 23:27:44 | [diff] [blame] | 2528 | } |
| 2529 | |
[email protected] | 7936898 | 2013-11-13 01:11:01 | [diff] [blame] | 2530 | void NavigationControllerImpl::PruneAllButLastCommittedInternal() { |
[email protected] | 474f851 | 2013-05-31 22:31:16 | [diff] [blame] | 2531 | // It is up to callers to check the invariants before calling this. |
[email protected] | 7936898 | 2013-11-13 01:11:01 | [diff] [blame] | 2532 | CHECK(CanPruneAllButLastCommitted()); |
[email protected] | 97b6c4f | 2010-09-27 19:31:26 | [diff] [blame] | 2533 | |
Nate Chapin | 9eb16be7 | 2022-09-23 22:54:31 | [diff] [blame] | 2534 | RemovedEntriesTracker tracker(weak_factory_.GetSafeRef()); |
| 2535 | |
[email protected] | 474f851 | 2013-05-31 22:31:16 | [diff] [blame] | 2536 | // Erase all entries but the last committed entry. There may still be a |
| 2537 | // new pending entry after this. |
| 2538 | entries_.erase(entries_.begin(), |
| 2539 | entries_.begin() + last_committed_entry_index_); |
| 2540 | entries_.erase(entries_.begin() + 1, entries_.end()); |
| 2541 | last_committed_entry_index_ = 0; |
[email protected] | 97b6c4f | 2010-09-27 19:31:26 | [diff] [blame] | 2542 | } |
| 2543 | |
Christian Dullweber | 1af31e6 | 2018-02-22 11:49:48 | [diff] [blame] | 2544 | void NavigationControllerImpl::DeleteNavigationEntries( |
| 2545 | const DeletionPredicate& deletionPredicate) { |
| 2546 | // It is up to callers to check the invariants before calling this. |
| 2547 | CHECK(CanPruneAllButLastCommitted()); |
| 2548 | std::vector<int> delete_indices; |
| 2549 | for (size_t i = 0; i < entries_.size(); i++) { |
| 2550 | if (i != static_cast<size_t>(last_committed_entry_index_) && |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2551 | deletionPredicate.Run(entries_[i].get())) { |
Christian Dullweber | 1af31e6 | 2018-02-22 11:49:48 | [diff] [blame] | 2552 | delete_indices.push_back(i); |
| 2553 | } |
| 2554 | } |
| 2555 | if (delete_indices.empty()) |
| 2556 | return; |
| 2557 | |
| 2558 | if (delete_indices.size() == GetEntryCount() - 1U) { |
| 2559 | PruneAllButLastCommitted(); |
| 2560 | } else { |
| 2561 | // Do the deletion in reverse to preserve indices. |
Ayu Ishii | 2f82585 | 2022-03-08 19:47:38 | [diff] [blame] | 2562 | for (const auto& index : base::Reversed(delete_indices)) { |
| 2563 | RemoveEntryAtIndex(index); |
Christian Dullweber | 1af31e6 | 2018-02-22 11:49:48 | [diff] [blame] | 2564 | } |
Hayato Ito | 2c8c08d0 | 2021-06-23 03:38:43 | [diff] [blame] | 2565 | BroadcastHistoryOffsetAndLength(); |
Christian Dullweber | 1af31e6 | 2018-02-22 11:49:48 | [diff] [blame] | 2566 | } |
| 2567 | delegate()->NotifyNavigationEntriesDeleted(); |
| 2568 | } |
| 2569 | |
Shivani Sharma | 883f5f3 | 2019-02-12 18:20:01 | [diff] [blame] | 2570 | bool NavigationControllerImpl::IsEntryMarkedToBeSkipped(int index) { |
| 2571 | auto* entry = GetEntryAtIndex(index); |
| 2572 | return entry && entry->should_skip_on_back_forward_ui(); |
| 2573 | } |
| 2574 | |
Carlos Caballero | 35ce710c | 2019-09-19 10:59:45 | [diff] [blame] | 2575 | BackForwardCacheImpl& NavigationControllerImpl::GetBackForwardCache() { |
| 2576 | return back_forward_cache_; |
| 2577 | } |
| 2578 | |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2579 | void NavigationControllerImpl::DiscardPendingEntry(bool was_failure) { |
| 2580 | // It is not safe to call DiscardPendingEntry while NavigateToEntry is in |
| 2581 | // progress, since this will cause a use-after-free. (We only allow this |
| 2582 | // when the tab is being destroyed for shutdown, since it won't return to |
| 2583 | // NavigateToEntry in that case.) http://crbug.com/347742. |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 2584 | CHECK(!in_navigate_to_pending_entry_ || frame_tree_->IsBeingDestroyed()); |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2585 | |
| 2586 | if (was_failure && pending_entry_) { |
| 2587 | failed_pending_entry_id_ = pending_entry_->GetUniqueID(); |
| 2588 | } else { |
| 2589 | failed_pending_entry_id_ = 0; |
| 2590 | } |
| 2591 | |
| 2592 | if (pending_entry_) { |
| 2593 | if (pending_entry_index_ == -1) |
Paul Semel | 7e51469e | 2022-07-12 12:16:33 | [diff] [blame] | 2594 | pending_entry_.ClearAndDelete(); |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2595 | pending_entry_index_ = -1; |
| 2596 | pending_entry_ = nullptr; |
| 2597 | } |
arthursonzogni | 66f711c | 2019-10-08 14:40:36 | [diff] [blame] | 2598 | |
| 2599 | // Ensure any refs to the current pending entry are ignored if they get |
| 2600 | // deleted, by clearing the set of known refs. All future pending entries will |
| 2601 | // only be affected by new refs. |
| 2602 | pending_entry_refs_.clear(); |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2603 | } |
| 2604 | |
| 2605 | void NavigationControllerImpl::SetPendingNavigationSSLError(bool error) { |
| 2606 | if (pending_entry_) |
| 2607 | pending_entry_->set_ssl_error(error); |
| 2608 | } |
| 2609 | |
Xiaohan Wang | 7f8052e0 | 2022-01-14 18:44:28 | [diff] [blame] | 2610 | #if BUILDFLAG(IS_ANDROID) |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 2611 | // static |
| 2612 | bool NavigationControllerImpl::ValidateDataURLAsString( |
| 2613 | const scoped_refptr<const base::RefCountedString>& data_url_as_string) { |
| 2614 | if (!data_url_as_string) |
| 2615 | return false; |
| 2616 | |
| 2617 | if (data_url_as_string->size() > kMaxLengthOfDataURLString) |
| 2618 | return false; |
| 2619 | |
| 2620 | // The number of characters that is enough for validating a data: URI. |
| 2621 | // From the GURL's POV, the only important part here is scheme, it doesn't |
| 2622 | // check the actual content. Thus we can take only the prefix of the url, to |
| 2623 | // avoid unneeded copying of a potentially long string. |
| 2624 | const size_t kDataUriPrefixMaxLen = 64; |
| 2625 | GURL data_url( |
| 2626 | std::string(data_url_as_string->front_as<char>(), |
| 2627 | std::min(data_url_as_string->size(), kDataUriPrefixMaxLen))); |
| 2628 | if (!data_url.is_valid() || !data_url.SchemeIs(url::kDataScheme)) |
| 2629 | return false; |
| 2630 | |
| 2631 | return true; |
| 2632 | } |
| 2633 | #endif |
| 2634 | |
Shivani Sharma | 19487703 | 2019-03-07 17:52:47 | [diff] [blame] | 2635 | void NavigationControllerImpl::NotifyUserActivation() { |
| 2636 | // When a user activation occurs, ensure that all adjacent entries for the |
| 2637 | // same document clear their skippable bit, so that the history manipulation |
| 2638 | // intervention does not apply to them. |
| 2639 | auto* last_committed_entry = GetLastCommittedEntry(); |
| 2640 | if (!last_committed_entry) |
| 2641 | return; |
Shivani Sharma | 19487703 | 2019-03-07 17:52:47 | [diff] [blame] | 2642 | |
shivanigithub | 9936838 | 2021-06-16 18:33:37 | [diff] [blame] | 2643 | if (base::FeatureList::IsEnabled( |
| 2644 | features::kDebugHistoryInterventionNoUserActivation)) { |
| 2645 | return; |
| 2646 | } |
| 2647 | |
Shivani Sharma | c4cc892 | 2019-04-18 03:11:17 | [diff] [blame] | 2648 | SetSkippableForSameDocumentEntries(GetLastCommittedEntryIndex(), false); |
Shivani Sharma | 19487703 | 2019-03-07 17:52:47 | [diff] [blame] | 2649 | } |
| 2650 | |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2651 | bool NavigationControllerImpl::StartHistoryNavigationInNewSubframe( |
| 2652 | RenderFrameHostImpl* render_frame_host, |
Julie Jeongeun Kim | ed2e5ba7 | 2019-09-12 10:14:17 | [diff] [blame] | 2653 | mojo::PendingAssociatedRemote<mojom::NavigationClient>* navigation_client) { |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2654 | NavigationEntryImpl* entry = |
| 2655 | GetEntryWithUniqueID(render_frame_host->nav_entry_id()); |
| 2656 | if (!entry) |
| 2657 | return false; |
| 2658 | |
| 2659 | FrameNavigationEntry* frame_entry = |
| 2660 | entry->GetFrameEntry(render_frame_host->frame_tree_node()); |
| 2661 | if (!frame_entry) |
| 2662 | return false; |
| 2663 | |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 2664 | // |is_browser_initiated| is false here because a navigation in a new subframe |
| 2665 | // always begins with renderer action (i.e., an HTML element being inserted |
| 2666 | // into the DOM), so it is always renderer-initiated. |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 2667 | std::unique_ptr<NavigationRequest> request = CreateNavigationRequestFromEntry( |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2668 | render_frame_host->frame_tree_node(), entry, frame_entry, |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 2669 | ReloadType::NONE, false /* is_same_document_history_load */, |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 2670 | true /* is_history_navigation_in_new_child */, |
| 2671 | false /* is_browser_initiated */); |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 2672 | |
| 2673 | if (!request) |
| 2674 | return false; |
| 2675 | |
arthursonzogni | f046d4a | 2019-12-12 19:08:10 | [diff] [blame] | 2676 | request->SetNavigationClient(std::move(*navigation_client)); |
Arthur Hemery | 06173ce | 2019-05-29 12:11:41 | [diff] [blame] | 2677 | |
Lukasz Anforowicz | 9ee83c27 | 2020-12-01 20:14:05 | [diff] [blame] | 2678 | render_frame_host->frame_tree_node()->navigator().Navigate(std::move(request), |
| 2679 | ReloadType::NONE); |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 2680 | |
| 2681 | return true; |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2682 | } |
| 2683 | |
Tsuyoshi Horo | 52fd08e | 2020-07-07 07:03:45 | [diff] [blame] | 2684 | bool NavigationControllerImpl::ReloadFrame(FrameTreeNode* frame_tree_node) { |
| 2685 | NavigationEntryImpl* entry = GetEntryAtIndex(GetCurrentEntryIndex()); |
| 2686 | if (!entry) |
| 2687 | return false; |
Rakina Zata Amni | f297a80 | 2022-01-18 03:53:43 | [diff] [blame] | 2688 | |
| 2689 | if (entry->IsInitialEntryNotForSynchronousAboutBlank()) { |
| 2690 | // We should never navigate to an existing initial NavigationEntry that is |
| 2691 | // the initial NavigationEntry for the initial empty document that hasn't |
| 2692 | // been overridden by the synchronous about:blank commit, to preserve |
| 2693 | // legacy behavior where trying to reload when the main frame is on the |
| 2694 | // initial empty document won't result in a navigation. See also |
| 2695 | // https://crbug.com/1277414. |
| 2696 | return false; |
| 2697 | } |
Tsuyoshi Horo | 52fd08e | 2020-07-07 07:03:45 | [diff] [blame] | 2698 | FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame_tree_node); |
| 2699 | if (!frame_entry) |
| 2700 | return false; |
John Abd-El-Malek | 5b66913 | 2020-07-14 01:04:14 | [diff] [blame] | 2701 | ReloadType reload_type = ReloadType::NORMAL; |
| 2702 | entry->set_reload_type(reload_type); |
Tsuyoshi Horo | 52fd08e | 2020-07-07 07:03:45 | [diff] [blame] | 2703 | std::unique_ptr<NavigationRequest> request = CreateNavigationRequestFromEntry( |
John Abd-El-Malek | 5b66913 | 2020-07-14 01:04:14 | [diff] [blame] | 2704 | frame_tree_node, entry, frame_entry, reload_type, |
Tsuyoshi Horo | 52fd08e | 2020-07-07 07:03:45 | [diff] [blame] | 2705 | false /* is_same_document_history_load */, |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 2706 | false /* is_history_navigation_in_new_child */, |
| 2707 | true /* is_browser_initiated */); |
Tsuyoshi Horo | 52fd08e | 2020-07-07 07:03:45 | [diff] [blame] | 2708 | if (!request) |
| 2709 | return false; |
Lukasz Anforowicz | 9ee83c27 | 2020-12-01 20:14:05 | [diff] [blame] | 2710 | frame_tree_node->navigator().Navigate(std::move(request), reload_type); |
Tsuyoshi Horo | 52fd08e | 2020-07-07 07:03:45 | [diff] [blame] | 2711 | return true; |
| 2712 | } |
| 2713 | |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2714 | void NavigationControllerImpl::NavigateFromFrameProxy( |
| 2715 | RenderFrameHostImpl* render_frame_host, |
| 2716 | const GURL& url, |
Chris Hamilton | 83272dc | 2021-02-23 00:24:02 | [diff] [blame] | 2717 | const blink::LocalFrameToken* initiator_frame_token, |
Antonio Sartori | 9a82f6f3 | 2020-12-14 09:22:45 | [diff] [blame] | 2718 | int initiator_process_id, |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 2719 | const absl::optional<url::Origin>& initiator_origin, |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2720 | bool is_renderer_initiated, |
| 2721 | SiteInstance* source_site_instance, |
| 2722 | const Referrer& referrer, |
| 2723 | ui::PageTransition page_transition, |
| 2724 | bool should_replace_current_entry, |
Yeunjoo Choi | 3df791a | 2021-02-17 07:07:25 | [diff] [blame] | 2725 | blink::NavigationDownloadPolicy download_policy, |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2726 | const std::string& method, |
| 2727 | scoped_refptr<network::ResourceRequestBody> post_body, |
Marijn Kruisselbrink | 7a0d5e18 | 2018-05-24 22:55:09 | [diff] [blame] | 2728 | const std::string& extra_headers, |
Antonio Sartori | 2f763d9d | 2021-04-21 10:04:14 | [diff] [blame] | 2729 | network::mojom::SourceLocationPtr source_location, |
John Delaney | 50425f8 | 2020-04-07 16:26:21 | [diff] [blame] | 2730 | scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory, |
jongdeok.kim | 5de823b3 | 2022-06-14 04:37:50 | [diff] [blame] | 2731 | bool is_form_submission, |
Tsuyoshi Horo | 167ca643 | 2022-03-09 05:16:39 | [diff] [blame] | 2732 | const absl::optional<blink::Impression>& impression, |
Nan Lin | 944e9b4e | 2022-04-12 13:51:22 | [diff] [blame] | 2733 | base::TimeTicks navigation_start_time, |
Garrett Tanzer | 405f340 | 2022-07-21 20:12:49 | [diff] [blame] | 2734 | bool is_embedder_initiated_fenced_frame_navigation, |
Garrett Tanzer | bb8db41 | 2022-09-27 21:59:46 | [diff] [blame] | 2735 | bool is_unfenced_top_navigation, |
| 2736 | bool force_new_browsing_instance) { |
Lukasz Anforowicz | 63f3b943 | 2019-05-30 05:42:58 | [diff] [blame] | 2737 | if (is_renderer_initiated) |
| 2738 | DCHECK(initiator_origin.has_value()); |
| 2739 | |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2740 | FrameTreeNode* node = render_frame_host->frame_tree_node(); |
Nasko Oskov | 18006bc | 2018-12-06 02:53:58 | [diff] [blame] | 2741 | |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 2742 | // Don't allow an entry replacement if there is no entry to replace. |
| 2743 | // http://crbug.com/457149 |
| 2744 | if (GetEntryCount() == 0) |
| 2745 | should_replace_current_entry = false; |
| 2746 | |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2747 | // Create a NavigationEntry for the transfer, without making it the pending |
| 2748 | // entry. Subframe transfers should have a clone of the last committed entry |
| 2749 | // with a FrameNavigationEntry for the target frame. Main frame transfers |
| 2750 | // should have a new NavigationEntry. |
| 2751 | // TODO(creis): Make this unnecessary by creating (and validating) the params |
| 2752 | // directly, passing them to the destination RenderFrameHost. See |
| 2753 | // https://crbug.com/536906. |
| 2754 | std::unique_ptr<NavigationEntryImpl> entry; |
Harkiran Bolaria | e1b5158b | 2021-09-16 19:03:26 | [diff] [blame] | 2755 | if (!render_frame_host->is_main_frame()) { |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2756 | // Subframe case: create FrameNavigationEntry. |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 2757 | if (GetLastCommittedEntry()) { |
| 2758 | entry = GetLastCommittedEntry()->Clone(); |
| 2759 | entry->set_extra_headers(extra_headers); |
| 2760 | // TODO(arthursonzogni): What about |is_renderer_initiated|? |
| 2761 | // Renderer-initiated navigation that target a remote frame are currently |
| 2762 | // classified as browser-initiated when this one has already navigated. |
| 2763 | // See https://crbug.com/722251. |
| 2764 | } else { |
| 2765 | // If there's no last committed entry, create an entry for about:blank |
| 2766 | // with a subframe entry for our destination. |
| 2767 | // TODO(creis): Ensure this case can't exist in https://crbug.com/524208. |
| 2768 | entry = NavigationEntryImpl::FromNavigationEntry(CreateNavigationEntry( |
| 2769 | GURL(url::kAboutBlankURL), referrer, initiator_origin, |
| 2770 | source_site_instance, page_transition, is_renderer_initiated, |
| 2771 | extra_headers, browser_context_, |
Julie Jeongeun Kim | 5b9aff7 | 2022-05-02 02:10:17 | [diff] [blame] | 2772 | nullptr /* blob_url_loader_factory */, |
| 2773 | false /* rewrite_virtual_urls */)); |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 2774 | } |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 2775 | // TODO(arthursonzogni): What about |is_renderer_initiated|? |
| 2776 | // Renderer-initiated navigation that target a remote frame are currently |
| 2777 | // classified as browser-initiated when this one has already navigated. |
| 2778 | // See https://crbug.com/722251. |
Nate Chapin | 9f16907 | 2021-06-09 19:32:37 | [diff] [blame] | 2779 | // The UpdatePolicy doesn't matter here. |entry| is only used as a parameter |
| 2780 | // to CreateNavigationRequestFromLoadParams(), so while kReplace might |
| 2781 | // remove child FrameNavigationEntries (e.g., if this is a cross-process |
| 2782 | // same-document navigation), they will still be present in the |
| 2783 | // committed NavigationEntry that will be referenced to construct the new |
| 2784 | // FrameNavigationEntry tree when this navigation commits. |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2785 | entry->AddOrUpdateFrameEntry( |
Nate Chapin | fbfe5af | 2021-06-10 17:22:08 | [diff] [blame] | 2786 | node, NavigationEntryImpl::UpdatePolicy::kReplace, -1, -1, "", nullptr, |
Nasko Oskov | 18006bc | 2018-12-06 02:53:58 | [diff] [blame] | 2787 | static_cast<SiteInstanceImpl*>(source_site_instance), url, |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 2788 | absl::nullopt /* commit_origin */, referrer, initiator_origin, |
Miyoung Shin | 5d77f7207 | 2020-10-09 15:14:20 | [diff] [blame] | 2789 | std::vector<GURL>(), blink::PageState(), method, -1, |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 2790 | blob_url_loader_factory, nullptr /* web_bundle_navigation_info */, |
Kunihiko Sakamoto | 346a74e | 2021-03-10 08:57:48 | [diff] [blame] | 2791 | nullptr /* subresource_web_bundle_navigation_info */, |
Antonio Sartori | 79d549d | 2021-02-18 12:59:54 | [diff] [blame] | 2792 | nullptr /* policy_container_policies */); |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2793 | } else { |
| 2794 | // Main frame case. |
Julie Jeongeun Kim | 5b9aff7 | 2022-05-02 02:10:17 | [diff] [blame] | 2795 | // If `node` is the outermost main frame, it rewrites a virtual url in order |
| 2796 | // to adjust the original input url if needed. For inner frames such as |
| 2797 | // fenced frames or subframes, they don't rewrite urls as the urls are not |
| 2798 | // input urls by users. |
| 2799 | bool rewrite_virtual_urls = node->IsOutermostMainFrame(); |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2800 | entry = NavigationEntryImpl::FromNavigationEntry(CreateNavigationEntry( |
Lukasz Anforowicz | 641234d5 | 2019-11-07 21:07:10 | [diff] [blame] | 2801 | url, referrer, initiator_origin, source_site_instance, page_transition, |
| 2802 | is_renderer_initiated, extra_headers, browser_context_, |
Julie Jeongeun Kim | 5b9aff7 | 2022-05-02 02:10:17 | [diff] [blame] | 2803 | blob_url_loader_factory, rewrite_virtual_urls)); |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2804 | entry->root_node()->frame_entry->set_source_site_instance( |
| 2805 | static_cast<SiteInstanceImpl*>(source_site_instance)); |
| 2806 | entry->root_node()->frame_entry->set_method(method); |
| 2807 | } |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2808 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 2809 | bool override_user_agent = false; |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2810 | if (GetLastCommittedEntry() && |
| 2811 | GetLastCommittedEntry()->GetIsOverridingUserAgent()) { |
| 2812 | entry->SetIsOverridingUserAgent(true); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 2813 | override_user_agent = true; |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2814 | } |
| 2815 | // TODO(creis): Set user gesture and intent received timestamp on Android. |
| 2816 | |
| 2817 | // We may not have successfully added the FrameNavigationEntry to |entry| |
| 2818 | // above (per https://crbug.com/608402), in which case we create it from |
| 2819 | // scratch. This works because we do not depend on |frame_entry| being inside |
| 2820 | // |entry| during NavigateToEntry. This will go away when we shortcut this |
| 2821 | // further in https://crbug.com/536906. |
| 2822 | scoped_refptr<FrameNavigationEntry> frame_entry(entry->GetFrameEntry(node)); |
| 2823 | if (!frame_entry) { |
Patrick Monette | 50e8bd8 | 2019-06-13 22:40:45 | [diff] [blame] | 2824 | frame_entry = base::MakeRefCounted<FrameNavigationEntry>( |
Nate Chapin | fbfe5af | 2021-06-10 17:22:08 | [diff] [blame] | 2825 | node->unique_name(), -1, -1, "", nullptr, |
Nasko Oskov | 18006bc | 2018-12-06 02:53:58 | [diff] [blame] | 2826 | static_cast<SiteInstanceImpl*>(source_site_instance), url, |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 2827 | absl::nullopt /* origin */, referrer, initiator_origin, |
Rakina Zata Amni | 3a1c0ec | 2021-04-15 03:35:12 | [diff] [blame] | 2828 | std::vector<GURL>(), blink::PageState(), method, -1, |
| 2829 | blob_url_loader_factory, nullptr /* web_bundle_navigation_info */, |
Kunihiko Sakamoto | 346a74e | 2021-03-10 08:57:48 | [diff] [blame] | 2830 | nullptr /* subresource_web_bundle_navigation_info */, |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 2831 | nullptr /* policy_container_policies */, |
Domenic Denicola | cc094fb | 2022-03-16 23:40:57 | [diff] [blame] | 2832 | false /* protect_url_in_navigation_api */); |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2833 | } |
| 2834 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 2835 | LoadURLParams params(url); |
Chris Hamilton | 83272dc | 2021-02-23 00:24:02 | [diff] [blame] | 2836 | params.initiator_frame_token = base::OptionalFromPtr(initiator_frame_token); |
Antonio Sartori | 9a82f6f3 | 2020-12-14 09:22:45 | [diff] [blame] | 2837 | params.initiator_process_id = initiator_process_id; |
Nasko Oskov | 93e7c55c | 2018-12-19 01:59:29 | [diff] [blame] | 2838 | params.initiator_origin = initiator_origin; |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 2839 | params.source_site_instance = source_site_instance; |
| 2840 | params.load_type = method == "POST" ? LOAD_TYPE_HTTP_POST : LOAD_TYPE_DEFAULT; |
| 2841 | params.transition_type = page_transition; |
Dominic Farolino | 226226af | 2019-06-25 00:58:03 | [diff] [blame] | 2842 | params.frame_tree_node_id = node->frame_tree_node_id(); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 2843 | params.referrer = referrer; |
| 2844 | /* params.redirect_chain: skip */ |
| 2845 | params.extra_headers = extra_headers; |
| 2846 | params.is_renderer_initiated = is_renderer_initiated; |
| 2847 | params.override_user_agent = UA_OVERRIDE_INHERIT; |
| 2848 | /* params.base_url_for_data_url: skip */ |
| 2849 | /* params.virtual_url_for_data_url: skip */ |
| 2850 | /* params.data_url_as_string: skip */ |
| 2851 | params.post_data = post_body; |
| 2852 | params.can_load_local_resources = false; |
Kevin McNee | e60e76b | 2019-11-27 20:01:58 | [diff] [blame] | 2853 | /* params.should_replace_current_entry: skip */ |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 2854 | /* params.frame_name: skip */ |
| 2855 | // TODO(clamy): See if user gesture should be propagated to this function. |
| 2856 | params.has_user_gesture = false; |
| 2857 | params.should_clear_history_list = false; |
| 2858 | params.started_from_context_menu = false; |
| 2859 | /* params.navigation_ui_data: skip */ |
| 2860 | /* params.input_start: skip */ |
Minggang Wang | f59db47b | 2021-06-16 01:56:22 | [diff] [blame] | 2861 | params.was_activated = blink::mojom::WasActivatedOption::kUnknown; |
Robert Ogden | 011a808 | 2019-01-23 19:04:54 | [diff] [blame] | 2862 | /* params.reload_type: skip */ |
John Delaney | 50425f8 | 2020-04-07 16:26:21 | [diff] [blame] | 2863 | params.impression = impression; |
Antonio Sartori | 6984c74 | 2021-08-26 08:03:41 | [diff] [blame] | 2864 | params.download_policy = std::move(download_policy); |
jongdeok.kim | 5de823b3 | 2022-06-14 04:37:50 | [diff] [blame] | 2865 | params.is_form_submission = is_form_submission; |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 2866 | |
| 2867 | std::unique_ptr<NavigationRequest> request = |
| 2868 | CreateNavigationRequestFromLoadParams( |
Dominic Farolino | 226226af | 2019-06-25 00:58:03 | [diff] [blame] | 2869 | node, params, override_user_agent, should_replace_current_entry, |
Antonio Sartori | 2f763d9d | 2021-04-21 10:04:14 | [diff] [blame] | 2870 | false /* has_user_gesture */, std::move(source_location), |
Tsuyoshi Horo | 167ca643 | 2022-03-09 05:16:39 | [diff] [blame] | 2871 | ReloadType::NONE, entry.get(), frame_entry.get(), |
Garrett Tanzer | 405f340 | 2022-07-21 20:12:49 | [diff] [blame] | 2872 | navigation_start_time, is_embedder_initiated_fenced_frame_navigation, |
| 2873 | is_unfenced_top_navigation); |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 2874 | |
| 2875 | if (!request) |
| 2876 | return; |
| 2877 | |
Garrett Tanzer | bb8db41 | 2022-09-27 21:59:46 | [diff] [blame] | 2878 | // Force the navigation to take place in a new browsing instance. |
| 2879 | // This is used by _unfencedTop in fenced frames to ensure that navigations |
| 2880 | // leaving the fenced context create a new browsing instance. |
| 2881 | if (force_new_browsing_instance) { |
| 2882 | request->coop_status().ForceBrowsingInstanceSwap(); |
| 2883 | } |
| 2884 | |
Arthur Hemery | 94874276 | 2019-09-18 10:06:24 | [diff] [blame] | 2885 | // At this stage we are proceeding with this navigation. If this was renderer |
| 2886 | // initiated with user gesture, we need to make sure we clear up potential |
| 2887 | // remains of a cancelled browser initiated navigation to avoid URL spoofs. |
| 2888 | DiscardNonCommittedEntries(); |
| 2889 | |
Lukasz Anforowicz | 9ee83c27 | 2020-12-01 20:14:05 | [diff] [blame] | 2890 | node->navigator().Navigate(std::move(request), ReloadType::NONE); |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2891 | } |
| 2892 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2893 | void NavigationControllerImpl::SetSessionStorageNamespace( |
Alex Moshchuk | 8015afcf | 2022-01-31 22:59:25 | [diff] [blame] | 2894 | const StoragePartitionConfig& partition_config, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 2895 | SessionStorageNamespace* session_storage_namespace) { |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2896 | if (!session_storage_namespace) |
| 2897 | return; |
| 2898 | |
| 2899 | // We can't overwrite an existing SessionStorage without violating spec. |
| 2900 | // Attempts to do so may give a tab access to another tab's session storage |
| 2901 | // so die hard on an error. |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 2902 | bool successful_insert = |
| 2903 | session_storage_namespace_map_ |
Alex Moshchuk | 8015afcf | 2022-01-31 22:59:25 | [diff] [blame] | 2904 | .insert(std::make_pair(partition_config, |
Aaron Colwell | f3b316e | 2021-03-11 20:17:05 | [diff] [blame] | 2905 | static_cast<SessionStorageNamespaceImpl*>( |
| 2906 | session_storage_namespace))) |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 2907 | .second; |
| 2908 | CHECK(successful_insert) << "Cannot replace existing SessionStorageNamespace"; |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2909 | } |
| 2910 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2911 | bool NavigationControllerImpl::IsUnmodifiedBlankTab() { |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 2912 | return IsInitialNavigation() && |
| 2913 | (!GetLastCommittedEntry() || |
| 2914 | GetLastCommittedEntry()->IsInitialEntry()) && |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 2915 | !frame_tree_->has_accessed_initial_main_document(); |
[email protected] | aa62afd | 2014-04-22 19:22:46 | [diff] [blame] | 2916 | } |
| 2917 | |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 2918 | SessionStorageNamespace* NavigationControllerImpl::GetSessionStorageNamespace( |
Alex Moshchuk | 8015afcf | 2022-01-31 22:59:25 | [diff] [blame] | 2919 | const StoragePartitionConfig& partition_config) { |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 2920 | StoragePartition* partition = |
Lukasz Anforowicz | b9a969a | 2021-04-29 15:26:25 | [diff] [blame] | 2921 | browser_context_->GetStoragePartition(partition_config); |
michaeln | bacbcbd | 2016-02-09 00:32:03 | [diff] [blame] | 2922 | DOMStorageContextWrapper* context_wrapper = |
| 2923 | static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext()); |
| 2924 | |
| 2925 | SessionStorageNamespaceMap::const_iterator it = |
Alex Moshchuk | 8015afcf | 2022-01-31 22:59:25 | [diff] [blame] | 2926 | session_storage_namespace_map_.find(partition_config); |
michaeln | bacbcbd | 2016-02-09 00:32:03 | [diff] [blame] | 2927 | if (it != session_storage_namespace_map_.end()) { |
| 2928 | // Ensure that this namespace actually belongs to this partition. |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 2929 | DCHECK(static_cast<SessionStorageNamespaceImpl*>(it->second.get()) |
| 2930 | ->IsFromContext(context_wrapper)); |
Aaron Colwell | b731a0ae | 2021-03-19 19:14:47 | [diff] [blame] | 2931 | |
michaeln | bacbcbd | 2016-02-09 00:32:03 | [diff] [blame] | 2932 | return it->second.get(); |
| 2933 | } |
| 2934 | |
| 2935 | // Create one if no one has accessed session storage for this partition yet. |
Daniel Murphy | 31bbb8b1 | 2018-02-07 21:44:10 | [diff] [blame] | 2936 | scoped_refptr<SessionStorageNamespaceImpl> session_storage_namespace = |
| 2937 | SessionStorageNamespaceImpl::Create(context_wrapper); |
| 2938 | SessionStorageNamespaceImpl* session_storage_namespace_ptr = |
| 2939 | session_storage_namespace.get(); |
Alex Moshchuk | 8015afcf | 2022-01-31 22:59:25 | [diff] [blame] | 2940 | session_storage_namespace_map_[partition_config] = |
Daniel Murphy | 31bbb8b1 | 2018-02-07 21:44:10 | [diff] [blame] | 2941 | std::move(session_storage_namespace); |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 2942 | |
Daniel Murphy | 31bbb8b1 | 2018-02-07 21:44:10 | [diff] [blame] | 2943 | return session_storage_namespace_ptr; |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 2944 | } |
| 2945 | |
| 2946 | SessionStorageNamespace* |
| 2947 | NavigationControllerImpl::GetDefaultSessionStorageNamespace() { |
Alex Moshchuk | 8015afcf | 2022-01-31 22:59:25 | [diff] [blame] | 2948 | return GetSessionStorageNamespace( |
| 2949 | StoragePartitionConfig::CreateDefault(GetBrowserContext())); |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 2950 | } |
| 2951 | |
| 2952 | const SessionStorageNamespaceMap& |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2953 | NavigationControllerImpl::GetSessionStorageNamespaceMap() { |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 2954 | return session_storage_namespace_map_; |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 2955 | } |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 2956 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2957 | bool NavigationControllerImpl::NeedsReload() { |
[email protected] | 71fde35 | 2011-12-29 03:29:56 | [diff] [blame] | 2958 | return needs_reload_; |
| 2959 | } |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 2960 | |
[email protected] | 46bb5e9c | 2013-10-03 22:16:47 | [diff] [blame] | 2961 | void NavigationControllerImpl::SetNeedsReload() { |
Alex Moshchuk | 7b4f065 | 2019-05-30 18:54:41 | [diff] [blame] | 2962 | SetNeedsReload(NeedsReloadType::kRequestedByClient); |
| 2963 | } |
| 2964 | |
| 2965 | void NavigationControllerImpl::SetNeedsReload(NeedsReloadType type) { |
[email protected] | 46bb5e9c | 2013-10-03 22:16:47 | [diff] [blame] | 2966 | needs_reload_ = true; |
Alex Moshchuk | 7b4f065 | 2019-05-30 18:54:41 | [diff] [blame] | 2967 | needs_reload_type_ = type; |
jaekyun | c8cefa8 | 2015-01-09 20:14:54 | [diff] [blame] | 2968 | |
| 2969 | if (last_committed_entry_index_ != -1) { |
| 2970 | entries_[last_committed_entry_index_]->SetTransitionType( |
| 2971 | ui::PAGE_TRANSITION_RELOAD); |
| 2972 | } |
[email protected] | 46bb5e9c | 2013-10-03 22:16:47 | [diff] [blame] | 2973 | } |
| 2974 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 2975 | void NavigationControllerImpl::RemoveEntryAtIndexInternal(int index) { |
Kevin McNee | 0516477 | 2019-09-03 17:24:57 | [diff] [blame] | 2976 | DCHECK_LT(index, GetEntryCount()); |
| 2977 | DCHECK_NE(index, last_committed_entry_index_); |
[email protected] | 4303234 | 2011-03-21 14:10:31 | [diff] [blame] | 2978 | DiscardNonCommittedEntries(); |
| 2979 | |
Nate Chapin | 9eb16be7 | 2022-09-23 22:54:31 | [diff] [blame] | 2980 | RemovedEntriesTracker tracker(weak_factory_.GetSafeRef()); |
[email protected] | 4303234 | 2011-03-21 14:10:31 | [diff] [blame] | 2981 | entries_.erase(entries_.begin() + index); |
[email protected] | 6a13a6c | 2011-12-20 21:47:12 | [diff] [blame] | 2982 | if (last_committed_entry_index_ > index) |
[email protected] | 4303234 | 2011-03-21 14:10:31 | [diff] [blame] | 2983 | last_committed_entry_index_--; |
| 2984 | } |
| 2985 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2986 | NavigationEntryImpl* NavigationControllerImpl::GetPendingEntry() { |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 2987 | // If there is no pending_entry_, there should be no pending_entry_index_. |
| 2988 | DCHECK(pending_entry_ || pending_entry_index_ == -1); |
| 2989 | |
| 2990 | // If there is a pending_entry_index_, then pending_entry_ must be the entry |
Carlos IL | 42b41659 | 2019-10-07 23:10:36 | [diff] [blame] | 2991 | // at that index. An exception is while a reload of a post commit error page |
| 2992 | // is ongoing; in that case pending entry will point to the entry replaced |
| 2993 | // by the error. |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 2994 | DCHECK(pending_entry_index_ == -1 || |
Carlos IL | 42b41659 | 2019-10-07 23:10:36 | [diff] [blame] | 2995 | pending_entry_ == GetEntryAtIndex(pending_entry_index_) || |
| 2996 | pending_entry_ == entry_replaced_by_post_commit_error_.get()); |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 2997 | |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 2998 | return pending_entry_; |
| 2999 | } |
| 3000 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 3001 | int NavigationControllerImpl::GetPendingEntryIndex() { |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 3002 | // The pending entry index must always be less than the number of entries. |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 3003 | // If there are no entries, it must be exactly -1. |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 3004 | DCHECK_LT(pending_entry_index_, GetEntryCount()); |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 3005 | DCHECK(GetEntryCount() != 0 || pending_entry_index_ == -1); |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 3006 | return pending_entry_index_; |
| 3007 | } |
| 3008 | |
avi | 2576470 | 2015-06-23 15:43:37 | [diff] [blame] | 3009 | void NavigationControllerImpl::InsertOrReplaceEntry( |
dcheng | 9bfa516 | 2016-04-09 01:00:57 | [diff] [blame] | 3010 | std::unique_ptr<NavigationEntryImpl> entry, |
Carlos IL | 42b41659 | 2019-10-07 23:10:36 | [diff] [blame] | 3011 | bool replace, |
Dave Tapuska | 87696ae | 2021-11-18 18:48:31 | [diff] [blame] | 3012 | bool was_post_commit_error, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 3013 | bool in_fenced_frame_tree, |
| 3014 | LoadCommittedDetails* commit_details) { |
Dave Tapuska | 87696ae | 2021-11-18 18:48:31 | [diff] [blame] | 3015 | // Fenced frame trees should always have `ui::PAGE_TRANSITION_AUTO_SUBFRAME` |
| 3016 | // set because: |
| 3017 | // 1) They don't influence the history of the outer page. |
| 3018 | // 2) They are always replace only navigation (there is always only one entry |
| 3019 | // in their history stack). |
| 3020 | // 3) Are not top level navigations and appear similar to iframes. |
| 3021 | // Navigations of the fenced frame might create a new NavigationEntry, which |
| 3022 | // will call this function. Non fenced frame navigations will never have |
| 3023 | // `ui::PAGE_TRANSITION_AUTO_SUBFRAME` because they won't call |
| 3024 | // InsertOrReplaceEntry. |
| 3025 | DCHECK_EQ(in_fenced_frame_tree, |
| 3026 | ui::PageTransitionCoreTypeIs(entry->GetTransitionType(), |
| 3027 | ui::PAGE_TRANSITION_AUTO_SUBFRAME)); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 3028 | |
avi | 5cad491 | 2015-06-19 05:25:44 | [diff] [blame] | 3029 | // If the pending_entry_index_ is -1, the navigation was to a new page, and we |
| 3030 | // need to keep continuity with the pending entry, so copy the pending entry's |
| 3031 | // unique ID to the committed entry. If the pending_entry_index_ isn't -1, |
| 3032 | // then the renderer navigated on its own, independent of the pending entry, |
| 3033 | // so don't copy anything. |
| 3034 | if (pending_entry_ && pending_entry_index_ == -1) |
| 3035 | entry->set_unique_id(pending_entry_->GetUniqueID()); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 3036 | |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 3037 | DiscardNonCommittedEntriesWithCommitDetails(commit_details); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 3038 | |
creis | ee17e93 | 2015-07-17 17:56:22 | [diff] [blame] | 3039 | // When replacing, don't prune the forward history. |
Carlos IL | 42b41659 | 2019-10-07 23:10:36 | [diff] [blame] | 3040 | if ((replace || was_post_commit_error) && entries_.size() > 0) { |
Mikel Astiz | ba9cf2fd | 2017-12-17 10:38:10 | [diff] [blame] | 3041 | CopyReplacedNavigationEntryDataIfPreviouslyEmpty( |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 3042 | entries_[last_committed_entry_index_].get(), entry.get()); |
Carlos IL | 42b41659 | 2019-10-07 23:10:36 | [diff] [blame] | 3043 | // If the new entry is a post-commit error page, we store the current last |
| 3044 | // committed entry to the side so that we can put it back when navigating |
| 3045 | // away from the error. |
| 3046 | if (was_post_commit_error) { |
| 3047 | DCHECK(!entry_replaced_by_post_commit_error_); |
| 3048 | entry_replaced_by_post_commit_error_ = |
| 3049 | std::move(entries_[last_committed_entry_index_]); |
| 3050 | } |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame] | 3051 | entries_[last_committed_entry_index_] = std::move(entry); |
creis | ee17e93 | 2015-07-17 17:56:22 | [diff] [blame] | 3052 | return; |
| 3053 | } |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 3054 | |
creis | 37979a6 | 2015-08-04 19:48:18 | [diff] [blame] | 3055 | // We shouldn't see replace == true when there's no committed entries. |
| 3056 | DCHECK(!replace); |
| 3057 | |
Michael Thiessen | 9b14d51 | 2019-09-23 21:19:47 | [diff] [blame] | 3058 | PruneForwardEntries(); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 3059 | |
Shivani Sharma | d8c8d65 | 2019-02-13 17:27:57 | [diff] [blame] | 3060 | PruneOldestSkippableEntryIfFull(); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 3061 | |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame] | 3062 | entries_.push_back(std::move(entry)); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 3063 | last_committed_entry_index_ = static_cast<int>(entries_.size()) - 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3064 | } |
| 3065 | |
Shivani Sharma | d8c8d65 | 2019-02-13 17:27:57 | [diff] [blame] | 3066 | void NavigationControllerImpl::PruneOldestSkippableEntryIfFull() { |
Shivani Sharma | 2d5b4b6b | 2019-01-08 16:07:16 | [diff] [blame] | 3067 | if (entries_.size() < max_entry_count()) |
| 3068 | return; |
| 3069 | |
| 3070 | DCHECK_EQ(max_entry_count(), entries_.size()); |
| 3071 | DCHECK_GT(last_committed_entry_index_, 0); |
Shivani Sharma | d8c8d65 | 2019-02-13 17:27:57 | [diff] [blame] | 3072 | CHECK_EQ(pending_entry_index_, -1); |
| 3073 | |
| 3074 | int index = 0; |
Elly Fong-Jones | ccc6d1f | 2021-06-14 18:32:42 | [diff] [blame] | 3075 | // Retrieve the oldest skippable entry. |
| 3076 | for (; index < GetEntryCount(); index++) { |
| 3077 | if (GetEntryAtIndex(index)->should_skip_on_back_forward_ui()) |
| 3078 | break; |
Shivani Sharma | d8c8d65 | 2019-02-13 17:27:57 | [diff] [blame] | 3079 | } |
| 3080 | |
| 3081 | // If there is no skippable entry or if it is the last committed entry then |
| 3082 | // fall back to pruning the oldest entry. It is not safe to prune the last |
| 3083 | // committed entry. |
| 3084 | if (index == GetEntryCount() || index == last_committed_entry_index_) |
| 3085 | index = 0; |
| 3086 | |
| 3087 | bool should_succeed = RemoveEntryAtIndex(index); |
| 3088 | DCHECK_EQ(true, should_succeed); |
| 3089 | |
| 3090 | NotifyPrunedEntries(this, index, 1); |
[email protected] | 944822b | 2012-03-02 20:57:25 | [diff] [blame] | 3091 | } |
| 3092 | |
clamy | 3cb9bea9 | 2018-07-10 12:42:02 | [diff] [blame] | 3093 | void NavigationControllerImpl::NavigateToExistingPendingEntry( |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 3094 | ReloadType reload_type, |
Nate Chapin | bf682fa3 | 2022-09-26 22:41:20 | [diff] [blame] | 3095 | RenderFrameHostImpl* initiator_rfh, |
| 3096 | const std::string* navigation_api_key) { |
Alexander Timin | 3a92df7 | 2019-09-20 11:59:50 | [diff] [blame] | 3097 | TRACE_EVENT0("navigation", |
| 3098 | "NavigationControllerImpl::NavigateToExistingPendingEntry"); |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 3099 | DCHECK(pending_entry_); |
clamy | 3cb9bea9 | 2018-07-10 12:42:02 | [diff] [blame] | 3100 | DCHECK(IsInitialNavigation() || pending_entry_index_ != -1); |
Carlos IL | 42b41659 | 2019-10-07 23:10:36 | [diff] [blame] | 3101 | if (pending_entry_index_ != -1) { |
| 3102 | // The pending entry may not be in entries_ if a post-commit error page is |
| 3103 | // showing. |
| 3104 | DCHECK(pending_entry_ == entries_[pending_entry_index_].get() || |
| 3105 | pending_entry_ == entry_replaced_by_post_commit_error_.get()); |
| 3106 | } |
Gyuyoung Kim | 107c2a0 | 2021-04-13 01:49:30 | [diff] [blame] | 3107 | DCHECK(!blink::IsRendererDebugURL(pending_entry_->GetURL())); |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3108 | bool is_forced_reload = needs_reload_; |
[email protected] | 72097fd0 | 2010-01-21 23:36:01 | [diff] [blame] | 3109 | needs_reload_ = false; |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 3110 | FrameTreeNode* root = frame_tree_->root(); |
Arthur Sonzogni | 620cec6 | 2018-12-13 13:08:57 | [diff] [blame] | 3111 | int nav_entry_id = pending_entry_->GetUniqueID(); |
Nate Chapin | bf682fa3 | 2022-09-26 22:41:20 | [diff] [blame] | 3112 | bool is_browser_initiated = !initiator_rfh; |
Arthur Sonzogni | 620cec6 | 2018-12-13 13:08:57 | [diff] [blame] | 3113 | |
[email protected] | 83c2e23 | 2011-10-07 21:36:46 | [diff] [blame] | 3114 | // If we were navigating to a slow-to-commit page, and the user performs |
| 3115 | // a session history navigation to the last committed page, RenderViewHost |
| 3116 | // will force the throbber to start, but WebKit will essentially ignore the |
| 3117 | // navigation, and won't send a message to stop the throbber. To prevent this |
| 3118 | // from happening, we drop the navigation here and stop the slow-to-commit |
| 3119 | // page from loading (which would normally happen during the navigation). |
clamy | 3cb9bea9 | 2018-07-10 12:42:02 | [diff] [blame] | 3120 | if (pending_entry_index_ == last_committed_entry_index_ && |
Lukasz Anforowicz | 6b75c0d | 2020-12-01 22:56:08 | [diff] [blame] | 3121 | !pending_entry_->IsRestored() && |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 3122 | pending_entry_->GetTransitionType() & ui::PAGE_TRANSITION_FORWARD_BACK) { |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 3123 | frame_tree_->StopLoading(); |
[email protected] | 6a13a6c | 2011-12-20 21:47:12 | [diff] [blame] | 3124 | |
[email protected] | 83c2e23 | 2011-10-07 21:36:46 | [diff] [blame] | 3125 | DiscardNonCommittedEntries(); |
| 3126 | return; |
| 3127 | } |
| 3128 | |
creis | ce0ef357 | 2017-01-26 17:53:08 | [diff] [blame] | 3129 | // Compare FrameNavigationEntries to see which frames in the tree need to be |
| 3130 | // navigated. |
clamy | 3cb9bea9 | 2018-07-10 12:42:02 | [diff] [blame] | 3131 | std::vector<std::unique_ptr<NavigationRequest>> same_document_loads; |
| 3132 | std::vector<std::unique_ptr<NavigationRequest>> different_document_loads; |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 3133 | FindFramesToNavigate(root, reload_type, is_browser_initiated, |
| 3134 | &same_document_loads, &different_document_loads); |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 3135 | |
| 3136 | if (same_document_loads.empty() && different_document_loads.empty()) { |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3137 | // We were unable to match any frames to navigate. This can happen if a |
| 3138 | // history navigation targets a subframe that no longer exists |
| 3139 | // (https://crbug.com/705550). In this case, we need to update the current |
| 3140 | // history entry to the pending one but keep the main document loaded. We |
| 3141 | // also need to ensure that observers are informed about the updated |
| 3142 | // current history entry (e.g., for greying out back/forward buttons), and |
| 3143 | // that renderer processes update their history offsets. The easiest way |
| 3144 | // to do all that is to schedule a "redundant" same-document navigation in |
| 3145 | // the main frame. |
| 3146 | // |
| 3147 | // Note that we don't want to remove this history entry, as it might still |
| 3148 | // be valid later, since a frame that it's targeting may be recreated. |
| 3149 | // |
| 3150 | // TODO(alexmos, creis): This behavior isn't ideal, as the user would |
| 3151 | // need to repeat history navigations until finding the one that works. |
| 3152 | // Consider changing this behavior to keep looking for the first valid |
| 3153 | // history entry that finds frames to navigate. |
clamy | 3cb9bea9 | 2018-07-10 12:42:02 | [diff] [blame] | 3154 | std::unique_ptr<NavigationRequest> navigation_request = |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3155 | CreateNavigationRequestFromEntry( |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 3156 | root, pending_entry_, pending_entry_->GetFrameEntry(root), |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3157 | ReloadType::NONE /* reload_type */, |
| 3158 | true /* is_same_document_history_load */, |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 3159 | false /* is_history_navigation_in_new_child */, |
| 3160 | is_browser_initiated); |
clamy | 3cb9bea9 | 2018-07-10 12:42:02 | [diff] [blame] | 3161 | if (!navigation_request) { |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3162 | // If this navigation cannot start, delete the pending NavigationEntry. |
clamy | 3cb9bea9 | 2018-07-10 12:42:02 | [diff] [blame] | 3163 | DiscardPendingEntry(false); |
| 3164 | return; |
| 3165 | } |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3166 | same_document_loads.push_back(std::move(navigation_request)); |
| 3167 | |
| 3168 | // Sanity check that we never take this branch for any kinds of reloads, |
| 3169 | // as those should've queued a different-document load in the main frame. |
| 3170 | DCHECK(!is_forced_reload); |
| 3171 | DCHECK_EQ(reload_type, ReloadType::NONE); |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 3172 | } |
| 3173 | |
Nate Chapin | bf682fa3 | 2022-09-26 22:41:20 | [diff] [blame] | 3174 | // If the initiator is top-navigation sandboxed, then track whether this |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 3175 | // navigation affects any frame outside the frame's subtree. |
Nate Chapin | bf682fa3 | 2022-09-26 22:41:20 | [diff] [blame] | 3176 | if (initiator_rfh && initiator_rfh->IsSandboxed( |
| 3177 | network::mojom::WebSandboxFlags::kTopNavigation)) { |
| 3178 | bool navigates_inside_tree = DoesSandboxNavigationStayWithinSubtree( |
| 3179 | initiator_rfh, same_document_loads) && |
| 3180 | DoesSandboxNavigationStayWithinSubtree( |
| 3181 | initiator_rfh, different_document_loads); |
Dave Tapuska | 716ed3af | 2019-09-23 18:45:50 | [diff] [blame] | 3182 | // Count the navigations as web use counters so we can determine |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 3183 | // the number of pages that trigger this. |
Nate Chapin | bf682fa3 | 2022-09-26 22:41:20 | [diff] [blame] | 3184 | GetContentClient()->browser()->LogWebFeatureForCurrentPage( |
| 3185 | initiator_rfh, |
| 3186 | navigates_inside_tree |
| 3187 | ? blink::mojom::WebFeature::kSandboxBackForwardStaysWithinSubtree |
| 3188 | : blink::mojom::WebFeature:: |
| 3189 | kSandboxBackForwardAffectsFramesOutsideSubtree); |
Dave Tapuska | 855c1e1 | 2019-08-23 20:45:52 | [diff] [blame] | 3190 | |
| 3191 | // If the navigation occurred outside the tree discard it because |
| 3192 | // the sandboxed frame didn't have permission to navigate outside |
| 3193 | // its tree. If it is possible that the navigation is both inside and |
| 3194 | // outside the frame tree and we discard it entirely because we don't |
| 3195 | // want to end up in a history state that didn't exist before. |
Dominic Farolino | 05744004 | 2022-01-19 18:18:14 | [diff] [blame] | 3196 | if (!navigates_inside_tree) { |
Nate Chapin | bf682fa3 | 2022-09-26 22:41:20 | [diff] [blame] | 3197 | // If a |navigation_api_key| was provided, this navigation originated from |
| 3198 | // the navigation API. Notify the renderer that the navigation was |
| 3199 | // cancelled so the navigation API can fire an error event and reject the |
| 3200 | // relevant promise. |
| 3201 | if (navigation_api_key) { |
| 3202 | initiator_rfh->GetAssociatedLocalFrame()->TraverseCancelled( |
| 3203 | *navigation_api_key, |
| 3204 | blink::mojom::TraverseCancelledReason::kSandboxViolation); |
| 3205 | } |
Dave Tapuska | 855c1e1 | 2019-08-23 20:45:52 | [diff] [blame] | 3206 | DiscardPendingEntry(false); |
| 3207 | return; |
| 3208 | } |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 3209 | } |
| 3210 | |
Carlos Caballero | 539a421c | 2020-07-06 10:25:57 | [diff] [blame] | 3211 | // BackForwardCache: |
| 3212 | // Navigate immediately if the document is in the BackForwardCache. |
| 3213 | if (back_forward_cache_.GetEntry(nav_entry_id)) { |
| 3214 | TRACE_EVENT0("navigation", "BackForwardCache_CreateNavigationRequest"); |
| 3215 | DCHECK_EQ(reload_type, ReloadType::NONE); |
| 3216 | auto navigation_request = CreateNavigationRequestFromEntry( |
| 3217 | root, pending_entry_, pending_entry_->GetFrameEntry(root), |
| 3218 | ReloadType::NONE, false /* is_same_document_history_load */, |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 3219 | false /* is_history_navigation_in_new_child */, is_browser_initiated); |
Lukasz Anforowicz | 9ee83c27 | 2020-12-01 20:14:05 | [diff] [blame] | 3220 | root->navigator().Navigate(std::move(navigation_request), ReloadType::NONE); |
Carlos Caballero | 539a421c | 2020-07-06 10:25:57 | [diff] [blame] | 3221 | |
| 3222 | return; |
| 3223 | } |
| 3224 | |
| 3225 | // History navigation might try to reuse a specific BrowsingInstance, already |
| 3226 | // used by a page in the cache. To avoid having two different main frames that |
| 3227 | // live in the same BrowsingInstance, evict the all pages with this |
| 3228 | // BrowsingInstance from the cache. |
| 3229 | // |
| 3230 | // For example, take the following scenario: |
| 3231 | // |
| 3232 | // A1 = Some page on a.com |
| 3233 | // A2 = Some other page on a.com |
| 3234 | // B3 = An uncacheable page on b.com |
| 3235 | // |
| 3236 | // Then the following navigations occur: |
| 3237 | // A1->A2->B3->A1 |
| 3238 | // On the navigation from B3 to A1, A2 will remain in the cache (B3 doesn't |
| 3239 | // take its place) and A1 will be created in the same BrowsingInstance (and |
| 3240 | // SiteInstance), as A2. |
| 3241 | // |
| 3242 | // If we didn't do anything, both A1 and A2 would remain alive in the same |
| 3243 | // BrowsingInstance/SiteInstance, which is unsupported by |
| 3244 | // RenderFrameHostManager::CommitPending(). To avoid this conundrum, we evict |
| 3245 | // A2 from the cache. |
| 3246 | if (pending_entry_->site_instance()) { |
| 3247 | back_forward_cache_.EvictFramesInRelatedSiteInstances( |
| 3248 | pending_entry_->site_instance()); |
| 3249 | } |
| 3250 | |
Rakina Zata Amni | d605d46 | 2022-06-01 10:17:03 | [diff] [blame] | 3251 | SCOPED_CRASH_KEY_BOOL("nav_reentrancy", "pending_entry_restored", |
| 3252 | pending_entry_ && pending_entry_->IsRestored()); |
| 3253 | SCOPED_CRASH_KEY_NUMBER("nav_reentrancy", "pending_entry_id", |
| 3254 | pending_entry_ ? pending_entry_->GetUniqueID() : -1); |
| 3255 | SCOPED_CRASH_KEY_NUMBER("nav_reentrancy", "pending_entry_index", |
| 3256 | pending_entry_index_); |
| 3257 | SCOPED_CRASH_KEY_NUMBER("nav_reentrancy", "last_committed_index", |
| 3258 | last_committed_entry_index_); |
| 3259 | SCOPED_CRASH_KEY_NUMBER("nav_reentrancy", "entries_size", entries_.size()); |
| 3260 | SCOPED_CRASH_KEY_BOOL("nav_reentrancy", "pending_entry_initial", |
| 3261 | pending_entry_ && pending_entry_->IsInitialEntry()); |
| 3262 | SCOPED_CRASH_KEY_BOOL( |
| 3263 | "nav_reentrancy", "pending_entry_initial2", |
| 3264 | pending_entry_ && |
| 3265 | pending_entry_->IsInitialEntryNotForSynchronousAboutBlank()); |
| 3266 | SCOPED_CRASH_KEY_BOOL("nav_reentrancy", "is_initial_nav", |
| 3267 | IsInitialNavigation()); |
| 3268 | SCOPED_CRASH_KEY_BOOL("nav_reentrancy", "is_initial_blank_nav", |
| 3269 | IsInitialBlankNavigation()); |
| 3270 | SCOPED_CRASH_KEY_BOOL("nav_reentrancy", "is_forced_reload", is_forced_reload); |
| 3271 | SCOPED_CRASH_KEY_NUMBER("nav_reentrancy", "pending_reload_type", |
| 3272 | (int)pending_reload_); |
| 3273 | |
clamy | 3cb9bea9 | 2018-07-10 12:42:02 | [diff] [blame] | 3274 | // This call does not support re-entrancy. See http://crbug.com/347742. |
| 3275 | CHECK(!in_navigate_to_pending_entry_); |
| 3276 | in_navigate_to_pending_entry_ = true; |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 3277 | |
Rakina Zata Amni | d605d46 | 2022-06-01 10:17:03 | [diff] [blame] | 3278 | // If the navigation-reentrancy is caused by calling |
| 3279 | // NavigateToExistingPendingEntry twice, this will note the previous call's |
| 3280 | // pending entry's ID. |
| 3281 | SCOPED_CRASH_KEY_NUMBER("nav_reentrancy", "prev_pending_entry_id", |
| 3282 | pending_entry_ ? pending_entry_->GetUniqueID() : -1); |
| 3283 | |
arthursonzogni | 66f711c | 2019-10-08 14:40:36 | [diff] [blame] | 3284 | // It is not possible to delete the pending NavigationEntry while navigating |
| 3285 | // to it. Grab a reference to delay potential deletion until the end of this |
| 3286 | // function. |
| 3287 | std::unique_ptr<PendingEntryRef> pending_entry_ref = ReferencePendingEntry(); |
| 3288 | |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 3289 | // Send all the same document frame loads before the different document loads. |
clamy | 3cb9bea9 | 2018-07-10 12:42:02 | [diff] [blame] | 3290 | for (auto& item : same_document_loads) { |
| 3291 | FrameTreeNode* frame = item->frame_tree_node(); |
Lukasz Anforowicz | 9ee83c27 | 2020-12-01 20:14:05 | [diff] [blame] | 3292 | frame->navigator().Navigate(std::move(item), reload_type); |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 3293 | } |
clamy | 3cb9bea9 | 2018-07-10 12:42:02 | [diff] [blame] | 3294 | for (auto& item : different_document_loads) { |
| 3295 | FrameTreeNode* frame = item->frame_tree_node(); |
Lukasz Anforowicz | 9ee83c27 | 2020-12-01 20:14:05 | [diff] [blame] | 3296 | frame->navigator().Navigate(std::move(item), reload_type); |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 3297 | } |
clamy | 3cb9bea9 | 2018-07-10 12:42:02 | [diff] [blame] | 3298 | |
| 3299 | in_navigate_to_pending_entry_ = false; |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 3300 | } |
| 3301 | |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3302 | NavigationControllerImpl::HistoryNavigationAction |
| 3303 | NavigationControllerImpl::DetermineActionForHistoryNavigation( |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 3304 | FrameTreeNode* frame, |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3305 | ReloadType reload_type) { |
Sreeja Kamishetty | 8eacabb | 2021-03-09 11:45:42 | [diff] [blame] | 3306 | RenderFrameHostImpl* render_frame_host = frame->current_frame_host(); |
Sreeja Kamishetty | db8e289 | 2021-03-10 09:30:58 | [diff] [blame] | 3307 | // Only active and prerendered documents are allowed to navigate in their |
| 3308 | // frame. |
Sreeja Kamishetty | 8eacabb | 2021-03-09 11:45:42 | [diff] [blame] | 3309 | if (render_frame_host->lifecycle_state() != |
Sreeja Kamishetty | 299329ad | 2021-03-25 14:06:01 | [diff] [blame] | 3310 | RenderFrameHostImpl::LifecycleStateImpl::kPrerendering) { |
Sreeja Kamishetty | db8e289 | 2021-03-10 09:30:58 | [diff] [blame] | 3311 | // - If the document is in pending deletion, the browser already committed |
| 3312 | // to destroying this RenderFrameHost. See https://crbug.com/930278. |
| 3313 | // - If the document is in back-forward cache, it's not allowed to navigate |
| 3314 | // as it should remain frozen. Ignore the request and evict the document |
| 3315 | // from back-forward cache. |
Sreeja Kamishetty | 8eacabb | 2021-03-09 11:45:42 | [diff] [blame] | 3316 | // |
Sreeja Kamishetty | db8e289 | 2021-03-10 09:30:58 | [diff] [blame] | 3317 | // If the document is inactive, there's no need to recurse into subframes, |
Sreeja Kamishetty | 8eacabb | 2021-03-09 11:45:42 | [diff] [blame] | 3318 | // which should all be inactive as well. |
Fergal Daly | 1336ac64 | 2021-09-14 15:13:11 | [diff] [blame] | 3319 | if (frame->current_frame_host()->IsInactiveAndDisallowActivation( |
| 3320 | DisallowActivationReasonId::kDetermineActionForHistoryNavigation)) { |
Sreeja Kamishetty | 8eacabb | 2021-03-09 11:45:42 | [diff] [blame] | 3321 | return HistoryNavigationAction::kStopLooking; |
Fergal Daly | 1336ac64 | 2021-09-14 15:13:11 | [diff] [blame] | 3322 | } |
Sreeja Kamishetty | 8eacabb | 2021-03-09 11:45:42 | [diff] [blame] | 3323 | } |
arthursonzogni | 03f7615 | 2019-02-12 10:35:20 | [diff] [blame] | 3324 | |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3325 | // If there's no last committed entry, there is no previous history entry to |
| 3326 | // compare against, so fall back to a different-document load. Note that we |
| 3327 | // should only reach this case for the root frame and not descend further |
| 3328 | // into subframes. |
| 3329 | if (!GetLastCommittedEntry()) { |
| 3330 | DCHECK(frame->IsMainFrame()); |
| 3331 | return HistoryNavigationAction::kDifferentDocument; |
| 3332 | } |
| 3333 | |
| 3334 | // Reloads should result in a different-document load. Note that reloads may |
| 3335 | // also happen via the |needs_reload_| mechanism where the reload_type is |
| 3336 | // NONE, so detect this by comparing whether we're going to the same |
| 3337 | // entry that we're currently on. Similarly to above, only main frames |
| 3338 | // should reach this. Note that subframes support reloads, but that's done |
| 3339 | // via a different path that doesn't involve FindFramesToNavigate (see |
| 3340 | // RenderFrameHost::Reload()). |
| 3341 | if (reload_type != ReloadType::NONE || |
| 3342 | pending_entry_index_ == last_committed_entry_index_) { |
| 3343 | DCHECK(frame->IsMainFrame()); |
| 3344 | return HistoryNavigationAction::kDifferentDocument; |
| 3345 | } |
| 3346 | |
Alex Moshchuk | 47d1a4bd | 2020-06-01 22:15:34 | [diff] [blame] | 3347 | // If there is no new FrameNavigationEntry for the frame, ignore the |
| 3348 | // load. For example, this may happen when going back to an entry before a |
| 3349 | // frame was created. Suppose we commit a same-document navigation that also |
| 3350 | // results in adding a new subframe somewhere in the tree. If we go back, |
| 3351 | // the new subframe will be missing a FrameNavigationEntry in the previous |
| 3352 | // NavigationEntry, but we shouldn't delete or change what's loaded in |
| 3353 | // it. |
| 3354 | // |
Alex Moshchuk | e65c3927 | 2020-06-03 17:55:37 | [diff] [blame] | 3355 | // Note that in this case, there is no need to keep looking for navigations |
| 3356 | // in subframes, which would be missing FrameNavigationEntries as well. |
| 3357 | // |
Alex Moshchuk | 47d1a4bd | 2020-06-01 22:15:34 | [diff] [blame] | 3358 | // It's important to check this before checking |old_item| below, since both |
| 3359 | // might be null, and in that case we still shouldn't change what's loaded in |
| 3360 | // this frame. Note that scheduling any loads assumes that |new_item| is |
| 3361 | // non-null. See https://crbug.com/1088354. |
| 3362 | FrameNavigationEntry* new_item = pending_entry_->GetFrameEntry(frame); |
| 3363 | if (!new_item) |
Alex Moshchuk | e65c3927 | 2020-06-03 17:55:37 | [diff] [blame] | 3364 | return HistoryNavigationAction::kStopLooking; |
Alex Moshchuk | 47d1a4bd | 2020-06-01 22:15:34 | [diff] [blame] | 3365 | |
Charlie Reis | a474fb6 | 2022-03-17 02:31:36 | [diff] [blame] | 3366 | // Use the RenderFrameHost's last committed FrameNavigationEntry to identify |
| 3367 | // which history item it is currently on, since this may be different than the |
| 3368 | // FrameNavigationEntry for the frame in the last committed NavigationEntry |
| 3369 | // (e.g., if a history navigation is targeting multiple frames and only some |
| 3370 | // have committed so far). |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 3371 | FrameNavigationEntry* old_item = |
Charlie Reis | a474fb6 | 2022-03-17 02:31:36 | [diff] [blame] | 3372 | frame->current_frame_host()->last_committed_frame_entry(); |
| 3373 | if (!old_item) { |
| 3374 | // In cases where the RenderFrameHost does not have a FrameNavigationEntry, |
| 3375 | // fall back to the last committed NavigationEntry's record for this frame. |
| 3376 | // This may happen in cases like the initial state of the RenderFrameHost. |
| 3377 | // TODO(https://crbug.com/1304466): Ensure the RenderFrameHost always has an |
| 3378 | // accurate FrameNavigationEntry and eliminate this case. |
| 3379 | old_item = GetLastCommittedEntry()->GetFrameEntry(frame); |
| 3380 | } |
| 3381 | // If neither approach finds a FrameNavigationEntry, schedule a |
| 3382 | // different-document load. |
| 3383 | // TODO(https://crbug.com/608402): Remove this case. |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3384 | if (!old_item) |
| 3385 | return HistoryNavigationAction::kDifferentDocument; |
| 3386 | |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3387 | // If the new item is not in the same SiteInstance, schedule a |
| 3388 | // different-document load. Newly restored items may not have a SiteInstance |
| 3389 | // yet, in which case it will be assigned on first commit. |
| 3390 | if (new_item->site_instance() && |
| 3391 | new_item->site_instance() != old_item->site_instance()) |
| 3392 | return HistoryNavigationAction::kDifferentDocument; |
| 3393 | |
| 3394 | // Schedule a different-document load if the current RenderFrameHost is not |
danakj | 25c436d | 2021-04-01 16:35:31 | [diff] [blame] | 3395 | // live. This case can happen for Ctrl+Back or after a renderer crash. Note |
| 3396 | // that we do this even if the history navigation would not be modifying this |
| 3397 | // frame were it live. |
| 3398 | if (!frame->current_frame_host()->IsRenderFrameLive()) |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3399 | return HistoryNavigationAction::kDifferentDocument; |
| 3400 | |
| 3401 | if (new_item->item_sequence_number() != old_item->item_sequence_number()) { |
danakj | 25c436d | 2021-04-01 16:35:31 | [diff] [blame] | 3402 | // Starting a navigation after a crash early-promotes the speculative |
| 3403 | // RenderFrameHost. Then we have a RenderFrameHost with no document in it |
| 3404 | // committed yet, so we can not possibly perform a same-document history |
| 3405 | // navigation. The frame would need to be reloaded with a cross-document |
| 3406 | // navigation. |
| 3407 | if (!frame->current_frame_host()->has_committed_any_navigation()) |
| 3408 | return HistoryNavigationAction::kDifferentDocument; |
| 3409 | |
creis | 5413169 | 2016-08-12 18:32:25 | [diff] [blame] | 3410 | // Same document loads happen if the previous item has the same document |
danakj | b952ef1 | 2021-01-14 19:58:49 | [diff] [blame] | 3411 | // sequence number but different item sequence number. |
| 3412 | if (new_item->document_sequence_number() == |
| 3413 | old_item->document_sequence_number()) { |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3414 | return HistoryNavigationAction::kSameDocument; |
danakj | b952ef1 | 2021-01-14 19:58:49 | [diff] [blame] | 3415 | } |
avi | b48cb31 | 2016-05-05 21:35:00 | [diff] [blame] | 3416 | |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3417 | // Otherwise, if both item and document sequence numbers differ, this |
| 3418 | // should be a different document load. |
| 3419 | return HistoryNavigationAction::kDifferentDocument; |
| 3420 | } |
| 3421 | |
| 3422 | // If the item sequence numbers match, there is no need to navigate this |
Alex Moshchuk | e65c3927 | 2020-06-03 17:55:37 | [diff] [blame] | 3423 | // frame. Keep looking for navigations in this frame's children. |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3424 | DCHECK_EQ(new_item->document_sequence_number(), |
| 3425 | old_item->document_sequence_number()); |
Alex Moshchuk | e65c3927 | 2020-06-03 17:55:37 | [diff] [blame] | 3426 | return HistoryNavigationAction::kKeepLooking; |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3427 | } |
| 3428 | |
| 3429 | void NavigationControllerImpl::FindFramesToNavigate( |
| 3430 | FrameTreeNode* frame, |
| 3431 | ReloadType reload_type, |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 3432 | bool is_browser_initiated, |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3433 | std::vector<std::unique_ptr<NavigationRequest>>* same_document_loads, |
| 3434 | std::vector<std::unique_ptr<NavigationRequest>>* different_document_loads) { |
| 3435 | DCHECK(pending_entry_); |
| 3436 | FrameNavigationEntry* new_item = pending_entry_->GetFrameEntry(frame); |
| 3437 | |
| 3438 | auto action = DetermineActionForHistoryNavigation(frame, reload_type); |
| 3439 | |
| 3440 | if (action == HistoryNavigationAction::kSameDocument) { |
| 3441 | std::unique_ptr<NavigationRequest> navigation_request = |
| 3442 | CreateNavigationRequestFromEntry( |
| 3443 | frame, pending_entry_, new_item, reload_type, |
| 3444 | true /* is_same_document_history_load */, |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 3445 | false /* is_history_navigation_in_new_child */, |
| 3446 | is_browser_initiated); |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3447 | if (navigation_request) { |
| 3448 | // Only add the request if was properly created. It's possible for the |
| 3449 | // creation to fail in certain cases, e.g. when the URL is invalid. |
| 3450 | same_document_loads->push_back(std::move(navigation_request)); |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 3451 | } |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3452 | } else if (action == HistoryNavigationAction::kDifferentDocument) { |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 3453 | std::unique_ptr<NavigationRequest> navigation_request = |
| 3454 | CreateNavigationRequestFromEntry( |
| 3455 | frame, pending_entry_, new_item, reload_type, |
| 3456 | false /* is_same_document_history_load */, |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 3457 | false /* is_history_navigation_in_new_child */, |
| 3458 | is_browser_initiated); |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 3459 | if (navigation_request) { |
| 3460 | // Only add the request if was properly created. It's possible for the |
| 3461 | // creation to fail in certain cases, e.g. when the URL is invalid. |
| 3462 | different_document_loads->push_back(std::move(navigation_request)); |
| 3463 | } |
| 3464 | // For a different document, the subframes will be destroyed, so there's |
| 3465 | // no need to consider them. |
| 3466 | return; |
Alex Moshchuk | e65c3927 | 2020-06-03 17:55:37 | [diff] [blame] | 3467 | } else if (action == HistoryNavigationAction::kStopLooking) { |
| 3468 | return; |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 3469 | } |
| 3470 | |
| 3471 | for (size_t i = 0; i < frame->child_count(); i++) { |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 3472 | FindFramesToNavigate(frame->child_at(i), reload_type, is_browser_initiated, |
| 3473 | same_document_loads, different_document_loads); |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 3474 | } |
| 3475 | } |
| 3476 | |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 3477 | base::WeakPtr<NavigationHandle> NavigationControllerImpl::NavigateWithoutEntry( |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3478 | const LoadURLParams& params) { |
| 3479 | // Find the appropriate FrameTreeNode. |
| 3480 | FrameTreeNode* node = nullptr; |
| 3481 | if (params.frame_tree_node_id != RenderFrameHost::kNoFrameTreeNodeId || |
| 3482 | !params.frame_name.empty()) { |
| 3483 | node = params.frame_tree_node_id != RenderFrameHost::kNoFrameTreeNodeId |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 3484 | ? frame_tree_->FindByID(params.frame_tree_node_id) |
| 3485 | : frame_tree_->FindByName(params.frame_name); |
| 3486 | DCHECK(!node || node->frame_tree() == &*frame_tree_); |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3487 | } |
| 3488 | |
| 3489 | // If no FrameTreeNode was specified, navigate the main frame. |
| 3490 | if (!node) |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 3491 | node = frame_tree_->root(); |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3492 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3493 | // Compute overrides to the LoadURLParams for |override_user_agent|, |
| 3494 | // |should_replace_current_entry| and |has_user_gesture| that will be used |
| 3495 | // both in the creation of the NavigationEntry and the NavigationRequest. |
| 3496 | // Ideally, the LoadURLParams themselves would be updated, but since they are |
| 3497 | // passed as a const reference, this is not possible. |
| 3498 | // TODO(clamy): When we only create a NavigationRequest, move this to |
| 3499 | // CreateNavigationRequestFromLoadURLParams. |
| 3500 | bool override_user_agent = ShouldOverrideUserAgent(params.override_user_agent, |
| 3501 | GetLastCommittedEntry()); |
| 3502 | |
| 3503 | // Don't allow an entry replacement if there is no entry to replace. |
| 3504 | // http://crbug.com/457149 |
Hayato Ito | 7a80db4 | 2021-07-05 06:18:54 | [diff] [blame] | 3505 | // |
| 3506 | // If there is an entry, an entry replacement must happen if the current |
| 3507 | // browsing context should maintain a trivial session history. |
shivanigithub | f405bf0d | 2021-11-05 17:58:33 | [diff] [blame] | 3508 | bool should_replace_current_entry = |
| 3509 | (params.should_replace_current_entry || |
| 3510 | ShouldMaintainTrivialSessionHistory(node)) && |
| 3511 | entries_.size(); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3512 | |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3513 | // Javascript URLs should not create NavigationEntries. All other navigations |
| 3514 | // do, including navigations to chrome renderer debug URLs. |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3515 | if (!params.url.SchemeIs(url::kJavaScriptScheme)) { |
Scott Violet | 5ae6c42e | 2020-10-28 02:47:37 | [diff] [blame] | 3516 | std::unique_ptr<NavigationEntryImpl> entry = |
| 3517 | CreateNavigationEntryFromLoadParams(node, params, override_user_agent, |
| 3518 | should_replace_current_entry, |
| 3519 | params.has_user_gesture); |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3520 | DiscardPendingEntry(false); |
| 3521 | SetPendingEntry(std::move(entry)); |
| 3522 | } |
| 3523 | |
| 3524 | // Renderer-debug URLs are sent to the renderer process immediately for |
| 3525 | // processing and don't need to create a NavigationRequest. |
| 3526 | // Note: this includes navigations to JavaScript URLs, which are considered |
| 3527 | // renderer-debug URLs. |
| 3528 | // Note: we intentionally leave the pending entry in place for renderer debug |
| 3529 | // URLs, unlike the cases below where we clear it if the navigation doesn't |
| 3530 | // proceed. |
Gyuyoung Kim | 107c2a0 | 2021-04-13 01:49:30 | [diff] [blame] | 3531 | if (blink::IsRendererDebugURL(params.url)) { |
Oleg Davydov | 2cc0167b | 2019-02-05 14:32:48 | [diff] [blame] | 3532 | // Renderer-debug URLs won't go through NavigationThrottlers so we have to |
| 3533 | // check them explicitly. See bug 913334. |
Aaron Colwell | e1908d98 | 2020-06-26 22:08:15 | [diff] [blame] | 3534 | if (GetContentClient()->browser()->ShouldBlockRendererDebugURL( |
Oleg Davydov | 2cc0167b | 2019-02-05 14:32:48 | [diff] [blame] | 3535 | params.url, browser_context_)) { |
| 3536 | DiscardPendingEntry(false); |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 3537 | return nullptr; |
Oleg Davydov | 2cc0167b | 2019-02-05 14:32:48 | [diff] [blame] | 3538 | } |
| 3539 | |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3540 | HandleRendererDebugURL(node, params.url); |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 3541 | return nullptr; |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3542 | } |
| 3543 | |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 3544 | DCHECK(pending_entry_); |
| 3545 | |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3546 | // Convert navigations to the current URL to a reload. |
| 3547 | // TODO(clamy): We should be using FrameTreeNode::IsMainFrame here instead of |
| 3548 | // relying on the frame tree node id from LoadURLParams. Unfortunately, |
| 3549 | // DevTools sometimes issues navigations to main frames that they do not |
| 3550 | // expect to see treated as reload, and it only works because they pass a |
| 3551 | // FrameTreeNode id in their LoadURLParams. Change this once they no longer do |
| 3552 | // that. See https://crbug.com/850926. |
Robert Ogden | 011a808 | 2019-01-23 19:04:54 | [diff] [blame] | 3553 | ReloadType reload_type = params.reload_type; |
| 3554 | if (reload_type == ReloadType::NONE && |
| 3555 | ShouldTreatNavigationAsReload( |
Fergal Daly | 766177d | 2020-07-07 07:54:04 | [diff] [blame] | 3556 | node, params.url, pending_entry_->GetVirtualURL(), |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3557 | params.base_url_for_data_url, params.transition_type, |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3558 | params.load_type == |
| 3559 | NavigationController::LOAD_TYPE_HTTP_POST /* is_post */, |
Hayato Ito | 7a80db4 | 2021-07-05 06:18:54 | [diff] [blame] | 3560 | should_replace_current_entry, GetLastCommittedEntry())) { |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3561 | reload_type = ReloadType::NORMAL; |
Alexander Timin | b70f6738 | 2020-12-10 00:03:47 | [diff] [blame] | 3562 | pending_entry_->set_reload_type(reload_type); |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 3563 | |
| 3564 | // If this is a reload of an existing FrameNavigationEntry and we had a |
| 3565 | // policy container for it, then we should copy it into the pending entry, |
| 3566 | // so that it is copied to the navigation request in |
| 3567 | // CreateNavigationRequestFromLoadParams later. |
| 3568 | if (GetLastCommittedEntry()) { |
| 3569 | FrameNavigationEntry* previous_frame_entry = |
| 3570 | GetLastCommittedEntry()->GetFrameEntry(node); |
Titouan Rigoudy | 6ec7040 | 2021-02-02 15:42:19 | [diff] [blame] | 3571 | if (previous_frame_entry && |
| 3572 | previous_frame_entry->policy_container_policies()) { |
| 3573 | pending_entry_->GetFrameEntry(node)->set_policy_container_policies( |
Titouan Rigoudy | 72f892d | 2022-05-02 18:21:23 | [diff] [blame] | 3574 | previous_frame_entry->policy_container_policies()->ClonePtr()); |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 3575 | } |
| 3576 | } |
| 3577 | } |
| 3578 | |
| 3579 | // If this navigation is an "Enter-in-omnibox" with the initial about:blank |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 3580 | // document, then we should copy the document polices from RenderFrameHost's |
| 3581 | // PolicyContainerHost. The NavigationRequest will create a new |
| 3582 | // PolicyContainerHost with the document policies from the |pending_entry_|, |
| 3583 | // and that PolicyContainerHost will be put in the final RenderFrameHost for |
| 3584 | // the navigation. This way, we ensure that we keep enforcing the right |
| 3585 | // policies on the initial empty document after the reload. |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 3586 | if ((!GetLastCommittedEntry() || GetLastCommittedEntry()->IsInitialEntry()) && |
| 3587 | params.url.IsAboutBlank()) { |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 3588 | if (node->current_frame_host() && |
| 3589 | node->current_frame_host()->policy_container_host()) { |
Titouan Rigoudy | 6ec7040 | 2021-02-02 15:42:19 | [diff] [blame] | 3590 | pending_entry_->GetFrameEntry(node)->set_policy_container_policies( |
Antonio Sartori | 5d09b30f | 2021-03-02 09:27:16 | [diff] [blame] | 3591 | node->current_frame_host() |
| 3592 | ->policy_container_host() |
| 3593 | ->policies() |
Titouan Rigoudy | 72f892d | 2022-05-02 18:21:23 | [diff] [blame] | 3594 | .ClonePtr()); |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 3595 | } |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3596 | } |
| 3597 | |
| 3598 | // navigation_ui_data should only be present for main frame navigations. |
Ian Vollick | 1c6dd3e | 2022-04-13 02:06:26 | [diff] [blame] | 3599 | DCHECK(node->IsOutermostMainFrame() || !params.navigation_ui_data); |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3600 | |
Tsuyoshi Horo | 167ca643 | 2022-03-09 05:16:39 | [diff] [blame] | 3601 | // This will be used to set the Navigation Timing API navigationStart |
| 3602 | // parameter for browser navigations in new tabs (intents, tabs opened through |
| 3603 | // "Open link in new tab"). If the navigation must wait on the current |
| 3604 | // RenderFrameHost to execute its BeforeUnload event, the navigation start |
| 3605 | // will be updated when the BeforeUnload ack is received. |
| 3606 | const auto navigation_start_time = base::TimeTicks::Now(); |
| 3607 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3608 | std::unique_ptr<NavigationRequest> request = |
| 3609 | CreateNavigationRequestFromLoadParams( |
| 3610 | node, params, override_user_agent, should_replace_current_entry, |
Antonio Sartori | 2f763d9d | 2021-04-21 10:04:14 | [diff] [blame] | 3611 | params.has_user_gesture, network::mojom::SourceLocation::New(), |
Tsuyoshi Horo | 167ca643 | 2022-03-09 05:16:39 | [diff] [blame] | 3612 | reload_type, pending_entry_, pending_entry_->GetFrameEntry(node), |
| 3613 | navigation_start_time); |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3614 | |
| 3615 | // If the navigation couldn't start, return immediately and discard the |
| 3616 | // pending NavigationEntry. |
| 3617 | if (!request) { |
| 3618 | DiscardPendingEntry(false); |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 3619 | return nullptr; |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3620 | } |
| 3621 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3622 | #if DCHECK_IS_ON() |
| 3623 | // Safety check that NavigationRequest and NavigationEntry match. |
| 3624 | ValidateRequestMatchesEntry(request.get(), pending_entry_); |
| 3625 | #endif |
| 3626 | |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3627 | // This call does not support re-entrancy. See http://crbug.com/347742. |
| 3628 | CHECK(!in_navigate_to_pending_entry_); |
| 3629 | in_navigate_to_pending_entry_ = true; |
| 3630 | |
arthursonzogni | 66f711c | 2019-10-08 14:40:36 | [diff] [blame] | 3631 | // It is not possible to delete the pending NavigationEntry while navigating |
| 3632 | // to it. Grab a reference to delay potential deletion until the end of this |
| 3633 | // function. |
| 3634 | std::unique_ptr<PendingEntryRef> pending_entry_ref = ReferencePendingEntry(); |
| 3635 | |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 3636 | base::WeakPtr<NavigationHandle> created_navigation_handle( |
| 3637 | request->GetWeakPtr()); |
Lukasz Anforowicz | 9ee83c27 | 2020-12-01 20:14:05 | [diff] [blame] | 3638 | node->navigator().Navigate(std::move(request), reload_type); |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3639 | |
| 3640 | in_navigate_to_pending_entry_ = false; |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 3641 | return created_navigation_handle; |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3642 | } |
| 3643 | |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3644 | void NavigationControllerImpl::HandleRendererDebugURL( |
| 3645 | FrameTreeNode* frame_tree_node, |
| 3646 | const GURL& url) { |
| 3647 | if (!frame_tree_node->current_frame_host()->IsRenderFrameLive()) { |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3648 | // Any renderer-side debug URLs or javascript: URLs should be ignored if |
| 3649 | // the renderer process is not live, unless it is the initial navigation |
| 3650 | // of the tab. |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3651 | if (!IsInitialNavigation()) { |
| 3652 | DiscardNonCommittedEntries(); |
| 3653 | return; |
| 3654 | } |
Fergal Daly | ecd3b020 | 2020-06-25 01:57:37 | [diff] [blame] | 3655 | // The current frame is always a main frame. If IsInitialNavigation() is |
| 3656 | // true then there have been no navigations and any frames of this tab must |
| 3657 | // be in the same renderer process. If that has crashed then the only frame |
| 3658 | // that can be revived is the main frame. |
| 3659 | frame_tree_node->render_manager() |
| 3660 | ->InitializeMainRenderFrameForImmediateUse(); |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3661 | } |
Julie Jeongeun Kim | 50d124c | 2022-10-21 13:51:22 | [diff] [blame] | 3662 | |
| 3663 | // Several tests expect a load of Chrome Debug URLs to send a DidStopLoading |
| 3664 | // notification, so set is loading to true here to properly surface it when |
| 3665 | // the renderer process is done handling the URL. |
| 3666 | // TODO(crbug.com/1254130): Remove the test dependency on this behavior. |
| 3667 | if (!url.SchemeIs(url::kJavaScriptScheme)) { |
| 3668 | bool was_loading = frame_tree_node->frame_tree() |
| 3669 | ->LoadingTree() |
| 3670 | ->IsLoadingIncludingInnerFrameTrees(); |
| 3671 | frame_tree_node->current_frame_host()->SetIsLoadingForRendererDebugURL(); |
| 3672 | frame_tree_node->DidStartLoading(true /* should_show_loading_ui */, |
| 3673 | was_loading); |
| 3674 | } |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3675 | frame_tree_node->current_frame_host()->HandleRendererDebugURL(url); |
| 3676 | } |
| 3677 | |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3678 | std::unique_ptr<NavigationEntryImpl> |
| 3679 | NavigationControllerImpl::CreateNavigationEntryFromLoadParams( |
| 3680 | FrameTreeNode* node, |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3681 | const LoadURLParams& params, |
| 3682 | bool override_user_agent, |
| 3683 | bool should_replace_current_entry, |
| 3684 | bool has_user_gesture) { |
Marijn Kruisselbrink | 0c87e6e | 2018-06-22 22:57:39 | [diff] [blame] | 3685 | // Browser initiated navigations might not have a blob_url_loader_factory set |
| 3686 | // in params even if the navigation is to a blob URL. If that happens, lookup |
| 3687 | // the correct url loader factory to use here. |
| 3688 | auto blob_url_loader_factory = params.blob_url_loader_factory; |
Kinuko Yasuda | 7d925ea2 | 2019-08-01 10:08:48 | [diff] [blame] | 3689 | if (!blob_url_loader_factory && params.url.SchemeIsBlob()) { |
Marijn Kruisselbrink | 8ffda44 | 2020-09-03 18:29:47 | [diff] [blame] | 3690 | // Resolve the blob URL in the storage partition associated with the target |
| 3691 | // frame. This is the storage partition the URL will be loaded in, and only |
| 3692 | // URLs that can be resolved by it should be able to access its data. |
Marijn Kruisselbrink | 0c87e6e | 2018-06-22 22:57:39 | [diff] [blame] | 3693 | blob_url_loader_factory = ChromeBlobStorageContext::URLLoaderFactoryForUrl( |
Marijn Kruisselbrink | 8ffda44 | 2020-09-03 18:29:47 | [diff] [blame] | 3694 | node->current_frame_host()->GetStoragePartition(), params.url); |
Marijn Kruisselbrink | 0c87e6e | 2018-06-22 22:57:39 | [diff] [blame] | 3695 | } |
| 3696 | |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3697 | std::unique_ptr<NavigationEntryImpl> entry; |
Tommy C. Li | 03eee77a | 2019-02-05 02:07:44 | [diff] [blame] | 3698 | // extra_headers in params are \n separated; navigation entries want \r\n. |
| 3699 | std::string extra_headers_crlf; |
| 3700 | base::ReplaceChars(params.extra_headers, "\n", "\r\n", &extra_headers_crlf); |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3701 | |
| 3702 | // For subframes, create a pending entry with a corresponding frame entry. |
| 3703 | if (!node->IsMainFrame()) { |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 3704 | if (GetLastCommittedEntry()) { |
| 3705 | entry = GetLastCommittedEntry()->Clone(); |
| 3706 | } else { |
| 3707 | // If there's no last committed entry, create an entry for about:blank |
| 3708 | // with a subframe entry for our destination. |
| 3709 | // TODO(creis): Ensure this case can't exist in https://crbug.com/524208. |
| 3710 | entry = NavigationEntryImpl::FromNavigationEntry(CreateNavigationEntry( |
| 3711 | GURL(url::kAboutBlankURL), params.referrer, params.initiator_origin, |
| 3712 | params.source_site_instance.get(), params.transition_type, |
| 3713 | params.is_renderer_initiated, extra_headers_crlf, browser_context_, |
Julie Jeongeun Kim | 5b9aff7 | 2022-05-02 02:10:17 | [diff] [blame] | 3714 | blob_url_loader_factory, false /* rewrite_virtual_urls */)); |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 3715 | } |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3716 | entry->AddOrUpdateFrameEntry( |
Nate Chapin | fbfe5af | 2021-06-10 17:22:08 | [diff] [blame] | 3717 | node, NavigationEntryImpl::UpdatePolicy::kReplace, -1, -1, "", nullptr, |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3718 | static_cast<SiteInstanceImpl*>(params.source_site_instance.get()), |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 3719 | params.url, absl::nullopt, params.referrer, params.initiator_origin, |
Miyoung Shin | 5d77f7207 | 2020-10-09 15:14:20 | [diff] [blame] | 3720 | params.redirect_chain, blink::PageState(), "GET", -1, |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 3721 | blob_url_loader_factory, nullptr /* web_bundle_navigation_info */, |
Kunihiko Sakamoto | 346a74e | 2021-03-10 08:57:48 | [diff] [blame] | 3722 | nullptr /* subresource_web_bundle_navigation_info */, |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 3723 | // If in NavigateWithoutEntry we later determine that this navigation is |
Charlie Reis | 7e2cb6d | 2021-01-26 01:27:16 | [diff] [blame] | 3724 | // a conversion of a new navigation into a reload, we will set the right |
| 3725 | // document policies there. |
Titouan Rigoudy | 6ec7040 | 2021-02-02 15:42:19 | [diff] [blame] | 3726 | nullptr /* policy_container_policies */); |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3727 | } else { |
| 3728 | // Otherwise, create a pending entry for the main frame. |
Julie Jeongeun Kim | 5b9aff7 | 2022-05-02 02:10:17 | [diff] [blame] | 3729 | // If `node` is the outermost main frame, it rewrites a virtual url in order |
| 3730 | // to adjust the original input url if needed. For inner frames such as |
| 3731 | // fenced frames or subframes, they don't rewrite urls as the urls are not |
| 3732 | // input urls by users. |
| 3733 | bool rewrite_virtual_urls = node->IsOutermostMainFrame(); |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3734 | entry = NavigationEntryImpl::FromNavigationEntry(CreateNavigationEntry( |
Lukasz Anforowicz | 435bcb58 | 2019-07-12 20:50:06 | [diff] [blame] | 3735 | params.url, params.referrer, params.initiator_origin, |
Lukasz Anforowicz | 641234d5 | 2019-11-07 21:07:10 | [diff] [blame] | 3736 | params.source_site_instance.get(), params.transition_type, |
| 3737 | params.is_renderer_initiated, extra_headers_crlf, browser_context_, |
Julie Jeongeun Kim | 5b9aff7 | 2022-05-02 02:10:17 | [diff] [blame] | 3738 | blob_url_loader_factory, rewrite_virtual_urls)); |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3739 | entry->set_source_site_instance( |
| 3740 | static_cast<SiteInstanceImpl*>(params.source_site_instance.get())); |
| 3741 | entry->SetRedirectChain(params.redirect_chain); |
| 3742 | } |
| 3743 | |
| 3744 | // Set the FTN ID (only used in non-site-per-process, for tests). |
| 3745 | entry->set_frame_tree_node_id(node->frame_tree_node_id()); |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3746 | entry->set_should_clear_history_list(params.should_clear_history_list); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3747 | entry->SetIsOverridingUserAgent(override_user_agent); |
| 3748 | entry->set_has_user_gesture(has_user_gesture); |
Robert Ogden | 011a808 | 2019-01-23 19:04:54 | [diff] [blame] | 3749 | entry->set_reload_type(params.reload_type); |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3750 | |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3751 | switch (params.load_type) { |
| 3752 | case LOAD_TYPE_DEFAULT: |
| 3753 | break; |
| 3754 | case LOAD_TYPE_HTTP_POST: |
| 3755 | entry->SetHasPostData(true); |
| 3756 | entry->SetPostData(params.post_data); |
| 3757 | break; |
| 3758 | case LOAD_TYPE_DATA: |
| 3759 | entry->SetBaseURLForDataURL(params.base_url_for_data_url); |
| 3760 | entry->SetVirtualURL(params.virtual_url_for_data_url); |
Xiaohan Wang | 7f8052e0 | 2022-01-14 18:44:28 | [diff] [blame] | 3761 | #if BUILDFLAG(IS_ANDROID) |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3762 | entry->SetDataURLAsString(params.data_url_as_string); |
| 3763 | #endif |
| 3764 | entry->SetCanLoadLocalResources(params.can_load_local_resources); |
| 3765 | break; |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3766 | } |
| 3767 | |
| 3768 | // TODO(clamy): NavigationEntry is meant for information that will be kept |
| 3769 | // after the navigation ended and therefore is not appropriate for |
| 3770 | // started_from_context_menu. Move started_from_context_menu to |
| 3771 | // NavigationUIData. |
| 3772 | entry->set_started_from_context_menu(params.started_from_context_menu); |
| 3773 | |
| 3774 | return entry; |
| 3775 | } |
| 3776 | |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3777 | std::unique_ptr<NavigationRequest> |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3778 | NavigationControllerImpl::CreateNavigationRequestFromLoadParams( |
| 3779 | FrameTreeNode* node, |
| 3780 | const LoadURLParams& params, |
| 3781 | bool override_user_agent, |
| 3782 | bool should_replace_current_entry, |
| 3783 | bool has_user_gesture, |
Antonio Sartori | 2f763d9d | 2021-04-21 10:04:14 | [diff] [blame] | 3784 | network::mojom::SourceLocationPtr source_location, |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3785 | ReloadType reload_type, |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 3786 | NavigationEntryImpl* entry, |
Tsuyoshi Horo | 167ca643 | 2022-03-09 05:16:39 | [diff] [blame] | 3787 | FrameNavigationEntry* frame_entry, |
Nan Lin | 944e9b4e | 2022-04-12 13:51:22 | [diff] [blame] | 3788 | base::TimeTicks navigation_start_time, |
Garrett Tanzer | 405f340 | 2022-07-21 20:12:49 | [diff] [blame] | 3789 | bool is_embedder_initiated_fenced_frame_navigation, |
| 3790 | bool is_unfenced_top_navigation) { |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 3791 | DCHECK_EQ(-1, GetIndexOfEntry(entry)); |
Camille Lamy | b9ed3c5 | 2018-11-19 15:34:28 | [diff] [blame] | 3792 | DCHECK(frame_entry); |
Nasko Oskov | 3c2f9e25 | 2019-01-10 17:45:53 | [diff] [blame] | 3793 | // All renderer-initiated navigations must have an initiator_origin. |
| 3794 | DCHECK(!params.is_renderer_initiated || params.initiator_origin.has_value()); |
Camille Lamy | ff7c482 | 2018-11-07 15:42:51 | [diff] [blame] | 3795 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3796 | GURL url_to_load; |
| 3797 | GURL virtual_url; |
Nasko Oskov | 0391210 | 2019-01-11 00:21:32 | [diff] [blame] | 3798 | |
Camille Lamy | 2baa802 | 2018-10-19 16:43:17 | [diff] [blame] | 3799 | // For main frames, rewrite the URL if necessary and compute the virtual URL |
| 3800 | // that should be shown in the address bar. |
Ian Vollick | 1c6dd3e | 2022-04-13 02:06:26 | [diff] [blame] | 3801 | if (node->IsOutermostMainFrame()) { |
Lukasz Anforowicz | b2eb19b1 | 2020-01-25 00:40:42 | [diff] [blame] | 3802 | bool ignored_reverse_on_redirect = false; |
Camille Lamy | 2baa802 | 2018-10-19 16:43:17 | [diff] [blame] | 3803 | RewriteUrlForNavigation(params.url, browser_context_, &url_to_load, |
Lukasz Anforowicz | b2eb19b1 | 2020-01-25 00:40:42 | [diff] [blame] | 3804 | &virtual_url, &ignored_reverse_on_redirect); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3805 | |
Camille Lamy | 2baa802 | 2018-10-19 16:43:17 | [diff] [blame] | 3806 | // For DATA loads, override the virtual URL. |
| 3807 | if (params.load_type == LOAD_TYPE_DATA) |
| 3808 | virtual_url = params.virtual_url_for_data_url; |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3809 | |
Camille Lamy | 2baa802 | 2018-10-19 16:43:17 | [diff] [blame] | 3810 | if (virtual_url.is_empty()) |
| 3811 | virtual_url = url_to_load; |
| 3812 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 3813 | CHECK(virtual_url == entry->GetVirtualURL()); |
Camille Lamy | b9ed3c5 | 2018-11-19 15:34:28 | [diff] [blame] | 3814 | |
Aran Gilman | 249eb12 | 2019-12-02 23:32:46 | [diff] [blame] | 3815 | // This is a LOG and not a CHECK/DCHECK as URL rewrite has non-deterministic |
| 3816 | // behavior: it is possible for two calls to RewriteUrlForNavigation to |
| 3817 | // return different results, leading to a different URL in the |
| 3818 | // NavigationRequest and FrameEntry. This will be fixed once we remove the |
| 3819 | // pending NavigationEntry, as we'll only make one call to |
| 3820 | // RewriteUrlForNavigation. |
| 3821 | VLOG_IF(1, (url_to_load != frame_entry->url())) |
| 3822 | << "NavigationRequest and FrameEntry have different URLs: " |
| 3823 | << url_to_load << " vs " << frame_entry->url(); |
Camille Lamy | b9ed3c5 | 2018-11-19 15:34:28 | [diff] [blame] | 3824 | |
Camille Lamy | 2baa802 | 2018-10-19 16:43:17 | [diff] [blame] | 3825 | // TODO(clamy): In order to remove the pending NavigationEntry, |
Lukasz Anforowicz | b2eb19b1 | 2020-01-25 00:40:42 | [diff] [blame] | 3826 | // |virtual_url| and |ignored_reverse_on_redirect| should be stored in the |
Camille Lamy | 2baa802 | 2018-10-19 16:43:17 | [diff] [blame] | 3827 | // NavigationRequest. |
| 3828 | } else { |
| 3829 | url_to_load = params.url; |
| 3830 | virtual_url = params.url; |
Camille Lamy | f664f762 | 2019-01-07 19:28:24 | [diff] [blame] | 3831 | CHECK(!frame_entry || url_to_load == frame_entry->url()); |
Camille Lamy | 2baa802 | 2018-10-19 16:43:17 | [diff] [blame] | 3832 | } |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3833 | |
Ehsan Karamad | 44fc7211 | 2019-02-26 18:15:47 | [diff] [blame] | 3834 | if (node->render_manager()->is_attaching_inner_delegate()) { |
| 3835 | // Avoid starting any new navigations since this node is now preparing for |
| 3836 | // attaching an inner delegate. |
| 3837 | return nullptr; |
Ehsan Karamad | dd9a414 | 2018-12-04 20:38:20 | [diff] [blame] | 3838 | } |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3839 | |
Ian Vollick | 1c6dd3e | 2022-04-13 02:06:26 | [diff] [blame] | 3840 | if (!IsValidURLForNavigation(node->IsOutermostMainFrame(), virtual_url, |
| 3841 | url_to_load)) |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3842 | return nullptr; |
| 3843 | |
danakj | d83d706d | 2020-11-25 22:11:12 | [diff] [blame] | 3844 | // Look for a pending commit that is to another document in this |
| 3845 | // FrameTreeNode. If one exists, then the last committed URL will not be the |
| 3846 | // current URL by the time this navigation commits. |
| 3847 | bool has_pending_cross_document_commit = |
| 3848 | node->render_manager()->HasPendingCommitForCrossDocumentNavigation(); |
Miyoung Shin | a2dd6a4 | 2021-10-07 12:19:21 | [diff] [blame] | 3849 | bool is_currently_error_page = node->current_frame_host()->IsErrorDocument(); |
danakj | d83d706d | 2020-11-25 22:11:12 | [diff] [blame] | 3850 | |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 3851 | blink::mojom::NavigationType navigation_type = GetNavigationType( |
danakj | b952ef1 | 2021-01-14 19:58:49 | [diff] [blame] | 3852 | /*old_url=*/node->current_url(), |
| 3853 | /*new_url=*/url_to_load, reload_type, entry, *frame_entry, |
| 3854 | has_pending_cross_document_commit, is_currently_error_page, |
Garrett Tanzer | 267c2b8 | 2022-07-26 16:53:13 | [diff] [blame] | 3855 | /*is_same_document_history_load=*/false, |
| 3856 | is_embedder_initiated_fenced_frame_navigation, |
| 3857 | is_unfenced_top_navigation); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3858 | |
| 3859 | // Create the NavigationParams based on |params|. |
| 3860 | |
Hiroki Nakagawa | 4ed6128 | 2021-06-18 05:37:23 | [diff] [blame] | 3861 | bool is_view_source_mode = entry->IsViewSourceMode(); |
| 3862 | DCHECK_EQ(is_view_source_mode, virtual_url.SchemeIs(kViewSourceScheme)); |
Charlie Harrison | 8c113a3 | 2019-01-07 16:08:29 | [diff] [blame] | 3863 | |
Antonio Sartori | 6984c74 | 2021-08-26 08:03:41 | [diff] [blame] | 3864 | blink::NavigationDownloadPolicy download_policy = params.download_policy; |
Hiroki Nakagawa | 4ed6128 | 2021-06-18 05:37:23 | [diff] [blame] | 3865 | // Update |download_policy| if the virtual URL is view-source. |
Charlie Harrison | 8c113a3 | 2019-01-07 16:08:29 | [diff] [blame] | 3866 | if (is_view_source_mode) |
Yeunjoo Choi | 3df791a | 2021-02-17 07:07:25 | [diff] [blame] | 3867 | download_policy.SetDisallowed(blink::NavigationDownloadType::kViewSource); |
Charlie Harrison | 8c113a3 | 2019-01-07 16:08:29 | [diff] [blame] | 3868 | |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 3869 | blink::mojom::CommonNavigationParamsPtr common_params = |
| 3870 | blink::mojom::CommonNavigationParams::New( |
Lucas Furukawa Gadani | ef8290a | 2019-07-29 20:27:51 | [diff] [blame] | 3871 | url_to_load, params.initiator_origin, |
| 3872 | blink::mojom::Referrer::New(params.referrer.url, |
| 3873 | params.referrer.policy), |
Scott Violet | cf6ea7e | 2021-06-09 21:09:21 | [diff] [blame] | 3874 | params.transition_type, navigation_type, download_policy, |
Lucas Furukawa Gadani | ef8290a | 2019-07-29 20:27:51 | [diff] [blame] | 3875 | should_replace_current_entry, params.base_url_for_data_url, |
Tsuyoshi Horo | 167ca643 | 2022-03-09 05:16:39 | [diff] [blame] | 3876 | navigation_start_time, |
Lucas Furukawa Gadani | ef8290a | 2019-07-29 20:27:51 | [diff] [blame] | 3877 | params.load_type == LOAD_TYPE_HTTP_POST ? "POST" : "GET", |
Antonio Sartori | 2f763d9d | 2021-04-21 10:04:14 | [diff] [blame] | 3878 | params.post_data, std::move(source_location), |
arthursonzogni | af7c62c5 | 2020-02-12 10:49:41 | [diff] [blame] | 3879 | params.started_from_context_menu, has_user_gesture, |
Antonio Sartori | 636adba | 2021-03-09 12:15:27 | [diff] [blame] | 3880 | false /* has_text_fragment_token */, |
| 3881 | network::mojom::CSPDisposition::CHECK, std::vector<int>(), |
| 3882 | params.href_translate, |
Lucas Furukawa Gadani | ef8290a | 2019-07-29 20:27:51 | [diff] [blame] | 3883 | false /* is_history_navigation_in_new_child_frame */, |
Nan Lin | d91c815 | 2021-10-21 16:22:37 | [diff] [blame] | 3884 | params.input_start, network::mojom::RequestDestination::kEmpty); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3885 | |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 3886 | blink::mojom::CommitNavigationParamsPtr commit_params = |
| 3887 | blink::mojom::CommitNavigationParams::New( |
Rakina Zata Amni | c736785 | 2022-11-07 17:10:40 | [diff] [blame] | 3888 | absl::nullopt, |
Antonio Sartori | 3e8de6d | 2021-07-26 10:28:41 | [diff] [blame] | 3889 | // The correct storage key will be computed before committing the |
| 3890 | // navigation. |
Pâris Meuleman | 4d97a70 | 2022-07-05 10:42:00 | [diff] [blame] | 3891 | blink::StorageKey(), override_user_agent, params.redirect_chain, |
Lucas Furukawa Gadani | 81e294b | 2019-08-29 16:26:32 | [diff] [blame] | 3892 | std::vector<network::mojom::URLResponseHeadPtr>(), |
jongdeok.kim | 5de823b3 | 2022-06-14 04:37:50 | [diff] [blame] | 3893 | std::vector<net::RedirectInfo>(), params.post_content_type, |
| 3894 | common_params->url, common_params->method, |
| 3895 | params.can_load_local_resources, |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 3896 | frame_entry->page_state().ToEncodedData(), entry->GetUniqueID(), |
Lucas Furukawa Gadani | a9c4568 | 2019-07-31 22:05:14 | [diff] [blame] | 3897 | entry->GetSubframeUniqueNames(node), true /* intended_as_new_entry */, |
| 3898 | -1 /* pending_history_list_offset */, |
| 3899 | params.should_clear_history_list ? -1 : GetLastCommittedEntryIndex(), |
| 3900 | params.should_clear_history_list ? 0 : GetEntryCount(), |
| 3901 | false /* was_discarded */, is_view_source_mode, |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 3902 | params.should_clear_history_list, |
| 3903 | blink::mojom::NavigationTiming::New(), |
Minggang Wang | f59db47b | 2021-06-16 01:56:22 | [diff] [blame] | 3904 | blink::mojom::WasActivatedOption::kUnknown, |
Lucas Furukawa Gadani | a9c4568 | 2019-07-31 22:05:14 | [diff] [blame] | 3905 | base::UnguessableToken::Create() /* navigation_token */, |
Minggang Wang | 7ee0c74 | 2021-06-16 16:16:51 | [diff] [blame] | 3906 | std::vector<blink::mojom::PrefetchedSignedExchangeInfoPtr>(), |
Xiaohan Wang | 7f8052e0 | 2022-01-14 18:44:28 | [diff] [blame] | 3907 | #if BUILDFLAG(IS_ANDROID) |
Lucas Furukawa Gadani | a9c4568 | 2019-07-31 22:05:14 | [diff] [blame] | 3908 | std::string(), /* data_url_as_string */ |
| 3909 | #endif |
arthursonzogni | 1437978 | 2020-05-15 09:09:27 | [diff] [blame] | 3910 | !params.is_renderer_initiated, /* is_browser_initiated */ |
Tsuyoshi Horo | e86d770 | 2019-11-29 01:52:47 | [diff] [blame] | 3911 | GURL() /* web_bundle_physical_url */, |
Charlie Hu | 5ffc015 | 2019-12-06 15:59:53 | [diff] [blame] | 3912 | GURL() /* base_url_override_for_web_bundle */, |
Yue Ru Sun | 12880493 | 2020-09-30 22:19:17 | [diff] [blame] | 3913 | ukm::kInvalidSourceId /* document_ukm_source_id */, |
Jiewei Qian | 0406fc0 | 2020-03-09 06:02:07 | [diff] [blame] | 3914 | node->pending_frame_policy(), |
Domenic Denicola | 4778c3539 | 2020-06-25 21:25:16 | [diff] [blame] | 3915 | std::vector<std::string>() /* force_enabled_origin_trials */, |
Domenic Denicola | 55701ee | 2021-01-14 00:18:33 | [diff] [blame] | 3916 | false /* origin_agent_cluster */, |
Daniel Vogelheim | 243df9f | 2022-02-22 10:32:03 | [diff] [blame] | 3917 | true /* origin_agent_cluster_left_as_default */, |
Maks Orlovich | c66745a | 2020-06-30 17:40:02 | [diff] [blame] | 3918 | std::vector< |
Shuran Huang | a055ce7 | 2020-07-23 14:13:21 | [diff] [blame] | 3919 | network::mojom::WebClientHintsType>() /* enabled_client_hints */, |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 3920 | false /* is_cross_browsing_instance */, nullptr /* old_page_info */, |
| 3921 | -1 /* http_response_code */, |
Domenic Denicola | cd30f5f8 | 2022-03-16 21:48:01 | [diff] [blame] | 3922 | blink::mojom::NavigationApiHistoryEntryArrays::New(), |
Matt Menke | 4e20908 | 2021-11-09 04:59:31 | [diff] [blame] | 3923 | std::vector<GURL>() /* early_hints_preloaded_resources */, |
Clark DuVall | 8ee487a2 | 2021-11-10 02:25:58 | [diff] [blame] | 3924 | absl::nullopt /* ad_auction_components */, |
shivanigithub | c7b97ca | 2022-04-05 19:41:40 | [diff] [blame] | 3925 | /*fenced_frame_reporting_metadata=*/nullptr, |
Clark DuVall | 8ee487a2 | 2021-11-10 02:25:58 | [diff] [blame] | 3926 | // This timestamp will be populated when the commit IPC is sent. |
Arthur Sonzogni | e41678a | 2022-06-16 15:51:19 | [diff] [blame] | 3927 | base::TimeTicks() /* commit_sent */, std::string() /* srcdoc_value */, |
W. James MacLean | b7d609268 | 2022-10-05 15:23:26 | [diff] [blame] | 3928 | GURL() /* fallback_srcdoc_baseurl_value */, |
Liam Brady | d2a41e15 | 2022-07-19 13:58:48 | [diff] [blame] | 3929 | false /* should_load_data_url */, |
Victor Tan | 10d93aca | 2022-08-12 16:46:28 | [diff] [blame] | 3930 | /*ancestor_or_self_has_cspee=*/node->AncestorOrSelfHasCSPEE(), |
William Liu | 2c82547 | 2022-10-31 12:01:44 | [diff] [blame] | 3931 | std::string() /* reduced_accept_language */, |
| 3932 | /*navigation_delivery_type=*/ |
Khushal Sagar | 7b26135c6 | 2022-11-08 20:25:42 | [diff] [blame] | 3933 | network::mojom::NavigationDeliveryType::kDefault, |
| 3934 | /*view_transition_state=*/absl::nullopt); |
Xiaohan Wang | 7f8052e0 | 2022-01-14 18:44:28 | [diff] [blame] | 3935 | #if BUILDFLAG(IS_ANDROID) |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3936 | if (ValidateDataURLAsString(params.data_url_as_string)) { |
Lucas Furukawa Gadani | a9c4568 | 2019-07-31 22:05:14 | [diff] [blame] | 3937 | commit_params->data_url_as_string = params.data_url_as_string->data(); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3938 | } |
| 3939 | #endif |
| 3940 | |
Lucas Furukawa Gadani | a9c4568 | 2019-07-31 22:05:14 | [diff] [blame] | 3941 | commit_params->was_activated = params.was_activated; |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3942 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3943 | // extra_headers in params are \n separated; NavigationRequests want \r\n. |
| 3944 | std::string extra_headers_crlf; |
| 3945 | base::ReplaceChars(params.extra_headers, "\n", "\r\n", &extra_headers_crlf); |
Yao Xiao | dc5ed10 | 2019-06-04 19:19:09 | [diff] [blame] | 3946 | |
| 3947 | auto navigation_request = NavigationRequest::CreateBrowserInitiated( |
Lucas Furukawa Gadani | a9c4568 | 2019-07-31 22:05:14 | [diff] [blame] | 3948 | node, std::move(common_params), std::move(commit_params), |
Takashi Toyoshima | e87b7be | 2021-01-22 11:51:08 | [diff] [blame] | 3949 | !params.is_renderer_initiated, params.was_opener_suppressed, |
Antonio Sartori | 9a82f6f3 | 2020-12-14 09:22:45 | [diff] [blame] | 3950 | params.initiator_frame_token.has_value() |
| 3951 | ? &(params.initiator_frame_token.value()) |
| 3952 | : nullptr, |
| 3953 | params.initiator_process_id, extra_headers_crlf, frame_entry, entry, |
jongdeok.kim | 5de823b3 | 2022-06-14 04:37:50 | [diff] [blame] | 3954 | params.is_form_submission, |
John Delaney | 50425f8 | 2020-04-07 16:26:21 | [diff] [blame] | 3955 | params.navigation_ui_data ? params.navigation_ui_data->Clone() : nullptr, |
Garrett Tanzer | 4785246 | 2022-07-20 18:16:41 | [diff] [blame] | 3956 | params.impression, params.is_pdf, |
| 3957 | is_embedder_initiated_fenced_frame_navigation); |
Yao Xiao | dc5ed10 | 2019-06-04 19:19:09 | [diff] [blame] | 3958 | navigation_request->set_from_download_cross_origin_redirect( |
| 3959 | params.from_download_cross_origin_redirect); |
W. James MacLean | 00568d7 | 2022-02-24 19:36:55 | [diff] [blame] | 3960 | navigation_request->set_force_new_browsing_instance( |
| 3961 | params.force_new_browsing_instance); |
Yao Xiao | dc5ed10 | 2019-06-04 19:19:09 | [diff] [blame] | 3962 | return navigation_request; |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3963 | } |
| 3964 | |
| 3965 | std::unique_ptr<NavigationRequest> |
| 3966 | NavigationControllerImpl::CreateNavigationRequestFromEntry( |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3967 | FrameTreeNode* frame_tree_node, |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 3968 | NavigationEntryImpl* entry, |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3969 | FrameNavigationEntry* frame_entry, |
| 3970 | ReloadType reload_type, |
| 3971 | bool is_same_document_history_load, |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 3972 | bool is_history_navigation_in_new_child_frame, |
| 3973 | bool is_browser_initiated) { |
Alex Moshchuk | 47d1a4bd | 2020-06-01 22:15:34 | [diff] [blame] | 3974 | DCHECK(frame_entry); |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3975 | GURL dest_url = frame_entry->url(); |
Rakina Zata Amni | f297a80 | 2022-01-18 03:53:43 | [diff] [blame] | 3976 | // We should never navigate to an existing initial NavigationEntry that is the |
| 3977 | // initial NavigationEntry for the initial empty document that hasn't been |
| 3978 | // overridden by the synchronous about:blank commit, to preserve previous |
| 3979 | // behavior where trying to reload when the main frame is on the initial empty |
| 3980 | // document won't result in a navigation. |
| 3981 | // See also https://crbug.com/1277414. |
| 3982 | DCHECK(!entry->IsInitialEntryNotForSynchronousAboutBlank()); |
Nasko Oskov | 0391210 | 2019-01-11 00:21:32 | [diff] [blame] | 3983 | |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3984 | Referrer dest_referrer = frame_entry->referrer(); |
Ryan Sturm | c4da199 | 2018-07-17 16:59:01 | [diff] [blame] | 3985 | if (reload_type == ReloadType::ORIGINAL_REQUEST_URL && |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 3986 | entry->GetOriginalRequestURL().is_valid() && !entry->GetHasPostData()) { |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3987 | // We may have been redirected when navigating to the current URL. |
| 3988 | // Use the URL the user originally intended to visit as signaled by the |
| 3989 | // ReloadType, if it's valid and if a POST wasn't involved; the latter |
Ryan Sturm | c4da199 | 2018-07-17 16:59:01 | [diff] [blame] | 3990 | // case avoids issues with sending data to the wrong page. |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 3991 | dest_url = entry->GetOriginalRequestURL(); |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3992 | dest_referrer = Referrer(); |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3993 | } |
| 3994 | |
Ehsan Karamad | 44fc7211 | 2019-02-26 18:15:47 | [diff] [blame] | 3995 | if (frame_tree_node->render_manager()->is_attaching_inner_delegate()) { |
| 3996 | // Avoid starting any new navigations since this node is now preparing for |
| 3997 | // attaching an inner delegate. |
| 3998 | return nullptr; |
Ehsan Karamad | dd9a414 | 2018-12-04 20:38:20 | [diff] [blame] | 3999 | } |
| 4000 | |
Ian Vollick | 1c6dd3e | 2022-04-13 02:06:26 | [diff] [blame] | 4001 | if (!IsValidURLForNavigation(frame_tree_node->IsOutermostMainFrame(), |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 4002 | entry->GetVirtualURL(), dest_url)) { |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 4003 | return nullptr; |
| 4004 | } |
| 4005 | |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 4006 | // This will be used to set the Navigation Timing API navigationStart |
| 4007 | // parameter for browser navigations in new tabs (intents, tabs opened through |
| 4008 | // "Open link in new tab"). If the navigation must wait on the current |
| 4009 | // RenderFrameHost to execute its BeforeUnload event, the navigation start |
| 4010 | // will be updated when the BeforeUnload ack is received. |
| 4011 | base::TimeTicks navigation_start = base::TimeTicks::Now(); |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 4012 | |
danakj | d83d706d | 2020-11-25 22:11:12 | [diff] [blame] | 4013 | // Look for a pending commit that is to another document in this |
| 4014 | // FrameTreeNode. If one exists, then the last committed URL will not be the |
| 4015 | // current URL by the time this navigation commits. |
| 4016 | bool has_pending_cross_document_commit = |
| 4017 | frame_tree_node->render_manager() |
| 4018 | ->HasPendingCommitForCrossDocumentNavigation(); |
danakj | b952ef1 | 2021-01-14 19:58:49 | [diff] [blame] | 4019 | bool is_currently_error_page = |
Miyoung Shin | a2dd6a4 | 2021-10-07 12:19:21 | [diff] [blame] | 4020 | frame_tree_node->current_frame_host()->IsErrorDocument(); |
danakj | d83d706d | 2020-11-25 22:11:12 | [diff] [blame] | 4021 | |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 4022 | blink::mojom::NavigationType navigation_type = GetNavigationType( |
danakj | d83d706d | 2020-11-25 22:11:12 | [diff] [blame] | 4023 | /*old_url=*/frame_tree_node->current_url(), |
| 4024 | /*new_url=*/dest_url, reload_type, entry, *frame_entry, |
danakj | b952ef1 | 2021-01-14 19:58:49 | [diff] [blame] | 4025 | has_pending_cross_document_commit, is_currently_error_page, |
Garrett Tanzer | 405f340 | 2022-07-21 20:12:49 | [diff] [blame] | 4026 | is_same_document_history_load, |
Garrett Tanzer | 267c2b8 | 2022-07-26 16:53:13 | [diff] [blame] | 4027 | /*is_embedder_initiated_fenced_frame_navigation=*/false, |
Garrett Tanzer | 405f340 | 2022-07-21 20:12:49 | [diff] [blame] | 4028 | /*is_unfenced_top_navigation=*/false); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 4029 | |
| 4030 | // A form submission may happen here if the navigation is a |
| 4031 | // back/forward/reload navigation that does a form resubmission. |
| 4032 | scoped_refptr<network::ResourceRequestBody> request_body; |
| 4033 | std::string post_content_type; |
jongdeok.kim | 5de823b3 | 2022-06-14 04:37:50 | [diff] [blame] | 4034 | // TODO(https://crbug.com/931209) Store |is_form_submission| in the history |
| 4035 | // entry. This way, it could be directly retrieved here. Right now, it is only |
| 4036 | // partially recovered when request.method == "POST" and request.body exists. |
| 4037 | bool is_form_submission = false; |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 4038 | if (frame_entry->method() == "POST") { |
| 4039 | request_body = frame_entry->GetPostData(&post_content_type); |
| 4040 | // Might have a LF at end. |
Peter Kasting | b53b8191 | 2021-04-28 19:23:30 | [diff] [blame] | 4041 | post_content_type = std::string( |
| 4042 | base::TrimWhitespaceASCII(post_content_type, base::TRIM_ALL)); |
jongdeok.kim | 5de823b3 | 2022-06-14 04:37:50 | [diff] [blame] | 4043 | is_form_submission = !!request_body; |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 4044 | } |
| 4045 | |
| 4046 | // Create the NavigationParams based on |entry| and |frame_entry|. |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 4047 | blink::mojom::CommonNavigationParamsPtr common_params = |
Lucas Furukawa Gadani | ef8290a | 2019-07-29 20:27:51 | [diff] [blame] | 4048 | entry->ConstructCommonNavigationParams( |
| 4049 | *frame_entry, request_body, dest_url, |
| 4050 | blink::mojom::Referrer::New(dest_referrer.url, dest_referrer.policy), |
Tarun Bansal | bcd62c8 | 2022-01-18 17:27:38 | [diff] [blame] | 4051 | navigation_type, navigation_start, |
Charlie Hu | 5ffc015 | 2019-12-06 15:59:53 | [diff] [blame] | 4052 | base::TimeTicks() /* input_start */); |
Lucas Furukawa Gadani | ef8290a | 2019-07-29 20:27:51 | [diff] [blame] | 4053 | common_params->is_history_navigation_in_new_child_frame = |
Arthur Hemery | bee4a75 | 2019-05-29 10:50:55 | [diff] [blame] | 4054 | is_history_navigation_in_new_child_frame; |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 4055 | |
| 4056 | // TODO(clamy): |intended_as_new_entry| below should always be false once |
| 4057 | // Reload no longer leads to this being called for a pending NavigationEntry |
| 4058 | // of index -1. |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 4059 | blink::mojom::CommitNavigationParamsPtr commit_params = |
Lucas Furukawa Gadani | a9c4568 | 2019-07-31 22:05:14 | [diff] [blame] | 4060 | entry->ConstructCommitNavigationParams( |
Rakina Zata Amni | c736785 | 2022-11-07 17:10:40 | [diff] [blame] | 4061 | *frame_entry, common_params->url, common_params->method, |
| 4062 | entry->GetSubframeUniqueNames(frame_tree_node), |
Lucas Furukawa Gadani | a9c4568 | 2019-07-31 22:05:14 | [diff] [blame] | 4063 | GetPendingEntryIndex() == -1 /* intended_as_new_entry */, |
Charlie Hu | 5ffc015 | 2019-12-06 15:59:53 | [diff] [blame] | 4064 | GetIndexOfEntry(entry), GetLastCommittedEntryIndex(), GetEntryCount(), |
Liam Brady | d2a41e15 | 2022-07-19 13:58:48 | [diff] [blame] | 4065 | frame_tree_node->pending_frame_policy(), |
| 4066 | frame_tree_node->AncestorOrSelfHasCSPEE()); |
Lucas Furukawa Gadani | a9c4568 | 2019-07-31 22:05:14 | [diff] [blame] | 4067 | commit_params->post_content_type = post_content_type; |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 4068 | |
W. James MacLean | b7d609268 | 2022-10-05 15:23:26 | [diff] [blame] | 4069 | if (common_params->url.IsAboutSrcdoc()) { |
| 4070 | // TODO(wjmaclean): initialize this in NavigationRequest's constructor |
| 4071 | // instead. |
W. James MacLean | 81b8d01f | 2022-01-25 20:50:59 | [diff] [blame] | 4072 | commit_params->srcdoc_value = frame_tree_node->srcdoc_value(); |
W. James MacLean | b7d609268 | 2022-10-05 15:23:26 | [diff] [blame] | 4073 | } |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 4074 | return NavigationRequest::CreateBrowserInitiated( |
Lucas Furukawa Gadani | a9c4568 | 2019-07-31 22:05:14 | [diff] [blame] | 4075 | frame_tree_node, std::move(common_params), std::move(commit_params), |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 4076 | is_browser_initiated, false /* was_opener_suppressed */, |
Takashi Toyoshima | e87b7be | 2021-01-22 11:51:08 | [diff] [blame] | 4077 | nullptr /* initiator_frame_token */, |
Antonio Sartori | 9a82f6f3 | 2020-12-14 09:22:45 | [diff] [blame] | 4078 | ChildProcessHost::kInvalidUniqueID /* initiator_process_id */, |
jongdeok.kim | 5de823b3 | 2022-06-14 04:37:50 | [diff] [blame] | 4079 | entry->extra_headers(), frame_entry, entry, is_form_submission, |
Daniel Hosseinian | f0fbfb4 | 2021-09-08 02:20:47 | [diff] [blame] | 4080 | nullptr /* navigation_ui_data */, absl::nullopt /* impression */, |
| 4081 | false /* is_pdf */); |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 4082 | } |
| 4083 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 4084 | void NavigationControllerImpl::NotifyNavigationEntryCommitted( |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4085 | LoadCommittedDetails* details) { |
[email protected] | 6286a379 | 2013-10-09 04:03:27 | [diff] [blame] | 4086 | details->entry = GetLastCommittedEntry(); |
[email protected] | df1af24 | 2009-05-01 00:11:40 | [diff] [blame] | 4087 | |
Takashi Toyoshima | ea534ef2 | 2021-07-21 03:27:59 | [diff] [blame] | 4088 | // We need to notify the ssl_manager_ before the WebContents so the |
[email protected] | df1af24 | 2009-05-01 00:11:40 | [diff] [blame] | 4089 | // location bar will have up-to-date information about the security style |
| 4090 | // when it wants to draw. See http://crbug.com/11157 |
[email protected] | b0f724c | 2013-09-05 04:21:13 | [diff] [blame] | 4091 | ssl_manager_.DidCommitProvisionalLoad(*details); |
[email protected] | df1af24 | 2009-05-01 00:11:40 | [diff] [blame] | 4092 | |
Abhijeet Kandalkar | 3dc6e60 | 2022-11-09 05:08:37 | [diff] [blame^] | 4093 | delegate_->NotifyNavigationStateChangedFromController(INVALIDATE_TYPE_ALL); |
[email protected] | ec6c05f | 2013-10-23 18:41:57 | [diff] [blame] | 4094 | delegate_->NotifyNavigationEntryCommitted(*details); |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 4095 | |
[email protected] | b0f724c | 2013-09-05 04:21:13 | [diff] [blame] | 4096 | // TODO(avi): Remove. http://crbug.com/170921 |
| 4097 | NotificationDetails notification_details = |
| 4098 | Details<LoadCommittedDetails>(details); |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 4099 | NotificationService::current()->Notify(NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 4100 | Source<NavigationController>(this), |
| 4101 | notification_details); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4102 | } |
| 4103 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4104 | // static |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 4105 | size_t NavigationControllerImpl::max_entry_count() { |
[email protected] | 9b51970d | 2011-12-09 23:10:23 | [diff] [blame] | 4106 | if (max_entry_count_for_testing_ != kMaxEntryCountForTestingNotSet) |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 4107 | return max_entry_count_for_testing_; |
Miyoung Shin | 1c565c91 | 2021-03-17 12:11:21 | [diff] [blame] | 4108 | return blink::kMaxSessionHistoryEntries; |
[email protected] | 9b51970d | 2011-12-09 23:10:23 | [diff] [blame] | 4109 | } |
| 4110 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 4111 | void NavigationControllerImpl::SetActive(bool is_active) { |
[email protected] | ee61392 | 2009-09-02 20:38:22 | [diff] [blame] | 4112 | if (is_active && needs_reload_) |
| 4113 | LoadIfNecessary(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4114 | } |
| 4115 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 4116 | void NavigationControllerImpl::LoadIfNecessary() { |
Rakina Zata Amni | d605d46 | 2022-06-01 10:17:03 | [diff] [blame] | 4117 | SCOPED_CRASH_KEY_BOOL("nav_reentrancy_caller1", "LoadIf_pending", |
| 4118 | !!pending_entry_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4119 | if (!needs_reload_) |
| 4120 | return; |
| 4121 | |
Bo Liu | cdfa4b1 | 2018-11-06 00:21:44 | [diff] [blame] | 4122 | UMA_HISTOGRAM_ENUMERATION("Navigation.LoadIfNecessaryType", |
| 4123 | needs_reload_type_); |
| 4124 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4125 | // Calling Reload() results in ignoring state, and not loading. |
| 4126 | // Explicitly use NavigateToPendingEntry so that the renderer uses the |
| 4127 | // cached state. |
avi | cc872d724 | 2015-08-19 21:26:34 | [diff] [blame] | 4128 | if (pending_entry_) { |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 4129 | NavigateToExistingPendingEntry(ReloadType::NONE, |
Nate Chapin | bf682fa3 | 2022-09-26 22:41:20 | [diff] [blame] | 4130 | nullptr /* initiator_frame */, |
| 4131 | nullptr /* navigation_api_key */); |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 4132 | } else if (last_committed_entry_index_ != -1 && |
| 4133 | !GetLastCommittedEntry() |
Rakina Zata Amni | f297a80 | 2022-01-18 03:53:43 | [diff] [blame] | 4134 | ->IsInitialEntryNotForSynchronousAboutBlank()) { |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 4135 | pending_entry_ = entries_[last_committed_entry_index_].get(); |
avi | cc872d724 | 2015-08-19 21:26:34 | [diff] [blame] | 4136 | pending_entry_index_ = last_committed_entry_index_; |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 4137 | NavigateToExistingPendingEntry(ReloadType::NONE, |
Nate Chapin | bf682fa3 | 2022-09-26 22:41:20 | [diff] [blame] | 4138 | nullptr /* initiator_frame */, |
| 4139 | nullptr /* navigation_api_key */); |
avi | cc872d724 | 2015-08-19 21:26:34 | [diff] [blame] | 4140 | } else { |
Rakina Zata Amni | f297a80 | 2022-01-18 03:53:43 | [diff] [blame] | 4141 | // We should never navigate to an existing initial NavigationEntry that is |
| 4142 | // the initial NavigationEntry for the initial empty document that hasn't |
| 4143 | // been overridden by the synchronous about:blank commit, to preserve |
| 4144 | // legacy behavior where trying to reload when the main frame is on the |
| 4145 | // initial empty document won't result in a navigation. See also |
| 4146 | // https://crbug.com/1277414. If there is something to reload, the |
| 4147 | // successful reload will clear the |needs_reload_| flag. Otherwise, just do |
| 4148 | // it here. |
avi | cc872d724 | 2015-08-19 21:26:34 | [diff] [blame] | 4149 | needs_reload_ = false; |
| 4150 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4151 | } |
| 4152 | |
Kevin McNee | ccca617 | 2021-10-19 17:11:14 | [diff] [blame] | 4153 | base::WeakPtr<NavigationHandle> |
| 4154 | NavigationControllerImpl::LoadPostCommitErrorPage( |
Carlos IL | 42b41659 | 2019-10-07 23:10:36 | [diff] [blame] | 4155 | RenderFrameHost* render_frame_host, |
| 4156 | const GURL& url, |
| 4157 | const std::string& error_page_html, |
| 4158 | net::Error error) { |
Rakina Zata Amni | 919b792 | 2020-12-11 09:03:13 | [diff] [blame] | 4159 | RenderFrameHostImpl* rfhi = |
| 4160 | static_cast<RenderFrameHostImpl*>(render_frame_host); |
Sreeja Kamishetty | db8e289 | 2021-03-10 09:30:58 | [diff] [blame] | 4161 | |
| 4162 | // Only active documents can load post-commit error pages: |
| 4163 | // - If the document is in pending deletion, the browser already committed to |
| 4164 | // destroying this RenderFrameHost so ignore loading the error page. |
| 4165 | // - If the document is in back-forward cache, it's not allowed to navigate as |
| 4166 | // it should remain frozen. Ignore the request and evict the document from |
| 4167 | // back-forward cache. |
| 4168 | // - If the document is prerendering, it can navigate but when loading error |
| 4169 | // pages, cancel prerendering. |
Fergal Daly | 1336ac64 | 2021-09-14 15:13:11 | [diff] [blame] | 4170 | if (rfhi->IsInactiveAndDisallowActivation( |
| 4171 | DisallowActivationReasonId::kLoadPostCommitErrorPage)) { |
Kevin McNee | ccca617 | 2021-10-19 17:11:14 | [diff] [blame] | 4172 | return nullptr; |
Fergal Daly | 1336ac64 | 2021-09-14 15:13:11 | [diff] [blame] | 4173 | } |
Sreeja Kamishetty | db8e289 | 2021-03-10 09:30:58 | [diff] [blame] | 4174 | |
Rakina Zata Amni | 919b792 | 2020-12-11 09:03:13 | [diff] [blame] | 4175 | FrameTreeNode* node = rfhi->frame_tree_node(); |
John Delaney | 131ad36 | 2019-08-08 21:57:41 | [diff] [blame] | 4176 | |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 4177 | blink::mojom::CommonNavigationParamsPtr common_params = |
Minggang Wang | a13c796e | 2021-07-02 05:54:43 | [diff] [blame] | 4178 | blink::CreateCommonNavigationParams(); |
Rakina Zata Amni | d2da154 | 2020-12-23 00:52:59 | [diff] [blame] | 4179 | // |url| might be empty, such as when LoadPostCommitErrorPage happens before |
| 4180 | // the frame actually committed (e.g. iframe with "src" set to a |
| 4181 | // slow-responding URL). We should rewrite the URL to about:blank in this |
| 4182 | // case, as the renderer will only think a page is an error page if it has a |
| 4183 | // non-empty unreachable URL. |
Rakina Zata Amni | 919b792 | 2020-12-11 09:03:13 | [diff] [blame] | 4184 | common_params->url = url.is_empty() ? GURL("about:blank") : url; |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 4185 | blink::mojom::CommitNavigationParamsPtr commit_params = |
Minggang Wang | a13c796e | 2021-07-02 05:54:43 | [diff] [blame] | 4186 | blink::CreateCommitNavigationParams(); |
Antonio Sartori | 58591c89 | 2021-04-21 06:54:33 | [diff] [blame] | 4187 | commit_params->original_url = common_params->url; |
John Delaney | 131ad36 | 2019-08-08 21:57:41 | [diff] [blame] | 4188 | |
arthursonzogni | 70ac730 | 2020-05-28 08:49:05 | [diff] [blame] | 4189 | // Error pages have a fully permissive FramePolicy. |
| 4190 | // TODO(arthursonzogni): Consider providing the minimal capabilities to the |
| 4191 | // error pages. |
| 4192 | commit_params->frame_policy = blink::FramePolicy(); |
| 4193 | |
John Delaney | 131ad36 | 2019-08-08 21:57:41 | [diff] [blame] | 4194 | std::unique_ptr<NavigationRequest> navigation_request = |
| 4195 | NavigationRequest::CreateBrowserInitiated( |
| 4196 | node, std::move(common_params), std::move(commit_params), |
Takashi Toyoshima | e87b7be | 2021-01-22 11:51:08 | [diff] [blame] | 4197 | true /* browser_initiated */, false /* was_opener_suppressed */, |
Lingqi Chi | 82efa95e | 2020-12-29 05:31:19 | [diff] [blame] | 4198 | nullptr /* initiator_frame_token */, |
Antonio Sartori | 9a82f6f3 | 2020-12-14 09:22:45 | [diff] [blame] | 4199 | ChildProcessHost::kInvalidUniqueID /* initiator_process_id */, |
John Delaney | f43556d | 2020-05-04 23:19:06 | [diff] [blame] | 4200 | "" /* extra_headers */, nullptr /* frame_entry */, |
jongdeok.kim | 5de823b3 | 2022-06-14 04:37:50 | [diff] [blame] | 4201 | nullptr /* entry */, false /* is_form_submission */, |
Daniel Hosseinian | f0fbfb4 | 2021-09-08 02:20:47 | [diff] [blame] | 4202 | nullptr /* navigation_ui_data */, absl::nullopt /* impression */, |
| 4203 | false /* is_pdf */); |
Carlos IL | 42b41659 | 2019-10-07 23:10:36 | [diff] [blame] | 4204 | navigation_request->set_post_commit_error_page_html(error_page_html); |
John Delaney | 131ad36 | 2019-08-08 21:57:41 | [diff] [blame] | 4205 | navigation_request->set_net_error(error); |
| 4206 | node->CreatedNavigationRequest(std::move(navigation_request)); |
| 4207 | DCHECK(node->navigation_request()); |
Kevin McNee | ccca617 | 2021-10-19 17:11:14 | [diff] [blame] | 4208 | |
| 4209 | // Calling BeginNavigation may destroy the NavigationRequest. |
| 4210 | base::WeakPtr<NavigationRequest> created_navigation_request( |
| 4211 | node->navigation_request()->GetWeakPtr()); |
John Delaney | 131ad36 | 2019-08-08 21:57:41 | [diff] [blame] | 4212 | node->navigation_request()->BeginNavigation(); |
Kevin McNee | ccca617 | 2021-10-19 17:11:14 | [diff] [blame] | 4213 | return created_navigation_request; |
John Delaney | 131ad36 | 2019-08-08 21:57:41 | [diff] [blame] | 4214 | } |
| 4215 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 4216 | void NavigationControllerImpl::NotifyEntryChanged(NavigationEntry* entry) { |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4217 | EntryChangedDetails det; |
[email protected] | 534e54b | 2008-08-13 15:40:09 | [diff] [blame] | 4218 | det.changed_entry = entry; |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 4219 | det.index = GetIndexOfEntry(NavigationEntryImpl::FromNavigationEntry(entry)); |
Sam McNally | 5c087a3 | 2017-08-25 01:46:14 | [diff] [blame] | 4220 | delegate_->NotifyNavigationEntryChanged(det); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4221 | } |
| 4222 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 4223 | void NavigationControllerImpl::FinishRestore(int selected_index, |
[email protected] | 2ca1ea66 | 2012-10-04 02:26:36 | [diff] [blame] | 4224 | RestoreType type) { |
Charlie Reis | 23c26da | 2022-01-29 00:57:47 | [diff] [blame] | 4225 | // TODO(https://crbug.com/1287624): Don't allow an index of -1, which would |
| 4226 | // represent a no-committed-entry state. |
| 4227 | DCHECK(selected_index >= -1 && selected_index < GetEntryCount()); |
[email protected] | 2ca1ea66 | 2012-10-04 02:26:36 | [diff] [blame] | 4228 | ConfigureEntriesForRestore(&entries_, type); |
Charlie Reis | 23c26da | 2022-01-29 00:57:47 | [diff] [blame] | 4229 | // TODO(https://crbug.com/1287624): This will be pointing to the wrong entry |
| 4230 | // if `entries_` contains pre-existing entries from the NavigationController |
| 4231 | // before restore, which would not be removed and will be at the front of the |
| 4232 | // entries list, causing the index to be off by the amount of pre-existing |
| 4233 | // entries in the list. Fix this to point to the correct entry. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4234 | last_committed_entry_index_ = selected_index; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4235 | } |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 4236 | |
arthursonzogni | 69a6a1b | 2019-09-17 09:23:00 | [diff] [blame] | 4237 | void NavigationControllerImpl::DiscardNonCommittedEntries() { |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 4238 | DiscardNonCommittedEntriesWithCommitDetails(nullptr /* commit_details */); |
| 4239 | } |
| 4240 | |
| 4241 | void NavigationControllerImpl::DiscardNonCommittedEntriesWithCommitDetails( |
| 4242 | LoadCommittedDetails* commit_details) { |
Michael Thiessen | 9b14d51 | 2019-09-23 21:19:47 | [diff] [blame] | 4243 | // Avoid sending a notification if there is nothing to discard. |
Michael Thiessen | c5676d2 | 2019-09-25 22:32:10 | [diff] [blame] | 4244 | // TODO(mthiesse): Temporarily checking failed_pending_entry_id_ to help |
| 4245 | // diagnose https://bugs.chromium.org/p/chromium/issues/detail?id=1007570. |
Carlos IL | 4dea890 | 2020-05-26 15:14:29 | [diff] [blame] | 4246 | if (!pending_entry_ && failed_pending_entry_id_ == 0) { |
Michael Thiessen | 9b14d51 | 2019-09-23 21:19:47 | [diff] [blame] | 4247 | return; |
Michael Thiessen | c5676d2 | 2019-09-25 22:32:10 | [diff] [blame] | 4248 | } |
avi | 45a7253 | 2015-04-07 21:01:45 | [diff] [blame] | 4249 | DiscardPendingEntry(false); |
Rakina Zata Amni | daa84f6 | 2022-02-17 00:55:31 | [diff] [blame] | 4250 | |
| 4251 | if (!delegate_) |
| 4252 | return; |
Abhijeet Kandalkar | 3dc6e60 | 2022-11-09 05:08:37 | [diff] [blame^] | 4253 | delegate_->NotifyNavigationStateChangedFromController(INVALIDATE_TYPE_ALL); |
[email protected] | b12eb22 | 2013-09-10 00:11:48 | [diff] [blame] | 4254 | } |
| 4255 | |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 4256 | int NavigationControllerImpl::GetEntryIndexWithUniqueID( |
| 4257 | int nav_entry_id) const { |
| 4258 | for (int i = static_cast<int>(entries_.size()) - 1; i >= 0; --i) { |
| 4259 | if (entries_[i]->GetUniqueID() == nav_entry_id) |
| 4260 | return i; |
| 4261 | } |
| 4262 | return -1; |
| 4263 | } |
| 4264 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 4265 | void NavigationControllerImpl::InsertEntriesFrom( |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 4266 | NavigationControllerImpl* source, |
[email protected] | e1cd545 | 2010-08-26 18:03:25 | [diff] [blame] | 4267 | int max_index) { |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 4268 | DCHECK_LE(max_index, source->GetEntryCount()); |
Nate Chapin | 214a86a | 2021-06-21 20:35:57 | [diff] [blame] | 4269 | std::unique_ptr<NavigationEntryRestoreContextImpl> context = |
| 4270 | std::make_unique<NavigationEntryRestoreContextImpl>(); |
[email protected] | e1cd545 | 2010-08-26 18:03:25 | [diff] [blame] | 4271 | for (int i = 0; i < max_index; i++) { |
Nate Chapin | 9f16907 | 2021-06-09 19:32:37 | [diff] [blame] | 4272 | // Normally, cloning a NavigationEntryImpl results in sharing |
| 4273 | // FrameNavigationEntries between the original and the clone. However, when |
| 4274 | // cloning from a different NavigationControllerImpl, we want to fork the |
| 4275 | // FrameNavigationEntries. |
Nate Chapin | 9f16907 | 2021-06-09 19:32:37 | [diff] [blame] | 4276 | entries_.insert(entries_.begin() + i, |
Nate Chapin | 214a86a | 2021-06-21 20:35:57 | [diff] [blame] | 4277 | source->entries_[i]->CloneWithoutSharing(context.get())); |
[email protected] | e1cd545 | 2010-08-26 18:03:25 | [diff] [blame] | 4278 | } |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 4279 | DCHECK(pending_entry_index_ == -1 || |
| 4280 | pending_entry_ == GetEntryAtIndex(pending_entry_index_)); |
[email protected] | e1cd545 | 2010-08-26 18:03:25 | [diff] [blame] | 4281 | } |
[email protected] | c5b88d8 | 2012-10-06 17:03:33 | [diff] [blame] | 4282 | |
| 4283 | void NavigationControllerImpl::SetGetTimestampCallbackForTest( |
Makoto Shimazu | d2aa220 | 2019-10-09 13:57:18 | [diff] [blame] | 4284 | const base::RepeatingCallback<base::Time()>& get_timestamp_callback) { |
[email protected] | c5b88d8 | 2012-10-06 17:03:33 | [diff] [blame] | 4285 | get_timestamp_callback_ = get_timestamp_callback; |
| 4286 | } |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4287 | |
Shivani Sharma | ffb32b8 | 2019-04-09 16:58:47 | [diff] [blame] | 4288 | // History manipulation intervention: |
| 4289 | void NavigationControllerImpl::SetShouldSkipOnBackForwardUIIfNeeded( |
Shivani Sharma | ffb32b8 | 2019-04-09 16:58:47 | [diff] [blame] | 4290 | bool replace_entry, |
| 4291 | bool previous_document_was_activated, |
Alexander Timin | e3ec419 | 2020-04-20 16:39:40 | [diff] [blame] | 4292 | bool is_renderer_initiated, |
| 4293 | ukm::SourceId previous_page_load_ukm_source_id) { |
Shivani Sharma | 712d5d7 | 2019-04-16 21:56:45 | [diff] [blame] | 4294 | // Note that for a subframe, previous_document_was_activated is true if the |
| 4295 | // gesture happened in any subframe (propagated to main frame) or in the main |
| 4296 | // frame itself. |
Shivani Sharma | ffb32b8 | 2019-04-09 16:58:47 | [diff] [blame] | 4297 | if (replace_entry || previous_document_was_activated || |
shivanigithub | cceeacf | 2020-03-06 20:00:27 | [diff] [blame] | 4298 | !is_renderer_initiated) { |
Shivani Sharma | ffb32b8 | 2019-04-09 16:58:47 | [diff] [blame] | 4299 | return; |
| 4300 | } |
| 4301 | if (last_committed_entry_index_ == -1) |
| 4302 | return; |
| 4303 | |
Shivani Sharma | c4cc892 | 2019-04-18 03:11:17 | [diff] [blame] | 4304 | SetSkippableForSameDocumentEntries(last_committed_entry_index_, true); |
Shivani Sharma | ffb32b8 | 2019-04-09 16:58:47 | [diff] [blame] | 4305 | |
Alexander Timin | e3ec419 | 2020-04-20 16:39:40 | [diff] [blame] | 4306 | // Log UKM with the URL we are navigating away from. |
| 4307 | ukm::builders::HistoryManipulationIntervention( |
| 4308 | previous_page_load_ukm_source_id) |
| 4309 | .Record(ukm::UkmRecorder::Get()); |
Shivani Sharma | ffb32b8 | 2019-04-09 16:58:47 | [diff] [blame] | 4310 | } |
| 4311 | |
Shivani Sharma | c4cc892 | 2019-04-18 03:11:17 | [diff] [blame] | 4312 | void NavigationControllerImpl::SetSkippableForSameDocumentEntries( |
| 4313 | int reference_index, |
| 4314 | bool skippable) { |
| 4315 | auto* reference_entry = GetEntryAtIndex(reference_index); |
| 4316 | reference_entry->set_should_skip_on_back_forward_ui(skippable); |
| 4317 | |
| 4318 | int64_t document_sequence_number = |
| 4319 | reference_entry->root_node()->frame_entry->document_sequence_number(); |
| 4320 | for (int index = 0; index < GetEntryCount(); index++) { |
| 4321 | auto* entry = GetEntryAtIndex(index); |
| 4322 | if (entry->root_node()->frame_entry->document_sequence_number() == |
| 4323 | document_sequence_number) { |
| 4324 | entry->set_should_skip_on_back_forward_ui(skippable); |
| 4325 | } |
| 4326 | } |
| 4327 | } |
| 4328 | |
arthursonzogni | 66f711c | 2019-10-08 14:40:36 | [diff] [blame] | 4329 | std::unique_ptr<NavigationControllerImpl::PendingEntryRef> |
| 4330 | NavigationControllerImpl::ReferencePendingEntry() { |
| 4331 | DCHECK(pending_entry_); |
| 4332 | auto pending_entry_ref = |
| 4333 | std::make_unique<PendingEntryRef>(weak_factory_.GetWeakPtr()); |
| 4334 | pending_entry_refs_.insert(pending_entry_ref.get()); |
| 4335 | return pending_entry_ref; |
| 4336 | } |
| 4337 | |
| 4338 | void NavigationControllerImpl::PendingEntryRefDeleted(PendingEntryRef* ref) { |
| 4339 | // Ignore refs that don't correspond to the current pending entry. |
| 4340 | auto it = pending_entry_refs_.find(ref); |
| 4341 | if (it == pending_entry_refs_.end()) |
| 4342 | return; |
| 4343 | pending_entry_refs_.erase(it); |
| 4344 | |
| 4345 | if (!pending_entry_refs_.empty()) |
| 4346 | return; |
| 4347 | |
| 4348 | // The pending entry may be deleted before the last PendingEntryRef. |
| 4349 | if (!pending_entry_) |
| 4350 | return; |
| 4351 | |
| 4352 | // We usually clear the pending entry when the matching NavigationRequest |
| 4353 | // fails, so that an arbitrary URL isn't left visible above a committed page. |
| 4354 | // |
| 4355 | // However, we do preserve the pending entry in some cases, such as on the |
| 4356 | // initial navigation of an unmodified blank tab. We also allow the delegate |
| 4357 | // to say when it's safe to leave aborted URLs in the omnibox, to let the |
| 4358 | // user edit the URL and try again. This may be useful in cases that the |
| 4359 | // committed page cannot be attacker-controlled. In these cases, we still |
| 4360 | // allow the view to clear the pending entry and typed URL if the user |
| 4361 | // requests (e.g., hitting Escape with focus in the address bar). |
| 4362 | // |
| 4363 | // Do not leave the pending entry visible if it has an invalid URL, since this |
| 4364 | // might be formatted in an unexpected or unsafe way. |
| 4365 | // TODO(creis): Block navigations to invalid URLs in https://crbug.com/850824. |
arthursonzogni | 66f711c | 2019-10-08 14:40:36 | [diff] [blame] | 4366 | bool should_preserve_entry = |
| 4367 | (pending_entry_ == GetVisibleEntry()) && |
| 4368 | pending_entry_->GetURL().is_valid() && |
| 4369 | (IsUnmodifiedBlankTab() || delegate_->ShouldPreserveAbortedURLs()); |
| 4370 | if (should_preserve_entry) |
| 4371 | return; |
| 4372 | |
| 4373 | DiscardPendingEntry(true); |
Abhijeet Kandalkar | 3dc6e60 | 2022-11-09 05:08:37 | [diff] [blame^] | 4374 | delegate_->NotifyNavigationStateChangedFromController(INVALIDATE_TYPE_URL); |
arthursonzogni | 66f711c | 2019-10-08 14:40:36 | [diff] [blame] | 4375 | } |
| 4376 | |
Titouan Rigoudy | 6ec7040 | 2021-02-02 15:42:19 | [diff] [blame] | 4377 | std::unique_ptr<PolicyContainerPolicies> |
| 4378 | NavigationControllerImpl::ComputePolicyContainerPoliciesForFrameEntry( |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 4379 | RenderFrameHostImpl* rfh, |
| 4380 | bool is_same_document, |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 4381 | const GURL& url) { |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 4382 | if (is_same_document) { |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 4383 | // TODO(https://crbug.com/524208): Remove this nullptr check when we can |
| 4384 | // ensure we always have a FrameNavigationEntry here. |
| 4385 | if (!GetLastCommittedEntry()) |
| 4386 | return nullptr; |
Charlie Reis | 73e35624 | 2021-04-02 17:10:31 | [diff] [blame] | 4387 | |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 4388 | FrameNavigationEntry* previous_frame_entry = |
| 4389 | GetLastCommittedEntry()->GetFrameEntry(rfh->frame_tree_node()); |
| 4390 | |
| 4391 | // TODO(https://crbug.com/608402): Remove this nullptr check when we can |
| 4392 | // ensure we always have a FrameNavigationEntry here. |
| 4393 | if (!previous_frame_entry) |
| 4394 | return nullptr; |
| 4395 | |
Titouan Rigoudy | 6ec7040 | 2021-02-02 15:42:19 | [diff] [blame] | 4396 | const PolicyContainerPolicies* previous_policies = |
| 4397 | previous_frame_entry->policy_container_policies(); |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 4398 | |
Titouan Rigoudy | 6ec7040 | 2021-02-02 15:42:19 | [diff] [blame] | 4399 | if (!previous_policies) |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 4400 | return nullptr; |
| 4401 | |
| 4402 | // Make a copy of the policy container for the new FrameNavigationEntry. |
Titouan Rigoudy | 72f892d | 2022-05-02 18:21:23 | [diff] [blame] | 4403 | return previous_policies->ClonePtr(); |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 4404 | } |
| 4405 | |
Titouan Rigoudy | 72f892d | 2022-05-02 18:21:23 | [diff] [blame] | 4406 | return rfh->policy_container_host()->policies().ClonePtr(); |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 4407 | } |
| 4408 | |
Hayato Ito | 2c8c08d0 | 2021-06-23 03:38:43 | [diff] [blame] | 4409 | void NavigationControllerImpl::BroadcastHistoryOffsetAndLength() { |
Carlos Caballero | ede6f8c | 2021-01-28 11:01:50 | [diff] [blame] | 4410 | OPTIONAL_TRACE_EVENT2( |
Hayato Ito | 2c8c08d0 | 2021-06-23 03:38:43 | [diff] [blame] | 4411 | "content", "NavigationControllerImpl::BroadcastHistoryOffsetAndLength", |
| 4412 | "history_offset", GetLastCommittedEntryIndex(), "history_length", |
| 4413 | GetEntryCount()); |
Carlos Caballero | ede6f8c | 2021-01-28 11:01:50 | [diff] [blame] | 4414 | |
| 4415 | auto callback = base::BindRepeating( |
| 4416 | [](int history_offset, int history_length, RenderViewHostImpl* rvh) { |
| 4417 | if (auto& broadcast = rvh->GetAssociatedPageBroadcast()) { |
| 4418 | broadcast->SetHistoryOffsetAndLength(history_offset, history_length); |
| 4419 | } |
| 4420 | }, |
Hayato Ito | 2c8c08d0 | 2021-06-23 03:38:43 | [diff] [blame] | 4421 | GetLastCommittedEntryIndex(), GetEntryCount()); |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 4422 | frame_tree_->root()->render_manager()->ExecutePageBroadcastMethod(callback); |
Carlos Caballero | ede6f8c | 2021-01-28 11:01:50 | [diff] [blame] | 4423 | } |
| 4424 | |
| 4425 | void NavigationControllerImpl::DidAccessInitialMainDocument() { |
| 4426 | // We may have left a failed browser-initiated navigation in the address bar |
| 4427 | // to let the user edit it and try again. Clear it now that content might |
| 4428 | // show up underneath it. |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 4429 | if (!frame_tree_->IsLoadingIncludingInnerFrameTrees() && GetPendingEntry()) |
Carlos Caballero | ede6f8c | 2021-01-28 11:01:50 | [diff] [blame] | 4430 | DiscardPendingEntry(false); |
| 4431 | |
| 4432 | // Update the URL display. |
Abhijeet Kandalkar | 3dc6e60 | 2022-11-09 05:08:37 | [diff] [blame^] | 4433 | delegate_->NotifyNavigationStateChangedFromController(INVALIDATE_TYPE_URL); |
Carlos Caballero | ede6f8c | 2021-01-28 11:01:50 | [diff] [blame] | 4434 | } |
| 4435 | |
| 4436 | void NavigationControllerImpl::UpdateStateForFrame( |
| 4437 | RenderFrameHostImpl* rfhi, |
| 4438 | const blink::PageState& page_state) { |
Alexander Timin | f785f34 | 2021-03-18 00:00:56 | [diff] [blame] | 4439 | OPTIONAL_TRACE_EVENT1("content", |
| 4440 | "NavigationControllerImpl::UpdateStateForFrame", |
| 4441 | "render_frame_host", rfhi); |
Carlos Caballero | ede6f8c | 2021-01-28 11:01:50 | [diff] [blame] | 4442 | // The state update affects the last NavigationEntry associated with the given |
| 4443 | // |render_frame_host|. This may not be the last committed NavigationEntry (as |
| 4444 | // in the case of an UpdateState from a frame being swapped out). We track |
| 4445 | // which entry this is in the RenderFrameHost's nav_entry_id. |
| 4446 | NavigationEntryImpl* entry = GetEntryWithUniqueID(rfhi->nav_entry_id()); |
| 4447 | if (!entry) |
| 4448 | return; |
| 4449 | |
| 4450 | FrameNavigationEntry* frame_entry = |
| 4451 | entry->GetFrameEntry(rfhi->frame_tree_node()); |
| 4452 | if (!frame_entry) |
| 4453 | return; |
| 4454 | |
| 4455 | // The SiteInstance might not match if we do a cross-process navigation with |
| 4456 | // replacement (e.g., auto-subframe), in which case the swap out of the old |
| 4457 | // RenderFrameHost runs in the background after the old FrameNavigationEntry |
| 4458 | // has already been replaced and destroyed. |
| 4459 | if (frame_entry->site_instance() != rfhi->GetSiteInstance()) |
| 4460 | return; |
| 4461 | |
| 4462 | if (page_state == frame_entry->page_state()) |
| 4463 | return; // Nothing to update. |
| 4464 | |
| 4465 | DCHECK(page_state.IsValid()) << "Shouldn't set an empty PageState."; |
| 4466 | |
| 4467 | // The document_sequence_number and item_sequence_number recorded in the |
| 4468 | // FrameNavigationEntry should not differ from the one coming with the update, |
| 4469 | // since it must come from the same document. Do not update it if a difference |
| 4470 | // is detected, as this indicates that |frame_entry| is not the correct one. |
| 4471 | blink::ExplodedPageState exploded_state; |
| 4472 | if (!blink::DecodePageState(page_state.ToEncodedData(), &exploded_state)) |
| 4473 | return; |
| 4474 | |
| 4475 | if (exploded_state.top.document_sequence_number != |
| 4476 | frame_entry->document_sequence_number() || |
| 4477 | exploded_state.top.item_sequence_number != |
| 4478 | frame_entry->item_sequence_number()) { |
| 4479 | return; |
| 4480 | } |
| 4481 | |
| 4482 | frame_entry->SetPageState(page_state); |
| 4483 | NotifyEntryChanged(entry); |
| 4484 | } |
| 4485 | |
Domenic Denicola | cd30f5f8 | 2022-03-16 21:48:01 | [diff] [blame] | 4486 | std::vector<blink::mojom::NavigationApiHistoryEntryPtr> |
| 4487 | NavigationControllerImpl::PopulateSingleNavigationApiHistoryEntryVector( |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4488 | Direction direction, |
| 4489 | int entry_index, |
| 4490 | const url::Origin& pending_origin, |
| 4491 | FrameTreeNode* node, |
| 4492 | SiteInstance* site_instance, |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 4493 | int64_t pending_item_sequence_number, |
| 4494 | int64_t pending_document_sequence_number) { |
Domenic Denicola | cd30f5f8 | 2022-03-16 21:48:01 | [diff] [blame] | 4495 | std::vector<blink::mojom::NavigationApiHistoryEntryPtr> entries; |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame] | 4496 | if (GetLastCommittedEntry() && GetLastCommittedEntry()->IsInitialEntry()) { |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 4497 | // Don't process the initial entry. |
| 4498 | DCHECK_EQ(GetEntryCount(), 1); |
| 4499 | return entries; |
| 4500 | } |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4501 | int offset = direction == Direction::kForward ? 1 : -1; |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 4502 | int64_t previous_item_sequence_number = pending_item_sequence_number; |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4503 | for (int i = entry_index + offset; i >= 0 && i < GetEntryCount(); |
| 4504 | i += offset) { |
| 4505 | FrameNavigationEntry* frame_entry = GetEntryAtIndex(i)->GetFrameEntry(node); |
Nate Chapin | dedfa64 | 2022-01-28 23:59:41 | [diff] [blame] | 4506 | if (!frame_entry) |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4507 | break; |
Domenic Denicola | cd30f5f8 | 2022-03-16 21:48:01 | [diff] [blame] | 4508 | // An entry should only appear in the navigation API entries if it is for |
| 4509 | // the same origin as the document being committed. Check the committed |
| 4510 | // origin, or if that is not available (during restore), check against the |
| 4511 | // FNE's url. |
Nate Chapin | dedfa64 | 2022-01-28 23:59:41 | [diff] [blame] | 4512 | url::Origin frame_entry_origin = |
| 4513 | frame_entry->committed_origin().value_or(url::Origin::Resolve( |
| 4514 | frame_entry->url(), |
| 4515 | frame_entry->initiator_origin().value_or(url::Origin()))); |
| 4516 | if (!pending_origin.IsSameOriginWith(frame_entry_origin)) |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4517 | break; |
| 4518 | if (previous_item_sequence_number == frame_entry->item_sequence_number()) |
| 4519 | continue; |
| 4520 | blink::ExplodedPageState exploded_page_state; |
| 4521 | if (blink::DecodePageState(frame_entry->page_state().ToEncodedData(), |
| 4522 | &exploded_page_state)) { |
| 4523 | blink::ExplodedFrameState frame_state = exploded_page_state.top; |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 4524 | |
| 4525 | // If the document represented by this FNE hid its full url from appearing |
| 4526 | // in a referrer via a "no-referrer" or "origin" referrer policy, censor |
Domenic Denicola | cd30f5f8 | 2022-03-16 21:48:01 | [diff] [blame] | 4527 | // the url in the navigation API as well (unless we're navigating to that |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 4528 | // document). |
| 4529 | std::u16string url; |
| 4530 | if (pending_document_sequence_number == |
| 4531 | frame_entry->document_sequence_number() || |
Domenic Denicola | cc094fb | 2022-03-16 23:40:57 | [diff] [blame] | 4532 | !frame_entry->protect_url_in_navigation_api()) { |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 4533 | url = frame_state.url_string.value_or(std::u16string()); |
| 4534 | } |
| 4535 | |
Domenic Denicola | cd30f5f8 | 2022-03-16 21:48:01 | [diff] [blame] | 4536 | blink::mojom::NavigationApiHistoryEntryPtr entry = |
| 4537 | blink::mojom::NavigationApiHistoryEntry::New( |
Domenic Denicola | cc094fb | 2022-03-16 23:40:57 | [diff] [blame] | 4538 | frame_state.navigation_api_key.value_or(std::u16string()), |
| 4539 | frame_state.navigation_api_id.value_or(std::u16string()), url, |
Nate Chapin | ab5c3a71 | 2021-11-18 22:17:09 | [diff] [blame] | 4540 | frame_state.item_sequence_number, |
| 4541 | frame_state.document_sequence_number, |
Nate Chapin | 393cbde1 | 2022-05-27 00:36:30 | [diff] [blame] | 4542 | frame_state.navigation_api_state); |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 4543 | |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 4544 | DCHECK(entry->url.empty() || |
| 4545 | pending_origin.CanBeDerivedFrom(GURL(entry->url))); |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4546 | entries.push_back(std::move(entry)); |
| 4547 | previous_item_sequence_number = frame_entry->item_sequence_number(); |
| 4548 | } |
| 4549 | } |
| 4550 | // If |entries| was constructed by iterating backwards from |
| 4551 | // |entry_index|, it's latest-at-the-front, but the renderer will want it |
| 4552 | // earliest-at-the-front. Reverse it. |
| 4553 | if (direction == Direction::kBack) |
| 4554 | std::reverse(entries.begin(), entries.end()); |
| 4555 | return entries; |
| 4556 | } |
| 4557 | |
Domenic Denicola | cd30f5f8 | 2022-03-16 21:48:01 | [diff] [blame] | 4558 | blink::mojom::NavigationApiHistoryEntryArraysPtr |
| 4559 | NavigationControllerImpl::GetNavigationApiHistoryEntryVectors( |
Nate Chapin | 97d2f54 | 2022-02-18 01:34:55 | [diff] [blame] | 4560 | FrameTreeNode* node, |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4561 | NavigationRequest* request) { |
Rakina Zata Amni | c736785 | 2022-11-07 17:10:40 | [diff] [blame] | 4562 | url::Origin pending_origin = request |
| 4563 | ? request->GetOriginToCommit() |
| 4564 | : url::Origin::Create(node->current_url()); |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4565 | |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4566 | scoped_refptr<SiteInstance> site_instance = |
Nate Chapin | 97d2f54 | 2022-02-18 01:34:55 | [diff] [blame] | 4567 | node->current_frame_host()->GetSiteInstance(); |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4568 | |
Nate Chapin | e82339d0 | 2022-05-03 23:48:25 | [diff] [blame] | 4569 | // NOTE: |entry_index| is the index where this entry will commit if no |
| 4570 | // modifications are made between now and DidCommitNavigation. This is used to |
| 4571 | // walk |entries_| and determine which entries should be exposed by the |
| 4572 | // navigation API. It is important to calculate this correctly, because blink |
| 4573 | // will cancel a same-document history commit if it's not present in the |
| 4574 | // entries blink knows about. |
| 4575 | int entry_index = GetLastCommittedEntryIndex(); |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4576 | int64_t pending_item_sequence_number = 0; |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 4577 | int64_t pending_document_sequence_number = 0; |
Nate Chapin | e82339d0 | 2022-05-03 23:48:25 | [diff] [blame] | 4578 | bool will_create_new_entry = false; |
| 4579 | if (GetPendingEntryIndex() != -1) { |
| 4580 | entry_index = GetPendingEntryIndex(); |
| 4581 | if (auto* frame_entry = GetPendingEntry()->GetFrameEntry(node)) { |
| 4582 | pending_item_sequence_number = frame_entry->item_sequence_number(); |
| 4583 | pending_document_sequence_number = |
| 4584 | frame_entry->document_sequence_number(); |
| 4585 | } |
| 4586 | } else if (request && |
| 4587 | !NavigationTypeUtils::IsReload( |
| 4588 | request->common_params().navigation_type) && |
| 4589 | !NavigationTypeUtils::IsHistory( |
| 4590 | request->common_params().navigation_type) && |
| 4591 | !request->common_params().should_replace_current_entry && |
| 4592 | !request->common_params() |
| 4593 | .is_history_navigation_in_new_child_frame) { |
| 4594 | will_create_new_entry = true; |
| 4595 | entry_index = GetLastCommittedEntryIndex() + 1; |
| 4596 | // Don't set pending_item_sequence_number or |
| 4597 | // pending_document_sequence_number in this case - a new unique isn/dsn will |
| 4598 | // be calculated in the renderer later. |
| 4599 | } else if (GetLastCommittedEntryIndex() != -1) { |
| 4600 | entry_index = GetLastCommittedEntryIndex(); |
| 4601 | if (auto* frame_entry = GetLastCommittedEntry()->GetFrameEntry(node)) { |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4602 | pending_item_sequence_number = frame_entry->item_sequence_number(); |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 4603 | pending_document_sequence_number = |
| 4604 | frame_entry->document_sequence_number(); |
| 4605 | } |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4606 | } |
| 4607 | |
Domenic Denicola | cd30f5f8 | 2022-03-16 21:48:01 | [diff] [blame] | 4608 | auto entry_arrays = blink::mojom::NavigationApiHistoryEntryArrays::New(); |
Nate Chapin | e82339d0 | 2022-05-03 23:48:25 | [diff] [blame] | 4609 | if (entry_index == -1) { |
| 4610 | // TODO(rakina): Exit early when there is no last committed entry. |
| 4611 | // Remove when InitialNavigationEntry ships. |
| 4612 | return entry_arrays; |
| 4613 | } |
| 4614 | |
Domenic Denicola | cd30f5f8 | 2022-03-16 21:48:01 | [diff] [blame] | 4615 | entry_arrays->back_entries = PopulateSingleNavigationApiHistoryEntryVector( |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4616 | Direction::kBack, entry_index, pending_origin, node, site_instance.get(), |
Nate Chapin | 4e657a47 | 2022-02-06 03:38:37 | [diff] [blame] | 4617 | pending_item_sequence_number, pending_document_sequence_number); |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4618 | |
| 4619 | // Don't populate forward entries if they will be truncated by a new entry. |
| 4620 | if (!will_create_new_entry) { |
Domenic Denicola | cd30f5f8 | 2022-03-16 21:48:01 | [diff] [blame] | 4621 | entry_arrays->forward_entries = |
| 4622 | PopulateSingleNavigationApiHistoryEntryVector( |
| 4623 | Direction::kForward, entry_index, pending_origin, node, |
| 4624 | site_instance.get(), pending_item_sequence_number, |
| 4625 | pending_document_sequence_number); |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4626 | } |
Nate Chapin | 4e657a47 | 2022-02-06 03:38:37 | [diff] [blame] | 4627 | return entry_arrays; |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4628 | } |
| 4629 | |
Nate Chapin | fbfe5af | 2021-06-10 17:22:08 | [diff] [blame] | 4630 | NavigationControllerImpl::HistoryNavigationAction |
Domenic Denicola | cc094fb | 2022-03-16 23:40:57 | [diff] [blame] | 4631 | NavigationControllerImpl::ShouldNavigateToEntryForNavigationApiKey( |
Nate Chapin | fbfe5af | 2021-06-10 17:22:08 | [diff] [blame] | 4632 | FrameNavigationEntry* current_entry, |
| 4633 | FrameNavigationEntry* target_entry, |
Domenic Denicola | cc094fb | 2022-03-16 23:40:57 | [diff] [blame] | 4634 | const std::string& navigation_api_key) { |
Nate Chapin | fbfe5af | 2021-06-10 17:22:08 | [diff] [blame] | 4635 | if (!target_entry || !target_entry->committed_origin()) |
| 4636 | return HistoryNavigationAction::kStopLooking; |
| 4637 | if (current_entry->site_instance() != target_entry->site_instance()) |
| 4638 | return HistoryNavigationAction::kStopLooking; |
| 4639 | if (!current_entry->committed_origin()->IsSameOriginWith( |
| 4640 | *target_entry->committed_origin())) { |
| 4641 | return HistoryNavigationAction::kStopLooking; |
| 4642 | } |
| 4643 | |
| 4644 | // NOTE: We don't actually care between kSameDocument and |
| 4645 | // kDifferentDocument, so always use kDifferentDocument by convention. |
Domenic Denicola | cc094fb | 2022-03-16 23:40:57 | [diff] [blame] | 4646 | if (target_entry->navigation_api_key() == navigation_api_key) |
Nate Chapin | fbfe5af | 2021-06-10 17:22:08 | [diff] [blame] | 4647 | return HistoryNavigationAction::kDifferentDocument; |
| 4648 | return HistoryNavigationAction::kKeepLooking; |
| 4649 | } |
| 4650 | |
Domenic Denicola | cc094fb | 2022-03-16 23:40:57 | [diff] [blame] | 4651 | void NavigationControllerImpl::NavigateToNavigationApiKey( |
Nate Chapin | bf682fa3 | 2022-09-26 22:41:20 | [diff] [blame] | 4652 | RenderFrameHostImpl* initiator_rfh, |
Domenic Denicola | cc094fb | 2022-03-16 23:40:57 | [diff] [blame] | 4653 | const std::string& key) { |
Nate Chapin | bf682fa3 | 2022-09-26 22:41:20 | [diff] [blame] | 4654 | FrameTreeNode* node = initiator_rfh->frame_tree_node(); |
Nate Chapin | fbfe5af | 2021-06-10 17:22:08 | [diff] [blame] | 4655 | FrameNavigationEntry* current_entry = |
| 4656 | GetLastCommittedEntry()->GetFrameEntry(node); |
| 4657 | if (!current_entry) |
| 4658 | return; |
| 4659 | |
| 4660 | // We want to find the nearest matching entry that is contiguously |
| 4661 | // same-instance and same-origin. Check back first, then forward. |
| 4662 | // TODO(japhet): Link spec here once it exists. |
| 4663 | for (int i = GetCurrentEntryIndex() - 1; i >= 0; i--) { |
Domenic Denicola | cc094fb | 2022-03-16 23:40:57 | [diff] [blame] | 4664 | auto result = ShouldNavigateToEntryForNavigationApiKey( |
Nate Chapin | fbfe5af | 2021-06-10 17:22:08 | [diff] [blame] | 4665 | current_entry, GetEntryAtIndex(i)->GetFrameEntry(node), key); |
| 4666 | if (result == HistoryNavigationAction::kStopLooking) |
| 4667 | break; |
| 4668 | if (result != HistoryNavigationAction::kKeepLooking) { |
Nate Chapin | bf682fa3 | 2022-09-26 22:41:20 | [diff] [blame] | 4669 | GoToIndex(i, initiator_rfh, &key); |
Nate Chapin | fbfe5af | 2021-06-10 17:22:08 | [diff] [blame] | 4670 | return; |
| 4671 | } |
| 4672 | } |
| 4673 | for (int i = GetCurrentEntryIndex() + 1; i < GetEntryCount(); i++) { |
Domenic Denicola | cc094fb | 2022-03-16 23:40:57 | [diff] [blame] | 4674 | auto result = ShouldNavigateToEntryForNavigationApiKey( |
Nate Chapin | fbfe5af | 2021-06-10 17:22:08 | [diff] [blame] | 4675 | current_entry, GetEntryAtIndex(i)->GetFrameEntry(node), key); |
| 4676 | if (result == HistoryNavigationAction::kStopLooking) |
| 4677 | break; |
| 4678 | if (result != HistoryNavigationAction::kKeepLooking) { |
Nate Chapin | bf682fa3 | 2022-09-26 22:41:20 | [diff] [blame] | 4679 | GoToIndex(i, initiator_rfh, &key); |
Nate Chapin | fbfe5af | 2021-06-10 17:22:08 | [diff] [blame] | 4680 | return; |
| 4681 | } |
| 4682 | } |
Nate Chapin | bf682fa3 | 2022-09-26 22:41:20 | [diff] [blame] | 4683 | |
| 4684 | // If we fall through to here, a matching NavigationEntry couldn't be found. |
| 4685 | // Notify the renderer that the navigation was cancelled. |
| 4686 | initiator_rfh->GetAssociatedLocalFrame()->TraverseCancelled( |
| 4687 | key, blink::mojom::TraverseCancelledReason::kNotFound); |
Nate Chapin | fbfe5af | 2021-06-10 17:22:08 | [diff] [blame] | 4688 | } |
| 4689 | |
Domenic Denicola | cc094fb | 2022-03-16 23:40:57 | [diff] [blame] | 4690 | bool NavigationControllerImpl::ShouldProtectUrlInNavigationApi( |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 4691 | network::mojom::ReferrerPolicy referrer_policy) { |
| 4692 | return referrer_policy == network::mojom::ReferrerPolicy::kNever || |
| 4693 | referrer_policy == network::mojom::ReferrerPolicy::kOrigin; |
| 4694 | } |
| 4695 | |
shivanigithub | f405bf0d | 2021-11-05 17:58:33 | [diff] [blame] | 4696 | bool NavigationControllerImpl::ShouldMaintainTrivialSessionHistory( |
| 4697 | const FrameTreeNode* frame_tree_node) const { |
| 4698 | // TODO(https://crbug.com/1197384): We may have to add portals in addition to |
| 4699 | // prerender and fenced frames. This should be kept in sync with |
Hayato Ito | 7a80db4 | 2021-07-05 06:18:54 | [diff] [blame] | 4700 | // LocalFrame version, LocalFrame::ShouldMaintainTrivialSessionHistory. |
Ali Hijazi | d87307d | 2022-11-07 20:15:03 | [diff] [blame] | 4701 | return frame_tree_->is_prerendering() || |
shivanigithub | f405bf0d | 2021-11-05 17:58:33 | [diff] [blame] | 4702 | frame_tree_node->IsInFencedFrameTree(); |
Hayato Ito | 7a80db4 | 2021-07-05 06:18:54 | [diff] [blame] | 4703 | } |
| 4704 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4705 | } // namespace content |