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