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