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