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