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