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