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