[email protected] | d4a8ca48 | 2013-10-30 21:06:40 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
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" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 43 | #include "base/logging.h" |
asvitkine | 3033081 | 2016-08-30 04:01:08 | [diff] [blame] | 44 | #include "base/metrics/histogram_macros.h" |
Chris Hamilton | 83272dc | 2021-02-23 00:24:02 | [diff] [blame] | 45 | #include "base/stl_util.h" |
Peter Kasting | b53b8191 | 2021-04-28 19:23:30 | [diff] [blame] | 46 | #include "base/strings/string_piece.h" |
[email protected] | 348fbaac | 2013-06-11 06:31:51 | [diff] [blame] | 47 | #include "base/strings/string_util.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 48 | #include "base/strings/utf_string_conversions.h" |
[email protected] | a43858f | 2013-06-28 15:18:37 | [diff] [blame] | 49 | #include "base/time/time.h" |
Carlos Caballero | 40b0efd | 2021-01-26 11:55:00 | [diff] [blame] | 50 | #include "base/trace_event/optional_trace_event.h" |
Carlos Caballero | ede6f8c | 2021-01-28 11:01:50 | [diff] [blame] | 51 | #include "base/trace_event/trace_conversion_helper.h" |
ssid | 3e76561 | 2015-01-28 04:03:42 | [diff] [blame] | 52 | #include "base/trace_event/trace_event.h" |
servolk | f395553 | 2015-05-16 00:01:59 | [diff] [blame] | 53 | #include "build/build_config.h" |
[email protected] | eabfe191 | 2014-05-12 10:07:28 | [diff] [blame] | 54 | #include "cc/base/switches.h" |
jamescook | da250581 | 2015-03-20 18:01:18 | [diff] [blame] | 55 | #include "content/browser/bad_message.h" |
Marijn Kruisselbrink | 0c87e6e | 2018-06-22 22:57:39 | [diff] [blame] | 56 | #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
[email protected] | 825b166 | 2012-03-12 19:07:31 | [diff] [blame] | 57 | #include "content/browser/browser_url_handler_impl.h" |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 58 | #include "content/browser/dom_storage/dom_storage_context_wrapper.h" |
[email protected] | 1ea3c79 | 2012-04-17 01:25:04 | [diff] [blame] | 59 | #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 60 | #include "content/browser/renderer_host/debug_urls.h" |
| 61 | #include "content/browser/renderer_host/frame_tree.h" |
Carlos Caballero | 40b0efd | 2021-01-26 11:55:00 | [diff] [blame] | 62 | #include "content/browser/renderer_host/frame_tree_node.h" |
Chris Bookholt | 27faf8d | 2022-01-20 01:03:33 | [diff] [blame] | 63 | #include "content/browser/renderer_host/navigation_controller_delegate.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 64 | #include "content/browser/renderer_host/navigation_entry_impl.h" |
Nate Chapin | 214a86a | 2021-06-21 20:35:57 | [diff] [blame] | 65 | #include "content/browser/renderer_host/navigation_entry_restore_context_impl.h" |
danakj | c492bf8 | 2020-09-09 20:02:44 | [diff] [blame] | 66 | #include "content/browser/renderer_host/navigation_request.h" |
| 67 | #include "content/browser/renderer_host/navigator.h" |
| 68 | #include "content/browser/renderer_host/render_frame_host_delegate.h" |
Carlos Caballero | 40b0efd | 2021-01-26 11:55:00 | [diff] [blame] | 69 | #include "content/browser/renderer_host/render_view_host_impl.h" |
Sharon Yang | d70a539 | 2021-10-26 23:06:32 | [diff] [blame] | 70 | #include "content/browser/site_info.h" |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 71 | #include "content/browser/site_instance_impl.h" |
Kunihiko Sakamoto | 346a74e | 2021-03-10 08:57:48 | [diff] [blame] | 72 | #include "content/browser/web_package/subresource_web_bundle_navigation_info.h" |
Tsuyoshi Horo | 37493af | 2019-11-21 23:43:14 | [diff] [blame] | 73 | #include "content/browser/web_package/web_bundle_navigation_info.h" |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 74 | #include "content/common/content_constants_internal.h" |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 75 | #include "content/common/navigation_params_utils.h" |
Nasko Oskov | ae49e29 | 2020-08-13 02:08:51 | [diff] [blame] | 76 | #include "content/common/trace_utils.h" |
[email protected] | ccb79730 | 2011-12-15 16:55:11 | [diff] [blame] | 77 | #include "content/public/browser/browser_context.h" |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 78 | #include "content/public/browser/content_browser_client.h" |
Fergal Daly | 1336ac64 | 2021-09-14 15:13:11 | [diff] [blame] | 79 | #include "content/public/browser/disallow_activation_reason.h" |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 80 | #include "content/public/browser/invalidate_type.h" |
[email protected] | 5b96836f | 2011-12-22 07:39:00 | [diff] [blame] | 81 | #include "content/public/browser/navigation_details.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 82 | #include "content/public/browser/notification_service.h" |
[email protected] | 0d6e9bd | 2011-10-18 04:29:16 | [diff] [blame] | 83 | #include "content/public/browser/notification_types.h" |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 84 | #include "content/public/browser/render_view_host.h" |
[email protected] | 9677a3c | 2012-12-22 04:18:58 | [diff] [blame] | 85 | #include "content/public/browser/render_widget_host.h" |
| 86 | #include "content/public/browser/render_widget_host_view.h" |
Mikel Astiz | ba9cf2fd | 2017-12-17 10:38:10 | [diff] [blame] | 87 | #include "content/public/browser/replaced_navigation_entry_data.h" |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 88 | #include "content/public/browser/storage_partition.h" |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 89 | #include "content/public/common/content_client.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 90 | #include "content/public/common/content_constants.h" |
toyoshim | 86e34ec | 2016-02-25 08:56:10 | [diff] [blame] | 91 | #include "content/public/common/content_features.h" |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 92 | #include "content/public/common/url_constants.h" |
clamy | 7fced7b | 2017-11-16 19:52:43 | [diff] [blame] | 93 | #include "content/public/common/url_utils.h" |
servolk | f395553 | 2015-05-16 00:01:59 | [diff] [blame] | 94 | #include "media/base/mime_util.h" |
[email protected] | a23de857 | 2009-06-03 02:16:32 | [diff] [blame] | 95 | #include "net/base/escape.h" |
Arthur Sonzogni | 620cec6 | 2018-12-13 13:08:57 | [diff] [blame] | 96 | #include "net/http/http_status_code.h" |
Shivani Sharma | 9332910 | 2019-01-24 19:44:18 | [diff] [blame] | 97 | #include "services/metrics/public/cpp/ukm_builders.h" |
| 98 | #include "services/metrics/public/cpp/ukm_recorder.h" |
Yue Ru Sun | 12880493 | 2020-09-30 22:19:17 | [diff] [blame] | 99 | #include "services/metrics/public/cpp/ukm_source_id.h" |
Nan Lin | d91c815 | 2021-10-21 16:22:37 | [diff] [blame] | 100 | #include "services/network/public/mojom/fetch_api.mojom.h" |
[email protected] | 9677a3c | 2012-12-22 04:18:58 | [diff] [blame] | 101 | #include "skia/ext/platform_canvas.h" |
Marijn Kruisselbrink | 0c87e6e | 2018-06-22 22:57:39 | [diff] [blame] | 102 | #include "third_party/blink/public/common/blob/blob_utils.h" |
Gyuyoung Kim | 107c2a0 | 2021-04-13 01:49:30 | [diff] [blame] | 103 | #include "third_party/blink/public/common/chrome_debug_urls.h" |
Miyoung Shin | 1c565c91 | 2021-03-17 12:11:21 | [diff] [blame] | 104 | #include "third_party/blink/public/common/history/session_history_constants.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 105 | #include "third_party/blink/public/common/mime_util/mime_util.h" |
Minggang Wang | a13c796e | 2021-07-02 05:54:43 | [diff] [blame] | 106 | #include "third_party/blink/public/common/navigation/navigation_params.h" |
Carlos Caballero | ede6f8c | 2021-01-28 11:01:50 | [diff] [blame] | 107 | #include "third_party/blink/public/common/page_state/page_state_serialization.h" |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 108 | #include "third_party/blink/public/mojom/navigation/navigation_params.mojom.h" |
Minggang Wang | 7ee0c74 | 2021-06-16 16:16:51 | [diff] [blame] | 109 | #include "third_party/blink/public/mojom/navigation/prefetched_signed_exchange_info.mojom.h" |
[email protected] | cca6f39 | 2014-05-28 21:32:26 | [diff] [blame] | 110 | #include "url/url_constants.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 111 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 112 | namespace content { |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 113 | namespace { |
| 114 | |
| 115 | // Invoked when entries have been pruned, or removed. For example, if the |
| 116 | // current entries are [google, digg, yahoo], with the current entry google, |
| 117 | // and the user types in cnet, then digg and yahoo are pruned. |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 118 | void NotifyPrunedEntries(NavigationControllerImpl* nav_controller, |
Shivani Sharma | b9c46de8 | 2019-02-08 16:54:50 | [diff] [blame] | 119 | int index, |
[email protected] | c12bf1a1 | 2008-09-17 16:28:49 | [diff] [blame] | 120 | int count) { |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 121 | PrunedDetails details; |
Shivani Sharma | b9c46de8 | 2019-02-08 16:54:50 | [diff] [blame] | 122 | details.index = index; |
[email protected] | c12bf1a1 | 2008-09-17 16:28:49 | [diff] [blame] | 123 | details.count = count; |
Sam McNally | 5c087a3 | 2017-08-25 01:46:14 | [diff] [blame] | 124 | nav_controller->delegate()->NotifyNavigationListPruned(details); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 125 | } |
| 126 | |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 127 | // Configure all the NavigationEntries in entries for restore. This resets |
| 128 | // the transition type to reload and makes sure the content state isn't empty. |
| 129 | void ConfigureEntriesForRestore( |
dcheng | 9bfa516 | 2016-04-09 01:00:57 | [diff] [blame] | 130 | std::vector<std::unique_ptr<NavigationEntryImpl>>* entries, |
toyoshim | 0df1d3a | 2016-09-09 09:52:48 | [diff] [blame] | 131 | RestoreType type) { |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 132 | for (auto& entry : *entries) { |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 133 | // Use a transition type of reload so that we don't incorrectly increase |
| 134 | // the typed count. |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 135 | entry->SetTransitionType(ui::PAGE_TRANSITION_RELOAD); |
| 136 | entry->set_restore_type(type); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 140 | // Determines whether or not we should be carrying over a user agent override |
| 141 | // between two NavigationEntries. |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 142 | bool ShouldKeepOverride(NavigationEntry* last_entry) { |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 143 | return last_entry && last_entry->GetIsOverridingUserAgent(); |
| 144 | } |
| 145 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 146 | // Determines whether to override user agent for a navigation. |
| 147 | bool ShouldOverrideUserAgent( |
| 148 | NavigationController::UserAgentOverrideOption override_user_agent, |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 149 | NavigationEntry* last_committed_entry) { |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 150 | switch (override_user_agent) { |
| 151 | case NavigationController::UA_OVERRIDE_INHERIT: |
| 152 | return ShouldKeepOverride(last_committed_entry); |
| 153 | case NavigationController::UA_OVERRIDE_TRUE: |
| 154 | return true; |
| 155 | case NavigationController::UA_OVERRIDE_FALSE: |
| 156 | return false; |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 157 | } |
| 158 | NOTREACHED(); |
| 159 | return false; |
| 160 | } |
| 161 | |
Rakina Zata Amni | 312822d7 | 2021-06-04 16:13:37 | [diff] [blame] | 162 | // Returns true if this navigation should be treated as a reload. For e.g. |
clamy | 0a656e4 | 2018-02-06 18:18:28 | [diff] [blame] | 163 | // 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] | 164 | // link which results in a navigation to the last committed URL (but wasn't |
| 165 | // converted to do a replacement navigation in the renderer), etc. |
Fergal Daly | 766177d | 2020-07-07 07:54:04 | [diff] [blame] | 166 | // |node| is the FrameTreeNode which is navigating. |url|, |virtual_url|, |
| 167 | // |base_url_for_data_url|, |transition_type| correspond to the new navigation |
| 168 | // (i.e. the pending NavigationEntry). |last_committed_entry| is the last |
| 169 | // navigation that committed. |
| 170 | bool ShouldTreatNavigationAsReload(FrameTreeNode* node, |
| 171 | const GURL& url, |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 172 | const GURL& virtual_url, |
| 173 | const GURL& base_url_for_data_url, |
| 174 | ui::PageTransition transition_type, |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 175 | bool is_post, |
Rakina Zata Amni | 312822d7 | 2021-06-04 16:13:37 | [diff] [blame] | 176 | bool should_replace_current_entry, |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 177 | NavigationEntryImpl* last_committed_entry) { |
Rakina Zata Amni | 312822d7 | 2021-06-04 16:13:37 | [diff] [blame] | 178 | // Navigations intended to do a replacement shouldn't be converted to do a |
| 179 | // reload. |
| 180 | if (should_replace_current_entry) |
clamy | 0a656e4 | 2018-02-06 18:18:28 | [diff] [blame] | 181 | return false; |
clamy | 0a656e4 | 2018-02-06 18:18:28 | [diff] [blame] | 182 | // Only convert to reload if at least one navigation committed. |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 183 | if (!last_committed_entry || last_committed_entry->IsInitialEntry()) |
ananta | 3bdd8ae | 2016-12-22 17:11:55 | [diff] [blame] | 184 | return false; |
| 185 | |
arthursonzogni | 7a824368 | 2017-12-14 16:41:42 | [diff] [blame] | 186 | // Skip navigations initiated by external applications. |
clamy | 0a656e4 | 2018-02-06 18:18:28 | [diff] [blame] | 187 | if (transition_type & ui::PAGE_TRANSITION_FROM_API) |
arthursonzogni | 7a824368 | 2017-12-14 16:41:42 | [diff] [blame] | 188 | return false; |
| 189 | |
ananta | 3bdd8ae | 2016-12-22 17:11:55 | [diff] [blame] | 190 | // We treat (PAGE_TRANSITION_RELOAD | PAGE_TRANSITION_FROM_ADDRESS_BAR), |
| 191 | // PAGE_TRANSITION_TYPED or PAGE_TRANSITION_LINK transitions as navigations |
| 192 | // which should be treated as reloads. |
clamy | 0a656e4 | 2018-02-06 18:18:28 | [diff] [blame] | 193 | bool transition_type_can_be_converted = false; |
| 194 | if (ui::PageTransitionCoreTypeIs(transition_type, |
| 195 | ui::PAGE_TRANSITION_RELOAD) && |
| 196 | (transition_type & ui::PAGE_TRANSITION_FROM_ADDRESS_BAR)) { |
| 197 | transition_type_can_be_converted = true; |
ananta | 3bdd8ae | 2016-12-22 17:11:55 | [diff] [blame] | 198 | } |
clamy | 0a656e4 | 2018-02-06 18:18:28 | [diff] [blame] | 199 | if (ui::PageTransitionCoreTypeIs(transition_type, |
ananta | 3bdd8ae | 2016-12-22 17:11:55 | [diff] [blame] | 200 | ui::PAGE_TRANSITION_TYPED)) { |
clamy | 0a656e4 | 2018-02-06 18:18:28 | [diff] [blame] | 201 | transition_type_can_be_converted = true; |
| 202 | } |
| 203 | if (ui::PageTransitionCoreTypeIs(transition_type, ui::PAGE_TRANSITION_LINK)) |
| 204 | transition_type_can_be_converted = true; |
| 205 | if (!transition_type_can_be_converted) |
| 206 | return false; |
| 207 | |
| 208 | // This check is required for cases like view-source:, etc. Here the URL of |
| 209 | // the navigation entry would contain the url of the page, while the virtual |
| 210 | // URL contains the full URL including the view-source prefix. |
| 211 | if (virtual_url != last_committed_entry->GetVirtualURL()) |
| 212 | return false; |
| 213 | |
Fergal Daly | 766177d | 2020-07-07 07:54:04 | [diff] [blame] | 214 | // Check that the URLs match. |
| 215 | FrameNavigationEntry* frame_entry = last_committed_entry->GetFrameEntry(node); |
| 216 | // If there's no frame entry then by definition the URLs don't match. |
| 217 | if (!frame_entry) |
| 218 | return false; |
| 219 | |
| 220 | if (url != frame_entry->url()) |
clamy | 0a656e4 | 2018-02-06 18:18:28 | [diff] [blame] | 221 | return false; |
| 222 | |
| 223 | // This check is required for Android WebView loadDataWithBaseURL. Apps |
| 224 | // can pass in anything in the base URL and we need to ensure that these |
| 225 | // match before classifying it as a reload. |
| 226 | if (url.SchemeIs(url::kDataScheme) && base_url_for_data_url.is_valid()) { |
| 227 | if (base_url_for_data_url != last_committed_entry->GetBaseURLForDataURL()) |
| 228 | return false; |
ananta | 3bdd8ae | 2016-12-22 17:11:55 | [diff] [blame] | 229 | } |
| 230 | |
clamy | 0a656e4 | 2018-02-06 18:18:28 | [diff] [blame] | 231 | // Skip entries with SSL errors. |
| 232 | if (last_committed_entry->ssl_error()) |
| 233 | return false; |
| 234 | |
| 235 | // Don't convert to a reload when the last navigation was a POST or the new |
| 236 | // navigation is a POST. |
Fergal Daly | 766177d | 2020-07-07 07:54:04 | [diff] [blame] | 237 | if (frame_entry->get_has_post_data() || is_post) |
clamy | 0a656e4 | 2018-02-06 18:18:28 | [diff] [blame] | 238 | return false; |
| 239 | |
| 240 | return true; |
ananta | 3bdd8ae | 2016-12-22 17:11:55 | [diff] [blame] | 241 | } |
| 242 | |
Nasko Oskov | 0391210 | 2019-01-11 00:21:32 | [diff] [blame] | 243 | bool DoesURLMatchOriginForNavigation( |
| 244 | const GURL& url, |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 245 | const absl::optional<url::Origin>& origin, |
Kunihiko Sakamoto | 346a74e | 2021-03-10 08:57:48 | [diff] [blame] | 246 | SubresourceWebBundleNavigationInfo* |
| 247 | subresource_web_bundle_navigation_info) { |
Nasko Oskov | 0391210 | 2019-01-11 00:21:32 | [diff] [blame] | 248 | // If there is no origin supplied there is nothing to match. This can happen |
| 249 | // for navigations to a pending entry and therefore it should be allowed. |
| 250 | if (!origin) |
| 251 | return true; |
| 252 | |
Kunihiko Sakamoto | 260ee0a | 2021-10-15 01:44:08 | [diff] [blame] | 253 | // Urn: and uuid-in-package: subframe from WebBundle has an opaque origin |
| 254 | // derived from the Bundle's origin. |
| 255 | // TODO(https://crbug.com/1257045): Remove urn: scheme support. |
| 256 | if ((url.SchemeIs(url::kUrnScheme) || |
| 257 | url.SchemeIs(url::kUuidInPackageScheme)) && |
| 258 | subresource_web_bundle_navigation_info) { |
Kunihiko Sakamoto | 346a74e | 2021-03-10 08:57:48 | [diff] [blame] | 259 | return origin->CanBeDerivedFrom( |
| 260 | subresource_web_bundle_navigation_info->bundle_url()); |
| 261 | } |
| 262 | |
Nasko Oskov | 0391210 | 2019-01-11 00:21:32 | [diff] [blame] | 263 | return origin->CanBeDerivedFrom(url); |
| 264 | } |
| 265 | |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 266 | absl::optional<url::Origin> GetCommittedOriginForFrameEntry( |
Rakina Zata Amni | 3a1c0ec | 2021-04-15 03:35:12 | [diff] [blame] | 267 | const mojom::DidCommitProvisionalLoadParams& params, |
| 268 | NavigationRequest* request) { |
Nasko Oskov | 0391210 | 2019-01-11 00:21:32 | [diff] [blame] | 269 | // Error pages commit in an opaque origin, yet have the real URL that resulted |
| 270 | // in an error as the |params.url|. Since successful reload of an error page |
| 271 | // should commit in the correct origin, setting the opaque origin on the |
| 272 | // FrameNavigationEntry will be incorrect. |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 273 | if (request && request->DidEncounterError()) |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 274 | return absl::nullopt; |
Nasko Oskov | 0391210 | 2019-01-11 00:21:32 | [diff] [blame] | 275 | |
Rakina Zata Amni | 3a1c0ec | 2021-04-15 03:35:12 | [diff] [blame] | 276 | // We also currently don't save committed origins for loadDataWithBaseURL |
| 277 | // navigations (probably accidentally). Without this check, navigations to |
| 278 | // the FrameNavigationEntry might fail the DoesURLMatchOriginForNavigation() |
| 279 | // check since the origin will be based on the base URL instead of the data: |
| 280 | // URL used for the navigation. |
| 281 | // TODO(https://crbug.com/1198406): Save committed origin in |
| 282 | // FrameNavigationEntry for this case too. |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 283 | if (request && request->IsLoadDataWithBaseURL()) |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 284 | return absl::nullopt; |
Rakina Zata Amni | 3a1c0ec | 2021-04-15 03:35:12 | [diff] [blame] | 285 | |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 286 | return absl::make_optional(params.origin); |
Nasko Oskov | 0391210 | 2019-01-11 00:21:32 | [diff] [blame] | 287 | } |
| 288 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 289 | bool IsValidURLForNavigation(bool is_main_frame, |
| 290 | const GURL& virtual_url, |
| 291 | const GURL& dest_url) { |
| 292 | // Don't attempt to navigate if the virtual URL is non-empty and invalid. |
| 293 | if (is_main_frame && !virtual_url.is_valid() && !virtual_url.is_empty()) { |
| 294 | LOG(WARNING) << "Refusing to load for invalid virtual URL: " |
| 295 | << virtual_url.possibly_invalid_spec(); |
| 296 | return false; |
| 297 | } |
| 298 | |
| 299 | // Don't attempt to navigate to non-empty invalid URLs. |
| 300 | if (!dest_url.is_valid() && !dest_url.is_empty()) { |
| 301 | LOG(WARNING) << "Refusing to load invalid URL: " |
| 302 | << dest_url.possibly_invalid_spec(); |
| 303 | return false; |
| 304 | } |
| 305 | |
| 306 | // The renderer will reject IPC messages with URLs longer than |
| 307 | // this limit, so don't attempt to navigate with a longer URL. |
| 308 | if (dest_url.spec().size() > url::kMaxURLChars) { |
| 309 | LOG(WARNING) << "Refusing to load URL as it exceeds " << url::kMaxURLChars |
| 310 | << " characters."; |
| 311 | return false; |
| 312 | } |
| 313 | |
Aaron Colwell | 33109c59 | 2020-04-21 21:31:19 | [diff] [blame] | 314 | // Reject renderer debug URLs because they should have been handled before |
| 315 | // we get to this point. This check handles renderer debug URLs |
| 316 | // that are inside a view-source: URL (e.g. view-source:chrome://kill) and |
| 317 | // provides defense-in-depth if a renderer debug URL manages to get here via |
| 318 | // some other path. We want to reject the navigation here so it doesn't |
| 319 | // violate assumptions in downstream code. |
Gyuyoung Kim | 107c2a0 | 2021-04-13 01:49:30 | [diff] [blame] | 320 | if (blink::IsRendererDebugURL(dest_url)) { |
Aaron Colwell | 33109c59 | 2020-04-21 21:31:19 | [diff] [blame] | 321 | LOG(WARNING) << "Refusing to load renderer debug URL: " |
| 322 | << dest_url.possibly_invalid_spec(); |
| 323 | return false; |
| 324 | } |
| 325 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 326 | return true; |
| 327 | } |
| 328 | |
Mikel Astiz | ba9cf2fd | 2017-12-17 10:38:10 | [diff] [blame] | 329 | // See replaced_navigation_entry_data.h for details: this information is meant |
| 330 | // to ensure |*output_entry| keeps track of its original URL (landing page in |
| 331 | // case of server redirects) as it gets replaced (e.g. history.replaceState()), |
| 332 | // without overwriting it later, for main frames. |
| 333 | void CopyReplacedNavigationEntryDataIfPreviouslyEmpty( |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 334 | NavigationEntryImpl* replaced_entry, |
Mikel Astiz | ba9cf2fd | 2017-12-17 10:38:10 | [diff] [blame] | 335 | NavigationEntryImpl* output_entry) { |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 336 | if (output_entry->GetReplacedEntryData().has_value() || |
| 337 | replaced_entry->IsInitialEntry()) { |
Mikel Astiz | ba9cf2fd | 2017-12-17 10:38:10 | [diff] [blame] | 338 | return; |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 339 | } |
Mikel Astiz | ba9cf2fd | 2017-12-17 10:38:10 | [diff] [blame] | 340 | |
| 341 | ReplacedNavigationEntryData data; |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 342 | data.first_committed_url = replaced_entry->GetURL(); |
| 343 | data.first_timestamp = replaced_entry->GetTimestamp(); |
| 344 | data.first_transition_type = replaced_entry->GetTransitionType(); |
Charlie Reis | b55438f | 2019-01-08 01:54:29 | [diff] [blame] | 345 | output_entry->set_replaced_entry_data(data); |
Mikel Astiz | ba9cf2fd | 2017-12-17 10:38:10 | [diff] [blame] | 346 | } |
| 347 | |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 348 | blink::mojom::NavigationType GetNavigationType( |
| 349 | const GURL& old_url, |
| 350 | const GURL& new_url, |
| 351 | ReloadType reload_type, |
| 352 | NavigationEntryImpl* entry, |
| 353 | const FrameNavigationEntry& frame_entry, |
| 354 | bool has_pending_cross_document_commit, |
| 355 | bool is_currently_error_page, |
| 356 | bool is_same_document_history_load) { |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 357 | // Reload navigations |
| 358 | switch (reload_type) { |
| 359 | case ReloadType::NORMAL: |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 360 | return blink::mojom::NavigationType::RELOAD; |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 361 | case ReloadType::BYPASSING_CACHE: |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 362 | return blink::mojom::NavigationType::RELOAD_BYPASSING_CACHE; |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 363 | case ReloadType::ORIGINAL_REQUEST_URL: |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 364 | return blink::mojom::NavigationType::RELOAD_ORIGINAL_REQUEST_URL; |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 365 | case ReloadType::NONE: |
| 366 | break; // Fall through to rest of function. |
| 367 | } |
| 368 | |
Lukasz Anforowicz | 6b75c0d | 2020-12-01 22:56:08 | [diff] [blame] | 369 | if (entry->IsRestored()) { |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 370 | return entry->GetHasPostData() |
| 371 | ? blink::mojom::NavigationType::RESTORE_WITH_POST |
| 372 | : blink::mojom::NavigationType::RESTORE; |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 373 | } |
| 374 | |
danakj | b952ef1 | 2021-01-14 19:58:49 | [diff] [blame] | 375 | const bool can_be_same_document = |
| 376 | // A pending cross-document commit means this navigation will not occur in |
| 377 | // the current document, as that document would end up being replaced in |
| 378 | // the meantime. |
| 379 | !has_pending_cross_document_commit && |
| 380 | // If the current document is an error page, we should always treat it as |
| 381 | // a different-document navigation so that we'll attempt to load the |
| 382 | // document we're navigating to (and not stay in the current error page). |
| 383 | !is_currently_error_page; |
danakj | d83d706d | 2020-11-25 22:11:12 | [diff] [blame] | 384 | |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 385 | // History navigations. |
| 386 | if (frame_entry.page_state().IsValid()) { |
danakj | d83d706d | 2020-11-25 22:11:12 | [diff] [blame] | 387 | return can_be_same_document && is_same_document_history_load |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 388 | ? blink::mojom::NavigationType::HISTORY_SAME_DOCUMENT |
| 389 | : blink::mojom::NavigationType::HISTORY_DIFFERENT_DOCUMENT; |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 390 | } |
| 391 | DCHECK(!is_same_document_history_load); |
| 392 | |
| 393 | // A same-document fragment-navigation happens when the only part of the url |
| 394 | // that is modified is after the '#' character. |
| 395 | // |
| 396 | // When modifying this condition, please take a look at: |
danakj | d83d706d | 2020-11-25 22:11:12 | [diff] [blame] | 397 | // FrameLoader::ShouldPerformFragmentNavigation(). |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 398 | // |
| 399 | // Note: this check is only valid for navigations that are not history |
| 400 | // navigations. For instance, if the history is: 'A#bar' -> 'B' -> 'A#foo', a |
| 401 | // history navigation from 'A#foo' to 'A#bar' is not a same-document |
| 402 | // navigation, but a different-document one. This is why history navigation |
| 403 | // are classified before this check. |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 404 | bool is_same_doc = new_url.has_ref() && old_url.EqualsIgnoringRef(new_url) && |
| 405 | frame_entry.method() == "GET"; |
danakj | d83d706d | 2020-11-25 22:11:12 | [diff] [blame] | 406 | |
| 407 | // The one case where we do the wrong thing here and incorrectly choose |
| 408 | // SAME_DOCUMENT is if the navigation is browser-initiated but the document in |
| 409 | // the renderer is a frameset. All frameset navigations should be |
| 410 | // DIFFERENT_DOCUMENT, even if their URLs match. A renderer-initiated |
| 411 | // navigation would do the right thing, as it would send it to the browser and |
| 412 | // all renderer-initiated navigations are DIFFERENT_DOCUMENT (they don't get |
| 413 | // into this method). But since we can't tell that case here for browser- |
| 414 | // initiated navigations, we have to get the renderer involved. In that case |
| 415 | // the navigation would be restarted due to the renderer spending a reply of |
| 416 | // mojom::CommitResult::RestartCrossDocument. |
| 417 | |
| 418 | return can_be_same_document && is_same_doc |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 419 | ? blink::mojom::NavigationType::SAME_DOCUMENT |
| 420 | : blink::mojom::NavigationType::DIFFERENT_DOCUMENT; |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 421 | } |
| 422 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 423 | // Adjusts the original input URL if needed, to get the URL to actually load and |
| 424 | // the virtual URL, which may differ. |
| 425 | void RewriteUrlForNavigation(const GURL& original_url, |
| 426 | BrowserContext* browser_context, |
| 427 | GURL* url_to_load, |
| 428 | GURL* virtual_url, |
| 429 | bool* reverse_on_redirect) { |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 430 | // Allow the browser URL handler to rewrite the URL. This will, for example, |
| 431 | // remove "view-source:" from the beginning of the URL to get the URL that |
| 432 | // will actually be loaded. This real URL won't be shown to the user, just |
| 433 | // used internally. |
Lukasz Anforowicz | 7b07879 | 2020-10-20 17:04:31 | [diff] [blame] | 434 | *url_to_load = *virtual_url = original_url; |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 435 | BrowserURLHandlerImpl::GetInstance()->RewriteURLIfNecessary( |
| 436 | url_to_load, browser_context, reverse_on_redirect); |
| 437 | } |
| 438 | |
| 439 | #if DCHECK_IS_ON() |
| 440 | // Helper sanity check function used in debug mode. |
| 441 | void ValidateRequestMatchesEntry(NavigationRequest* request, |
| 442 | NavigationEntryImpl* entry) { |
| 443 | if (request->frame_tree_node()->IsMainFrame()) { |
| 444 | DCHECK_EQ(request->browser_initiated(), !entry->is_renderer_initiated()); |
| 445 | DCHECK(ui::PageTransitionTypeIncludingQualifiersIs( |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 446 | ui::PageTransitionFromInt(request->common_params().transition), |
| 447 | entry->GetTransitionType())); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 448 | } |
Nasko Oskov | c36327d | 2019-01-03 23:23:04 | [diff] [blame] | 449 | DCHECK_EQ(request->commit_params().should_clear_history_list, |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 450 | entry->should_clear_history_list()); |
| 451 | DCHECK_EQ(request->common_params().has_user_gesture, |
| 452 | entry->has_user_gesture()); |
| 453 | DCHECK_EQ(request->common_params().base_url_for_data_url, |
| 454 | entry->GetBaseURLForDataURL()); |
Nasko Oskov | c36327d | 2019-01-03 23:23:04 | [diff] [blame] | 455 | DCHECK_EQ(request->commit_params().can_load_local_resources, |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 456 | entry->GetCanLoadLocalResources()); |
| 457 | DCHECK_EQ(request->common_params().started_from_context_menu, |
| 458 | entry->has_started_from_context_menu()); |
| 459 | |
| 460 | FrameNavigationEntry* frame_entry = |
| 461 | entry->GetFrameEntry(request->frame_tree_node()); |
| 462 | if (!frame_entry) { |
| 463 | NOTREACHED(); |
| 464 | return; |
| 465 | } |
| 466 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 467 | DCHECK_EQ(request->common_params().method, frame_entry->method()); |
| 468 | |
Nasko Oskov | c36327d | 2019-01-03 23:23:04 | [diff] [blame] | 469 | size_t redirect_size = request->commit_params().redirects.size(); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 470 | if (redirect_size == frame_entry->redirect_chain().size()) { |
| 471 | for (size_t i = 0; i < redirect_size; ++i) { |
Nasko Oskov | c36327d | 2019-01-03 23:23:04 | [diff] [blame] | 472 | DCHECK_EQ(request->commit_params().redirects[i], |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 473 | frame_entry->redirect_chain()[i]); |
| 474 | } |
| 475 | } else { |
| 476 | NOTREACHED(); |
| 477 | } |
| 478 | } |
| 479 | #endif // DCHECK_IS_ON() |
| 480 | |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 481 | // Returns whether the session history NavigationRequests in |navigations| |
| 482 | // would stay within the subtree of the sandboxed iframe in |
| 483 | // |sandbox_frame_tree_node_id|. |
| 484 | bool DoesSandboxNavigationStayWithinSubtree( |
| 485 | int sandbox_frame_tree_node_id, |
| 486 | const std::vector<std::unique_ptr<NavigationRequest>>& navigations) { |
| 487 | for (auto& item : navigations) { |
| 488 | bool within_subtree = false; |
| 489 | // Check whether this NavigationRequest affects a frame within the |
| 490 | // sandboxed frame's subtree by walking up the tree looking for the |
| 491 | // sandboxed frame. |
| 492 | for (auto* frame = item->frame_tree_node(); frame; |
Alexander Timin | 381e7e18 | 2020-04-28 19:04:03 | [diff] [blame] | 493 | frame = FrameTreeNode::From(frame->parent())) { |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 494 | if (frame->frame_tree_node_id() == sandbox_frame_tree_node_id) { |
| 495 | within_subtree = true; |
| 496 | break; |
| 497 | } |
| 498 | } |
| 499 | if (!within_subtree) |
| 500 | return false; |
| 501 | } |
| 502 | return true; |
| 503 | } |
| 504 | |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 505 | } // namespace |
| 506 | |
arthursonzogni | 66f711c | 2019-10-08 14:40:36 | [diff] [blame] | 507 | // NavigationControllerImpl::PendingEntryRef------------------------------------ |
| 508 | |
| 509 | NavigationControllerImpl::PendingEntryRef::PendingEntryRef( |
| 510 | base::WeakPtr<NavigationControllerImpl> controller) |
| 511 | : controller_(controller) {} |
| 512 | |
| 513 | NavigationControllerImpl::PendingEntryRef::~PendingEntryRef() { |
| 514 | if (!controller_) // Can be null with interstitials. |
| 515 | return; |
| 516 | |
| 517 | controller_->PendingEntryRefDeleted(this); |
| 518 | } |
| 519 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 520 | // NavigationControllerImpl ---------------------------------------------------- |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 521 | |
[email protected] | 23a918b | 2014-07-15 09:51:36 | [diff] [blame] | 522 | const size_t kMaxEntryCountForTestingNotSet = static_cast<size_t>(-1); |
[email protected] | 9b51970d | 2011-12-09 23:10:23 | [diff] [blame] | 523 | |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 524 | // static |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 525 | size_t NavigationControllerImpl::max_entry_count_for_testing_ = |
[email protected] | 9b51970d | 2011-12-09 23:10:23 | [diff] [blame] | 526 | kMaxEntryCountForTestingNotSet; |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 527 | |
[email protected] | e6fec47 | 2013-05-14 05:29:02 | [diff] [blame] | 528 | // 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] | 529 | // when testing. |
| 530 | static bool g_check_for_repost = true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 531 | |
[email protected] | 71fde35 | 2011-12-29 03:29:56 | [diff] [blame] | 532 | // static |
dcheng | 9bfa516 | 2016-04-09 01:00:57 | [diff] [blame] | 533 | std::unique_ptr<NavigationEntry> NavigationController::CreateNavigationEntry( |
| 534 | const GURL& url, |
Lukasz Anforowicz | 641234d5 | 2019-11-07 21:07:10 | [diff] [blame] | 535 | Referrer referrer, |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 536 | absl::optional<url::Origin> initiator_origin, |
Lukasz Anforowicz | 641234d5 | 2019-11-07 21:07:10 | [diff] [blame] | 537 | ui::PageTransition transition, |
| 538 | bool is_renderer_initiated, |
| 539 | const std::string& extra_headers, |
| 540 | BrowserContext* browser_context, |
| 541 | scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory) { |
| 542 | return NavigationControllerImpl::CreateNavigationEntry( |
| 543 | url, referrer, std::move(initiator_origin), |
| 544 | nullptr /* source_site_instance */, transition, is_renderer_initiated, |
Hayato Ito | 303654c | 2021-06-30 09:07:54 | [diff] [blame] | 545 | extra_headers, browser_context, std::move(blob_url_loader_factory)); |
Lukasz Anforowicz | 641234d5 | 2019-11-07 21:07:10 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | // static |
| 549 | std::unique_ptr<NavigationEntryImpl> |
| 550 | NavigationControllerImpl::CreateNavigationEntry( |
| 551 | const GURL& url, |
| 552 | Referrer referrer, |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 553 | absl::optional<url::Origin> initiator_origin, |
Lukasz Anforowicz | 641234d5 | 2019-11-07 21:07:10 | [diff] [blame] | 554 | SiteInstance* source_site_instance, |
dcheng | 9bfa516 | 2016-04-09 01:00:57 | [diff] [blame] | 555 | ui::PageTransition transition, |
| 556 | bool is_renderer_initiated, |
| 557 | const std::string& extra_headers, |
Marijn Kruisselbrink | 7a0d5e18 | 2018-05-24 22:55:09 | [diff] [blame] | 558 | BrowserContext* browser_context, |
Hayato Ito | 303654c | 2021-06-30 09:07:54 | [diff] [blame] | 559 | scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory) { |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 560 | GURL url_to_load; |
| 561 | GURL virtual_url; |
[email protected] | 71fde35 | 2011-12-29 03:29:56 | [diff] [blame] | 562 | bool reverse_on_redirect = false; |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 563 | RewriteUrlForNavigation(url, browser_context, &url_to_load, &virtual_url, |
| 564 | &reverse_on_redirect); |
[email protected] | 71fde35 | 2011-12-29 03:29:56 | [diff] [blame] | 565 | |
Lukasz Anforowicz | 641234d5 | 2019-11-07 21:07:10 | [diff] [blame] | 566 | // Let the NTP override the navigation params and pretend that this is a |
| 567 | // browser-initiated, bookmark-like navigation. |
| 568 | GetContentClient()->browser()->OverrideNavigationParams( |
Scott Violet | cf6ea7e | 2021-06-09 21:09:21 | [diff] [blame] | 569 | source_site_instance, &transition, &is_renderer_initiated, &referrer, |
| 570 | &initiator_origin); |
Lukasz Anforowicz | 641234d5 | 2019-11-07 21:07:10 | [diff] [blame] | 571 | |
Patrick Monette | f507e98 | 2019-06-19 20:18:06 | [diff] [blame] | 572 | auto entry = std::make_unique<NavigationEntryImpl>( |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 573 | nullptr, // The site instance for tabs is sent on navigation |
| 574 | // (WebContents::GetSiteInstance). |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 575 | url_to_load, referrer, initiator_origin, std::u16string(), transition, |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 576 | is_renderer_initiated, blob_url_loader_factory, |
| 577 | /* is_initial_entry = */ false); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 578 | entry->SetVirtualURL(virtual_url); |
| 579 | entry->set_user_typed_url(virtual_url); |
[email protected] | 71fde35 | 2011-12-29 03:29:56 | [diff] [blame] | 580 | entry->set_update_virtual_url_with_url(reverse_on_redirect); |
| 581 | entry->set_extra_headers(extra_headers); |
Patrick Monette | f507e98 | 2019-06-19 20:18:06 | [diff] [blame] | 582 | return entry; |
[email protected] | 71fde35 | 2011-12-29 03:29:56 | [diff] [blame] | 583 | } |
| 584 | |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 585 | // static |
| 586 | void NavigationController::DisablePromptOnRepost() { |
| 587 | g_check_for_repost = false; |
| 588 | } |
| 589 | |
[email protected] | c5b88d8 | 2012-10-06 17:03:33 | [diff] [blame] | 590 | base::Time NavigationControllerImpl::TimeSmoother::GetSmoothedTime( |
| 591 | base::Time t) { |
| 592 | // If |t| is between the water marks, we're in a run of duplicates |
| 593 | // or just getting out of it, so increase the high-water mark to get |
| 594 | // a time that probably hasn't been used before and return it. |
| 595 | if (low_water_mark_ <= t && t <= high_water_mark_) { |
Peter Kasting | e5a38ed | 2021-10-02 03:06:35 | [diff] [blame] | 596 | high_water_mark_ += base::Microseconds(1); |
[email protected] | c5b88d8 | 2012-10-06 17:03:33 | [diff] [blame] | 597 | return high_water_mark_; |
| 598 | } |
| 599 | |
| 600 | // Otherwise, we're clear of the last duplicate run, so reset the |
| 601 | // water marks. |
| 602 | low_water_mark_ = high_water_mark_ = t; |
| 603 | return t; |
| 604 | } |
| 605 | |
ckitagawa | 0faa5e4 | 2020-06-17 17:30:54 | [diff] [blame] | 606 | NavigationControllerImpl::ScopedShowRepostDialogForTesting:: |
| 607 | ScopedShowRepostDialogForTesting() |
| 608 | : was_disallowed_(g_check_for_repost) { |
| 609 | g_check_for_repost = true; |
| 610 | } |
| 611 | |
| 612 | NavigationControllerImpl::ScopedShowRepostDialogForTesting:: |
| 613 | ~ScopedShowRepostDialogForTesting() { |
| 614 | g_check_for_repost = was_disallowed_; |
| 615 | } |
| 616 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 617 | NavigationControllerImpl::NavigationControllerImpl( |
Carlos Caballero | 40b0efd | 2021-01-26 11:55:00 | [diff] [blame] | 618 | BrowserContext* browser_context, |
| 619 | FrameTree& frame_tree, |
| 620 | NavigationControllerDelegate* delegate) |
| 621 | : frame_tree_(frame_tree), |
| 622 | browser_context_(browser_context), |
[email protected] | ec6c05f | 2013-10-23 18:41:57 | [diff] [blame] | 623 | delegate_(delegate), |
[email protected] | 69e797f | 2013-04-30 01:10:22 | [diff] [blame] | 624 | ssl_manager_(this), |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 625 | get_timestamp_callback_(base::BindRepeating(&base::Time::Now)) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 626 | DCHECK(browser_context_); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 627 | } |
| 628 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 629 | NavigationControllerImpl::~NavigationControllerImpl() { |
arthursonzogni | 69a6a1b | 2019-09-17 09:23:00 | [diff] [blame] | 630 | // The NavigationControllerImpl might be called inside its delegate |
| 631 | // destructor. Calling it is not valid anymore. |
| 632 | delegate_ = nullptr; |
| 633 | DiscardNonCommittedEntries(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 634 | } |
| 635 | |
Matt Falkenhagen | 548ed156 | 2021-07-06 01:38:26 | [diff] [blame] | 636 | WebContents* NavigationControllerImpl::DeprecatedGetWebContents() { |
| 637 | return delegate_->DeprecatedGetWebContents(); |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 638 | } |
| 639 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 640 | BrowserContext* NavigationControllerImpl::GetBrowserContext() { |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 641 | return browser_context_; |
| 642 | } |
| 643 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 644 | void NavigationControllerImpl::Restore( |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 645 | int selected_navigation, |
[email protected] | 2ca1ea66 | 2012-10-04 02:26:36 | [diff] [blame] | 646 | RestoreType type, |
dcheng | 9bfa516 | 2016-04-09 01:00:57 | [diff] [blame] | 647 | std::vector<std::unique_ptr<NavigationEntry>>* entries) { |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 648 | // Verify that this controller is unused and that the input is valid. |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 649 | if (blink::features::IsInitialNavigationEntryEnabled()) { |
| 650 | DCHECK_EQ(1, GetEntryCount()); |
| 651 | DCHECK(GetLastCommittedEntry()->IsInitialEntry()); |
| 652 | } else { |
| 653 | DCHECK_EQ(0, GetEntryCount()); |
| 654 | } |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 655 | DCHECK(!GetPendingEntry()); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 656 | DCHECK(selected_navigation >= 0 && |
[email protected] | 03838e2 | 2011-06-06 15:27:14 | [diff] [blame] | 657 | selected_navigation < static_cast<int>(entries->size())); |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 658 | DCHECK_EQ(-1, pending_entry_index_); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 659 | |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 660 | needs_reload_ = true; |
Bo Liu | cdfa4b1 | 2018-11-06 00:21:44 | [diff] [blame] | 661 | needs_reload_type_ = NeedsReloadType::kRestoreSession; |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 662 | entries_.clear(); |
avi | f16f85a7 | 2015-11-13 18:25:03 | [diff] [blame] | 663 | entries_.reserve(entries->size()); |
| 664 | for (auto& entry : *entries) |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame] | 665 | entries_.push_back( |
| 666 | NavigationEntryImpl::FromNavigationEntry(std::move(entry))); |
avi | f16f85a7 | 2015-11-13 18:25:03 | [diff] [blame] | 667 | |
| 668 | // At this point, the |entries| is full of empty scoped_ptrs, so it can be |
| 669 | // cleared out safely. |
| 670 | entries->clear(); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 671 | |
| 672 | // And finish the restore. |
[email protected] | 2ca1ea66 | 2012-10-04 02:26:36 | [diff] [blame] | 673 | FinishRestore(selected_navigation, type); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 674 | } |
| 675 | |
toyoshim | 6142d96f | 2016-12-19 09:07:25 | [diff] [blame] | 676 | void NavigationControllerImpl::Reload(ReloadType reload_type, |
| 677 | bool check_for_repost) { |
liaoyuke | 9168fba | 2017-03-10 19:20:28 | [diff] [blame] | 678 | DCHECK_NE(ReloadType::NONE, reload_type); |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 679 | NavigationEntryImpl* entry = nullptr; |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 680 | int current_index = -1; |
| 681 | |
Carlos IL | 42b41659 | 2019-10-07 23:10:36 | [diff] [blame] | 682 | if (entry_replaced_by_post_commit_error_) { |
| 683 | // If there is an entry that was replaced by a currently active post-commit |
| 684 | // error navigation, this can't be the initial navigation. |
| 685 | DCHECK(!IsInitialNavigation()); |
| 686 | // If the current entry is a post commit error, we reload the entry it |
| 687 | // replaced instead. We leave the error entry in place until a commit |
| 688 | // replaces it, but the pending entry points to the original entry in the |
| 689 | // meantime. Note that NavigateToExistingPendingEntry is able to handle the |
| 690 | // case that pending_entry_ != entries_[pending_entry_index_]. |
| 691 | entry = entry_replaced_by_post_commit_error_.get(); |
| 692 | current_index = GetCurrentEntryIndex(); |
| 693 | } else if (IsInitialNavigation() && pending_entry_) { |
| 694 | // If we are reloading the initial navigation, just use the current |
| 695 | // pending entry. Otherwise look up the current entry. |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 696 | entry = pending_entry_; |
| 697 | // The pending entry might be in entries_ (e.g., after a Clone), so we |
| 698 | // should also update the current_index. |
| 699 | current_index = pending_entry_index_; |
| 700 | } else { |
arthursonzogni | 69a6a1b | 2019-09-17 09:23:00 | [diff] [blame] | 701 | DiscardNonCommittedEntries(); |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 702 | current_index = GetCurrentEntryIndex(); |
| 703 | if (current_index != -1) { |
creis | 3da0387 | 2015-02-20 21:12:32 | [diff] [blame] | 704 | entry = GetEntryAtIndex(current_index); |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 705 | } |
[email protected] | 979a4bc | 2013-04-24 01:27:15 | [diff] [blame] | 706 | } |
[email protected] | 241db35 | 2013-04-22 18:04:05 | [diff] [blame] | 707 | |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 708 | // If we are no where, then we can't reload. TODO(darin): We should add a |
| 709 | // CanReload method. |
| 710 | if (!entry) |
| 711 | return; |
| 712 | |
Rakina Zata Amni | f297a80 | 2022-01-18 03:53:43 | [diff] [blame] | 713 | if (entry->IsInitialEntryNotForSynchronousAboutBlank()) { |
| 714 | // We should never navigate to an existing initial NavigationEntry that is |
| 715 | // the initial NavigationEntry for the initial empty document that hasn't |
| 716 | // been overridden by the synchronous about:blank commit, to preserve |
| 717 | // legacy behavior where trying to reload when the main frame is on the |
| 718 | // initial empty document won't result in a navigation. See also |
| 719 | // https://crbug.com/1277414. |
| 720 | return; |
| 721 | } |
| 722 | |
Takashi Toyoshima | c7df3c2 | 2019-06-25 14:18:47 | [diff] [blame] | 723 | // Set ReloadType for |entry|. |
toyoshim | a63c2a6 | 2016-09-29 09:03:26 | [diff] [blame] | 724 | entry->set_reload_type(reload_type); |
| 725 | |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 726 | if (g_check_for_repost && check_for_repost && entry->GetHasPostData()) { |
[email protected] | a3a1d14 | 2008-12-19 00:42:30 | [diff] [blame] | 727 | // 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] | 728 | // they really want to do this. If they do, the dialog will call us back |
| 729 | // with check_for_repost = false. |
[email protected] | ec6c05f | 2013-10-23 18:41:57 | [diff] [blame] | 730 | delegate_->NotifyBeforeFormRepostWarningShow(); |
[email protected] | 965bb09 | 2010-04-09 11:59:02 | [diff] [blame] | 731 | |
[email protected] | 106a081 | 2010-03-18 00:15:12 | [diff] [blame] | 732 | pending_reload_ = reload_type; |
[email protected] | ec6c05f | 2013-10-23 18:41:57 | [diff] [blame] | 733 | delegate_->ActivateAndShowRepostFormWarningDialog(); |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 734 | return; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 735 | } |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 736 | |
| 737 | if (!IsInitialNavigation()) |
| 738 | DiscardNonCommittedEntries(); |
| 739 | |
| 740 | pending_entry_ = entry; |
| 741 | pending_entry_index_ = current_index; |
| 742 | pending_entry_->SetTransitionType(ui::PAGE_TRANSITION_RELOAD); |
| 743 | |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 744 | // location.reload() goes through BeginNavigation, so all reloads triggered |
| 745 | // via this codepath are browser initiated. |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 746 | NavigateToExistingPendingEntry(reload_type, |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 747 | FrameTreeNode::kFrameTreeNodeInvalidId, |
| 748 | true /* is_browser_initiated */); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 749 | } |
| 750 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 751 | void NavigationControllerImpl::CancelPendingReload() { |
toyoshim | 0df1d3a | 2016-09-09 09:52:48 | [diff] [blame] | 752 | DCHECK(pending_reload_ != ReloadType::NONE); |
| 753 | pending_reload_ = ReloadType::NONE; |
[email protected] | 106a081 | 2010-03-18 00:15:12 | [diff] [blame] | 754 | } |
| 755 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 756 | void NavigationControllerImpl::ContinuePendingReload() { |
toyoshim | 0df1d3a | 2016-09-09 09:52:48 | [diff] [blame] | 757 | if (pending_reload_ == ReloadType::NONE) { |
[email protected] | 106a081 | 2010-03-18 00:15:12 | [diff] [blame] | 758 | NOTREACHED(); |
| 759 | } else { |
toyoshim | 6142d96f | 2016-12-19 09:07:25 | [diff] [blame] | 760 | Reload(pending_reload_, false); |
toyoshim | 0df1d3a | 2016-09-09 09:52:48 | [diff] [blame] | 761 | pending_reload_ = ReloadType::NONE; |
[email protected] | 106a081 | 2010-03-18 00:15:12 | [diff] [blame] | 762 | } |
| 763 | } |
| 764 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 765 | bool NavigationControllerImpl::IsInitialNavigation() { |
[email protected] | 27ba81c | 2012-08-21 17:04:09 | [diff] [blame] | 766 | return is_initial_navigation_; |
[email protected] | c70f9b8 | 2010-04-21 07:31:11 | [diff] [blame] | 767 | } |
| 768 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 769 | bool NavigationControllerImpl::IsInitialBlankNavigation() { |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 770 | if (blink::features::IsInitialNavigationEntryEnabled()) { |
| 771 | // Check that we're on the initial NavigationEntry and that this is not a |
| 772 | // cloned tab. |
| 773 | return IsInitialNavigation() && GetEntryCount() == 1 && |
| 774 | GetLastCommittedEntry()->IsInitialEntry() && |
| 775 | GetLastCommittedEntry()->restore_type() == RestoreType::kNotRestored; |
| 776 | } else { |
| 777 | return IsInitialNavigation() && GetEntryCount() == 0; |
| 778 | } |
creis | 10a4ab7 | 2015-10-13 17:22:40 | [diff] [blame] | 779 | } |
| 780 | |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 781 | NavigationEntryImpl* NavigationControllerImpl::GetEntryWithUniqueID( |
| 782 | int nav_entry_id) const { |
avi | 254eff0 | 2015-07-01 08:27:58 | [diff] [blame] | 783 | int index = GetEntryIndexWithUniqueID(nav_entry_id); |
avi | f16f85a7 | 2015-11-13 18:25:03 | [diff] [blame] | 784 | return (index != -1) ? entries_[index].get() : nullptr; |
avi | 254eff0 | 2015-07-01 08:27:58 | [diff] [blame] | 785 | } |
| 786 | |
Adithya Srinivasan | 9b0c99c | 2021-08-10 15:19:45 | [diff] [blame] | 787 | NavigationEntryImpl* |
| 788 | NavigationControllerImpl::GetEntryWithUniqueIDIncludingPending( |
| 789 | int nav_entry_id) const { |
| 790 | NavigationEntryImpl* entry = GetEntryWithUniqueID(nav_entry_id); |
| 791 | if (entry) |
| 792 | return entry; |
| 793 | return pending_entry_ && pending_entry_->GetUniqueID() == nav_entry_id |
Keishi Hattori | 0e45c02 | 2021-11-27 09:25:52 | [diff] [blame] | 794 | ? pending_entry_.get() |
Adithya Srinivasan | 9b0c99c | 2021-08-10 15:19:45 | [diff] [blame] | 795 | : nullptr; |
| 796 | } |
| 797 | |
W. James MacLean | 1c40862c | 2020-04-27 21:05:57 | [diff] [blame] | 798 | void NavigationControllerImpl::RegisterExistingOriginToPreventOptInIsolation( |
| 799 | const url::Origin& origin) { |
| 800 | for (int i = 0; i < GetEntryCount(); i++) { |
| 801 | auto* entry = GetEntryAtIndex(i); |
| 802 | entry->RegisterExistingOriginToPreventOptInIsolation(origin); |
| 803 | } |
| 804 | if (entry_replaced_by_post_commit_error_) { |
| 805 | // It's possible we could come back to this entry if the error |
| 806 | // page/interstitial goes away. |
| 807 | entry_replaced_by_post_commit_error_ |
| 808 | ->RegisterExistingOriginToPreventOptInIsolation(origin); |
| 809 | } |
| 810 | // TODO(wjmaclean): Register pending commit NavigationRequests rather than |
| 811 | // visiting pending_entry_, which lacks a committed origin. This will be done |
| 812 | // in https://chromium-review.googlesource.com/c/chromium/src/+/2136703. |
| 813 | } |
| 814 | |
avi | 2576470 | 2015-06-23 15:43:37 | [diff] [blame] | 815 | void NavigationControllerImpl::SetPendingEntry( |
dcheng | 9bfa516 | 2016-04-09 01:00:57 | [diff] [blame] | 816 | std::unique_ptr<NavigationEntryImpl> entry) { |
arthursonzogni | 69a6a1b | 2019-09-17 09:23:00 | [diff] [blame] | 817 | DiscardNonCommittedEntries(); |
avi | 2576470 | 2015-06-23 15:43:37 | [diff] [blame] | 818 | pending_entry_ = entry.release(); |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 819 | DCHECK_EQ(-1, pending_entry_index_); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 820 | } |
| 821 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 822 | NavigationEntryImpl* NavigationControllerImpl::GetActiveEntry() { |
[email protected] | cbab76d | 2008-10-13 22:42:47 | [diff] [blame] | 823 | if (pending_entry_) |
| 824 | return pending_entry_; |
| 825 | return GetLastCommittedEntry(); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 826 | } |
| 827 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 828 | NavigationEntryImpl* NavigationControllerImpl::GetVisibleEntry() { |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 829 | // The pending entry is safe to return for new (non-history), browser- |
| 830 | // initiated navigations. Most renderer-initiated navigations should not |
| 831 | // show the pending entry, to prevent URL spoof attacks. |
| 832 | // |
| 833 | // We make an exception for renderer-initiated navigations in new tabs, as |
| 834 | // long as no other page has tried to access the initial empty document in |
| 835 | // the new tab. If another page modifies this blank page, a URL spoof is |
| 836 | // possible, so we must stop showing the pending entry. |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 837 | bool safe_to_show_pending = |
| 838 | pending_entry_ && |
| 839 | // Require a new navigation. |
avi | 0dca04d | 2015-01-26 20:21:09 | [diff] [blame] | 840 | pending_entry_index_ == -1 && |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 841 | // Require either browser-initiated or an unmodified new tab. |
[email protected] | aa62afd | 2014-04-22 19:22:46 | [diff] [blame] | 842 | (!pending_entry_->is_renderer_initiated() || IsUnmodifiedBlankTab()); |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 843 | |
| 844 | // Also allow showing the pending entry for history navigations in a new tab, |
| 845 | // such as Ctrl+Back. In this case, no existing page is visible and no one |
| 846 | // can script the new tab before it commits. |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 847 | if (!safe_to_show_pending && pending_entry_ && pending_entry_index_ != -1 && |
| 848 | IsInitialNavigation() && !pending_entry_->is_renderer_initiated()) |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 849 | safe_to_show_pending = true; |
| 850 | |
| 851 | if (safe_to_show_pending) |
[email protected] | 867e1f9 | 2011-08-30 19:01:19 | [diff] [blame] | 852 | return pending_entry_; |
| 853 | return GetLastCommittedEntry(); |
| 854 | } |
| 855 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 856 | int NavigationControllerImpl::GetCurrentEntryIndex() { |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 857 | if (pending_entry_index_ != -1) |
| 858 | return pending_entry_index_; |
| 859 | return last_committed_entry_index_; |
| 860 | } |
| 861 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 862 | NavigationEntryImpl* NavigationControllerImpl::GetLastCommittedEntry() { |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 863 | if (last_committed_entry_index_ == -1) { |
| 864 | // The last committed entry must always exist when InitialNavigationEntry |
| 865 | // is enabled. TODO(https://crbug.com/524208): Remove this case and all |
| 866 | // related nullchecks entirely. |
| 867 | DCHECK(!blink::features::IsInitialNavigationEntryEnabled()); |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 868 | return nullptr; |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 869 | } |
avi | f16f85a7 | 2015-11-13 18:25:03 | [diff] [blame] | 870 | return entries_[last_committed_entry_index_].get(); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 871 | } |
| 872 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 873 | bool NavigationControllerImpl::CanViewSource() { |
Jeremy Roman | 2d8dfe13 | 2021-07-06 20:51:26 | [diff] [blame] | 874 | const std::string& mime_type = |
| 875 | frame_tree_.root()->current_frame_host()->GetPage().contents_mime_type(); |
Kinuko Yasuda | 74702f9 | 2017-07-31 03:27:53 | [diff] [blame] | 876 | bool is_viewable_mime_type = blink::IsSupportedNonImageMimeType(mime_type) && |
| 877 | !media::IsSupportedMediaMimeType(mime_type); |
[email protected] | 6286a379 | 2013-10-09 04:03:27 | [diff] [blame] | 878 | NavigationEntry* visible_entry = GetVisibleEntry(); |
| 879 | return visible_entry && !visible_entry->IsViewSourceMode() && |
Carlos IL | d51e770 | 2020-05-07 18:51:39 | [diff] [blame] | 880 | is_viewable_mime_type; |
[email protected] | 3168228 | 2010-01-15 18:05:16 | [diff] [blame] | 881 | } |
| 882 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 883 | int NavigationControllerImpl::GetLastCommittedEntryIndex() { |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 884 | // 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^] | 885 | // entries. If there are no entries, it must be -1. |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 886 | DCHECK_LT(last_committed_entry_index_, GetEntryCount()); |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 887 | DCHECK(GetEntryCount() || last_committed_entry_index_ == -1); |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 888 | return last_committed_entry_index_; |
| 889 | } |
| 890 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 891 | int NavigationControllerImpl::GetEntryCount() { |
Carlos IL | 4dea890 | 2020-05-26 15:14:29 | [diff] [blame] | 892 | DCHECK_LE(entries_.size(), max_entry_count()); |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 893 | return static_cast<int>(entries_.size()); |
| 894 | } |
| 895 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 896 | NavigationEntryImpl* NavigationControllerImpl::GetEntryAtIndex(int index) { |
avi | 2576470 | 2015-06-23 15:43:37 | [diff] [blame] | 897 | if (index < 0 || index >= GetEntryCount()) |
| 898 | return nullptr; |
| 899 | |
avi | f16f85a7 | 2015-11-13 18:25:03 | [diff] [blame] | 900 | return entries_[index].get(); |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 901 | } |
| 902 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 903 | NavigationEntryImpl* NavigationControllerImpl::GetEntryAtOffset(int offset) { |
avi | 057ce149 | 2015-06-29 15:59:47 | [diff] [blame] | 904 | return GetEntryAtIndex(GetIndexForOffset(offset)); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 905 | } |
| 906 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 907 | int NavigationControllerImpl::GetIndexForOffset(int offset) { |
[email protected] | 7bc2b03 | 2012-12-19 22:45:46 | [diff] [blame] | 908 | return GetCurrentEntryIndex() + offset; |
[email protected] | 9ba1405 | 2012-06-22 23:50:03 | [diff] [blame] | 909 | } |
| 910 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 911 | bool NavigationControllerImpl::CanGoBack() { |
Shivani Sharma | 298d1285 | 2019-01-22 20:04:03 | [diff] [blame] | 912 | for (int index = GetIndexForOffset(-1); index >= 0; index--) { |
| 913 | if (!GetEntryAtIndex(index)->should_skip_on_back_forward_ui()) |
| 914 | return true; |
| 915 | } |
| 916 | return false; |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 917 | } |
| 918 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 919 | bool NavigationControllerImpl::CanGoForward() { |
WangHui | 74286d5 | 2021-03-31 16:17:15 | [diff] [blame] | 920 | for (int index = GetIndexForOffset(1); index < GetEntryCount(); index++) { |
| 921 | if (!GetEntryAtIndex(index)->should_skip_on_back_forward_ui()) |
| 922 | return true; |
| 923 | } |
| 924 | return false; |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 925 | } |
| 926 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 927 | bool NavigationControllerImpl::CanGoToOffset(int offset) { |
[email protected] | 9ba1405 | 2012-06-22 23:50:03 | [diff] [blame] | 928 | int index = GetIndexForOffset(offset); |
| 929 | return index >= 0 && index < GetEntryCount(); |
| 930 | } |
| 931 | |
Xiaohan Wang | 7f8052e0 | 2022-01-14 18:44:28 | [diff] [blame] | 932 | #if BUILDFLAG(IS_ANDROID) |
WangHui | 74286d5 | 2021-03-31 16:17:15 | [diff] [blame] | 933 | bool NavigationControllerImpl::CanGoToOffsetWithSkipping(int offset) { |
WangHui | 74286d5 | 2021-03-31 16:17:15 | [diff] [blame] | 934 | if (offset == 0) |
| 935 | return true; |
| 936 | int increment = offset > 0 ? 1 : -1; |
| 937 | int non_skippable_entries = 0; |
| 938 | for (int index = GetIndexForOffset(increment); |
| 939 | index >= 0 && index < GetEntryCount(); index += increment) { |
| 940 | if (!GetEntryAtIndex(index)->should_skip_on_back_forward_ui()) |
| 941 | non_skippable_entries++; |
| 942 | |
| 943 | if (non_skippable_entries == std::abs(offset)) |
| 944 | return true; |
| 945 | } |
| 946 | return false; |
| 947 | } |
| 948 | #endif |
| 949 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 950 | void NavigationControllerImpl::GoBack() { |
shivanisha | 5520187 | 2018-12-13 04:29:06 | [diff] [blame] | 951 | int target_index = GetIndexForOffset(-1); |
| 952 | |
Elly Fong-Jones | 40ee811 | 2021-06-23 19:10:52 | [diff] [blame] | 953 | // Move the target index past the skippable entries. |
Shivani Sharma | 298d1285 | 2019-01-22 20:04:03 | [diff] [blame] | 954 | bool all_skippable_entries = true; |
Elly Fong-Jones | 40ee811 | 2021-06-23 19:10:52 | [diff] [blame] | 955 | while (target_index >= 0) { |
| 956 | if (!GetEntryAtIndex(target_index)->should_skip_on_back_forward_ui()) { |
Shivani Sharma | 298d1285 | 2019-01-22 20:04:03 | [diff] [blame] | 957 | all_skippable_entries = false; |
shivanisha | 5520187 | 2018-12-13 04:29:06 | [diff] [blame] | 958 | break; |
Shivani Sharma | 2d5b4b6b | 2019-01-08 16:07:16 | [diff] [blame] | 959 | } |
Elly Fong-Jones | 40ee811 | 2021-06-23 19:10:52 | [diff] [blame] | 960 | target_index--; |
shivanisha | 5520187 | 2018-12-13 04:29:06 | [diff] [blame] | 961 | } |
Miyoung Shin | 1c565c91 | 2021-03-17 12:11:21 | [diff] [blame] | 962 | |
Shivani Sharma | 298d1285 | 2019-01-22 20:04:03 | [diff] [blame] | 963 | // Do nothing if all entries are skippable. Normally this path would not |
| 964 | // happen as consumers would have already checked it in CanGoBack but a lot of |
| 965 | // tests do not do that. |
Elly Fong-Jones | ccc6d1f | 2021-06-14 18:32:42 | [diff] [blame] | 966 | if (all_skippable_entries) |
Shivani Sharma | 298d1285 | 2019-01-22 20:04:03 | [diff] [blame] | 967 | return; |
shivanisha | 5520187 | 2018-12-13 04:29:06 | [diff] [blame] | 968 | |
shivanisha | 5520187 | 2018-12-13 04:29:06 | [diff] [blame] | 969 | GoToIndex(target_index); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 970 | } |
| 971 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 972 | void NavigationControllerImpl::GoForward() { |
shivanisha | 5520187 | 2018-12-13 04:29:06 | [diff] [blame] | 973 | int target_index = GetIndexForOffset(1); |
| 974 | |
Shivani Sharma | 2d5b4b6b | 2019-01-08 16:07:16 | [diff] [blame] | 975 | // Note that at least one entry (the last one) will be non-skippable since |
| 976 | // entries are marked skippable only when they add another entry because of |
| 977 | // redirect or pushState. |
Elly Fong-Jones | 40ee811 | 2021-06-23 19:10:52 | [diff] [blame] | 978 | while (target_index < static_cast<int>(entries_.size())) { |
| 979 | if (!GetEntryAtIndex(target_index)->should_skip_on_back_forward_ui()) |
shivanisha | 5520187 | 2018-12-13 04:29:06 | [diff] [blame] | 980 | break; |
Elly Fong-Jones | 40ee811 | 2021-06-23 19:10:52 | [diff] [blame] | 981 | target_index++; |
shivanisha | 5520187 | 2018-12-13 04:29:06 | [diff] [blame] | 982 | } |
shivanisha | 5520187 | 2018-12-13 04:29:06 | [diff] [blame] | 983 | GoToIndex(target_index); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 984 | } |
| 985 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 986 | void NavigationControllerImpl::GoToIndex(int index) { |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 987 | GoToIndex(index, FrameTreeNode::kFrameTreeNodeInvalidId, |
| 988 | true /* is_browser_initiated */); |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 989 | } |
| 990 | |
| 991 | void NavigationControllerImpl::GoToIndex(int index, |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 992 | int sandbox_frame_tree_node_id, |
| 993 | bool is_browser_initiated) { |
| 994 | DCHECK(sandbox_frame_tree_node_id == FrameTreeNode::kFrameTreeNodeInvalidId || |
| 995 | !is_browser_initiated); |
sunjian | 30574a6 | 2017-03-21 21:39:44 | [diff] [blame] | 996 | TRACE_EVENT0("browser,navigation,benchmark", |
| 997 | "NavigationControllerImpl::GoToIndex"); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 998 | if (index < 0 || index >= static_cast<int>(entries_.size())) { |
| 999 | NOTREACHED(); |
| 1000 | return; |
| 1001 | } |
| 1002 | |
Rakina Zata Amni | f297a80 | 2022-01-18 03:53:43 | [diff] [blame] | 1003 | if (entries_[index]->IsInitialEntryNotForSynchronousAboutBlank()) { |
| 1004 | // We should never navigate to an existing initial NavigationEntry that is |
| 1005 | // the initial NavigationEntry for the initial empty document that hasn't |
| 1006 | // been overridden by the synchronous about:blank commit, to preserve |
| 1007 | // legacy behavior where trying to reload when the main frame is on the |
| 1008 | // initial empty document won't result in a navigation. See also |
| 1009 | // https://crbug.com/1277414. |
| 1010 | return; |
| 1011 | } |
| 1012 | |
[email protected] | cbab76d | 2008-10-13 22:42:47 | [diff] [blame] | 1013 | DiscardNonCommittedEntries(); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 1014 | |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 1015 | DCHECK_EQ(nullptr, pending_entry_); |
| 1016 | DCHECK_EQ(-1, pending_entry_index_); |
Rakina Zata Amni | f297a80 | 2022-01-18 03:53:43 | [diff] [blame] | 1017 | |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 1018 | pending_entry_ = entries_[index].get(); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 1019 | pending_entry_index_ = index; |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 1020 | pending_entry_->SetTransitionType(ui::PageTransitionFromInt( |
| 1021 | pending_entry_->GetTransitionType() | ui::PAGE_TRANSITION_FORWARD_BACK)); |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 1022 | NavigateToExistingPendingEntry(ReloadType::NONE, sandbox_frame_tree_node_id, |
| 1023 | is_browser_initiated); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 1024 | } |
| 1025 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 1026 | void NavigationControllerImpl::GoToOffset(int offset) { |
toyoshim | 3af4d50 | 2016-03-30 12:38:12 | [diff] [blame] | 1027 | // Note: This is actually reached in unit tests. |
[email protected] | 9ba1405 | 2012-06-22 23:50:03 | [diff] [blame] | 1028 | if (!CanGoToOffset(offset)) |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 1029 | return; |
| 1030 | |
[email protected] | 9ba1405 | 2012-06-22 23:50:03 | [diff] [blame] | 1031 | GoToIndex(GetIndexForOffset(offset)); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 1032 | } |
| 1033 | |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 1034 | void NavigationControllerImpl::GoToOffsetFromRenderer(int offset) { |
| 1035 | // Note: This is actually reached in unit tests. |
| 1036 | if (!CanGoToOffset(offset)) |
| 1037 | return; |
| 1038 | |
| 1039 | GoToIndex(GetIndexForOffset(offset), FrameTreeNode::kFrameTreeNodeInvalidId, |
| 1040 | false /* is_browser_initiated */); |
| 1041 | } |
| 1042 | |
Xiaohan Wang | 7f8052e0 | 2022-01-14 18:44:28 | [diff] [blame] | 1043 | #if BUILDFLAG(IS_ANDROID) |
WangHui | 74286d5 | 2021-03-31 16:17:15 | [diff] [blame] | 1044 | void NavigationControllerImpl::GoToOffsetWithSkipping(int offset) { |
| 1045 | // Note: This is actually reached in unit tests. |
| 1046 | if (!CanGoToOffsetWithSkipping(offset)) |
| 1047 | return; |
| 1048 | |
Elly Fong-Jones | ccc6d1f | 2021-06-14 18:32:42 | [diff] [blame] | 1049 | if (offset == 0) { |
WangHui | 74286d5 | 2021-03-31 16:17:15 | [diff] [blame] | 1050 | GoToIndex(GetIndexForOffset(offset)); |
| 1051 | return; |
| 1052 | } |
| 1053 | int increment = offset > 0 ? 1 : -1; |
| 1054 | // Find the offset without counting skippable entries. |
| 1055 | int target_index = GetIndexForOffset(increment); |
| 1056 | int non_skippable_entries = 0; |
| 1057 | for (int index = target_index; index >= 0 && index < GetEntryCount(); |
| 1058 | index += increment) { |
| 1059 | if (!GetEntryAtIndex(index)->should_skip_on_back_forward_ui()) |
| 1060 | non_skippable_entries++; |
| 1061 | |
| 1062 | if (non_skippable_entries == std::abs(offset)) { |
| 1063 | target_index = index; |
| 1064 | break; |
| 1065 | } |
| 1066 | } |
| 1067 | |
| 1068 | GoToIndex(target_index); |
| 1069 | } |
| 1070 | #endif |
| 1071 | |
[email protected] | 41374f1 | 2013-07-24 02:49:28 | [diff] [blame] | 1072 | bool NavigationControllerImpl::RemoveEntryAtIndex(int index) { |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 1073 | if (index == last_committed_entry_index_ || index == pending_entry_index_) |
[email protected] | 41374f1 | 2013-07-24 02:49:28 | [diff] [blame] | 1074 | return false; |
[email protected] | 6a13a6c | 2011-12-20 21:47:12 | [diff] [blame] | 1075 | |
[email protected] | 4303234 | 2011-03-21 14:10:31 | [diff] [blame] | 1076 | RemoveEntryAtIndexInternal(index); |
[email protected] | 41374f1 | 2013-07-24 02:49:28 | [diff] [blame] | 1077 | return true; |
[email protected] | cbab76d | 2008-10-13 22:42:47 | [diff] [blame] | 1078 | } |
| 1079 | |
Michael Thiessen | 9b14d51 | 2019-09-23 21:19:47 | [diff] [blame] | 1080 | void NavigationControllerImpl::PruneForwardEntries() { |
| 1081 | DiscardNonCommittedEntries(); |
| 1082 | int remove_start_index = last_committed_entry_index_ + 1; |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 1083 | int num_removed = static_cast<int>(entries_.size()) - remove_start_index; |
Michael Thiessen | 9b14d51 | 2019-09-23 21:19:47 | [diff] [blame] | 1084 | if (num_removed <= 0) |
| 1085 | return; |
| 1086 | entries_.erase(entries_.begin() + remove_start_index, entries_.end()); |
| 1087 | NotifyPrunedEntries(this, remove_start_index /* start index */, |
| 1088 | num_removed /* count */); |
| 1089 | } |
| 1090 | |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 1091 | void NavigationControllerImpl::UpdateVirtualURLToURL(NavigationEntryImpl* entry, |
| 1092 | const GURL& new_url) { |
[email protected] | 38178a4 | 2009-12-17 18:58:32 | [diff] [blame] | 1093 | GURL new_virtual_url(new_url); |
[email protected] | 825b166 | 2012-03-12 19:07:31 | [diff] [blame] | 1094 | if (BrowserURLHandlerImpl::GetInstance()->ReverseURLRewrite( |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1095 | &new_virtual_url, entry->GetVirtualURL(), browser_context_)) { |
| 1096 | entry->SetVirtualURL(new_virtual_url); |
[email protected] | 38178a4 | 2009-12-17 18:58:32 | [diff] [blame] | 1097 | } |
| 1098 | } |
| 1099 | |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 1100 | base::WeakPtr<NavigationHandle> NavigationControllerImpl::LoadURL( |
| 1101 | const GURL& url, |
| 1102 | const Referrer& referrer, |
| 1103 | ui::PageTransition transition, |
| 1104 | const std::string& extra_headers) { |
[email protected] | cf00233 | 2012-08-14 19:17:47 | [diff] [blame] | 1105 | LoadURLParams params(url); |
| 1106 | params.referrer = referrer; |
| 1107 | params.transition_type = transition; |
| 1108 | params.extra_headers = extra_headers; |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 1109 | return LoadURLWithParams(params); |
[email protected] | cf00233 | 2012-08-14 19:17:47 | [diff] [blame] | 1110 | } |
| 1111 | |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 1112 | base::WeakPtr<NavigationHandle> NavigationControllerImpl::LoadURLWithParams( |
| 1113 | const LoadURLParams& params) { |
Lukasz Anforowicz | 435bcb58 | 2019-07-12 20:50:06 | [diff] [blame] | 1114 | if (params.is_renderer_initiated) |
| 1115 | DCHECK(params.initiator_origin.has_value()); |
| 1116 | |
nasko | b8744d2 | 2014-08-28 17:07:43 | [diff] [blame] | 1117 | TRACE_EVENT1("browser,navigation", |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 1118 | "NavigationControllerImpl::LoadURLWithParams", "url", |
| 1119 | params.url.possibly_invalid_spec()); |
Ian Vollick | 9dda052 | 2019-09-11 02:24:29 | [diff] [blame] | 1120 | bool is_explicit_navigation = |
| 1121 | GetContentClient()->browser()->IsExplicitNavigation( |
| 1122 | params.transition_type); |
| 1123 | if (HandleDebugURL(params.url, params.transition_type, |
| 1124 | is_explicit_navigation)) { |
[email protected] | 4775298 | 2014-07-29 08:01:43 | [diff] [blame] | 1125 | // If Telemetry is running, allow the URL load to proceed as if it's |
| 1126 | // unhandled, otherwise Telemetry can't tell if Navigation completed. |
avi | 83883c8 | 2014-12-23 00:08:49 | [diff] [blame] | 1127 | if (!base::CommandLine::ForCurrentProcess()->HasSwitch( |
[email protected] | 4775298 | 2014-07-29 08:01:43 | [diff] [blame] | 1128 | cc::switches::kEnableGpuBenchmarking)) |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 1129 | return nullptr; |
[email protected] | 4775298 | 2014-07-29 08:01:43 | [diff] [blame] | 1130 | } |
[email protected] | 8bf104801 | 2012-02-08 01:22:18 | [diff] [blame] | 1131 | |
[email protected] | cf00233 | 2012-08-14 19:17:47 | [diff] [blame] | 1132 | // Checks based on params.load_type. |
| 1133 | switch (params.load_type) { |
| 1134 | case LOAD_TYPE_DEFAULT: |
lukasza | 477a5a2 | 2016-06-16 18:28:43 | [diff] [blame] | 1135 | case LOAD_TYPE_HTTP_POST: |
[email protected] | cf00233 | 2012-08-14 19:17:47 | [diff] [blame] | 1136 | break; |
| 1137 | case LOAD_TYPE_DATA: |
[email protected] | cca6f39 | 2014-05-28 21:32:26 | [diff] [blame] | 1138 | if (!params.url.SchemeIs(url::kDataScheme)) { |
[email protected] | cf00233 | 2012-08-14 19:17:47 | [diff] [blame] | 1139 | NOTREACHED() << "Data load must use data scheme."; |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 1140 | return nullptr; |
[email protected] | cf00233 | 2012-08-14 19:17:47 | [diff] [blame] | 1141 | } |
| 1142 | break; |
Lukasz Anforowicz | bb0cfd5e | 2017-12-14 22:39:46 | [diff] [blame] | 1143 | } |
[email protected] | e47ae947 | 2011-10-13 19:48:34 | [diff] [blame] | 1144 | |
[email protected] | e47ae947 | 2011-10-13 19:48:34 | [diff] [blame] | 1145 | // The user initiated a load, we don't need to reload anymore. |
| 1146 | needs_reload_ = false; |
| 1147 | |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 1148 | return NavigateWithoutEntry(params); |
[email protected] | 132e281a | 2012-07-31 18:32:44 | [diff] [blame] | 1149 | } |
| 1150 | |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 1151 | bool NavigationControllerImpl::PendingEntryMatchesRequest( |
| 1152 | NavigationRequest* request) const { |
creis | b4dc933 | 2016-03-14 21:39:19 | [diff] [blame] | 1153 | return pending_entry_ && |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 1154 | pending_entry_->GetUniqueID() == request->nav_entry_id(); |
creis | b4dc933 | 2016-03-14 21:39:19 | [diff] [blame] | 1155 | } |
| 1156 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 1157 | bool NavigationControllerImpl::RendererDidNavigate( |
creis | 3da0387 | 2015-02-20 21:12:32 | [diff] [blame] | 1158 | RenderFrameHostImpl* rfh, |
arthursonzogni | 73fe321 | 2020-11-17 13:24:07 | [diff] [blame] | 1159 | const mojom::DidCommitProvisionalLoadParams& params, |
peary2 | 1b0f797b | 2016-09-28 17:28:33 | [diff] [blame] | 1160 | LoadCommittedDetails* details, |
Eugene But | 712f03d | 2018-05-22 16:03:44 | [diff] [blame] | 1161 | bool is_same_document_navigation, |
Nate Chapin | c7019dd7d | 2021-06-25 18:29:25 | [diff] [blame] | 1162 | bool was_on_initial_empty_document, |
Shivani Sharma | ffb32b8 | 2019-04-09 16:58:47 | [diff] [blame] | 1163 | bool previous_document_was_activated, |
Camille Lamy | 10aafcd3 | 2018-12-05 15:48:13 | [diff] [blame] | 1164 | NavigationRequest* navigation_request) { |
| 1165 | DCHECK(navigation_request); |
Chris Bookholt | 27faf8d | 2022-01-20 01:03:33 | [diff] [blame] | 1166 | |
| 1167 | // Note: validation checks and renderer kills due to invalid commit messages |
| 1168 | // must happen before getting here, in |
| 1169 | // RenderFrameHostImpl::ValidateDidCommitParams. By the time we get here, some |
| 1170 | // effects of the navigation have already occurred. |
| 1171 | |
shivanigithub | f405bf0d | 2021-11-05 17:58:33 | [diff] [blame] | 1172 | if (ShouldMaintainTrivialSessionHistory(rfh->frame_tree_node()) && |
| 1173 | GetLastCommittedEntry()) { |
Takashi Toyoshima | a9f6680 | 2021-08-18 02:40:17 | [diff] [blame] | 1174 | // Ensure that this navigation does not add a navigation entry, since |
| 1175 | // ShouldMaintainTrivialSessionHistory() means we should not add an entry |
| 1176 | // beyond the last committed one. Therefore, `should_replace_current_entry` |
| 1177 | // should be set, which replaces the current entry, or this should be a |
| 1178 | // reload, which does not create a new entry. |
| 1179 | DCHECK(params.should_replace_current_entry || |
| 1180 | navigation_request->GetReloadType() != ReloadType::NONE); |
| 1181 | } |
[email protected] | cd2e1574 | 2013-03-08 04:08:31 | [diff] [blame] | 1182 | is_initial_navigation_ = false; |
| 1183 | |
[email protected] | 0e8db94 | 2008-09-24 21:21:48 | [diff] [blame] | 1184 | // Save the previous state before we clobber it. |
aelias | 100c919 | 2017-01-13 00:01:43 | [diff] [blame] | 1185 | bool overriding_user_agent_changed = false; |
[email protected] | 0e8db94 | 2008-09-24 21:21:48 | [diff] [blame] | 1186 | if (GetLastCommittedEntry()) { |
Carlos IL | 42b41659 | 2019-10-07 23:10:36 | [diff] [blame] | 1187 | if (entry_replaced_by_post_commit_error_) { |
Chris Bookholt | 27faf8d | 2022-01-20 01:03:33 | [diff] [blame] | 1188 | // Same document navigation events with a post-commit error should already |
| 1189 | // be blocked by RenderFrameHostImpl::ValidateDidCommitParams() before |
| 1190 | // reaching here. |
| 1191 | CHECK(!is_same_document_navigation); |
| 1192 | |
Carlos IL | 42b41659 | 2019-10-07 23:10:36 | [diff] [blame] | 1193 | // Any commit while a post-commit error page is showing should put the |
| 1194 | // original entry back, replacing the error page's entry. This includes |
| 1195 | // reloads, where the original entry was used as the pending entry and |
| 1196 | // should now be at the correct index at commit time. |
| 1197 | entries_[last_committed_entry_index_] = |
| 1198 | std::move(entry_replaced_by_post_commit_error_); |
| 1199 | } |
Fergal Daly | 8e33cf6 | 2020-12-12 01:06:07 | [diff] [blame] | 1200 | details->previous_main_frame_url = GetLastCommittedEntry()->GetURL(); |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 1201 | details->previous_entry_index = GetLastCommittedEntryIndex(); |
aelias | 100c919 | 2017-01-13 00:01:43 | [diff] [blame] | 1202 | if (pending_entry_ && |
| 1203 | pending_entry_->GetIsOverridingUserAgent() != |
| 1204 | GetLastCommittedEntry()->GetIsOverridingUserAgent()) |
| 1205 | overriding_user_agent_changed = true; |
Xiaohan Wang | 7f8052e0 | 2022-01-14 18:44:28 | [diff] [blame] | 1206 | #if BUILDFLAG(IS_ANDROID) |
Shu Yang | 5756fa42 | 2021-11-05 23:02:54 | [diff] [blame] | 1207 | // TODO(crbug.com/1266277): Clean up the logic of setting |
| 1208 | // |overriding_user_agent_changed| post-launch. |
Shu Yang | 9eabbb90 | 2021-11-17 00:45:03 | [diff] [blame] | 1209 | if (base::FeatureList::IsEnabled(features::kRequestDesktopSiteExceptions)) { |
Shu Yang | 5756fa42 | 2021-11-05 23:02:54 | [diff] [blame] | 1210 | // Must honor user agent overrides in the |navigation_request|, such as |
| 1211 | // from things like RequestDesktopSiteWebContentsObserverAndroid. As a |
| 1212 | // result, besides comparing |pending_entry_|'s user agent against |
| 1213 | // LastCommittedEntry's, also need to compare |navigation_request|'s user |
| 1214 | // agent against LastCommittedEntry's. |
| 1215 | if (navigation_request->is_overriding_user_agent() != |
| 1216 | GetLastCommittedEntry()->GetIsOverridingUserAgent()) { |
| 1217 | overriding_user_agent_changed = true; |
| 1218 | } |
| 1219 | } |
Xiaohan Wang | 7f8052e0 | 2022-01-14 18:44:28 | [diff] [blame] | 1220 | #endif // BUILDFLAG(IS_ANDROID) |
[email protected] | 0e8db94 | 2008-09-24 21:21:48 | [diff] [blame] | 1221 | } else { |
Gang Wu | 325f03f4 | 2021-02-25 20:00:46 | [diff] [blame] | 1222 | // GetLastCommittedEntry() is null, so this is the first entry. |
Fergal Daly | 8e33cf6 | 2020-12-12 01:06:07 | [diff] [blame] | 1223 | details->previous_main_frame_url = GURL(); |
[email protected] | 0e8db94 | 2008-09-24 21:21:48 | [diff] [blame] | 1224 | details->previous_entry_index = -1; |
Gang Wu | 325f03f4 | 2021-02-25 20:00:46 | [diff] [blame] | 1225 | if (pending_entry_ && pending_entry_->GetIsOverridingUserAgent()) { |
| 1226 | // Default setting is NOT override the user agent, so overriding the user |
| 1227 | // agent in first entry should be considered as user agent changed as |
| 1228 | // well. |
| 1229 | overriding_user_agent_changed = true; |
| 1230 | } |
Xiaohan Wang | 7f8052e0 | 2022-01-14 18:44:28 | [diff] [blame] | 1231 | #if BUILDFLAG(IS_ANDROID) |
Shu Yang | 5756fa42 | 2021-11-05 23:02:54 | [diff] [blame] | 1232 | // TODO(crbug.com/1266277): Clean up the logic of setting |
| 1233 | // |overriding_user_agent_changed| post-launch. |
Shu Yang | 9eabbb90 | 2021-11-17 00:45:03 | [diff] [blame] | 1234 | if (base::FeatureList::IsEnabled(features::kRequestDesktopSiteExceptions)) { |
Shu Yang | 5756fa42 | 2021-11-05 23:02:54 | [diff] [blame] | 1235 | // Must honor user agent overrides in the |navigation_request|, such as |
| 1236 | // from things like RequestDesktopSiteWebContentsObserverAndroid. As a |
| 1237 | // result, besides checking |pending_entry_|'s user agent, also need to |
| 1238 | // check |navigation_request|'s. |
| 1239 | if (navigation_request->is_overriding_user_agent()) { |
| 1240 | overriding_user_agent_changed = true; |
| 1241 | } |
| 1242 | } |
Xiaohan Wang | 7f8052e0 | 2022-01-14 18:44:28 | [diff] [blame] | 1243 | #endif // BUILDFLAG(IS_ANDROID) |
[email protected] | 0e8db94 | 2008-09-24 21:21:48 | [diff] [blame] | 1244 | } |
[email protected] | ecd9d870 | 2008-08-28 22:10:17 | [diff] [blame] | 1245 | |
Dave Tapuska | a2ab4f25 | 2021-07-08 21:31:28 | [diff] [blame] | 1246 | bool is_main_frame_navigation = !rfh->GetParent(); |
| 1247 | |
Alexander Timin | d2f2e4f2 | 2019-04-02 20:04:53 | [diff] [blame] | 1248 | // TODO(altimin, crbug.com/933147): Remove this logic after we are done with |
| 1249 | // implementing back-forward cache. |
Dave Tapuska | a2ab4f25 | 2021-07-08 21:31:28 | [diff] [blame] | 1250 | // For primary frame tree navigations, choose an appropriate |
| 1251 | // BackForwardCacheMetrics to be associated with the NavigationEntry, by |
| 1252 | // either creating a new object or reusing the previous one depending on |
| 1253 | // whether it's a main frame navigation or not. |
| 1254 | scoped_refptr<BackForwardCacheMetrics> back_forward_cache_metrics; |
| 1255 | if (navigation_request->frame_tree_node()->frame_tree()->type() == |
| 1256 | FrameTree::Type::kPrimary) { |
| 1257 | back_forward_cache_metrics = |
| 1258 | BackForwardCacheMetrics::CreateOrReuseBackForwardCacheMetrics( |
| 1259 | GetLastCommittedEntry(), is_main_frame_navigation, |
| 1260 | params.document_sequence_number); |
| 1261 | } |
Alexander Timin | d2f2e4f2 | 2019-04-02 20:04:53 | [diff] [blame] | 1262 | // Notify the last active entry that we have navigated away. |
Dave Tapuska | a2ab4f25 | 2021-07-08 21:31:28 | [diff] [blame] | 1263 | if (is_main_frame_navigation && !is_same_document_navigation) { |
Alexander Timin | d2f2e4f2 | 2019-04-02 20:04:53 | [diff] [blame] | 1264 | if (NavigationEntryImpl* navigation_entry = GetLastCommittedEntry()) { |
| 1265 | if (auto* metrics = navigation_entry->back_forward_cache_metrics()) { |
Hajime Hoshi | c760650 | 2021-04-14 02:42:16 | [diff] [blame] | 1266 | metrics->MainFrameDidNavigateAwayFromDocument(rfh, navigation_request); |
Alexander Timin | d2f2e4f2 | 2019-04-02 20:04:53 | [diff] [blame] | 1267 | } |
| 1268 | } |
| 1269 | } |
| 1270 | |
fdegans | 9caf66a | 2015-07-30 21:10:42 | [diff] [blame] | 1271 | // If there is a pending entry at this point, it should have a SiteInstance, |
| 1272 | // except for restored entries. |
jam | 48cea908 | 2017-02-15 06:13:29 | [diff] [blame] | 1273 | bool was_restored = false; |
toyoshim | 0df1d3a | 2016-09-09 09:52:48 | [diff] [blame] | 1274 | DCHECK(pending_entry_index_ == -1 || pending_entry_->site_instance() || |
Lukasz Anforowicz | 6b75c0d | 2020-12-01 22:56:08 | [diff] [blame] | 1275 | pending_entry_->IsRestored()); |
| 1276 | if (pending_entry_ && pending_entry_->IsRestored()) { |
Lukasz Anforowicz | 0de0f45 | 2020-12-02 19:57:15 | [diff] [blame] | 1277 | pending_entry_->set_restore_type(RestoreType::kNotRestored); |
jam | 48cea908 | 2017-02-15 06:13:29 | [diff] [blame] | 1278 | was_restored = true; |
toyoshim | 0df1d3a | 2016-09-09 09:52:48 | [diff] [blame] | 1279 | } |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1280 | |
Nasko Oskov | aee2f86 | 2018-06-15 00:05:52 | [diff] [blame] | 1281 | // If this is a navigation to a matching pending_entry_ and the SiteInstance |
| 1282 | // has changed, this must be treated as a new navigation with replacement. |
| 1283 | // Set the replacement bit here and ClassifyNavigation will identify this |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1284 | // case and return NEW_ENTRY. |
Nasko Oskov | aee2f86 | 2018-06-15 00:05:52 | [diff] [blame] | 1285 | if (!rfh->GetParent() && pending_entry_ && |
Rakina Zata Amni | f6950d55 | 2020-11-24 03:26:10 | [diff] [blame] | 1286 | pending_entry_->GetUniqueID() == |
| 1287 | navigation_request->commit_params().nav_entry_id && |
Nasko Oskov | aee2f86 | 2018-06-15 00:05:52 | [diff] [blame] | 1288 | pending_entry_->site_instance() && |
| 1289 | pending_entry_->site_instance() != rfh->GetSiteInstance()) { |
| 1290 | DCHECK_NE(-1, pending_entry_index_); |
| 1291 | // TODO(nasko,creis): Instead of setting this value here, set |
| 1292 | // should_replace_current_entry on the parameters we send to the |
| 1293 | // renderer process as part of CommitNavigation. The renderer should |
| 1294 | // in turn send it back here as part of |params| and it can be just |
| 1295 | // enforced and renderer process terminated on mismatch. |
| 1296 | details->did_replace_entry = true; |
| 1297 | } else { |
| 1298 | // The renderer tells us whether the navigation replaces the current entry. |
| 1299 | details->did_replace_entry = params.should_replace_current_entry; |
| 1300 | } |
[email protected] | bcd90448 | 2012-02-01 01:54:22 | [diff] [blame] | 1301 | |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1302 | // Do navigation-type specific actions. These will make and commit an entry. |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 1303 | details->type = ClassifyNavigation(rfh, params, navigation_request); |
| 1304 | if (GetLastCommittedEntry() && GetLastCommittedEntry()->IsInitialEntry()) { |
Rakina Zata Amni | ddf1050 | 2022-01-15 02:56:55 | [diff] [blame] | 1305 | if (rfh->GetParent()) { |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 1306 | // This is a subframe navigation on the initial empty document, which used |
| 1307 | // to not have a NavigationEntry to attach to. Now it can attach to the |
| 1308 | // initial NavigationEntry, and we must ensure that its NavigationEntry |
| 1309 | // will keep the "initial NavigationEntry" status and won't append a new |
| 1310 | // NavigationEntry (it should always do replacement instead). |
| 1311 | // See also https://crbug.com/1277414. |
| 1312 | details->should_stay_as_initial_entry = true; |
Rakina Zata Amni | ddf1050 | 2022-01-15 02:56:55 | [diff] [blame] | 1313 | // Subframe navigation on initial NavigationEntry must not append a new |
| 1314 | // NavigationEntry (i.e. should not be classified as NEW_SUBFRAME). This |
| 1315 | // means every subframe navigation that happens while we're on the initial |
| 1316 | // NavigationEntry will always reuse the existing NavigationEntry and |
| 1317 | // just update the corresponding FrameNavigationEntry. |
| 1318 | DCHECK_EQ(details->type, NAVIGATION_TYPE_AUTO_SUBFRAME); |
| 1319 | } else if (details->type == NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY) { |
| 1320 | // This is a navigation that modifies the initial NavigationEntry, either |
| 1321 | // for a replacement or a reload. The initial NavigationEntry should |
| 1322 | // retain its "initial NavigationEntry" status in this case. |
| 1323 | details->should_stay_as_initial_entry = true; |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 1324 | } else if (navigation_request->is_synchronous_renderer_commit() && |
| 1325 | !navigation_request->IsSameDocument() && !rfh->GetParent() && |
| 1326 | params.should_replace_current_entry) { |
| 1327 | // This is a synchronous about:blank navigation on the main frame, which |
| 1328 | // used to not create a NavigationEntry when we have no NavigationEntry on |
| 1329 | // FrameTree creation. We now have the initial NavigationEntry and are on |
| 1330 | // the initial NavigationEntry. To preserve old behavior, we should still |
| 1331 | // keep the "initial" status for the new NavigationEntry that we will |
| 1332 | // create for this navigation, so that subframe navigations under the |
| 1333 | // synchronously committed about:blank document will never append new |
| 1334 | // NavigationEntry, and instead will just reuse the initial |
| 1335 | // NavigationEntry and modify the corresponding FrameNavigationEntries. |
| 1336 | // See also https://crbug.com/1277414. |
| 1337 | details->should_stay_as_initial_entry = true; |
Rakina Zata Amni | ddf1050 | 2022-01-15 02:56:55 | [diff] [blame] | 1338 | } |
| 1339 | } |
| 1340 | DCHECK(!details->should_stay_as_initial_entry || |
| 1341 | GetLastCommittedEntry()->IsInitialEntry()); |
[email protected] | 4bf3522c | 2010-08-19 21:00:20 | [diff] [blame] | 1342 | |
eugenebut | ee08663a | 2017-04-27 17:43:12 | [diff] [blame] | 1343 | // is_same_document must be computed before the entry gets committed. |
Eugene But | 712f03d | 2018-05-22 16:03:44 | [diff] [blame] | 1344 | details->is_same_document = is_same_document_navigation; |
[email protected] | b9d4dfdc | 2013-08-08 00:25:12 | [diff] [blame] | 1345 | |
Lucas Furukawa Gadani | e3f7e79 | 2021-04-22 17:56:07 | [diff] [blame] | 1346 | details->is_prerender_activation = |
| 1347 | navigation_request->IsPrerenderedPageActivation(); |
| 1348 | |
Peter Boström | d759213 | 2019-01-30 04:50:31 | [diff] [blame] | 1349 | // Make sure we do not discard the pending entry for a different ongoing |
| 1350 | // navigation when a same document commit comes in unexpectedly from the |
| 1351 | // renderer. Limit this to a very narrow set of conditions to avoid risks to |
| 1352 | // other navigation types. See https://crbug.com/900036. |
| 1353 | // TODO(crbug.com/926009): Handle history.pushState() as well. |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1354 | bool keep_pending_entry = |
| 1355 | is_same_document_navigation && |
| 1356 | details->type == NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY && |
| 1357 | pending_entry_ && !PendingEntryMatchesRequest(navigation_request); |
Peter Boström | d759213 | 2019-01-30 04:50:31 | [diff] [blame] | 1358 | |
[email protected] | 0e8db94 | 2008-09-24 21:21:48 | [diff] [blame] | 1359 | switch (details->type) { |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1360 | case NAVIGATION_TYPE_MAIN_FRAME_NEW_ENTRY: |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1361 | RendererDidNavigateToNewEntry( |
shivanisha | 41f04c5 | 2018-12-12 15:52:05 | [diff] [blame] | 1362 | rfh, params, details->is_same_document, details->did_replace_entry, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 1363 | previous_document_was_activated, navigation_request, details); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1364 | break; |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1365 | case NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY: |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1366 | RendererDidNavigateToExistingEntry(rfh, params, details->is_same_document, |
| 1367 | was_restored, navigation_request, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 1368 | keep_pending_entry, details); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1369 | break; |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1370 | case NAVIGATION_TYPE_NEW_SUBFRAME: |
Shivani Sharma | ffb32b8 | 2019-04-09 16:58:47 | [diff] [blame] | 1371 | RendererDidNavigateNewSubframe( |
| 1372 | rfh, params, details->is_same_document, details->did_replace_entry, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 1373 | previous_document_was_activated, navigation_request, details); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1374 | break; |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1375 | case NAVIGATION_TYPE_AUTO_SUBFRAME: |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 1376 | if (!RendererDidNavigateAutoSubframe( |
Nate Chapin | c7019dd7d | 2021-06-25 18:29:25 | [diff] [blame] | 1377 | rfh, params, details->is_same_document, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 1378 | was_on_initial_empty_document, navigation_request, details)) { |
creis | ce0ef357 | 2017-01-26 17:53:08 | [diff] [blame] | 1379 | // We don't send a notification about auto-subframe PageState during |
| 1380 | // UpdateStateForFrame, since it looks like nothing has changed. Send |
| 1381 | // it here at commit time instead. |
| 1382 | NotifyEntryChanged(GetLastCommittedEntry()); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1383 | return false; |
creis | 59d5a47cb | 2016-08-24 23:57:19 | [diff] [blame] | 1384 | } |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1385 | break; |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 1386 | case NAVIGATION_TYPE_NAV_IGNORE: |
| 1387 | // If a pending navigation was in progress, this canceled it. We should |
| 1388 | // discard it and make sure it is removed from the URL bar. After that, |
| 1389 | // there is nothing we can do with this navigation, so we just return to |
| 1390 | // the caller that nothing has happened. |
| 1391 | if (pending_entry_) |
| 1392 | DiscardNonCommittedEntries(); |
| 1393 | return false; |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 1394 | case NAVIGATION_TYPE_UNKNOWN: |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1395 | NOTREACHED(); |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 1396 | break; |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 1397 | } |
| 1398 | |
[email protected] | 688aa65c6 | 2012-09-28 04:32:22 | [diff] [blame] | 1399 | // At this point, we know that the navigation has just completed, so |
| 1400 | // record the time. |
| 1401 | // |
| 1402 | // TODO(akalin): Use "sane time" as described in |
Adam Langley | 4463fb83 | 2018-01-28 22:42:26 | [diff] [blame] | 1403 | // https://www.chromium.org/developers/design-documents/sane-time . |
[email protected] | c5b88d8 | 2012-10-06 17:03:33 | [diff] [blame] | 1404 | base::Time timestamp = |
| 1405 | time_smoother_.GetSmoothedTime(get_timestamp_callback_.Run()); |
| 1406 | DVLOG(1) << "Navigation finished at (smoothed) timestamp " |
danakj | f26536bf | 2020-09-10 00:46:13 | [diff] [blame] | 1407 | << timestamp.ToDeltaSinceWindowsEpoch().InMicroseconds(); |
[email protected] | 688aa65c6 | 2012-09-28 04:32:22 | [diff] [blame] | 1408 | |
Peter Boström | d759213 | 2019-01-30 04:50:31 | [diff] [blame] | 1409 | // If we aren't keeping the pending entry, there shouldn't be one at this |
| 1410 | // point. Clear it again in case any error cases above forgot to do so. |
| 1411 | // TODO(pbos): Consider a CHECK here that verifies that the pending entry has |
| 1412 | // been cleared instead of protecting against it. |
| 1413 | if (!keep_pending_entry) |
Rakina Zata Amni | ddf1050 | 2022-01-15 02:56:55 | [diff] [blame] | 1414 | DiscardNonCommittedEntriesWithCommitDetails(details); |
[email protected] | f233e423 | 2013-02-23 00:55:14 | [diff] [blame] | 1415 | |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1416 | // All committed entries should have nonempty content state so WebKit doesn't |
| 1417 | // get confused when we go back to them (see the function for details). |
creis | 0cade2e | 2017-02-28 06:37:47 | [diff] [blame] | 1418 | DCHECK(params.page_state.IsValid()) << "Shouldn't see an empty PageState."; |
creis | 3da0387 | 2015-02-20 21:12:32 | [diff] [blame] | 1419 | NavigationEntryImpl* active_entry = GetLastCommittedEntry(); |
[email protected] | 688aa65c6 | 2012-09-28 04:32:22 | [diff] [blame] | 1420 | active_entry->SetTimestamp(timestamp); |
[email protected] | f49737b3 | 2013-08-28 07:51:44 | [diff] [blame] | 1421 | active_entry->SetHttpStatusCode(params.http_status_code); |
Alexander Timin | d2f2e4f2 | 2019-04-02 20:04:53 | [diff] [blame] | 1422 | // TODO(altimin, crbug.com/933147): Remove this logic after we are done with |
| 1423 | // implementing back-forward cache. |
Dave Tapuska | a2ab4f25 | 2021-07-08 21:31:28 | [diff] [blame] | 1424 | if (back_forward_cache_metrics && |
| 1425 | !active_entry->back_forward_cache_metrics()) { |
Alexander Timin | d2f2e4f2 | 2019-04-02 20:04:53 | [diff] [blame] | 1426 | active_entry->set_back_forward_cache_metrics( |
| 1427 | std::move(back_forward_cache_metrics)); |
| 1428 | } |
Dave Tapuska | a2ab4f25 | 2021-07-08 21:31:28 | [diff] [blame] | 1429 | |
| 1430 | // `back_forward_cache_metrics()` may return null as we do not record |
| 1431 | // back-forward cache metrics for navigations in non-primary frame trees. |
| 1432 | if (active_entry->back_forward_cache_metrics()) { |
| 1433 | active_entry->back_forward_cache_metrics()->DidCommitNavigation( |
| 1434 | navigation_request, |
| 1435 | back_forward_cache_.IsAllowed(navigation_request->GetURL())); |
| 1436 | } |
nasko | c753351 | 2016-05-06 17:01:12 | [diff] [blame] | 1437 | |
Charles Reis | c050720 | 2017-09-21 00:40:02 | [diff] [blame] | 1438 | // Grab the corresponding FrameNavigationEntry for a few updates, but only if |
| 1439 | // the SiteInstance matches (to avoid updating the wrong entry by mistake). |
| 1440 | // A mismatch can occur if the renderer lies or due to a unique name collision |
| 1441 | // after a race with an OOPIF (see https://crbug.com/616820). |
nasko | c753351 | 2016-05-06 17:01:12 | [diff] [blame] | 1442 | FrameNavigationEntry* frame_entry = |
| 1443 | active_entry->GetFrameEntry(rfh->frame_tree_node()); |
Charles Reis | c050720 | 2017-09-21 00:40:02 | [diff] [blame] | 1444 | if (frame_entry && frame_entry->site_instance() != rfh->GetSiteInstance()) |
| 1445 | frame_entry = nullptr; |
Charles Reis | f4448202 | 2017-10-13 21:15:03 | [diff] [blame] | 1446 | // Make sure we've updated the PageState in one of the helper methods. |
creis | ce0ef357 | 2017-01-26 17:53:08 | [diff] [blame] | 1447 | // TODO(creis): Remove the "if" once https://crbug.com/522193 is fixed. |
| 1448 | if (frame_entry) { |
Charles Reis | f4448202 | 2017-10-13 21:15:03 | [diff] [blame] | 1449 | DCHECK(params.page_state == frame_entry->page_state()); |
Nasko Oskov | bbcfc000 | 2019-11-20 20:03:20 | [diff] [blame] | 1450 | |
| 1451 | // Remember the bindings the renderer process has at this point, so that |
| 1452 | // we do not grant this entry additional bindings if we come back to it. |
| 1453 | frame_entry->SetBindings(rfh->GetEnabledBindings()); |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 1454 | } |
[email protected] | 132e281a | 2012-07-31 18:32:44 | [diff] [blame] | 1455 | |
[email protected] | 97d8f0d | 2013-10-29 16:49:21 | [diff] [blame] | 1456 | // Once it is committed, we no longer need to track several pieces of state on |
| 1457 | // the entry. |
nasko | c753351 | 2016-05-06 17:01:12 | [diff] [blame] | 1458 | active_entry->ResetForCommit(frame_entry); |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 1459 | |
[email protected] | 49bd30e6 | 2011-03-22 20:12:59 | [diff] [blame] | 1460 | // The active entry's SiteInstance should match our SiteInstance. |
[email protected] | a1b9926 | 2013-12-27 21:56:22 | [diff] [blame] | 1461 | // TODO(creis): This check won't pass for subframes until we create entries |
| 1462 | // for subframe navigations. |
avi | 39c1edd3 | 2015-06-04 20:06:00 | [diff] [blame] | 1463 | if (!rfh->GetParent()) |
creis | 77c9aa3 | 2015-09-25 19:59:42 | [diff] [blame] | 1464 | CHECK_EQ(active_entry->site_instance(), rfh->GetSiteInstance()); |
[email protected] | 49bd30e6 | 2011-03-22 20:12:59 | [diff] [blame] | 1465 | |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1466 | // Now prep the rest of the details for the notification and broadcast. |
[email protected] | 0f38dc455 | 2011-02-25 11:24:00 | [diff] [blame] | 1467 | details->entry = active_entry; |
avi | 39c1edd3 | 2015-06-04 20:06:00 | [diff] [blame] | 1468 | details->is_main_frame = !rfh->GetParent(); |
[email protected] | 2e39d2e | 2009-02-19 18:41:31 | [diff] [blame] | 1469 | details->http_status_code = params.http_status_code; |
estark | a5635c4 | 2015-07-14 00:06:53 | [diff] [blame] | 1470 | |
arthursonzogni | 7ddc654 | 2021-04-09 09:16:50 | [diff] [blame] | 1471 | active_entry->SetIsOverridingUserAgent( |
| 1472 | navigation_request->is_overriding_user_agent()); |
Scott Violet | c36f746 | 2020-05-06 23:13:03 | [diff] [blame] | 1473 | |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 1474 | NotifyNavigationEntryCommitted(details); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1475 | |
aelias | 100c919 | 2017-01-13 00:01:43 | [diff] [blame] | 1476 | if (overriding_user_agent_changed) |
| 1477 | delegate_->UpdateOverridingUserAgent(); |
| 1478 | |
creis | 03b4800 | 2015-11-04 00:54:56 | [diff] [blame] | 1479 | // Update the nav_entry_id for each RenderFrameHost in the tree, so that each |
| 1480 | // one knows the latest NavigationEntry it is showing (whether it has |
| 1481 | // committed anything in this navigation or not). This allows things like |
| 1482 | // state and title updates from RenderFrames to apply to the latest relevant |
| 1483 | // NavigationEntry. |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 1484 | int nav_entry_id = active_entry->GetUniqueID(); |
Carlos Caballero | 40b0efd | 2021-01-26 11:55:00 | [diff] [blame] | 1485 | for (FrameTreeNode* node : frame_tree_.Nodes()) |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 1486 | node->current_frame_host()->set_nav_entry_id(nav_entry_id); |
Hayato Ito | 2c8c08d0 | 2021-06-23 03:38:43 | [diff] [blame] | 1487 | |
| 1488 | if (navigation_request->IsPrerenderedPageActivation()) { |
| 1489 | BroadcastHistoryOffsetAndLength(); |
| 1490 | // TODO(crbug.com/1222893): Broadcasting happens after the prerendered page |
| 1491 | // is activated. As a result, a "prerenderingchange" event listener sees the |
| 1492 | // history.length which is not updated yet. We should guarantee that |
| 1493 | // history's length and offset should be updated before a |
| 1494 | // "prerenderingchange" event listener runs. One possible approach is to use |
| 1495 | // the same IPC which "prerenderingchange" uses, and propagate history's |
| 1496 | // length and offset together with that. |
| 1497 | } |
| 1498 | |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1499 | return true; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 1500 | } |
| 1501 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1502 | NavigationType NavigationControllerImpl::ClassifyNavigation( |
creis | 3da0387 | 2015-02-20 21:12:32 | [diff] [blame] | 1503 | RenderFrameHostImpl* rfh, |
Rakina Zata Amni | f6950d55 | 2020-11-24 03:26:10 | [diff] [blame] | 1504 | const mojom::DidCommitProvisionalLoadParams& params, |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 1505 | NavigationRequest* navigation_request) { |
Piotr Tworek | bad5128 | 2020-09-30 19:17:59 | [diff] [blame] | 1506 | TraceReturnReason<tracing_category::kNavigation> trace_return( |
Nasko Oskov | ae49e29 | 2020-08-13 02:08:51 | [diff] [blame] | 1507 | "ClassifyNavigation"); |
Nasko Oskov | ae49e29 | 2020-08-13 02:08:51 | [diff] [blame] | 1508 | |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1509 | if (params.did_create_new_entry) { |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 1510 | // A new entry. We may or may not have a corresponding pending entry, and |
| 1511 | // this may or may not be the main frame. |
avi | 39c1edd3 | 2015-06-04 20:06:00 | [diff] [blame] | 1512 | if (!rfh->GetParent()) { |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1513 | trace_return.set_return_reason("new entry, no parent, new entry"); |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1514 | return NAVIGATION_TYPE_MAIN_FRAME_NEW_ENTRY; |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1515 | } |
| 1516 | |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 1517 | // When this is a new subframe navigation, we should have a committed page |
| 1518 | // in which it's a subframe. This may not be the case when an iframe is |
| 1519 | // navigated on a popup navigated to about:blank (the iframe would be |
| 1520 | // written into the popup by script on the main page). For these cases, |
| 1521 | // there isn't any navigation stuff we can do, so just ignore it. |
| 1522 | if (!GetLastCommittedEntry()) { |
| 1523 | trace_return.set_return_reason("new entry, no last committed, ignore"); |
| 1524 | return NAVIGATION_TYPE_NAV_IGNORE; |
| 1525 | } |
| 1526 | |
| 1527 | // Valid subframe navigation. |
Nasko Oskov | ae49e29 | 2020-08-13 02:08:51 | [diff] [blame] | 1528 | trace_return.set_return_reason("new entry, new subframe"); |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1529 | return NAVIGATION_TYPE_NEW_SUBFRAME; |
| 1530 | } |
| 1531 | |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1532 | // We only clear the session history in tests when navigating to a new entry. |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1533 | DCHECK(!params.history_list_was_cleared); |
| 1534 | |
avi | 39c1edd3 | 2015-06-04 20:06:00 | [diff] [blame] | 1535 | if (rfh->GetParent()) { |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1536 | // All manual subframes would be did_create_new_entry and handled above, so |
| 1537 | // we know this is auto. |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 1538 | if (GetLastCommittedEntry()) { |
| 1539 | trace_return.set_return_reason("subframe, last commmited, auto subframe"); |
| 1540 | return NAVIGATION_TYPE_AUTO_SUBFRAME; |
| 1541 | } |
| 1542 | |
| 1543 | // We ignore subframes created in non-committed pages; we'd appreciate if |
| 1544 | // people stopped doing that. |
| 1545 | trace_return.set_return_reason("subframe, no last commmited, ignore"); |
| 1546 | return NAVIGATION_TYPE_NAV_IGNORE; |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1547 | } |
| 1548 | |
Rakina Zata Amni | f6950d55 | 2020-11-24 03:26:10 | [diff] [blame] | 1549 | const int nav_entry_id = navigation_request->commit_params().nav_entry_id; |
| 1550 | if (nav_entry_id == 0) { |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1551 | // This is a renderer-initiated navigation (nav_entry_id == 0), but didn't |
| 1552 | // create a new page. |
| 1553 | |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 1554 | // Just like above in the did_create_new_entry case, it's possible to |
| 1555 | // scribble onto an uncommitted page. Again, there isn't any navigation |
| 1556 | // stuff that we can do, so ignore it here as well. |
| 1557 | NavigationEntry* last_committed = GetLastCommittedEntry(); |
| 1558 | if (!last_committed) { |
| 1559 | trace_return.set_return_reason("nav entry 0, no last committed, ignore"); |
| 1560 | return NAVIGATION_TYPE_NAV_IGNORE; |
| 1561 | } |
| 1562 | |
Hayato Ito | 2ae4944 | 2021-07-02 02:59:25 | [diff] [blame] | 1563 | // This main frame navigation is not a history navigation (since |
| 1564 | // nav_entry_id is 0), but didn't create a new entry. So this must be a |
| 1565 | // reload or a replacement navigation, which will modify the existing entry. |
| 1566 | // |
Nasko Oskov | 332593c | 2018-08-16 17:21:34 | [diff] [blame] | 1567 | // TODO(nasko): With error page isolation, reloading an existing session |
| 1568 | // history entry can result in change of SiteInstance. Check for such a case |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1569 | // here and classify it as NEW_ENTRY, as such navigations should be treated |
Nasko Oskov | 332593c | 2018-08-16 17:21:34 | [diff] [blame] | 1570 | // as new with replacement. |
Nasko Oskov | ae49e29 | 2020-08-13 02:08:51 | [diff] [blame] | 1571 | trace_return.set_return_reason( |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1572 | "nav entry 0, last committed, existing entry"); |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1573 | return NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY; |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1574 | } |
| 1575 | |
Rakina Zata Amni | f6950d55 | 2020-11-24 03:26:10 | [diff] [blame] | 1576 | if (pending_entry_ && pending_entry_->GetUniqueID() == nav_entry_id) { |
Nasko Oskov | aee2f86 | 2018-06-15 00:05:52 | [diff] [blame] | 1577 | // If the SiteInstance of the |pending_entry_| does not match the |
| 1578 | // SiteInstance that got committed, treat this as a new navigation with |
| 1579 | // replacement. This can happen if back/forward/reload encounters a server |
| 1580 | // redirect to a different site or an isolated error page gets successfully |
| 1581 | // reloaded into a different SiteInstance. |
| 1582 | if (pending_entry_->site_instance() && |
| 1583 | pending_entry_->site_instance() != rfh->GetSiteInstance()) { |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1584 | trace_return.set_return_reason("pending matching nav entry, new entry"); |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1585 | return NAVIGATION_TYPE_MAIN_FRAME_NEW_ENTRY; |
Nasko Oskov | aee2f86 | 2018-06-15 00:05:52 | [diff] [blame] | 1586 | } |
creis | 77c9aa3 | 2015-09-25 19:59:42 | [diff] [blame] | 1587 | |
Nasko Oskov | aee2f86 | 2018-06-15 00:05:52 | [diff] [blame] | 1588 | if (pending_entry_index_ == -1) { |
| 1589 | // In this case, we have a pending entry for a load of a new URL but Blink |
| 1590 | // didn't do a new navigation (params.did_create_new_entry). First check |
| 1591 | // to make sure Blink didn't treat a new cross-process navigation as |
| 1592 | // 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] | 1593 | // we must treat it as NEW rather than the converted reload case below, |
| 1594 | // since the new SiteInstance doesn't match the last committed entry. |
Nasko Oskov | aee2f86 | 2018-06-15 00:05:52 | [diff] [blame] | 1595 | if (!GetLastCommittedEntry() || |
| 1596 | GetLastCommittedEntry()->site_instance() != rfh->GetSiteInstance()) { |
Charlie Reis | 7e2cb6d | 2021-01-26 01:27:16 | [diff] [blame] | 1597 | trace_return.set_return_reason("new pending, new entry"); |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1598 | return NAVIGATION_TYPE_MAIN_FRAME_NEW_ENTRY; |
Nasko Oskov | aee2f86 | 2018-06-15 00:05:52 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | // Otherwise, this happens when you press enter in the URL bar to reload. |
Charlie Reis | 7e2cb6d | 2021-01-26 01:27:16 | [diff] [blame] | 1602 | // We will create a pending entry, but NavigateWithoutEntry will convert |
| 1603 | // it to a reload since it's the same page and not create a new entry for |
| 1604 | // it. (The user doesn't want to have a new back/forward entry when they |
| 1605 | // do this.) Therefore we want to just ignore the pending entry and go |
| 1606 | // back to where we were (the "existing entry"). |
| 1607 | trace_return.set_return_reason("new pending, existing (same) entry"); |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1608 | return NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY; |
Nasko Oskov | aee2f86 | 2018-06-15 00:05:52 | [diff] [blame] | 1609 | } |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1610 | } |
| 1611 | |
creis | 26d2263 | 2017-04-21 20:23:56 | [diff] [blame] | 1612 | // Everything below here is assumed to be an existing entry, but if there is |
| 1613 | // no last committed entry, we must consider it a new navigation instead. |
Nasko Oskov | ae49e29 | 2020-08-13 02:08:51 | [diff] [blame] | 1614 | if (!GetLastCommittedEntry()) { |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1615 | trace_return.set_return_reason("no last committed, new entry"); |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1616 | return NAVIGATION_TYPE_MAIN_FRAME_NEW_ENTRY; |
Nasko Oskov | ae49e29 | 2020-08-13 02:08:51 | [diff] [blame] | 1617 | } |
creis | 26d2263 | 2017-04-21 20:23:56 | [diff] [blame] | 1618 | |
Rakina Zata Amni | 153d570 | 2021-09-13 22:48:00 | [diff] [blame] | 1619 | if (navigation_request->commit_params().intended_as_new_entry) { |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1620 | // 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] | 1621 | // got cleared in the meanwhile. Classify as EXISTING_ENTRY because we may |
| 1622 | // or may not have a pending entry. |
Charlie Reis | 7e2cb6d | 2021-01-26 01:27:16 | [diff] [blame] | 1623 | trace_return.set_return_reason("intended as new entry, existing entry"); |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1624 | return NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY; |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1625 | } |
| 1626 | |
Rakina Zata Amni | 3a1c0ec | 2021-04-15 03:35:12 | [diff] [blame] | 1627 | if (navigation_request->DidEncounterError() && |
| 1628 | failed_pending_entry_id_ != 0 && |
Rakina Zata Amni | f6950d55 | 2020-11-24 03:26:10 | [diff] [blame] | 1629 | nav_entry_id == failed_pending_entry_id_) { |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1630 | // If the renderer was going to a new pending entry that got cleared because |
| 1631 | // 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] | 1632 | // by pressing return. Classify as EXISTING_ENTRY because we probably don't |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1633 | // have a pending entry. |
Nasko Oskov | ae49e29 | 2020-08-13 02:08:51 | [diff] [blame] | 1634 | trace_return.set_return_reason( |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1635 | "unreachable, matching pending, existing entry"); |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1636 | return NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY; |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1637 | } |
| 1638 | |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1639 | // 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] | 1640 | int existing_entry_index = GetEntryIndexWithUniqueID(nav_entry_id); |
Nasko Oskov | ae49e29 | 2020-08-13 02:08:51 | [diff] [blame] | 1641 | trace_return.traced_value()->SetInteger("existing_entry_index", |
| 1642 | existing_entry_index); |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1643 | if (existing_entry_index == -1) { |
avi | 5cad491 | 2015-06-19 05:25:44 | [diff] [blame] | 1644 | // The renderer has committed a navigation to an entry that no longer |
| 1645 | // exists. Because the renderer is showing that page, resurrect that entry. |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1646 | trace_return.set_return_reason("existing entry -1, new entry"); |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1647 | return NAVIGATION_TYPE_MAIN_FRAME_NEW_ENTRY; |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1648 | } |
| 1649 | |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1650 | // Since we weeded out "new" navigations above, we know this is an existing |
| 1651 | // (back/forward) navigation. |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1652 | trace_return.set_return_reason("default return, existing entry"); |
Yoshisato Yanagisawa | 2ccba60 | 2021-11-17 08:24:06 | [diff] [blame] | 1653 | return NAVIGATION_TYPE_MAIN_FRAME_EXISTING_ENTRY; |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 1654 | } |
| 1655 | |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 1656 | void NavigationControllerImpl::UpdateNavigationEntryDetails( |
| 1657 | NavigationEntryImpl* entry, |
| 1658 | RenderFrameHostImpl* rfh, |
| 1659 | const mojom::DidCommitProvisionalLoadParams& params, |
| 1660 | NavigationRequest* request, |
| 1661 | NavigationEntryImpl::UpdatePolicy update_policy, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 1662 | bool is_new_entry, |
| 1663 | LoadCommittedDetails* commit_details) { |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 1664 | // Update the FrameNavigationEntry. |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 1665 | std::vector<GURL> redirects; |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 1666 | entry->AddOrUpdateFrameEntry( |
| 1667 | rfh->frame_tree_node(), update_policy, params.item_sequence_number, |
| 1668 | params.document_sequence_number, params.app_history_key, |
| 1669 | rfh->GetSiteInstance(), nullptr, params.url, |
| 1670 | GetCommittedOriginForFrameEntry(params, request), |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 1671 | Referrer(*params.referrer), |
| 1672 | request ? request->common_params().initiator_origin : params.origin, |
| 1673 | request ? request->GetRedirectChain() : redirects, params.page_state, |
| 1674 | params.method, params.post_id, nullptr /* blob_url_loader_factory */, |
| 1675 | (request && request->web_bundle_navigation_info()) |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 1676 | ? request->web_bundle_navigation_info()->Clone() |
| 1677 | : nullptr, |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 1678 | (request ? request->GetSubresourceWebBundleNavigationInfo() : nullptr), |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 1679 | ComputePolicyContainerPoliciesForFrameEntry( |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 1680 | rfh, request && request->IsSameDocument(), |
| 1681 | request ? request->common_params().url : params.url)); |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 1682 | |
| 1683 | if (rfh->GetParent()) { |
| 1684 | // Only modify the NavigationEntry for main frame navigations. |
| 1685 | return; |
| 1686 | } |
| 1687 | if (entry->update_virtual_url_with_url()) |
| 1688 | UpdateVirtualURLToURL(entry, params.url); |
| 1689 | // Don't use the page type from the pending entry. Some interstitial page |
| 1690 | // may have set the type to interstitial. Once we commit, however, the page |
| 1691 | // type must always be normal or error. |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 1692 | entry->set_page_type((request && request->DidEncounterError()) |
| 1693 | ? PAGE_TYPE_ERROR |
| 1694 | : PAGE_TYPE_NORMAL); |
Rakina Zata Amni | f297a80 | 2022-01-18 03:53:43 | [diff] [blame] | 1695 | if (commit_details && commit_details->should_stay_as_initial_entry) { |
| 1696 | // Retain the "initial NavigationEntry" status. |
| 1697 | if (request->IsSameDocument()) { |
| 1698 | // If this is for a same-document navigation, the NavigationEntry must be |
| 1699 | // reused and should already be marked as the initial NavigationEntry. |
| 1700 | DCHECK(entry->IsInitialEntry()); |
| 1701 | } else { |
| 1702 | // If this is for a cross-document navigation, it can be caused by a |
| 1703 | // renderer-initiated reload, or the synchronous about:blank commit. Mark |
| 1704 | // "for synchronous about:blank" in the latter case, and also when it is |
| 1705 | // reloading a "for synchronous about:blank" entry. Otherwise, the entry |
| 1706 | // is not for a synchronous about:blank commit. |
| 1707 | NavigationEntryImpl::InitialNavigationEntryState new_state = |
| 1708 | NavigationEntryImpl::InitialNavigationEntryState:: |
| 1709 | kInitialNotForSynchronousAboutBlank; |
| 1710 | if (entry->IsInitialEntryForSynchronousAboutBlank() || |
| 1711 | request->is_synchronous_renderer_commit()) { |
| 1712 | new_state = NavigationEntryImpl::InitialNavigationEntryState:: |
| 1713 | kInitialForSynchronousAboutBlank; |
| 1714 | } |
| 1715 | entry->set_initial_navigation_entry_state(new_state); |
| 1716 | } |
| 1717 | } else if (commit_details && !commit_details->should_stay_as_initial_entry) { |
| 1718 | // Remove the "initial NavigationEntry" status. |
| 1719 | entry->set_initial_navigation_entry_state( |
| 1720 | NavigationEntryImpl::InitialNavigationEntryState::kNonInitial); |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 1721 | } |
Rakina Zata Amni | ddf1050 | 2022-01-15 02:56:55 | [diff] [blame] | 1722 | |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 1723 | if (is_new_entry) { |
| 1724 | // Some properties of the NavigationEntry are only set when the entry is |
| 1725 | // new (we aren't reusing it). |
| 1726 | entry->SetTransitionType(params.transition); |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 1727 | entry->SetOriginalRequestURL(request ? request->GetOriginalRequestURL() |
| 1728 | : GURL::EmptyGURL()); |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 1729 | DCHECK_EQ(rfh->is_overriding_user_agent(), params.is_overriding_user_agent); |
| 1730 | entry->SetIsOverridingUserAgent(params.is_overriding_user_agent); |
| 1731 | } else { |
| 1732 | // We are reusing the NavigationEntry. The site instance will normally be |
| 1733 | // the same except for a few cases: |
| 1734 | // 1) session restore, when no site instance will be assigned or |
| 1735 | // 2) redirect, when the site instance is reset. |
| 1736 | DCHECK(!entry->site_instance() || !entry->GetRedirectChain().empty() || |
| 1737 | entry->site_instance() == rfh->GetSiteInstance()); |
| 1738 | } |
| 1739 | } |
| 1740 | |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 1741 | void NavigationControllerImpl::CreateInitialEntry() { |
| 1742 | DCHECK_EQ(entries_.size(), 0u); |
| 1743 | RenderFrameHostImpl* rfh = frame_tree_.root()->current_frame_host(); |
| 1744 | auto params = mojom::DidCommitProvisionalLoadParams::New(); |
| 1745 | // The initial NavigationEntry's URL is the empty URL. This preserves the old |
| 1746 | // behavior of WebContent's GetLastCommittedURL() and GetVisibleURL() from |
| 1747 | // before we have initial NavigationEntries. |
| 1748 | params->url = GURL::EmptyGURL(); |
| 1749 | params->http_status_code = 0; |
| 1750 | params->url_is_unreachable = false; |
| 1751 | params->method = "GET"; |
| 1752 | params->should_replace_current_entry = false; |
| 1753 | params->post_id = -1; |
| 1754 | params->embedding_token = base::UnguessableToken::Create(); |
| 1755 | params->navigation_token = base::UnguessableToken::Create(); |
| 1756 | params->did_create_new_entry = true; |
| 1757 | params->origin = rfh->GetLastCommittedOrigin(); |
| 1758 | params->should_update_history = true; |
| 1759 | params->item_sequence_number = 0; |
| 1760 | params->document_sequence_number = 0; |
| 1761 | bool is_in_fenced_frame_tree = rfh->frame_tree_node()->IsInFencedFrameTree(); |
| 1762 | params->transition = is_in_fenced_frame_tree |
| 1763 | ? ui::PAGE_TRANSITION_AUTO_SUBFRAME |
| 1764 | : ui::PAGE_TRANSITION_LINK; |
| 1765 | params->referrer = blink::mojom::Referrer::New(); |
| 1766 | |
| 1767 | // Create and insert the initial NavigationEntry. |
| 1768 | auto new_entry = std::make_unique<NavigationEntryImpl>( |
| 1769 | rfh->GetSiteInstance(), params->url, Referrer(*params->referrer), |
| 1770 | rfh->GetLastCommittedOrigin(), std::u16string() /* title */, |
| 1771 | ui::PAGE_TRANSITION_TYPED, false /* renderer_initiated */, |
| 1772 | nullptr /* blob_url_loader_factory */, true /* is_initial_entry */); |
| 1773 | UpdateNavigationEntryDetails( |
| 1774 | new_entry.get(), rfh, *params, nullptr /* request */, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 1775 | NavigationEntryImpl::UpdatePolicy::kUpdate, true /* is_new_entry */, |
| 1776 | nullptr /* commit_details */); |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 1777 | |
| 1778 | InsertOrReplaceEntry(std::move(new_entry), false /* replace_entry */, |
| 1779 | false /* was_post_commit_error */, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 1780 | is_in_fenced_frame_tree, nullptr /* commit_details */); |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 1781 | } |
| 1782 | |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1783 | void NavigationControllerImpl::RendererDidNavigateToNewEntry( |
creis | 3da0387 | 2015-02-20 21:12:32 | [diff] [blame] | 1784 | RenderFrameHostImpl* rfh, |
arthursonzogni | 73fe321 | 2020-11-17 13:24:07 | [diff] [blame] | 1785 | const mojom::DidCommitProvisionalLoadParams& params, |
eugenebut | 604866f | 2017-05-10 21:35:36 | [diff] [blame] | 1786 | bool is_same_document, |
clamy | 3bf35e3c | 2016-11-10 15:59:44 | [diff] [blame] | 1787 | bool replace_entry, |
Shivani Sharma | ffb32b8 | 2019-04-09 16:58:47 | [diff] [blame] | 1788 | bool previous_document_was_activated, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 1789 | NavigationRequest* request, |
| 1790 | LoadCommittedDetails* commit_details) { |
dcheng | 9bfa516 | 2016-04-09 01:00:57 | [diff] [blame] | 1791 | std::unique_ptr<NavigationEntryImpl> new_entry; |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 1792 | const absl::optional<url::Origin>& initiator_origin = |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 1793 | request->common_params().initiator_origin; |
Lukasz Anforowicz | 435bcb58 | 2019-07-12 20:50:06 | [diff] [blame] | 1794 | |
creis | f49dfc9 | 2016-07-26 17:05:18 | [diff] [blame] | 1795 | // First check if this is an in-page navigation. If so, clone the current |
| 1796 | // entry instead of looking at the pending entry, because the pending entry |
| 1797 | // does not have any subframe history items. |
eugenebut | 604866f | 2017-05-10 21:35:36 | [diff] [blame] | 1798 | if (is_same_document && GetLastCommittedEntry()) { |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 1799 | FrameNavigationEntry* previous_frame_entry = |
| 1800 | GetLastCommittedEntry()->GetFrameEntry(rfh->frame_tree_node()); |
Patrick Monette | 50e8bd8 | 2019-06-13 22:40:45 | [diff] [blame] | 1801 | auto frame_entry = base::MakeRefCounted<FrameNavigationEntry>( |
Charles Reis | d2a509f | 2017-09-27 23:47:48 | [diff] [blame] | 1802 | rfh->frame_tree_node()->unique_name(), params.item_sequence_number, |
Nate Chapin | fbfe5af | 2021-06-10 17:22:08 | [diff] [blame] | 1803 | params.document_sequence_number, params.app_history_key, |
| 1804 | rfh->GetSiteInstance(), nullptr, params.url, |
| 1805 | GetCommittedOriginForFrameEntry(params, request), |
Rakina Zata Amni | 82fafba | 2021-03-11 07:07:09 | [diff] [blame] | 1806 | Referrer(*params.referrer), initiator_origin, |
| 1807 | request->GetRedirectChain(), params.page_state, params.method, |
| 1808 | params.post_id, nullptr /* blob_url_loader_factory */, |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 1809 | nullptr /* web_bundle_navigation_info */, |
Kunihiko Sakamoto | 346a74e | 2021-03-10 08:57:48 | [diff] [blame] | 1810 | request->GetSubresourceWebBundleNavigationInfo(), |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 1811 | // We will set the document policies later in this function. |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 1812 | nullptr /* policy_container_policies */, |
| 1813 | // Try to preserve protect_url_in_app_history from the previous |
| 1814 | // FrameNavigationEntry. |
| 1815 | previous_frame_entry && |
| 1816 | previous_frame_entry->protect_url_in_app_history()); |
Charles Reis | f4448202 | 2017-10-13 21:15:03 | [diff] [blame] | 1817 | |
creis | f49dfc9 | 2016-07-26 17:05:18 | [diff] [blame] | 1818 | new_entry = GetLastCommittedEntry()->CloneAndReplace( |
Harkiran Bolaria | 081c5c2 | 2021-09-13 08:44:53 | [diff] [blame] | 1819 | frame_entry, true, request->frame_tree_node(), frame_tree_.root()); |
Mike West | 800532c | 2021-10-14 09:26:52 | [diff] [blame] | 1820 | if (new_entry->GetURL().DeprecatedGetOriginAsURL() != |
| 1821 | params.url.DeprecatedGetOriginAsURL()) { |
jam | a78746e | 2017-02-22 17:21:57 | [diff] [blame] | 1822 | // TODO(jam): we had one report of this with a URL that was redirecting to |
| 1823 | // only tildes. Until we understand that better, don't copy the cert in |
| 1824 | // this case. |
| 1825 | new_entry->GetSSL() = SSLStatus(); |
jam | a78746e | 2017-02-22 17:21:57 | [diff] [blame] | 1826 | } |
creis | f49dfc9 | 2016-07-26 17:05:18 | [diff] [blame] | 1827 | |
Patrick Monette | 50e8bd8 | 2019-06-13 22:40:45 | [diff] [blame] | 1828 | // It is expected that |frame_entry| is now owned by |new_entry|. This means |
| 1829 | // that |frame_entry| should now have a reference count of exactly 2: one |
| 1830 | // due to the local variable |frame_entry|, and another due to |new_entry| |
| 1831 | // also retaining one. This should never fail, because it's the main frame. |
| 1832 | CHECK(!frame_entry->HasOneRef() && frame_entry->HasAtLeastOneRef()); |
creis | f49dfc9 | 2016-07-26 17:05:18 | [diff] [blame] | 1833 | } |
| 1834 | |
Harkiran Bolaria | 59290d6 | 2021-03-17 01:53:01 | [diff] [blame] | 1835 | // If this is an activation navigation from a prerendered page, transfer the |
| 1836 | // new entry from an entry already created and stored in the |
| 1837 | // NavigationRequest. |new_entry| will not have been set prior to this as |
| 1838 | // |is_same_document| is mutually exclusive with |
| 1839 | // |IsPrerenderedPageActivation|. |
| 1840 | if (request->IsPrerenderedPageActivation()) { |
| 1841 | DCHECK(!is_same_document); |
| 1842 | DCHECK(!new_entry); |
| 1843 | new_entry = request->TakePrerenderNavigationEntry(); |
| 1844 | DCHECK(new_entry); |
| 1845 | } |
| 1846 | |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1847 | // Only make a copy of the pending entry if it is appropriate for the new |
| 1848 | // document that just loaded. Verify this by checking if the entry corresponds |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 1849 | // to the given NavigationRequest. Additionally, coarsely check that: |
csharrison | 9a9142bc4 | 2016-03-01 17:24:04 | [diff] [blame] | 1850 | // 1. The SiteInstance hasn't been assigned to something else. |
| 1851 | // 2. The pending entry was intended as a new entry, rather than being a |
| 1852 | // history navigation that was interrupted by an unrelated, |
| 1853 | // renderer-initiated navigation. |
| 1854 | // TODO(csharrison): Investigate whether we can remove some of the coarser |
| 1855 | // checks. |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 1856 | if (!new_entry && PendingEntryMatchesRequest(request) && |
| 1857 | pending_entry_index_ == -1 && |
[email protected] | 6dd86ab | 2013-02-27 00:30:34 | [diff] [blame] | 1858 | (!pending_entry_->site_instance() || |
[email protected] | 27dd82fd | 2014-03-03 22:11:43 | [diff] [blame] | 1859 | pending_entry_->site_instance() == rfh->GetSiteInstance())) { |
creis | ef4a0cb | 2015-03-12 19:14:35 | [diff] [blame] | 1860 | new_entry = pending_entry_->Clone(); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1861 | |
Camille Lamy | 62b82601 | 2019-02-26 09:15:47 | [diff] [blame] | 1862 | new_entry->GetSSL() = |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 1863 | SSLStatus(request->GetSSLInfo().value_or(net::SSLInfo())); |
creis | f49dfc9 | 2016-07-26 17:05:18 | [diff] [blame] | 1864 | } |
| 1865 | |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1866 | // For cross-document commits with no matching pending entry, create a new |
| 1867 | // entry. |
creis | f49dfc9 | 2016-07-26 17:05:18 | [diff] [blame] | 1868 | if (!new_entry) { |
Lukasz Anforowicz | 435bcb58 | 2019-07-12 20:50:06 | [diff] [blame] | 1869 | new_entry = std::make_unique<NavigationEntryImpl>( |
arthursonzogni | 73fe321 | 2020-11-17 13:24:07 | [diff] [blame] | 1870 | rfh->GetSiteInstance(), params.url, Referrer(*params.referrer), |
| 1871 | initiator_origin, |
Jan Wilken Dörrie | aace0cfef | 2021-03-11 22:01:58 | [diff] [blame] | 1872 | std::u16string(), // title |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 1873 | params.transition, request->IsRendererInitiated(), |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 1874 | nullptr, // blob_url_loader_factory |
| 1875 | false); // is_initial_entry |
[email protected] | f8f93eb | 2012-09-25 03:06:24 | [diff] [blame] | 1876 | |
| 1877 | // Find out whether the new entry needs to update its virtual URL on URL |
| 1878 | // change and set up the entry accordingly. This is needed to correctly |
| 1879 | // update the virtual URL when replaceState is called after a pushState. |
| 1880 | GURL url = params.url; |
| 1881 | bool needs_update = false; |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1882 | // 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] | 1883 | // update the virtual URL based on the new URL. For example, this is needed |
| 1884 | // to show chrome://bookmarks/#1 when the bookmarks webui extension changes |
| 1885 | // the URL. |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 1886 | BrowserURLHandlerImpl::GetInstance()->RewriteURLIfNecessary( |
| 1887 | &url, browser_context_, &needs_update); |
| 1888 | new_entry->set_update_virtual_url_with_url(needs_update); |
| 1889 | |
Camille Lamy | 62b82601 | 2019-02-26 09:15:47 | [diff] [blame] | 1890 | new_entry->GetSSL() = |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 1891 | SSLStatus(request->GetSSLInfo().value_or(net::SSLInfo())); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1892 | } |
| 1893 | |
Harkiran Bolaria | 59290d6 | 2021-03-17 01:53:01 | [diff] [blame] | 1894 | // TODO(crbug.com/1179428) - determine which parts of the entry need to be set |
| 1895 | // for prerendered contents, if any. This is because prerendering/activation |
| 1896 | // technically won't be creating a new document. Unlike BFCache, prerendering |
| 1897 | // creates a new NavigationEntry rather than using an existing one. |
| 1898 | if (!request->IsPrerenderedPageActivation()) { |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 1899 | UpdateNavigationEntryDetails(new_entry.get(), rfh, params, request, |
| 1900 | NavigationEntryImpl::UpdatePolicy::kUpdate, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 1901 | true /* is_new_entry */, commit_details); |
creis | 8b5cd4c | 2015-06-19 00:11:08 | [diff] [blame] | 1902 | |
Harkiran Bolaria | 59290d6 | 2021-03-17 01:53:01 | [diff] [blame] | 1903 | // history.pushState() is classified as a navigation to a new page, but sets |
| 1904 | // is_same_document to true. In this case, we already have the title and |
| 1905 | // favicon available, so set them immediately. |
| 1906 | if (is_same_document && GetLastCommittedEntry()) { |
| 1907 | new_entry->SetTitle(GetLastCommittedEntry()->GetTitle()); |
| 1908 | new_entry->GetFavicon() = GetLastCommittedEntry()->GetFavicon(); |
| 1909 | } |
[email protected] | 3a868f21 | 2014-08-09 10:41:19 | [diff] [blame] | 1910 | } |
[email protected] | ff64b3e | 2014-05-31 04:07:33 | [diff] [blame] | 1911 | |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 1912 | DCHECK(!params.history_list_was_cleared || !replace_entry); |
| 1913 | // The browser requested to clear the session history when it initiated the |
| 1914 | // navigation. Now we know that the renderer has updated its state accordingly |
| 1915 | // and it is safe to also clear the browser side history. |
| 1916 | if (params.history_list_was_cleared) { |
Rakina Zata Amni | ddf1050 | 2022-01-15 02:56:55 | [diff] [blame] | 1917 | DiscardNonCommittedEntriesWithCommitDetails(commit_details); |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 1918 | entries_.clear(); |
| 1919 | last_committed_entry_index_ = -1; |
| 1920 | } |
| 1921 | |
Nasko Oskov | aee2f86 | 2018-06-15 00:05:52 | [diff] [blame] | 1922 | // If this is a new navigation with replacement and there is a |
| 1923 | // pending_entry_ which matches the navigation reported by the renderer |
| 1924 | // process, then it should be the one replaced, so update the |
| 1925 | // last_committed_entry_index_ to use it. |
| 1926 | if (replace_entry && pending_entry_index_ != -1 && |
Rakina Zata Amni | f6950d55 | 2020-11-24 03:26:10 | [diff] [blame] | 1927 | pending_entry_->GetUniqueID() == request->commit_params().nav_entry_id) { |
Nasko Oskov | aee2f86 | 2018-06-15 00:05:52 | [diff] [blame] | 1928 | last_committed_entry_index_ = pending_entry_index_; |
| 1929 | } |
| 1930 | |
Alexander Timin | e3ec419 | 2020-04-20 16:39:40 | [diff] [blame] | 1931 | SetShouldSkipOnBackForwardUIIfNeeded( |
shivanigithub | e92c33da | 2020-09-14 13:01:41 | [diff] [blame] | 1932 | replace_entry, previous_document_was_activated, |
Alexander Timin | e3ec419 | 2020-04-20 16:39:40 | [diff] [blame] | 1933 | request->IsRendererInitiated(), request->GetPreviousPageUkmSourceId()); |
shivanisha | 41f04c5 | 2018-12-12 15:52:05 | [diff] [blame] | 1934 | |
Carlos IL | 42b41659 | 2019-10-07 23:10:36 | [diff] [blame] | 1935 | InsertOrReplaceEntry(std::move(new_entry), replace_entry, |
Dave Tapuska | 87696ae | 2021-11-18 18:48:31 | [diff] [blame] | 1936 | !request->post_commit_error_page_html().empty(), |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 1937 | rfh->frame_tree_node()->IsInFencedFrameTree(), |
| 1938 | commit_details); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1939 | } |
| 1940 | |
Charlie Reis | c0f17d2d | 2021-01-12 18:52:49 | [diff] [blame] | 1941 | void NavigationControllerImpl::RendererDidNavigateToExistingEntry( |
creis | 3da0387 | 2015-02-20 21:12:32 | [diff] [blame] | 1942 | RenderFrameHostImpl* rfh, |
arthursonzogni | 73fe321 | 2020-11-17 13:24:07 | [diff] [blame] | 1943 | const mojom::DidCommitProvisionalLoadParams& params, |
eugenebut | 604866f | 2017-05-10 21:35:36 | [diff] [blame] | 1944 | bool is_same_document, |
jam | 48cea908 | 2017-02-15 06:13:29 | [diff] [blame] | 1945 | bool was_restored, |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 1946 | NavigationRequest* request, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 1947 | bool keep_pending_entry, |
| 1948 | LoadCommittedDetails* commit_details) { |
creis | 26d2263 | 2017-04-21 20:23:56 | [diff] [blame] | 1949 | DCHECK(GetLastCommittedEntry()) << "ClassifyNavigation should guarantee " |
| 1950 | << "that a last committed entry exists."; |
| 1951 | |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1952 | // We should only get here for main frame navigations. |
avi | 39c1edd3 | 2015-06-04 20:06:00 | [diff] [blame] | 1953 | DCHECK(!rfh->GetParent()); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 1954 | |
Charlie Reis | 7e2cb6d | 2021-01-26 01:27:16 | [diff] [blame] | 1955 | NavigationEntryImpl* entry = nullptr; |
Rakina Zata Amni | 153d570 | 2021-09-13 22:48:00 | [diff] [blame] | 1956 | if (request->commit_params().intended_as_new_entry) { |
Charlie Reis | 7e2cb6d | 2021-01-26 01:27:16 | [diff] [blame] | 1957 | // We're guaranteed to have a last committed entry if intended_as_new_entry |
| 1958 | // is true. |
avi | cbdc4c1 | 2015-07-01 16:07:11 | [diff] [blame] | 1959 | entry = GetLastCommittedEntry(); |
Charlie Reis | 7e2cb6d | 2021-01-26 01:27:16 | [diff] [blame] | 1960 | DCHECK(entry); |
| 1961 | |
| 1962 | // If the NavigationRequest matches a new pending entry and is classified as |
| 1963 | // EXISTING_ENTRY, then it is a navigation to the same URL that was |
| 1964 | // converted to a reload, such as a user pressing enter in the omnibox. |
| 1965 | if (pending_entry_ && pending_entry_index_ == -1 && |
| 1966 | pending_entry_->GetUniqueID() == |
| 1967 | request->commit_params().nav_entry_id) { |
| 1968 | // Note: The pending entry will usually have a real ReloadType here, but |
| 1969 | // it can still be ReloadType::NONE in cases that |
| 1970 | // ShouldTreatNavigationAsReload returns false (e.g., POST, view-source). |
| 1971 | |
| 1972 | // If we classified this correctly, the SiteInstance should not have |
| 1973 | // changed. |
| 1974 | CHECK_EQ(entry->site_instance(), rfh->GetSiteInstance()); |
| 1975 | |
| 1976 | // For converted reloads, we assign the entry's unique ID to be that of |
| 1977 | // the new one. Since this is always the result of a user action, we want |
| 1978 | // to dismiss infobars, etc. like a regular user-initiated navigation. |
| 1979 | entry->set_unique_id(pending_entry_->GetUniqueID()); |
| 1980 | |
| 1981 | // The extra headers may have changed due to reloading with different |
| 1982 | // headers. |
| 1983 | entry->set_extra_headers(pending_entry_->extra_headers()); |
| 1984 | } |
| 1985 | // Otherwise, this was intended as a new entry but the pending entry was |
| 1986 | // lost in the meantime and no new entry was created. We are stuck at the |
| 1987 | // last committed entry. |
| 1988 | |
| 1989 | // Even if this is a converted reload from pressing enter in the omnibox, |
| 1990 | // the server could redirect, requiring an update to the SSL status. If this |
| 1991 | // is a same document navigation, though, there's no SSLStatus in the |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 1992 | // NavigationRequest so don't overwrite the existing entry's SSLStatus. |
Charlie Reis | 7e2cb6d | 2021-01-26 01:27:16 | [diff] [blame] | 1993 | if (!is_same_document) { |
Camille Lamy | 62b82601 | 2019-02-26 09:15:47 | [diff] [blame] | 1994 | entry->GetSSL() = |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 1995 | SSLStatus(request->GetSSLInfo().value_or(net::SSLInfo())); |
Charlie Reis | 7e2cb6d | 2021-01-26 01:27:16 | [diff] [blame] | 1996 | } |
Rakina Zata Amni | f6950d55 | 2020-11-24 03:26:10 | [diff] [blame] | 1997 | } else if (const int nav_entry_id = request->commit_params().nav_entry_id) { |
avi | cbdc4c1 | 2015-07-01 16:07:11 | [diff] [blame] | 1998 | // This is a browser-initiated navigation (back/forward/reload). |
Rakina Zata Amni | f6950d55 | 2020-11-24 03:26:10 | [diff] [blame] | 1999 | entry = GetEntryWithUniqueID(nav_entry_id); |
jam | d208b90 | 2016-09-01 16:58:16 | [diff] [blame] | 2000 | |
eugenebut | 604866f | 2017-05-10 21:35:36 | [diff] [blame] | 2001 | if (is_same_document) { |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 2002 | // There's no SSLStatus in the NavigationRequest for same document |
eugenebut | 604866f | 2017-05-10 21:35:36 | [diff] [blame] | 2003 | // navigations, so normally we leave |entry|'s SSLStatus as is. However if |
| 2004 | // this was a restored same document navigation entry, then it won't have |
| 2005 | // an SSLStatus. So we need to copy over the SSLStatus from the entry that |
| 2006 | // navigated it. |
jam | 48cea908 | 2017-02-15 06:13:29 | [diff] [blame] | 2007 | NavigationEntryImpl* last_entry = GetLastCommittedEntry(); |
Mike West | 800532c | 2021-10-14 09:26:52 | [diff] [blame] | 2008 | if (entry->GetURL().DeprecatedGetOriginAsURL() == |
| 2009 | last_entry->GetURL().DeprecatedGetOriginAsURL() && |
jam | 48cea908 | 2017-02-15 06:13:29 | [diff] [blame] | 2010 | last_entry->GetSSL().initialized && !entry->GetSSL().initialized && |
| 2011 | was_restored) { |
| 2012 | entry->GetSSL() = last_entry->GetSSL(); |
| 2013 | } |
| 2014 | } else { |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 2015 | // In rapid back/forward navigations |request| sometimes won't have a cert |
| 2016 | // (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] | 2017 | // otherwise we only reuse the existing cert if the origins match. |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 2018 | if (request->GetSSLInfo().has_value() && |
| 2019 | request->GetSSLInfo()->is_valid()) { |
| 2020 | entry->GetSSL() = SSLStatus(*(request->GetSSLInfo())); |
Mike West | 800532c | 2021-10-14 09:26:52 | [diff] [blame] | 2021 | } else if (entry->GetURL().DeprecatedGetOriginAsURL() != |
| 2022 | request->GetURL().DeprecatedGetOriginAsURL()) { |
John Abd-El-Malek | 3f24708 | 2017-12-07 19:02:19 | [diff] [blame] | 2023 | entry->GetSSL() = SSLStatus(); |
| 2024 | } |
jam | 48cea908 | 2017-02-15 06:13:29 | [diff] [blame] | 2025 | } |
avi | cbdc4c1 | 2015-07-01 16:07:11 | [diff] [blame] | 2026 | } else { |
| 2027 | // This is renderer-initiated. The only kinds of renderer-initated |
Rakina Zata Amni | 557afb9 | 2021-07-17 04:39:57 | [diff] [blame] | 2028 | // navigations that are EXISTING_ENTRY are same-document navigations that |
| 2029 | // result in replacement (e.g. history.replaceState(), location.replace(), |
| 2030 | // forced replacements for trivial session history contexts). For these |
| 2031 | // cases, we reuse the last committed entry. |
avi | cbdc4c1 | 2015-07-01 16:07:11 | [diff] [blame] | 2032 | entry = GetLastCommittedEntry(); |
jam | 0576b13 | 2016-09-07 05:13:10 | [diff] [blame] | 2033 | |
Mikel Astiz | ba9cf2fd | 2017-12-17 10:38:10 | [diff] [blame] | 2034 | // TODO(crbug.com/751023): Set page transition type to PAGE_TRANSITION_LINK |
| 2035 | // to avoid misleading interpretations (e.g. URLs paired with |
| 2036 | // PAGE_TRANSITION_TYPED that haven't actually been typed) as well as to fix |
| 2037 | // the inconsistency with what we report to observers (PAGE_TRANSITION_LINK |
| 2038 | // | PAGE_TRANSITION_CLIENT_REDIRECT). |
| 2039 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2040 | CopyReplacedNavigationEntryDataIfPreviouslyEmpty(entry, entry); |
Mikel Astiz | ba9cf2fd | 2017-12-17 10:38:10 | [diff] [blame] | 2041 | |
eugenebut | 604866f | 2017-05-10 21:35:36 | [diff] [blame] | 2042 | // 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] | 2043 | // NavigationRequest so don't overwrite the existing entry's SSLStatus. |
eugenebut | 604866f | 2017-05-10 21:35:36 | [diff] [blame] | 2044 | if (!is_same_document) |
Camille Lamy | 62b82601 | 2019-02-26 09:15:47 | [diff] [blame] | 2045 | entry->GetSSL() = |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 2046 | SSLStatus(request->GetSSLInfo().value_or(net::SSLInfo())); |
avi | cbdc4c1 | 2015-07-01 16:07:11 | [diff] [blame] | 2047 | } |
| 2048 | DCHECK(entry); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 2049 | |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 2050 | UpdateNavigationEntryDetails(entry, rfh, params, request, |
| 2051 | NavigationEntryImpl::UpdatePolicy::kUpdate, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 2052 | false /* is_new_entry */, commit_details); |
creis | 22a7b4c | 2016-04-28 07:20:30 | [diff] [blame] | 2053 | |
[email protected] | 5ccd4dc | 2012-10-24 02:28:14 | [diff] [blame] | 2054 | // The redirected to page should not inherit the favicon from the previous |
| 2055 | // page. |
eugenebut | 604866f | 2017-05-10 21:35:36 | [diff] [blame] | 2056 | if (ui::PageTransitionIsRedirect(params.transition) && !is_same_document) |
[email protected] | 91a4ff8 | 2012-10-29 20:29:48 | [diff] [blame] | 2057 | entry->GetFavicon() = FaviconStatus(); |
[email protected] | 5ccd4dc | 2012-10-24 02:28:14 | [diff] [blame] | 2058 | |
Peter Boström | d759213 | 2019-01-30 04:50:31 | [diff] [blame] | 2059 | // We should also usually discard the pending entry if it corresponds to a |
| 2060 | // different navigation, since that one is now likely canceled. In rare |
| 2061 | // cases, we leave the pending entry for another navigation in place when we |
| 2062 | // know it is still ongoing, to avoid a flicker in the omnibox (see |
| 2063 | // https://crbug.com/900036). |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 2064 | // |
| 2065 | // Note that we need to use the "internal" version since we don't want to |
| 2066 | // actually change any other state, just kill the pointer. |
Peter Boström | d759213 | 2019-01-30 04:50:31 | [diff] [blame] | 2067 | if (!keep_pending_entry) |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 2068 | DiscardNonCommittedEntriesWithCommitDetails(commit_details); |
[email protected] | 40bcc30 | 2009-03-02 20:50:39 | [diff] [blame] | 2069 | |
Carlos IL | 4dea890 | 2020-05-26 15:14:29 | [diff] [blame] | 2070 | // Update the last committed index to reflect the committed entry. |
avi | cbdc4c1 | 2015-07-01 16:07:11 | [diff] [blame] | 2071 | last_committed_entry_index_ = GetIndexOfEntry(entry); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 2072 | } |
| 2073 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 2074 | void NavigationControllerImpl::RendererDidNavigateNewSubframe( |
creis | 3da0387 | 2015-02-20 21:12:32 | [diff] [blame] | 2075 | RenderFrameHostImpl* rfh, |
arthursonzogni | 73fe321 | 2020-11-17 13:24:07 | [diff] [blame] | 2076 | const mojom::DidCommitProvisionalLoadParams& params, |
eugenebut | 604866f | 2017-05-10 21:35:36 | [diff] [blame] | 2077 | bool is_same_document, |
Shivani Sharma | ffb32b8 | 2019-04-09 16:58:47 | [diff] [blame] | 2078 | bool replace_entry, |
| 2079 | bool previous_document_was_activated, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 2080 | NavigationRequest* request, |
| 2081 | LoadCommittedDetails* commit_details) { |
avi | 25f5f9e | 2015-07-17 20:08:26 | [diff] [blame] | 2082 | DCHECK(ui::PageTransitionCoreTypeIs(params.transition, |
| 2083 | ui::PAGE_TRANSITION_MANUAL_SUBFRAME)); |
Rakina Zata Amni | ddf1050 | 2022-01-15 02:56:55 | [diff] [blame] | 2084 | // The NEW_SUBFRAME path should never result in an initial NavigationEntry. |
| 2085 | DCHECK(!commit_details->should_stay_as_initial_entry); |
[email protected] | 09b8f82f | 2009-06-16 20:22:11 | [diff] [blame] | 2086 | |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 2087 | // Manual subframe navigations just get the current entry cloned so the user |
| 2088 | // can go back or forward to it. The actual subframe information will be |
| 2089 | // stored in the page state for each of those entries. This happens out of |
| 2090 | // band with the actual navigations. |
[email protected] | 4c27ba8 | 2008-09-24 16:49:09 | [diff] [blame] | 2091 | DCHECK(GetLastCommittedEntry()) << "ClassifyNavigation should guarantee " |
| 2092 | << "that a last committed entry exists."; |
creis | 96fc5508 | 2015-06-13 06:42:38 | [diff] [blame] | 2093 | |
Mikel Astiz | ba9cf2fd | 2017-12-17 10:38:10 | [diff] [blame] | 2094 | // The DCHECK below documents the fact that we don't know of any situation |
| 2095 | // where |replace_entry| is true for subframe navigations. This simplifies |
| 2096 | // reasoning about the replacement struct for subframes (see |
| 2097 | // CopyReplacedNavigationEntryDataIfPreviouslyEmpty()). |
| 2098 | DCHECK(!replace_entry); |
| 2099 | |
Patrick Monette | 50e8bd8 | 2019-06-13 22:40:45 | [diff] [blame] | 2100 | // This FrameNavigationEntry might not end up being used in the |
| 2101 | // 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] | 2102 | const absl::optional<url::Origin>& initiator_origin = |
Mohamed Abdelhalim | 833de90 | 2019-09-16 17:41:45 | [diff] [blame] | 2103 | request->common_params().initiator_origin; |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 2104 | std::unique_ptr<PolicyContainerPolicies> policy_container_policies = |
| 2105 | ComputePolicyContainerPoliciesForFrameEntry(rfh, is_same_document, |
| 2106 | request->GetURL()); |
| 2107 | bool protect_url_in_app_history = false; |
| 2108 | if (is_same_document) { |
| 2109 | FrameNavigationEntry* previous_frame_entry = |
| 2110 | GetLastCommittedEntry()->GetFrameEntry(rfh->frame_tree_node()); |
| 2111 | // Try to preserve protect_url_in_app_history from the previous |
| 2112 | // FrameNavigationEntry. |
| 2113 | protect_url_in_app_history = |
| 2114 | previous_frame_entry && |
| 2115 | previous_frame_entry->protect_url_in_app_history(); |
| 2116 | } else { |
| 2117 | protect_url_in_app_history = |
| 2118 | policy_container_policies && |
| 2119 | ShouldProtectUrlInAppHistory( |
| 2120 | policy_container_policies->referrer_policy); |
| 2121 | } |
| 2122 | |
Patrick Monette | 50e8bd8 | 2019-06-13 22:40:45 | [diff] [blame] | 2123 | auto frame_entry = base::MakeRefCounted<FrameNavigationEntry>( |
Charles Reis | d2a509f | 2017-09-27 23:47:48 | [diff] [blame] | 2124 | rfh->frame_tree_node()->unique_name(), params.item_sequence_number, |
Nate Chapin | fbfe5af | 2021-06-10 17:22:08 | [diff] [blame] | 2125 | params.document_sequence_number, params.app_history_key, |
| 2126 | rfh->GetSiteInstance(), nullptr, params.url, |
| 2127 | GetCommittedOriginForFrameEntry(params, request), |
Rakina Zata Amni | 82fafba | 2021-03-11 07:07:09 | [diff] [blame] | 2128 | Referrer(*params.referrer), initiator_origin, request->GetRedirectChain(), |
arthursonzogni | 73fe321 | 2020-11-17 13:24:07 | [diff] [blame] | 2129 | params.page_state, params.method, params.post_id, |
| 2130 | nullptr /* blob_url_loader_factory */, |
Tsuyoshi Horo | 0c60578 | 2020-05-27 00:21:03 | [diff] [blame] | 2131 | request->web_bundle_navigation_info() |
| 2132 | ? request->web_bundle_navigation_info()->Clone() |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 2133 | : nullptr, |
Kunihiko Sakamoto | 346a74e | 2021-03-10 08:57:48 | [diff] [blame] | 2134 | request->GetSubresourceWebBundleNavigationInfo(), |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 2135 | std::move(policy_container_policies), protect_url_in_app_history); |
Charles Reis | f4448202 | 2017-10-13 21:15:03 | [diff] [blame] | 2136 | |
creis | ce0ef357 | 2017-01-26 17:53:08 | [diff] [blame] | 2137 | std::unique_ptr<NavigationEntryImpl> new_entry = |
| 2138 | GetLastCommittedEntry()->CloneAndReplace( |
Patrick Monette | 50e8bd8 | 2019-06-13 22:40:45 | [diff] [blame] | 2139 | std::move(frame_entry), is_same_document, rfh->frame_tree_node(), |
Carlos Caballero | 40b0efd | 2021-01-26 11:55:00 | [diff] [blame] | 2140 | frame_tree_.root()); |
creis | e062d54 | 2015-08-25 02:01:55 | [diff] [blame] | 2141 | |
Alexander Timin | e3ec419 | 2020-04-20 16:39:40 | [diff] [blame] | 2142 | SetShouldSkipOnBackForwardUIIfNeeded( |
shivanigithub | e92c33da | 2020-09-14 13:01:41 | [diff] [blame] | 2143 | replace_entry, previous_document_was_activated, |
Alexander Timin | e3ec419 | 2020-04-20 16:39:40 | [diff] [blame] | 2144 | request->IsRendererInitiated(), request->GetPreviousPageUkmSourceId()); |
Shivani Sharma | ffb32b8 | 2019-04-09 16:58:47 | [diff] [blame] | 2145 | |
creis | ce0ef357 | 2017-01-26 17:53:08 | [diff] [blame] | 2146 | // 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] | 2147 | // to replace, which can happen due to a unique name change. See |
| 2148 | // https://crbug.com/607205. For now, the call to CloneAndReplace() will |
| 2149 | // delete the |frame_entry| when the function exits if it doesn't get used. |
creis | 96fc5508 | 2015-06-13 06:42:38 | [diff] [blame] | 2150 | |
Dave Tapuska | 87696ae | 2021-11-18 18:48:31 | [diff] [blame] | 2151 | InsertOrReplaceEntry(std::move(new_entry), replace_entry, false, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 2152 | rfh->frame_tree_node()->IsInFencedFrameTree(), |
| 2153 | commit_details); |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 2154 | } |
| 2155 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 2156 | bool NavigationControllerImpl::RendererDidNavigateAutoSubframe( |
creis | 3da0387 | 2015-02-20 21:12:32 | [diff] [blame] | 2157 | RenderFrameHostImpl* rfh, |
arthursonzogni | 73fe321 | 2020-11-17 13:24:07 | [diff] [blame] | 2158 | const mojom::DidCommitProvisionalLoadParams& params, |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 2159 | bool is_same_document, |
Nate Chapin | c7019dd7d | 2021-06-25 18:29:25 | [diff] [blame] | 2160 | bool was_on_initial_empty_document, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 2161 | NavigationRequest* request, |
| 2162 | LoadCommittedDetails* commit_details) { |
avi | 9f07a0c | 2015-02-18 22:51:29 | [diff] [blame] | 2163 | DCHECK(ui::PageTransitionCoreTypeIs(params.transition, |
| 2164 | ui::PAGE_TRANSITION_AUTO_SUBFRAME)); |
| 2165 | |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 2166 | // We're guaranteed to have a previously committed entry, and we now need to |
| 2167 | // handle navigation inside of a subframe in it without creating a new entry. |
| 2168 | DCHECK(GetLastCommittedEntry()); |
| 2169 | |
creis | 913c63ce | 2016-07-16 19:52:52 | [diff] [blame] | 2170 | // For newly created subframes, we don't need to send a commit notification. |
| 2171 | // This is only necessary for history navigations in subframes. |
| 2172 | bool send_commit_notification = false; |
| 2173 | |
Rakina Zata Amni | f6950d55 | 2020-11-24 03:26:10 | [diff] [blame] | 2174 | // If |nav_entry_id| is non-zero and matches an existing entry, this |
| 2175 | // is a history navigation. Update the last committed index accordingly. If |
| 2176 | // we don't recognize the |nav_entry_id|, it might be a recently |
| 2177 | // pruned entry. We'll handle it below. |
| 2178 | if (const int nav_entry_id = request->commit_params().nav_entry_id) { |
| 2179 | int entry_index = GetEntryIndexWithUniqueID(nav_entry_id); |
creis | 3cdc3b0 | 2015-05-29 23:00:47 | [diff] [blame] | 2180 | if (entry_index != -1 && entry_index != last_committed_entry_index_) { |
avi | 98405c2 | 2015-05-21 20:47:06 | [diff] [blame] | 2181 | // Make sure that a subframe commit isn't changing the main frame's |
| 2182 | // origin. Otherwise the renderer process may be confused, leading to a |
| 2183 | // URL spoof. We can't check the path since that may change |
| 2184 | // (https://crbug.com/373041). |
creis | 37988b9 | 2016-06-10 18:03:57 | [diff] [blame] | 2185 | // TODO(creis): For now, restrict this check to HTTP(S) origins, because |
| 2186 | // about:blank, file, and unique origins are more subtle to get right. |
Charlie Reis | 95fbca44 | 2021-05-21 21:38:24 | [diff] [blame] | 2187 | // We should use checks similar to RenderFrameHostImpl's |
| 2188 | // CanCommitUrlAndOrigin on the main frame during subframe commits. |
| 2189 | // See https://crbug.com/1209092. |
creis | 37988b9 | 2016-06-10 18:03:57 | [diff] [blame] | 2190 | const GURL& dest_top_url = GetEntryAtIndex(entry_index)->GetURL(); |
| 2191 | const GURL& current_top_url = GetLastCommittedEntry()->GetURL(); |
| 2192 | if (current_top_url.SchemeIsHTTPOrHTTPS() && |
| 2193 | dest_top_url.SchemeIsHTTPOrHTTPS() && |
Mike West | 800532c | 2021-10-14 09:26:52 | [diff] [blame] | 2194 | current_top_url.DeprecatedGetOriginAsURL() != |
| 2195 | dest_top_url.DeprecatedGetOriginAsURL()) { |
creis | fb6eeb6 | 2016-05-10 19:01:51 | [diff] [blame] | 2196 | bad_message::ReceivedBadMessage(rfh->GetProcess(), |
| 2197 | bad_message::NC_AUTO_SUBFRAME); |
avi | 98405c2 | 2015-05-21 20:47:06 | [diff] [blame] | 2198 | } |
creis | 3cdc3b0 | 2015-05-29 23:00:47 | [diff] [blame] | 2199 | |
creis | 913c63ce | 2016-07-16 19:52:52 | [diff] [blame] | 2200 | // We only need to discard the pending entry in this history navigation |
| 2201 | // case. For newly created subframes, there was no pending entry. |
avi | 98405c2 | 2015-05-21 20:47:06 | [diff] [blame] | 2202 | last_committed_entry_index_ = entry_index; |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 2203 | DiscardNonCommittedEntriesWithCommitDetails(commit_details); |
creis | 913c63ce | 2016-07-16 19:52:52 | [diff] [blame] | 2204 | |
| 2205 | // History navigations should send a commit notification. |
| 2206 | send_commit_notification = true; |
avi | 98405c2 | 2015-05-21 20:47:06 | [diff] [blame] | 2207 | } |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 2208 | } |
[email protected] | f233e423 | 2013-02-23 00:55:14 | [diff] [blame] | 2209 | |
creis | ce0ef357 | 2017-01-26 17:53:08 | [diff] [blame] | 2210 | // This may be a "new auto" case where we add a new FrameNavigationEntry, or |
| 2211 | // it may be a "history auto" case where we update an existing one. |
| 2212 | NavigationEntryImpl* last_committed = GetLastCommittedEntry(); |
Nate Chapin | 9f16907 | 2021-06-09 19:32:37 | [diff] [blame] | 2213 | |
| 2214 | // We may want to update |last_committed|'s FrameNavigationEntry (if one |
| 2215 | // exists), or we may want to clobber it and create a new one. We update in |
| 2216 | // cases where the corresponding FrameNavigationEntry is conceptually similar |
| 2217 | // to the document described by the commit params: same-document |
| 2218 | // navigations, history traversal to an existing entry, and reloads (including |
| 2219 | // a "soft reload" where we navigate to the same url without flagging it as a |
| 2220 | // reload). But in the case of a different document that is not logically |
| 2221 | // related to the committed FrameNavigationEntry's document (cross-document, |
| 2222 | // not same url, not a reload, not a history traversal), we replace rather |
| 2223 | // than update. |
Nate Chapin | c7019dd7d | 2021-06-25 18:29:25 | [diff] [blame] | 2224 | // |
Nate Chapin | 9f16907 | 2021-06-09 19:32:37 | [diff] [blame] | 2225 | // In the case where we update, the FrameNavigationEntry will potentially be |
| 2226 | // shared across multiple NavigationEntries, and any updates will be reflected |
| 2227 | // in all of those NavigationEntries. In the replace case, any existing |
| 2228 | // sharing with other NavigationEntries will stop. |
Nate Chapin | c7019dd7d | 2021-06-25 18:29:25 | [diff] [blame] | 2229 | // |
| 2230 | // When navigating away from the initial empty document, we also update rather |
| 2231 | // than replace. Either update or replace will overwrite the initial empty |
| 2232 | // document state for |last_committed|, but if the FrameNavigationEntry for |
| 2233 | // the initial empty document is shared across multiple NavigationEntries (due |
| 2234 | // to a navigation in another frame), we want to make sure we overwrite the |
| 2235 | // initial empty document state everywhere this FrameNavigationEntry is used, |
| 2236 | // which is accompished by updating the existing FrameNavigationEntry. |
Nate Chapin | 9f16907 | 2021-06-09 19:32:37 | [diff] [blame] | 2237 | FrameNavigationEntry* last_committed_frame_entry = |
| 2238 | last_committed->GetFrameEntry(rfh->frame_tree_node()); |
| 2239 | NavigationEntryImpl::UpdatePolicy update_policy = |
| 2240 | NavigationEntryImpl::UpdatePolicy::kUpdate; |
| 2241 | if (request->common_params().navigation_type == |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 2242 | blink::mojom::NavigationType::DIFFERENT_DOCUMENT && |
Nate Chapin | 9f16907 | 2021-06-09 19:32:37 | [diff] [blame] | 2243 | last_committed_frame_entry && |
Nate Chapin | c7019dd7d | 2021-06-25 18:29:25 | [diff] [blame] | 2244 | last_committed_frame_entry->url() != params.url && |
| 2245 | !was_on_initial_empty_document) { |
Nate Chapin | 9f16907 | 2021-06-09 19:32:37 | [diff] [blame] | 2246 | update_policy = NavigationEntryImpl::UpdatePolicy::kReplace; |
| 2247 | } |
| 2248 | |
Rakina Zata Amni | 3460d38 | 2021-10-29 00:43:37 | [diff] [blame] | 2249 | UpdateNavigationEntryDetails(last_committed, rfh, params, request, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 2250 | update_policy, false /* is_new_entry */, |
| 2251 | commit_details); |
creis | 625a0c7d | 2015-03-24 23:17:12 | [diff] [blame] | 2252 | |
creis | 913c63ce | 2016-07-16 19:52:52 | [diff] [blame] | 2253 | return send_commit_notification; |
[email protected] | e9ba447 | 2008-09-14 15:42:43 | [diff] [blame] | 2254 | } |
| 2255 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 2256 | int NavigationControllerImpl::GetIndexOfEntry( |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 2257 | const NavigationEntryImpl* entry) const { |
avi | f16f85a7 | 2015-11-13 18:25:03 | [diff] [blame] | 2258 | for (size_t i = 0; i < entries_.size(); ++i) { |
| 2259 | if (entries_[i].get() == entry) |
| 2260 | return i; |
| 2261 | } |
| 2262 | return -1; |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 2263 | } |
| 2264 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2265 | void NavigationControllerImpl::CopyStateFrom(NavigationController* temp, |
Francois Doray | eaace78 | 2017-06-21 16:37:24 | [diff] [blame] | 2266 | bool needs_reload) { |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2267 | NavigationControllerImpl* source = |
| 2268 | static_cast<NavigationControllerImpl*>(temp); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 2269 | // Verify that we look new. |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 2270 | if (blink::features::IsInitialNavigationEntryEnabled()) { |
| 2271 | DCHECK_EQ(1, GetEntryCount()); |
| 2272 | DCHECK(GetLastCommittedEntry()->IsInitialEntry()); |
| 2273 | } else { |
| 2274 | DCHECK_EQ(0, GetEntryCount()); |
| 2275 | } |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 2276 | DCHECK(!GetPendingEntry()); |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 2277 | entries_.clear(); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 2278 | |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 2279 | if (source->GetEntryCount() == 0) { |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 2280 | return; |
| 2281 | } |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 2282 | |
Francois Doray | eaace78 | 2017-06-21 16:37:24 | [diff] [blame] | 2283 | needs_reload_ = needs_reload; |
Bo Liu | cdfa4b1 | 2018-11-06 00:21:44 | [diff] [blame] | 2284 | needs_reload_type_ = NeedsReloadType::kCopyStateFrom; |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2285 | InsertEntriesFrom(source, source->GetEntryCount()); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 2286 | |
Fergal Daly | a1d56997 | 2021-03-16 03:24:53 | [diff] [blame] | 2287 | for (auto& it : source->session_storage_namespace_map_) { |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 2288 | SessionStorageNamespaceImpl* source_namespace = |
Fergal Daly | a1d56997 | 2021-03-16 03:24:53 | [diff] [blame] | 2289 | static_cast<SessionStorageNamespaceImpl*>(it.second.get()); |
| 2290 | session_storage_namespace_map_[it.first] = source_namespace->Clone(); |
Aaron Colwell | b731a0ae | 2021-03-19 19:14:47 | [diff] [blame] | 2291 | OnStoragePartitionIdAdded(it.first); |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 2292 | } |
[email protected] | 4e6419c | 2010-01-15 04:50:34 | [diff] [blame] | 2293 | |
Lukasz Anforowicz | 0de0f45 | 2020-12-02 19:57:15 | [diff] [blame] | 2294 | FinishRestore(source->last_committed_entry_index_, RestoreType::kRestored); |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 2295 | } |
| 2296 | |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 2297 | void NavigationControllerImpl::CopyStateFromAndPrune(NavigationController* temp, |
| 2298 | bool replace_entry) { |
[email protected] | 474f851 | 2013-05-31 22:31:16 | [diff] [blame] | 2299 | // It is up to callers to check the invariants before calling this. |
[email protected] | 7936898 | 2013-11-13 01:11:01 | [diff] [blame] | 2300 | CHECK(CanPruneAllButLastCommitted()); |
[email protected] | 474f851 | 2013-05-31 22:31:16 | [diff] [blame] | 2301 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 2302 | NavigationControllerImpl* source = |
| 2303 | static_cast<NavigationControllerImpl*>(temp); |
[email protected] | e1cd545 | 2010-08-26 18:03:25 | [diff] [blame] | 2304 | |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 2305 | // Remove all the entries leaving the last committed entry. |
[email protected] | 7936898 | 2013-11-13 01:11:01 | [diff] [blame] | 2306 | PruneAllButLastCommittedInternal(); |
[email protected] | e1cd545 | 2010-08-26 18:03:25 | [diff] [blame] | 2307 | |
[email protected] | 474f851 | 2013-05-31 22:31:16 | [diff] [blame] | 2308 | // We now have one entry, possibly with a new pending entry. Ensure that |
| 2309 | // adding the entries from source won't put us over the limit. |
| 2310 | DCHECK_EQ(1, GetEntryCount()); |
[email protected] | e78a685 | 2013-12-13 08:08:57 | [diff] [blame] | 2311 | if (!replace_entry) |
Shivani Sharma | d8c8d65 | 2019-02-13 17:27:57 | [diff] [blame] | 2312 | source->PruneOldestSkippableEntryIfFull(); |
[email protected] | 944822b | 2012-03-02 20:57:25 | [diff] [blame] | 2313 | |
Carlos IL | 4dea890 | 2020-05-26 15:14:29 | [diff] [blame] | 2314 | // Insert the entries from source. Ignore any pending entry, since it has not |
| 2315 | // committed in source. |
[email protected] | 474f851 | 2013-05-31 22:31:16 | [diff] [blame] | 2316 | int max_source_index = source->last_committed_entry_index_; |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 2317 | DCHECK_NE(max_source_index, -1); |
| 2318 | max_source_index++; |
[email protected] | e78a685 | 2013-12-13 08:08:57 | [diff] [blame] | 2319 | |
| 2320 | // Ignore the source's current entry if merging with replacement. |
| 2321 | // TODO(davidben): This should preserve entries forward of the current |
| 2322 | // too. http://crbug.com/317872 |
| 2323 | if (replace_entry && max_source_index > 0) |
| 2324 | max_source_index--; |
| 2325 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2326 | InsertEntriesFrom(source, max_source_index); |
[email protected] | e1cd545 | 2010-08-26 18:03:25 | [diff] [blame] | 2327 | |
| 2328 | // 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] | 2329 | last_committed_entry_index_ = GetEntryCount() - 1; |
[email protected] | 796931a9 | 2011-08-10 01:32:14 | [diff] [blame] | 2330 | |
Hayato Ito | 2c8c08d0 | 2021-06-23 03:38:43 | [diff] [blame] | 2331 | BroadcastHistoryOffsetAndLength(); |
[email protected] | e1cd545 | 2010-08-26 18:03:25 | [diff] [blame] | 2332 | } |
| 2333 | |
[email protected] | 7936898 | 2013-11-13 01:11:01 | [diff] [blame] | 2334 | bool NavigationControllerImpl::CanPruneAllButLastCommitted() { |
[email protected] | 474f851 | 2013-05-31 22:31:16 | [diff] [blame] | 2335 | // If there is no last committed entry, we cannot prune. Even if there is a |
| 2336 | // pending entry, it may not commit, leaving this WebContents blank, despite |
| 2337 | // possibly giving it new entries via CopyStateFromAndPrune. |
| 2338 | if (last_committed_entry_index_ == -1) |
| 2339 | return false; |
[email protected] | 9350602e | 2013-02-26 23:27:44 | [diff] [blame] | 2340 | |
[email protected] | 474f851 | 2013-05-31 22:31:16 | [diff] [blame] | 2341 | // We cannot prune if there is a pending entry at an existing entry index. |
| 2342 | // It may not commit, so we have to keep the last committed entry, and thus |
| 2343 | // there is no sensible place to keep the pending entry. It is ok to have |
| 2344 | // a new pending entry, which can optionally commit as a new navigation. |
| 2345 | if (pending_entry_index_ != -1) |
| 2346 | return false; |
| 2347 | |
[email protected] | 474f851 | 2013-05-31 22:31:16 | [diff] [blame] | 2348 | return true; |
| 2349 | } |
| 2350 | |
[email protected] | 7936898 | 2013-11-13 01:11:01 | [diff] [blame] | 2351 | void NavigationControllerImpl::PruneAllButLastCommitted() { |
| 2352 | PruneAllButLastCommittedInternal(); |
[email protected] | 474f851 | 2013-05-31 22:31:16 | [diff] [blame] | 2353 | |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 2354 | DCHECK_EQ(0, last_committed_entry_index_); |
| 2355 | DCHECK_EQ(1, GetEntryCount()); |
[email protected] | 9350602e | 2013-02-26 23:27:44 | [diff] [blame] | 2356 | |
Hayato Ito | 2c8c08d0 | 2021-06-23 03:38:43 | [diff] [blame] | 2357 | BroadcastHistoryOffsetAndLength(); |
[email protected] | 9350602e | 2013-02-26 23:27:44 | [diff] [blame] | 2358 | } |
| 2359 | |
[email protected] | 7936898 | 2013-11-13 01:11:01 | [diff] [blame] | 2360 | void NavigationControllerImpl::PruneAllButLastCommittedInternal() { |
[email protected] | 474f851 | 2013-05-31 22:31:16 | [diff] [blame] | 2361 | // It is up to callers to check the invariants before calling this. |
[email protected] | 7936898 | 2013-11-13 01:11:01 | [diff] [blame] | 2362 | CHECK(CanPruneAllButLastCommitted()); |
[email protected] | 97b6c4f | 2010-09-27 19:31:26 | [diff] [blame] | 2363 | |
[email protected] | 474f851 | 2013-05-31 22:31:16 | [diff] [blame] | 2364 | // Erase all entries but the last committed entry. There may still be a |
| 2365 | // new pending entry after this. |
| 2366 | entries_.erase(entries_.begin(), |
| 2367 | entries_.begin() + last_committed_entry_index_); |
| 2368 | entries_.erase(entries_.begin() + 1, entries_.end()); |
| 2369 | last_committed_entry_index_ = 0; |
[email protected] | 97b6c4f | 2010-09-27 19:31:26 | [diff] [blame] | 2370 | } |
| 2371 | |
Christian Dullweber | 1af31e6 | 2018-02-22 11:49:48 | [diff] [blame] | 2372 | void NavigationControllerImpl::DeleteNavigationEntries( |
| 2373 | const DeletionPredicate& deletionPredicate) { |
| 2374 | // It is up to callers to check the invariants before calling this. |
| 2375 | CHECK(CanPruneAllButLastCommitted()); |
| 2376 | std::vector<int> delete_indices; |
| 2377 | for (size_t i = 0; i < entries_.size(); i++) { |
| 2378 | if (i != static_cast<size_t>(last_committed_entry_index_) && |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2379 | deletionPredicate.Run(entries_[i].get())) { |
Christian Dullweber | 1af31e6 | 2018-02-22 11:49:48 | [diff] [blame] | 2380 | delete_indices.push_back(i); |
| 2381 | } |
| 2382 | } |
| 2383 | if (delete_indices.empty()) |
| 2384 | return; |
| 2385 | |
| 2386 | if (delete_indices.size() == GetEntryCount() - 1U) { |
| 2387 | PruneAllButLastCommitted(); |
| 2388 | } else { |
| 2389 | // Do the deletion in reverse to preserve indices. |
| 2390 | for (auto it = delete_indices.rbegin(); it != delete_indices.rend(); ++it) { |
| 2391 | RemoveEntryAtIndex(*it); |
| 2392 | } |
Hayato Ito | 2c8c08d0 | 2021-06-23 03:38:43 | [diff] [blame] | 2393 | BroadcastHistoryOffsetAndLength(); |
Christian Dullweber | 1af31e6 | 2018-02-22 11:49:48 | [diff] [blame] | 2394 | } |
| 2395 | delegate()->NotifyNavigationEntriesDeleted(); |
| 2396 | } |
| 2397 | |
Shivani Sharma | 883f5f3 | 2019-02-12 18:20:01 | [diff] [blame] | 2398 | bool NavigationControllerImpl::IsEntryMarkedToBeSkipped(int index) { |
| 2399 | auto* entry = GetEntryAtIndex(index); |
| 2400 | return entry && entry->should_skip_on_back_forward_ui(); |
| 2401 | } |
| 2402 | |
Carlos Caballero | 35ce710c | 2019-09-19 10:59:45 | [diff] [blame] | 2403 | BackForwardCacheImpl& NavigationControllerImpl::GetBackForwardCache() { |
| 2404 | return back_forward_cache_; |
| 2405 | } |
| 2406 | |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2407 | void NavigationControllerImpl::DiscardPendingEntry(bool was_failure) { |
| 2408 | // It is not safe to call DiscardPendingEntry while NavigateToEntry is in |
| 2409 | // progress, since this will cause a use-after-free. (We only allow this |
| 2410 | // when the tab is being destroyed for shutdown, since it won't return to |
| 2411 | // NavigateToEntry in that case.) http://crbug.com/347742. |
Takashi Toyoshima | ea534ef2 | 2021-07-21 03:27:59 | [diff] [blame] | 2412 | CHECK(!in_navigate_to_pending_entry_ || frame_tree_.IsBeingDestroyed()); |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2413 | |
| 2414 | if (was_failure && pending_entry_) { |
| 2415 | failed_pending_entry_id_ = pending_entry_->GetUniqueID(); |
| 2416 | } else { |
| 2417 | failed_pending_entry_id_ = 0; |
| 2418 | } |
| 2419 | |
| 2420 | if (pending_entry_) { |
| 2421 | if (pending_entry_index_ == -1) |
| 2422 | delete pending_entry_; |
| 2423 | pending_entry_index_ = -1; |
| 2424 | pending_entry_ = nullptr; |
| 2425 | } |
arthursonzogni | 66f711c | 2019-10-08 14:40:36 | [diff] [blame] | 2426 | |
| 2427 | // Ensure any refs to the current pending entry are ignored if they get |
| 2428 | // deleted, by clearing the set of known refs. All future pending entries will |
| 2429 | // only be affected by new refs. |
| 2430 | pending_entry_refs_.clear(); |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2431 | } |
| 2432 | |
| 2433 | void NavigationControllerImpl::SetPendingNavigationSSLError(bool error) { |
| 2434 | if (pending_entry_) |
| 2435 | pending_entry_->set_ssl_error(error); |
| 2436 | } |
| 2437 | |
Xiaohan Wang | 7f8052e0 | 2022-01-14 18:44:28 | [diff] [blame] | 2438 | #if BUILDFLAG(IS_ANDROID) |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 2439 | // static |
| 2440 | bool NavigationControllerImpl::ValidateDataURLAsString( |
| 2441 | const scoped_refptr<const base::RefCountedString>& data_url_as_string) { |
| 2442 | if (!data_url_as_string) |
| 2443 | return false; |
| 2444 | |
| 2445 | if (data_url_as_string->size() > kMaxLengthOfDataURLString) |
| 2446 | return false; |
| 2447 | |
| 2448 | // The number of characters that is enough for validating a data: URI. |
| 2449 | // From the GURL's POV, the only important part here is scheme, it doesn't |
| 2450 | // check the actual content. Thus we can take only the prefix of the url, to |
| 2451 | // avoid unneeded copying of a potentially long string. |
| 2452 | const size_t kDataUriPrefixMaxLen = 64; |
| 2453 | GURL data_url( |
| 2454 | std::string(data_url_as_string->front_as<char>(), |
| 2455 | std::min(data_url_as_string->size(), kDataUriPrefixMaxLen))); |
| 2456 | if (!data_url.is_valid() || !data_url.SchemeIs(url::kDataScheme)) |
| 2457 | return false; |
| 2458 | |
| 2459 | return true; |
| 2460 | } |
| 2461 | #endif |
| 2462 | |
Shivani Sharma | 19487703 | 2019-03-07 17:52:47 | [diff] [blame] | 2463 | void NavigationControllerImpl::NotifyUserActivation() { |
| 2464 | // When a user activation occurs, ensure that all adjacent entries for the |
| 2465 | // same document clear their skippable bit, so that the history manipulation |
| 2466 | // intervention does not apply to them. |
| 2467 | auto* last_committed_entry = GetLastCommittedEntry(); |
| 2468 | if (!last_committed_entry) |
| 2469 | return; |
Shivani Sharma | 19487703 | 2019-03-07 17:52:47 | [diff] [blame] | 2470 | |
shivanigithub | 9936838 | 2021-06-16 18:33:37 | [diff] [blame] | 2471 | if (base::FeatureList::IsEnabled( |
| 2472 | features::kDebugHistoryInterventionNoUserActivation)) { |
| 2473 | return; |
| 2474 | } |
| 2475 | |
Shivani Sharma | c4cc892 | 2019-04-18 03:11:17 | [diff] [blame] | 2476 | SetSkippableForSameDocumentEntries(GetLastCommittedEntryIndex(), false); |
Shivani Sharma | 19487703 | 2019-03-07 17:52:47 | [diff] [blame] | 2477 | } |
| 2478 | |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2479 | bool NavigationControllerImpl::StartHistoryNavigationInNewSubframe( |
| 2480 | RenderFrameHostImpl* render_frame_host, |
Julie Jeongeun Kim | ed2e5ba7 | 2019-09-12 10:14:17 | [diff] [blame] | 2481 | mojo::PendingAssociatedRemote<mojom::NavigationClient>* navigation_client) { |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2482 | NavigationEntryImpl* entry = |
| 2483 | GetEntryWithUniqueID(render_frame_host->nav_entry_id()); |
| 2484 | if (!entry) |
| 2485 | return false; |
| 2486 | |
| 2487 | FrameNavigationEntry* frame_entry = |
| 2488 | entry->GetFrameEntry(render_frame_host->frame_tree_node()); |
| 2489 | if (!frame_entry) |
| 2490 | return false; |
| 2491 | |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 2492 | // |is_browser_initiated| is false here because a navigation in a new subframe |
| 2493 | // always begins with renderer action (i.e., an HTML element being inserted |
| 2494 | // into the DOM), so it is always renderer-initiated. |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 2495 | std::unique_ptr<NavigationRequest> request = CreateNavigationRequestFromEntry( |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2496 | render_frame_host->frame_tree_node(), entry, frame_entry, |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 2497 | ReloadType::NONE, false /* is_same_document_history_load */, |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 2498 | true /* is_history_navigation_in_new_child */, |
| 2499 | false /* is_browser_initiated */); |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 2500 | |
| 2501 | if (!request) |
| 2502 | return false; |
| 2503 | |
arthursonzogni | f046d4a | 2019-12-12 19:08:10 | [diff] [blame] | 2504 | request->SetNavigationClient(std::move(*navigation_client)); |
Arthur Hemery | 06173ce | 2019-05-29 12:11:41 | [diff] [blame] | 2505 | |
Lukasz Anforowicz | 9ee83c27 | 2020-12-01 20:14:05 | [diff] [blame] | 2506 | render_frame_host->frame_tree_node()->navigator().Navigate(std::move(request), |
| 2507 | ReloadType::NONE); |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 2508 | |
| 2509 | return true; |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2510 | } |
| 2511 | |
Tsuyoshi Horo | 52fd08e | 2020-07-07 07:03:45 | [diff] [blame] | 2512 | bool NavigationControllerImpl::ReloadFrame(FrameTreeNode* frame_tree_node) { |
| 2513 | NavigationEntryImpl* entry = GetEntryAtIndex(GetCurrentEntryIndex()); |
| 2514 | if (!entry) |
| 2515 | return false; |
Rakina Zata Amni | f297a80 | 2022-01-18 03:53:43 | [diff] [blame] | 2516 | |
| 2517 | if (entry->IsInitialEntryNotForSynchronousAboutBlank()) { |
| 2518 | // We should never navigate to an existing initial NavigationEntry that is |
| 2519 | // the initial NavigationEntry for the initial empty document that hasn't |
| 2520 | // been overridden by the synchronous about:blank commit, to preserve |
| 2521 | // legacy behavior where trying to reload when the main frame is on the |
| 2522 | // initial empty document won't result in a navigation. See also |
| 2523 | // https://crbug.com/1277414. |
| 2524 | return false; |
| 2525 | } |
Tsuyoshi Horo | 52fd08e | 2020-07-07 07:03:45 | [diff] [blame] | 2526 | FrameNavigationEntry* frame_entry = entry->GetFrameEntry(frame_tree_node); |
| 2527 | if (!frame_entry) |
| 2528 | return false; |
John Abd-El-Malek | 5b66913 | 2020-07-14 01:04:14 | [diff] [blame] | 2529 | ReloadType reload_type = ReloadType::NORMAL; |
| 2530 | entry->set_reload_type(reload_type); |
Tsuyoshi Horo | 52fd08e | 2020-07-07 07:03:45 | [diff] [blame] | 2531 | std::unique_ptr<NavigationRequest> request = CreateNavigationRequestFromEntry( |
John Abd-El-Malek | 5b66913 | 2020-07-14 01:04:14 | [diff] [blame] | 2532 | frame_tree_node, entry, frame_entry, reload_type, |
Tsuyoshi Horo | 52fd08e | 2020-07-07 07:03:45 | [diff] [blame] | 2533 | false /* is_same_document_history_load */, |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 2534 | false /* is_history_navigation_in_new_child */, |
| 2535 | true /* is_browser_initiated */); |
Tsuyoshi Horo | 52fd08e | 2020-07-07 07:03:45 | [diff] [blame] | 2536 | if (!request) |
| 2537 | return false; |
Lukasz Anforowicz | 9ee83c27 | 2020-12-01 20:14:05 | [diff] [blame] | 2538 | frame_tree_node->navigator().Navigate(std::move(request), reload_type); |
Tsuyoshi Horo | 52fd08e | 2020-07-07 07:03:45 | [diff] [blame] | 2539 | return true; |
| 2540 | } |
| 2541 | |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 2542 | void NavigationControllerImpl::GoToOffsetInSandboxedFrame( |
| 2543 | int offset, |
| 2544 | int sandbox_frame_tree_node_id) { |
| 2545 | if (!CanGoToOffset(offset)) |
| 2546 | return; |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 2547 | GoToIndex(GetIndexForOffset(offset), sandbox_frame_tree_node_id, |
| 2548 | false /* is_browser_initiated */); |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 2549 | } |
| 2550 | |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2551 | void NavigationControllerImpl::NavigateFromFrameProxy( |
| 2552 | RenderFrameHostImpl* render_frame_host, |
| 2553 | const GURL& url, |
Chris Hamilton | 83272dc | 2021-02-23 00:24:02 | [diff] [blame] | 2554 | const blink::LocalFrameToken* initiator_frame_token, |
Antonio Sartori | 9a82f6f3 | 2020-12-14 09:22:45 | [diff] [blame] | 2555 | int initiator_process_id, |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 2556 | const absl::optional<url::Origin>& initiator_origin, |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2557 | bool is_renderer_initiated, |
| 2558 | SiteInstance* source_site_instance, |
| 2559 | const Referrer& referrer, |
| 2560 | ui::PageTransition page_transition, |
| 2561 | bool should_replace_current_entry, |
Yeunjoo Choi | 3df791a | 2021-02-17 07:07:25 | [diff] [blame] | 2562 | blink::NavigationDownloadPolicy download_policy, |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2563 | const std::string& method, |
| 2564 | scoped_refptr<network::ResourceRequestBody> post_body, |
Marijn Kruisselbrink | 7a0d5e18 | 2018-05-24 22:55:09 | [diff] [blame] | 2565 | const std::string& extra_headers, |
Antonio Sartori | 2f763d9d | 2021-04-21 10:04:14 | [diff] [blame] | 2566 | network::mojom::SourceLocationPtr source_location, |
John Delaney | 50425f8 | 2020-04-07 16:26:21 | [diff] [blame] | 2567 | scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory, |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 2568 | const absl::optional<blink::Impression>& impression) { |
Lukasz Anforowicz | 63f3b943 | 2019-05-30 05:42:58 | [diff] [blame] | 2569 | if (is_renderer_initiated) |
| 2570 | DCHECK(initiator_origin.has_value()); |
| 2571 | |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2572 | FrameTreeNode* node = render_frame_host->frame_tree_node(); |
Nasko Oskov | 18006bc | 2018-12-06 02:53:58 | [diff] [blame] | 2573 | |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 2574 | // Don't allow an entry replacement if there is no entry to replace. |
| 2575 | // http://crbug.com/457149 |
| 2576 | if (GetEntryCount() == 0) |
| 2577 | should_replace_current_entry = false; |
| 2578 | |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2579 | // Create a NavigationEntry for the transfer, without making it the pending |
| 2580 | // entry. Subframe transfers should have a clone of the last committed entry |
| 2581 | // with a FrameNavigationEntry for the target frame. Main frame transfers |
| 2582 | // should have a new NavigationEntry. |
| 2583 | // TODO(creis): Make this unnecessary by creating (and validating) the params |
| 2584 | // directly, passing them to the destination RenderFrameHost. See |
| 2585 | // https://crbug.com/536906. |
| 2586 | std::unique_ptr<NavigationEntryImpl> entry; |
Harkiran Bolaria | e1b5158b | 2021-09-16 19:03:26 | [diff] [blame] | 2587 | if (!render_frame_host->is_main_frame()) { |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2588 | // Subframe case: create FrameNavigationEntry. |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 2589 | if (GetLastCommittedEntry()) { |
| 2590 | entry = GetLastCommittedEntry()->Clone(); |
| 2591 | entry->set_extra_headers(extra_headers); |
| 2592 | // TODO(arthursonzogni): What about |is_renderer_initiated|? |
| 2593 | // Renderer-initiated navigation that target a remote frame are currently |
| 2594 | // classified as browser-initiated when this one has already navigated. |
| 2595 | // See https://crbug.com/722251. |
| 2596 | } else { |
| 2597 | // If there's no last committed entry, create an entry for about:blank |
| 2598 | // with a subframe entry for our destination. |
| 2599 | // TODO(creis): Ensure this case can't exist in https://crbug.com/524208. |
| 2600 | entry = NavigationEntryImpl::FromNavigationEntry(CreateNavigationEntry( |
| 2601 | GURL(url::kAboutBlankURL), referrer, initiator_origin, |
| 2602 | source_site_instance, page_transition, is_renderer_initiated, |
| 2603 | extra_headers, browser_context_, |
| 2604 | nullptr /* blob_url_loader_factory */)); |
| 2605 | } |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 2606 | // TODO(arthursonzogni): What about |is_renderer_initiated|? |
| 2607 | // Renderer-initiated navigation that target a remote frame are currently |
| 2608 | // classified as browser-initiated when this one has already navigated. |
| 2609 | // See https://crbug.com/722251. |
Nate Chapin | 9f16907 | 2021-06-09 19:32:37 | [diff] [blame] | 2610 | // The UpdatePolicy doesn't matter here. |entry| is only used as a parameter |
| 2611 | // to CreateNavigationRequestFromLoadParams(), so while kReplace might |
| 2612 | // remove child FrameNavigationEntries (e.g., if this is a cross-process |
| 2613 | // same-document navigation), they will still be present in the |
| 2614 | // committed NavigationEntry that will be referenced to construct the new |
| 2615 | // FrameNavigationEntry tree when this navigation commits. |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2616 | entry->AddOrUpdateFrameEntry( |
Nate Chapin | fbfe5af | 2021-06-10 17:22:08 | [diff] [blame] | 2617 | node, NavigationEntryImpl::UpdatePolicy::kReplace, -1, -1, "", nullptr, |
Nasko Oskov | 18006bc | 2018-12-06 02:53:58 | [diff] [blame] | 2618 | static_cast<SiteInstanceImpl*>(source_site_instance), url, |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 2619 | absl::nullopt /* commit_origin */, referrer, initiator_origin, |
Miyoung Shin | 5d77f7207 | 2020-10-09 15:14:20 | [diff] [blame] | 2620 | std::vector<GURL>(), blink::PageState(), method, -1, |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 2621 | blob_url_loader_factory, nullptr /* web_bundle_navigation_info */, |
Kunihiko Sakamoto | 346a74e | 2021-03-10 08:57:48 | [diff] [blame] | 2622 | nullptr /* subresource_web_bundle_navigation_info */, |
Antonio Sartori | 79d549d | 2021-02-18 12:59:54 | [diff] [blame] | 2623 | nullptr /* policy_container_policies */); |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2624 | } else { |
| 2625 | // Main frame case. |
| 2626 | entry = NavigationEntryImpl::FromNavigationEntry(CreateNavigationEntry( |
Lukasz Anforowicz | 641234d5 | 2019-11-07 21:07:10 | [diff] [blame] | 2627 | url, referrer, initiator_origin, source_site_instance, page_transition, |
| 2628 | is_renderer_initiated, extra_headers, browser_context_, |
Hayato Ito | 303654c | 2021-06-30 09:07:54 | [diff] [blame] | 2629 | blob_url_loader_factory)); |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2630 | entry->root_node()->frame_entry->set_source_site_instance( |
| 2631 | static_cast<SiteInstanceImpl*>(source_site_instance)); |
| 2632 | entry->root_node()->frame_entry->set_method(method); |
| 2633 | } |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2634 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 2635 | bool override_user_agent = false; |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2636 | if (GetLastCommittedEntry() && |
| 2637 | GetLastCommittedEntry()->GetIsOverridingUserAgent()) { |
| 2638 | entry->SetIsOverridingUserAgent(true); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 2639 | override_user_agent = true; |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2640 | } |
| 2641 | // TODO(creis): Set user gesture and intent received timestamp on Android. |
| 2642 | |
| 2643 | // We may not have successfully added the FrameNavigationEntry to |entry| |
| 2644 | // above (per https://crbug.com/608402), in which case we create it from |
| 2645 | // scratch. This works because we do not depend on |frame_entry| being inside |
| 2646 | // |entry| during NavigateToEntry. This will go away when we shortcut this |
| 2647 | // further in https://crbug.com/536906. |
| 2648 | scoped_refptr<FrameNavigationEntry> frame_entry(entry->GetFrameEntry(node)); |
| 2649 | if (!frame_entry) { |
Patrick Monette | 50e8bd8 | 2019-06-13 22:40:45 | [diff] [blame] | 2650 | frame_entry = base::MakeRefCounted<FrameNavigationEntry>( |
Nate Chapin | fbfe5af | 2021-06-10 17:22:08 | [diff] [blame] | 2651 | node->unique_name(), -1, -1, "", nullptr, |
Nasko Oskov | 18006bc | 2018-12-06 02:53:58 | [diff] [blame] | 2652 | static_cast<SiteInstanceImpl*>(source_site_instance), url, |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 2653 | absl::nullopt /* origin */, referrer, initiator_origin, |
Rakina Zata Amni | 3a1c0ec | 2021-04-15 03:35:12 | [diff] [blame] | 2654 | std::vector<GURL>(), blink::PageState(), method, -1, |
| 2655 | blob_url_loader_factory, nullptr /* web_bundle_navigation_info */, |
Kunihiko Sakamoto | 346a74e | 2021-03-10 08:57:48 | [diff] [blame] | 2656 | nullptr /* subresource_web_bundle_navigation_info */, |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 2657 | nullptr /* policy_container_policies */, |
| 2658 | false /* protect_url_in_app_history */); |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2659 | } |
| 2660 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 2661 | LoadURLParams params(url); |
Chris Hamilton | 83272dc | 2021-02-23 00:24:02 | [diff] [blame] | 2662 | params.initiator_frame_token = base::OptionalFromPtr(initiator_frame_token); |
Antonio Sartori | 9a82f6f3 | 2020-12-14 09:22:45 | [diff] [blame] | 2663 | params.initiator_process_id = initiator_process_id; |
Nasko Oskov | 93e7c55c | 2018-12-19 01:59:29 | [diff] [blame] | 2664 | params.initiator_origin = initiator_origin; |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 2665 | params.source_site_instance = source_site_instance; |
| 2666 | params.load_type = method == "POST" ? LOAD_TYPE_HTTP_POST : LOAD_TYPE_DEFAULT; |
| 2667 | params.transition_type = page_transition; |
Dominic Farolino | 226226af | 2019-06-25 00:58:03 | [diff] [blame] | 2668 | params.frame_tree_node_id = node->frame_tree_node_id(); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 2669 | params.referrer = referrer; |
| 2670 | /* params.redirect_chain: skip */ |
| 2671 | params.extra_headers = extra_headers; |
| 2672 | params.is_renderer_initiated = is_renderer_initiated; |
| 2673 | params.override_user_agent = UA_OVERRIDE_INHERIT; |
| 2674 | /* params.base_url_for_data_url: skip */ |
| 2675 | /* params.virtual_url_for_data_url: skip */ |
| 2676 | /* params.data_url_as_string: skip */ |
| 2677 | params.post_data = post_body; |
| 2678 | params.can_load_local_resources = false; |
Kevin McNee | e60e76b | 2019-11-27 20:01:58 | [diff] [blame] | 2679 | /* params.should_replace_current_entry: skip */ |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 2680 | /* params.frame_name: skip */ |
| 2681 | // TODO(clamy): See if user gesture should be propagated to this function. |
| 2682 | params.has_user_gesture = false; |
| 2683 | params.should_clear_history_list = false; |
| 2684 | params.started_from_context_menu = false; |
| 2685 | /* params.navigation_ui_data: skip */ |
| 2686 | /* params.input_start: skip */ |
Minggang Wang | f59db47b | 2021-06-16 01:56:22 | [diff] [blame] | 2687 | params.was_activated = blink::mojom::WasActivatedOption::kUnknown; |
Robert Ogden | 011a808 | 2019-01-23 19:04:54 | [diff] [blame] | 2688 | /* params.reload_type: skip */ |
John Delaney | 50425f8 | 2020-04-07 16:26:21 | [diff] [blame] | 2689 | params.impression = impression; |
Antonio Sartori | 6984c74 | 2021-08-26 08:03:41 | [diff] [blame] | 2690 | params.download_policy = std::move(download_policy); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 2691 | |
| 2692 | std::unique_ptr<NavigationRequest> request = |
| 2693 | CreateNavigationRequestFromLoadParams( |
Dominic Farolino | 226226af | 2019-06-25 00:58:03 | [diff] [blame] | 2694 | node, params, override_user_agent, should_replace_current_entry, |
Antonio Sartori | 2f763d9d | 2021-04-21 10:04:14 | [diff] [blame] | 2695 | false /* has_user_gesture */, std::move(source_location), |
Antonio Sartori | 6984c74 | 2021-08-26 08:03:41 | [diff] [blame] | 2696 | ReloadType::NONE, entry.get(), frame_entry.get()); |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 2697 | |
| 2698 | if (!request) |
| 2699 | return; |
| 2700 | |
Arthur Hemery | 94874276 | 2019-09-18 10:06:24 | [diff] [blame] | 2701 | // At this stage we are proceeding with this navigation. If this was renderer |
| 2702 | // initiated with user gesture, we need to make sure we clear up potential |
| 2703 | // remains of a cancelled browser initiated navigation to avoid URL spoofs. |
| 2704 | DiscardNonCommittedEntries(); |
| 2705 | |
Lukasz Anforowicz | 9ee83c27 | 2020-12-01 20:14:05 | [diff] [blame] | 2706 | node->navigator().Navigate(std::move(request), ReloadType::NONE); |
clamy | 987a375 | 2018-05-03 17:36:26 | [diff] [blame] | 2707 | } |
| 2708 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2709 | void NavigationControllerImpl::SetSessionStorageNamespace( |
Aaron Colwell | f3b316e | 2021-03-11 20:17:05 | [diff] [blame] | 2710 | const StoragePartitionId& partition_id, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 2711 | SessionStorageNamespace* session_storage_namespace) { |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2712 | if (!session_storage_namespace) |
| 2713 | return; |
| 2714 | |
| 2715 | // We can't overwrite an existing SessionStorage without violating spec. |
| 2716 | // Attempts to do so may give a tab access to another tab's session storage |
| 2717 | // so die hard on an error. |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 2718 | bool successful_insert = |
| 2719 | session_storage_namespace_map_ |
Aaron Colwell | f3b316e | 2021-03-11 20:17:05 | [diff] [blame] | 2720 | .insert(std::make_pair(partition_id, |
| 2721 | static_cast<SessionStorageNamespaceImpl*>( |
| 2722 | session_storage_namespace))) |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 2723 | .second; |
| 2724 | CHECK(successful_insert) << "Cannot replace existing SessionStorageNamespace"; |
Aaron Colwell | b731a0ae | 2021-03-19 19:14:47 | [diff] [blame] | 2725 | OnStoragePartitionIdAdded(partition_id); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2726 | } |
| 2727 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2728 | bool NavigationControllerImpl::IsUnmodifiedBlankTab() { |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 2729 | return IsInitialNavigation() && |
| 2730 | (!GetLastCommittedEntry() || |
| 2731 | GetLastCommittedEntry()->IsInitialEntry()) && |
Carlos Caballero | ede6f8c | 2021-01-28 11:01:50 | [diff] [blame] | 2732 | !frame_tree_.has_accessed_initial_main_document(); |
[email protected] | aa62afd | 2014-04-22 19:22:46 | [diff] [blame] | 2733 | } |
| 2734 | |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 2735 | SessionStorageNamespace* NavigationControllerImpl::GetSessionStorageNamespace( |
Aaron Colwell | 78b4bde | 2021-03-16 16:16:09 | [diff] [blame] | 2736 | const SiteInfo& site_info) { |
| 2737 | // TODO(acolwell): Remove partition_id logic once we have successfully |
| 2738 | // migrated the implementation to be a StoragePartitionConfig. At that point |
| 2739 | // |site_info| can be replaced with a StoragePartitionConfig. |
| 2740 | const StoragePartitionId partition_id = |
| 2741 | site_info.GetStoragePartitionId(browser_context_); |
| 2742 | const StoragePartitionConfig partition_config = |
Robbie McElrath | 7d4bd85 | 2021-07-24 04:02:19 | [diff] [blame] | 2743 | site_info.storage_partition_config(); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2744 | |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 2745 | StoragePartition* partition = |
Lukasz Anforowicz | b9a969a | 2021-04-29 15:26:25 | [diff] [blame] | 2746 | browser_context_->GetStoragePartition(partition_config); |
michaeln | bacbcbd | 2016-02-09 00:32:03 | [diff] [blame] | 2747 | DOMStorageContextWrapper* context_wrapper = |
| 2748 | static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext()); |
| 2749 | |
| 2750 | SessionStorageNamespaceMap::const_iterator it = |
| 2751 | session_storage_namespace_map_.find(partition_id); |
| 2752 | if (it != session_storage_namespace_map_.end()) { |
| 2753 | // Ensure that this namespace actually belongs to this partition. |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 2754 | DCHECK(static_cast<SessionStorageNamespaceImpl*>(it->second.get()) |
| 2755 | ->IsFromContext(context_wrapper)); |
Aaron Colwell | b731a0ae | 2021-03-19 19:14:47 | [diff] [blame] | 2756 | |
| 2757 | // Verify that the config we generated now matches the one that |
| 2758 | // was generated when the namespace was added to the map. |
Aaron Colwell | b731a0ae | 2021-03-19 19:14:47 | [diff] [blame] | 2759 | if (partition_config != it->first.config()) { |
| 2760 | LogStoragePartitionIdCrashKeys(it->first, partition_id); |
| 2761 | } |
Sharon Yang | d4f4879 | 2021-06-30 17:02:53 | [diff] [blame] | 2762 | CHECK_EQ(partition_config, it->first.config()); |
Aaron Colwell | b731a0ae | 2021-03-19 19:14:47 | [diff] [blame] | 2763 | |
michaeln | bacbcbd | 2016-02-09 00:32:03 | [diff] [blame] | 2764 | return it->second.get(); |
| 2765 | } |
| 2766 | |
| 2767 | // Create one if no one has accessed session storage for this partition yet. |
Daniel Murphy | 31bbb8b1 | 2018-02-07 21:44:10 | [diff] [blame] | 2768 | scoped_refptr<SessionStorageNamespaceImpl> session_storage_namespace = |
| 2769 | SessionStorageNamespaceImpl::Create(context_wrapper); |
| 2770 | SessionStorageNamespaceImpl* session_storage_namespace_ptr = |
| 2771 | session_storage_namespace.get(); |
| 2772 | session_storage_namespace_map_[partition_id] = |
| 2773 | std::move(session_storage_namespace); |
Aaron Colwell | b731a0ae | 2021-03-19 19:14:47 | [diff] [blame] | 2774 | OnStoragePartitionIdAdded(partition_id); |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 2775 | |
Daniel Murphy | 31bbb8b1 | 2018-02-07 21:44:10 | [diff] [blame] | 2776 | return session_storage_namespace_ptr; |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | SessionStorageNamespace* |
| 2780 | NavigationControllerImpl::GetDefaultSessionStorageNamespace() { |
Robbie McElrath | 7d4bd85 | 2021-07-24 04:02:19 | [diff] [blame] | 2781 | return GetSessionStorageNamespace(SiteInfo(GetBrowserContext())); |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 2782 | } |
| 2783 | |
| 2784 | const SessionStorageNamespaceMap& |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2785 | NavigationControllerImpl::GetSessionStorageNamespaceMap() { |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 2786 | return session_storage_namespace_map_; |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 2787 | } |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 2788 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2789 | bool NavigationControllerImpl::NeedsReload() { |
[email protected] | 71fde35 | 2011-12-29 03:29:56 | [diff] [blame] | 2790 | return needs_reload_; |
| 2791 | } |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 2792 | |
[email protected] | 46bb5e9c | 2013-10-03 22:16:47 | [diff] [blame] | 2793 | void NavigationControllerImpl::SetNeedsReload() { |
Alex Moshchuk | 7b4f065 | 2019-05-30 18:54:41 | [diff] [blame] | 2794 | SetNeedsReload(NeedsReloadType::kRequestedByClient); |
| 2795 | } |
| 2796 | |
| 2797 | void NavigationControllerImpl::SetNeedsReload(NeedsReloadType type) { |
[email protected] | 46bb5e9c | 2013-10-03 22:16:47 | [diff] [blame] | 2798 | needs_reload_ = true; |
Alex Moshchuk | 7b4f065 | 2019-05-30 18:54:41 | [diff] [blame] | 2799 | needs_reload_type_ = type; |
jaekyun | c8cefa8 | 2015-01-09 20:14:54 | [diff] [blame] | 2800 | |
| 2801 | if (last_committed_entry_index_ != -1) { |
| 2802 | entries_[last_committed_entry_index_]->SetTransitionType( |
| 2803 | ui::PAGE_TRANSITION_RELOAD); |
| 2804 | } |
[email protected] | 46bb5e9c | 2013-10-03 22:16:47 | [diff] [blame] | 2805 | } |
| 2806 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 2807 | void NavigationControllerImpl::RemoveEntryAtIndexInternal(int index) { |
Kevin McNee | 0516477 | 2019-09-03 17:24:57 | [diff] [blame] | 2808 | DCHECK_LT(index, GetEntryCount()); |
| 2809 | DCHECK_NE(index, last_committed_entry_index_); |
[email protected] | 4303234 | 2011-03-21 14:10:31 | [diff] [blame] | 2810 | DiscardNonCommittedEntries(); |
| 2811 | |
| 2812 | entries_.erase(entries_.begin() + index); |
[email protected] | 6a13a6c | 2011-12-20 21:47:12 | [diff] [blame] | 2813 | if (last_committed_entry_index_ > index) |
[email protected] | 4303234 | 2011-03-21 14:10:31 | [diff] [blame] | 2814 | last_committed_entry_index_--; |
| 2815 | } |
| 2816 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2817 | NavigationEntryImpl* NavigationControllerImpl::GetPendingEntry() { |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 2818 | // If there is no pending_entry_, there should be no pending_entry_index_. |
| 2819 | DCHECK(pending_entry_ || pending_entry_index_ == -1); |
| 2820 | |
| 2821 | // 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] | 2822 | // at that index. An exception is while a reload of a post commit error page |
| 2823 | // is ongoing; in that case pending entry will point to the entry replaced |
| 2824 | // by the error. |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 2825 | DCHECK(pending_entry_index_ == -1 || |
Carlos IL | 42b41659 | 2019-10-07 23:10:36 | [diff] [blame] | 2826 | pending_entry_ == GetEntryAtIndex(pending_entry_index_) || |
| 2827 | pending_entry_ == entry_replaced_by_post_commit_error_.get()); |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 2828 | |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 2829 | return pending_entry_; |
| 2830 | } |
| 2831 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2832 | int NavigationControllerImpl::GetPendingEntryIndex() { |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 2833 | // 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^] | 2834 | // If there are no entries, it must be exactly -1. |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 2835 | DCHECK_LT(pending_entry_index_, GetEntryCount()); |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 2836 | DCHECK(GetEntryCount() != 0 || pending_entry_index_ == -1); |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 2837 | return pending_entry_index_; |
| 2838 | } |
| 2839 | |
avi | 2576470 | 2015-06-23 15:43:37 | [diff] [blame] | 2840 | void NavigationControllerImpl::InsertOrReplaceEntry( |
dcheng | 9bfa516 | 2016-04-09 01:00:57 | [diff] [blame] | 2841 | std::unique_ptr<NavigationEntryImpl> entry, |
Carlos IL | 42b41659 | 2019-10-07 23:10:36 | [diff] [blame] | 2842 | bool replace, |
Dave Tapuska | 87696ae | 2021-11-18 18:48:31 | [diff] [blame] | 2843 | bool was_post_commit_error, |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 2844 | bool in_fenced_frame_tree, |
| 2845 | LoadCommittedDetails* commit_details) { |
Dave Tapuska | 87696ae | 2021-11-18 18:48:31 | [diff] [blame] | 2846 | // Fenced frame trees should always have `ui::PAGE_TRANSITION_AUTO_SUBFRAME` |
| 2847 | // set because: |
| 2848 | // 1) They don't influence the history of the outer page. |
| 2849 | // 2) They are always replace only navigation (there is always only one entry |
| 2850 | // in their history stack). |
| 2851 | // 3) Are not top level navigations and appear similar to iframes. |
| 2852 | // Navigations of the fenced frame might create a new NavigationEntry, which |
| 2853 | // will call this function. Non fenced frame navigations will never have |
| 2854 | // `ui::PAGE_TRANSITION_AUTO_SUBFRAME` because they won't call |
| 2855 | // InsertOrReplaceEntry. |
| 2856 | DCHECK_EQ(in_fenced_frame_tree, |
| 2857 | ui::PageTransitionCoreTypeIs(entry->GetTransitionType(), |
| 2858 | ui::PAGE_TRANSITION_AUTO_SUBFRAME)); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 2859 | |
avi | 5cad491 | 2015-06-19 05:25:44 | [diff] [blame] | 2860 | // If the pending_entry_index_ is -1, the navigation was to a new page, and we |
| 2861 | // need to keep continuity with the pending entry, so copy the pending entry's |
| 2862 | // unique ID to the committed entry. If the pending_entry_index_ isn't -1, |
| 2863 | // then the renderer navigated on its own, independent of the pending entry, |
| 2864 | // so don't copy anything. |
| 2865 | if (pending_entry_ && pending_entry_index_ == -1) |
| 2866 | entry->set_unique_id(pending_entry_->GetUniqueID()); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 2867 | |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 2868 | DiscardNonCommittedEntriesWithCommitDetails(commit_details); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 2869 | |
creis | ee17e93 | 2015-07-17 17:56:22 | [diff] [blame] | 2870 | // When replacing, don't prune the forward history. |
Carlos IL | 42b41659 | 2019-10-07 23:10:36 | [diff] [blame] | 2871 | if ((replace || was_post_commit_error) && entries_.size() > 0) { |
Mikel Astiz | ba9cf2fd | 2017-12-17 10:38:10 | [diff] [blame] | 2872 | CopyReplacedNavigationEntryDataIfPreviouslyEmpty( |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2873 | entries_[last_committed_entry_index_].get(), entry.get()); |
Carlos IL | 42b41659 | 2019-10-07 23:10:36 | [diff] [blame] | 2874 | // If the new entry is a post-commit error page, we store the current last |
| 2875 | // committed entry to the side so that we can put it back when navigating |
| 2876 | // away from the error. |
| 2877 | if (was_post_commit_error) { |
| 2878 | DCHECK(!entry_replaced_by_post_commit_error_); |
| 2879 | entry_replaced_by_post_commit_error_ = |
| 2880 | std::move(entries_[last_committed_entry_index_]); |
| 2881 | } |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame] | 2882 | entries_[last_committed_entry_index_] = std::move(entry); |
creis | ee17e93 | 2015-07-17 17:56:22 | [diff] [blame] | 2883 | return; |
| 2884 | } |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 2885 | |
creis | 37979a6 | 2015-08-04 19:48:18 | [diff] [blame] | 2886 | // We shouldn't see replace == true when there's no committed entries. |
| 2887 | DCHECK(!replace); |
| 2888 | |
Michael Thiessen | 9b14d51 | 2019-09-23 21:19:47 | [diff] [blame] | 2889 | PruneForwardEntries(); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 2890 | |
Shivani Sharma | d8c8d65 | 2019-02-13 17:27:57 | [diff] [blame] | 2891 | PruneOldestSkippableEntryIfFull(); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 2892 | |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame] | 2893 | entries_.push_back(std::move(entry)); |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 2894 | last_committed_entry_index_ = static_cast<int>(entries_.size()) - 1; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 2895 | } |
| 2896 | |
Shivani Sharma | d8c8d65 | 2019-02-13 17:27:57 | [diff] [blame] | 2897 | void NavigationControllerImpl::PruneOldestSkippableEntryIfFull() { |
Shivani Sharma | 2d5b4b6b | 2019-01-08 16:07:16 | [diff] [blame] | 2898 | if (entries_.size() < max_entry_count()) |
| 2899 | return; |
| 2900 | |
| 2901 | DCHECK_EQ(max_entry_count(), entries_.size()); |
| 2902 | DCHECK_GT(last_committed_entry_index_, 0); |
Shivani Sharma | d8c8d65 | 2019-02-13 17:27:57 | [diff] [blame] | 2903 | CHECK_EQ(pending_entry_index_, -1); |
| 2904 | |
| 2905 | int index = 0; |
Elly Fong-Jones | ccc6d1f | 2021-06-14 18:32:42 | [diff] [blame] | 2906 | // Retrieve the oldest skippable entry. |
| 2907 | for (; index < GetEntryCount(); index++) { |
| 2908 | if (GetEntryAtIndex(index)->should_skip_on_back_forward_ui()) |
| 2909 | break; |
Shivani Sharma | d8c8d65 | 2019-02-13 17:27:57 | [diff] [blame] | 2910 | } |
| 2911 | |
| 2912 | // If there is no skippable entry or if it is the last committed entry then |
| 2913 | // fall back to pruning the oldest entry. It is not safe to prune the last |
| 2914 | // committed entry. |
| 2915 | if (index == GetEntryCount() || index == last_committed_entry_index_) |
| 2916 | index = 0; |
| 2917 | |
| 2918 | bool should_succeed = RemoveEntryAtIndex(index); |
| 2919 | DCHECK_EQ(true, should_succeed); |
| 2920 | |
| 2921 | NotifyPrunedEntries(this, index, 1); |
[email protected] | 944822b | 2012-03-02 20:57:25 | [diff] [blame] | 2922 | } |
| 2923 | |
clamy | 3cb9bea9 | 2018-07-10 12:42:02 | [diff] [blame] | 2924 | void NavigationControllerImpl::NavigateToExistingPendingEntry( |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 2925 | ReloadType reload_type, |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 2926 | int sandboxed_source_frame_tree_node_id, |
| 2927 | bool is_browser_initiated) { |
Alexander Timin | 3a92df7 | 2019-09-20 11:59:50 | [diff] [blame] | 2928 | TRACE_EVENT0("navigation", |
| 2929 | "NavigationControllerImpl::NavigateToExistingPendingEntry"); |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 2930 | DCHECK(pending_entry_); |
clamy | 3cb9bea9 | 2018-07-10 12:42:02 | [diff] [blame] | 2931 | DCHECK(IsInitialNavigation() || pending_entry_index_ != -1); |
Carlos IL | 42b41659 | 2019-10-07 23:10:36 | [diff] [blame] | 2932 | if (pending_entry_index_ != -1) { |
| 2933 | // The pending entry may not be in entries_ if a post-commit error page is |
| 2934 | // showing. |
| 2935 | DCHECK(pending_entry_ == entries_[pending_entry_index_].get() || |
| 2936 | pending_entry_ == entry_replaced_by_post_commit_error_.get()); |
| 2937 | } |
Gyuyoung Kim | 107c2a0 | 2021-04-13 01:49:30 | [diff] [blame] | 2938 | DCHECK(!blink::IsRendererDebugURL(pending_entry_->GetURL())); |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 2939 | bool is_forced_reload = needs_reload_; |
[email protected] | 72097fd0 | 2010-01-21 23:36:01 | [diff] [blame] | 2940 | needs_reload_ = false; |
Carlos Caballero | 40b0efd | 2021-01-26 11:55:00 | [diff] [blame] | 2941 | FrameTreeNode* root = frame_tree_.root(); |
Arthur Sonzogni | 620cec6 | 2018-12-13 13:08:57 | [diff] [blame] | 2942 | int nav_entry_id = pending_entry_->GetUniqueID(); |
| 2943 | |
[email protected] | 83c2e23 | 2011-10-07 21:36:46 | [diff] [blame] | 2944 | // If we were navigating to a slow-to-commit page, and the user performs |
| 2945 | // a session history navigation to the last committed page, RenderViewHost |
| 2946 | // will force the throbber to start, but WebKit will essentially ignore the |
| 2947 | // navigation, and won't send a message to stop the throbber. To prevent this |
| 2948 | // from happening, we drop the navigation here and stop the slow-to-commit |
| 2949 | // page from loading (which would normally happen during the navigation). |
clamy | 3cb9bea9 | 2018-07-10 12:42:02 | [diff] [blame] | 2950 | if (pending_entry_index_ == last_committed_entry_index_ && |
Lukasz Anforowicz | 6b75c0d | 2020-12-01 22:56:08 | [diff] [blame] | 2951 | !pending_entry_->IsRestored() && |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 2952 | pending_entry_->GetTransitionType() & ui::PAGE_TRANSITION_FORWARD_BACK) { |
Takashi Toyoshima | bf54947 | 2021-07-01 07:47:20 | [diff] [blame] | 2953 | frame_tree_.StopLoading(); |
[email protected] | 6a13a6c | 2011-12-20 21:47:12 | [diff] [blame] | 2954 | |
[email protected] | 83c2e23 | 2011-10-07 21:36:46 | [diff] [blame] | 2955 | DiscardNonCommittedEntries(); |
| 2956 | return; |
| 2957 | } |
| 2958 | |
creis | ce0ef357 | 2017-01-26 17:53:08 | [diff] [blame] | 2959 | // Compare FrameNavigationEntries to see which frames in the tree need to be |
| 2960 | // navigated. |
clamy | 3cb9bea9 | 2018-07-10 12:42:02 | [diff] [blame] | 2961 | std::vector<std::unique_ptr<NavigationRequest>> same_document_loads; |
| 2962 | std::vector<std::unique_ptr<NavigationRequest>> different_document_loads; |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 2963 | FindFramesToNavigate(root, reload_type, is_browser_initiated, |
| 2964 | &same_document_loads, &different_document_loads); |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 2965 | |
| 2966 | if (same_document_loads.empty() && different_document_loads.empty()) { |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 2967 | // We were unable to match any frames to navigate. This can happen if a |
| 2968 | // history navigation targets a subframe that no longer exists |
| 2969 | // (https://crbug.com/705550). In this case, we need to update the current |
| 2970 | // history entry to the pending one but keep the main document loaded. We |
| 2971 | // also need to ensure that observers are informed about the updated |
| 2972 | // current history entry (e.g., for greying out back/forward buttons), and |
| 2973 | // that renderer processes update their history offsets. The easiest way |
| 2974 | // to do all that is to schedule a "redundant" same-document navigation in |
| 2975 | // the main frame. |
| 2976 | // |
| 2977 | // Note that we don't want to remove this history entry, as it might still |
| 2978 | // be valid later, since a frame that it's targeting may be recreated. |
| 2979 | // |
| 2980 | // TODO(alexmos, creis): This behavior isn't ideal, as the user would |
| 2981 | // need to repeat history navigations until finding the one that works. |
| 2982 | // Consider changing this behavior to keep looking for the first valid |
| 2983 | // history entry that finds frames to navigate. |
clamy | 3cb9bea9 | 2018-07-10 12:42:02 | [diff] [blame] | 2984 | std::unique_ptr<NavigationRequest> navigation_request = |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 2985 | CreateNavigationRequestFromEntry( |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 2986 | root, pending_entry_, pending_entry_->GetFrameEntry(root), |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 2987 | ReloadType::NONE /* reload_type */, |
| 2988 | true /* is_same_document_history_load */, |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 2989 | false /* is_history_navigation_in_new_child */, |
| 2990 | is_browser_initiated); |
clamy | 3cb9bea9 | 2018-07-10 12:42:02 | [diff] [blame] | 2991 | if (!navigation_request) { |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 2992 | // If this navigation cannot start, delete the pending NavigationEntry. |
clamy | 3cb9bea9 | 2018-07-10 12:42:02 | [diff] [blame] | 2993 | DiscardPendingEntry(false); |
| 2994 | return; |
| 2995 | } |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 2996 | same_document_loads.push_back(std::move(navigation_request)); |
| 2997 | |
| 2998 | // Sanity check that we never take this branch for any kinds of reloads, |
| 2999 | // as those should've queued a different-document load in the main frame. |
| 3000 | DCHECK(!is_forced_reload); |
| 3001 | DCHECK_EQ(reload_type, ReloadType::NONE); |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 3002 | } |
| 3003 | |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 3004 | // If |sandboxed_source_frame_node_id| is valid, then track whether this |
| 3005 | // navigation affects any frame outside the frame's subtree. |
| 3006 | if (sandboxed_source_frame_tree_node_id != |
| 3007 | FrameTreeNode::kFrameTreeNodeInvalidId) { |
| 3008 | bool navigates_inside_tree = |
| 3009 | DoesSandboxNavigationStayWithinSubtree( |
| 3010 | sandboxed_source_frame_tree_node_id, same_document_loads) && |
| 3011 | DoesSandboxNavigationStayWithinSubtree( |
| 3012 | sandboxed_source_frame_tree_node_id, different_document_loads); |
Dave Tapuska | 716ed3af | 2019-09-23 18:45:50 | [diff] [blame] | 3013 | // Count the navigations as web use counters so we can determine |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 3014 | // the number of pages that trigger this. |
| 3015 | FrameTreeNode* sandbox_source_frame_tree_node = |
| 3016 | FrameTreeNode::GloballyFindByID(sandboxed_source_frame_tree_node_id); |
| 3017 | if (sandbox_source_frame_tree_node) { |
| 3018 | GetContentClient()->browser()->LogWebFeatureForCurrentPage( |
| 3019 | sandbox_source_frame_tree_node->current_frame_host(), |
| 3020 | navigates_inside_tree |
| 3021 | ? blink::mojom::WebFeature::kSandboxBackForwardStaysWithinSubtree |
| 3022 | : blink::mojom::WebFeature:: |
| 3023 | kSandboxBackForwardAffectsFramesOutsideSubtree); |
| 3024 | } |
Dave Tapuska | 855c1e1 | 2019-08-23 20:45:52 | [diff] [blame] | 3025 | |
| 3026 | // If the navigation occurred outside the tree discard it because |
| 3027 | // the sandboxed frame didn't have permission to navigate outside |
| 3028 | // its tree. If it is possible that the navigation is both inside and |
| 3029 | // outside the frame tree and we discard it entirely because we don't |
| 3030 | // want to end up in a history state that didn't exist before. |
Dominic Farolino | 05744004 | 2022-01-19 18:18:14 | [diff] [blame] | 3031 | if (!navigates_inside_tree) { |
Dave Tapuska | 855c1e1 | 2019-08-23 20:45:52 | [diff] [blame] | 3032 | DiscardPendingEntry(false); |
| 3033 | return; |
| 3034 | } |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 3035 | } |
| 3036 | |
Carlos Caballero | 539a421c | 2020-07-06 10:25:57 | [diff] [blame] | 3037 | // BackForwardCache: |
| 3038 | // Navigate immediately if the document is in the BackForwardCache. |
| 3039 | if (back_forward_cache_.GetEntry(nav_entry_id)) { |
| 3040 | TRACE_EVENT0("navigation", "BackForwardCache_CreateNavigationRequest"); |
| 3041 | DCHECK_EQ(reload_type, ReloadType::NONE); |
| 3042 | auto navigation_request = CreateNavigationRequestFromEntry( |
| 3043 | root, pending_entry_, pending_entry_->GetFrameEntry(root), |
| 3044 | ReloadType::NONE, false /* is_same_document_history_load */, |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 3045 | false /* is_history_navigation_in_new_child */, is_browser_initiated); |
Lukasz Anforowicz | 9ee83c27 | 2020-12-01 20:14:05 | [diff] [blame] | 3046 | root->navigator().Navigate(std::move(navigation_request), ReloadType::NONE); |
Carlos Caballero | 539a421c | 2020-07-06 10:25:57 | [diff] [blame] | 3047 | |
| 3048 | return; |
| 3049 | } |
| 3050 | |
| 3051 | // History navigation might try to reuse a specific BrowsingInstance, already |
| 3052 | // used by a page in the cache. To avoid having two different main frames that |
| 3053 | // live in the same BrowsingInstance, evict the all pages with this |
| 3054 | // BrowsingInstance from the cache. |
| 3055 | // |
| 3056 | // For example, take the following scenario: |
| 3057 | // |
| 3058 | // A1 = Some page on a.com |
| 3059 | // A2 = Some other page on a.com |
| 3060 | // B3 = An uncacheable page on b.com |
| 3061 | // |
| 3062 | // Then the following navigations occur: |
| 3063 | // A1->A2->B3->A1 |
| 3064 | // On the navigation from B3 to A1, A2 will remain in the cache (B3 doesn't |
| 3065 | // take its place) and A1 will be created in the same BrowsingInstance (and |
| 3066 | // SiteInstance), as A2. |
| 3067 | // |
| 3068 | // If we didn't do anything, both A1 and A2 would remain alive in the same |
| 3069 | // BrowsingInstance/SiteInstance, which is unsupported by |
| 3070 | // RenderFrameHostManager::CommitPending(). To avoid this conundrum, we evict |
| 3071 | // A2 from the cache. |
| 3072 | if (pending_entry_->site_instance()) { |
| 3073 | back_forward_cache_.EvictFramesInRelatedSiteInstances( |
| 3074 | pending_entry_->site_instance()); |
| 3075 | } |
| 3076 | |
clamy | 3cb9bea9 | 2018-07-10 12:42:02 | [diff] [blame] | 3077 | // This call does not support re-entrancy. See http://crbug.com/347742. |
| 3078 | CHECK(!in_navigate_to_pending_entry_); |
| 3079 | in_navigate_to_pending_entry_ = true; |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 3080 | |
arthursonzogni | 66f711c | 2019-10-08 14:40:36 | [diff] [blame] | 3081 | // It is not possible to delete the pending NavigationEntry while navigating |
| 3082 | // to it. Grab a reference to delay potential deletion until the end of this |
| 3083 | // function. |
| 3084 | std::unique_ptr<PendingEntryRef> pending_entry_ref = ReferencePendingEntry(); |
| 3085 | |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 3086 | // Send all the same document frame loads before the different document loads. |
clamy | 3cb9bea9 | 2018-07-10 12:42:02 | [diff] [blame] | 3087 | for (auto& item : same_document_loads) { |
| 3088 | FrameTreeNode* frame = item->frame_tree_node(); |
Lukasz Anforowicz | 9ee83c27 | 2020-12-01 20:14:05 | [diff] [blame] | 3089 | frame->navigator().Navigate(std::move(item), reload_type); |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 3090 | } |
clamy | 3cb9bea9 | 2018-07-10 12:42:02 | [diff] [blame] | 3091 | for (auto& item : different_document_loads) { |
| 3092 | FrameTreeNode* frame = item->frame_tree_node(); |
Lukasz Anforowicz | 9ee83c27 | 2020-12-01 20:14:05 | [diff] [blame] | 3093 | frame->navigator().Navigate(std::move(item), reload_type); |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 3094 | } |
clamy | 3cb9bea9 | 2018-07-10 12:42:02 | [diff] [blame] | 3095 | |
| 3096 | in_navigate_to_pending_entry_ = false; |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 3097 | } |
| 3098 | |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3099 | NavigationControllerImpl::HistoryNavigationAction |
| 3100 | NavigationControllerImpl::DetermineActionForHistoryNavigation( |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 3101 | FrameTreeNode* frame, |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3102 | ReloadType reload_type) { |
Sreeja Kamishetty | 8eacabb | 2021-03-09 11:45:42 | [diff] [blame] | 3103 | RenderFrameHostImpl* render_frame_host = frame->current_frame_host(); |
Sreeja Kamishetty | db8e289 | 2021-03-10 09:30:58 | [diff] [blame] | 3104 | // Only active and prerendered documents are allowed to navigate in their |
| 3105 | // frame. |
Sreeja Kamishetty | 8eacabb | 2021-03-09 11:45:42 | [diff] [blame] | 3106 | if (render_frame_host->lifecycle_state() != |
Sreeja Kamishetty | 299329ad | 2021-03-25 14:06:01 | [diff] [blame] | 3107 | RenderFrameHostImpl::LifecycleStateImpl::kPrerendering) { |
Sreeja Kamishetty | db8e289 | 2021-03-10 09:30:58 | [diff] [blame] | 3108 | // - If the document is in pending deletion, the browser already committed |
| 3109 | // to destroying this RenderFrameHost. See https://crbug.com/930278. |
| 3110 | // - If the document is in back-forward cache, it's not allowed to navigate |
| 3111 | // as it should remain frozen. Ignore the request and evict the document |
| 3112 | // from back-forward cache. |
Sreeja Kamishetty | 8eacabb | 2021-03-09 11:45:42 | [diff] [blame] | 3113 | // |
Sreeja Kamishetty | db8e289 | 2021-03-10 09:30:58 | [diff] [blame] | 3114 | // If the document is inactive, there's no need to recurse into subframes, |
Sreeja Kamishetty | 8eacabb | 2021-03-09 11:45:42 | [diff] [blame] | 3115 | // which should all be inactive as well. |
Fergal Daly | 1336ac64 | 2021-09-14 15:13:11 | [diff] [blame] | 3116 | if (frame->current_frame_host()->IsInactiveAndDisallowActivation( |
| 3117 | DisallowActivationReasonId::kDetermineActionForHistoryNavigation)) { |
Sreeja Kamishetty | 8eacabb | 2021-03-09 11:45:42 | [diff] [blame] | 3118 | return HistoryNavigationAction::kStopLooking; |
Fergal Daly | 1336ac64 | 2021-09-14 15:13:11 | [diff] [blame] | 3119 | } |
Sreeja Kamishetty | 8eacabb | 2021-03-09 11:45:42 | [diff] [blame] | 3120 | } |
arthursonzogni | 03f7615 | 2019-02-12 10:35:20 | [diff] [blame] | 3121 | |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3122 | // If there's no last committed entry, there is no previous history entry to |
| 3123 | // compare against, so fall back to a different-document load. Note that we |
| 3124 | // should only reach this case for the root frame and not descend further |
| 3125 | // into subframes. |
| 3126 | if (!GetLastCommittedEntry()) { |
| 3127 | DCHECK(frame->IsMainFrame()); |
| 3128 | return HistoryNavigationAction::kDifferentDocument; |
| 3129 | } |
| 3130 | |
| 3131 | // Reloads should result in a different-document load. Note that reloads may |
| 3132 | // also happen via the |needs_reload_| mechanism where the reload_type is |
| 3133 | // NONE, so detect this by comparing whether we're going to the same |
| 3134 | // entry that we're currently on. Similarly to above, only main frames |
| 3135 | // should reach this. Note that subframes support reloads, but that's done |
| 3136 | // via a different path that doesn't involve FindFramesToNavigate (see |
| 3137 | // RenderFrameHost::Reload()). |
| 3138 | if (reload_type != ReloadType::NONE || |
| 3139 | pending_entry_index_ == last_committed_entry_index_) { |
| 3140 | DCHECK(frame->IsMainFrame()); |
| 3141 | return HistoryNavigationAction::kDifferentDocument; |
| 3142 | } |
| 3143 | |
Alex Moshchuk | 47d1a4bd | 2020-06-01 22:15:34 | [diff] [blame] | 3144 | // If there is no new FrameNavigationEntry for the frame, ignore the |
| 3145 | // load. For example, this may happen when going back to an entry before a |
| 3146 | // frame was created. Suppose we commit a same-document navigation that also |
| 3147 | // results in adding a new subframe somewhere in the tree. If we go back, |
| 3148 | // the new subframe will be missing a FrameNavigationEntry in the previous |
| 3149 | // NavigationEntry, but we shouldn't delete or change what's loaded in |
| 3150 | // it. |
| 3151 | // |
Alex Moshchuk | e65c3927 | 2020-06-03 17:55:37 | [diff] [blame] | 3152 | // Note that in this case, there is no need to keep looking for navigations |
| 3153 | // in subframes, which would be missing FrameNavigationEntries as well. |
| 3154 | // |
Alex Moshchuk | 47d1a4bd | 2020-06-01 22:15:34 | [diff] [blame] | 3155 | // It's important to check this before checking |old_item| below, since both |
| 3156 | // might be null, and in that case we still shouldn't change what's loaded in |
| 3157 | // this frame. Note that scheduling any loads assumes that |new_item| is |
| 3158 | // non-null. See https://crbug.com/1088354. |
| 3159 | FrameNavigationEntry* new_item = pending_entry_->GetFrameEntry(frame); |
| 3160 | if (!new_item) |
Alex Moshchuk | e65c3927 | 2020-06-03 17:55:37 | [diff] [blame] | 3161 | return HistoryNavigationAction::kStopLooking; |
Alex Moshchuk | 47d1a4bd | 2020-06-01 22:15:34 | [diff] [blame] | 3162 | |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3163 | // If there is no old FrameNavigationEntry, schedule a different-document |
| 3164 | // load. |
| 3165 | // |
creis | 225a743 | 2016-06-03 22:56:27 | [diff] [blame] | 3166 | // TODO(creis): Store the last committed FrameNavigationEntry to use here, |
| 3167 | // rather than assuming the NavigationEntry has up to date info on subframes. |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 3168 | FrameNavigationEntry* old_item = |
| 3169 | GetLastCommittedEntry()->GetFrameEntry(frame); |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3170 | if (!old_item) |
| 3171 | return HistoryNavigationAction::kDifferentDocument; |
| 3172 | |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3173 | // If the new item is not in the same SiteInstance, schedule a |
| 3174 | // different-document load. Newly restored items may not have a SiteInstance |
| 3175 | // yet, in which case it will be assigned on first commit. |
| 3176 | if (new_item->site_instance() && |
| 3177 | new_item->site_instance() != old_item->site_instance()) |
| 3178 | return HistoryNavigationAction::kDifferentDocument; |
| 3179 | |
| 3180 | // Schedule a different-document load if the current RenderFrameHost is not |
danakj | 25c436d | 2021-04-01 16:35:31 | [diff] [blame] | 3181 | // live. This case can happen for Ctrl+Back or after a renderer crash. Note |
| 3182 | // that we do this even if the history navigation would not be modifying this |
| 3183 | // frame were it live. |
| 3184 | if (!frame->current_frame_host()->IsRenderFrameLive()) |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3185 | return HistoryNavigationAction::kDifferentDocument; |
| 3186 | |
| 3187 | if (new_item->item_sequence_number() != old_item->item_sequence_number()) { |
danakj | 25c436d | 2021-04-01 16:35:31 | [diff] [blame] | 3188 | // Starting a navigation after a crash early-promotes the speculative |
| 3189 | // RenderFrameHost. Then we have a RenderFrameHost with no document in it |
| 3190 | // committed yet, so we can not possibly perform a same-document history |
| 3191 | // navigation. The frame would need to be reloaded with a cross-document |
| 3192 | // navigation. |
| 3193 | if (!frame->current_frame_host()->has_committed_any_navigation()) |
| 3194 | return HistoryNavigationAction::kDifferentDocument; |
| 3195 | |
creis | 5413169 | 2016-08-12 18:32:25 | [diff] [blame] | 3196 | // Same document loads happen if the previous item has the same document |
danakj | b952ef1 | 2021-01-14 19:58:49 | [diff] [blame] | 3197 | // sequence number but different item sequence number. |
| 3198 | if (new_item->document_sequence_number() == |
| 3199 | old_item->document_sequence_number()) { |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3200 | return HistoryNavigationAction::kSameDocument; |
danakj | b952ef1 | 2021-01-14 19:58:49 | [diff] [blame] | 3201 | } |
avi | b48cb31 | 2016-05-05 21:35:00 | [diff] [blame] | 3202 | |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3203 | // Otherwise, if both item and document sequence numbers differ, this |
| 3204 | // should be a different document load. |
| 3205 | return HistoryNavigationAction::kDifferentDocument; |
| 3206 | } |
| 3207 | |
| 3208 | // If the item sequence numbers match, there is no need to navigate this |
Alex Moshchuk | e65c3927 | 2020-06-03 17:55:37 | [diff] [blame] | 3209 | // frame. Keep looking for navigations in this frame's children. |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3210 | DCHECK_EQ(new_item->document_sequence_number(), |
| 3211 | old_item->document_sequence_number()); |
Alex Moshchuk | e65c3927 | 2020-06-03 17:55:37 | [diff] [blame] | 3212 | return HistoryNavigationAction::kKeepLooking; |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3213 | } |
| 3214 | |
| 3215 | void NavigationControllerImpl::FindFramesToNavigate( |
| 3216 | FrameTreeNode* frame, |
| 3217 | ReloadType reload_type, |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 3218 | bool is_browser_initiated, |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3219 | std::vector<std::unique_ptr<NavigationRequest>>* same_document_loads, |
| 3220 | std::vector<std::unique_ptr<NavigationRequest>>* different_document_loads) { |
| 3221 | DCHECK(pending_entry_); |
| 3222 | FrameNavigationEntry* new_item = pending_entry_->GetFrameEntry(frame); |
| 3223 | |
| 3224 | auto action = DetermineActionForHistoryNavigation(frame, reload_type); |
| 3225 | |
| 3226 | if (action == HistoryNavigationAction::kSameDocument) { |
| 3227 | std::unique_ptr<NavigationRequest> navigation_request = |
| 3228 | CreateNavigationRequestFromEntry( |
| 3229 | frame, pending_entry_, new_item, reload_type, |
| 3230 | true /* is_same_document_history_load */, |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 3231 | false /* is_history_navigation_in_new_child */, |
| 3232 | is_browser_initiated); |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3233 | if (navigation_request) { |
| 3234 | // Only add the request if was properly created. It's possible for the |
| 3235 | // creation to fail in certain cases, e.g. when the URL is invalid. |
| 3236 | same_document_loads->push_back(std::move(navigation_request)); |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 3237 | } |
Alex Moshchuk | 3a4e77a | 2020-05-29 21:32:57 | [diff] [blame] | 3238 | } else if (action == HistoryNavigationAction::kDifferentDocument) { |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 3239 | std::unique_ptr<NavigationRequest> navigation_request = |
| 3240 | CreateNavigationRequestFromEntry( |
| 3241 | frame, pending_entry_, new_item, reload_type, |
| 3242 | false /* is_same_document_history_load */, |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 3243 | false /* is_history_navigation_in_new_child */, |
| 3244 | is_browser_initiated); |
Lei Zhang | 9603153 | 2019-10-10 19:05:47 | [diff] [blame] | 3245 | if (navigation_request) { |
| 3246 | // Only add the request if was properly created. It's possible for the |
| 3247 | // creation to fail in certain cases, e.g. when the URL is invalid. |
| 3248 | different_document_loads->push_back(std::move(navigation_request)); |
| 3249 | } |
| 3250 | // For a different document, the subframes will be destroyed, so there's |
| 3251 | // no need to consider them. |
| 3252 | return; |
Alex Moshchuk | e65c3927 | 2020-06-03 17:55:37 | [diff] [blame] | 3253 | } else if (action == HistoryNavigationAction::kStopLooking) { |
| 3254 | return; |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 3255 | } |
| 3256 | |
| 3257 | for (size_t i = 0; i < frame->child_count(); i++) { |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 3258 | FindFramesToNavigate(frame->child_at(i), reload_type, is_browser_initiated, |
| 3259 | same_document_loads, different_document_loads); |
creis | 4e2ecb7 | 2015-06-20 00:46:30 | [diff] [blame] | 3260 | } |
| 3261 | } |
| 3262 | |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 3263 | base::WeakPtr<NavigationHandle> NavigationControllerImpl::NavigateWithoutEntry( |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3264 | const LoadURLParams& params) { |
| 3265 | // Find the appropriate FrameTreeNode. |
| 3266 | FrameTreeNode* node = nullptr; |
| 3267 | if (params.frame_tree_node_id != RenderFrameHost::kNoFrameTreeNodeId || |
| 3268 | !params.frame_name.empty()) { |
| 3269 | node = params.frame_tree_node_id != RenderFrameHost::kNoFrameTreeNodeId |
Carlos Caballero | 40b0efd | 2021-01-26 11:55:00 | [diff] [blame] | 3270 | ? frame_tree_.FindByID(params.frame_tree_node_id) |
| 3271 | : frame_tree_.FindByName(params.frame_name); |
Hayato Ito | 7a80db4 | 2021-07-05 06:18:54 | [diff] [blame] | 3272 | DCHECK(!node || node->frame_tree() == &frame_tree_); |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3273 | } |
| 3274 | |
| 3275 | // If no FrameTreeNode was specified, navigate the main frame. |
| 3276 | if (!node) |
Carlos Caballero | 40b0efd | 2021-01-26 11:55:00 | [diff] [blame] | 3277 | node = frame_tree_.root(); |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3278 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3279 | // Compute overrides to the LoadURLParams for |override_user_agent|, |
| 3280 | // |should_replace_current_entry| and |has_user_gesture| that will be used |
| 3281 | // both in the creation of the NavigationEntry and the NavigationRequest. |
| 3282 | // Ideally, the LoadURLParams themselves would be updated, but since they are |
| 3283 | // passed as a const reference, this is not possible. |
| 3284 | // TODO(clamy): When we only create a NavigationRequest, move this to |
| 3285 | // CreateNavigationRequestFromLoadURLParams. |
| 3286 | bool override_user_agent = ShouldOverrideUserAgent(params.override_user_agent, |
| 3287 | GetLastCommittedEntry()); |
| 3288 | |
| 3289 | // Don't allow an entry replacement if there is no entry to replace. |
| 3290 | // http://crbug.com/457149 |
Hayato Ito | 7a80db4 | 2021-07-05 06:18:54 | [diff] [blame] | 3291 | // |
| 3292 | // If there is an entry, an entry replacement must happen if the current |
| 3293 | // browsing context should maintain a trivial session history. |
shivanigithub | f405bf0d | 2021-11-05 17:58:33 | [diff] [blame] | 3294 | bool should_replace_current_entry = |
| 3295 | (params.should_replace_current_entry || |
| 3296 | ShouldMaintainTrivialSessionHistory(node)) && |
| 3297 | entries_.size(); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3298 | |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3299 | // Javascript URLs should not create NavigationEntries. All other navigations |
| 3300 | // do, including navigations to chrome renderer debug URLs. |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3301 | if (!params.url.SchemeIs(url::kJavaScriptScheme)) { |
Scott Violet | 5ae6c42e | 2020-10-28 02:47:37 | [diff] [blame] | 3302 | std::unique_ptr<NavigationEntryImpl> entry = |
| 3303 | CreateNavigationEntryFromLoadParams(node, params, override_user_agent, |
| 3304 | should_replace_current_entry, |
| 3305 | params.has_user_gesture); |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3306 | DiscardPendingEntry(false); |
| 3307 | SetPendingEntry(std::move(entry)); |
| 3308 | } |
| 3309 | |
| 3310 | // Renderer-debug URLs are sent to the renderer process immediately for |
| 3311 | // processing and don't need to create a NavigationRequest. |
| 3312 | // Note: this includes navigations to JavaScript URLs, which are considered |
| 3313 | // renderer-debug URLs. |
| 3314 | // Note: we intentionally leave the pending entry in place for renderer debug |
| 3315 | // URLs, unlike the cases below where we clear it if the navigation doesn't |
| 3316 | // proceed. |
Gyuyoung Kim | 107c2a0 | 2021-04-13 01:49:30 | [diff] [blame] | 3317 | if (blink::IsRendererDebugURL(params.url)) { |
Oleg Davydov | 2cc0167b | 2019-02-05 14:32:48 | [diff] [blame] | 3318 | // Renderer-debug URLs won't go through NavigationThrottlers so we have to |
| 3319 | // check them explicitly. See bug 913334. |
Aaron Colwell | e1908d98 | 2020-06-26 22:08:15 | [diff] [blame] | 3320 | if (GetContentClient()->browser()->ShouldBlockRendererDebugURL( |
Oleg Davydov | 2cc0167b | 2019-02-05 14:32:48 | [diff] [blame] | 3321 | params.url, browser_context_)) { |
| 3322 | DiscardPendingEntry(false); |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 3323 | return nullptr; |
Oleg Davydov | 2cc0167b | 2019-02-05 14:32:48 | [diff] [blame] | 3324 | } |
| 3325 | |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3326 | HandleRendererDebugURL(node, params.url); |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 3327 | return nullptr; |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3328 | } |
| 3329 | |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 3330 | DCHECK(pending_entry_); |
| 3331 | |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3332 | // Convert navigations to the current URL to a reload. |
| 3333 | // TODO(clamy): We should be using FrameTreeNode::IsMainFrame here instead of |
| 3334 | // relying on the frame tree node id from LoadURLParams. Unfortunately, |
| 3335 | // DevTools sometimes issues navigations to main frames that they do not |
| 3336 | // expect to see treated as reload, and it only works because they pass a |
| 3337 | // FrameTreeNode id in their LoadURLParams. Change this once they no longer do |
| 3338 | // that. See https://crbug.com/850926. |
Robert Ogden | 011a808 | 2019-01-23 19:04:54 | [diff] [blame] | 3339 | ReloadType reload_type = params.reload_type; |
| 3340 | if (reload_type == ReloadType::NONE && |
| 3341 | ShouldTreatNavigationAsReload( |
Fergal Daly | 766177d | 2020-07-07 07:54:04 | [diff] [blame] | 3342 | node, params.url, pending_entry_->GetVirtualURL(), |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3343 | params.base_url_for_data_url, params.transition_type, |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3344 | params.load_type == |
| 3345 | NavigationController::LOAD_TYPE_HTTP_POST /* is_post */, |
Hayato Ito | 7a80db4 | 2021-07-05 06:18:54 | [diff] [blame] | 3346 | should_replace_current_entry, GetLastCommittedEntry())) { |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3347 | reload_type = ReloadType::NORMAL; |
Alexander Timin | b70f6738 | 2020-12-10 00:03:47 | [diff] [blame] | 3348 | pending_entry_->set_reload_type(reload_type); |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 3349 | |
| 3350 | // If this is a reload of an existing FrameNavigationEntry and we had a |
| 3351 | // policy container for it, then we should copy it into the pending entry, |
| 3352 | // so that it is copied to the navigation request in |
| 3353 | // CreateNavigationRequestFromLoadParams later. |
| 3354 | if (GetLastCommittedEntry()) { |
| 3355 | FrameNavigationEntry* previous_frame_entry = |
| 3356 | GetLastCommittedEntry()->GetFrameEntry(node); |
Titouan Rigoudy | 6ec7040 | 2021-02-02 15:42:19 | [diff] [blame] | 3357 | if (previous_frame_entry && |
| 3358 | previous_frame_entry->policy_container_policies()) { |
| 3359 | pending_entry_->GetFrameEntry(node)->set_policy_container_policies( |
Antonio Sartori | 5d09b30f | 2021-03-02 09:27:16 | [diff] [blame] | 3360 | previous_frame_entry->policy_container_policies()->Clone()); |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 3361 | } |
| 3362 | } |
| 3363 | } |
| 3364 | |
| 3365 | // 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] | 3366 | // document, then we should copy the document polices from RenderFrameHost's |
| 3367 | // PolicyContainerHost. The NavigationRequest will create a new |
| 3368 | // PolicyContainerHost with the document policies from the |pending_entry_|, |
| 3369 | // and that PolicyContainerHost will be put in the final RenderFrameHost for |
| 3370 | // the navigation. This way, we ensure that we keep enforcing the right |
| 3371 | // policies on the initial empty document after the reload. |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 3372 | if ((!GetLastCommittedEntry() || GetLastCommittedEntry()->IsInitialEntry()) && |
| 3373 | params.url.IsAboutBlank()) { |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 3374 | if (node->current_frame_host() && |
| 3375 | node->current_frame_host()->policy_container_host()) { |
Titouan Rigoudy | 6ec7040 | 2021-02-02 15:42:19 | [diff] [blame] | 3376 | pending_entry_->GetFrameEntry(node)->set_policy_container_policies( |
Antonio Sartori | 5d09b30f | 2021-03-02 09:27:16 | [diff] [blame] | 3377 | node->current_frame_host() |
| 3378 | ->policy_container_host() |
| 3379 | ->policies() |
| 3380 | .Clone()); |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 3381 | } |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3382 | } |
| 3383 | |
| 3384 | // navigation_ui_data should only be present for main frame navigations. |
| 3385 | DCHECK(node->IsMainFrame() || !params.navigation_ui_data); |
| 3386 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3387 | std::unique_ptr<NavigationRequest> request = |
| 3388 | CreateNavigationRequestFromLoadParams( |
| 3389 | node, params, override_user_agent, should_replace_current_entry, |
Antonio Sartori | 2f763d9d | 2021-04-21 10:04:14 | [diff] [blame] | 3390 | params.has_user_gesture, network::mojom::SourceLocation::New(), |
Antonio Sartori | 6984c74 | 2021-08-26 08:03:41 | [diff] [blame] | 3391 | reload_type, pending_entry_, pending_entry_->GetFrameEntry(node)); |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3392 | |
| 3393 | // If the navigation couldn't start, return immediately and discard the |
| 3394 | // pending NavigationEntry. |
| 3395 | if (!request) { |
| 3396 | DiscardPendingEntry(false); |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 3397 | return nullptr; |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3398 | } |
| 3399 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3400 | #if DCHECK_IS_ON() |
| 3401 | // Safety check that NavigationRequest and NavigationEntry match. |
| 3402 | ValidateRequestMatchesEntry(request.get(), pending_entry_); |
| 3403 | #endif |
| 3404 | |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3405 | // This call does not support re-entrancy. See http://crbug.com/347742. |
| 3406 | CHECK(!in_navigate_to_pending_entry_); |
| 3407 | in_navigate_to_pending_entry_ = true; |
| 3408 | |
arthursonzogni | 66f711c | 2019-10-08 14:40:36 | [diff] [blame] | 3409 | // It is not possible to delete the pending NavigationEntry while navigating |
| 3410 | // to it. Grab a reference to delay potential deletion until the end of this |
| 3411 | // function. |
| 3412 | std::unique_ptr<PendingEntryRef> pending_entry_ref = ReferencePendingEntry(); |
| 3413 | |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 3414 | base::WeakPtr<NavigationHandle> created_navigation_handle( |
| 3415 | request->GetWeakPtr()); |
Lukasz Anforowicz | 9ee83c27 | 2020-12-01 20:14:05 | [diff] [blame] | 3416 | node->navigator().Navigate(std::move(request), reload_type); |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3417 | |
| 3418 | in_navigate_to_pending_entry_ = false; |
Harkiran Bolaria | ba823e4 | 2021-05-21 18:30:36 | [diff] [blame] | 3419 | return created_navigation_handle; |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3420 | } |
| 3421 | |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3422 | void NavigationControllerImpl::HandleRendererDebugURL( |
| 3423 | FrameTreeNode* frame_tree_node, |
| 3424 | const GURL& url) { |
| 3425 | if (!frame_tree_node->current_frame_host()->IsRenderFrameLive()) { |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3426 | // Any renderer-side debug URLs or javascript: URLs should be ignored if |
| 3427 | // the renderer process is not live, unless it is the initial navigation |
| 3428 | // of the tab. |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3429 | if (!IsInitialNavigation()) { |
| 3430 | DiscardNonCommittedEntries(); |
| 3431 | return; |
| 3432 | } |
Fergal Daly | ecd3b020 | 2020-06-25 01:57:37 | [diff] [blame] | 3433 | // The current frame is always a main frame. If IsInitialNavigation() is |
| 3434 | // true then there have been no navigations and any frames of this tab must |
| 3435 | // be in the same renderer process. If that has crashed then the only frame |
| 3436 | // that can be revived is the main frame. |
| 3437 | frame_tree_node->render_manager() |
| 3438 | ->InitializeMainRenderFrameForImmediateUse(); |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3439 | } |
| 3440 | frame_tree_node->current_frame_host()->HandleRendererDebugURL(url); |
| 3441 | } |
| 3442 | |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3443 | std::unique_ptr<NavigationEntryImpl> |
| 3444 | NavigationControllerImpl::CreateNavigationEntryFromLoadParams( |
| 3445 | FrameTreeNode* node, |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3446 | const LoadURLParams& params, |
| 3447 | bool override_user_agent, |
| 3448 | bool should_replace_current_entry, |
| 3449 | bool has_user_gesture) { |
Marijn Kruisselbrink | 0c87e6e | 2018-06-22 22:57:39 | [diff] [blame] | 3450 | // Browser initiated navigations might not have a blob_url_loader_factory set |
| 3451 | // in params even if the navigation is to a blob URL. If that happens, lookup |
| 3452 | // the correct url loader factory to use here. |
| 3453 | auto blob_url_loader_factory = params.blob_url_loader_factory; |
Kinuko Yasuda | 7d925ea2 | 2019-08-01 10:08:48 | [diff] [blame] | 3454 | if (!blob_url_loader_factory && params.url.SchemeIsBlob()) { |
Marijn Kruisselbrink | 8ffda44 | 2020-09-03 18:29:47 | [diff] [blame] | 3455 | // Resolve the blob URL in the storage partition associated with the target |
| 3456 | // frame. This is the storage partition the URL will be loaded in, and only |
| 3457 | // 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] | 3458 | blob_url_loader_factory = ChromeBlobStorageContext::URLLoaderFactoryForUrl( |
Marijn Kruisselbrink | 8ffda44 | 2020-09-03 18:29:47 | [diff] [blame] | 3459 | node->current_frame_host()->GetStoragePartition(), params.url); |
Marijn Kruisselbrink | 0c87e6e | 2018-06-22 22:57:39 | [diff] [blame] | 3460 | } |
| 3461 | |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3462 | std::unique_ptr<NavigationEntryImpl> entry; |
Tommy C. Li | 03eee77a | 2019-02-05 02:07:44 | [diff] [blame] | 3463 | // extra_headers in params are \n separated; navigation entries want \r\n. |
| 3464 | std::string extra_headers_crlf; |
| 3465 | base::ReplaceChars(params.extra_headers, "\n", "\r\n", &extra_headers_crlf); |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3466 | |
| 3467 | // For subframes, create a pending entry with a corresponding frame entry. |
| 3468 | if (!node->IsMainFrame()) { |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 3469 | if (GetLastCommittedEntry()) { |
| 3470 | entry = GetLastCommittedEntry()->Clone(); |
| 3471 | } else { |
| 3472 | // If there's no last committed entry, create an entry for about:blank |
| 3473 | // with a subframe entry for our destination. |
| 3474 | // TODO(creis): Ensure this case can't exist in https://crbug.com/524208. |
| 3475 | entry = NavigationEntryImpl::FromNavigationEntry(CreateNavigationEntry( |
| 3476 | GURL(url::kAboutBlankURL), params.referrer, params.initiator_origin, |
| 3477 | params.source_site_instance.get(), params.transition_type, |
| 3478 | params.is_renderer_initiated, extra_headers_crlf, browser_context_, |
| 3479 | blob_url_loader_factory)); |
| 3480 | } |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3481 | entry->AddOrUpdateFrameEntry( |
Nate Chapin | fbfe5af | 2021-06-10 17:22:08 | [diff] [blame] | 3482 | node, NavigationEntryImpl::UpdatePolicy::kReplace, -1, -1, "", nullptr, |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3483 | static_cast<SiteInstanceImpl*>(params.source_site_instance.get()), |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 3484 | params.url, absl::nullopt, params.referrer, params.initiator_origin, |
Miyoung Shin | 5d77f7207 | 2020-10-09 15:14:20 | [diff] [blame] | 3485 | params.redirect_chain, blink::PageState(), "GET", -1, |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 3486 | blob_url_loader_factory, nullptr /* web_bundle_navigation_info */, |
Kunihiko Sakamoto | 346a74e | 2021-03-10 08:57:48 | [diff] [blame] | 3487 | nullptr /* subresource_web_bundle_navigation_info */, |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 3488 | // If in NavigateWithoutEntry we later determine that this navigation is |
Charlie Reis | 7e2cb6d | 2021-01-26 01:27:16 | [diff] [blame] | 3489 | // a conversion of a new navigation into a reload, we will set the right |
| 3490 | // document policies there. |
Titouan Rigoudy | 6ec7040 | 2021-02-02 15:42:19 | [diff] [blame] | 3491 | nullptr /* policy_container_policies */); |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3492 | } else { |
| 3493 | // Otherwise, create a pending entry for the main frame. |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3494 | entry = NavigationEntryImpl::FromNavigationEntry(CreateNavigationEntry( |
Lukasz Anforowicz | 435bcb58 | 2019-07-12 20:50:06 | [diff] [blame] | 3495 | params.url, params.referrer, params.initiator_origin, |
Lukasz Anforowicz | 641234d5 | 2019-11-07 21:07:10 | [diff] [blame] | 3496 | params.source_site_instance.get(), params.transition_type, |
| 3497 | params.is_renderer_initiated, extra_headers_crlf, browser_context_, |
Hayato Ito | 303654c | 2021-06-30 09:07:54 | [diff] [blame] | 3498 | blob_url_loader_factory)); |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3499 | entry->set_source_site_instance( |
| 3500 | static_cast<SiteInstanceImpl*>(params.source_site_instance.get())); |
| 3501 | entry->SetRedirectChain(params.redirect_chain); |
| 3502 | } |
| 3503 | |
| 3504 | // Set the FTN ID (only used in non-site-per-process, for tests). |
| 3505 | entry->set_frame_tree_node_id(node->frame_tree_node_id()); |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3506 | entry->set_should_clear_history_list(params.should_clear_history_list); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3507 | entry->SetIsOverridingUserAgent(override_user_agent); |
| 3508 | entry->set_has_user_gesture(has_user_gesture); |
Robert Ogden | 011a808 | 2019-01-23 19:04:54 | [diff] [blame] | 3509 | entry->set_reload_type(params.reload_type); |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3510 | |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3511 | switch (params.load_type) { |
| 3512 | case LOAD_TYPE_DEFAULT: |
| 3513 | break; |
| 3514 | case LOAD_TYPE_HTTP_POST: |
| 3515 | entry->SetHasPostData(true); |
| 3516 | entry->SetPostData(params.post_data); |
| 3517 | break; |
| 3518 | case LOAD_TYPE_DATA: |
| 3519 | entry->SetBaseURLForDataURL(params.base_url_for_data_url); |
| 3520 | entry->SetVirtualURL(params.virtual_url_for_data_url); |
Xiaohan Wang | 7f8052e0 | 2022-01-14 18:44:28 | [diff] [blame] | 3521 | #if BUILDFLAG(IS_ANDROID) |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3522 | entry->SetDataURLAsString(params.data_url_as_string); |
| 3523 | #endif |
| 3524 | entry->SetCanLoadLocalResources(params.can_load_local_resources); |
| 3525 | break; |
clamy | 21718cc2 | 2018-06-13 13:34:24 | [diff] [blame] | 3526 | } |
| 3527 | |
| 3528 | // TODO(clamy): NavigationEntry is meant for information that will be kept |
| 3529 | // after the navigation ended and therefore is not appropriate for |
| 3530 | // started_from_context_menu. Move started_from_context_menu to |
| 3531 | // NavigationUIData. |
| 3532 | entry->set_started_from_context_menu(params.started_from_context_menu); |
| 3533 | |
| 3534 | return entry; |
| 3535 | } |
| 3536 | |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3537 | std::unique_ptr<NavigationRequest> |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3538 | NavigationControllerImpl::CreateNavigationRequestFromLoadParams( |
| 3539 | FrameTreeNode* node, |
| 3540 | const LoadURLParams& params, |
| 3541 | bool override_user_agent, |
| 3542 | bool should_replace_current_entry, |
| 3543 | bool has_user_gesture, |
Antonio Sartori | 2f763d9d | 2021-04-21 10:04:14 | [diff] [blame] | 3544 | network::mojom::SourceLocationPtr source_location, |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3545 | ReloadType reload_type, |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 3546 | NavigationEntryImpl* entry, |
Scott Violet | cf6ea7e | 2021-06-09 21:09:21 | [diff] [blame] | 3547 | FrameNavigationEntry* frame_entry) { |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 3548 | DCHECK_EQ(-1, GetIndexOfEntry(entry)); |
Camille Lamy | b9ed3c5 | 2018-11-19 15:34:28 | [diff] [blame] | 3549 | DCHECK(frame_entry); |
Nasko Oskov | 3c2f9e25 | 2019-01-10 17:45:53 | [diff] [blame] | 3550 | // All renderer-initiated navigations must have an initiator_origin. |
| 3551 | DCHECK(!params.is_renderer_initiated || params.initiator_origin.has_value()); |
Camille Lamy | ff7c482 | 2018-11-07 15:42:51 | [diff] [blame] | 3552 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3553 | GURL url_to_load; |
| 3554 | GURL virtual_url; |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 3555 | absl::optional<url::Origin> origin_to_commit = |
| 3556 | frame_entry ? frame_entry->committed_origin() : absl::nullopt; |
Nasko Oskov | 0391210 | 2019-01-11 00:21:32 | [diff] [blame] | 3557 | |
Camille Lamy | 2baa802 | 2018-10-19 16:43:17 | [diff] [blame] | 3558 | // For main frames, rewrite the URL if necessary and compute the virtual URL |
| 3559 | // that should be shown in the address bar. |
| 3560 | if (node->IsMainFrame()) { |
Lukasz Anforowicz | b2eb19b1 | 2020-01-25 00:40:42 | [diff] [blame] | 3561 | bool ignored_reverse_on_redirect = false; |
Camille Lamy | 2baa802 | 2018-10-19 16:43:17 | [diff] [blame] | 3562 | RewriteUrlForNavigation(params.url, browser_context_, &url_to_load, |
Lukasz Anforowicz | b2eb19b1 | 2020-01-25 00:40:42 | [diff] [blame] | 3563 | &virtual_url, &ignored_reverse_on_redirect); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3564 | |
Camille Lamy | 2baa802 | 2018-10-19 16:43:17 | [diff] [blame] | 3565 | // For DATA loads, override the virtual URL. |
| 3566 | if (params.load_type == LOAD_TYPE_DATA) |
| 3567 | virtual_url = params.virtual_url_for_data_url; |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3568 | |
Camille Lamy | 2baa802 | 2018-10-19 16:43:17 | [diff] [blame] | 3569 | if (virtual_url.is_empty()) |
| 3570 | virtual_url = url_to_load; |
| 3571 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 3572 | CHECK(virtual_url == entry->GetVirtualURL()); |
Camille Lamy | b9ed3c5 | 2018-11-19 15:34:28 | [diff] [blame] | 3573 | |
Aran Gilman | 249eb12 | 2019-12-02 23:32:46 | [diff] [blame] | 3574 | // This is a LOG and not a CHECK/DCHECK as URL rewrite has non-deterministic |
| 3575 | // behavior: it is possible for two calls to RewriteUrlForNavigation to |
| 3576 | // return different results, leading to a different URL in the |
| 3577 | // NavigationRequest and FrameEntry. This will be fixed once we remove the |
| 3578 | // pending NavigationEntry, as we'll only make one call to |
| 3579 | // RewriteUrlForNavigation. |
| 3580 | VLOG_IF(1, (url_to_load != frame_entry->url())) |
| 3581 | << "NavigationRequest and FrameEntry have different URLs: " |
| 3582 | << url_to_load << " vs " << frame_entry->url(); |
Camille Lamy | b9ed3c5 | 2018-11-19 15:34:28 | [diff] [blame] | 3583 | |
Camille Lamy | 2baa802 | 2018-10-19 16:43:17 | [diff] [blame] | 3584 | // TODO(clamy): In order to remove the pending NavigationEntry, |
Lukasz Anforowicz | b2eb19b1 | 2020-01-25 00:40:42 | [diff] [blame] | 3585 | // |virtual_url| and |ignored_reverse_on_redirect| should be stored in the |
Camille Lamy | 2baa802 | 2018-10-19 16:43:17 | [diff] [blame] | 3586 | // NavigationRequest. |
| 3587 | } else { |
| 3588 | url_to_load = params.url; |
| 3589 | virtual_url = params.url; |
Camille Lamy | f664f762 | 2019-01-07 19:28:24 | [diff] [blame] | 3590 | CHECK(!frame_entry || url_to_load == frame_entry->url()); |
Camille Lamy | 2baa802 | 2018-10-19 16:43:17 | [diff] [blame] | 3591 | } |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3592 | |
Ehsan Karamad | 44fc7211 | 2019-02-26 18:15:47 | [diff] [blame] | 3593 | if (node->render_manager()->is_attaching_inner_delegate()) { |
| 3594 | // Avoid starting any new navigations since this node is now preparing for |
| 3595 | // attaching an inner delegate. |
| 3596 | return nullptr; |
Ehsan Karamad | dd9a414 | 2018-12-04 20:38:20 | [diff] [blame] | 3597 | } |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3598 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3599 | if (!IsValidURLForNavigation(node->IsMainFrame(), virtual_url, url_to_load)) |
| 3600 | return nullptr; |
| 3601 | |
Kunihiko Sakamoto | 346a74e | 2021-03-10 08:57:48 | [diff] [blame] | 3602 | if (!DoesURLMatchOriginForNavigation( |
| 3603 | url_to_load, origin_to_commit, |
| 3604 | frame_entry->subresource_web_bundle_navigation_info())) { |
Nasko Oskov | 0391210 | 2019-01-11 00:21:32 | [diff] [blame] | 3605 | DCHECK(false) << " url:" << url_to_load |
| 3606 | << " origin:" << origin_to_commit.value(); |
| 3607 | return nullptr; |
| 3608 | } |
| 3609 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3610 | // This will be used to set the Navigation Timing API navigationStart |
| 3611 | // parameter for browser navigations in new tabs (intents, tabs opened through |
| 3612 | // "Open link in new tab"). If the navigation must wait on the current |
| 3613 | // RenderFrameHost to execute its BeforeUnload event, the navigation start |
| 3614 | // will be updated when the BeforeUnload ack is received. |
| 3615 | base::TimeTicks navigation_start = base::TimeTicks::Now(); |
| 3616 | |
danakj | d83d706d | 2020-11-25 22:11:12 | [diff] [blame] | 3617 | // Look for a pending commit that is to another document in this |
| 3618 | // FrameTreeNode. If one exists, then the last committed URL will not be the |
| 3619 | // current URL by the time this navigation commits. |
| 3620 | bool has_pending_cross_document_commit = |
| 3621 | node->render_manager()->HasPendingCommitForCrossDocumentNavigation(); |
Miyoung Shin | a2dd6a4 | 2021-10-07 12:19:21 | [diff] [blame] | 3622 | bool is_currently_error_page = node->current_frame_host()->IsErrorDocument(); |
danakj | d83d706d | 2020-11-25 22:11:12 | [diff] [blame] | 3623 | |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 3624 | blink::mojom::NavigationType navigation_type = GetNavigationType( |
danakj | b952ef1 | 2021-01-14 19:58:49 | [diff] [blame] | 3625 | /*old_url=*/node->current_url(), |
| 3626 | /*new_url=*/url_to_load, reload_type, entry, *frame_entry, |
| 3627 | has_pending_cross_document_commit, is_currently_error_page, |
| 3628 | /*is_same_document_history_load=*/false); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3629 | |
| 3630 | // Create the NavigationParams based on |params|. |
| 3631 | |
Hiroki Nakagawa | 4ed6128 | 2021-06-18 05:37:23 | [diff] [blame] | 3632 | bool is_view_source_mode = entry->IsViewSourceMode(); |
| 3633 | DCHECK_EQ(is_view_source_mode, virtual_url.SchemeIs(kViewSourceScheme)); |
Charlie Harrison | 8c113a3 | 2019-01-07 16:08:29 | [diff] [blame] | 3634 | |
Antonio Sartori | 6984c74 | 2021-08-26 08:03:41 | [diff] [blame] | 3635 | blink::NavigationDownloadPolicy download_policy = params.download_policy; |
Hiroki Nakagawa | 4ed6128 | 2021-06-18 05:37:23 | [diff] [blame] | 3636 | // Update |download_policy| if the virtual URL is view-source. |
Charlie Harrison | 8c113a3 | 2019-01-07 16:08:29 | [diff] [blame] | 3637 | if (is_view_source_mode) |
Yeunjoo Choi | 3df791a | 2021-02-17 07:07:25 | [diff] [blame] | 3638 | download_policy.SetDisallowed(blink::NavigationDownloadType::kViewSource); |
Charlie Harrison | 8c113a3 | 2019-01-07 16:08:29 | [diff] [blame] | 3639 | |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 3640 | blink::mojom::CommonNavigationParamsPtr common_params = |
| 3641 | blink::mojom::CommonNavigationParams::New( |
Lucas Furukawa Gadani | ef8290a | 2019-07-29 20:27:51 | [diff] [blame] | 3642 | url_to_load, params.initiator_origin, |
| 3643 | blink::mojom::Referrer::New(params.referrer.url, |
| 3644 | params.referrer.policy), |
Scott Violet | cf6ea7e | 2021-06-09 21:09:21 | [diff] [blame] | 3645 | params.transition_type, navigation_type, download_policy, |
Lucas Furukawa Gadani | ef8290a | 2019-07-29 20:27:51 | [diff] [blame] | 3646 | should_replace_current_entry, params.base_url_for_data_url, |
Tarun Bansal | bcd62c8 | 2022-01-18 17:27:38 | [diff] [blame] | 3647 | navigation_start, |
Lucas Furukawa Gadani | ef8290a | 2019-07-29 20:27:51 | [diff] [blame] | 3648 | params.load_type == LOAD_TYPE_HTTP_POST ? "POST" : "GET", |
Antonio Sartori | 2f763d9d | 2021-04-21 10:04:14 | [diff] [blame] | 3649 | params.post_data, std::move(source_location), |
arthursonzogni | af7c62c5 | 2020-02-12 10:49:41 | [diff] [blame] | 3650 | params.started_from_context_menu, has_user_gesture, |
Antonio Sartori | 636adba | 2021-03-09 12:15:27 | [diff] [blame] | 3651 | false /* has_text_fragment_token */, |
| 3652 | network::mojom::CSPDisposition::CHECK, std::vector<int>(), |
| 3653 | params.href_translate, |
Lucas Furukawa Gadani | ef8290a | 2019-07-29 20:27:51 | [diff] [blame] | 3654 | false /* is_history_navigation_in_new_child_frame */, |
Nan Lin | d91c815 | 2021-10-21 16:22:37 | [diff] [blame] | 3655 | params.input_start, network::mojom::RequestDestination::kEmpty); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3656 | |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 3657 | blink::mojom::CommitNavigationParamsPtr commit_params = |
| 3658 | blink::mojom::CommitNavigationParams::New( |
Antonio Sartori | 3e8de6d | 2021-07-26 10:28:41 | [diff] [blame] | 3659 | frame_entry->committed_origin(), |
| 3660 | // The correct storage key will be computed before committing the |
| 3661 | // navigation. |
| 3662 | blink::StorageKey(), network::mojom::WebSandboxFlags(), |
arthursonzogni | d5a8d0b | 2021-03-11 17:36:43 | [diff] [blame] | 3663 | override_user_agent, params.redirect_chain, |
Lucas Furukawa Gadani | 81e294b | 2019-08-29 16:26:32 | [diff] [blame] | 3664 | std::vector<network::mojom::URLResponseHeadPtr>(), |
Lucas Furukawa Gadani | a9c4568 | 2019-07-31 22:05:14 | [diff] [blame] | 3665 | std::vector<net::RedirectInfo>(), |
| 3666 | std::string() /* post_content_type */, common_params->url, |
| 3667 | common_params->method, params.can_load_local_resources, |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 3668 | frame_entry->page_state().ToEncodedData(), entry->GetUniqueID(), |
Lucas Furukawa Gadani | a9c4568 | 2019-07-31 22:05:14 | [diff] [blame] | 3669 | entry->GetSubframeUniqueNames(node), true /* intended_as_new_entry */, |
| 3670 | -1 /* pending_history_list_offset */, |
| 3671 | params.should_clear_history_list ? -1 : GetLastCommittedEntryIndex(), |
| 3672 | params.should_clear_history_list ? 0 : GetEntryCount(), |
| 3673 | false /* was_discarded */, is_view_source_mode, |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 3674 | params.should_clear_history_list, |
| 3675 | blink::mojom::NavigationTiming::New(), |
Minggang Wang | f59db47b | 2021-06-16 01:56:22 | [diff] [blame] | 3676 | blink::mojom::WasActivatedOption::kUnknown, |
Lucas Furukawa Gadani | a9c4568 | 2019-07-31 22:05:14 | [diff] [blame] | 3677 | base::UnguessableToken::Create() /* navigation_token */, |
Minggang Wang | 7ee0c74 | 2021-06-16 16:16:51 | [diff] [blame] | 3678 | std::vector<blink::mojom::PrefetchedSignedExchangeInfoPtr>(), |
Xiaohan Wang | 7f8052e0 | 2022-01-14 18:44:28 | [diff] [blame] | 3679 | #if BUILDFLAG(IS_ANDROID) |
Lucas Furukawa Gadani | a9c4568 | 2019-07-31 22:05:14 | [diff] [blame] | 3680 | std::string(), /* data_url_as_string */ |
| 3681 | #endif |
arthursonzogni | 1437978 | 2020-05-15 09:09:27 | [diff] [blame] | 3682 | !params.is_renderer_initiated, /* is_browser_initiated */ |
Tsuyoshi Horo | e86d770 | 2019-11-29 01:52:47 | [diff] [blame] | 3683 | GURL() /* web_bundle_physical_url */, |
Charlie Hu | 5ffc015 | 2019-12-06 15:59:53 | [diff] [blame] | 3684 | GURL() /* base_url_override_for_web_bundle */, |
Yue Ru Sun | 12880493 | 2020-09-30 22:19:17 | [diff] [blame] | 3685 | ukm::kInvalidSourceId /* document_ukm_source_id */, |
Jiewei Qian | 0406fc0 | 2020-03-09 06:02:07 | [diff] [blame] | 3686 | node->pending_frame_policy(), |
Domenic Denicola | 4778c3539 | 2020-06-25 21:25:16 | [diff] [blame] | 3687 | std::vector<std::string>() /* force_enabled_origin_trials */, |
Domenic Denicola | 55701ee | 2021-01-14 00:18:33 | [diff] [blame] | 3688 | false /* origin_agent_cluster */, |
Maks Orlovich | c66745a | 2020-06-30 17:40:02 | [diff] [blame] | 3689 | std::vector< |
Shuran Huang | a055ce7 | 2020-07-23 14:13:21 | [diff] [blame] | 3690 | network::mojom::WebClientHintsType>() /* enabled_client_hints */, |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 3691 | false /* is_cross_browsing_instance */, nullptr /* old_page_info */, |
| 3692 | -1 /* http_response_code */, |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 3693 | std::vector<blink::mojom:: |
| 3694 | AppHistoryEntryPtr>() /* app_history_back_entries */, |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 3695 | std::vector< |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 3696 | blink::mojom:: |
| 3697 | AppHistoryEntryPtr>() /* app_history_forward_entries */, |
Matt Menke | 4e20908 | 2021-11-09 04:59:31 | [diff] [blame] | 3698 | std::vector<GURL>() /* early_hints_preloaded_resources */, |
Clark DuVall | 8ee487a2 | 2021-11-10 02:25:58 | [diff] [blame] | 3699 | absl::nullopt /* ad_auction_components */, |
| 3700 | // This timestamp will be populated when the commit IPC is sent. |
Yifan Luo | e1a2e05d | 2022-01-12 16:47:59 | [diff] [blame] | 3701 | base::TimeTicks() /* commit_sent */, false /* anonymous */); |
Xiaohan Wang | 7f8052e0 | 2022-01-14 18:44:28 | [diff] [blame] | 3702 | #if BUILDFLAG(IS_ANDROID) |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3703 | if (ValidateDataURLAsString(params.data_url_as_string)) { |
Lucas Furukawa Gadani | a9c4568 | 2019-07-31 22:05:14 | [diff] [blame] | 3704 | commit_params->data_url_as_string = params.data_url_as_string->data(); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3705 | } |
| 3706 | #endif |
| 3707 | |
Lucas Furukawa Gadani | a9c4568 | 2019-07-31 22:05:14 | [diff] [blame] | 3708 | commit_params->was_activated = params.was_activated; |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3709 | |
| 3710 | // A form submission may happen here if the navigation is a renderer-initiated |
| 3711 | // form submission that took the OpenURL path. |
| 3712 | scoped_refptr<network::ResourceRequestBody> request_body = params.post_data; |
| 3713 | |
| 3714 | // extra_headers in params are \n separated; NavigationRequests want \r\n. |
| 3715 | std::string extra_headers_crlf; |
| 3716 | base::ReplaceChars(params.extra_headers, "\n", "\r\n", &extra_headers_crlf); |
Yao Xiao | dc5ed10 | 2019-06-04 19:19:09 | [diff] [blame] | 3717 | |
| 3718 | auto navigation_request = NavigationRequest::CreateBrowserInitiated( |
Lucas Furukawa Gadani | a9c4568 | 2019-07-31 22:05:14 | [diff] [blame] | 3719 | node, std::move(common_params), std::move(commit_params), |
Takashi Toyoshima | e87b7be | 2021-01-22 11:51:08 | [diff] [blame] | 3720 | !params.is_renderer_initiated, params.was_opener_suppressed, |
Antonio Sartori | 9a82f6f3 | 2020-12-14 09:22:45 | [diff] [blame] | 3721 | params.initiator_frame_token.has_value() |
| 3722 | ? &(params.initiator_frame_token.value()) |
| 3723 | : nullptr, |
| 3724 | params.initiator_process_id, extra_headers_crlf, frame_entry, entry, |
| 3725 | request_body, |
John Delaney | 50425f8 | 2020-04-07 16:26:21 | [diff] [blame] | 3726 | params.navigation_ui_data ? params.navigation_ui_data->Clone() : nullptr, |
Daniel Hosseinian | f0fbfb4 | 2021-09-08 02:20:47 | [diff] [blame] | 3727 | params.impression, params.is_pdf); |
Yao Xiao | dc5ed10 | 2019-06-04 19:19:09 | [diff] [blame] | 3728 | navigation_request->set_from_download_cross_origin_redirect( |
| 3729 | params.from_download_cross_origin_redirect); |
| 3730 | return navigation_request; |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3731 | } |
| 3732 | |
| 3733 | std::unique_ptr<NavigationRequest> |
| 3734 | NavigationControllerImpl::CreateNavigationRequestFromEntry( |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3735 | FrameTreeNode* frame_tree_node, |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 3736 | NavigationEntryImpl* entry, |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3737 | FrameNavigationEntry* frame_entry, |
| 3738 | ReloadType reload_type, |
| 3739 | bool is_same_document_history_load, |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 3740 | bool is_history_navigation_in_new_child_frame, |
| 3741 | bool is_browser_initiated) { |
Alex Moshchuk | 47d1a4bd | 2020-06-01 22:15:34 | [diff] [blame] | 3742 | DCHECK(frame_entry); |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3743 | GURL dest_url = frame_entry->url(); |
Rakina Zata Amni | f297a80 | 2022-01-18 03:53:43 | [diff] [blame] | 3744 | // We should never navigate to an existing initial NavigationEntry that is the |
| 3745 | // initial NavigationEntry for the initial empty document that hasn't been |
| 3746 | // overridden by the synchronous about:blank commit, to preserve previous |
| 3747 | // behavior where trying to reload when the main frame is on the initial empty |
| 3748 | // document won't result in a navigation. |
| 3749 | // See also https://crbug.com/1277414. |
| 3750 | DCHECK(!entry->IsInitialEntryNotForSynchronousAboutBlank()); |
Anton Bikineev | f62d1bf | 2021-05-15 17:56:07 | [diff] [blame] | 3751 | absl::optional<url::Origin> origin_to_commit = |
Nasko Oskov | 0391210 | 2019-01-11 00:21:32 | [diff] [blame] | 3752 | frame_entry->committed_origin(); |
| 3753 | |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3754 | Referrer dest_referrer = frame_entry->referrer(); |
Ryan Sturm | c4da199 | 2018-07-17 16:59:01 | [diff] [blame] | 3755 | if (reload_type == ReloadType::ORIGINAL_REQUEST_URL && |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 3756 | entry->GetOriginalRequestURL().is_valid() && !entry->GetHasPostData()) { |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3757 | // We may have been redirected when navigating to the current URL. |
| 3758 | // Use the URL the user originally intended to visit as signaled by the |
| 3759 | // 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] | 3760 | // case avoids issues with sending data to the wrong page. |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 3761 | dest_url = entry->GetOriginalRequestURL(); |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3762 | dest_referrer = Referrer(); |
Nasko Oskov | 0391210 | 2019-01-11 00:21:32 | [diff] [blame] | 3763 | origin_to_commit.reset(); |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3764 | } |
| 3765 | |
Ehsan Karamad | 44fc7211 | 2019-02-26 18:15:47 | [diff] [blame] | 3766 | if (frame_tree_node->render_manager()->is_attaching_inner_delegate()) { |
| 3767 | // Avoid starting any new navigations since this node is now preparing for |
| 3768 | // attaching an inner delegate. |
| 3769 | return nullptr; |
Ehsan Karamad | dd9a414 | 2018-12-04 20:38:20 | [diff] [blame] | 3770 | } |
| 3771 | |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3772 | if (!IsValidURLForNavigation(frame_tree_node->IsMainFrame(), |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 3773 | entry->GetVirtualURL(), dest_url)) { |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3774 | return nullptr; |
| 3775 | } |
| 3776 | |
Kunihiko Sakamoto | 346a74e | 2021-03-10 08:57:48 | [diff] [blame] | 3777 | if (!DoesURLMatchOriginForNavigation( |
| 3778 | dest_url, origin_to_commit, |
| 3779 | frame_entry->subresource_web_bundle_navigation_info())) { |
| 3780 | DCHECK(false) << " url:" << dest_url |
| 3781 | << " origin:" << origin_to_commit.value(); |
Nasko Oskov | 0391210 | 2019-01-11 00:21:32 | [diff] [blame] | 3782 | return nullptr; |
| 3783 | } |
| 3784 | |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3785 | // This will be used to set the Navigation Timing API navigationStart |
| 3786 | // parameter for browser navigations in new tabs (intents, tabs opened through |
| 3787 | // "Open link in new tab"). If the navigation must wait on the current |
| 3788 | // RenderFrameHost to execute its BeforeUnload event, the navigation start |
| 3789 | // will be updated when the BeforeUnload ack is received. |
| 3790 | base::TimeTicks navigation_start = base::TimeTicks::Now(); |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3791 | |
danakj | d83d706d | 2020-11-25 22:11:12 | [diff] [blame] | 3792 | // Look for a pending commit that is to another document in this |
| 3793 | // FrameTreeNode. If one exists, then the last committed URL will not be the |
| 3794 | // current URL by the time this navigation commits. |
| 3795 | bool has_pending_cross_document_commit = |
| 3796 | frame_tree_node->render_manager() |
| 3797 | ->HasPendingCommitForCrossDocumentNavigation(); |
danakj | b952ef1 | 2021-01-14 19:58:49 | [diff] [blame] | 3798 | bool is_currently_error_page = |
Miyoung Shin | a2dd6a4 | 2021-10-07 12:19:21 | [diff] [blame] | 3799 | frame_tree_node->current_frame_host()->IsErrorDocument(); |
danakj | d83d706d | 2020-11-25 22:11:12 | [diff] [blame] | 3800 | |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 3801 | blink::mojom::NavigationType navigation_type = GetNavigationType( |
danakj | d83d706d | 2020-11-25 22:11:12 | [diff] [blame] | 3802 | /*old_url=*/frame_tree_node->current_url(), |
| 3803 | /*new_url=*/dest_url, reload_type, entry, *frame_entry, |
danakj | b952ef1 | 2021-01-14 19:58:49 | [diff] [blame] | 3804 | has_pending_cross_document_commit, is_currently_error_page, |
| 3805 | is_same_document_history_load); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3806 | |
| 3807 | // A form submission may happen here if the navigation is a |
| 3808 | // back/forward/reload navigation that does a form resubmission. |
| 3809 | scoped_refptr<network::ResourceRequestBody> request_body; |
| 3810 | std::string post_content_type; |
| 3811 | if (frame_entry->method() == "POST") { |
| 3812 | request_body = frame_entry->GetPostData(&post_content_type); |
| 3813 | // Might have a LF at end. |
Peter Kasting | b53b8191 | 2021-04-28 19:23:30 | [diff] [blame] | 3814 | post_content_type = std::string( |
| 3815 | base::TrimWhitespaceASCII(post_content_type, base::TRIM_ALL)); |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3816 | } |
| 3817 | |
| 3818 | // Create the NavigationParams based on |entry| and |frame_entry|. |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 3819 | blink::mojom::CommonNavigationParamsPtr common_params = |
Lucas Furukawa Gadani | ef8290a | 2019-07-29 20:27:51 | [diff] [blame] | 3820 | entry->ConstructCommonNavigationParams( |
| 3821 | *frame_entry, request_body, dest_url, |
| 3822 | blink::mojom::Referrer::New(dest_referrer.url, dest_referrer.policy), |
Tarun Bansal | bcd62c8 | 2022-01-18 17:27:38 | [diff] [blame] | 3823 | navigation_type, navigation_start, |
Charlie Hu | 5ffc015 | 2019-12-06 15:59:53 | [diff] [blame] | 3824 | base::TimeTicks() /* input_start */); |
Lucas Furukawa Gadani | ef8290a | 2019-07-29 20:27:51 | [diff] [blame] | 3825 | common_params->is_history_navigation_in_new_child_frame = |
Arthur Hemery | bee4a75 | 2019-05-29 10:50:55 | [diff] [blame] | 3826 | is_history_navigation_in_new_child_frame; |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3827 | |
| 3828 | // TODO(clamy): |intended_as_new_entry| below should always be false once |
| 3829 | // Reload no longer leads to this being called for a pending NavigationEntry |
| 3830 | // of index -1. |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 3831 | blink::mojom::CommitNavigationParamsPtr commit_params = |
Lucas Furukawa Gadani | a9c4568 | 2019-07-31 22:05:14 | [diff] [blame] | 3832 | entry->ConstructCommitNavigationParams( |
| 3833 | *frame_entry, common_params->url, origin_to_commit, |
| 3834 | common_params->method, entry->GetSubframeUniqueNames(frame_tree_node), |
| 3835 | GetPendingEntryIndex() == -1 /* intended_as_new_entry */, |
Charlie Hu | 5ffc015 | 2019-12-06 15:59:53 | [diff] [blame] | 3836 | GetIndexOfEntry(entry), GetLastCommittedEntryIndex(), GetEntryCount(), |
| 3837 | frame_tree_node->pending_frame_policy()); |
Lucas Furukawa Gadani | a9c4568 | 2019-07-31 22:05:14 | [diff] [blame] | 3838 | commit_params->post_content_type = post_content_type; |
Camille Lamy | 5193caa | 2018-10-12 11:59:42 | [diff] [blame] | 3839 | |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3840 | return NavigationRequest::CreateBrowserInitiated( |
Lucas Furukawa Gadani | a9c4568 | 2019-07-31 22:05:14 | [diff] [blame] | 3841 | frame_tree_node, std::move(common_params), std::move(commit_params), |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 3842 | is_browser_initiated, false /* was_opener_suppressed */, |
Takashi Toyoshima | e87b7be | 2021-01-22 11:51:08 | [diff] [blame] | 3843 | nullptr /* initiator_frame_token */, |
Antonio Sartori | 9a82f6f3 | 2020-12-14 09:22:45 | [diff] [blame] | 3844 | ChildProcessHost::kInvalidUniqueID /* initiator_process_id */, |
| 3845 | entry->extra_headers(), frame_entry, entry, request_body, |
Daniel Hosseinian | f0fbfb4 | 2021-09-08 02:20:47 | [diff] [blame] | 3846 | nullptr /* navigation_ui_data */, absl::nullopt /* impression */, |
| 3847 | false /* is_pdf */); |
clamy | ea99ea1 | 2018-05-28 13:54:23 | [diff] [blame] | 3848 | } |
| 3849 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 3850 | void NavigationControllerImpl::NotifyNavigationEntryCommitted( |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 3851 | LoadCommittedDetails* details) { |
[email protected] | 6286a379 | 2013-10-09 04:03:27 | [diff] [blame] | 3852 | details->entry = GetLastCommittedEntry(); |
[email protected] | df1af24 | 2009-05-01 00:11:40 | [diff] [blame] | 3853 | |
Takashi Toyoshima | ea534ef2 | 2021-07-21 03:27:59 | [diff] [blame] | 3854 | // We need to notify the ssl_manager_ before the WebContents so the |
[email protected] | df1af24 | 2009-05-01 00:11:40 | [diff] [blame] | 3855 | // location bar will have up-to-date information about the security style |
| 3856 | // when it wants to draw. See http://crbug.com/11157 |
[email protected] | b0f724c | 2013-09-05 04:21:13 | [diff] [blame] | 3857 | ssl_manager_.DidCommitProvisionalLoad(*details); |
[email protected] | df1af24 | 2009-05-01 00:11:40 | [diff] [blame] | 3858 | |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 3859 | delegate_->NotifyNavigationStateChanged( |
Rakina Zata Amni | ddf1050 | 2022-01-15 02:56:55 | [diff] [blame] | 3860 | (details && details->should_stay_as_initial_entry) |
| 3861 | ? INVALIDATE_TYPE_ALL_BUT_KEEPS_INITIAL_NAVIGATION_ENTRY_STATUS |
| 3862 | : INVALIDATE_TYPE_ALL_AND_REMOVES_INITIAL_NAVIGATION_ENTRY_STATUS); |
[email protected] | ec6c05f | 2013-10-23 18:41:57 | [diff] [blame] | 3863 | delegate_->NotifyNavigationEntryCommitted(*details); |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 3864 | |
[email protected] | b0f724c | 2013-09-05 04:21:13 | [diff] [blame] | 3865 | // TODO(avi): Remove. http://crbug.com/170921 |
| 3866 | NotificationDetails notification_details = |
| 3867 | Details<LoadCommittedDetails>(details); |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 3868 | NotificationService::current()->Notify(NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 3869 | Source<NavigationController>(this), |
| 3870 | notification_details); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3871 | } |
| 3872 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3873 | // static |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 3874 | size_t NavigationControllerImpl::max_entry_count() { |
[email protected] | 9b51970d | 2011-12-09 23:10:23 | [diff] [blame] | 3875 | if (max_entry_count_for_testing_ != kMaxEntryCountForTestingNotSet) |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 3876 | return max_entry_count_for_testing_; |
Miyoung Shin | 1c565c91 | 2021-03-17 12:11:21 | [diff] [blame] | 3877 | return blink::kMaxSessionHistoryEntries; |
[email protected] | 9b51970d | 2011-12-09 23:10:23 | [diff] [blame] | 3878 | } |
| 3879 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 3880 | void NavigationControllerImpl::SetActive(bool is_active) { |
[email protected] | ee61392 | 2009-09-02 20:38:22 | [diff] [blame] | 3881 | if (is_active && needs_reload_) |
| 3882 | LoadIfNecessary(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3883 | } |
| 3884 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 3885 | void NavigationControllerImpl::LoadIfNecessary() { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3886 | if (!needs_reload_) |
| 3887 | return; |
| 3888 | |
Bo Liu | cdfa4b1 | 2018-11-06 00:21:44 | [diff] [blame] | 3889 | UMA_HISTOGRAM_ENUMERATION("Navigation.LoadIfNecessaryType", |
| 3890 | needs_reload_type_); |
| 3891 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3892 | // Calling Reload() results in ignoring state, and not loading. |
| 3893 | // Explicitly use NavigateToPendingEntry so that the renderer uses the |
| 3894 | // cached state. |
avi | cc872d724 | 2015-08-19 21:26:34 | [diff] [blame] | 3895 | if (pending_entry_) { |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 3896 | NavigateToExistingPendingEntry(ReloadType::NONE, |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 3897 | FrameTreeNode::kFrameTreeNodeInvalidId, |
| 3898 | true /* is_browser_initiated */); |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 3899 | } else if (last_committed_entry_index_ != -1 && |
| 3900 | !GetLastCommittedEntry() |
Rakina Zata Amni | f297a80 | 2022-01-18 03:53:43 | [diff] [blame] | 3901 | ->IsInitialEntryNotForSynchronousAboutBlank()) { |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 3902 | pending_entry_ = entries_[last_committed_entry_index_].get(); |
avi | cc872d724 | 2015-08-19 21:26:34 | [diff] [blame] | 3903 | pending_entry_index_ = last_committed_entry_index_; |
Dave Tapuska | 8bfd84c | 2019-03-26 20:47:16 | [diff] [blame] | 3904 | NavigateToExistingPendingEntry(ReloadType::NONE, |
Nate Chapin | 45f62058 | 2021-09-30 17:45:43 | [diff] [blame] | 3905 | FrameTreeNode::kFrameTreeNodeInvalidId, |
| 3906 | true /* is_browser_initiated */); |
avi | cc872d724 | 2015-08-19 21:26:34 | [diff] [blame] | 3907 | } else { |
Rakina Zata Amni | f297a80 | 2022-01-18 03:53:43 | [diff] [blame] | 3908 | // We should never navigate to an existing initial NavigationEntry that is |
| 3909 | // the initial NavigationEntry for the initial empty document that hasn't |
| 3910 | // been overridden by the synchronous about:blank commit, to preserve |
| 3911 | // legacy behavior where trying to reload when the main frame is on the |
| 3912 | // initial empty document won't result in a navigation. See also |
| 3913 | // https://crbug.com/1277414. If there is something to reload, the |
| 3914 | // successful reload will clear the |needs_reload_| flag. Otherwise, just do |
| 3915 | // it here. |
avi | cc872d724 | 2015-08-19 21:26:34 | [diff] [blame] | 3916 | needs_reload_ = false; |
| 3917 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3918 | } |
| 3919 | |
Kevin McNee | ccca617 | 2021-10-19 17:11:14 | [diff] [blame] | 3920 | base::WeakPtr<NavigationHandle> |
| 3921 | NavigationControllerImpl::LoadPostCommitErrorPage( |
Carlos IL | 42b41659 | 2019-10-07 23:10:36 | [diff] [blame] | 3922 | RenderFrameHost* render_frame_host, |
| 3923 | const GURL& url, |
| 3924 | const std::string& error_page_html, |
| 3925 | net::Error error) { |
Rakina Zata Amni | 919b792 | 2020-12-11 09:03:13 | [diff] [blame] | 3926 | RenderFrameHostImpl* rfhi = |
| 3927 | static_cast<RenderFrameHostImpl*>(render_frame_host); |
Sreeja Kamishetty | db8e289 | 2021-03-10 09:30:58 | [diff] [blame] | 3928 | |
| 3929 | // Only active documents can load post-commit error pages: |
| 3930 | // - If the document is in pending deletion, the browser already committed to |
| 3931 | // destroying this RenderFrameHost so ignore loading the error page. |
| 3932 | // - If the document is in back-forward cache, it's not allowed to navigate as |
| 3933 | // it should remain frozen. Ignore the request and evict the document from |
| 3934 | // back-forward cache. |
| 3935 | // - If the document is prerendering, it can navigate but when loading error |
| 3936 | // pages, cancel prerendering. |
Fergal Daly | 1336ac64 | 2021-09-14 15:13:11 | [diff] [blame] | 3937 | if (rfhi->IsInactiveAndDisallowActivation( |
| 3938 | DisallowActivationReasonId::kLoadPostCommitErrorPage)) { |
Kevin McNee | ccca617 | 2021-10-19 17:11:14 | [diff] [blame] | 3939 | return nullptr; |
Fergal Daly | 1336ac64 | 2021-09-14 15:13:11 | [diff] [blame] | 3940 | } |
Sreeja Kamishetty | db8e289 | 2021-03-10 09:30:58 | [diff] [blame] | 3941 | |
Rakina Zata Amni | 919b792 | 2020-12-11 09:03:13 | [diff] [blame] | 3942 | FrameTreeNode* node = rfhi->frame_tree_node(); |
John Delaney | 131ad36 | 2019-08-08 21:57:41 | [diff] [blame] | 3943 | |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 3944 | blink::mojom::CommonNavigationParamsPtr common_params = |
Minggang Wang | a13c796e | 2021-07-02 05:54:43 | [diff] [blame] | 3945 | blink::CreateCommonNavigationParams(); |
Rakina Zata Amni | d2da154 | 2020-12-23 00:52:59 | [diff] [blame] | 3946 | // |url| might be empty, such as when LoadPostCommitErrorPage happens before |
| 3947 | // the frame actually committed (e.g. iframe with "src" set to a |
| 3948 | // slow-responding URL). We should rewrite the URL to about:blank in this |
| 3949 | // case, as the renderer will only think a page is an error page if it has a |
| 3950 | // non-empty unreachable URL. |
Rakina Zata Amni | 919b792 | 2020-12-11 09:03:13 | [diff] [blame] | 3951 | common_params->url = url.is_empty() ? GURL("about:blank") : url; |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 3952 | blink::mojom::CommitNavigationParamsPtr commit_params = |
Minggang Wang | a13c796e | 2021-07-02 05:54:43 | [diff] [blame] | 3953 | blink::CreateCommitNavigationParams(); |
Antonio Sartori | 58591c89 | 2021-04-21 06:54:33 | [diff] [blame] | 3954 | commit_params->original_url = common_params->url; |
John Delaney | 131ad36 | 2019-08-08 21:57:41 | [diff] [blame] | 3955 | |
arthursonzogni | 70ac730 | 2020-05-28 08:49:05 | [diff] [blame] | 3956 | // Error pages have a fully permissive FramePolicy. |
| 3957 | // TODO(arthursonzogni): Consider providing the minimal capabilities to the |
| 3958 | // error pages. |
| 3959 | commit_params->frame_policy = blink::FramePolicy(); |
| 3960 | |
John Delaney | 131ad36 | 2019-08-08 21:57:41 | [diff] [blame] | 3961 | std::unique_ptr<NavigationRequest> navigation_request = |
| 3962 | NavigationRequest::CreateBrowserInitiated( |
| 3963 | node, std::move(common_params), std::move(commit_params), |
Takashi Toyoshima | e87b7be | 2021-01-22 11:51:08 | [diff] [blame] | 3964 | true /* browser_initiated */, false /* was_opener_suppressed */, |
Lingqi Chi | 82efa95e | 2020-12-29 05:31:19 | [diff] [blame] | 3965 | nullptr /* initiator_frame_token */, |
Antonio Sartori | 9a82f6f3 | 2020-12-14 09:22:45 | [diff] [blame] | 3966 | ChildProcessHost::kInvalidUniqueID /* initiator_process_id */, |
John Delaney | f43556d | 2020-05-04 23:19:06 | [diff] [blame] | 3967 | "" /* extra_headers */, nullptr /* frame_entry */, |
| 3968 | nullptr /* entry */, nullptr /* post_body */, |
Daniel Hosseinian | f0fbfb4 | 2021-09-08 02:20:47 | [diff] [blame] | 3969 | nullptr /* navigation_ui_data */, absl::nullopt /* impression */, |
| 3970 | false /* is_pdf */); |
Carlos IL | 42b41659 | 2019-10-07 23:10:36 | [diff] [blame] | 3971 | navigation_request->set_post_commit_error_page_html(error_page_html); |
John Delaney | 131ad36 | 2019-08-08 21:57:41 | [diff] [blame] | 3972 | navigation_request->set_net_error(error); |
| 3973 | node->CreatedNavigationRequest(std::move(navigation_request)); |
| 3974 | DCHECK(node->navigation_request()); |
Kevin McNee | ccca617 | 2021-10-19 17:11:14 | [diff] [blame] | 3975 | |
| 3976 | // Calling BeginNavigation may destroy the NavigationRequest. |
| 3977 | base::WeakPtr<NavigationRequest> created_navigation_request( |
| 3978 | node->navigation_request()->GetWeakPtr()); |
John Delaney | 131ad36 | 2019-08-08 21:57:41 | [diff] [blame] | 3979 | node->navigation_request()->BeginNavigation(); |
Kevin McNee | ccca617 | 2021-10-19 17:11:14 | [diff] [blame] | 3980 | return created_navigation_request; |
John Delaney | 131ad36 | 2019-08-08 21:57:41 | [diff] [blame] | 3981 | } |
| 3982 | |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 3983 | void NavigationControllerImpl::NotifyEntryChanged(NavigationEntry* entry) { |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 3984 | EntryChangedDetails det; |
[email protected] | 534e54b | 2008-08-13 15:40:09 | [diff] [blame] | 3985 | det.changed_entry = entry; |
Aran Gilman | 37d1163 | 2019-10-08 23:07:15 | [diff] [blame] | 3986 | det.index = GetIndexOfEntry(NavigationEntryImpl::FromNavigationEntry(entry)); |
Sam McNally | 5c087a3 | 2017-08-25 01:46:14 | [diff] [blame] | 3987 | delegate_->NotifyNavigationEntryChanged(det); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3988 | } |
| 3989 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 3990 | void NavigationControllerImpl::FinishRestore(int selected_index, |
[email protected] | 2ca1ea66 | 2012-10-04 02:26:36 | [diff] [blame] | 3991 | RestoreType type) { |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 3992 | DCHECK(selected_index >= 0 && selected_index < GetEntryCount()); |
[email protected] | 2ca1ea66 | 2012-10-04 02:26:36 | [diff] [blame] | 3993 | ConfigureEntriesForRestore(&entries_, type); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3994 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3995 | last_committed_entry_index_ = selected_index; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 3996 | } |
[email protected] | 765b3550 | 2008-08-21 00:51:20 | [diff] [blame] | 3997 | |
arthursonzogni | 69a6a1b | 2019-09-17 09:23:00 | [diff] [blame] | 3998 | void NavigationControllerImpl::DiscardNonCommittedEntries() { |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 3999 | DiscardNonCommittedEntriesWithCommitDetails(nullptr /* commit_details */); |
| 4000 | } |
| 4001 | |
| 4002 | void NavigationControllerImpl::DiscardNonCommittedEntriesWithCommitDetails( |
| 4003 | LoadCommittedDetails* commit_details) { |
Michael Thiessen | 9b14d51 | 2019-09-23 21:19:47 | [diff] [blame] | 4004 | // Avoid sending a notification if there is nothing to discard. |
Michael Thiessen | c5676d2 | 2019-09-25 22:32:10 | [diff] [blame] | 4005 | // TODO(mthiesse): Temporarily checking failed_pending_entry_id_ to help |
| 4006 | // diagnose https://bugs.chromium.org/p/chromium/issues/detail?id=1007570. |
Carlos IL | 4dea890 | 2020-05-26 15:14:29 | [diff] [blame] | 4007 | if (!pending_entry_ && failed_pending_entry_id_ == 0) { |
Michael Thiessen | 9b14d51 | 2019-09-23 21:19:47 | [diff] [blame] | 4008 | return; |
Michael Thiessen | c5676d2 | 2019-09-25 22:32:10 | [diff] [blame] | 4009 | } |
avi | 45a7253 | 2015-04-07 21:01:45 | [diff] [blame] | 4010 | DiscardPendingEntry(false); |
Rakina Zata Amni | ddf1050 | 2022-01-15 02:56:55 | [diff] [blame] | 4011 | if (delegate_) { |
Rakina Zata Amni | a4e2722 | 2021-12-22 01:05:00 | [diff] [blame] | 4012 | delegate_->NotifyNavigationStateChanged( |
Rakina Zata Amni | ddf1050 | 2022-01-15 02:56:55 | [diff] [blame] | 4013 | (commit_details && commit_details->should_stay_as_initial_entry) |
| 4014 | ? INVALIDATE_TYPE_ALL_BUT_KEEPS_INITIAL_NAVIGATION_ENTRY_STATUS |
| 4015 | : INVALIDATE_TYPE_ALL_AND_REMOVES_INITIAL_NAVIGATION_ENTRY_STATUS); |
| 4016 | } |
[email protected] | b12eb22 | 2013-09-10 00:11:48 | [diff] [blame] | 4017 | } |
| 4018 | |
avi | 7c6f35e | 2015-05-08 17:52:38 | [diff] [blame] | 4019 | int NavigationControllerImpl::GetEntryIndexWithUniqueID( |
| 4020 | int nav_entry_id) const { |
| 4021 | for (int i = static_cast<int>(entries_.size()) - 1; i >= 0; --i) { |
| 4022 | if (entries_[i]->GetUniqueID() == nav_entry_id) |
| 4023 | return i; |
| 4024 | } |
| 4025 | return -1; |
| 4026 | } |
| 4027 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 4028 | void NavigationControllerImpl::InsertEntriesFrom( |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 4029 | NavigationControllerImpl* source, |
[email protected] | e1cd545 | 2010-08-26 18:03:25 | [diff] [blame] | 4030 | int max_index) { |
Lucas Furukawa Gadani | 5553a158 | 2019-01-08 18:55:57 | [diff] [blame] | 4031 | DCHECK_LE(max_index, source->GetEntryCount()); |
Nate Chapin | 214a86a | 2021-06-21 20:35:57 | [diff] [blame] | 4032 | std::unique_ptr<NavigationEntryRestoreContextImpl> context = |
| 4033 | std::make_unique<NavigationEntryRestoreContextImpl>(); |
[email protected] | e1cd545 | 2010-08-26 18:03:25 | [diff] [blame] | 4034 | for (int i = 0; i < max_index; i++) { |
Nate Chapin | 9f16907 | 2021-06-09 19:32:37 | [diff] [blame] | 4035 | // Normally, cloning a NavigationEntryImpl results in sharing |
| 4036 | // FrameNavigationEntries between the original and the clone. However, when |
| 4037 | // cloning from a different NavigationControllerImpl, we want to fork the |
| 4038 | // FrameNavigationEntries. |
Nate Chapin | 9f16907 | 2021-06-09 19:32:37 | [diff] [blame] | 4039 | entries_.insert(entries_.begin() + i, |
Nate Chapin | 214a86a | 2021-06-21 20:35:57 | [diff] [blame] | 4040 | source->entries_[i]->CloneWithoutSharing(context.get())); |
[email protected] | e1cd545 | 2010-08-26 18:03:25 | [diff] [blame] | 4041 | } |
arthursonzogni | 5c4c202d | 2017-04-25 23:41:27 | [diff] [blame] | 4042 | DCHECK(pending_entry_index_ == -1 || |
| 4043 | pending_entry_ == GetEntryAtIndex(pending_entry_index_)); |
Rakina Zata Amni | 9055528 | 2022-01-21 07:35:54 | [diff] [blame] | 4044 | if (!source->frame_tree_.root()->is_on_initial_empty_document()) { |
| 4045 | // If the source frame tree's root is not on the initial empty document, |
| 4046 | // also mark this FrameTree's root as such, so that the next navigation |
| 4047 | // won't replace the latest NavigationEntry due to it still being marked as |
| 4048 | // "on the initial empty document". |
| 4049 | frame_tree_.root()->SetNotOnInitialEmptyDocument(); |
| 4050 | } |
[email protected] | e1cd545 | 2010-08-26 18:03:25 | [diff] [blame] | 4051 | } |
[email protected] | c5b88d8 | 2012-10-06 17:03:33 | [diff] [blame] | 4052 | |
| 4053 | void NavigationControllerImpl::SetGetTimestampCallbackForTest( |
Makoto Shimazu | d2aa220 | 2019-10-09 13:57:18 | [diff] [blame] | 4054 | const base::RepeatingCallback<base::Time()>& get_timestamp_callback) { |
[email protected] | c5b88d8 | 2012-10-06 17:03:33 | [diff] [blame] | 4055 | get_timestamp_callback_ = get_timestamp_callback; |
| 4056 | } |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4057 | |
Shivani Sharma | ffb32b8 | 2019-04-09 16:58:47 | [diff] [blame] | 4058 | // History manipulation intervention: |
| 4059 | void NavigationControllerImpl::SetShouldSkipOnBackForwardUIIfNeeded( |
Shivani Sharma | ffb32b8 | 2019-04-09 16:58:47 | [diff] [blame] | 4060 | bool replace_entry, |
| 4061 | bool previous_document_was_activated, |
Alexander Timin | e3ec419 | 2020-04-20 16:39:40 | [diff] [blame] | 4062 | bool is_renderer_initiated, |
| 4063 | ukm::SourceId previous_page_load_ukm_source_id) { |
Shivani Sharma | 712d5d7 | 2019-04-16 21:56:45 | [diff] [blame] | 4064 | // Note that for a subframe, previous_document_was_activated is true if the |
| 4065 | // gesture happened in any subframe (propagated to main frame) or in the main |
| 4066 | // frame itself. |
Shivani Sharma | ffb32b8 | 2019-04-09 16:58:47 | [diff] [blame] | 4067 | if (replace_entry || previous_document_was_activated || |
shivanigithub | cceeacf | 2020-03-06 20:00:27 | [diff] [blame] | 4068 | !is_renderer_initiated) { |
Shivani Sharma | ffb32b8 | 2019-04-09 16:58:47 | [diff] [blame] | 4069 | return; |
| 4070 | } |
| 4071 | if (last_committed_entry_index_ == -1) |
| 4072 | return; |
| 4073 | |
Shivani Sharma | c4cc892 | 2019-04-18 03:11:17 | [diff] [blame] | 4074 | SetSkippableForSameDocumentEntries(last_committed_entry_index_, true); |
Shivani Sharma | ffb32b8 | 2019-04-09 16:58:47 | [diff] [blame] | 4075 | |
Alexander Timin | e3ec419 | 2020-04-20 16:39:40 | [diff] [blame] | 4076 | // Log UKM with the URL we are navigating away from. |
| 4077 | ukm::builders::HistoryManipulationIntervention( |
| 4078 | previous_page_load_ukm_source_id) |
| 4079 | .Record(ukm::UkmRecorder::Get()); |
Shivani Sharma | ffb32b8 | 2019-04-09 16:58:47 | [diff] [blame] | 4080 | } |
| 4081 | |
Shivani Sharma | c4cc892 | 2019-04-18 03:11:17 | [diff] [blame] | 4082 | void NavigationControllerImpl::SetSkippableForSameDocumentEntries( |
| 4083 | int reference_index, |
| 4084 | bool skippable) { |
| 4085 | auto* reference_entry = GetEntryAtIndex(reference_index); |
| 4086 | reference_entry->set_should_skip_on_back_forward_ui(skippable); |
| 4087 | |
| 4088 | int64_t document_sequence_number = |
| 4089 | reference_entry->root_node()->frame_entry->document_sequence_number(); |
| 4090 | for (int index = 0; index < GetEntryCount(); index++) { |
| 4091 | auto* entry = GetEntryAtIndex(index); |
| 4092 | if (entry->root_node()->frame_entry->document_sequence_number() == |
| 4093 | document_sequence_number) { |
| 4094 | entry->set_should_skip_on_back_forward_ui(skippable); |
| 4095 | } |
| 4096 | } |
| 4097 | } |
| 4098 | |
arthursonzogni | 66f711c | 2019-10-08 14:40:36 | [diff] [blame] | 4099 | std::unique_ptr<NavigationControllerImpl::PendingEntryRef> |
| 4100 | NavigationControllerImpl::ReferencePendingEntry() { |
| 4101 | DCHECK(pending_entry_); |
| 4102 | auto pending_entry_ref = |
| 4103 | std::make_unique<PendingEntryRef>(weak_factory_.GetWeakPtr()); |
| 4104 | pending_entry_refs_.insert(pending_entry_ref.get()); |
| 4105 | return pending_entry_ref; |
| 4106 | } |
| 4107 | |
| 4108 | void NavigationControllerImpl::PendingEntryRefDeleted(PendingEntryRef* ref) { |
| 4109 | // Ignore refs that don't correspond to the current pending entry. |
| 4110 | auto it = pending_entry_refs_.find(ref); |
| 4111 | if (it == pending_entry_refs_.end()) |
| 4112 | return; |
| 4113 | pending_entry_refs_.erase(it); |
| 4114 | |
| 4115 | if (!pending_entry_refs_.empty()) |
| 4116 | return; |
| 4117 | |
| 4118 | // The pending entry may be deleted before the last PendingEntryRef. |
| 4119 | if (!pending_entry_) |
| 4120 | return; |
| 4121 | |
| 4122 | // We usually clear the pending entry when the matching NavigationRequest |
| 4123 | // fails, so that an arbitrary URL isn't left visible above a committed page. |
| 4124 | // |
| 4125 | // However, we do preserve the pending entry in some cases, such as on the |
| 4126 | // initial navigation of an unmodified blank tab. We also allow the delegate |
| 4127 | // to say when it's safe to leave aborted URLs in the omnibox, to let the |
| 4128 | // user edit the URL and try again. This may be useful in cases that the |
| 4129 | // committed page cannot be attacker-controlled. In these cases, we still |
| 4130 | // allow the view to clear the pending entry and typed URL if the user |
| 4131 | // requests (e.g., hitting Escape with focus in the address bar). |
| 4132 | // |
| 4133 | // Do not leave the pending entry visible if it has an invalid URL, since this |
| 4134 | // might be formatted in an unexpected or unsafe way. |
| 4135 | // TODO(creis): Block navigations to invalid URLs in https://crbug.com/850824. |
arthursonzogni | 66f711c | 2019-10-08 14:40:36 | [diff] [blame] | 4136 | bool should_preserve_entry = |
| 4137 | (pending_entry_ == GetVisibleEntry()) && |
| 4138 | pending_entry_->GetURL().is_valid() && |
| 4139 | (IsUnmodifiedBlankTab() || delegate_->ShouldPreserveAbortedURLs()); |
| 4140 | if (should_preserve_entry) |
| 4141 | return; |
| 4142 | |
| 4143 | DiscardPendingEntry(true); |
| 4144 | delegate_->NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); |
| 4145 | } |
| 4146 | |
Titouan Rigoudy | 6ec7040 | 2021-02-02 15:42:19 | [diff] [blame] | 4147 | std::unique_ptr<PolicyContainerPolicies> |
| 4148 | NavigationControllerImpl::ComputePolicyContainerPoliciesForFrameEntry( |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 4149 | RenderFrameHostImpl* rfh, |
| 4150 | bool is_same_document, |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 4151 | const GURL& url) { |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 4152 | if (is_same_document) { |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 4153 | // TODO(https://crbug.com/524208): Remove this nullptr check when we can |
| 4154 | // ensure we always have a FrameNavigationEntry here. |
| 4155 | if (!GetLastCommittedEntry()) |
| 4156 | return nullptr; |
Charlie Reis | 73e35624 | 2021-04-02 17:10:31 | [diff] [blame] | 4157 | |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 4158 | FrameNavigationEntry* previous_frame_entry = |
| 4159 | GetLastCommittedEntry()->GetFrameEntry(rfh->frame_tree_node()); |
| 4160 | |
| 4161 | // TODO(https://crbug.com/608402): Remove this nullptr check when we can |
| 4162 | // ensure we always have a FrameNavigationEntry here. |
| 4163 | if (!previous_frame_entry) |
| 4164 | return nullptr; |
| 4165 | |
Titouan Rigoudy | 6ec7040 | 2021-02-02 15:42:19 | [diff] [blame] | 4166 | const PolicyContainerPolicies* previous_policies = |
| 4167 | previous_frame_entry->policy_container_policies(); |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 4168 | |
Titouan Rigoudy | 6ec7040 | 2021-02-02 15:42:19 | [diff] [blame] | 4169 | if (!previous_policies) |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 4170 | return nullptr; |
| 4171 | |
| 4172 | // Make a copy of the policy container for the new FrameNavigationEntry. |
Antonio Sartori | 5d09b30f | 2021-03-02 09:27:16 | [diff] [blame] | 4173 | return previous_policies->Clone(); |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 4174 | } |
| 4175 | |
Antonio Sartori | 4f537379 | 2021-05-31 10:56:47 | [diff] [blame] | 4176 | return rfh->policy_container_host()->policies().Clone(); |
Antonio Sartori | 78a749f | 2020-11-30 12:03:39 | [diff] [blame] | 4177 | } |
| 4178 | |
Hayato Ito | 2c8c08d0 | 2021-06-23 03:38:43 | [diff] [blame] | 4179 | void NavigationControllerImpl::BroadcastHistoryOffsetAndLength() { |
Carlos Caballero | ede6f8c | 2021-01-28 11:01:50 | [diff] [blame] | 4180 | OPTIONAL_TRACE_EVENT2( |
Hayato Ito | 2c8c08d0 | 2021-06-23 03:38:43 | [diff] [blame] | 4181 | "content", "NavigationControllerImpl::BroadcastHistoryOffsetAndLength", |
| 4182 | "history_offset", GetLastCommittedEntryIndex(), "history_length", |
| 4183 | GetEntryCount()); |
Carlos Caballero | ede6f8c | 2021-01-28 11:01:50 | [diff] [blame] | 4184 | |
| 4185 | auto callback = base::BindRepeating( |
| 4186 | [](int history_offset, int history_length, RenderViewHostImpl* rvh) { |
| 4187 | if (auto& broadcast = rvh->GetAssociatedPageBroadcast()) { |
| 4188 | broadcast->SetHistoryOffsetAndLength(history_offset, history_length); |
| 4189 | } |
| 4190 | }, |
Hayato Ito | 2c8c08d0 | 2021-06-23 03:38:43 | [diff] [blame] | 4191 | GetLastCommittedEntryIndex(), GetEntryCount()); |
Carlos Caballero | ede6f8c | 2021-01-28 11:01:50 | [diff] [blame] | 4192 | frame_tree_.root()->render_manager()->ExecutePageBroadcastMethod(callback); |
| 4193 | } |
| 4194 | |
| 4195 | void NavigationControllerImpl::DidAccessInitialMainDocument() { |
| 4196 | // We may have left a failed browser-initiated navigation in the address bar |
| 4197 | // to let the user edit it and try again. Clear it now that content might |
| 4198 | // show up underneath it. |
| 4199 | if (!frame_tree_.IsLoading() && GetPendingEntry()) |
| 4200 | DiscardPendingEntry(false); |
| 4201 | |
| 4202 | // Update the URL display. |
| 4203 | delegate_->NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); |
| 4204 | } |
| 4205 | |
| 4206 | void NavigationControllerImpl::UpdateStateForFrame( |
| 4207 | RenderFrameHostImpl* rfhi, |
| 4208 | const blink::PageState& page_state) { |
Alexander Timin | f785f34 | 2021-03-18 00:00:56 | [diff] [blame] | 4209 | OPTIONAL_TRACE_EVENT1("content", |
| 4210 | "NavigationControllerImpl::UpdateStateForFrame", |
| 4211 | "render_frame_host", rfhi); |
Carlos Caballero | ede6f8c | 2021-01-28 11:01:50 | [diff] [blame] | 4212 | // The state update affects the last NavigationEntry associated with the given |
| 4213 | // |render_frame_host|. This may not be the last committed NavigationEntry (as |
| 4214 | // in the case of an UpdateState from a frame being swapped out). We track |
| 4215 | // which entry this is in the RenderFrameHost's nav_entry_id. |
| 4216 | NavigationEntryImpl* entry = GetEntryWithUniqueID(rfhi->nav_entry_id()); |
| 4217 | if (!entry) |
| 4218 | return; |
| 4219 | |
| 4220 | FrameNavigationEntry* frame_entry = |
| 4221 | entry->GetFrameEntry(rfhi->frame_tree_node()); |
| 4222 | if (!frame_entry) |
| 4223 | return; |
| 4224 | |
| 4225 | // The SiteInstance might not match if we do a cross-process navigation with |
| 4226 | // replacement (e.g., auto-subframe), in which case the swap out of the old |
| 4227 | // RenderFrameHost runs in the background after the old FrameNavigationEntry |
| 4228 | // has already been replaced and destroyed. |
| 4229 | if (frame_entry->site_instance() != rfhi->GetSiteInstance()) |
| 4230 | return; |
| 4231 | |
| 4232 | if (page_state == frame_entry->page_state()) |
| 4233 | return; // Nothing to update. |
| 4234 | |
| 4235 | DCHECK(page_state.IsValid()) << "Shouldn't set an empty PageState."; |
| 4236 | |
| 4237 | // The document_sequence_number and item_sequence_number recorded in the |
| 4238 | // FrameNavigationEntry should not differ from the one coming with the update, |
| 4239 | // since it must come from the same document. Do not update it if a difference |
| 4240 | // is detected, as this indicates that |frame_entry| is not the correct one. |
| 4241 | blink::ExplodedPageState exploded_state; |
| 4242 | if (!blink::DecodePageState(page_state.ToEncodedData(), &exploded_state)) |
| 4243 | return; |
| 4244 | |
| 4245 | if (exploded_state.top.document_sequence_number != |
| 4246 | frame_entry->document_sequence_number() || |
| 4247 | exploded_state.top.item_sequence_number != |
| 4248 | frame_entry->item_sequence_number()) { |
| 4249 | return; |
| 4250 | } |
| 4251 | |
| 4252 | frame_entry->SetPageState(page_state); |
| 4253 | NotifyEntryChanged(entry); |
| 4254 | } |
| 4255 | |
Aaron Colwell | b731a0ae | 2021-03-19 19:14:47 | [diff] [blame] | 4256 | void NavigationControllerImpl::OnStoragePartitionIdAdded( |
| 4257 | const StoragePartitionId& partition_id) { |
| 4258 | auto it = partition_config_to_id_map_.insert( |
| 4259 | std::make_pair(partition_id.config(), partition_id)); |
| 4260 | bool successful_insert = it.second; |
Aaron Colwell | b731a0ae | 2021-03-19 19:14:47 | [diff] [blame] | 4261 | if (!successful_insert) { |
| 4262 | LogStoragePartitionIdCrashKeys(it.first->second, partition_id); |
| 4263 | } |
Sharon Yang | d4f4879 | 2021-06-30 17:02:53 | [diff] [blame] | 4264 | CHECK(successful_insert); |
Aaron Colwell | b731a0ae | 2021-03-19 19:14:47 | [diff] [blame] | 4265 | } |
| 4266 | |
| 4267 | void NavigationControllerImpl::LogStoragePartitionIdCrashKeys( |
| 4268 | const StoragePartitionId& original_partition_id, |
| 4269 | const StoragePartitionId& new_partition_id) { |
| 4270 | base::debug::SetCrashKeyString( |
| 4271 | base::debug::AllocateCrashKeyString("original_partition_id", |
| 4272 | base::debug::CrashKeySize::Size256), |
| 4273 | original_partition_id.ToString()); |
| 4274 | |
| 4275 | base::debug::SetCrashKeyString( |
| 4276 | base::debug::AllocateCrashKeyString("new_partition_id", |
| 4277 | base::debug::CrashKeySize::Size256), |
| 4278 | new_partition_id.ToString()); |
Aaron Colwell | b731a0ae | 2021-03-19 19:14:47 | [diff] [blame] | 4279 | } |
| 4280 | |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 4281 | std::vector<blink::mojom::AppHistoryEntryPtr> |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4282 | NavigationControllerImpl::PopulateSingleAppHistoryEntryVector( |
| 4283 | Direction direction, |
| 4284 | int entry_index, |
| 4285 | const url::Origin& pending_origin, |
| 4286 | FrameTreeNode* node, |
| 4287 | SiteInstance* site_instance, |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 4288 | int64_t pending_item_sequence_number, |
| 4289 | int64_t pending_document_sequence_number) { |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 4290 | std::vector<blink::mojom::AppHistoryEntryPtr> entries; |
Rakina Zata Amni | 2322f4f8 | 2022-01-24 13:24:24 | [diff] [blame^] | 4291 | if (GetLastCommittedEntry() && GetLastCommittedEntry()->IsInitialEntry()) { |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 4292 | // Don't process the initial entry. |
| 4293 | DCHECK_EQ(GetEntryCount(), 1); |
| 4294 | return entries; |
| 4295 | } |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4296 | int offset = direction == Direction::kForward ? 1 : -1; |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 4297 | int64_t previous_item_sequence_number = pending_item_sequence_number; |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4298 | for (int i = entry_index + offset; i >= 0 && i < GetEntryCount(); |
| 4299 | i += offset) { |
| 4300 | FrameNavigationEntry* frame_entry = GetEntryAtIndex(i)->GetFrameEntry(node); |
| 4301 | if (!frame_entry || !frame_entry->committed_origin()) |
| 4302 | break; |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4303 | if (!pending_origin.IsSameOriginWith(*frame_entry->committed_origin())) |
| 4304 | break; |
| 4305 | if (previous_item_sequence_number == frame_entry->item_sequence_number()) |
| 4306 | continue; |
| 4307 | blink::ExplodedPageState exploded_page_state; |
| 4308 | if (blink::DecodePageState(frame_entry->page_state().ToEncodedData(), |
| 4309 | &exploded_page_state)) { |
| 4310 | blink::ExplodedFrameState frame_state = exploded_page_state.top; |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 4311 | |
| 4312 | // If the document represented by this FNE hid its full url from appearing |
| 4313 | // in a referrer via a "no-referrer" or "origin" referrer policy, censor |
| 4314 | // the url in appHistory as well (unless we're navigating to that |
| 4315 | // document). |
| 4316 | std::u16string url; |
| 4317 | if (pending_document_sequence_number == |
| 4318 | frame_entry->document_sequence_number() || |
| 4319 | !frame_entry->protect_url_in_app_history()) { |
| 4320 | url = frame_state.url_string.value_or(std::u16string()); |
| 4321 | } |
| 4322 | |
Minggang Wang | b9f3fa9 | 2021-07-01 15:30:31 | [diff] [blame] | 4323 | blink::mojom::AppHistoryEntryPtr entry = |
| 4324 | blink::mojom::AppHistoryEntry::New( |
| 4325 | frame_state.app_history_key.value_or(std::u16string()), |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 4326 | frame_state.app_history_id.value_or(std::u16string()), url, |
Nate Chapin | ab5c3a71 | 2021-11-18 22:17:09 | [diff] [blame] | 4327 | frame_state.item_sequence_number, |
| 4328 | frame_state.document_sequence_number, |
| 4329 | frame_state.app_history_state.value_or(std::u16string())); |
Rakina Zata Amni | afd3c658 | 2021-11-30 06:19:17 | [diff] [blame] | 4330 | |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 4331 | DCHECK(entry->url.empty() || |
| 4332 | pending_origin.CanBeDerivedFrom(GURL(entry->url))); |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4333 | entries.push_back(std::move(entry)); |
| 4334 | previous_item_sequence_number = frame_entry->item_sequence_number(); |
| 4335 | } |
| 4336 | } |
| 4337 | // If |entries| was constructed by iterating backwards from |
| 4338 | // |entry_index|, it's latest-at-the-front, but the renderer will want it |
| 4339 | // earliest-at-the-front. Reverse it. |
| 4340 | if (direction == Direction::kBack) |
| 4341 | std::reverse(entries.begin(), entries.end()); |
| 4342 | return entries; |
| 4343 | } |
| 4344 | |
| 4345 | void NavigationControllerImpl::PopulateAppHistoryEntryVectors( |
| 4346 | NavigationRequest* request) { |
| 4347 | url::Origin pending_origin = |
| 4348 | request->commit_params().origin_to_commit |
| 4349 | ? *request->commit_params().origin_to_commit |
| 4350 | : url::Origin::Create(request->common_params().url); |
| 4351 | |
| 4352 | FrameTreeNode* node = request->frame_tree_node(); |
| 4353 | scoped_refptr<SiteInstance> site_instance = |
| 4354 | request->GetRenderFrameHost()->GetSiteInstance(); |
| 4355 | |
| 4356 | // NOTE: |entry_index| is an estimate of the index where this entry will |
| 4357 | // commit, but it may be wrong in corner cases (e.g., if we are at the max |
| 4358 | // entry limit, the earliest entry will be dropped). This is ok because this |
| 4359 | // algorithm only uses |entry_index| to walk the entry list as it stands right |
| 4360 | // now, and it isn't saved for anything post-commit. |
| 4361 | int entry_index = GetPendingEntryIndex(); |
| 4362 | bool will_create_new_entry = false; |
| 4363 | if (NavigationTypeUtils::IsReload(request->common_params().navigation_type) || |
| 4364 | request->common_params().should_replace_current_entry) { |
| 4365 | entry_index = GetLastCommittedEntryIndex(); |
| 4366 | } else if (entry_index == -1) { |
| 4367 | will_create_new_entry = true; |
| 4368 | entry_index = GetLastCommittedEntryIndex() + 1; |
| 4369 | } |
| 4370 | |
| 4371 | int64_t pending_item_sequence_number = 0; |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 4372 | int64_t pending_document_sequence_number = 0; |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4373 | if (auto* pending_entry = GetPendingEntry()) { |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 4374 | if (auto* frame_entry = pending_entry->GetFrameEntry(node)) { |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4375 | pending_item_sequence_number = frame_entry->item_sequence_number(); |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 4376 | pending_document_sequence_number = |
| 4377 | frame_entry->document_sequence_number(); |
| 4378 | } |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4379 | } |
| 4380 | |
| 4381 | request->set_app_history_back_entries(PopulateSingleAppHistoryEntryVector( |
| 4382 | Direction::kBack, entry_index, pending_origin, node, site_instance.get(), |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 4383 | pending_item_sequence_number, pending_document_sequence_number)); |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4384 | |
| 4385 | // Don't populate forward entries if they will be truncated by a new entry. |
| 4386 | if (!will_create_new_entry) { |
| 4387 | request->set_app_history_forward_entries( |
| 4388 | PopulateSingleAppHistoryEntryVector( |
| 4389 | Direction::kForward, entry_index, pending_origin, node, |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 4390 | site_instance.get(), pending_item_sequence_number, |
| 4391 | pending_document_sequence_number)); |
Nate Chapin | d1fe361 | 2021-04-16 20:45:57 | [diff] [blame] | 4392 | } |
| 4393 | } |
| 4394 | |
Nate Chapin | fbfe5af | 2021-06-10 17:22:08 | [diff] [blame] | 4395 | NavigationControllerImpl::HistoryNavigationAction |
| 4396 | NavigationControllerImpl::ShouldNavigateToEntryForAppHistoryKey( |
| 4397 | FrameNavigationEntry* current_entry, |
| 4398 | FrameNavigationEntry* target_entry, |
| 4399 | const std::string& app_history_key) { |
| 4400 | if (!target_entry || !target_entry->committed_origin()) |
| 4401 | return HistoryNavigationAction::kStopLooking; |
| 4402 | if (current_entry->site_instance() != target_entry->site_instance()) |
| 4403 | return HistoryNavigationAction::kStopLooking; |
| 4404 | if (!current_entry->committed_origin()->IsSameOriginWith( |
| 4405 | *target_entry->committed_origin())) { |
| 4406 | return HistoryNavigationAction::kStopLooking; |
| 4407 | } |
| 4408 | |
| 4409 | // NOTE: We don't actually care between kSameDocument and |
| 4410 | // kDifferentDocument, so always use kDifferentDocument by convention. |
| 4411 | if (target_entry->app_history_key() == app_history_key) |
| 4412 | return HistoryNavigationAction::kDifferentDocument; |
| 4413 | return HistoryNavigationAction::kKeepLooking; |
| 4414 | } |
| 4415 | |
| 4416 | void NavigationControllerImpl::NavigateToAppHistoryKey(FrameTreeNode* node, |
| 4417 | const std::string& key) { |
| 4418 | FrameNavigationEntry* current_entry = |
| 4419 | GetLastCommittedEntry()->GetFrameEntry(node); |
| 4420 | if (!current_entry) |
| 4421 | return; |
| 4422 | |
| 4423 | // We want to find the nearest matching entry that is contiguously |
| 4424 | // same-instance and same-origin. Check back first, then forward. |
| 4425 | // TODO(japhet): Link spec here once it exists. |
| 4426 | for (int i = GetCurrentEntryIndex() - 1; i >= 0; i--) { |
| 4427 | auto result = ShouldNavigateToEntryForAppHistoryKey( |
| 4428 | current_entry, GetEntryAtIndex(i)->GetFrameEntry(node), key); |
| 4429 | if (result == HistoryNavigationAction::kStopLooking) |
| 4430 | break; |
| 4431 | if (result != HistoryNavigationAction::kKeepLooking) { |
Nate Chapin | 2892b37c | 2021-10-08 17:33:11 | [diff] [blame] | 4432 | GoToIndex(i, FrameTreeNode::kFrameTreeNodeInvalidId, |
| 4433 | false /* is_browser_initiated*/); |
Nate Chapin | fbfe5af | 2021-06-10 17:22:08 | [diff] [blame] | 4434 | return; |
| 4435 | } |
| 4436 | } |
| 4437 | for (int i = GetCurrentEntryIndex() + 1; i < GetEntryCount(); i++) { |
| 4438 | auto result = ShouldNavigateToEntryForAppHistoryKey( |
| 4439 | current_entry, GetEntryAtIndex(i)->GetFrameEntry(node), key); |
| 4440 | if (result == HistoryNavigationAction::kStopLooking) |
| 4441 | break; |
| 4442 | if (result != HistoryNavigationAction::kKeepLooking) { |
Nate Chapin | 2892b37c | 2021-10-08 17:33:11 | [diff] [blame] | 4443 | GoToIndex(i, FrameTreeNode::kFrameTreeNodeInvalidId, |
| 4444 | false /* is_browser_initiated*/); |
Nate Chapin | fbfe5af | 2021-06-10 17:22:08 | [diff] [blame] | 4445 | return; |
| 4446 | } |
| 4447 | } |
| 4448 | } |
| 4449 | |
Nate Chapin | 63db0d1 | 2022-01-20 22:03:30 | [diff] [blame] | 4450 | bool NavigationControllerImpl::ShouldProtectUrlInAppHistory( |
| 4451 | network::mojom::ReferrerPolicy referrer_policy) { |
| 4452 | return referrer_policy == network::mojom::ReferrerPolicy::kNever || |
| 4453 | referrer_policy == network::mojom::ReferrerPolicy::kOrigin; |
| 4454 | } |
| 4455 | |
shivanigithub | f405bf0d | 2021-11-05 17:58:33 | [diff] [blame] | 4456 | bool NavigationControllerImpl::ShouldMaintainTrivialSessionHistory( |
| 4457 | const FrameTreeNode* frame_tree_node) const { |
| 4458 | // TODO(https://crbug.com/1197384): We may have to add portals in addition to |
| 4459 | // prerender and fenced frames. This should be kept in sync with |
Hayato Ito | 7a80db4 | 2021-07-05 06:18:54 | [diff] [blame] | 4460 | // LocalFrame version, LocalFrame::ShouldMaintainTrivialSessionHistory. |
shivanigithub | f405bf0d | 2021-11-05 17:58:33 | [diff] [blame] | 4461 | return frame_tree_.is_prerendering() || |
| 4462 | frame_tree_node->IsInFencedFrameTree(); |
Hayato Ito | 7a80db4 | 2021-07-05 06:18:54 | [diff] [blame] | 4463 | } |
| 4464 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4465 | } // namespace content |