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