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