blob: ff2f261fea97f8b780ded0c4ca575cf03778ad46 [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2014 The Chromium Authors
danakjc492bf82020-09-09 20:02:442// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef CONTENT_BROWSER_RENDERER_HOST_NAVIGATION_REQUEST_H_
6#define CONTENT_BROWSER_RENDERER_HOST_NAVIGATION_REQUEST_H_
7
8#include <memory>
Arthur Sonzognic686e8f2024-01-11 08:36:379#include <optional>
Cammie Smith Barnesa0da2cf2021-01-11 22:09:3710#include <string>
Daniel Chengd08a43a2023-03-16 05:10:5011#include <utility>
Cammie Smith Barnesa0da2cf2021-01-11 22:09:3712#include <vector>
danakjc492bf82020-09-09 20:02:4413
Lukasz Anforowicz0e07b7652021-06-04 18:27:5114#include "base/debug/crash_logging.h"
Avi Drissmanadac21992023-01-11 23:46:3915#include "base/functional/callback.h"
16#include "base/functional/callback_forward.h"
Keishi Hattori0e45c022021-11-27 09:25:5217#include "base/memory/raw_ptr.h"
Keishi Hattori130ae0a2023-03-27 03:48:4718#include "base/memory/raw_ptr_exclusion.h"
David Bokan42f8dc22022-02-23 17:33:2819#include "base/memory/safe_ref.h"
danakjc492bf82020-09-09 20:02:4420#include "base/memory/weak_ptr.h"
danakjc492bf82020-09-09 20:02:4421#include "base/strings/string_util.h"
22#include "base/time/time.h"
23#include "base/timer/timer.h"
24#include "build/build_config.h"
Matt Menke4e209082021-11-09 04:59:3125#include "content/browser/fenced_frame/fenced_frame_url_mapping.h"
Ming-Ying Chung977404c2023-11-08 12:30:1026#include "content/browser/loader/keep_alive_url_loader_service.h"
danakjc492bf82020-09-09 20:02:4427#include "content/browser/loader/navigation_url_loader_delegate.h"
Yao Xiao58c2f2c2023-05-16 20:05:1828#include "content/browser/loader/subresource_proxying_url_loader_service.h"
danakjc492bf82020-09-09 20:02:4429#include "content/browser/navigation_subresource_loader_params.h"
Keita Suzuki633dd4862025-08-02 01:59:1030#include "content/browser/preloading/prerender/reserved_prerender_host_info.h"
Jiacheng Guo2d8489d72025-08-18 06:51:1431#include "content/browser/prerender_host_id.h"
Lei Zhanga4ddcf652023-03-02 18:54:0632#include "content/browser/renderer_host/browsing_context_group_swap.h"
David Bokan1bdb3701f2021-04-30 22:02:3533#include "content/browser/renderer_host/commit_deferring_condition_runner.h"
Giovanni Ortuño Urquidie0a77b42025-03-28 14:31:3534#include "content/browser/renderer_host/cookie_access_observers.h"
danakjc492bf82020-09-09 20:02:4435#include "content/browser/renderer_host/navigation_controller_impl.h"
Titouan Rigoudy4f2819532022-04-29 15:35:5336#include "content/browser/renderer_host/navigation_policy_container_builder.h"
Takashi Toyoshima96a07bb2025-06-06 06:45:5837#include "content/browser/renderer_host/navigation_throttle_registry_impl.h"
Miyoung Shin3299cbf2022-11-22 01:41:1038#include "content/browser/renderer_host/navigation_type.h"
Antonio Sartori5ecc8b932021-03-05 06:56:1039#include "content/browser/renderer_host/render_frame_host_impl.h"
Khushal Sagar91b544222024-03-12 17:36:5940#include "content/browser/renderer_host/scoped_view_transition_resources.h"
Camille Lamy103a1b282024-04-17 01:11:3641#include "content/browser/security/coop/cross_origin_opener_policy_status.h"
Camille Lamy36afacd2025-01-16 14:25:1842#include "content/browser/security/dip/document_isolation_policy_reporter.h"
danakjc492bf82020-09-09 20:02:4443#include "content/browser/site_instance_impl.h"
Rakina Zata Amnia2292302023-04-04 06:22:1144#include "content/browser/webui/web_ui_controller_factory_registry.h"
Stephan Hartmannfd0369712023-04-10 07:05:5945#include "content/browser/webui/web_ui_impl.h"
danakjc492bf82020-09-09 20:02:4446#include "content/common/content_export.h"
arthursonzogni73fe3212020-11-17 13:24:0747#include "content/common/navigation_client.mojom-forward.h"
Keita Suzukif300e442025-07-16 07:38:1148#include "content/public/browser/error_navigation_trigger.h"
danakjc492bf82020-09-09 20:02:4449#include "content/public/browser/global_routing_id.h"
50#include "content/public/browser/navigation_handle.h"
51#include "content/public/browser/navigation_throttle.h"
Kouhei Ueno3f37992b2023-11-09 23:29:0252#include "content/public/browser/preloading_trigger_type.h"
danakjc492bf82020-09-09 20:02:4453#include "content/public/browser/render_process_host_observer.h"
Jeremy Roman04ad4e3f2021-12-22 18:54:5454#include "content/public/browser/weak_document_ptr.h"
Rakina Zata Amnia2292302023-04-04 06:22:1155#include "content/public/browser/web_ui_controller.h"
Patrick Monette779c1542025-01-17 17:18:3656#include "content/public/common/content_constants.h"
danakjc492bf82020-09-09 20:02:4457#include "mojo/public/cpp/bindings/associated_remote.h"
58#include "mojo/public/cpp/bindings/pending_associated_remote.h"
59#include "mojo/public/cpp/bindings/pending_remote.h"
60#include "mojo/public/cpp/system/data_pipe.h"
Igor Ruvinovdcb81982023-06-21 22:22:1761#include "mojo/public/cpp/system/simple_watcher.h"
Matt Menke7f2e1ac52020-12-10 01:16:1062#include "net/base/isolation_info.h"
danakjc492bf82020-09-09 20:02:4463#include "net/dns/public/resolve_error_info.h"
Tsuyoshi Horo3023b5d2023-11-28 21:40:3164#include "net/http/http_connection_info.h"
Hayato Ito5750b442025-05-29 02:38:0665#include "services/metrics/public/cpp/ukm_builders.h"
danakjc492bf82020-09-09 20:02:4466#include "services/metrics/public/cpp/ukm_source_id.h"
Antonio Sartori5ecc8b932021-03-05 06:56:1067#include "services/network/public/cpp/content_security_policy/csp_context.h"
danakjc492bf82020-09-09 20:02:4468#include "services/network/public/mojom/blocked_by_response_reason.mojom-shared.h"
69#include "services/network/public/mojom/content_security_policy.mojom.h"
Tsuyoshi Horobcd0b9f62023-06-28 11:35:3270#include "services/network/public/mojom/shared_dictionary_access_observer.mojom.h"
Steven Valdeza06f680c2023-03-21 19:00:1071#include "services/network/public/mojom/trust_token_access_observer.mojom-shared.h"
danakjc492bf82020-09-09 20:02:4472#include "services/network/public/mojom/web_sandbox_flags.mojom-shared.h"
sbinglera07ae732022-12-02 20:49:0573#include "third_party/blink/public/common/runtime_feature_state/runtime_feature_state_context.h"
Chris Hamilton83272dc2021-02-23 00:24:0274#include "third_party/blink/public/common/tokens/tokens.h"
Mike Jackson82654a3a2025-02-13 07:48:2275#include "third_party/blink/public/mojom/confidence_level.mojom.h"
Kouhei Uenoa0297b0b2023-06-15 05:39:4876#include "third_party/blink/public/mojom/lcp_critical_path_predictor/lcp_critical_path_predictor.mojom.h"
Henrique Ferreiro621b3ad2021-02-15 12:51:4177#include "third_party/blink/public/mojom/loader/mixed_content.mojom-forward.h"
Yao Xiao720ef9d62022-12-09 05:18:2978#include "third_party/blink/public/mojom/navigation/navigation_initiator_activation_and_ad_status.mojom.h"
Minggang Wangb9f3fa92021-07-01 15:30:3179#include "third_party/blink/public/mojom/navigation/navigation_params.mojom-forward.h"
Lukasz Anforowicz36d24d32022-02-15 19:02:5380#include "url/gurl.h"
Lei Zhangb570a3f2025-06-17 20:19:2281#include "url/gurl_debug.h"
Lukasz Anforowicz0e07b7652021-06-04 18:27:5182#include "url/origin.h"
Lei Zhangb570a3f2025-06-17 20:19:2283#include "url/origin_debug.h"
danakjc492bf82020-09-09 20:02:4484
Xiaohan Wang7f8052e02022-01-14 18:44:2885#if BUILDFLAG(IS_ANDROID)
danakjc492bf82020-09-09 20:02:4486#include "base/android/scoped_java_ref.h"
87#include "content/browser/android/navigation_handle_proxy.h"
88#endif
89
danakjc492bf82020-09-09 20:02:4490namespace network {
Yoav Weiss93d38b502025-05-06 15:55:5191struct IntegrityPolicy;
danakjc492bf82020-09-09 20:02:4492struct URLLoaderCompletionStatus;
93} // namespace network
94
Clark DuVall3d91432d2021-12-07 20:29:4495namespace ui {
96class CompositorLock;
97} // namespace ui
98
danakjc492bf82020-09-09 20:02:4499namespace content {
100
Camille Lamyd1f015d2024-07-06 14:14:10101class AgentClusterKey;
danakjc492bf82020-09-09 20:02:44102class CrossOriginEmbedderPolicyReporter;
danakjc492bf82020-09-09 20:02:44103class FrameTreeNode;
danakjc492bf82020-09-09 20:02:44104class NavigationUIData;
Lei Zhanga4ddcf652023-03-02 18:54:06105class NavigationURLLoader;
danakjc492bf82020-09-09 20:02:44106class NavigatorDelegate;
107class PrefetchedSignedExchangeCache;
Lei Zhanga4ddcf652023-03-02 18:54:06108class PrerenderHostRegistry;
109class RenderFrameHostCSPContext;
danakjc492bf82020-09-09 20:02:44110class ServiceWorkerMainResourceHandle;
Lei Zhanga4ddcf652023-03-02 18:54:06111class SubframeHistoryNavigationThrottle;
danakjc492bf82020-09-09 20:02:44112
Matt Falkenhagen54adeaa2021-07-06 14:10:00113// The primary implementation of NavigationHandle.
114//
115// Lives from navigation start until the navigation has been committed.
danakjc492bf82020-09-09 20:02:44116class CONTENT_EXPORT NavigationRequest
117 : public NavigationHandle,
118 public NavigationURLLoaderDelegate,
David Bokan1bdb3701f2021-04-30 22:02:35119 public CommitDeferringConditionRunner::Delegate,
Yao Xiao6e1f7d32022-01-07 03:28:40120 public FencedFrameURLMapping::MappingResultObserver,
Rakina Zata Amniaf55b5b62022-07-19 23:11:03121 public mojom::NavigationRendererCancellationListener,
danakjc492bf82020-09-09 20:02:44122 private RenderProcessHostObserver,
Tsuyoshi Horobcd0b9f62023-06-28 11:35:32123 private network::mojom::TrustTokenAccessObserver,
Daniel Rubery6420d74302024-11-19 01:42:40124 private network::mojom::SharedDictionaryAccessObserver,
125 public network::mojom::DeviceBoundSessionAccessObserver {
danakjc492bf82020-09-09 20:02:44126 public:
127 // Keeps track of the various stages of a NavigationRequest.
128 // To see what state transitions are allowed, see |SetState|.
129 enum NavigationState {
130 // Initial state.
131 NOT_STARTED = 0,
132
133 // Waiting for a BeginNavigation IPC from the renderer in a
134 // browser-initiated navigation. If there is no live renderer when the
135 // request is created, this stage is skipped.
136 WAITING_FOR_RENDERER_RESPONSE,
137
138 // TODO(zetamoo): Merge this state with WILL_START_REQUEST.
139 // Temporary state where:
140 // - Before unload handlers have run and this navigation is allowed to
141 // start.
142 // - The navigation is still not visible to embedders (via
143 // NavigationHandle).
144 WILL_START_NAVIGATION,
145
146 // The navigation is visible to embedders (via NavigationHandle). Wait for
147 // the NavigationThrottles to finish running the WillStartRequest event.
148 // This is potentially asynchronous.
Adithya Srinivasanb00dceb02021-10-28 15:47:57149 // For navigations that have already committed synchronously in the renderer
150 // (see |is_synchronous_renderer_commit_|), this will synchronously proceed
151 // to DID_COMMIT directly without any waiting (or the navigation might not
152 // commit in certain cases, and be cleared in this state). All other
153 // navigations can only reach DID_COMMIT from READY_TO_COMMIT.
danakjc492bf82020-09-09 20:02:44154 WILL_START_REQUEST,
155
156 // The request is being redirected. Wait for the NavigationThrottles to
157 // finish running the WillRedirectRequest event. This is potentially
158 // asynchronous.
159 WILL_REDIRECT_REQUEST,
160
161 // The response is being processed. Wait for the NavigationThrottles to
162 // finish running the WillProcessResponse event. This is potentially
163 // asynchronous.
164 WILL_PROCESS_RESPONSE,
165
Nate Chapin060cb952023-02-08 21:13:07166 // The navigation does not require a request/response. Wait only for
167 // NavigationThrottles to finish before calling CommitNavigation(). This
168 // will only be asynchronous if a throttle defers the navigation.
169 WILL_COMMIT_WITHOUT_URL_LOADER,
170
Matt Falkenhagen54adeaa2021-07-06 14:10:00171 // The browser process has asked the renderer to commit the response
172 // and is waiting for acknowledgement that it has been committed.
danakjc492bf82020-09-09 20:02:44173 READY_TO_COMMIT,
174
175 // The response has been committed. This is one of the two final states of
176 // the request.
177 DID_COMMIT,
178
179 // The request is being canceled.
180 CANCELING,
181
182 // The request is failing. Wait for the NavigationThrottles to finish
183 // running the WillFailRequest event. This is potentially asynchronous.
184 WILL_FAIL_REQUEST,
185
Matt Falkenhagen54adeaa2021-07-06 14:10:00186 // The request failed with a net error code and an error page should be
danakjc492bf82020-09-09 20:02:44187 // displayed. This is one of the two final states for the request.
188 DID_COMMIT_ERROR_PAGE,
189 };
190
Rakina Zata Amni7af54b12022-06-28 10:36:17191 // The RenderFrameHost currently associated with the navigation. Note that the
danakjc492bf82020-09-09 20:02:44192 // final value will only be known when the response is received, or the
Rakina Zata Amni7af54b12022-06-28 10:36:17193 // navigation fails, as server redirects can modify the RenderFrameHost to use
danakjc492bf82020-09-09 20:02:44194 // for the navigation.
Rakina Zata Amni7af54b12022-06-28 10:36:17195 enum class AssociatedRenderFrameHostType {
danakjc492bf82020-09-09 20:02:44196 NONE = 0,
Rakina Zata Amni7af54b12022-06-28 10:36:17197 // The navigation reuses the current RenderFrameHost.
danakjc492bf82020-09-09 20:02:44198 CURRENT,
Rakina Zata Amni7af54b12022-06-28 10:36:17199 // The navigation uses a new RenderFrameHost, the speculative
200 // RenderFrameHost.
danakjc492bf82020-09-09 20:02:44201 SPECULATIVE,
202 };
203
Hiroki Nakagawa1aef8b02021-06-25 10:30:33204 // This enum is used in UMA histograms, so existing values should neither be
205 // reordered or removed.
206 enum class OriginAgentClusterEndResult {
W. James MacLean04279f52022-03-21 16:33:56207 // The first four enums are for use when OAC-by-default is disabled.
Hiroki Nakagawa1aef8b02021-06-25 10:30:33208 kNotRequestedAndNotOriginKeyed,
209 kNotRequestedButOriginKeyed,
210 kRequestedButNotOriginKeyed,
211 kRequestedAndOriginKeyed,
W. James MacLean04279f52022-03-21 16:33:56212 // The remaining enums are for use when OAC-by-default is enabled.
213 kExplicitlyNotRequestedAndNotOriginKeyed,
214 kExplicitlyNotRequestedButOriginKeyed,
215 kExplicitlyRequestedButNotOriginKeyed,
216 kExplicitlyRequestedAndOriginKeyed,
217 kNotExplicitlyRequestedButNotOriginKeyed,
218 kNotExplicitlyRequestedAndOriginKeyed,
219 kMaxValue = kNotExplicitlyRequestedAndOriginKeyed
Hiroki Nakagawa1aef8b02021-06-25 10:30:33220 };
221
Andrew Verge754c70a2025-04-17 17:19:19222 // If this navigation is a browser-initiated error page navigation, this enum
223 // describes the scenario that triggered the navigation, and how session
224 // history will be affected as a result.
225 enum class BrowserInitiatedErrorNavigationType {
226 // This navigation is not a browser-initiated error page navigation. The
227 // default value for all newly-created NavigationRequests.
228 kNone,
229
230 // This is a normal error navigation as triggered by
231 // NavigationControllerImpl::NavigateFrameToErrorPage(). The current session
232 // history item will be fully replaced when the navigation commits.
233 kRegular,
234
235 // This is a post-commit error page navigation as triggered by
236 // NavigationController::LoadPostCommitErrorPage(). The current session
237 // history item will be set aside when the navigation commits, and replaced
238 // when any following navigation commits.
239 kPostCommit,
240 };
241
Yue Ru Sun128804932020-09-30 22:19:17242 // Creates a request for a browser-initiated navigation.
danakjc492bf82020-09-09 20:02:44243 static std::unique_ptr<NavigationRequest> CreateBrowserInitiated(
244 FrameTreeNode* frame_tree_node,
Minggang Wangb9f3fa92021-07-01 15:30:31245 blink::mojom::CommonNavigationParamsPtr common_params,
246 blink::mojom::CommitNavigationParamsPtr commit_params,
Alex Moshchuk9321e6a2022-12-07 21:58:31247 bool was_opener_suppressed,
Alex Moshchuk9321e6a2022-12-07 21:58:31248 const std::string& extra_headers,
249 FrameNavigationEntry* frame_entry,
250 NavigationEntryImpl* entry,
251 bool is_form_submission,
252 std::unique_ptr<NavigationUIData> navigation_ui_data,
Arthur Sonzognic686e8f2024-01-11 08:36:37253 const std::optional<blink::Impression>& impression,
Alex Moshchuk9321e6a2022-12-07 21:58:31254 bool is_pdf,
Camillia Smith Barnes6a643962023-03-03 00:28:58255 bool is_embedder_initiated_fenced_frame_navigation = false,
Arthur Sonzognic686e8f2024-01-11 08:36:37256 std::optional<std::u16string> embedder_shared_storage_context =
257 std::nullopt);
Alex Moshchuk9321e6a2022-12-07 21:58:31258
259 // Creates a request for either a browser-initiated navigation or a
Liam Bradyedb866e2025-01-22 22:28:13260 // renderer-initiated navigation. Returns nullptr if the navigation could not
261 // be started, such as when network access has been revoked (see
262 // RenderFrameHost::IsUntrustedNetworkDisabled()). Normally,
263 // renderer-initiated navigations use CreateRendererInitiated(), but some
264 // legacy renderer-initiated navigation paths, such as OpenURL, are stuck
265 // using this path instead; these cases specify `browser_initiated` as false.
Alex Moshchuk9321e6a2022-12-07 21:58:31266 //
267 // Do NOT add more uses of this function. Browser-initiated navigations
268 // should use CreateBrowserInitiated() and renderer-initiated navigations
269 // should use CreateRendererInitiated().
270 //
Alison Gale81f4f2c72024-04-22 19:33:31271 // TODO(crbug.com/40249771): Refactor the remaining uses of this function to
Alex Moshchuk9321e6a2022-12-07 21:58:31272 // use either CreateBrowserInitiated() or CreateRendererInitiated() and then
273 // remove this helper.
274 static std::unique_ptr<NavigationRequest> Create(
275 FrameTreeNode* frame_tree_node,
276 blink::mojom::CommonNavigationParamsPtr common_params,
277 blink::mojom::CommitNavigationParamsPtr commit_params,
danakjc492bf82020-09-09 20:02:44278 bool browser_initiated,
John Delaney8623c642021-01-06 17:37:07279 bool was_opener_suppressed,
Arthur Sonzognic686e8f2024-01-11 08:36:37280 const std::optional<blink::LocalFrameToken>& initiator_frame_token,
Antonio Sartori9a82f6f32020-12-14 09:22:45281 int initiator_process_id,
danakjc492bf82020-09-09 20:02:44282 const std::string& extra_headers,
283 FrameNavigationEntry* frame_entry,
284 NavigationEntryImpl* entry,
jongdeok.kim5de823b32022-06-14 04:37:50285 bool is_form_submission,
danakjc492bf82020-09-09 20:02:44286 std::unique_ptr<NavigationUIData> navigation_ui_data,
Arthur Sonzognic686e8f2024-01-11 08:36:37287 const std::optional<blink::Impression>& impression,
Yao Xiao720ef9d62022-12-09 05:18:29288 blink::mojom::NavigationInitiatorActivationAndAdStatus
289 initiator_activation_and_ad_status,
Nan Lin944e9b4e2022-04-12 13:51:22290 bool is_pdf,
Sergey Poromovdd557c12023-03-01 11:28:45291 bool is_embedder_initiated_fenced_frame_navigation = false,
Camillia Smith Barnes6a643962023-03-03 00:28:58292 bool is_container_initiated = false,
Kevin McNee6455638a2024-06-27 22:05:03293 bool has_rel_opener = false,
W. James MacLean443ef3e2024-07-16 13:42:34294 net::StorageAccessApiStatus storage_access_api_status =
295 net::StorageAccessApiStatus::kNone,
Arthur Sonzognic686e8f2024-01-11 08:36:37296 std::optional<std::u16string> embedder_shared_storage_context =
297 std::nullopt);
danakjc492bf82020-09-09 20:02:44298
Yue Ru Sun128804932020-09-30 22:19:17299 // Creates a request for a renderer-initiated navigation.
danakjc492bf82020-09-09 20:02:44300 static std::unique_ptr<NavigationRequest> CreateRendererInitiated(
301 FrameTreeNode* frame_tree_node,
302 NavigationEntryImpl* entry,
Minggang Wangb9f3fa92021-07-01 15:30:31303 blink::mojom::CommonNavigationParamsPtr common_params,
304 blink::mojom::BeginNavigationParamsPtr begin_params,
Charlie Reis99b2eba22025-01-31 19:18:57305 int current_history_list_index,
danakjc492bf82020-09-09 20:02:44306 int current_history_list_length,
307 bool override_user_agent,
308 scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory,
309 mojo::PendingAssociatedRemote<mojom::NavigationClient> navigation_client,
danakjc492bf82020-09-09 20:02:44310 scoped_refptr<PrefetchedSignedExchangeCache>
311 prefetched_signed_exchange_cache,
Rakina Zata Amniaf55b5b62022-07-19 23:11:03312 mojo::PendingReceiver<mojom::NavigationRendererCancellationListener>
313 renderer_cancellation_listener);
danakjc492bf82020-09-09 20:02:44314
Hiroki Nakagawa544acd42021-06-17 13:58:44315 // Creates a NavigationRequest for synchronous navigation that have committed
316 // in the renderer process. Those are:
317 // - same-document renderer-initiated navigations.
318 // - synchronous about:blank navigations.
319 //
danakjc492bf82020-09-09 20:02:44320 // TODO(clamy): Eventually, this should only be called for same-document
321 // renderer-initiated navigations.
Hiroki Nakagawa544acd42021-06-17 13:58:44322 static std::unique_ptr<NavigationRequest> CreateForSynchronousRendererCommit(
danakjc492bf82020-09-09 20:02:44323 FrameTreeNode* frame_tree_node,
324 RenderFrameHostImpl* render_frame_host,
danakjc492bf82020-09-09 20:02:44325 bool is_same_document,
Rakina Zata Amnia8866d22020-11-19 10:05:10326 const GURL& url,
327 const url::Origin& origin,
Arthur Sonzognic686e8f2024-01-11 08:36:37328 const std::optional<GURL>& initiator_base_url,
Matt Menke7f2e1ac52020-12-10 01:16:10329 const net::IsolationInfo& isolation_info_for_subresources,
Rakina Zata Amnia8866d22020-11-19 10:05:10330 blink::mojom::ReferrerPtr referrer,
331 const ui::PageTransition& transition,
332 bool should_replace_current_entry,
Rakina Zata Amni26357782020-12-03 11:45:01333 const std::string& method,
Rakina Zata Amniff10975d2021-10-08 06:04:24334 bool has_transient_activation,
Rakina Zata Amnieca27992020-12-12 10:48:31335 bool is_overriding_user_agent,
Rakina Zata Amnia8866d22020-11-19 10:05:10336 const std::vector<GURL>& redirects,
Rakina Zata Amnieca27992020-12-12 10:48:31337 const GURL& original_url,
Rakina Zata Amnia8866d22020-11-19 10:05:10338 std::unique_ptr<CrossOriginEmbedderPolicyReporter> coep_reporter,
Camille Lamy36afacd2025-01-16 14:25:18339 std::unique_ptr<DocumentIsolationPolicyReporter> dip_reporter,
Charlie Reise1d9b8182025-04-02 04:32:12340 int http_response_code,
341 base::TimeTicks actual_navigation_start);
danakjc492bf82020-09-09 20:02:44342
343 static NavigationRequest* From(NavigationHandle* handle);
344
345 // If |type| is a reload, returns the equivalent ReloadType. Otherwise returns
346 // ReloadType::NONE.
Minggang Wangb9f3fa92021-07-01 15:30:31347 static ReloadType NavigationTypeToReloadType(
348 blink::mojom::NavigationType type);
danakjc492bf82020-09-09 20:02:44349
Daniel Hosseinianf0fbfb42021-09-08 02:20:47350 NavigationRequest(const NavigationRequest&) = delete;
351 NavigationRequest& operator=(const NavigationRequest&) = delete;
352
danakjc492bf82020-09-09 20:02:44353 ~NavigationRequest() override;
354
355 // Returns true if this request's URL matches |origin| and the request state
356 // is at (or past) WILL_PROCESS_RESPONSE.
357 bool HasCommittingOrigin(const url::Origin& origin);
358
Alex Moshchuk3b8eb3b2021-03-24 06:16:56359 // Returns true if this navigation's COOP header implies that the destination
360 // site of this navigation should be site-isolated. In addition to checking
361 // for eligible COOP header values, this function also verifies other
362 // criteria, such as whether this feature is enabled on the device (e.g.,
363 // above memory threshold) or whether the site is already isolated.
364 bool ShouldRequestSiteIsolationForCOOP();
365
danakjc492bf82020-09-09 20:02:44366 // NavigationHandle implementation:
William Liub26568da2024-02-21 20:46:14367 int64_t GetNavigationId() const override;
danakjc492bf82020-09-09 20:02:44368 ukm::SourceId GetNextPageUkmSourceId() override;
369 const GURL& GetURL() override;
370 SiteInstanceImpl* GetStartingSiteInstance() override;
371 SiteInstanceImpl* GetSourceSiteInstance() override;
Rakina Zata Amni18463252021-08-10 17:48:10372 bool IsInMainFrame() const override;
373 bool IsInPrimaryMainFrame() const override;
Takashi Toyoshima1a925f02025-06-13 17:56:14374 bool IsInOutermostMainFrame() const override;
Takashi Toyoshima3638f9c02023-01-18 06:47:57375 bool IsInPrerenderedMainFrame() const override;
Miyoung Shinda2cde12022-08-29 12:54:39376 bool IsPrerenderedPageActivation() const override;
377 bool IsInFencedFrameTree() const override;
W. James MacLean5d4f8e552025-03-17 16:58:15378 bool IsGuestViewMainFrame() const override;
Julie Jeongeun Kimf38c1eca2021-12-14 07:46:55379 FrameType GetNavigatingFrameType() const override;
danakjc492bf82020-09-09 20:02:44380 bool IsRendererInitiated() override;
Yao Xiao720ef9d62022-12-09 05:18:29381 blink::mojom::NavigationInitiatorActivationAndAdStatus
382 GetNavigationInitiatorActivationAndAdStatus() override;
Yoav Weiss3e46271d2021-04-30 20:35:21383 bool IsSameOrigin() override;
danakjc492bf82020-09-09 20:02:44384 bool WasServerRedirect() override;
385 const std::vector<GURL>& GetRedirectChain() override;
Avi Drissmanbd153642024-09-03 18:58:05386 FrameTreeNodeId GetFrameTreeNodeId() override;
danakjc492bf82020-09-09 20:02:44387 RenderFrameHostImpl* GetParentFrame() override;
Dave Tapuskac8de3b02021-12-03 21:51:01388 RenderFrameHostImpl* GetParentFrameOrOuterDocument() override;
danakjc492bf82020-09-09 20:02:44389 base::TimeTicks NavigationStart() override;
390 base::TimeTicks NavigationInputStart() override;
391 const NavigationHandleTiming& GetNavigationHandleTiming() override;
392 bool IsPost() override;
Min Qin3669650b2024-08-07 18:13:52393 std::string GetRequestMethod() override;
danakjc492bf82020-09-09 20:02:44394 const blink::mojom::Referrer& GetReferrer() override;
395 void SetReferrer(blink::mojom::ReferrerPtr referrer) override;
396 bool HasUserGesture() override;
397 ui::PageTransition GetPageTransition() override;
398 NavigationUIData* GetNavigationUIData() override;
399 bool IsExternalProtocol() override;
400 net::Error GetNetErrorCode() override;
Keita Suzukic2057642025-05-13 07:39:49401 int GetNetExtendedErrorCode() override;
Keita Suzukif300e442025-07-16 07:38:11402 std::optional<ErrorNavigationTrigger> GetErrorNavigationTrigger() override;
Alexander Timin074cd182022-03-23 18:11:22403 RenderFrameHostImpl* GetRenderFrameHost() const override;
Daniel Cheng284c38942022-09-22 23:30:34404 bool IsSameDocument() const override;
Rakina Zata Amnic0a74fa2024-04-24 00:32:43405 bool IsHistory() const override;
Alexander Timin074cd182022-03-23 18:11:22406 bool HasCommitted() const override;
407 bool IsErrorPage() const override;
danakjc492bf82020-09-09 20:02:44408 bool HasSubframeNavigationEntryCommitted() override;
409 bool DidReplaceEntry() override;
410 bool ShouldUpdateHistory() override;
Kevin McNeeb49d2b82022-06-14 16:53:14411 const GURL& GetPreviousPrimaryMainFrameURL() override;
danakjc492bf82020-09-09 20:02:44412 net::IPEndPoint GetSocketAddress() override;
413 const net::HttpRequestHeaders& GetRequestHeaders() override;
414 void RemoveRequestHeader(const std::string& header_name) override;
415 void SetRequestHeader(const std::string& header_name,
416 const std::string& header_value) override;
417 void SetCorsExemptRequestHeader(const std::string& header_name,
418 const std::string& header_value) override;
Kouhei Uenoa0297b0b2023-06-15 05:39:48419 void SetLCPPNavigationHint(
420 const blink::mojom::LCPCriticalPathPredictorNavigationTimeHint& hint)
421 override;
Kouhei Ueno0cea932732023-08-04 00:19:41422 const blink::mojom::LCPCriticalPathPredictorNavigationTimeHintPtr&
423 GetLCPPNavigationHint() override;
danakjc492bf82020-09-09 20:02:44424 const net::HttpResponseHeaders* GetResponseHeaders() override;
Tsuyoshi Horo3023b5d2023-11-28 21:40:31425 net::HttpConnectionInfo GetConnectionInfo() override;
Arthur Sonzognic686e8f2024-01-11 08:36:37426 const std::optional<net::SSLInfo>& GetSSLInfo() override;
427 const std::optional<net::AuthChallengeInfo>& GetAuthChallengeInfo() override;
danakjc492bf82020-09-09 20:02:44428 net::ResolveErrorInfo GetResolveErrorInfo() override;
429 net::IsolationInfo GetIsolationInfo() override;
430 void RegisterThrottleForTesting(
431 std::unique_ptr<NavigationThrottle> navigation_throttle) override;
432 bool IsDeferredForTesting() override;
David Bokan3d0d4082021-07-27 17:40:26433 bool IsCommitDeferringConditionDeferredForTesting() override;
David Bokan5e2c64f2022-03-08 19:59:53434 CommitDeferringCondition* GetCommitDeferringConditionForTesting() override;
danakjc492bf82020-09-09 20:02:44435 bool WasStartedFromContextMenu() override;
436 const GURL& GetSearchableFormURL() override;
437 const std::string& GetSearchableFormEncoding() override;
William Liu2b6336bc2023-09-07 14:42:39438 ReloadType GetReloadType() const override;
439 RestoreType GetRestoreType() const override;
danakjc492bf82020-09-09 20:02:44440 const GURL& GetBaseURLForDataURL() override;
441 const GlobalRequestID& GetGlobalRequestID() override;
442 bool IsDownload() override;
443 bool IsFormSubmission() override;
444 bool WasInitiatedByLinkClick() override;
445 bool IsSignedExchangeInnerResponse() override;
446 bool HasPrefetchedAlternativeSubresourceSignedExchange() override;
447 bool WasResponseCached() override;
danakjc492bf82020-09-09 20:02:44448 const std::string& GetHrefTranslate() override;
Arthur Sonzognic686e8f2024-01-11 08:36:37449 const std::optional<blink::Impression>& GetImpression() override;
450 const std::optional<blink::LocalFrameToken>& GetInitiatorFrameToken()
Antonio Sartori9a82f6f32020-12-14 09:22:45451 override;
Liam Brady767b85e2023-07-05 16:59:59452 int GetInitiatorProcessId() override;
Arthur Sonzognic686e8f2024-01-11 08:36:37453 const std::optional<url::Origin>& GetInitiatorOrigin() override;
454 const std::optional<GURL>& GetInitiatorBaseUrl() override;
Cammie Smith Barnesa0da2cf2021-01-11 22:09:37455 const std::vector<std::string>& GetDnsAliases() override;
danakjc492bf82020-09-09 20:02:44456 bool IsSameProcess() override;
William Liu2b6336bc2023-09-07 14:42:39457 NavigationEntry* GetNavigationEntry() const override;
Aldo Culquicondor3d10ff02025-01-30 19:01:03458 int GetNavigationEntryOffset() const override;
danakjc492bf82020-09-09 20:02:44459 void RegisterSubresourceOverride(
460 blink::mojom::TransferrableURLLoaderPtr transferrable_loader) override;
Alexander Timin8690530c2021-06-19 00:34:32461 GlobalRenderFrameHostId GetPreviousRenderFrameHostId() override;
Patrick Monette779c1542025-01-17 17:18:36462 ChildProcessId GetExpectedRenderProcessHostId() override;
Fergal Daly7fa11712025-08-18 07:28:47463 bool IsServedFromBackForwardCache() const override;
danakjc492bf82020-09-09 20:02:44464 void SetIsOverridingUserAgent(bool override_ua) override;
Daniel Chengf776864c2020-09-26 09:55:22465 void SetSilentlyIgnoreErrors() override;
Kyra800d1d012024-03-27 17:05:48466 void SetVisitedLinkSalt(uint64_t salt) override;
Arthur Sonzognidc8508ab2023-08-17 08:42:42467 network::mojom::WebSandboxFlags SandboxFlagsInitiator() override;
Michael Thiessen8fd3520b2023-03-10 20:55:47468 network::mojom::WebSandboxFlags SandboxFlagsInherited() override;
Rakina Zata Amnib0c816b2020-11-11 04:07:01469 network::mojom::WebSandboxFlags SandboxFlagsToCommit() override;
Alex Turner12519eb2020-11-16 22:23:46470 bool IsWaitingToCommit() override;
Kenichi Ishibashi784dd402021-10-15 00:19:24471 bool WasResourceHintsReceived() override;
Daniel Hosseinian46c816c2021-10-19 02:43:10472 bool IsPdf() override;
Alexander Timin074cd182022-03-23 18:11:22473 void WriteIntoTrace(perfetto::TracedProto<TraceProto> context) const override;
Chris Thompson066eed22021-10-07 20:20:43474 bool SetNavigationTimeout(base::TimeDelta timeout) override;
Mustafa Acer7b99ac22024-07-23 14:57:28475 void CancelNavigationTimeout() override;
Igor Ruvinov0ea2ebb2022-12-01 16:33:06476 void SetAllowCookiesFromBrowser(bool allow_cookies_from_browser) override;
Igor Ruvinovdcb81982023-06-21 22:22:17477 void GetResponseBody(ResponseBodyCallback callback) override;
Kouhei Ueno3f37992b2023-11-09 23:29:02478 PreloadingTriggerType GetPrerenderTriggerType() override;
Asami Doicf0f1642021-11-25 05:00:26479 std::string GetPrerenderEmbedderHistogramSuffix() override;
Keita Suzuki1b7cf512025-08-02 02:46:59480 bool IsPrerenderHostReused() override;
Michael Thiessenca245a382022-02-21 16:11:17481#if BUILDFLAG(IS_ANDROID)
482 const base::android::JavaRef<jobject>& GetJavaNavigationHandle() override;
483#endif
David Bokan42f8dc22022-02-23 17:33:28484 base::SafeRef<NavigationHandle> GetSafeRef() override;
Anthony Vallee-Dubois2c8022172022-08-22 15:29:41485 bool ExistingDocumentWasDiscarded() const override;
Jonathan Njeunje58618592023-04-06 21:10:02486 blink::RuntimeFeatureStateContext& GetMutableRuntimeFeatureStateContext()
487 override;
Erik Chen5fe571f2023-10-11 23:01:15488 void SetContentSettings(
489 blink::mojom::RendererContentSettingsPtr content_settings) override;
Erik Chen7ce5f052023-10-19 22:28:24490 blink::mojom::RendererContentSettingsPtr GetContentSettingsForTesting()
491 override;
John Delaney4cf7d6ea2023-11-09 17:29:56492 void SetIsAdTagged() override;
Rakina Zata Amni58681c62024-06-25 06:32:13493 std::optional<NavigationDiscardReason> GetNavigationDiscardReason() override;
Kyra800d1d012024-03-27 17:05:48494 // NOTE: Read function comments in NavigationHandle before use!
495 std::optional<url::Origin> GetOriginToCommit() override;
Jonathan Njeunje58618592023-04-06 21:10:02496 // End of NavigationHandle implementation.
danakjc492bf82020-09-09 20:02:44497
Jonathan Njeunje58618592023-04-06 21:10:02498 // mojom::NavigationRendererCancellationListener implementation:
Rakina Zata Amniaf55b5b62022-07-19 23:11:03499 void RendererCancellationWindowEnded() override;
Jonathan Njeunje58618592023-04-06 21:10:02500 // End of mojom::NavigationRendererCancellationListener implementation.
Rakina Zata Amniaf55b5b62022-07-19 23:11:03501
David Bokan1bdb3701f2021-04-30 22:02:35502 void RegisterCommitDeferringConditionForTesting(
503 std::unique_ptr<CommitDeferringCondition> condition);
504
Giovanni Ortuño Urquidie0a77b42025-03-28 14:31:35505 // Used by tests that want to control the timing of cookie access
506 // notifications.
507 void SetCookieAccessObserversForTesting(
508 std::unique_ptr<CookieAccessObservers> cookie_access_observers);
509
danakjc492bf82020-09-09 20:02:44510 // Called on the UI thread by the Navigator to start the navigation.
511 // The NavigationRequest can be deleted while BeginNavigation() is called.
512 void BeginNavigation();
513
Minggang Wangb9f3fa92021-07-01 15:30:31514 const blink::mojom::CommonNavigationParams& common_params() const {
danakjc492bf82020-09-09 20:02:44515 return *common_params_;
516 }
517
Minggang Wangb9f3fa92021-07-01 15:30:31518 const blink::mojom::BeginNavigationParams& begin_params() const {
Harkiran Bolaria2d0e38932021-04-27 17:44:35519 return *begin_params_;
danakjc492bf82020-09-09 20:02:44520 }
521
Minggang Wangb9f3fa92021-07-01 15:30:31522 const blink::mojom::CommitNavigationParams& commit_params() const {
danakjc492bf82020-09-09 20:02:44523 return *commit_params_;
524 }
525
Charlie Reis9e20dd12025-01-02 20:11:53526 // This describes the cases where the navigation start time is adjusted to be
527 // later in time, after BeforeUnloadCompleted. This enum is used in UMA
528 // histograms, so existing values should be neither reordered nor removed.
529 enum class NavigationStartAdjustmentType {
530 // No adjustment to the navigation start time was made.
531 kNone = 0,
532 // The start time was adjusted so that the navigation could proceed via a
533 // posted task, even though there were no beforeunload handlers registered.
534 kLegacyPostTask = 1,
535 // The start time was adjusted because beforeunload handlers ran, but no
536 // dialog was displayed to the user.
537 kBeforeUnloadHandlers = 2,
538 // The start time was adjusted because a beforeunload dialog was shown.
539 kBeforeUnloadDialog = 3,
540 kMaxValue = kBeforeUnloadDialog,
541 };
542
543 // Updates the navigation start time, after beforeunload has completed.
544 // `for_legacy` indicates that the navigation proceeded in a separate task for
545 // legacy reasons, without running beforeunload handlers. `showed_dialog`
546 // indicates whether the beforeunload handlers actually displayed a dialog.
547 void UpdateNavigationStartTime(const base::TimeTicks& time,
548 bool for_legacy,
549 bool showed_dialog);
danakjc492bf82020-09-09 20:02:44550
Shuran Huangd11e73e2021-04-14 16:10:12551 void set_is_cross_site_cross_browsing_context_group(
552 bool is_cross_site_cross_browsing_context_group) {
553 commit_params_->is_cross_site_cross_browsing_context_group =
554 is_cross_site_cross_browsing_context_group;
Shuran Huangecc0bfe22020-10-26 20:15:04555 }
556
danakjc492bf82020-09-09 20:02:44557 NavigationURLLoader* loader_for_testing() const { return loader_.get(); }
558
559 NavigationState state() const { return state_; }
560
561 FrameTreeNode* frame_tree_node() const { return frame_tree_node_; }
562
Nate Chapind7e7fe82021-06-30 01:15:43563 bool is_synchronous_renderer_commit() const {
564 return is_synchronous_renderer_commit_;
565 }
566
danakjc492bf82020-09-09 20:02:44567 SiteInstanceImpl* dest_site_instance() const {
568 return dest_site_instance_.get();
569 }
570
Avi Drissman78865bbb2024-08-22 20:57:19571 std::optional<BindingsPolicySet> bindings() const { return bindings_; }
danakjc492bf82020-09-09 20:02:44572
Hiroki Nakagawa07565592021-06-04 11:36:17573 bool browser_initiated() const {
574 return commit_params_->is_browser_initiated;
575 }
danakjc492bf82020-09-09 20:02:44576
577 bool from_begin_navigation() const { return from_begin_navigation_; }
578
Rakina Zata Amni8d4ed052022-12-07 23:03:30579 AssociatedRenderFrameHostType GetAssociatedRFHType() const;
580
581 void SetAssociatedRFHType(AssociatedRenderFrameHostType type);
danakjc492bf82020-09-09 20:02:44582
Rakina Zata Amni7b75ae342023-03-03 05:59:14583 bool HasRenderFrameHost() const { return render_frame_host_.has_value(); }
584
danakjc492bf82020-09-09 20:02:44585 void set_was_discarded() { commit_params_->was_discarded = true; }
586
587 void set_net_error(net::Error net_error) { net_error_ = net_error; }
588
589 const std::string& GetMimeType() {
590 return response_head_ ? response_head_->mime_type : base::EmptyString();
591 }
592
593 const network::mojom::URLResponseHead* response() {
594 return response_head_.get();
595 }
596
Rakina Zata Amniba3eecb2020-11-02 10:12:28597 const mojo::DataPipeConsumerHandle& response_body() {
598 DCHECK_EQ(state_, WILL_PROCESS_RESPONSE);
599 return response_body_.get();
600 }
601
602 mojo::ScopedDataPipeConsumerHandle& mutable_response_body_for_testing() {
603 return response_body_;
604 }
605
danakjc492bf82020-09-09 20:02:44606 void SetWaitingForRendererResponse();
607
608 // Notifies the NavigatorDelegate the navigation started. This should be
609 // called after any previous NavigationRequest for the FrameTreeNode has been
Hiroki Nakagawaadcffc502021-06-16 10:47:51610 // destroyed.
611 void StartNavigation();
danakjc492bf82020-09-09 20:02:44612
613 void set_on_start_checks_complete_closure_for_testing(
614 base::OnceClosure closure) {
615 on_start_checks_complete_closure_ = std::move(closure);
616 }
617
danakjc492bf82020-09-09 20:02:44618 // Updates the destination SiteInfo for this navigation. This is called on
619 // redirects. |post_redirect_process| is the renderer process that should
620 // handle the navigation following the redirect if it can be handled by an
621 // existing RenderProcessHost. Otherwise, it should be null.
Arthur Hemery3a991c092021-12-22 12:04:24622 void UpdateSiteInfo(RenderProcessHost* post_redirect_process);
danakjc492bf82020-09-09 20:02:44623
624 int nav_entry_id() const { return nav_entry_id_; }
625
danakjc492bf82020-09-09 20:02:44626 // For automation driver-initiated navigations over the devtools protocol,
627 // |devtools_navigation_token_| is used to tag the navigation. This navigation
628 // token is then sent into the renderer and lands on the DocumentLoader. That
629 // way subsequent Blink-level frame lifecycle events can be associated with
630 // the concrete navigation.
631 // - The value should not be sent back to the browser.
632 // - The value on DocumentLoader may be generated in the renderer in some
633 // cases, and thus shouldn't be trusted.
Alison Gale770f3fc2024-04-27 00:39:58634 // TODO(crbug.com/40549185): Replace devtools navigation token with the
635 // generic navigation token that can be passed from renderer to the browser.
danakjc492bf82020-09-09 20:02:44636 const base::UnguessableToken& devtools_navigation_token() const {
637 return devtools_navigation_token_;
638 }
639
Mike Jackson82654a3a2025-02-13 07:48:22640 blink::mojom::ConfidenceLevel navigation_confidence() const {
641 return confidence_level_;
642 }
643
Alex Moshchukd0d759c22025-05-09 18:18:35644 // This token is passed in various IPCs pertaining to navigations, such as
645 // frame and proxy creation as well as CommitNavigation, and is used by
646 // renderer-side metrics code to tie together different IPCs that were sent as
647 // part of performing a particular navigation. It is not intended to be used
648 // for anything other than metrics and trace events.
649 //
650 // Note that this token is stored in CommitNavigationParams, even though it's
651 // also needed before CommitNavigation (e.g., it needs to be included in frame
652 // and proxy creation IPCs which are sent before CommitNavigation) - this
653 // should be ok since commit_params() are initialized when a NavigationRequest
654 // is created.
655 const base::UnguessableToken& navigation_metrics_token() const {
656 return commit_params().navigation_metrics_token;
657 }
658
danakjc492bf82020-09-09 20:02:44659 // Called on same-document navigation requests that need to be restarted as
660 // cross-document navigations. This happens when a same-document commit fails
661 // due to another navigation committing in the meantime.
662 void ResetForCrossDocumentRestart();
663
664 // If the navigation redirects cross-process or otherwise is forced to use a
665 // different SiteInstance than anticipated (e.g., for switching between error
666 // states), then reset any sensitive state that shouldn't carry over to the
667 // new process.
668 void ResetStateForSiteInstanceChange();
669
Sohom7299b222023-01-20 15:20:52670 // If a navigation has been cancelled, and was initiated by the parent
671 // document, report it with the appropriate ResourceTiming entry information.
672 //
673 // The ResourceTiming entry may not be sent if the current frame
674 // does not have a parent, or if the navigation was cancelled before
675 // a request was made.
676 void MaybeAddResourceTimingEntryForCancelledNavigation();
677
Sergey Poromovdd557c12023-03-01 11:28:45678 // Adds a resource timing entry to the parent in case of cancelled navigations
679 // and failed <object> navigations.
680 void AddResourceTimingEntryForFailedSubframeNavigation(
681 const network::URLLoaderCompletionStatus& status);
682
danakjc492bf82020-09-09 20:02:44683 // Lazily initializes and returns the mojo::NavigationClient interface used
Nasko Oskovd22f9bf872020-12-23 00:31:35684 // for commit.
danakjc492bf82020-09-09 20:02:44685 mojom::NavigationClient* GetCommitNavigationClient();
686
687 void set_transition(ui::PageTransition transition) {
688 common_params_->transition = transition;
689 }
690
691 void set_has_user_gesture(bool has_user_gesture) {
692 common_params_->has_user_gesture = has_user_gesture;
693 }
694
695 // Ignores any interface disconnect that might happen to the
696 // navigation_client used to commit.
697 void IgnoreCommitInterfaceDisconnection();
698
699 // Resume and CancelDeferredNavigation must only be called by the
700 // NavigationThrottle that is currently deferring the navigation.
701 // |resuming_throttle| and |cancelling_throttle| are the throttles calling
702 // these methods.
703 void Resume(NavigationThrottle* resuming_throttle);
704 void CancelDeferredNavigation(NavigationThrottle* cancelling_throttle,
705 NavigationThrottle::ThrottleCheckResult result);
706
Takashi Toyoshima96a07bb2025-06-06 06:45:58707 // Returns the underlying NavigationThrottleRegistry for tests to manipulate.
Takashi Toyoshimacc4d947f2025-06-24 08:38:34708 NavigationThrottleRegistryImpl* GetNavigationThrottleRegistryForTesting() {
Takashi Toyoshima96a07bb2025-06-06 06:45:58709 return throttle_registry_.get();
710 }
711
Rakina Zata Amniaf55b5b62022-07-19 23:11:03712 // Simulates renderer cancelling the navigation.
713 void RendererRequestedNavigationCancellationForTesting();
danakjc492bf82020-09-09 20:02:44714
715 typedef base::OnceCallback<bool(NavigationThrottle::ThrottleCheckResult)>
716 ThrottleChecksFinishedCallback;
717
danakjc492bf82020-09-09 20:02:44718 // Called when the navigation was committed.
719 // This will update the |state_|.
720 // |navigation_entry_committed| indicates whether the navigation changed which
721 // NavigationEntry is current.
722 // |did_replace_entry| is true if the committed entry has replaced the
723 // existing one. A non-user initiated redirect causes such replacement.
Fergal Daly8e33cf62020-12-12 01:06:07724
arthursonzogni73fe3212020-11-17 13:24:07725 void DidCommitNavigation(const mojom::DidCommitProvisionalLoadParams& params,
726 bool navigation_entry_committed,
727 bool did_replace_entry,
Miyoung Shin3299cbf2022-11-22 01:41:10728 const GURL& previous_main_frame_url);
danakjc492bf82020-09-09 20:02:44729
730 NavigationType navigation_type() const {
731 DCHECK(state_ == DID_COMMIT || state_ == DID_COMMIT_ERROR_PAGE);
732 return navigation_type_;
733 }
734
Miyoung Shin3299cbf2022-11-22 01:41:10735 void set_navigation_type(NavigationType navigation_type) {
736 navigation_type_ = navigation_type;
737 }
738
Andrew Verge754c70a2025-04-17 17:19:19739 void set_browser_initiated_error_navigation_type(
740 BrowserInitiatedErrorNavigationType type) {
741 browser_initiated_error_navigation_type_ = type;
danakjc492bf82020-09-09 20:02:44742 }
743
Andrew Verge754c70a2025-04-17 17:19:19744 BrowserInitiatedErrorNavigationType
745 browser_initiated_error_navigation_type() {
746 return browser_initiated_error_navigation_type_;
747 }
748
749 void set_error_page_html(const std::string& error_page_html) {
750 CHECK(browser_initiated_error_navigation_type_ !=
751 BrowserInitiatedErrorNavigationType::kNone);
752 error_page_html_ = error_page_html;
danakjc492bf82020-09-09 20:02:44753 }
754
755 void set_from_download_cross_origin_redirect(
756 bool from_download_cross_origin_redirect) {
757 from_download_cross_origin_redirect_ = from_download_cross_origin_redirect;
758 }
759
760 // This should be a private method. The only valid reason to be used
761 // outside of the class constructor is in the case of an initial history
762 // navigation in a subframe. This allows a browser-initiated NavigationRequest
763 // to be canceled by the renderer.
764 void SetNavigationClient(
765 mojo::PendingAssociatedRemote<mojom::NavigationClient> navigation_client);
766
Lukasz Anforowicz39a8aef2020-12-17 23:50:15767 // Whether the navigation loads an MHTML document or a subframe of an MHTML
768 // document. The navigation might or might not be fullfilled from the MHTML
769 // archive (see `is_mhtml_subframe_loaded_from_achive` in the NeedsUrlLoader
770 // method). The navigation will commit in the main frame process.
771 bool IsMhtmlOrSubframe();
arthursonzogni3fc224b2020-10-07 10:41:16772
Lukasz Anforowicz39a8aef2020-12-17 23:50:15773 // Whether this navigation navigates a subframe of an MHTML document.
danakjc492bf82020-09-09 20:02:44774 bool IsForMhtmlSubframe() const;
775
Rakina Zata Amni3a1c0ec2021-04-15 03:35:12776 // Whether the navigation has a non-OK net error code.
777 // Note that this is different from IsErrorPage(), which only returns true if
778 // the navigation has finished committing an error page. The net error code
779 // can be non-OK before commit and also in cases that didn't result in the
780 // navigation being committed (e.g. canceled navigations).
781 virtual bool DidEncounterError() const;
782
Yao Xiao6e1f7d32022-01-07 03:28:40783 void set_begin_navigation_callback_for_testing(base::OnceClosure callback) {
784 begin_navigation_callback_for_testing_ = std::move(callback);
785 }
786
danakjc492bf82020-09-09 20:02:44787 void set_complete_callback_for_testing(
788 ThrottleChecksFinishedCallback callback) {
789 complete_callback_for_testing_ = std::move(callback);
790 }
791
Daniel Chenge8b69402021-05-25 20:44:44792 network::mojom::URLLoaderClientEndpointsPtr&
793 mutable_url_loader_client_endpoints_for_testing() {
794 return url_loader_client_endpoints_;
795 }
796
David Bokan1bdb3701f2021-04-30 22:02:35797 void set_ready_to_commit_callback_for_testing(base::OnceClosure callback) {
798 ready_to_commit_callback_for_testing_ = std::move(callback);
799 }
800
Rakina Zata Amni49657c772023-03-31 06:41:53801 // Whether this navigation is queued, waiting for an existing pending commit
802 // RenderFrameHost to finish navigating.
803 bool IsQueued() const { return !!resume_commit_closure_; }
804
Rakina Zata Amniaf55b5b62022-07-19 23:11:03805 void set_renderer_cancellation_window_ended_callback(
806 base::OnceClosure callback) {
807 DCHECK(!renderer_cancellation_window_ended());
808 renderer_cancellation_window_ended_callback_ = std::move(callback);
809 }
810
811 bool renderer_cancellation_window_ended() const {
812 return renderer_cancellation_window_ended_;
813 }
814
815 // Returns true if this navigation should wait for the renderer-initiated
816 // navigation cancellation window to end before committing, and returns false
817 // otherwise. See comment for `renderer_cancellation_listener_` for more
818 // details.
819 bool ShouldWaitForRendererCancellationWindowToEnd();
820
danakjc492bf82020-09-09 20:02:44821 // Sets the READY_TO_COMMIT -> DID_COMMIT timeout. Resets the timeout to the
822 // default value if |timeout| is zero.
823 static void SetCommitTimeoutForTesting(const base::TimeDelta& timeout);
824
Mingyu Lei2e0b586e2023-07-25 18:26:00825 // Returns the `rfh_restored_from_back_forward_cache_` if the navigation is
826 // a BFCache restore, or nullptr otherwise.
827 RenderFrameHostImpl* GetRenderFrameHostRestoredFromBackForwardCache() const;
danakjc492bf82020-09-09 20:02:44828
Matt Falkenhagena0b95d7b2021-08-06 20:37:40829 // The NavigatorDelegate to notify/query for various navigation events. This
830 // is always the WebContents.
danakjc492bf82020-09-09 20:02:44831 NavigatorDelegate* GetDelegate() const;
832
833 blink::mojom::RequestContextType request_context_type() const {
834 return begin_params_->request_context_type;
835 }
836
837 network::mojom::RequestDestination request_destination() const {
Nan Lind91c8152021-10-21 16:22:37838 return common_params_->request_destination;
danakjc492bf82020-09-09 20:02:44839 }
840
Henrique Ferreiro621b3ad2021-02-15 12:51:41841 blink::mojom::MixedContentContextType mixed_content_context_type() const {
danakjc492bf82020-09-09 20:02:44842 return begin_params_->mixed_content_context_type;
843 }
844
845 // Returns true if the navigation was started by the Navigator by calling
846 // BeginNavigation(), or if the request was created at commit time by calling
847 // CreateForCommit().
848 bool IsNavigationStarted() const;
849
Aman Vermac59efd02024-11-18 20:30:17850 std::unique_ptr<viz::PeakGpuMemoryTracker> TakePeakGpuMemoryTracker();
danakjc492bf82020-09-09 20:02:44851
Kenichi Ishibashi7eb8cf62021-04-07 12:35:05852 std::unique_ptr<NavigationEarlyHintsManager> TakeEarlyHintsManager();
853
danakjc492bf82020-09-09 20:02:44854 // Returns true for navigation responses to be rendered in a renderer process.
855 // This excludes:
Sharon Yang9e727282023-11-13 19:51:40856 // - 204/205 navigation responses
857 // - Most downloads
858 // (Note: downloads with unsuccessful response codes will render an error
859 // page, causing this to return true.)
danakjc492bf82020-09-09 20:02:44860 //
Sharon Yang9e727282023-11-13 19:51:40861 // Must not be called before having received the response. After
862 // OnResponseStarted(), this is expected to be equivalent to
863 // HasRenderFrameHost().
danakjc492bf82020-09-09 20:02:44864 bool response_should_be_rendered() const {
865 DCHECK_GE(state_, WILL_PROCESS_RESPONSE);
866 return response_should_be_rendered_;
867 }
868
Titouan Rigoudyff5a84b2023-07-25 16:02:20869 // Returns the `ClientSecurityState` we should pass to
870 // `NavigationURLLoaderFactory`.
871 //
872 // For subresource requests the `ClientSecurityState` is passed through
873 // `URLLoaderFactoryParams`, since each request client has a dedicated
874 // factory. That does not work for navigation requests because they all share
875 // a common factory, so each request is tagged with a `ClientSecurityState` to
876 // use instead.
877 network::mojom::ClientSecurityStatePtr
878 BuildClientSecurityStateForNavigationFetch();
879
880 // Returns the `ClientSecurityState` to be used for subresource fetches by the
881 // document we are navigating to.
882 //
883 // Must only be called after `ReadyToCommitNavigation()`.
884 network::mojom::ClientSecurityStatePtr
885 BuildClientSecurityStateForCommittedDocument();
danakjc492bf82020-09-09 20:02:44886
887 bool ua_change_requires_reload() const { return ua_change_requires_reload_; }
888
danakjc492bf82020-09-09 20:02:44889 void SetRequiredCSP(network::mojom::ContentSecurityPolicyPtr csp);
890 network::mojom::ContentSecurityPolicyPtr TakeRequiredCSP();
891
Arthur Sonzogni64457592022-11-22 11:08:59892 bool is_credentialless() const { return is_credentialless_; }
Antonio Sartori5abc8de2021-07-13 08:42:47893
Titouan Rigoudy2f995bc2021-02-19 19:39:41894 // Returns a pointer to the policies copied from the navigation initiator.
895 // Returns nullptr if this navigation had no initiator.
896 const PolicyContainerPolicies* GetInitiatorPolicyContainerPolicies() const;
897
Daniel Cheng284c38942022-09-22 23:30:34898 // The DocumentToken that should be used for the document created as a result
899 // of committing this navigation.
900 // - must only be called for cross-document navigations
901 // - must not be called before the navigation is ready to commit
902 const blink::DocumentToken& GetDocumentToken() const;
903
Titouan Rigoudy2f995bc2021-02-19 19:39:41904 // Returns the policies of the new document being navigated to.
905 //
906 // Must only be called after ReadyToCommitNavigation().
907 const PolicyContainerPolicies& GetPolicyContainerPolicies() const;
908
909 // Creates a new policy container for Blink connected to this navigation's
910 // PolicyContainerHost.
911 //
912 // Must only be called after ReadyToCommitNavigation().
913 blink::mojom::PolicyContainerPtr CreatePolicyContainerForBlink();
914
Ming-Ying Chungc327e532023-04-17 05:55:29915 // Returns a new refptr to this navigation's PolicyContainerHost.
916 //
917 // Must only be called after ReadyToCommitNavigation().
918 // It is invalid to call after `TakePolicyContainerHost()`.
919 scoped_refptr<PolicyContainerHost> GetPolicyContainerHost();
920
Titouan Rigoudy2f995bc2021-02-19 19:39:41921 // Moves this navigation's PolicyContainerHost out of this instance.
922 //
923 // Must only be called after ReadyToCommitNavigation().
Antonio Sartoridb967c52021-01-20 09:54:30924 scoped_refptr<PolicyContainerHost> TakePolicyContainerHost();
Antonio Sartori3cfa3b62020-10-09 10:42:40925
danakjc492bf82020-09-09 20:02:44926 CrossOriginEmbedderPolicyReporter* coep_reporter() {
927 return coep_reporter_.get();
928 }
929
Camille Lamy36afacd2025-01-16 14:25:18930 DocumentIsolationPolicyReporter* dip_reporter() {
931 return dip_reporter_.get();
932 }
933
danakjc492bf82020-09-09 20:02:44934 std::unique_ptr<CrossOriginEmbedderPolicyReporter> TakeCoepReporter();
Camille Lamy36afacd2025-01-16 14:25:18935 std::unique_ptr<DocumentIsolationPolicyReporter> TakeDipReporter();
danakjc492bf82020-09-09 20:02:44936
937 // Returns UKM SourceId for the page we are navigating away from.
938 // Equal to GetRenderFrameHost()->GetPageUkmSourceId() for subframe
939 // and same-document navigations and to
940 // RenderFrameHost::FromID(GetPreviousRenderFrameHostId())
941 // ->GetPageUkmSourceId() for main-frame cross-document navigations.
Takashi Toyoshimac27d7b42023-07-27 05:09:26942 // Note: If this method is called on a prerender navigation, it will return
943 // ukm::kInvalidSourceId due to our data collection policy.
danakjc492bf82020-09-09 20:02:44944 ukm::SourceId GetPreviousPageUkmSourceId();
945
danakjc492bf82020-09-09 20:02:44946 void OnServiceWorkerAccessed(const GURL& scope,
947 AllowServiceWorkerResult allowed);
948
949 // Take all cookie observers associated with this navigation.
950 // Typically this is called when navigation commits to move these observers to
951 // the committed document.
Daniel Cheng9c9fa1a2022-01-14 03:42:11952 [[nodiscard]] std::vector<
Giovanni Ortuño Urquidid2e5fab2025-04-02 20:44:03953 std::pair<mojo::PendingReceiver<network::mojom::CookieAccessObserver>,
954 CookieAccessDetails::Source>>
Daniel Cheng9c9fa1a2022-01-14 03:42:11955 TakeCookieObservers();
danakjc492bf82020-09-09 20:02:44956
Giovanni Ortuño Urquidie0a77b42025-03-28 14:31:35957 void NotifyCookiesAccessed(
958 std::vector<network::mojom::CookieAccessDetailsPtr> details_vector,
959 CookieAccessDetails::Source source);
960
Steven Valdeza06f680c2023-03-21 19:00:10961 // Take all Trust Token observers associated with this navigation.
962 // Typically this is called when navigation commits to move these observers to
963 // the committed document.
964 [[nodiscard]] std::vector<
965 mojo::PendingReceiver<network::mojom::TrustTokenAccessObserver>>
966 TakeTrustTokenObservers();
967
Tsuyoshi Horobcd0b9f62023-06-28 11:35:32968 // Take all shared dictionary observers associated with this navigation.
969 // Typically this is called when navigation commits to move these observers to
970 // the committed document.
971 [[nodiscard]] std::vector<
972 mojo::PendingReceiver<network::mojom::SharedDictionaryAccessObserver>>
973 TakeSharedDictionaryAccessObservers();
974
Daniel Rubery6420d74302024-11-19 01:42:40975 [[nodiscard]] std::vector<
976 mojo::PendingReceiver<network::mojom::DeviceBoundSessionAccessObserver>>
977 TakeDeviceBoundSessionAccessObservers();
978
danakjc492bf82020-09-09 20:02:44979 // Returns the coop status information relevant to the current navigation.
980 CrossOriginOpenerPolicyStatus& coop_status() { return coop_status_; }
981
Rakina Zata Amni21e66f22021-09-17 00:41:51982 // Returns true if this is a NavigationRequest represents a WebView
983 // loadDataWithBaseUrl navigation.
Rakina Zata Amni8a1c6b32021-09-29 06:41:29984 bool IsLoadDataWithBaseURL() const;
Rakina Zata Amnieca27992020-12-12 10:48:31985
Robbie McElrathe28ca822021-09-27 20:23:29986 // Calculates the origin that this NavigationRequest may commit.
987 //
988 // GetTentativeOriginAtRequestTime must be called before the final HTTP
989 // response is received (unlike GetOriginToCommit), but the returned origin
990 // may differ from the final origin committed by this navigation (e.g. the
991 // origin may change because of subsequent redirects, or because of CSP
Lukasz Anforowicz435e68d2022-11-09 21:47:44992 // headers in the final response; or because no commit may happen at all in
993 // case of downloads or 204 responses). Prefer to use GetOriginToCommit if
Robbie McElrathe28ca822021-09-27 20:23:29994 // possible.
995 url::Origin GetTentativeOriginAtRequestTime();
996
Daniel Cheng738266dc2020-09-11 19:56:28997 // If this navigation fails with net::ERR_BLOCKED_BY_CLIENT, act as if it were
998 // cancelled by the user and do not commit an error page.
999 void SetSilentlyIgnoreBlockedByClient() {
1000 silently_ignore_blocked_by_client_ = true;
1001 }
1002
W. James MacLean46cf26212020-10-01 16:43:371003 // Returns the current url from GetURL() packaged with other state required to
1004 // properly determine SiteInstances and process allocation.
1005 UrlInfo GetUrlInfo();
1006
arthursonzogni7ddc6542021-04-09 09:16:501007 bool is_overriding_user_agent() const {
1008 return commit_params_->is_overriding_user_agent;
Rakina Zata Amnib597d632020-12-01 00:56:001009 }
1010
Matt Menke7f2e1ac52020-12-10 01:16:101011 // Returns the IsolationInfo that should be used to load subresources.
1012 const net::IsolationInfo& isolation_info_for_subresources() const {
1013 return isolation_info_for_subresources_;
1014 }
1015
Rakina Zata Amni1f34f4d2020-12-12 09:36:211016 // NeedsUrlLoader() returns true if the navigation needs to use the
1017 // NavigationURLLoader for loading the document.
1018 //
1019 // A few types of navigations don't make any network requests. They can be
1020 // committed immediately in BeginNavigation(). They self-contain the data
1021 // needed for commit:
1022 // - about:blank: The renderer already knows how to load the empty document.
1023 // - about:srcdoc: The data is stored in the iframe srcdoc attribute.
1024 // - same-document: Only the history and URL are updated, no new document.
1025 // - MHTML subframe: The data is in the archive, owned by the main frame.
1026 //
1027 // Note #1: Even though "data:" URLs don't generate actual network requests,
1028 // including within MHTML subframes, they are still handled by the network
1029 // stack. The reason is that a few of them can't always be handled otherwise.
1030 // For instance:
1031 // - the ones resulting in downloads.
1032 // - the "invalid" ones. An error page is generated instead.
1033 // - the ones with an unsupported MIME type.
1034 // - the ones targeting the top-level frame on Android.
1035 //
1036 // Note #2: Even though "javascript:" URL and RendererDebugURL fit very well
1037 // in this category, they don't use the NavigationRequest.
1038 //
Nate Chapin060cb952023-02-08 21:13:071039 // Note #3: Navigations that do not use a URL loader do not send the usual
1040 // set of callbacks to NavigationThrottle. Instead, they send a single
1041 // separate callback, WillCommitWithoutUrlLoader().
Rakina Zata Amni1f34f4d2020-12-12 09:36:211042 bool NeedsUrlLoader();
1043
Jonathan Hao90ddbd42023-07-12 14:23:481044 network::mojom::PrivateNetworkRequestPolicy private_network_request_policy()
Arthur Hemery373a7802020-12-23 16:32:361045 const {
Jonathan Hao90ddbd42023-07-12 14:23:481046 return private_network_request_policy_;
Arthur Hemery373a7802020-12-23 16:32:361047 }
1048
Alexander Timin23c110b2021-01-14 02:39:041049 // Whether this navigation request waits for the result of beforeunload before
1050 // proceeding.
1051 bool IsWaitingForBeforeUnload();
1052
Rakina Zata Amni6345d2f2021-02-12 04:07:571053 // Returns the original request url:
1054 // - If this navigation resulted in an error page, this will return the URL
1055 // of the page that failed to load.
1056 // - If this is navigation is triggered by loadDataWithBaseURL or related
1057 // functions, this will return the data URL (or data header, in case of
1058 // loadDataAsStringWithBaseURL).
1059 // - Otherwise, this will return the first URL in |redirect_chain_|. This
1060 // means if the navigation is started due to a client redirect, we will return
1061 // the URL of the page that initiated the client redirect. Otherwise we will
1062 // return the first destination URL for this navigation.
1063 // NOTE: This might result in a different value than original_url in
1064 // |commit_params_|, which is always set to the first destination URL for this
1065 // navigation.
1066 const GURL& GetOriginalRequestURL();
1067
Kevin McNeeb49d2b82022-06-14 16:53:141068 // The previous main frame URL. This may be empty if there was no last
1069 // committed entry.
1070 const GURL& GetPreviousMainFrameURL() const;
1071
Carlos Caballeroa3837972021-04-13 12:25:381072 // Whether this navigation is activating an existing page (e.g. served from
1073 // the BackForwardCache or Prerender)
Julie Jeongeun Kim5a66adb42021-08-11 07:14:101074 bool IsPageActivation() const override;
Carlos Caballeroa3837972021-04-13 12:25:381075
Rakina Zata Amnida410b462024-09-17 00:07:481076 // Returns whether the navigation type is a restore navigation.
1077 bool IsRestore() const;
1078
1079 // Returns whether the navigation type is a reload navigation.
1080 bool IsReload() const;
1081
Harkiran Bolaria8bee0062021-08-12 10:06:341082 // Sets state pertaining to prerender activations. This is only called if
1083 // this navigation is a prerender activation.
1084 void SetPrerenderActivationNavigationState(
1085 std::unique_ptr<NavigationEntryImpl> prerender_navigation_entry,
1086 const blink::mojom::FrameReplicationState& replication_state);
Harkiran Bolaria59290d62021-03-17 01:53:011087
1088 std::unique_ptr<NavigationEntryImpl> TakePrerenderNavigationEntry();
1089
Harkiran Bolaria8bee0062021-08-12 10:06:341090 // Returns value that is only valid for prerender activation navigations.
1091 const blink::mojom::FrameReplicationState&
1092 prerender_main_frame_replication_state() {
1093 return prerender_navigation_state_->prerender_main_frame_replication_state;
1094 }
1095
W. James MacLean53e24b72023-05-09 20:57:071096 // Origin-keyed Agent Cluster (OAC) state needs to be tracked for origins that
1097 // opt-in or opt-out, so that a given origin is treated consistently within a
1098 // given BrowsingInstance. This ensures that foo.example.com will have the
1099 // same OAC state in a BrowsingInstance even if multiple documents in the
1100 // origin have different headers.
1101 //
1102 // This function ensures that this OAC state is tracked in cases where it is
1103 // not handled elsewhere. For example, OAC origins that end up in origin-keyed
1104 // processes already track their OAC state during SiteInstance creation.
1105 // However, SiteInstance does not track origin state in the following cases,
1106 // which this function handles:
1107 //
1108 // 1) If process isolation for OAC is disabled (e.g., on low-memory Android
1109 // devices), the origin will use a site-keyed SiteInstance that does not
1110 // record OAC state for the origin.
1111 //
1112 // 2) If the origin has no header but ends up with OAC-by-default (and
1113 // kOriginKeyedProcessesByDefault is not enabled), the origin will use a
1114 // site-keyed SiteInstance.
1115 //
1116 // 3) If the origin opts-out of OAC using a header, it will use a site-keyed
1117 // SiteInstance.
1118 //
W. James MacLean2a84fbf2023-05-12 18:13:431119 // 4)If the origin opts-in to OAC using a header, but it is first placed in a
1120 // speculative RenderFrameHost before the header is received, it creates a
1121 // SiteInfo with default isolation and an origin-keyed process (by default).
1122 // In this case, the origin was not tracked when the SiteInstance was created,
1123 // and needs to be tracked later when the opt-in header is observed.
1124 //
W. James MacLean53e24b72023-05-09 20:57:071125 // In all of these cases, this function updates the BrowsingInstance to keep
1126 // track of the OAC state for this NavigationRequest's origin.
1127 //
1128 // TODO(wjmaclean): Cases 1 and 2 will not be necessary once we use
1129 // origin-keyed SiteInstances within a site-keyed process, via
W. James MacLean2a84fbf2023-05-12 18:13:431130 // SiteInstanceGroup. Cases 3 and 4 will still be needed at that point, but
1131 // might become simpler.
W. James MacLean53e24b72023-05-09 20:57:071132 void AddOriginAgentClusterStateIfNecessary(
1133 const IsolationContext& isolation_context);
1134
Antonio Sartori0a7117a2021-04-01 09:23:371135 // Store a console message, which will be sent to the final RenderFrameHost
1136 // immediately after requesting the navigation to commit.
1137 //
1138 // /!\ WARNING /!\: Beware of not leaking cross-origin information to a
1139 // potentially compromised renderer when using this method.
1140 void AddDeferredConsoleMessage(blink::mojom::ConsoleMessageLevel level,
1141 std::string message);
1142
Yao Xiao6e1f7d32022-01-07 03:28:401143 bool is_deferred_on_fenced_frame_url_mapping_for_testing() const {
1144 return is_deferred_on_fenced_frame_url_mapping_;
1145 }
1146
Harkiran Bolariaba823e42021-05-21 18:30:361147 base::WeakPtr<NavigationRequest> GetWeakPtr();
1148
Khushal Sagarc05a8b292024-02-28 15:29:251149 bool is_running_potential_prerender_activation_checks() const {
1150 return is_running_potential_prerender_activation_checks_;
Hiroki Nakagawa6c5f39bd2021-07-13 00:22:361151 }
1152
Avi Drissmanbd153642024-09-03 18:58:051153 FrameTreeNodeId prerender_frame_tree_node_id() const {
David Bokanf7db7062021-05-27 16:23:101154 DCHECK(prerender_frame_tree_node_id_.has_value())
1155 << "Must be called after StartNavigation()";
1156 return prerender_frame_tree_node_id_.value();
Harkiran Bolariaba823e42021-05-21 18:30:361157 }
1158
Arthur Sonzognic686e8f2024-01-11 08:36:371159 const std::optional<FencedFrameProperties>& GetFencedFrameProperties() const {
Garrett Tanzer291a2d52023-03-20 22:41:571160 return fenced_frame_properties_;
1161 }
1162
Garrett Tanzer29de7112022-12-06 21:26:321163 // Compute and return the `FencedFrameProperties` that this
1164 // `NavigationRequest` acts under, i.e. the properties attached to this
Xiaochen Zhou86f2e712023-09-13 19:55:041165 // `NavigationRequest` if present.
1166 // Otherwise, returns the fenced frame properties associated with the given
1167 // source. See `FrameTreeNode::GetFencedFrameProperties()` on how fenced
1168 // frame properties are obtained for different sources.
Alison Gale770f3fc2024-04-27 00:39:581169 // TODO(crbug.com/40060657): Once navigation support for urn::uuid in iframes
Xiaochen Zhou86f2e712023-09-13 19:55:041170 // is deprecated, remove the parameter `node_source`.
Arthur Sonzognic686e8f2024-01-11 08:36:371171 const std::optional<FencedFrameProperties>& ComputeFencedFrameProperties(
Xiaochen Zhou86f2e712023-09-13 19:55:041172 FencedFramePropertiesNodeSource node_source =
1173 FencedFramePropertiesNodeSource::kClosestAncestor) const;
Garrett Tanzer29de7112022-12-06 21:26:321174
Arthur Sonzognic686e8f2024-01-11 08:36:371175 const std::optional<base::UnguessableToken> ComputeFencedFrameNonce() const;
Garrett Tanzer34cb92fe2022-09-28 17:50:541176
Daniel Chenge8b69402021-05-25 20:44:441177 void RenderFallbackContentForObjectTag();
1178
Titouan Rigoudy6f54ec52021-07-12 19:36:341179 // Returns the vector of web features used during the navigation, whose
1180 // recording was delayed until the new document that used them commits.
1181 //
1182 // Empties this instance's vector.
1183 std::vector<blink::mojom::WebFeature> TakeWebFeaturesToLog();
1184
Yao Xiao58c2f2c2023-05-16 20:05:181185 void set_subresource_proxying_url_loader_service_bind_context(
1186 base::WeakPtr<SubresourceProxyingURLLoaderService::BindContext>
1187 bind_context) {
1188 DCHECK(!subresource_proxying_url_loader_service_bind_context_);
1189 subresource_proxying_url_loader_service_bind_context_ = bind_context;
Yao Xiao549be4472023-01-03 22:53:121190 }
1191
Ming-Ying Chungae4dbb72023-12-07 05:32:371192 base::WeakPtr<KeepAliveURLLoaderService::FactoryContext>
1193 keep_alive_url_loader_factory_context() {
1194 return keep_alive_url_loader_factory_context_;
1195 }
1196
Ming-Ying Chung977404c2023-11-08 12:30:101197 void set_keep_alive_url_loader_factory_context(
Rakina Zata Amnia68329fe2025-07-02 10:15:031198 base::WeakPtr<KeepAliveURLLoaderService::FactoryContext> factory_context);
Ming-Ying Chung977404c2023-11-08 12:30:101199
Nan Linc643c962025-02-21 01:47:431200 base::WeakPtr<KeepAliveURLLoaderService::FactoryContext>
1201 fetch_later_loader_factory_context() {
1202 return fetch_later_loader_factory_context_;
1203 }
1204
Ming-Ying Chung977404c2023-11-08 12:30:101205 void set_fetch_later_loader_factory_context(
Rakina Zata Amnia68329fe2025-07-02 10:15:031206 base::WeakPtr<KeepAliveURLLoaderService::FactoryContext> factory_context);
1207
1208 void SetKeepAliveURLLoaderFactoryContextForTesting(
1209 base::WeakPtr<KeepAliveURLLoaderService::FactoryContext> factory_context);
1210 void SetFetchLaterLoaderFactoryContextForTesting(
1211 base::WeakPtr<KeepAliveURLLoaderService::FactoryContext> factory_context);
Ming-Ying Chung977404c2023-11-08 12:30:101212
Lukasz Anforowicz0e07b7652021-06-04 18:27:511213 // Helper for logging crash keys related to a NavigationRequest (e.g.
Lukasz Anforowicz36d24d32022-02-15 19:02:531214 // "navigation_request_url", "navigation_request_initiator", and
1215 // "navigation_request_is_same_document"). The crash keys will be logged if a
1216 // ScopedCrashKeys instance exists when a crash or DumpWithoutCrashing
1217 // happens.
Lukasz Anforowicz0e07b7652021-06-04 18:27:511218 class ScopedCrashKeys {
1219 public:
1220 explicit ScopedCrashKeys(NavigationRequest& navigation_request);
1221 ~ScopedCrashKeys();
1222
1223 // No copy constructor and no copy assignment operator.
1224 ScopedCrashKeys(const ScopedCrashKeys&) = delete;
1225 ScopedCrashKeys& operator=(const ScopedCrashKeys&) = delete;
1226
1227 private:
1228 url::debug::ScopedOriginCrashKey initiator_origin_;
Lukasz Anforowicz36d24d32022-02-15 19:02:531229 url::debug::ScopedUrlCrashKey url_;
1230 base::debug::ScopedCrashKeyString is_same_document_;
Lukasz Anforowicz0e07b7652021-06-04 18:27:511231 };
1232
W. James MacLean00568d72022-02-24 19:36:551233 // Used in tests to indicate this navigation should force a BrowsingInstance
1234 // swap.
1235 void set_force_new_browsing_instance(bool force_new_browsing_instance) {
1236 force_new_browsing_instance_ = force_new_browsing_instance;
1237 }
1238
1239 // When this returns true, it indicates this navigation should force a
1240 // BrowsingInstance swap. Used only in tests.
1241 bool force_new_browsing_instance() { return force_new_browsing_instance_; }
1242
Steve Kobes8d111ba2024-11-12 15:23:511243 // Marks this navigation as requiring a new compositor (RenderWidgetHost).
1244 void set_force_new_compositor(bool force_new_compositor) {
1245 force_new_compositor_ = force_new_compositor;
1246 }
1247
1248 // True if this navigation requires a new compositor (RenderWidgetHost).
1249 bool force_new_compositor() { return force_new_compositor_; }
1250
Julie Jeongeun Kim4a5fef22022-04-02 02:08:381251 const scoped_refptr<NavigationOrDocumentHandle>&
1252 navigation_or_document_handle() {
1253 return navigation_or_document_handle_;
1254 }
1255
Khushal Sagar7b26135c62022-11-08 20:25:421256 // Initializes state which is passed from the old Document to the new Document
1257 // for a ViewTransition.
Khushal Sagar91b544222024-03-12 17:36:591258 void SetViewTransitionState(
1259 std::unique_ptr<ScopedViewTransitionResources> resources,
1260 blink::ViewTransitionState view_transition_state);
Khushal Sagar7b26135c62022-11-08 20:25:421261
Jonathan Njeunje58618592023-04-06 21:10:021262 // Returns a const reference to a blink::RuntimeFeatureStateContext (RFSC)
1263 // object. Once the commit params are sent to the renderer we no longer allow
1264 // write access to the RFSC, but read access is still available.
sbinglera07ae732022-12-02 20:49:051265 //
Jonathan Njeunje58618592023-04-06 21:10:021266 // Note: This method has another
1267 // version, `GetMutableRuntimeFeatureStateContext()`, accessible via
1268 // NavigationHandle and will return a mutable reference to the RFSC.
sbinglera07ae732022-12-02 20:49:051269 const blink::RuntimeFeatureStateContext& GetRuntimeFeatureStateContext();
1270
Arthur Hemerya2e2c5f12023-01-16 15:00:151271 BrowsingContextGroupSwap browsing_context_group_swap() const {
1272 return browsing_context_group_swap_;
1273 }
1274
Nate Chapin6c43c022023-02-13 23:32:421275 // If the navigation fails before commit and |pending_navigation_api_key_| has
1276 // been set, then the renderer will be notified of the pre-commit failure and
1277 // provide |pending_navigation_api_key_| so that the Navigation API can fire
1278 // events and reject promises.
1279 // This should only be set if this request's frame initiated the navigation,
1280 // because only the initiating frame has outstanding promises to reject.
Arthur Sonzognic686e8f2024-01-11 08:36:371281 void set_pending_navigation_api_key(std::optional<std::string> key) {
Nate Chapin6c43c022023-02-13 23:32:421282 pending_navigation_api_key_ = key;
1283 }
1284
Nate Chapin154b14b2023-02-17 18:28:161285 // Returns the navigation token for this request if this NavigationRequest
1286 // is for a history navigation, and it might be cancelled via the navigate
1287 // event. In that case, any associated subframe history navigations will be
1288 // deferred until this navigation commits.
1289 // This may only be called if this is a main-frame same-document navigation.
1290 // Will return a valid token if canceling traversals via the navigate event is
1291 // enabled, this is a history navigation, a navigate event is registered in
1292 // the renderer, and the frame has met the user activation requirements to be
1293 // allowed to cancel the navigation.
1294 // This token will then be provided to the subframe NavigationRequests via
1295 // set_main_frame_same_document_history_token().
Arthur Sonzognic686e8f2024-01-11 08:36:371296 std::optional<base::UnguessableToken>
Nate Chapin154b14b2023-02-17 18:28:161297 GetNavigationTokenForDeferringSubframes();
1298
1299 // For subframe NavigationRequests, these set and return the main frame's
1300 // NavigationRequest token, in the case that the main frame returns it from
Nate Chapin17e648f2023-05-09 16:58:351301 // GetNavigationTokenForDeferringSubframes(). Note that by the time
1302 // `main_frame_same_document_history_token()` is called, the NavigationRequest
1303 // represented by that token may have already finished and been deleted, so
1304 // any attempt to lookup based on this token must null-check the request.
Nate Chapin154b14b2023-02-17 18:28:161305 void set_main_frame_same_document_history_token(
Arthur Sonzognic686e8f2024-01-11 08:36:371306 std::optional<base::UnguessableToken> token) {
Nate Chapin154b14b2023-02-17 18:28:161307 main_frame_same_document_navigation_token_ = token;
1308 }
Arthur Sonzognic686e8f2024-01-11 08:36:371309 std::optional<base::UnguessableToken>
Nate Chapin154b14b2023-02-17 18:28:161310 main_frame_same_document_history_token() {
1311 return main_frame_same_document_navigation_token_;
1312 }
1313
1314 // When a SubframeHistoryNavigationThrottle is created, it registers itself
1315 // with the NavigationRequest for the main frame. If the main frame
1316 // NavigationRequest commits, then these throttles will be resumed in
1317 // UnblockPendingSubframeNavigationRequestsIfNeeded().
1318 // If it is canceled instead, these throttles will all be canceled.
1319 // Takes a WeakPtr because `throttle` is owned by another NavigationRequest,
1320 // and that request may be canceled outside of our control, in which case
1321 // `throttle` will be destroyed.
1322 void AddDeferredSubframeNavigationThrottle(
1323 base::WeakPtr<SubframeHistoryNavigationThrottle> throttle);
1324
Mingyu Lei1fa6a1f2023-02-21 13:17:461325 std::unique_ptr<RenderFrameHostImpl::CookieChangeListener>
1326 TakeCookieChangeListener() {
1327 return std::move(cookie_change_listener_);
1328 }
1329
Daniel Rubery03e71992025-02-19 22:03:301330 std::unique_ptr<RenderFrameHostImpl::DeviceBoundSessionObserver>
1331 TakeDeviceBoundSessionObserver() {
1332 return std::move(device_bound_session_observer_);
1333 }
1334
Rakina Zata Amni49657c772023-03-31 06:41:531335 // Returns true if there is a speculative RFH that has a pending commit
1336 // cross-document navigation, and this NavigationRequest is not a pending
1337 // commit NavigationRequest itself. This means that this navigation should be
1338 // queued (i.e. wait for the pending commit navigation to finish committing),
1339 // before continuing and creating a new speculative RFH to commit in, so that
1340 // it won't cause the existing pending commit RFH to be deleted. This function
1341 // should only be called for navigations that are owned by the FrameTreeNode
1342 // (i.e. it hasn't moved to the RenderFrameHost that it will commit in yet),
1343 // as only those navigations can be queued.
1344 bool ShouldQueueDueToExistingPendingCommitRFH() const;
1345
1346 void set_resume_commit_closure(base::OnceClosure closure) {
Daniel Chengd08a43a2023-03-16 05:10:501347 resume_commit_closure_ = std::move(closure);
1348 }
1349
Daniel Cheng557868f2023-07-28 00:10:201350 // Records metrics for `GetFrameHostForNavigation()` attempts that failed due
1351 // to this `NavigationRequest` being in the pending commit state.
1352 // `commit_attempt` should be true if `GetFrameHostForNavigation()` failed
1353 // when trying to get a RenderFrameHost when committing a navigation.
1354 void RecordMetricsForBlockedGetFrameHostAttempt(bool commit_attempt);
1355
Rakina Zata Amni208f7672023-04-07 12:21:251356 // Creates a WebUI object for this navigation and saves it in `web_ui_`. Later
Rakina Zata Amni4fffc982023-04-09 12:44:121357 // on, the WebUI created will be moved to `frame_host` (if `frame_host` is
1358 // null, it means a RenderFrameHost has not been picked for the navigation).
Rakina Zata Amnibbae6512023-04-11 21:49:501359 void CreateWebUIIfNeeded(RenderFrameHostImpl* frame_host);
Rakina Zata Amni208f7672023-04-07 12:21:251360
1361 bool HasWebUI() { return !!web_ui_; }
1362
Rakina Zata Amnibbae6512023-04-11 21:49:501363 WebUIImpl* web_ui() { return web_ui_.get(); }
1364
Rakina Zata Amni208f7672023-04-07 12:21:251365 std::unique_ptr<WebUIImpl> TakeWebUI() {
1366 CHECK(HasWebUI());
1367 return std::move(web_ui_);
1368 }
Rakina Zata Amnia2292302023-04-04 06:22:111369
Camillia Smith Barnes3cad1ba2023-10-30 20:10:161370 bool shared_storage_writable_eligible() const {
1371 return shared_storage_writable_eligible_;
1372 }
Camillia Smith Barnes6d2966c82023-08-23 21:16:181373
Rakina Zata Amni1ca8dfdb2023-04-22 01:59:261374 enum ErrorPageProcess {
1375 kNotErrorPage,
1376 kPostCommitErrorPage,
1377 kCurrentProcess,
1378 kDestinationProcess,
1379 kIsolatedProcess
1380 };
1381 // Helper to determine whether a navigation is committing an error page and
1382 // should stay in the current process (kCurrentProcess), the destination
1383 // URL's process (kDestinationProcess), an isolated process
1384 // (kIsolatedProcess), or is a post-commit error page that does not have any
1385 // specific process requirements and goes through the "normal navigation"
1386 // path. Returns kNotErrorPage if the navigation is not anerror page
1387 // navigation.
1388 ErrorPageProcess ComputeErrorPageProcess();
1389
Alex Moshchuk854e0be72023-08-04 22:35:351390 // This describes the reason for performing an early RenderFrameHost swap, if
1391 // any. This enum is used in UMA histograms, so existing values should be
1392 // neither reordered nor removed.
1393 enum class EarlyRenderFrameHostSwapType {
1394 kNone = 0,
1395 kInitialFrame = 1,
1396 kCrashedFrame = 2,
Khushal Sagar3e7ea372024-05-28 13:34:481397 kNavigationTransition = 3, // DEPRECATED
Alex Moshchuk663e88d2023-09-15 16:21:001398 kMaxValue = kNavigationTransition,
Alex Moshchuk854e0be72023-08-04 22:35:351399 };
1400
1401 // Remember if this navigation triggered an early swap of a speculative
1402 // RenderFrameHost to become a current RenderFrameHost prior to the
1403 // navigation commit, and if so, what triggered it.
1404 void set_early_render_frame_host_swap_type(
1405 EarlyRenderFrameHostSwapType type) {
1406 early_render_frame_host_swap_type_ = type;
1407 }
Lijin Shene4511c12024-03-19 19:31:301408 EarlyRenderFrameHostSwapType early_render_frame_host_swap_type() const {
Alex Moshchuk663e88d2023-09-15 16:21:001409 return early_render_frame_host_swap_type_;
1410 }
Alex Moshchuk854e0be72023-08-04 22:35:351411
Rakina Zata Amni0c8ffbe2023-10-05 19:32:561412 void set_previous_render_frame_host_id(GlobalRenderFrameHostId id) {
1413 previous_render_frame_host_id_ = id;
1414 }
1415
murakinonokac3e32a32024-01-16 06:01:301416 // Returns true if URL Loader has been created and hasn't been reset yet for
1417 // this navigation.
1418 bool HasLoader() const;
1419
Khushal Sagar2dd8a3d2024-02-13 20:49:251420 // Notifies that an IPC will be sent to the old Document's renderer to
Khushal Sagar21c626812024-02-29 23:32:181421 // dispatch the `pageswap` event. Returns the parameters which should be
Khushal Sagar2dd8a3d2024-02-13 20:49:251422 // used for the event if this is a same-origin navigation.
Khushal Sagar21c626812024-02-29 23:32:181423 blink::mojom::PageSwapEventParamsPtr WillDispatchPageSwap();
Khushal Sagar2dd8a3d2024-02-13 20:49:251424
Khushal Sagar21c626812024-02-29 23:32:181425 // Returns true if this navigation is eligible for dispatching a `pageswap`
Khushal Sagarc05a8b292024-02-28 15:29:251426 // event on the old Document and the event has not been dispatched already.
Khushal Sagar21c626812024-02-29 23:32:181427 bool ShouldDispatchPageSwapEvent() const;
Khushal Sagard48998dc2024-02-26 16:05:321428
Khushal Sagar8e966702024-03-13 19:49:161429 // Returns true if there have been any cross-origin redirects in the
1430 // navigation's lifetime. A redirect is cross-origin if the redirect url is
1431 // cross-origin with "previous URL" of the navigation. previous URL here is
1432 // either the initial URL (which the navigation started with) or the URL from
1433 // the last redirect.
1434 //
1435 // Note: This will be false if the initial url is cross-origin and there are
1436 // no redirects.
1437 bool did_encounter_cross_origin_redirect() const {
1438 return did_encounter_cross_origin_redirect_;
1439 }
1440
Vladimir Levin6e894a92024-06-12 18:02:461441 // Determines whether this navigation request was initiated by an animated
1442 // transition.
1443 void set_was_initiated_by_animated_transition() {
1444 was_initiated_by_animated_transition_ = true;
1445 }
1446 bool was_initiated_by_animated_transition() const {
1447 return was_initiated_by_animated_transition_;
1448 }
1449
Rakina Zata Amni58681c62024-06-25 06:32:131450 void set_navigation_discard_reason(
1451 NavigationDiscardReason navigation_discard_reason) {
1452 CHECK(!navigation_discard_reason_.has_value());
1453 navigation_discard_reason_ = navigation_discard_reason;
1454 }
1455
Keita Suzukif300e442025-07-16 07:38:111456 void set_extended_error_code(int extended_error_code) {
1457 CHECK(!extended_error_code_);
1458 extended_error_code_ = extended_error_code;
1459 }
1460
1461 void set_error_navigation_trigger(
1462 ErrorNavigationTrigger error_navigation_trigger) {
1463 CHECK(!error_navigation_trigger_.has_value());
1464 error_navigation_trigger_ = error_navigation_trigger;
1465 }
1466
Rakina Zata Amni63a7ab02024-09-15 07:40:031467 // Returns the type of this navigation (e.g. history, browser-initiated, etc)
1468 // to set as a discard reason on another navigation that is being discarded
1469 // because this navigation is taking its place in the FrameTreeNode.
Rakina Zata Amnib5dbc9f2024-07-16 07:47:331470 NavigationDiscardReason GetTypeForNavigationDiscardReason();
1471
Mustafa Emre Acer1001b3d2024-07-09 23:10:431472 void set_force_no_https_upgrade() { force_no_https_upgrade_ = true; }
1473
William Liu0c323bfce2024-11-13 21:21:101474 bool was_reset_for_cross_document_restart() const {
1475 return was_reset_for_cross_document_restart_;
1476 }
1477
Diana Qu2d6c85b2025-06-17 01:13:141478 // Returns the document sequence number from the associated
1479 // FrameNavigationEntry, if this NavigationRequest corresponds to a session
1480 // history navigation. The value is cleared if the navigation performs a
1481 // redirect or results in an origin change, in which case the
1482 // NavigationRequest is no longer tied to the original entry.
1483 int64_t frame_entry_document_sequence_number() const {
1484 return frame_entry_document_sequence_number_;
1485 }
1486
John Kim1a6735b2025-08-12 19:16:501487 // Returns the canvas noise token used for canvas noising on the renderer.
1488 // Only one token should be generated per page and should use the main frame's
1489 // origin to generate such. Main frames should use this accessor to populate
1490 // the content::Page and subsequent blink::Pages. Subframes should not use
1491 // this accessor, but instead should use `PageImpl::canvas_noise_token()` to
1492 // get the canvas noise token.
1493 std::optional<uint64_t> canvas_noise_token() {
1494 CHECK(IsInMainFrame());
1495 return canvas_noise_token_;
1496 }
1497
Alex Moshchuk8e9a7f92025-02-03 22:50:351498 // Called when the browser process is about to process beforeunload handlers
1499 // for this navigation, including sending an IPC to the renderer process to
1500 // run beforeunload handlers when necessary.
1501 void WillStartBeforeUnload();
1502
1503 // This struct holds timestamps of various stages of one navigation. This is
1504 // useful for recording a trace of a navigation, as well as metrics for
1505 // durations of all intervals within a navigation once a navigation finishes
1506 // committing. Note that a navigation finishes committing once
1507 // RenderFrameHostImpl::DidCommitNavigation completes, which could be slightly
1508 // after the corresponding NavigationRequest has been destroyed.
1509 //
1510 // Over the course of a navigation, various timestamps are kept in different
1511 // places, such as NavigationRequest fields, NavigationHandleTiming,
1512 // CommonNavigationParams, etc. The purpose of this struct is to bring all the
1513 // relevant timestamps into one place, and make it possible to record a
1514 // complete navigation timeline after NavigationRequest destruction. Note that
1515 // this is different from NavigationHandleTiming, because the latter is in
1516 // content/public and exposed to content embedders, making it tricky to modify
1517 // or extend.
1518 //
1519 // This struct should be created near the end of NavigationRequest's lifetime
1520 // (see `GenerateNavigationTimelineForMetrics()`), and `MarkFinish()` should
1521 // be called at the end of a navigation before using the `Timeline`'s
1522 // timestamp values in traces and metrics.
1523 struct Timeline {
1524 Timeline();
1525 Timeline(const Timeline& timeline);
1526 ~Timeline();
1527
1528 // Record the timestamp for when the navigation finishes. Should be done at
1529 // the end of RenderFrameHostImpl::DidCommitNavigationInternal() before
1530 // recording a trace of this timeline.
1531 void MarkFinish();
1532
1533 // The timestamps below are in chronological order. Note that some of them
1534 // might be null depending on the navigation (e.g., navigations that don't
1535 // use the network stack will not populate the loader-related timestamps,
1536 // and renderer-initiated same-document navigations would be missing most
1537 // timestamps except for `start`, `finish`, and the DidCommit IPC
1538 // timestamps).
1539
Charlie Reise1d9b8182025-04-02 04:32:121540 // The time at which the navigation starts, as accurately as we can
1541 // determine. Note that for renderer-initiated navigations, this will be the
1542 // time when the navigation starts in the renderer.
Alex Moshchuk8e9a7f92025-02-03 22:50:351543 //
Charlie Reise1d9b8182025-04-02 04:32:121544 // Note that this may not be the start time used by many current navigation
1545 // related metrics, such as FCP, since those often use `common_params_start`
1546 // to avoid including beforeunload durations.
1547 // TODO(crbug.com/385170155): Update these metrics to have a more consistent
1548 // and representative start time and duration.
Alex Moshchuk8e9a7f92025-02-03 22:50:351549 base::TimeTicks start;
1550
Charlie Reise1d9b8182025-04-02 04:32:121551 // For navigations that start in the renderer and target local frames, this
1552 // is the time at which "beforeunload phase 1" starts, when ShouldClose is
1553 // called for any local frames that may be affected. This is null for other
1554 // types of navigations which do not use beforeunload phase 1 (e.g., browser
1555 // initiated navigations, or navigations that target remote frames). See
1556 // also beforeunload_phase2_start, for the second phase of running
1557 // beforeunload handlers which may exist in other processes.
1558 //
1559 // The delta between this and `start` captures the time the renderer process
1560 // spends initializing the navigation, including notifying
1561 // RenderFrameObserver::DidStartNavigation observers.
1562 base::TimeTicks beforeunload_phase1_start;
1563
1564 // The time "beforeunload phase 1" ends in the initiating renderer process,
1565 // or null if that phase is not used in this navigation. Recording this
1566 // allows beforeunload duration to be excluded from navigation metrics,
1567 // since that time may include user-visible dialogs or JavaScript code that
1568 // is out of our control.
1569 base::TimeTicks beforeunload_phase1_end;
1570
Alex Moshchuk8e9a7f92025-02-03 22:50:351571 // The time at which the NavigationRequest is created. The delta between
1572 // this and `start` covers the time between starting the navigation
1573 // (possibly in the renderer process) and the browser process starting
Charlie Reise1d9b8182025-04-02 04:32:121574 // doing work for it. It is often useful to exclude beforeunload phase 1
1575 // duration from this delta.
Alex Moshchuk8e9a7f92025-02-03 22:50:351576 base::TimeTicks navigation_request_creation;
1577
Charlie Reise1d9b8182025-04-02 04:32:121578 // The time "beforeunload phase 2" processing was started by the browser
1579 // process. This phase can occur on any type of navigation (e.g., browser or
1580 // renderer initiated), to run beforeunload handlers in any process that may
1581 // be affected by the navigation (e.g., remote frames, OOPIFs). Might be
1582 // null if the navigation did not need to run beforeunload handlers, or if
1583 // all of the necessary handlers have already run in "beforeunload phase 1."
1584 // Note that legacy PostTask cases (which do not run beforeunload handlers)
1585 // are not treated as beforeunload phase 2.
Alex Moshchuk8e9a7f92025-02-03 22:50:351586 //
1587 // The delta between this and `navigation_request_creation` captures the
1588 // time the browser process spends initializing the navigation, including
1589 // creating a speculative RenderFrameHost (if needed) and picking a target
1590 // SiteInstance/process.
Charlie Reise1d9b8182025-04-02 04:32:121591 base::TimeTicks beforeunload_phase2_start;
Alex Moshchuk8e9a7f92025-02-03 22:50:351592
Charlie Reise1d9b8182025-04-02 04:32:121593 // The time "beforeunload phase 2" processing ends, or null if that phase is
1594 // not used in this navigation. Recording this allows beforeunload duration
1595 // to be excluded from navigation metrics, since that may include
1596 // user-visible dialogs or JavaScript code that is out of our control.
1597 base::TimeTicks beforeunload_phase2_end;
1598
1599 // The adjusted start time used by many navigation metrics, such as FCP.
1600 // This is currently set inconsistently, and can be after beforeunload phase
1601 // 1 in the initiating renderer, or early in a browser-initiated navigation,
1602 // or after beforeunload phase 2 in the browser process if that phase is
1603 // used. As a result, this value may not be in chronological order in this
1604 // struct, and it is mainly recorded here for metrics that measure the start
1605 // time inconsistency.
1606 // TODO(crbug.com/385170155): Remove this once navigation start metrics are
1607 // more consistent.
1608 base::TimeTicks common_params_start;
1609
1610 // The time at which NavigationRequest::BeginNavigation() is called. This is
1611 // a decision point at which a network request may or may not be made. The
1612 // delta between this and `navigation_request_creation` (with any
1613 // beforeunload phase 2 duration removed) captures additional navigation
1614 // work in the browser process.
Alex Moshchuk8e9a7f92025-02-03 22:50:351615 base::TimeTicks begin_navigation;
1616
1617 // The time at which the NavigationURLLoader for the navigation was started.
1618 // This captures the time for additional initialization in the browser
1619 // process before the network request is sent, including processing of
1620 // WillStartRequest NavigationThrottle events.
1621 base::TimeTicks loader_start;
1622 // The time when the browser is ready to fetch the document using an HTTP
1623 // request.
1624 base::TimeTicks loader_fetch_start;
1625 // The time when the final (which might also be the first) headers are
1626 // received.
1627 base::TimeTicks loader_receive_headers;
1628 // The time when the HTTP response is received and
1629 // NavigationRequest::OnResponseStarted() is called. The delta between this
1630 // and `loader_start` captures the time spent waiting for a response from
1631 // the network stack.
1632 base::TimeTicks receive_response;
1633 // The time when the CommitNavigation IPC is sent to the renderer process.
1634 // Might be null if a navigation doesn't send the CommitNavigation IPC, such
1635 // as for renderer-initiated same-document navigations or synchronous
1636 // about:blank navigations. The delta between this and `receive_response`
1637 // captures the time spent running throttles and possibly selecting a more
1638 // appropriate renderer process.
1639 base::TimeTicks commit_ipc_sent;
1640 // The time when the renderer receives the CommitNavigation IPC. Taken in
1641 // the renderer process. Might be null in the same cases as
1642 // `commit_ipc_sent` above. The delta between this and `commit_ipc_sent`
1643 // represents the mojo and task delay to deliver the CommitNavigation
1644 // message from the browser process to renderer process.
1645 base::TimeTicks renderer_commit_ipc_received;
1646 // The time when the renderer finishes processing the navigation commit and
1647 // replies to the browser's CommitNavigation IPC. Taken in the renderer
1648 // process. The delta between this and `renderer_commit_ipc_received`
1649 // represents the total time the renderer process spend on committing the
1650 // navigation (e.g., swapping in the new frame/document and destroying the
1651 // old document).
1652 base::TimeTicks renderer_did_commit_ipc_sent;
1653 // The time at which the DidCommitNavigation IPC (which is usually a
1654 // response to the CommitNavigation IPC) is received by RenderFrameHost. The
1655 // delta between `renderer_did_commit_ipc_sent` and this represents the mojo
1656 // delay to deliver the response from the renderer process to the browser
1657 // process.
1658 base::TimeTicks did_commit_ipc_received;
1659 // The time at which DidCommitNavigation is completed. This includes the
1660 // time to commit the navigation, dispatch events such as
1661 // DidFinishNavigation() to observers, and destroy the NavigationRequest.
1662 // `MarkFinish()` is used to record this timestamp at the end of navigation.
1663 base::TimeTicks finish;
1664 };
1665
1666 // Fill in the timestamps needed to generate a trace of the navigation
1667 // timeline. This should only be called when processing the
1668 // DidCommitNavigation IPC, once the final DidCommitProvisionalLoadParams are
1669 // received from the renderer and timestamps from prior navigation stages are
1670 // already collected.
1671 //
1672 // Note that this leaves the `finish` timestamp empty in the returned
1673 // `Timeline` object. `finish` cannot be recorded within NavigationRequest
1674 // because a navigation actually ends after a NavigationRequest is destroyed.
1675 // `MarkFinish()` should be called on the returned `Timeline` to manually
1676 // record that timestamp before using it to record trace events or metrics.
1677 NavigationRequest::Timeline GenerateNavigationTimelineForMetrics(
1678 const mojom::DidCommitProvisionalLoadParams& params,
1679 const base::TimeTicks& did_commit_ipc_received_time);
1680
Hayato Ito5750b442025-05-29 02:38:061681 // Returns a UKM builder for the navigation timeline if UKMs should be
1682 // recorded for this navigation. Navigation timeline UKMs are recorded at the
1683 // frequency of 0.001.
1684 std::optional<ukm::builders::NavigationTimeline>
1685 GetNavigationTimelineUkmBuilder();
1686
Takashi Toyoshima96a07bb2025-06-06 06:45:581687 // Called when the NavigationThrottleRunner is done processing the navigation
1688 // event of type `event`. `result` is the final
1689 // NavigationThrottle::ThrottleCheckResult for this event.
1690 void OnNavigationEventProcessed(
1691 NavigationThrottleEvent event,
1692 NavigationThrottle::ThrottleCheckResult result);
1693
Jiacheng Guo2d8489d72025-08-18 06:51:141694 // Returns the PrerenderHostId driving the navigation. If the navigation
1695 // is not derived from a prerendered page, the default-consturcted null
1696 // value will be returned.
1697 PrerenderHostId GetPrerenderHostId() const;
1698
danakjc492bf82020-09-09 20:02:441699 private:
1700 friend class NavigationRequestTest;
Nasko Oskov32f95892025-06-02 20:45:081701 FRIEND_TEST_ALL_PREFIXES(NavigationRequestTest, SanitizeRedirectsForCommit);
danakjc492bf82020-09-09 20:02:441702
Antonio Sartori0a7117a2021-04-01 09:23:371703 struct ConsoleMessage {
1704 blink::mojom::ConsoleMessageLevel level;
1705 std::string message;
1706 };
1707
danakjc492bf82020-09-09 20:02:441708 NavigationRequest(
1709 FrameTreeNode* frame_tree_node,
Minggang Wangb9f3fa92021-07-01 15:30:311710 blink::mojom::CommonNavigationParamsPtr common_params,
1711 blink::mojom::BeginNavigationParamsPtr begin_params,
1712 blink::mojom::CommitNavigationParamsPtr commit_params,
danakjc492bf82020-09-09 20:02:441713 bool browser_initiated,
1714 bool from_begin_navigation,
Hiroki Nakagawaadcffc502021-06-16 10:47:511715 bool is_synchronous_renderer_commit,
danakjc492bf82020-09-09 20:02:441716 const FrameNavigationEntry* frame_navigation_entry,
1717 NavigationEntryImpl* navitation_entry,
1718 std::unique_ptr<NavigationUIData> navigation_ui_data,
Hiroki Nakagawab078d3ef2021-06-03 06:55:431719 scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory,
danakjc492bf82020-09-09 20:02:441720 mojo::PendingAssociatedRemote<mojom::NavigationClient> navigation_client,
Hiroki Nakagawaa67fe9c32021-06-04 01:15:491721 scoped_refptr<PrefetchedSignedExchangeCache>
1722 prefetched_signed_exchange_cache,
Arthur Sonzognic686e8f2024-01-11 08:36:371723 std::optional<base::SafeRef<RenderFrameHostImpl>>
Mingyu Lei2e0b586e2023-07-25 18:26:001724 rfh_restored_from_back_forward_cache,
John Delaney8623c642021-01-06 17:37:071725 int initiator_process_id,
Daniel Hosseinianf0fbfb42021-09-08 02:20:471726 bool was_opener_suppressed,
Nan Lin944e9b4e2022-04-12 13:51:221727 bool is_pdf,
Garrett Tanzer47852462022-07-20 18:16:411728 bool is_embedder_initiated_fenced_frame_navigation = false,
Rakina Zata Amniaf55b5b62022-07-19 23:11:031729 mojo::PendingReceiver<mojom::NavigationRendererCancellationListener>
Camillia Smith Barnes6a643962023-03-03 00:28:581730 renderer_cancellation_listener = mojo::NullReceiver(),
Arthur Sonzognic686e8f2024-01-11 08:36:371731 std::optional<std::u16string> embedder_shared_storage_context =
1732 std::nullopt);
danakjc492bf82020-09-09 20:02:441733
Hiroki Nakagawa6c5f39bd2021-07-13 00:22:361734 // Checks if this navigation may activate a prerendered page. If it's
1735 // possible, schedules to start running CommitDeferringConditions for
1736 // prerendered page activation and returns true.
1737 bool MaybeStartPrerenderingActivationChecks();
1738
1739 // Called from OnCommitDeferringConditionChecksComplete() if this request is
1740 // activating a prerendered page.
1741 void OnPrerenderingActivationChecksComplete(
1742 CommitDeferringCondition::NavigationType navigation_type,
Avi Drissmanbd153642024-09-03 18:58:051743 std::optional<FrameTreeNodeId> candidate_prerender_frame_tree_node_id);
Hiroki Nakagawa6c5f39bd2021-07-13 00:22:361744
Yao Xiao6e1f7d32022-01-07 03:28:401745 // Get the `FencedFrameURLMapping` associated with the current page.
1746 FencedFrameURLMapping& GetFencedFrameURLMap();
1747
1748 // True if this is a fenced frame navigation to an urn:uuid.
1749 bool NeedFencedFrameURLMapping();
1750
1751 // FencedFrameURLMapping::MappingResultObserver implementation.
1752 // Called from `FencedFrameURLMapping` when the mapping decision is made, and
1753 // resume the deferred navigation.
1754 void OnFencedFrameURLMappingComplete(
Arthur Sonzognic686e8f2024-01-11 08:36:371755 const std::optional<FencedFrameProperties>& properties) override;
Yao Xiao6e1f7d32022-01-07 03:28:401756
1757 // Called from BeginNavigation(), OnPrerenderingActivationChecksComplete(),
1758 // or OnFencedFrameURLMappingComplete().
Hiroki Nakagawa6c5f39bd2021-07-13 00:22:361759 void BeginNavigationImpl();
1760
Domenic Denicola5fdc2b7f2021-01-15 20:29:171761 // Checks if the response requests an isolated origin via the
1762 // Origin-Agent-Cluster header, and if so opts in the origin to be isolated.
danakjc492bf82020-09-09 20:02:441763 void CheckForIsolationOptIn(const GURL& url);
1764
Hiroki Nakagawa1aef8b02021-06-25 10:30:331765 // Returns whether this navigation request is requesting opt-in
1766 // origin-isolation.
W. James MacLeanc07dc41b2022-07-25 18:52:161767 bool IsOriginAgentClusterOptInRequested();
1768
1769 // Returns whether this navigation request is requesting opt-out from
1770 // origin-isolation. Always returns false if
1771 // AreOriginAgentClustersEnabledByDefault() is false.
1772 bool IsOriginAgentClusterOptOutRequested();
Hiroki Nakagawa1aef8b02021-06-25 10:30:331773
W. James MacLean53e24b72023-05-09 20:57:071774 // Returns whether this NavigationRequest should use an origin-keyed agent
1775 // cluster, specifically in cases where no Origin-Agent-Cluster header has
1776 // been observed, either because no response has yet been received or because
1777 // it had no such header. (Returns false if the header is observed.)
1778 //
1779 // Note that an origin-keyed process may be used if this returns true, if
1780 // kOriginKeyedProcessesByDefault is enabled.
Daniel Vogelheimc1413992021-12-02 22:54:081781 bool IsIsolationImplied();
1782
Hiroki Nakagawa1aef8b02021-06-25 10:30:331783 // The Origin-Agent-Cluster end result is determined early in the lifecycle of
1784 // a NavigationRequest, but used late. In particular, we want to trigger use
1785 // counters and console warnings once navigation has committed.
Daniel Vogelheimc1413992021-12-02 22:54:081786 void DetermineOriginAgentClusterEndResult();
Hiroki Nakagawa1aef8b02021-06-25 10:30:331787 void ProcessOriginAgentClusterEndResult();
1788
Daniel Cheng273a2c12022-09-28 02:28:221789 void PopulateDocumentTokenForCrossDocumentNavigation();
1790
danakjc492bf82020-09-09 20:02:441791 // NavigationURLLoaderDelegate implementation.
1792 void OnRequestRedirected(
1793 const net::RedirectInfo& redirect_info,
Brianna Goldsteind22b0642022-10-11 16:30:501794 const net::NetworkAnonymizationKey& network_anonymization_key,
danakjc492bf82020-09-09 20:02:441795 network::mojom::URLResponseHeadPtr response_head) override;
1796 void OnResponseStarted(
1797 network::mojom::URLLoaderClientEndpointsPtr url_loader_client_endpoints,
1798 network::mojom::URLResponseHeadPtr response_head,
1799 mojo::ScopedDataPipeConsumerHandle response_body,
Matt Menke7f615a12020-12-11 17:06:441800 GlobalRequestID request_id,
danakjc492bf82020-09-09 20:02:441801 bool is_download,
Brianna Goldsteind22b0642022-10-11 16:30:501802 net::NetworkAnonymizationKey network_anonymization_key,
Hiroshige Hayashizaki9e0f2862024-02-09 16:54:001803 SubresourceLoaderParams subresource_loader_params,
Kenichi Ishibashicf248fb2021-04-07 22:29:351804 EarlyHints early_hints) override;
danakjc492bf82020-09-09 20:02:441805 void OnRequestFailed(
1806 const network::URLLoaderCompletionStatus& status) override;
Arthur Sonzognic686e8f2024-01-11 08:36:371807 std::optional<NavigationEarlyHintsManagerParams>
Kenichi Ishibashi1f67a2d2021-09-02 01:36:481808 CreateNavigationEarlyHintsManagerParams(
Kenichi Ishibashif3f80522021-07-16 02:37:071809 const network::mojom::EarlyHints& early_hints) override;
Hiroshige Hayashizaki83cd1752025-07-31 17:46:251810 bool ShouldClearParsedHeadersOnTestReceiveRedirect() override;
danakjc492bf82020-09-09 20:02:441811
Daniel Chengd08a43a2023-03-16 05:10:501812 // Selecting a `RenderFrameHost` to commit a navigation may occasionally fail.
1813 // When this happens, the navigation will bind a closure to continue the
1814 // navigation and assign it to `resume_commit_closure_`. This closure may run
1815 // even when it is still not possible to proceed; see the comment on the
1816 // `resume_commit_closure_` field for the full details.
1817
1818 // Corresponds to navigations committing from `OnResponseStarted()`:
1819 void SelectFrameHostForOnResponseStarted(
1820 network::mojom::URLLoaderClientEndpointsPtr url_loader_client_endpoints,
1821 bool is_download,
Hiroshige Hayashizaki9e0f2862024-02-09 16:54:001822 SubresourceLoaderParams subresource_loader_params);
Daniel Chengdfb15f32023-04-26 05:17:021823 void SelectFrameHostForOnRequestFailedInternal(
Daniel Cheng77ae2b02023-05-10 04:16:461824 bool exists_in_cache,
Daniel Chengdfb15f32023-04-26 05:17:021825 bool skip_throttles,
Arthur Sonzognic686e8f2024-01-11 08:36:371826 const std::optional<std::string>& error_page_content);
Daniel Chengfa8ffcf2023-05-04 05:43:461827 void SelectFrameHostForCrossDocumentNavigationWithNoUrlLoader();
Daniel Chengd08a43a2023-03-16 05:10:501828
danakjc492bf82020-09-09 20:02:441829 // To be called whenever a navigation request fails. If |skip_throttles| is
1830 // true, the registered NavigationThrottle(s) won't get a chance to intercept
1831 // NavigationThrottle::WillFailRequest. It should be used when a request
1832 // failed due to a throttle result itself. |error_page_content| is only used
1833 // when |skip_throttles| is true. If |collapse_frame| is true, the associated
1834 // frame tree node is collapsed.
1835 void OnRequestFailedInternal(
1836 const network::URLLoaderCompletionStatus& status,
1837 bool skip_throttles,
Arthur Sonzognic686e8f2024-01-11 08:36:371838 const std::optional<std::string>& error_page_content,
danakjc492bf82020-09-09 20:02:441839 bool collapse_frame);
1840
danakjc492bf82020-09-09 20:02:441841 // Called when the NavigationThrottles have been checked by the
1842 // NavigationHandle.
1843 void OnStartChecksComplete(NavigationThrottle::ThrottleCheckResult result);
1844 void OnRedirectChecksComplete(NavigationThrottle::ThrottleCheckResult result);
1845 void OnFailureChecksComplete(NavigationThrottle::ThrottleCheckResult result);
1846 void OnWillProcessResponseChecksComplete(
1847 NavigationThrottle::ThrottleCheckResult result);
Nate Chapin060cb952023-02-08 21:13:071848 void OnWillCommitWithoutUrlLoaderChecksComplete(
1849 NavigationThrottle::ThrottleCheckResult result);
danakjc492bf82020-09-09 20:02:441850
Hiroki Nakagawa6c5f39bd2021-07-13 00:22:361851 // Runs CommitDeferringConditions.
1852 //
1853 // For prerendered page activation, this is called at the beginning of the
1854 // navigation (i.e., in BeginNavigation()). This is because activating a
1855 // prerendered page must be an atomic, synchronous operation so there is no
1856 // chance for the prerender to be cancelled during the operation. The
1857 // CommitDeferringConditions are asynchronous, so they run at the beginning
1858 // of navigation. Once they finish, the atomic activation sequence runs.
1859 void RunCommitDeferringConditions();
1860
David Bokan1bdb3701f2021-04-30 22:02:351861 // Similar to the NavigationThrottle checks above but this is called from
1862 // CommitDeferringConditionRunner rather than NavigationThrottles and is
1863 // invoked after all throttle checks and commit checks have completed and the
1864 // navigation can proceed to commit.
Hiroki Nakagawa6c5f39bd2021-07-13 00:22:361865 void OnCommitDeferringConditionChecksComplete(
1866 CommitDeferringCondition::NavigationType navigation_type,
Avi Drissmanbd153642024-09-03 18:58:051867 std::optional<FrameTreeNodeId> candidate_prerender_frame_tree_node_id)
1868 override;
David Bokan1bdb3701f2021-04-30 22:02:351869
danakjc492bf82020-09-09 20:02:441870 // Called either by OnFailureChecksComplete() or OnRequestFailed() directly.
1871 // |error_page_content| contains the content of the error page (i.e. flattened
1872 // HTML, JS, CSS).
Arthur Sonzognic686e8f2024-01-11 08:36:371873 void CommitErrorPage(const std::optional<std::string>& error_page_content);
danakjc492bf82020-09-09 20:02:441874
1875 // Have a RenderFrameHost commit the navigation. The NavigationRequest will
Matt Falkenhagen54adeaa2021-07-06 14:10:001876 // be destroyed sometime after this call, typically after the renderer has
1877 // informed the browser process that the commit has finished.
danakjc492bf82020-09-09 20:02:441878 void CommitNavigation();
1879
Harkiran Bolaria59290d62021-03-17 01:53:011880 // Commits the navigation to an existing page (back-forward cache navigation
1881 // or prerender activation). NavigationRequest will be destroyed after this
1882 // call.
1883 void CommitPageActivation();
1884
danakjc492bf82020-09-09 20:02:441885 // Checks if the specified CSP context's relevant CSP directive
Antonio Sartori60acdfb2024-09-12 09:39:041886 // allows the navigation. This is called to perform the frame-src check.
danakjc492bf82020-09-09 20:02:441887 bool IsAllowedByCSPDirective(
Antonio Sartori5ecc8b932021-03-05 06:56:101888 const std::vector<network::mojom::ContentSecurityPolicyPtr>& policies,
danakjc492bf82020-09-09 20:02:441889 network::CSPContext* context,
1890 network::mojom::CSPDirectiveName directive,
1891 bool has_followed_redirect,
1892 bool url_upgraded_after_redirect,
Nan Lin171fe9a2022-02-17 16:42:161893 bool is_opaque_fenced_frame,
danakjc492bf82020-09-09 20:02:441894 network::CSPContext::CheckCSPDisposition disposition);
1895
Antonio Sartori60acdfb2024-09-12 09:39:041896 // Checks if CSP allows the navigation. This will check the frame-src and
1897 // fenced-frame-src directives. Returns net::OK if the checks
Nan Linefd66c82022-01-24 20:33:151898 // pass, and net::ERR_ABORTED or net::ERR_BLOCKED_BY_CSP depending on which
1899 // checks fail.
danakjc492bf82020-09-09 20:02:441900 net::Error CheckCSPDirectives(
Antonio Sartori5ecc8b932021-03-05 06:56:101901 RenderFrameHostCSPContext parent_context,
1902 const PolicyContainerPolicies* parent_policies,
1903 RenderFrameHostCSPContext initiator_context,
1904 const PolicyContainerPolicies* initiator_policies,
danakjc492bf82020-09-09 20:02:441905 bool has_followed_redirect,
1906 bool url_upgraded_after_redirect,
1907 bool is_response_check,
1908 network::CSPContext::CheckCSPDisposition disposition);
1909
1910 // Check whether a request should be allowed to continue or should be blocked
1911 // because it violates a CSP. This method can have two side effects:
1912 // - If a CSP is configured to send reports and the request violates the CSP,
1913 // a report will be sent.
1914 // - The navigation request may be upgraded from HTTP to HTTPS if a CSP is
1915 // configured to upgrade insecure requests.
1916 net::Error CheckContentSecurityPolicy(bool has_followed_redirect,
1917 bool url_upgraded_after_redirect,
1918 bool is_response_check);
1919
1920 // Builds the parameters used to commit a navigation to a page that was
1921 // restored from the back-forward cache.
arthursonzogni73fe3212020-11-17 13:24:071922 mojom::DidCommitProvisionalLoadParamsPtr
Harkiran Bolaria59290d62021-03-17 01:53:011923 MakeDidCommitProvisionalLoadParamsForBFCacheRestore();
1924
1925 // Builds the parameters used to commit a navigation to a prerendered page
1926 // that was activated.
1927 mojom::DidCommitProvisionalLoadParamsPtr
1928 MakeDidCommitProvisionalLoadParamsForPrerenderActivation();
1929
1930 // Builds generic activation parameters used to commit a navigation to a page.
1931 mojom::DidCommitProvisionalLoadParamsPtr
1932 MakeDidCommitProvisionalLoadParamsForActivation();
danakjc492bf82020-09-09 20:02:441933
1934 // This enum describes the result of the credentialed subresource check for
1935 // the request.
1936 enum class CredentialedSubresourceCheckResult {
1937 ALLOW_REQUEST,
1938 BLOCK_REQUEST,
1939 };
1940
1941 // Chrome blocks subresource requests whose URLs contain embedded credentials
1942 // (e.g. `https://user:[email protected]/page.html`). Check whether the
1943 // request should be allowed to continue or should be blocked.
1944 CredentialedSubresourceCheckResult CheckCredentialedSubresource() const;
1945
1946 // This enum describes the result of the legacy protocol check for
1947 // the request.
1948 enum class LegacyProtocolInSubresourceCheckResult {
1949 ALLOW_REQUEST,
1950 BLOCK_REQUEST,
1951 };
1952
danakjc492bf82020-09-09 20:02:441953 // Block about:srcdoc navigation that aren't expected to happen. For instance,
1954 // main frame navigations or about:srcdoc#foo.
1955 enum class AboutSrcDocCheckResult {
1956 ALLOW_REQUEST,
1957 BLOCK_REQUEST,
1958 };
1959 AboutSrcDocCheckResult CheckAboutSrcDoc() const;
1960
arthursonzogni898dcda52021-01-21 08:50:101961 // When the embedder requires the use of Content Security Policy via Embedded
1962 // Enforcement, framed documents must either:
1963 // 1. Use the 'allow-csp-from' header to opt-into enforcement.
1964 // 2. Enforce its own CSP that subsumes the required CSP.
1965 // Framed documents that fail to do either of these will be blocked.
1966 //
1967 // See:
1968 // - https://w3c.github.io/webappsec-cspee/#required-csp-header
1969 // - https://w3c.github.io/webappsec-cspee/#allow-csp-from-header
1970 //
1971 // SetupCSPEmbeddedEnforcement() retrieve the iframe 'csp' attribute applying.
1972 // CheckCSPEmbeddedEnforcement() inspects the response headers. It decides if
1973 // the 'csp' attribute should be installed into the child. This might also
1974 // block it and display an error page instead.
1975 void SetupCSPEmbeddedEnforcement();
1976 enum class CSPEmbeddedEnforcementResult {
1977 ALLOW_RESPONSE,
1978 BLOCK_RESPONSE,
1979 };
1980 CSPEmbeddedEnforcementResult CheckCSPEmbeddedEnforcement();
1981
danakjc492bf82020-09-09 20:02:441982 // Called before a commit. Updates the history index and length held in
1983 // CommitNavigationParams. This is used to update this shared state with the
1984 // renderer process.
Alex Moshchuk2f89d702023-12-18 21:48:231985 void UpdateHistoryParamsInCommitNavigationParams();
danakjc492bf82020-09-09 20:02:441986
Nasko Oskov32f95892025-06-02 20:45:081987 // Helper method to sanitize URLs for redirects before the commit IPC is sent
1988 // to the renderer process. Must be called right before sending the IPC.
1989 void SanitizeRedirectsForCommit(
1990 blink::mojom::CommitNavigationParamsPtr& commit_params);
1991
Daniel Chengd08a43a2023-03-16 05:10:501992 // The disconnect handler for the NavigationClient Mojo interface; used as a
1993 // signal to potentially cancel navigations, e.g. when the renderer replaces
1994 // an existing NavigationClient connection with a new one or when the renderer
1995 // process crashes.
1996 void OnNavigationClientDisconnected(uint32_t reason,
1997 const std::string& description);
danakjc492bf82020-09-09 20:02:441998
1999 // Binds the given error_handler to be called when an interface disconnection
2000 // happens on the renderer side.
danakjc492bf82020-09-09 20:02:442001 void HandleInterfaceDisconnection(
Daniel Chengd08a43a2023-03-16 05:10:502002 mojo::AssociatedRemote<mojom::NavigationClient>&);
danakjc492bf82020-09-09 20:02:442003
2004 // When called, this NavigationRequest will no longer interpret the interface
2005 // disconnection on the renderer side as an AbortNavigation.
Alison Gale770f3fc2024-04-27 00:39:582006 // TODO(crbug.com/40276805): remove this function when
Arthur Hemery243e3e12023-07-25 14:00:262007 // NavigationRequest properly handles interface disconnection in all cases.
danakjc492bf82020-09-09 20:02:442008 void IgnoreInterfaceDisconnection();
2009
Hiroki Nakagawa1aef8b02021-06-25 10:30:332010 // Sets ID of the RenderProcessHost we expect the navigation to commit in.
2011 // This is used to inform the RenderProcessHost to expect a navigation to the
2012 // url we're navigating to.
2013 void SetExpectedProcess(RenderProcessHost* expected_process);
2014
danakjc492bf82020-09-09 20:02:442015 // Inform the RenderProcessHost to no longer expect a navigation.
2016 void ResetExpectedProcess();
2017
2018 // If this is a same-site main-frame navigation where we did a proactive
2019 // BrowsingInstance swap but we're reusing the old page's process, we need
2020 // to send the routing ID and the updated lifecycle state of the old page so
2021 // that we can run pagehide and visibilitychange handlers of the old page
2022 // when we commit the new page.
2023 void AddOldPageInfoToCommitParamsIfNeeded();
2024
danakjc492bf82020-09-09 20:02:442025 // Record download related UseCounters when navigation is a download before
2026 // filtered by download_policy.
Arthur Sonzogni6d88b3e2022-12-15 14:03:242027 void RecordDownloadUseCountersPrePolicyCheck();
danakjc492bf82020-09-09 20:02:442028
2029 // Record download related UseCounters when navigation is a download after
2030 // filtered by download_policy.
2031 void RecordDownloadUseCountersPostPolicyCheck();
2032
danakjc492bf82020-09-09 20:02:442033 void OnWillStartRequestProcessed(
2034 NavigationThrottle::ThrottleCheckResult result);
2035 void OnWillRedirectRequestProcessed(
2036 NavigationThrottle::ThrottleCheckResult result);
2037 void OnWillFailRequestProcessed(
2038 NavigationThrottle::ThrottleCheckResult result);
2039 void OnWillProcessResponseProcessed(
2040 NavigationThrottle::ThrottleCheckResult result);
Nate Chapin060cb952023-02-08 21:13:072041 void OnWillCommitWithoutUrlLoaderProcessed(
2042 NavigationThrottle::ThrottleCheckResult result);
danakjc492bf82020-09-09 20:02:442043
2044 void CancelDeferredNavigationInternal(
2045 NavigationThrottle::ThrottleCheckResult result);
2046
2047 // TODO(zetamoo): Remove the Will* methods and fold them into their callers.
2048
2049 // Called when the URLRequest will start in the network stack.
2050 void WillStartRequest();
2051
2052 // Called when the URLRequest will be redirected in the network stack.
2053 // This will also inform the delegate that the request was redirected.
2054 //
2055 // |post_redirect_process| is the renderer process we expect to use to commit
2056 // the navigation now that it has been redirected. It can be null if there is
2057 // no live process that can be used. In that case, a suitable renderer process
2058 // will be created at commit time.
Aaron Colwelldc50263c2020-09-18 01:54:222059 //
Arthur Hemery3a991c092021-12-22 12:04:242060 void WillRedirectRequest(const GURL& new_referrer_url,
2061 RenderProcessHost* post_redirect_process);
danakjc492bf82020-09-09 20:02:442062
2063 // Called when the URLRequest will fail.
2064 void WillFailRequest();
2065
2066 // Called when the URLRequest has delivered response headers and metadata.
2067 // |callback| will be called when all throttle checks have completed,
2068 // allowing the caller to cancel the navigation or let it proceed.
2069 // NavigationHandle will not call |callback| with a result of DEFER.
2070 // If the result is PROCEED, then 'ReadyToCommitNavigation' will be called
2071 // just before calling |callback|.
2072 void WillProcessResponse();
2073
Nate Chapin060cb952023-02-08 21:13:072074 // Called when no URLRequest will be needed to perform this navigation, just
2075 // before commit.
2076 void WillCommitWithoutUrlLoader();
2077
danakjc492bf82020-09-09 20:02:442078 // Checks for attempts to navigate to a page that is already referenced more
2079 // than once in the frame's ancestors. This is a helper function used by
2080 // WillStartRequest and WillRedirectRequest to prevent the navigation.
2081 bool IsSelfReferentialURL();
2082
2083 // RenderProcessHostObserver implementation.
2084 void RenderProcessExited(RenderProcessHost* host,
2085 const ChildProcessTerminationInfo& info) override;
2086 void RenderProcessHostDestroyed(RenderProcessHost* host) override;
2087
2088 // Updates navigation handle timings.
Rakina Zata Amni742c2022024-07-02 05:29:172089 void UpdateNavigationHandleTimingsOnResponseReceived(bool is_redirect,
2090 bool is_first_response);
danakjc492bf82020-09-09 20:02:442091 void UpdateNavigationHandleTimingsOnCommitSent();
2092
2093 // Helper function that computes the SiteInfo for |common_params_.url|.
2094 // Note: |site_info_| should only be updated with the result of this function.
Arthur Hemery3a991c092021-12-22 12:04:242095 SiteInfo GetSiteInfoForCommonParamsURL();
danakjc492bf82020-09-09 20:02:442096
2097 // Updates the state of the navigation handle after encountering a server
2098 // redirect.
2099 void UpdateStateFollowingRedirect(const GURL& new_referrer_url);
2100
Jonathan Hao90ddbd42023-07-12 14:23:482101 // Updates |private_network_request_policy_| for ReadyToCommitNavigation().
Titouan Rigoudy40a9b512020-09-18 16:18:092102 //
2103 // Must not be called for same-document navigation requests nor for requests
Harkiran Bolaria59290d62021-03-17 01:53:012104 // served from the back-forward cache or from prerendered pages.
Jonathan Hao513c7002023-07-11 14:27:572105 void UpdatePrivateNetworkRequestPolicy();
Titouan Rigoudy40a9b512020-09-18 16:18:092106
danakjc492bf82020-09-09 20:02:442107 // Called when the navigation is ready to be committed. This will update the
2108 // |state_| and inform the delegate.
John Abd-El-Malek3739f8812020-09-10 00:29:402109 void ReadyToCommitNavigation(bool is_error);
danakjc492bf82020-09-09 20:02:442110
2111 // Called if READY_TO_COMMIT -> COMMIT state transition takes an unusually
2112 // long time.
2113 void OnCommitTimeout();
2114
2115 // Called by the RenderProcessHost to handle the case when the process changed
2116 // its state of being blocked.
2117 void RenderProcessBlockedStateChanged(bool blocked);
2118
2119 void StopCommitTimeout();
2120 void RestartCommitTimeout();
2121
2122 std::vector<std::string> TakeRemovedRequestHeaders() {
2123 return std::move(removed_request_headers_);
2124 }
2125
2126 net::HttpRequestHeaders TakeModifiedRequestHeaders() {
2127 return std::move(modified_request_headers_);
2128 }
2129
2130 // Returns true if the contents of |common_params_| requires
2131 // |source_site_instance_| to be set. This is used to ensure that data: and
2132 // about:blank URLs with valid initiator origins always have
2133 // |source_site_instance_| set so that site isolation enforcements work
2134 // properly.
2135 bool RequiresInitiatorBasedSourceSiteInstance() const;
2136
2137 // Sets |source_site_instance_| to a SiteInstance that is derived from
2138 // |common_params_->initiator_origin| and related to the |frame_tree_node_|'s
2139 // current SiteInstance. |source_site_instance_| is only set if it doesn't
2140 // already have a value and RequiresInitiatorBasedSourceSiteInstance() returns
2141 // true.
2142 void SetSourceSiteInstanceToInitiatorIfNeeded();
2143
danakjc492bf82020-09-09 20:02:442144 void ForceEnableOriginTrials(const std::vector<std::string>& trials) override;
2145
2146 void CreateCoepReporter(StoragePartition* storage_partition);
Camille Lamy36afacd2025-01-16 14:25:182147 void CreateDipReporter(StoragePartition* storage_partition);
danakjc492bf82020-09-09 20:02:442148
Pâris Meuleman00d62b22022-01-14 13:43:422149 // [spec]: https://html.spec.whatwg.org/C/#obtain-an-embedder-policy
2150 //
2151 // Returns the CrossOriginEmbedderPolicy for the document, which is inherited
2152 // or retrieved from response headers.
2153 network::CrossOriginEmbedderPolicy ComputeCrossOriginEmbedderPolicy();
2154
Yoav Weiss93d38b502025-05-06 15:55:512155 struct IntegrityPolicies {
2156 network::IntegrityPolicy enforced;
2157 network::IntegrityPolicy report_only;
2158 };
2159
2160 // Calculates the integrity policies for a document, based on the
2161 // `Integrity-Policy` and `Integrity-Policy-Report-Only` headers.
2162 IntegrityPolicies ComputeIntegrityPolicies();
2163
Pâris Meuleman00d62b22022-01-14 13:43:422164 // [spec]:
2165 // https://html.spec.whatwg.org/C/#check-a-navigation-response's-adherence-to-its-embedder-policy
2166 //
2167 // Return whether the response's COEP is compatible with its parent's COEP. It
2168 // also sends COEP reports if needed.
2169 bool CheckResponseAdherenceToCoep(const GURL& url);
Arthur Sonzogni80129582021-12-21 10:34:572170
Arthur Sonzognic686e8f2024-01-11 08:36:372171 std::optional<network::mojom::BlockedByResponseReason> EnforceCOEP();
danakjc492bf82020-09-09 20:02:442172
Pâris MEULEMANa2e8623f2021-04-09 07:57:422173 // Check the COOP value of the page is compatible with the COEP value of each
2174 // of its documents. COOP:kSameOriginPlusCoep is incompatible with COEP:kNone.
Hiroki Nakagawaeb5e2fd2025-06-17 12:45:052175 // If they aren't, this emits a crash report.
2176 void CoopCoepSanityCheck();
Pâris MEULEMANa2e8623f2021-04-09 07:57:422177
Liam Brady25a14162022-12-02 15:25:572178 // Checks that, given an origin to be committed, all of the permissions
2179 // policies that a fenced frame requires to be enabled are enabled. If not, it
2180 // logs a console message and returns false.
Liam Bradyb1c43c22022-08-11 23:33:472181 bool CheckPermissionsPoliciesForFencedFrames(const url::Origin&);
2182
Liam Brady25a14162022-12-02 15:25:572183 // Helper function that determines if a given required permissions policy
2184 // feature is properly enabled for a given origin to be committed.
2185 bool IsFencedFrameRequiredPolicyFeatureAllowed(
2186 const url::Origin&,
Sandor «Alex» Majore9545a72025-01-31 20:40:462187 const network::mojom::PermissionsPolicyFeature feature);
Liam Brady25a14162022-12-02 15:25:572188
danakjc492bf82020-09-09 20:02:442189 // Returns the user-agent override, or an empty string if one isn't set.
2190 std::string GetUserAgentOverride();
2191
2192 mojo::PendingRemote<network::mojom::CookieAccessObserver>
2193 CreateCookieAccessObserver();
2194
Steven Valdeza06f680c2023-03-21 19:00:102195 mojo::PendingRemote<network::mojom::TrustTokenAccessObserver>
2196 CreateTrustTokenAccessObserver();
2197
2198 // network::mojom::TrustTokenAccessObserver:
2199 void OnTrustTokensAccessed(
2200 network::mojom::TrustTokenAccessDetailsPtr details) override;
2201 void Clone(mojo::PendingReceiver<network::mojom::TrustTokenAccessObserver>
2202 observer) override;
2203
Tsuyoshi Horobcd0b9f62023-06-28 11:35:322204 mojo::PendingRemote<network::mojom::SharedDictionaryAccessObserver>
2205 CreateSharedDictionaryAccessObserver();
2206
2207 // network::mojom::SharedDictionaryAccessObserver:
2208 void OnSharedDictionaryAccessed(
2209 network::mojom::SharedDictionaryAccessDetailsPtr details) override;
2210 void Clone(
2211 mojo::PendingReceiver<network::mojom::SharedDictionaryAccessObserver>
2212 observer) override;
2213
Daniel Rubery6420d74302024-11-19 01:42:402214 mojo::PendingRemote<network::mojom::DeviceBoundSessionAccessObserver>
2215 CreateDeviceBoundSessionObserver();
2216
2217 // network::mojom::DeviceBoundSessionAccessObserver:
2218 void OnDeviceBoundSessionAccessed(
Daniel Rubery7cdfa532025-01-24 16:57:502219 const net::device_bound_sessions::SessionAccess& access) override;
Daniel Rubery6420d74302024-11-19 01:42:402220 void Clone(
2221 mojo::PendingReceiver<network::mojom::DeviceBoundSessionAccessObserver>
2222 observer) override;
2223
danakjc492bf82020-09-09 20:02:442224 // Convenience function to return the NavigationControllerImpl this
2225 // NavigationRequest is in.
William Liu2b6336bc2023-09-07 14:42:392226 NavigationControllerImpl* GetNavigationController() const;
danakjc492bf82020-09-09 20:02:442227
Hiroki Nakagawa1cb14552021-04-23 03:37:342228 // Convenience function to return the PrerenderHostRegistry this
2229 // NavigationRequest can be associated with.
2230 PrerenderHostRegistry& GetPrerenderHostRegistry();
2231
Rakina Zata Amni39d8e7e2022-10-20 18:18:302232 // Returns the RenderFrameHost of the initiator document, iff there is such
2233 // a document and its RenderFrameHost has not committed a different document
Titouan Rigoudy78d83112021-06-23 14:49:592234 // since this navigation started. Otherwise returns nullptr.
2235 RenderFrameHostImpl* GetInitiatorDocumentRenderFrameHost();
2236
2237 // Records the appropriate kAddressSpace* WebFeature for the response we just
2238 // received on the initiator document, if possible.
2239 void RecordAddressSpaceFeature();
2240
arthursonzogniadb80882021-03-11 10:43:302241 // Computes the PolicyContainerPolicies and the sandbox flags to use for
2242 // committing a regular document.
2243 // Called when the response to commit is known.
2244 void ComputePoliciesToCommit();
2245
2246 // Computes the PolicyContainerPolicies and the sandbox flags to use for
2247 // committing an error document.
2248 //
2249 // Note:
2250 // |ComputePoliciesToCommit()| can be followed by
2251 // |ComputePoliciesToCommitForErrorPage()|. This happens when the decision to
2252 // commit an error document happens after receiving the regular document's
2253 // response.
2254 void ComputePoliciesToCommitForError();
2255
danakjc492bf82020-09-09 20:02:442256 // DCHECK that tranistioning from the current state to |state| valid. This
2257 // does nothing in non-debug builds.
2258 void CheckStateTransition(NavigationState state) const;
2259
2260 // Set |state_| to |state| and also DCHECK that this state transition is
2261 // valid.
2262 void SetState(NavigationState state);
2263
Daniel Cheng738266dc2020-09-11 19:56:282264 // When a navigation fails, one of two things can happen:
2265 // 1) An error page commits and replaces the old document.
2266 // 2) The navigation is canceled, and the previous document is kept.
2267 //
2268 // If appropriate, this applies (2), deletes |this|, and returns true.
2269 // In that case, the caller must immediately return.
2270 bool MaybeCancelFailedNavigation();
2271
Antonio Sartori0a7117a2021-04-01 09:23:372272 // Called just after a navigation commits (also in case of error): it
2273 // sends all console messages to the final RenderFrameHost.
2274 void SendDeferredConsoleMessages();
2275
Daniel Cheng9bd90f92021-04-23 20:49:452276 bool ShouldRenderFallbackContentForResponse(
2277 const net::HttpResponseHeaders& response_head) const;
Daniel Cheng9bd90f92021-04-23 20:49:452278
Rakina Zata Amnie36ce5342021-07-17 04:10:552279 // Whether this is a same-URL navigation that should replace the current entry
2280 // or not. Called when the navigation just started.
Nate Chapin8a7a0422021-06-28 20:29:242281 bool ShouldReplaceCurrentEntryForSameUrlNavigation() const;
2282
Rakina Zata Amniddf10502022-01-15 02:56:552283 // Whether this navigation happens on the initial empty document or initial
2284 // NavigationEntry, and thus should replace the current entry. Called when the
2285 // navigation just started.
2286 bool ShouldReplaceCurrentEntryForNavigationFromInitialEmptyDocumentOrEntry()
2287 const;
Rakina Zata Amni18463252021-08-10 17:48:102288
Rakina Zata Amnie36ce5342021-07-17 04:10:552289 // Whether a failed navigation should replace the current entry or not. Called
2290 // when an error page is about to be committed.
2291 bool ShouldReplaceCurrentEntryForFailedNavigation() const;
2292
Kenichi Ishibashi59973782021-07-02 07:01:142293 // Calculates the origin that this NavigationRequest may commit. See also the
2294 // comment of GetOriginToCommit(). Performs calculation without information
2295 // from RenderFrameHostImpl (e.g. CSPs are ignored). Should be used only in
2296 // situations where the final frame host hasn't been determined but the origin
2297 // is needed to create URLLoaderFactory.
Lukasz Anforowicz435e68d2022-11-09 21:47:442298 url::Origin GetOriginForURLLoaderFactoryBeforeResponse(
Kenichi Ishibashif3f80522021-07-16 02:37:072299 network::mojom::WebSandboxFlags sandbox_flags);
Kenichi Ishibashi59973782021-07-02 07:01:142300
Lukasz Anforowicz435e68d2022-11-09 21:47:442301 // Superset of GetOriginForURLLoaderFactoryBeforeResponse(). Calculates
Kenichi Ishibashi59973782021-07-02 07:01:142302 // the origin with information from the final frame host. Can be called only
2303 // after the final response is received or ready.
Arthur Sonzognic686e8f2024-01-11 08:36:372304 std::optional<url::Origin> GetOriginForURLLoaderFactoryAfterResponse();
Kenichi Ishibashi59973782021-07-02 07:01:142305
Camille Lamyd1f015d2024-07-06 14:14:102306 // Computes the CrossOriginIsolationKey to use for committing the navigation.
2307 // A nullopt result means that either the cross-origin isolation status of the
2308 // request cannot be determined because we do not have final headers for the
2309 // navigation yet, or that the navigation is not cross-origin isolated.
2310 std::optional<AgentClusterKey::CrossOriginIsolationKey>
2311 ComputeCrossOriginIsolationKey();
2312
Arthur Hemery821fa5d2021-08-30 13:32:422313 // Computes the web-exposed isolation information based on `coop_status_` and
2314 // current `frame_tree_node_` info.
Arthur Hemery3a991c092021-12-22 12:04:242315 // If the return result is nullopt, it means that the WebExposedIsolationInfo
2316 // is not relevant or unknown. This can happen for example when we do not have
2317 // a network response yet, or when going to an "about:blank" page.
Arthur Sonzognic686e8f2024-01-11 08:36:372318 std::optional<WebExposedIsolationInfo> ComputeWebExposedIsolationInfo();
Arthur Hemery821fa5d2021-08-30 13:32:422319
Yao Xiao6e1f7d32022-01-07 03:28:402320 // Assign an invalid frame tree node id to `prerender_frame_tree_node_id_`.
2321 // Called as soon as when we are certain that this navigation won't activate a
2322 // prerendered page. This is needed because `IsPrerenderedPageActivation()`,
2323 // which may be called at any point after BeginNavigation(), will assume that
2324 // 'prerender_frame_tree_node_id_' has an value assigned.
2325 void MaybeAssignInvalidPrerenderFrameTreeNodeId();
2326
Arthur Sonzogni258bee7ca2022-12-06 18:16:122327 // The NavigationDownloadPolicy is currently fully computed by the renderer
2328 // process. It is left empty for browser side initiated navigation. This is a
2329 // problem. This function is an incomplete attempt to start computing it from
2330 // the browser process instead.
Alison Gale81f4f2c72024-04-22 19:33:312331 // TODO(crbug.com/40249217): Complete the implementation the browser
Arthur Sonzogni258bee7ca2022-12-06 18:16:122332 // side implementation.
2333 void ComputeDownloadPolicy();
2334
Arthur Sonzogni6d88b3e2022-12-15 14:03:242335 blink::NavigationDownloadPolicy& download_policy() {
2336 return common_params_->download_policy;
2337 }
2338
Rakina Zata Amni49657c772023-03-31 06:41:532339 // Called on FrameTreeNode's queued NavigationRequest (if any) when another
2340 // NavigationRequest associated with the same FrameTreeNode is destroyed and
Rakina Zata Amnid7b90f22023-04-06 12:56:402341 // the queued NavigationRequest can be resumed. Will post a task to run the
2342 // `resume_commit_closure_` asynchronously.
2343 void PostResumeCommitTask();
Daniel Chenga8a80092023-01-09 22:50:162344
Arthur Sonzogni9b2f54c2023-02-03 15:00:262345 // See https://crbug.com/1412365
2346 void CheckSoftNavigationHeuristicsInvariants();
2347
Nate Chapin154b14b2023-02-17 18:28:162348 // Used to resume any SubframeHistoryNavigationThrottles in this FrameTree
2349 // when this NavigationRequest commits.
2350 // `subframe_history_navigation_throttles_` will only be populated if this
2351 // IsInMainFrame().
2352 void UnblockPendingSubframeNavigationRequestsIfNeeded();
2353
Nate Chapin364a72e02023-11-27 19:56:592354 // If this request is a same-origin cross-document traversal (i.e., session
2355 // history navigation), this will send a message to the renderer to have it
2356 // fire the navigate event. Normally, the renderer fires the navigate event at
2357 // navigation start for cross-document navigations, before sending the
2358 // BeginNavigation to the browser. That doesn't work for traversals, because
2359 // the renderer don't know which frame(s) will navigate. This is called after
2360 // beforeunload events fire and after any navigation start throttles have
2361 // resumed, so we know the navigation is proceeding. The navigate event can't
2362 // cancel a cross-document traversal, so it can be sent in parallel, instead
2363 // of blocking and waiting for the result.
2364 void MaybeDispatchNavigateEventForCrossDocumentTraversal();
2365
Mingyu Lei1fa6a1f2023-02-21 13:17:462366 // Returns if we should add/reset the `CookieChangeListener` for the current
2367 // navigation.
2368 bool ShouldAddCookieChangeListener();
2369
Daniel Rubery03e71992025-02-19 22:03:302370 // Returns if we should add/reset the `DeviceBoundSessionObserver` for
2371 // the current navigation.
2372 bool ShouldAddDeviceBoundSessionObserver();
2373
Mingyu Lei1fa6a1f2023-02-21 13:17:462374 // Returns the `StoragePartition` based on the config from the `site_info_`.
2375 StoragePartition* GetStoragePartitionWithCurrentSiteInfo();
2376
Igor Ruvinovdcb81982023-06-21 22:22:172377 // Passes the response body contents to the original caller using the stored
2378 // callback once the body has been successfully read from its corresponding
2379 // data pipe.
2380 void OnResponseBodyReady(MojoResult result);
2381
Alex Moshchuk854e0be72023-08-04 22:35:352382 // Helper to record early RenderFrameHost swap metrics at the end of a
2383 // navigation.
2384 void RecordEarlyRenderFrameHostSwapMetrics();
2385
Sharon Yang945cea52023-10-16 21:14:032386 // Helpers for GetTentativeOriginAtRequestTime and GetOriginToCommit.
Sharon Yang945cea52023-10-16 21:14:032387 url::Origin GetOriginForURLLoaderFactoryUnchecked();
2388
Minoru Chikamune3c58bbd2024-01-22 10:19:352389 void MaybeRecordTraceEventsAndHistograms();
Minoru Chikamune6e45f702024-01-18 15:05:302390
Charlie Reis9e20dd12025-01-02 20:11:532391 // Records how much the navigation start time was adjusted for beforeunload
2392 // handlers, for various scenarios (legacy, beforeunload handlers only, and
2393 // beforeunload dialogs). See https://crbug.com/385170155.
2394 void MaybeRecordNavigationStartAdjustments();
2395
Khushal Sagar91b544222024-03-12 17:36:592396 void ResetViewTransitionState();
2397
Xiaochen Zhou8294af82024-05-30 20:48:022398 // This check is to prevent a race condition where a parent fenced frame
2399 // initiates a nested fenced frame navigation right before the entire frame
2400 // tree has network access disabled. If such navigation is allowed to commit,
2401 // the navigated fenced frame will have network access. This allows parent
2402 // fenced frame to communicate cross-site data into child fenced frame, which
2403 // is bad. So we need to disable navigations when both the embedder and nested
2404 // frames have already disabled network.
2405 bool IsDisabledEmbedderInitiatedFencedFrameNavigation();
2406
Jiacheng Guoc77135fb2024-06-06 12:38:012407 // Sets the expected process to the process of the current associated RFH.
2408 void SetExpectedProcessIfAssociated();
2409
Camille Lamy17ad9e82024-06-21 11:06:302410 // Sets the Document-Isolation-Policy header to a default value in unsecure
2411 // contexts or if DocumentIsolationPolicy is not supported.
2412 void SanitizeDocumentIsolationPolicyHeader();
2413
Liang Zhao5b299ce2025-01-17 18:34:242414 // Sets up service worker client info to inherit controller from the parent
2415 // frame if it is a same origin srcdoc iframe.
2416 // This method creates a ServiceWorkerClient associated with the navigating
2417 // frame. It should not be called when NavigationURLLoader is used as that
2418 // would also create ServiceWorkerClient and cause conflict.
2419 void InheritServiceWorkerControllerFromParentIfNeeded();
2420
Diana Qu01f1c792025-06-04 20:33:452421 // If this navigation has a FrameNavigationEntry with a committed origin,
2422 // ensure that it matches the origin_to_commit when origin-sensitive state
2423 // (such as page_state) is being sent to the renderer.
2424 //
2425 // This invariant guards against scenarios where session history has been
2426 // unintentionally or maliciously corrupted, causing a document to commit
2427 // in a renderer under the wrong origin. This would violate site isolation
2428 // guarantees and could lead to security vulnerabilities.
2429 //
2430 // See https://crbug.com/41487933 for more background on the types of bugs
2431 // this protects against.
2432 void ValidateCommitOrigin(const url::Origin& origin_to_commit);
2433
Titouan Rigoudye10716b2020-09-29 13:29:552434 // Never null. The pointee node owns this navigation request instance.
Keishi Hattori130ae0a2023-03-27 03:48:472435 // This field is not a raw_ptr because of incompatibilities with tracing
2436 // (TRACE_EVENT*), perfetto::TracedDictionary::Add and gmock/EXPECT_THAT.
2437 RAW_PTR_EXCLUSION FrameTreeNode* const frame_tree_node_;
danakjc492bf82020-09-09 20:02:442438
Hayato Ito5750b442025-05-29 02:38:062439 // Returns true if navigation timeline UKMs should be recorded.
2440 // This is also used in `MaybeRecordTraceEventsAndHistograms()`, which should
2441 // eventually be replaced with the navigation timeline metrics.
2442 bool ShouldRecordNavigationTimelineUkm() const;
2443
Hiroki Nakagawaadcffc502021-06-16 10:47:512444 // Used for short-lived NavigationRequest created at DidCommit time for the
2445 // purpose of committing navigation that were not driven by the browser
2446 // process. This is used in only two cases:
2447 // - same-document navigation initiated by the renderer process.
2448 // - the synchronous about:blank navigation.
2449 const bool is_synchronous_renderer_commit_;
danakjc492bf82020-09-09 20:02:442450
Rakina Zata Amni7b75ae342023-03-03 05:59:142451 // The RenderFrameHost that this navigation intends to commit in. The value
2452 // will be set when we know the final RenderFrameHost that the navigation will
2453 // commit in (i.e. when we receive the final network response for most
Arthur Sonzognic686e8f2024-01-11 08:36:372454 // navigations). Note that currently this can be reset to std::nullopt for
Rakina Zata Amni7b75ae342023-03-03 05:59:142455 // cross-document restarts and some failed navigations.
Alison Gale81f4f2c72024-04-22 19:33:312456 // TODO(crbug.com/40063115): Don't reset this on failed navigations,
Rakina Zata Amni7b75ae342023-03-03 05:59:142457 // and ensure the NavigationRequest doesn't outlive the `render_frame_host_`
2458 // picked for failed Back/Forward Cache restores.
2459 // Invariant: At least one of |loader_| or |render_frame_host_| is
Arthur Sonzognic686e8f2024-01-11 08:36:372460 // null/std::nullopt.
2461 std::optional<
Paul Semel7e8f8882023-06-07 20:44:412462 base::SafeRef<RenderFrameHostImpl, base::SafeRefDanglingUntriaged>>
2463 render_frame_host_;
danakjc492bf82020-09-09 20:02:442464
2465 // Initialized on creation of the NavigationRequest. Sent to the renderer when
2466 // the navigation is ready to commit.
2467 // Note: When the navigation is ready to commit, the url in |common_params|
2468 // will be set to the final navigation url, obtained after following all
2469 // redirects.
Hiroki Nakagawa07565592021-06-04 11:36:172470 //
danakjc492bf82020-09-09 20:02:442471 // Note: |common_params_| and |begin_params_| are not const as they can be
2472 // modified during redirects.
Hiroki Nakagawa07565592021-06-04 11:36:172473 //
danakjc492bf82020-09-09 20:02:442474 // Note: |commit_params_| is not const because was_discarded will
2475 // be set in CreatedNavigationRequest.
Hiroki Nakagawa07565592021-06-04 11:36:172476 //
2477 // Note: |commit_params_->is_browser_initiated| and |common_params_| may be
2478 // mutated by ContentBrowserClient::OverrideNavigationParams at construction
2479 // time (i.e. before we actually kick off the navigation).
Minggang Wangb9f3fa92021-07-01 15:30:312480 blink::mojom::CommonNavigationParamsPtr common_params_;
2481 blink::mojom::BeginNavigationParamsPtr begin_params_;
2482 blink::mojom::CommitNavigationParamsPtr commit_params_;
Yoav Weiss3e46271d2021-04-30 20:35:212483 bool same_origin_ = false;
danakjc492bf82020-09-09 20:02:442484
2485 // Stores the NavigationUIData for this navigation until the NavigationHandle
2486 // is created. This can be null if the embedded did not provide a
2487 // NavigationUIData at the beginning of the navigation.
2488 std::unique_ptr<NavigationUIData> navigation_ui_data_;
2489
2490 // URLLoaderFactory to facilitate loading blob URLs.
Hiroki Nakagawab078d3ef2021-06-03 06:55:432491 const scoped_refptr<network::SharedURLLoaderFactory> blob_url_loader_factory_;
danakjc492bf82020-09-09 20:02:442492
Ming-Ying Chung763ee3282023-10-10 19:30:362493 // A bundle of URLLoaderFactory to facilitate loading subresources.
2494 // It is shared between prefetch, topics, keep-alive, and fetchLater.
2495 scoped_refptr<network::SharedURLLoaderFactory>
2496 subresource_proxying_factory_bundle_ = nullptr;
2497
arthursonzogni5761f4c2020-11-20 12:39:312498 NavigationState state_ = NOT_STARTED;
danakjc492bf82020-09-09 20:02:442499 bool is_navigation_started_ = false;
2500
Ali Jumab3775462023-10-20 21:31:082501 // Manages the lifetime of a pre-created ServiceWorkerContainerHost until a
2502 // corresponding container is created in the renderer. This must be destroyed
2503 // after `loader_` to avoid dangling pointers, since `loader_` can have a
2504 // raw_ptr to this object.
2505 std::unique_ptr<ServiceWorkerMainResourceHandle> service_worker_handle_;
2506
danakjc492bf82020-09-09 20:02:442507 std::unique_ptr<NavigationURLLoader> loader_;
2508
Pete Williamson1d87f4622022-10-18 19:36:432509 bool navigation_visible_to_embedder_ = false;
Xiaohan Wang7f8052e02022-01-14 18:44:282510#if BUILDFLAG(IS_ANDROID)
danakjc492bf82020-09-09 20:02:442511 // For each C++ NavigationHandle, there is a Java counterpart. It is the JNI
2512 // bridge in between the two.
2513 std::unique_ptr<NavigationHandleProxy> navigation_handle_proxy_;
2514#endif
2515
2516 // These next items are used in browser-initiated navigations to store
2517 // information from the NavigationEntryImpl that is required after request
2518 // creation time.
2519 scoped_refptr<SiteInstanceImpl> source_site_instance_;
2520 scoped_refptr<SiteInstanceImpl> dest_site_instance_;
2521 const RestoreType restore_type_;
2522 const ReloadType reload_type_;
2523 const int nav_entry_id_;
Avi Drissman78865bbb2024-08-22 20:57:192524 std::optional<BindingsPolicySet> bindings_;
danakjc492bf82020-09-09 20:02:442525
2526 scoped_refptr<SiteInstanceImpl> starting_site_instance_;
2527
2528 // Whether the navigation should be sent to a renderer a process. This is
2529 // true, except for 204/205 responses and downloads.
Sharon Yang34f89982023-11-09 22:35:242530 bool response_should_be_rendered_ = true;
danakjc492bf82020-09-09 20:02:442531
Ali Beyad3e6e4672021-11-02 19:34:062532 // Whether devtools overrides were applied on the User-Agent request header.
2533 bool devtools_user_agent_override_ = false;
2534
Victor Tan56323482022-08-12 19:05:132535 // Whether devtools overrides were applied on the Accept-Language request
2536 // header.
2537 bool devtools_accept_language_override_ = false;
2538
Rakina Zata Amni7af54b12022-06-28 10:36:172539 // The type of RenderFrameHost associated with this navigation.
2540 AssociatedRenderFrameHostType associated_rfh_type_ =
2541 AssociatedRenderFrameHostType::NONE;
danakjc492bf82020-09-09 20:02:442542
2543 // Stores the SiteInstance created on redirects to check if there is an
2544 // existing RenderProcessHost that can commit the navigation so that the
2545 // renderer process is not deleted while the navigation is ongoing. If the
2546 // SiteInstance was a brand new SiteInstance, it is not stored.
2547 scoped_refptr<SiteInstance> speculative_site_instance_;
2548
2549 // Whether the NavigationRequest was created after receiving a BeginNavigation
2550 // IPC. When true, main frame navigations should not commit in a different
2551 // process (unless asked by the content/ embedder). When true, the renderer
2552 // process expects to be notified if the navigation is aborted.
2553 const bool from_begin_navigation_;
2554
2555 // Holds objects received from OnResponseStarted while the WillProcessResponse
2556 // checks are performed by the NavigationHandle. Once the checks have been
2557 // completed, these objects will be used to continue the navigation.
2558 network::mojom::URLResponseHeadPtr response_head_;
2559 mojo::ScopedDataPipeConsumerHandle response_body_;
2560 network::mojom::URLLoaderClientEndpointsPtr url_loader_client_endpoints_;
Arthur Sonzognic686e8f2024-01-11 08:36:372561 std::optional<net::SSLInfo> ssl_info_;
2562 std::optional<net::AuthChallengeInfo> auth_challenge_info_;
danakjc492bf82020-09-09 20:02:442563 bool is_download_ = false;
2564 GlobalRequestID request_id_;
Kenichi Ishibashi7eb8cf62021-04-07 12:35:052565 std::unique_ptr<NavigationEarlyHintsManager> early_hints_manager_;
danakjc492bf82020-09-09 20:02:442566
2567 // Holds information for the navigation while the WillFailRequest
2568 // checks are performed by the NavigationHandle.
arthursonzogni5761f4c2020-11-20 12:39:312569 bool has_stale_copy_in_cache_ = false;
danakjc492bf82020-09-09 20:02:442570 net::Error net_error_ = net::OK;
Karandeep Bhatia3de98e52021-03-13 03:48:452571 int extended_error_code_ = 0;
2572
Keita Suzukif300e442025-07-16 07:38:112573 // The trigger for the error navigation.
2574 std::optional<ErrorNavigationTrigger> error_navigation_trigger_;
2575
danakjc492bf82020-09-09 20:02:442576 // Detailed host resolution error information. The error code in
2577 // |resolve_error_info_.error| should be consistent with (but not necessarily
2578 // the same as) |net_error_|. In the case of a host resolution error, for
2579 // example, |net_error_| should be ERR_NAME_NOT_RESOLVED while
2580 // |resolve_error_info_.error| may give a more detailed error such as
2581 // ERR_DNS_TIMED_OUT.
2582 net::ResolveErrorInfo resolve_error_info_;
2583
2584 // Identifies in which RenderProcessHost this navigation is expected to
2585 // commit.
Patrick Monette779c1542025-01-17 17:18:362586 ChildProcessId expected_render_process_host_id_;
danakjc492bf82020-09-09 20:02:442587
2588 // The SiteInfo of this navigation, as obtained from
2589 // SiteInstanceImpl::ComputeSiteInfo().
2590 SiteInfo site_info_;
2591
danakjc492bf82020-09-09 20:02:442592 base::OnceClosure on_start_checks_complete_closure_;
2593
2594 // Used in the network service world to pass the subressource loader params
Adrienne Walker5b98d1ee2021-10-19 16:57:412595 // to the renderer. Used by ServiceWorker and
danakjc492bf82020-09-09 20:02:442596 // SignedExchangeSubresourcePrefetch.
Hiroshige Hayashizaki9e0f2862024-02-09 16:54:002597 SubresourceLoaderParams subresource_loader_params_;
danakjc492bf82020-09-09 20:02:442598
Daniel Cheng284c38942022-09-22 23:30:342599 // DocumentToken to use for the newly-committed document in a cross-document
2600 // navigation. Currently set immediately before sending CommitNavigation to
2601 // the renderer. In the future, this may be populated earlier to allow lookup
2602 // of a navigation request by the document that it may create, similar to how
2603 // `NavigationOrDocumentHandle` behaves.
Arthur Sonzognic686e8f2024-01-11 08:36:372604 std::optional<blink::DocumentToken> document_token_;
Daniel Cheng284c38942022-09-22 23:30:342605
danakjc492bf82020-09-09 20:02:442606 // See comment on accessor.
arthursonzogni5761f4c2020-11-20 12:39:312607 const base::UnguessableToken devtools_navigation_token_ =
2608 base::UnguessableToken::Create();
danakjc492bf82020-09-09 20:02:442609
Arthur Sonzognic686e8f2024-01-11 08:36:372610 std::optional<std::vector<blink::mojom::TransferrableURLLoaderPtr>>
danakjc492bf82020-09-09 20:02:442611 subresource_overrides_;
2612
2613 // The NavigationClient interface for that requested this navigation in the
2614 // case of a renderer initiated navigation. It is expected to be bound until
2615 // this navigation commits or is canceled.
2616 mojo::AssociatedRemote<mojom::NavigationClient> request_navigation_client_;
2617
2618 // The NavigationClient interface used to commit the navigation. For now, this
2619 // is only used for same-site renderer-initiated navigation.
Alison Gale770f3fc2024-04-27 00:39:582620 // TODO(crbug.com/40276805): Extend to all types of navigation.
danakjc492bf82020-09-09 20:02:442621 mojo::AssociatedRemote<mojom::NavigationClient> commit_navigation_client_;
2622
2623 // If set, any redirects to HTTP for this navigation will be upgraded to
2624 // HTTPS. This is used only on subframe navigations, when
2625 // upgrade-insecure-requests is set as a CSP policy.
2626 bool upgrade_if_insecure_ = false;
2627
2628 // The offset of the new document in the history.
Hiroki Nakagawad69994c2021-06-01 21:20:452629 const int navigation_entry_offset_ = 0;
danakjc492bf82020-09-09 20:02:442630
Takashi Toyoshima96a07bb2025-06-06 06:45:582631 // Owns the NavigationThrottleRegistry associated with this navigation.
Takashi Toyoshima96a07bb2025-06-06 06:45:582632 std::unique_ptr<NavigationThrottleRegistryImpl> throttle_registry_;
2633
David Bokan1bdb3701f2021-04-30 22:02:352634 // Once the navigation has passed all throttle checks the navigation will
2635 // commit. However, we may need to defer the commit until certain conditions
2636 // are met. CommitDeferringConditionRunner is responsible for deferring a
2637 // commit if needed and resuming it, by calling
2638 // OnCommitDeferringConditionChecksComplete, once all checks passed.
Hiroki Nakagawa6c5f39bd2021-07-13 00:22:362639 //
2640 // For prerendered page activation, it doesn't run the NavigationThrottles and
2641 // run the CommitDeferringConditionRunner at the beginning of
2642 // BeginNavigation(). See the comment on RunCommitDeferringConditions() for
2643 // details.
David Bokan1bdb3701f2021-04-30 22:02:352644 std::unique_ptr<CommitDeferringConditionRunner> commit_deferrer_;
2645
danakjc492bf82020-09-09 20:02:442646 // Indicates whether the navigation changed which NavigationEntry is current.
2647 bool subframe_entry_committed_ = false;
2648
2649 // True if the committed entry has replaced the existing one.
2650 // A non-user initiated redirect causes such replacement.
2651 bool did_replace_entry_ = false;
2652
2653 // Set to false if we want to update the session history but not update the
Miyoung Shinba07a172022-02-14 13:38:542654 // browser history. E.g., on unreachable urls or navigations in non-primary
Adithya Srinivasan39c81912024-07-11 20:44:212655 // frame trees.
danakjc492bf82020-09-09 20:02:442656 bool should_update_history_ = false;
2657
2658 // The previous main frame URL that the user was on. This may be empty if
2659 // there was no last committed entry.
Fergal Daly8e33cf62020-12-12 01:06:072660 GURL previous_main_frame_url_;
danakjc492bf82020-09-09 20:02:442661
2662 // The type of navigation that just occurred. Note that not all types of
2663 // navigations in the enum are valid here, since some of them don't actually
2664 // cause a "commit" and won't generate this notification.
2665 NavigationType navigation_type_ = NAVIGATION_TYPE_UNKNOWN;
2666
2667 // The chain of redirects, including client-side redirect and the current URL.
2668 // TODO(zetamoo): Try to improve redirect tracking during navigation.
2669 std::vector<GURL> redirect_chain_;
2670
2671 // TODO(zetamoo): Try to remove this by always sanitizing the referrer in
2672 // common_params_.
2673 blink::mojom::ReferrerPtr sanitized_referrer_;
2674
2675 bool was_redirected_ = false;
2676
2677 // Whether this navigation was triggered by a x-origin redirect following a
2678 // prior (most likely <a download>) download attempt.
2679 bool from_download_cross_origin_redirect_ = false;
2680
Kunihiko Sakamoto2bebcc12022-08-19 08:00:182681 // Used to hold prefetched signed exchanges. This is shared with the
2682 // navigation initiator's RenderFrameHostImpl. This also means that only the
2683 // navigations that were directly initiated by the frame that made the
2684 // prefetches could use the prefetched resources, which is a different
2685 // behavior from regular prefetches (where all prefetched resources are
2686 // stored and shared in http cache).
danakjc492bf82020-09-09 20:02:442687 scoped_refptr<PrefetchedSignedExchangeCache>
2688 prefetched_signed_exchange_cache_;
2689
danakjc492bf82020-09-09 20:02:442690 // Timing information of loading for the navigation. Used for recording UMAs.
arthursonzogni5761f4c2020-11-20 12:39:312691 NavigationHandleTiming navigation_handle_timing_;
danakjc492bf82020-09-09 20:02:442692
Charlie Reis9e20dd12025-01-02 20:11:532693 // The original value of navigation start for a given navigation, before any
2694 // adjustment is made to avoid counting beforeunload dialogs. This is null
2695 // (i.e., `TimeTicks()`) unless an adjustment was made.
2696 base::TimeTicks original_navigation_start_;
2697
2698 // Tracks whether an adjustment to the navigation start time was done for
2699 // legacy PostTask reasons rather than for running a beforeunload handler.
2700 bool navigation_start_adjustment_for_legacy_ = false;
2701
2702 // Tracks whether a beforeunload dialog was shown as part of this navigation.
2703 bool beforeunload_dialog_shown_ = false;
2704
Alex Moshchuk8e9a7f92025-02-03 22:50:352705 // The time this NavigationRequest was created.
2706 base::TimeTicks creation_time_ = base::TimeTicks().Now();
2707
Charlie Reise1d9b8182025-04-02 04:32:122708 // The time that the browser process started running beforeunload phase 2,
2709 // which is used to run any beforeunload handlers that were not run already in
2710 // an initiating renderer process during beforeunload phase 1 (and may include
2711 // handlers in a remote target frame or OOPIFs within the target frame). This
2712 // value is null if the navigation did not need to run beforeunload phase 2.
2713 // Note that legacy PostTask cases are not considered beforeunload phase 2,
2714 // because they do not run actual beforeunload handlers.
2715 base::TimeTicks beforeunload_phase2_start_time_;
2716
2717 // The time that beforeunload phase 2 ended, if it ran.
2718 base::TimeTicks beforeunload_phase2_end_time_;
danakjc492bf82020-09-09 20:02:442719
Minoru Chikamune6e45f702024-01-18 15:05:302720 // The time BeginNavigation() was called.
2721 base::TimeTicks begin_navigation_time_;
2722
Minoru Chikamune6e45f702024-01-18 15:05:302723 // The time OnResponseStarted() was called.
2724 base::TimeTicks receive_response_time_;
2725
Alex Moshchuk8e9a7f92025-02-03 22:50:352726 // The time this navigation was ready to commit.
2727 base::TimeTicks ready_to_commit_time_;
2728
Minoru Chikamune6e45f702024-01-18 15:05:302729 // The first `fetchStart` time. This is different from the
2730 // `first_request_start_time` in `NavigationHandleTiming` since the
2731 // `first_fetch_start_time_` is the first time when the browser is
2732 // ready to fetch using an HTTP request, whereas the `requestStart` is
2733 // when the browser has obtained a connection and is ready to send the
2734 // HTTP request.
2735 base::TimeTicks first_fetch_start_time_;
2736
2737 // The time when the final (which might also be the first) headers are
2738 // received.
2739 base::TimeTicks final_receive_headers_end_time_;
2740
Clark DuVallc97bcf72021-12-08 22:58:242741 // The time WillStartRequest() was called.
2742 base::TimeTicks will_start_request_time_;
2743
Charlie Reis0e2b5d092025-04-24 05:12:182744 // For bfcache and prerender page activations, this is the time that the
2745 // activation commits (after ReadyToCommitNavigation), since no commit IPC is
2746 // sent to the renderer process.
2747 base::TimeTicks page_activation_commit_time_;
2748
danakjc492bf82020-09-09 20:02:442749 // Set in ReadyToCommitNavigation.
2750 bool is_same_process_ = true;
2751
Andrew Verge754c70a2025-04-17 17:19:192752 // If set to a value other than NONE, starting the navigation will immediately
2753 // result in an error page with |net_error_| as the network error and
2754 // |error_page_html_| as the content. This value of this field indicates what
2755 // scenario prompted the error navigation.
2756 BrowserInitiatedErrorNavigationType browser_initiated_error_navigation_type_ =
2757 BrowserInitiatedErrorNavigationType::kNone;
2758
2759 // If browser_initiated_error_navigation_type_ is set, this HTML will be
2760 // shown as the content of the resulting error page.
2761 std::string error_page_html_;
danakjc492bf82020-09-09 20:02:442762
Yao Xiao6e1f7d32022-01-07 03:28:402763 // This test-only callback will be run when BeginNavigation() is called.
2764 base::OnceClosure begin_navigation_callback_for_testing_;
2765
danakjc492bf82020-09-09 20:02:442766 // This test-only callback will be run when all throttle checks have been
2767 // performed. If the callback returns true, On*ChecksComplete functions are
2768 // skipped, and only the test callback is being performed.
2769 // TODO(clamy): Revisit the unit test architecture.
2770 ThrottleChecksFinishedCallback complete_callback_for_testing_;
2771
David Bokan1bdb3701f2021-04-30 22:02:352772 // Test-only callback. Called when we're ready to call CommitNavigation.
2773 // Unlike above, this is informational only; it does not affect the request.
2774 base::OnceClosure ready_to_commit_callback_for_testing_;
2775
danakjc492bf82020-09-09 20:02:442776 // Unique id that identifies the navigation for which this NavigationRequest
2777 // is created.
2778 const int64_t navigation_id_ = ++unique_id_counter_;
2779 // static member for generating the unique id above.
2780 static int64_t unique_id_counter_;
2781
danakjc492bf82020-09-09 20:02:442782 // Timer for detecting an unexpectedly long time to commit a navigation.
2783 base::OneShotTimer commit_timeout_timer_;
2784
Peter Kasting7ba9440c2020-11-22 01:49:022785 base::CallbackListSubscription
danakjc492bf82020-09-09 20:02:442786 render_process_blocked_state_changed_subscription_;
2787
2788 // The headers used for the request. The value of this comes from
2789 // |begin_params_->headers|. If not set, it needs to be calculated.
Arthur Sonzognic686e8f2024-01-11 08:36:372790 std::optional<net::HttpRequestHeaders> request_headers_;
danakjc492bf82020-09-09 20:02:442791
2792 // Used to update the request's headers. When modified during the navigation
2793 // start, the headers will be applied to the initial network request. When
2794 // modified during a redirect, the headers will be applied to the redirected
2795 // request.
2796 net::HttpRequestHeaders modified_request_headers_;
2797
2798 net::HttpRequestHeaders cors_exempt_request_headers_;
2799
2800 // Set of headers to remove during the redirect phase. This can only be
2801 // modified during the redirect phase.
2802 std::vector<std::string> removed_request_headers_;
2803
Mingyu Lei2e0b586e2023-07-25 18:26:002804 // The RenderFrameHost that is being restored from the back/forward cache.
2805 // This can be null if this navigation is not restoring a page from the
2806 // back/forward cache.
Arthur Sonzognic686e8f2024-01-11 08:36:372807 std::optional<base::SafeRef<RenderFrameHostImpl>>
Mingyu Lei2e0b586e2023-07-25 18:26:002808 rfh_restored_from_back_forward_cache_;
Rakina Zata Amni2eed6322021-09-30 22:22:572809
2810 // Whether the navigation is for restoring a page from the back/forward cache
Mingyu Lei7956b8b2023-07-24 08:24:082811 // or not.
Rakina Zata Amni2eed6322021-09-30 22:22:572812 const bool is_back_forward_cache_restore_;
danakjc492bf82020-09-09 20:02:442813
2814 // These are set to the values from the FrameNavigationEntry this
2815 // NavigationRequest is associated with (if any).
2816 int64_t frame_entry_item_sequence_number_ = -1;
2817 int64_t frame_entry_document_sequence_number_ = -1;
2818
2819 // If non-empty, it represents the IsolationInfo explicitly asked to be used
2820 // for this NavigationRequest.
Arthur Sonzognic686e8f2024-01-11 08:36:372821 std::optional<net::IsolationInfo> isolation_info_;
danakjc492bf82020-09-09 20:02:442822
Rakina Zata Amni0c8ffbe2023-10-05 19:32:562823 // This is used to store the `RenderFrameHostManager::current_frame_host()` id
2824 // when the navigation commits and about to potentially change the current
2825 // RenderFrameHost. The ID (if set) refers to the RFH of the document that was
2826 // replaced when this navigation committed, while the ID saved in
2827 // `current_render_frame_host_id_at_construction_` below refers to the RFH of
2828 // the document that was there when this navigation was started. The two might
2829 // be different, since other navigations could commit and change the current
2830 // RFH before this navigation commits, which can happen with navigation
2831 // queueing or early RFH swap.
2832 GlobalRenderFrameHostId previous_render_frame_host_id_;
2833
2834 // This is used to store the `RenderFrameHostManager::current_frame_host()` id
2835 // at request creation time. See also the comment for
2836 // `previous_render_frame_host_id_` above on how these two IDs may differ.
2837 const GlobalRenderFrameHostId current_render_frame_host_id_at_construction_;
danakjc492bf82020-09-09 20:02:442838
Antonio Sartori9a82f6f32020-12-14 09:22:452839 // Frame token of the frame host that initiated the navigation, derived from
Harkiran Bolaria2d0e38932021-04-27 17:44:352840 // |begin_params().initiator_frame_token|. This is best effort: it is only
danakjc492bf82020-09-09 20:02:442841 // defined for some renderer-initiated navigations (e.g., not drag and drop).
Antonio Sartori9a82f6f32020-12-14 09:22:452842 // The frame with the corresponding frame token may have been deleted before
2843 // the navigation begins. This parameter is defined if and only if
2844 // |initiator_process_id_| below is.
Arthur Sonzognic686e8f2024-01-11 08:36:372845 const std::optional<blink::LocalFrameToken> initiator_frame_token_;
Antonio Sartori9a82f6f32020-12-14 09:22:452846
2847 // ID of the renderer process of the frame host that initiated the navigation.
2848 // This is defined if and only if |initiator_frame_token_| above is, and it is
2849 // only valid in conjunction with it.
Hiroki Nakagawa656c8182021-06-01 05:56:382850 const int initiator_process_id_ = ChildProcessHost::kInvalidUniqueID;
danakjc492bf82020-09-09 20:02:442851
Hiroshige Hayashizaki8bf57882023-10-18 15:17:402852 // The initiator Document's token, if it is present when this
2853 // NavigationRequest was created.
Arthur Sonzognic686e8f2024-01-11 08:36:372854 std::optional<blink::DocumentToken> initiator_document_token_;
Hiroshige Hayashizaki8bf57882023-10-18 15:17:402855
Arthur Sonzognidc8508ab2023-08-17 08:42:422856 // The sandbox flags of the navigation's initiator, if any.
2857 // WebSandboxFlags::kNone otherwise.
2858 const network::mojom::WebSandboxFlags sandbox_flags_initiator_;
2859
John Delaney8623c642021-01-06 17:37:072860 // Whether a navigation in a new window had the opener suppressed. False if
2861 // the navigation is not in a new window. Can only be true for renderer
2862 // initiated navigations which use `CreateBrowserInitiated()`.
Hiroki Nakagawa656c8182021-06-01 05:56:382863 const bool was_opener_suppressed_ = false;
John Delaney8623c642021-01-06 17:37:072864
danakjc492bf82020-09-09 20:02:442865 // This tracks a connection between the current pending entry and this
2866 // request, such that the pending entry can be discarded if no requests are
2867 // left referencing it.
2868 std::unique_ptr<NavigationControllerImpl::PendingEntryRef> pending_entry_ref_;
2869
2870 // Used only by DCHECK.
2871 // True if the NavigationThrottles are running an event, the request then can
2872 // be cancelled for deferring.
2873 bool processing_navigation_throttle_ = false;
2874
danakjc492bf82020-09-09 20:02:442875 // Holds the required CSP for this navigation. This will be moved into
2876 // the RenderFrameHost at DidCommitNavigation time.
2877 network::mojom::ContentSecurityPolicyPtr required_csp_;
2878
Antonio Sartori5abc8de2021-07-13 08:42:472879 // Whether the document loaded by this navigation will be committed inside an
Arthur Sonzogni64457592022-11-22 11:08:592880 // iframe credentialless. Documents loaded inside credentialless iframes get
2881 // partitioned storage and use a transient NetworkAnonymizationKey.
2882 const bool is_credentialless_;
Antonio Sartori5abc8de2021-07-13 08:42:472883
Titouan Rigoudy2f995bc2021-02-19 19:39:412884 // Non-nullopt from construction until |TakePolicyContainerHost()| is called.
Arthur Sonzognic686e8f2024-01-11 08:36:372885 std::optional<NavigationPolicyContainerBuilder> policy_container_builder_;
Antonio Sartori3cfa3b62020-10-09 10:42:402886
danakjc492bf82020-09-09 20:02:442887 std::unique_ptr<CrossOriginEmbedderPolicyReporter> coep_reporter_;
2888
Camille Lamy36afacd2025-01-16 14:25:182889 std::unique_ptr<DocumentIsolationPolicyReporter> dip_reporter_;
2890
Aman Vermac59efd02024-11-18 20:30:172891 std::unique_ptr<viz::PeakGpuMemoryTracker> loading_mem_tracker_;
danakjc492bf82020-09-09 20:02:442892
2893 // Structure tracking the effects of the CrossOriginOpenerPolicy on this
2894 // navigation.
Hiroki Nakagawa656c8182021-06-01 05:56:382895 CrossOriginOpenerPolicyStatus coop_status_{this};
danakjc492bf82020-09-09 20:02:442896
2897#if DCHECK_IS_ON()
2898 bool is_safe_to_delete_ = true;
2899#endif
2900
2901 // UKM source associated with the page we are navigated away from.
2902 const ukm::SourceId previous_page_ukm_source_id_;
2903
2904 // If true, changes to the user-agent override require a reload. If false, a
2905 // reload is not necessary.
2906 bool ua_change_requires_reload_ = true;
2907
Daniel Chengf776864c2020-09-26 09:55:222908 // Controls whether or not an error page is displayed on error. If set to
2909 // true, an error will be treated as if the user simply cancelled the
2910 // navigation.
2911 bool silently_ignore_errors_ = false;
2912
2913 // Similar but only suppresses the error page when the error code is
2914 // net::ERR_BLOCKED_BY_CLIENT.
Daniel Cheng738266dc2020-09-11 19:56:282915 bool silently_ignore_blocked_by_client_ = false;
2916
Lukasz Anforowicz39a8aef2020-12-17 23:50:152917 // Whether the navigation loads an MHTML document or a subframe of an MHTML
2918 // document. The navigation might or might not be fullfilled from the MHTML
2919 // archive (see `is_mhtml_subframe_loaded_from_achive` in the NeedsUrlLoader
2920 // method).
2921 bool is_mhtml_or_subframe_ = false;
arthursonzogni3fc224b2020-10-07 10:41:162922
Kenichi Ishibashicf248fb2021-04-07 22:29:352923 // True when at least one preload Link header was received via an Early Hints
2924 // response. This is set only for a main frame navigation.
Kenichi Ishibashi784dd402021-10-15 00:19:242925 bool was_resource_hints_received_ = false;
Kenichi Ishibashicf248fb2021-04-07 22:29:352926
Kenichi Ishibashi6301d0362022-04-12 23:32:562927 // Set to true when this navigation has created parameters for
2928 // NavigationEarlyHintsManager. Used to check whether cross origin redirects
2929 // happened after Early Hints responses are received.
2930 bool did_create_early_hints_manager_params_ = false;
2931
2932 // Set to true when an Early Hints response was received before cross origin
2933 // redirects during navigation.
2934 bool did_receive_early_hints_before_cross_origin_redirect_ = false;
2935
danakjc492bf82020-09-09 20:02:442936 // Observers listening to cookie access notifications for the network requests
Giovanni Ortuño Urquidie0a77b42025-03-28 14:31:352937 // made by this navigation. unique_ptr so it can be replaced in tests.
2938 std::unique_ptr<CookieAccessObservers> cookie_observers_;
danakjc492bf82020-09-09 20:02:442939
Steven Valdeza06f680c2023-03-21 19:00:102940 // Observers listening to Trust Token access notifications for the network
2941 // requests made by this navigation.
2942 mojo::ReceiverSet<network::mojom::TrustTokenAccessObserver>
2943 trust_token_observers_;
2944
Tsuyoshi Horobcd0b9f62023-06-28 11:35:322945 // Observers listening to shared dictionary access notifications for the
2946 // network requests made by this navigation.
2947 mojo::ReceiverSet<network::mojom::SharedDictionaryAccessObserver>
2948 shared_dictionary_observers_;
2949
Daniel Rubery6420d74302024-11-19 01:42:402950 mojo::ReceiverSet<network::mojom::DeviceBoundSessionAccessObserver>
2951 device_bound_session_observers_;
2952
Domenic Denicola5fdc2b7f2021-01-15 20:29:172953 OriginAgentClusterEndResult origin_agent_cluster_end_result_ =
2954 OriginAgentClusterEndResult::kNotRequestedAndNotOriginKeyed;
danakjc492bf82020-09-09 20:02:442955
Matt Menke7f2e1ac52020-12-10 01:16:102956 net::IsolationInfo isolation_info_for_subresources_;
2957
Hiroki Nakagawa6c5f39bd2021-07-13 00:22:362958 // Set while CommitDeferringConditions are running for prerendered page
2959 // activation. This is needed as PrerenderHost hasn't been reserved and
2960 // prerender_frame_tree_node_id() is not available yet while they are
2961 // running.
Khushal Sagarc05a8b292024-02-28 15:29:252962 bool is_running_potential_prerender_activation_checks_ = false;
Hiroki Nakagawa6c5f39bd2021-07-13 00:22:362963
Yao Xiao6e1f7d32022-01-07 03:28:402964 // Set to true before the fenced frame url mapping. Reset to false when the
2965 // mapping finishes. If the initial mapping state of the urn:uuid is pending,
2966 // the mapping will finish asynchronously; otherwise, the mapping will finish
2967 // synchronously.
2968 bool is_deferred_on_fenced_frame_url_mapping_ = false;
2969
Yao Xiaod8d248fa2022-12-09 22:28:302970 // The start time of fenced frame url mapping.
2971 base::TimeTicks fenced_frame_url_mapping_start_time_;
2972
David Bokanf7db7062021-05-27 16:23:102973 // The root frame tree node id of the prerendered page. This will be a valid
Avi Drissmanbd153642024-09-03 18:58:052974 // FrameTreeNodeId value when this navigation will activate a prerendered
2975 // page. For all other navigations this will be an invalid FrameTreeNodeId. We
2976 // only know whether this is the case when BeginNavigation is called so the
2977 // optional will be empty until then and callers must not query its value
2978 // before it's been computed.
Keita Suzuki633dd4862025-08-02 01:59:102979 // TODO(crbug.com/427054641): Remove this field once the migration to use
2980 // `reserved_prerender_host_info_` is complete.
Avi Drissmanbd153642024-09-03 18:58:052981 std::optional<FrameTreeNodeId> prerender_frame_tree_node_id_;
Hiroki Nakagawa6c5f39bd2021-07-13 00:22:362982
Harkiran Bolaria8bee0062021-08-12 10:06:342983 // Contains state pertaining to a prerender activation. This is only used if
2984 // this navigation is a prerender activation.
2985 struct PrerenderActivationNavigationState {
2986 PrerenderActivationNavigationState();
2987 ~PrerenderActivationNavigationState();
2988
2989 // Used to store a cloned NavigationEntry for activating a prerendered page.
2990 // |prerender_navigation_entry| is cloned and stored in NavigationRequest
2991 // when the prerendered page is transferred to the target FrameTree and is
2992 // consumed when NavigationController needs a new entry to commit.
2993 std::unique_ptr<NavigationEntryImpl> prerender_navigation_entry;
2994
2995 // Used to store the FrameReplicationState for the prerendered page prior to
2996 // activation. Value is to be used to populate
2997 // DidCommitProvisionalLoadParams values and to verify the replication state
2998 // after activation.
2999 blink::mojom::FrameReplicationState prerender_main_frame_replication_state;
3000 };
3001
Arthur Sonzognic686e8f2024-01-11 08:36:373002 std::optional<PrerenderActivationNavigationState> prerender_navigation_state_;
Hiroki Nakagawa5034e1962020-11-12 09:11:303003
Arthur Hemery373a7802020-12-23 16:32:363004 // The following fields that constitute the ClientSecurityState. This
3005 // state is used to take security decisions about the request, and later on
3006 // when passed to the RenderFrameHostImpl, about the fetching of subresources.
3007 //
3008 // They have some default values and get updated via inheritance or network
3009 // responses/redirects. Finally they get passed down to the
3010 // RenderFrameHostImpl at commit time.
Arthur Hemery2c5cd1f2023-07-28 12:03:543011 //
3012 // The policy to apply to private network requests for subresources of the
3013 // document we are navigating to. Influenced by the document's policy
3014 // container, origin, and `ContentBrowserClient`.
Jonathan Hao90ddbd42023-07-12 14:23:483015 network::mojom::PrivateNetworkRequestPolicy private_network_request_policy_ =
3016 network::mojom::PrivateNetworkRequestPolicy::kWarn;
Arthur Hemery373a7802020-12-23 16:32:363017
Titouan Rigoudy6f54ec52021-07-12 19:36:343018 // The list of web features that were used by the new document during
3019 // navigation. These can only be logged once the document commits, so they are
3020 // held in this vector until then.
3021 std::vector<blink::mojom::WebFeature> web_features_to_log_;
3022
Antonio Sartori0a7117a2021-04-01 09:23:373023 // Messages to be printed on the console in the target RenderFrameHost of this
3024 // NavigationRequest.
3025 std::vector<ConsoleMessage> console_messages_;
3026
Min Qin1b84727c2024-03-08 18:39:353027 // Indicates that this navigation is for PDF content in a renderer. On
3028 // Android, this can only be true when a PDF NativePage is created for
3029 // a main frame navigation.
Daniel Hosseinianf0fbfb42021-09-08 02:20:473030 bool is_pdf_ = false;
danakjc492bf82020-09-09 20:02:443031
Garrett Tanzer47852462022-07-20 18:16:413032 // Indicates that this navigation is an embedder-initiated navigation of a
3033 // fenced frame root. That is to say, the navigation is caused by a `src`
3034 // attribute mutation on the <fencedframe> element, which cannot be performed
3035 // from inside the fenced frame tree.
Alison Gale770f3fc2024-04-27 00:39:583036 // TODO(crbug.com/40202462): Make this `const` again once ShadowDOM is gone.
Garrett Tanzer2975eeac2022-08-22 16:34:013037 bool is_embedder_initiated_fenced_frame_navigation_ = false;
Garrett Tanzer47852462022-07-20 18:16:413038
Garrett Tanzer34cb92fe2022-09-28 17:50:543039 // On every embedder-initiated navigation of a fenced frame, i.e.
3040 // `is_embedder_initiated_fenced_frame_navigation_`, we reinitialize
Garrett Tanzer2453345f2024-01-18 22:02:293041 // the fenced frame properties with the default `FencedFrameProperties(url)`
Garrett Tanzer34cb92fe2022-09-28 17:50:543042 // constructor, which gives the fenced frame a fresh partition nonce.
3043 //
Garrett Tanzer2453345f2024-01-18 22:02:293044 // If the embedder-initiated navigation is to a urn:uuid, we overwrite
Garrett Tanzer34cb92fe2022-09-28 17:50:543045 // the default properties stored in this `NavigationRequest` with the
3046 // `FencedFrameProperties` bound to that urn:uuid, in
3047 // `NavigationRequest::OnFencedFrameURLMappingComplete`.
3048 //
3049 // For certain actions related to the pending `NavigationRequest` (rather
3050 // than the existing fenced frame document), e.g. partitioned network
3051 // requests for the pending navigation, we use the pending
3052 // `FencedFrameProperties`.
3053 //
3054 // If the navigation commits, this new set of fenced frame properties will be
3055 // stored in the fenced frame root FrameTreeNode in
3056 // `NavigationRequest::DidCommitNavigation`.
3057 //
3058 // If the navigation doesn't commit (e.g. an HTTP 204 response), the fenced
3059 // frame properties will not be stored in the fenced frame root.
Arthur Sonzognic686e8f2024-01-11 08:36:373060 std::optional<FencedFrameProperties> fenced_frame_properties_;
Garrett Tanzerc69f4642022-08-15 22:15:143061
Camillia Smith Barnes6a643962023-03-03 00:28:583062 // For fenced frames, any contextual string that was written by the embedder
3063 // via `blink::FencedFrameConfig::setSharedStorageContext()` to be later
3064 // retrieved only inside an eligible shared storage worklet in the fenced
3065 // frame via `sharedStorage.context`. absl:nullopt if this request is not for
3066 // a fenced frame or if the context string wasn't set prior to this
3067 // navigation.
Arthur Sonzognic686e8f2024-01-11 08:36:373068 std::optional<std::u16string> embedder_shared_storage_context_;
Camillia Smith Barnes6a643962023-03-03 00:28:583069
Asami Doi02406272021-11-12 05:01:443070 // Prerender2:
Keita Suzuki633dd4862025-08-02 01:59:103071 // The information about the reserved prerender host. This is used to pass
3072 // information about the reserved host including information required for
3073 // metrics collection.
3074 std::optional<ReservedPrerenderHostInfo> reserved_prerender_host_info_;
Asami Doi02406272021-11-12 05:01:443075
Clark DuVall3d91432d2021-12-07 20:29:443076 // Prevents the compositor from requesting main frame updates early in
3077 // navigation.
3078 std::unique_ptr<ui::CompositorLock> compositor_lock_;
3079
W. James MacLean00568d72022-02-24 19:36:553080 // This navigation request should swap browsing instances as part of a test
3081 // reset.
3082 bool force_new_browsing_instance_ = false;
3083
Steve Kobes8d111ba2024-11-12 15:23:513084 // Indicates this navigation should use a new compositor. This is used by web
3085 // tests to ensure that input state is fully reset between tests. See comments
3086 // at RenderFrameHostImpl::must_be_replaced().
3087 bool force_new_compositor_ = false;
3088
Yao Xiao9f73e882023-03-27 19:01:413089 // Whether the ongoing navigation resource request is eligible for topics
3090 // calculation. This is set before the initial request and each subsequent
3091 // redirect. If `topics_eligible_` is true, the request headers will contain
3092 // the "Sec-Browsing-Topics" header, and if the corresponding response headers
3093 // contain "Observe-Browsing-Topics: ?1", a topic observation will be stored.
3094 bool topics_eligible_ = false;
3095
Orr Bernsteina0cc6792023-11-14 22:12:353096 // Whether this navigation request is an iframe navigation for which the
3097 // adAuctionHeaders attribute is set. Only requests with this attribute may be
3098 // eligible for ad auction headerse, but not all requests with this attribute
3099 // are eligible. `ad_auction_headers_eligible_`, below, indicates whether or
3100 // not this request is eligible.
3101 const bool has_ad_auction_headers_attribute_ = false;
3102
3103 // Whether the ongoing navigation resource request should have its Ad Auction
3104 // response headers examined for interception. This is set before the initial
3105 // request for iframe navigations that provide the `adAuctionHeaders`
3106 // attribute. On redirect or error, this is always set to false. If this is
3107 // set to true, the request headers will contain the "Sec-Ad-Auction-Fetch:
3108 // ?1" header, and several response headers will be intercepted. See
3109 // content/browser/interest_group/ad_auction_headers_util.h for more details.
3110 bool ad_auction_headers_eligible_ = false;
3111
Camillia Smith Barnes3cad1ba2023-10-30 20:10:163112 // Whether or not the original request (without considering redirects or
3113 // permissions policy) opted-in to write to shared storage from response
3114 // headers. See https://github.com/WICG/shared-storage#from-response-headers
3115 bool shared_storage_writable_opted_in_ = false;
3116
3117 // Whether or not the current request is eligible to shared storage from
Camillia Smith Barnes6d2966c82023-08-23 21:16:183118 // response headers. See
3119 // https://github.com/WICG/shared-storage#from-response-headers
Camillia Smith Barnes3cad1ba2023-10-30 20:10:163120 bool shared_storage_writable_eligible_ = false;
Camillia Smith Barnes6d2966c82023-08-23 21:16:183121
Yao Xiao58c2f2c2023-05-16 20:05:183122 // A WeakPtr for the BindContext associated with the browser routing loader
3123 // factory for the committing document. This will be set in
3124 // `CommitNavigation()`, and can become null if the corresponding factory is
3125 // destroyed. Upon `DidCommitNavigation()`,
3126 // `subresource_proxying_url_loader_service_bind_context_` will be notified
3127 // with the committed document.
3128 base::WeakPtr<SubresourceProxyingURLLoaderService::BindContext>
3129 subresource_proxying_url_loader_service_bind_context_;
Yao Xiao549be4472023-01-03 22:53:123130
Ming-Ying Chung977404c2023-11-08 12:30:103131 // A WeakPtr for the FactoryContext associated with the browser fetch
3132 // keepalive loader factory for the committing document.
3133 // This field will be set in `CommitNavigation()`, and can become null if the
3134 // corresponding factory is destroyed.
3135 // Upon `DidCommitNavigation()`, this field will be notified with the
3136 // committed document.
3137 base::WeakPtr<KeepAliveURLLoaderService::FactoryContext>
3138 keep_alive_url_loader_factory_context_;
3139 // A WeakPtr for the FactoryContext associated with the browser fetchlater
3140 // loader factory for the committing document.
3141 // See also `keep_alive_url_loader_factory_context_` for the timing to update.
3142 base::WeakPtr<KeepAliveURLLoaderService::FactoryContext>
3143 fetch_later_loader_factory_context_;
3144
Rakina Zata Amnia68329fe2025-07-02 10:15:033145 // Set to true when the loaders above are set by unittests that want to avoid
3146 // setting a real connection to the renderer.
3147 bool did_set_keep_alive_url_loader_factory_context_for_testing_ = false;
3148 bool did_set_fetch_later_url_loader_factory_context_for_testing_ = false;
3149
Julie Jeongeun Kim4a5fef22022-04-02 02:08:383150 scoped_refptr<NavigationOrDocumentHandle> navigation_or_document_handle_;
3151
sbinglera07ae732022-12-02 20:49:053152 // Exposes getters and setters for Blink Runtime-Enabled Features to the
3153 // browser process. Any feature set using the RuntimeFeatureStateContext
3154 // before navigation commit will be communicated back to the renderer process.
3155 // NOTE: these feature changes will apply to the "to-be-created" document.
3156 blink::RuntimeFeatureStateContext runtime_feature_state_context_;
3157
Rakina Zata Amniaf55b5b62022-07-19 23:11:033158 // Renderer-initiated navigations can be canceled until the JS task that
3159 // started the navigation finishes. See RendererCancellationThrottle for more
3160 // details. The window of time in which the renderer can cancel the navigation
3161 // is called the "cancellation window" and the navigation can't commit until
3162 // the cancellation window ended, which `renderer_cancellation_listener_`
3163 // listens to. `renderer_cancellation_window_ended_` is true if the
3164 // cancellation window had ended. If
3165 // `renderer_cancellation_window_ended_callback_` is set, the navigation is
3166 // being deferred by RendererCancellationThrottle to wait for the cancellation
3167 // window to finish or for the navigation to get canceled. If it is set when
3168 // the cancellation window ended, the callback will be run, to resume the
3169 // navigation.
3170 mojo::Receiver<mojom::NavigationRendererCancellationListener>
3171 renderer_cancellation_listener_{this};
3172 bool renderer_cancellation_window_ended_ = false;
3173 base::OnceClosure renderer_cancellation_window_ended_callback_;
3174
Igor Ruvinov0ea2ebb2022-12-01 16:33:063175 // Whether a Cookie header added to this request should not be overwritten by
3176 // the network service.
3177 bool allow_cookies_from_browser_ = false;
3178
Daniel Chenga8a80092023-01-09 22:50:163179 // If the browser has asked the renderer to commit the navigation in a
3180 // speculative RenderFrameHost, but the renderer has not yet responded, a
Rakina Zata Amni49657c772023-03-31 06:41:533181 // subsequent navigation request will be queued when it is about to pick its
3182 // final RenderFrameHost, to avoid deleting the previous navigation's pending
3183 // commit RenderFrameHost. A queued navigation should populate this field with
3184 // a closure that resumes committing the navigation when run.
Daniel Chenga8a80092023-01-09 22:50:163185 //
Rakina Zata Amni49657c772023-03-31 06:41:533186 // The closure should always be bound with a `WeakPtr` receiver. To avoid
3187 // weird reentrancy bugs, it will be run as a non-nested posted task, which
3188 // means the original NavigationRequest could already be deleted by the
3189 // time the closure runs.
Daniel Chenga8a80092023-01-09 22:50:163190 base::OnceClosure resume_commit_closure_;
3191
Daniel Cheng557868f2023-07-28 00:10:203192 // Metrics for measuring the impact of navigation queueing. Note that while
3193 // `resume_commit_closure_` is set on the navigation that was *blocked*, these
3194 // metrics are set on the NavigationRequest that is *blocking*.
3195 struct PendingCommitMetrics {
3196 // When this `NavigationRequest` caused its speculative RenderFrameHost to
3197 // enter pending commit.
3198 base::TimeTicks start_time;
3199 // How many `GetFrameHostForNavigation()` calls failed in total.
3200 int blocked_count = 0;
3201 // How many `GetFrameHostForNavigation()` calls failed when trying to assign
3202 // a final `RenderFrameHost` for commit.
3203 int blocked_commit_count = 0;
3204 };
3205 PendingCommitMetrics pending_commit_metrics_;
3206
Arthur Hemerya2e2c5f12023-01-16 15:00:153207 // Records whether the new document will commit inside another BrowsingContext
3208 // group as a result of this navigation, and for what reason. Deciding whether
3209 // to clear the window name and to clear the proxies are based on this value.
3210 //
3211 // It is created with a default no-swap value, and is set within
3212 // RenderFrameHostManager::GetSiteInstanceForNavigation(). It is generally set
3213 // more than once, first for a speculative computation before receiving
3214 // headers, then for each redirect, and finally once a definitve response has
3215 // been received. It might also never be set if the navigation does not go
3216 // through SiteInstance selection, such as for a renderer initiated
3217 // same-document navigation.
3218 BrowsingContextGroupSwap browsing_context_group_swap_ =
3219 BrowsingContextGroupSwap::CreateDefault();
3220
Nate Chapin6c43c022023-02-13 23:32:423221 // See `set_pending_navigation_api_key()` for context.
Arthur Sonzognic686e8f2024-01-11 08:36:373222 std::optional<std::string> pending_navigation_api_key_;
Nate Chapin6c43c022023-02-13 23:32:423223
Nate Chapin154b14b2023-02-17 18:28:163224 // If this NavigationRequest is for a main-frame same-document back/forward
3225 // navigation, any subframe NavigationRequests are deferred until the renderer
3226 // has a chance to fire a navigate event. If the navigate
3227 // event allows the navigation to proceed,
3228 // UnblockPendingSubframeNavigationRequestsIfNeeded() will resume these
3229 // requests
3230 std::vector<base::WeakPtr<SubframeHistoryNavigationThrottle>>
3231 subframe_history_navigation_throttles_;
3232
3233 // If this NavigationRequest is in a subframe and part of a history traversal,
3234 // and the main frame is performing a same-document navigation, this token
3235 // may be set if there is a possibility that JS in the main frame will cancel
3236 // the history traversal via the navigate event. In that case, this token is
3237 // used to look up the main frame's NavigationRequest so that it can be passed
3238 // SubframeHistoryNavigationThrottle can defer this request until the main
3239 // frame commits.
Arthur Sonzognic686e8f2024-01-11 08:36:373240 std::optional<base::UnguessableToken>
Nate Chapin154b14b2023-02-17 18:28:163241 main_frame_same_document_navigation_token_;
3242
Mingyu Lei1fa6a1f2023-02-21 13:17:463243 // The listener that receives cookie change events and maintains cookie change
3244 // information for the domain of the URL that this `NavigationRequest` is
3245 // navigating to. The listener will observe all the cookie changes starting
3246 // from the navigation/redirection, and it will be moved to the
3247 // `RenderFrameHostImpl` when the navigation is committed and continues
3248 // observing until the destruction of the document.
3249 // See `RenderFrameHostImpl::CookieChangeListener`.
3250 std::unique_ptr<RenderFrameHostImpl::CookieChangeListener>
3251 cookie_change_listener_;
3252
Daniel Rubery03e71992025-02-19 22:03:303253 // The observer that receives device bound session events and
3254 // maintains device bound session information for the domain of the
3255 // URL that this `NavigationRequest` is navigating to. The observer
3256 // will observe all device bound session changes starting from the
3257 // navigation/redirection, and it will be moved to the
3258 // `RenderFrameHostImpl` when the navigation is committed and
3259 // continues observing until the destructoin of the document.
3260 // See `RenderFrameHostImpl::DeviceBoundSessionObserver`.
3261 std::unique_ptr<RenderFrameHostImpl::DeviceBoundSessionObserver>
3262 device_bound_session_observer_;
3263
Kouhei Uenoa0297b0b2023-06-15 05:39:483264 // LCP Critical Path Predictor managed hint data those were already available
3265 // at the time of navigation. The hint is passed along to the renderer process
3266 // on commit along with the other navigation params.
3267 blink::mojom::LCPCriticalPathPredictorNavigationTimeHint lcpp_hint_;
3268
Rakina Zata Amni208f7672023-04-07 12:21:253269 // The WebUI object to be used for this navigation. When a RenderFrameHost has
3270 // been picked for the navigation, the WebUI object will be moved to be owned
3271 // by the RenderFrameHost.
3272 std::unique_ptr<WebUIImpl> web_ui_;
3273
Igor Ruvinovdcb81982023-06-21 22:22:173274 // Returns whether this navigation is currently deferred.
3275 bool IsDeferred();
3276
3277 // The watcher used to asynchronously read the response body from the data
3278 // pipe. Once the response body is read, it is passed to the original caller
3279 // using the stored callback. This is instantiated when a response body is
3280 // requested and destroyed upon returning the response body.
3281 std::unique_ptr<mojo::SimpleWatcher> response_body_watcher_;
3282 ResponseBodyCallback response_body_callback_;
3283 // Used to confirm that any NavigationThrottle that calls `GetResponseBody()`
3284 // becomes deferred.
3285 bool was_get_response_body_called_ = false;
3286
3287 // Used to prevent re-entrancy into `Resume()`.
3288 bool is_resuming_ = false;
3289
Alex Moshchuk854e0be72023-08-04 22:35:353290 EarlyRenderFrameHostSwapType early_render_frame_host_swap_type_ =
3291 EarlyRenderFrameHostSwapType::kNone;
3292
John Delaney4cf7d6ea2023-11-09 17:29:563293 // Whether the embedder indicated this navigation is being used for
3294 // advertising porpoises.
3295 bool is_ad_tagged_ = false;
3296
Sharon Yang13118162023-11-14 19:40:233297 // This is the origin to commit value calculated at request time for data: URL
3298 // navigations. It is stored so that the opaque origin nonce can be maintained
3299 // across a navigation. This value is used when a speculative SiteInstance
3300 // is created so the site URL of the navigation can match the initiator
3301 // origin. We store the tentative origin to commit value, since we need it
3302 // before ready to commit time, which is when the regular origin to commit
3303 // value is available.
Arthur Sonzognic686e8f2024-01-11 08:36:373304 std::optional<url::Origin> tentative_data_origin_to_commit_;
Sharon Yang13118162023-11-14 19:40:233305
Khushal Sagar21c626812024-02-29 23:32:183306 // `pageswap` can be fired at different stages of the navigation lifecycle:
Khushal Sagar2dd8a3d2024-02-13 20:49:253307 // - ready to commit if this navigation is associated with a ViewTransition.
3308 // - unload old document if there is no ViewTransition opt-in.
Khushal Sagar21c626812024-02-29 23:32:183309 // This tracks whether the pageswap event has been fired for this
Khushal Sagar2dd8a3d2024-02-13 20:49:253310 // navigation.
Khushal Sagar21c626812024-02-29 23:32:183311 bool did_fire_page_swap_ = false;
Khushal Sagar2dd8a3d2024-02-13 20:49:253312
Khushal Sagar8e966702024-03-13 19:49:163313 // Set if there has been any cross-origin redirects in the lifetime of this
3314 // request.
3315 bool did_encounter_cross_origin_redirect_ = false;
3316
Khushal Sagar91b544222024-03-12 17:36:593317 // A scoped reference on the ViewTransition resources generated for this
3318 // navigation. This is set after we received the cached results from the old
3319 // Document's renderer. If the navigation commits, the resources are
3320 // transferred to the new Document's view. If the navigation finishes without
3321 // committing, the resources are destroyed with this request.
3322 std::unique_ptr<ScopedViewTransitionResources> view_transition_resources_;
3323
Mustafa Emre Acer1001b3d2024-07-09 23:10:433324 // If true, this means that this navigation request was initiated by an
Vladimir Levin6e894a92024-06-12 18:02:463325 // animated transition.
3326 bool was_initiated_by_animated_transition_ = false;
3327
Rakina Zata Amni58681c62024-06-25 06:32:133328 // If the navigation is cancelled/discarded before it commits, the reason
3329 // for cancellation will be saved.
3330 std::optional<NavigationDiscardReason> navigation_discard_reason_;
3331
Mustafa Emre Acer1001b3d2024-07-09 23:10:433332 // If true, HTTPS Upgrades will be disabled on this navigation request.
3333 bool force_no_https_upgrade_ = false;
3334
Min Qin3669650b2024-08-07 18:13:523335 // The initial request method of the request, before any redirects.
3336 std::string request_method_;
3337
William Liu0c323bfce2024-11-13 21:21:103338 // Set to true if `this` started as a same-document navigation but couldn't
3339 // commit, and was restarted as a cross-document navigation. See
3340 // `blink::mojom::CommitResult::RestartCrossDocument`.
3341 bool was_reset_for_cross_document_restart_ = false;
3342
Mike Jackson82654a3a2025-02-13 07:48:223343 // The confidence level captured at the time the navigation request was
3344 // instantiated.
3345 blink::mojom::ConfidenceLevel confidence_level_ =
3346 blink::mojom::ConfidenceLevel::kHigh;
3347
John Kim1a6735b2025-08-12 19:16:503348 // The token value for canvas noising. This should only be set on main frame
3349 // navigations that subsequently set the token value on the page.
3350 std::optional<uint64_t> canvas_noise_token_ = std::nullopt;
3351
Jiacheng Guo2d8489d72025-08-18 06:51:143352 // For NavigationRequests not in a prerendered page, the value will be the
3353 // default-constructed null value.
3354 const PrerenderHostId prerender_host_id_;
3355
Daniel Hosseinianf0fbfb42021-09-08 02:20:473356 base::WeakPtrFactory<NavigationRequest> weak_factory_{this};
danakjc492bf82020-09-09 20:02:443357};
3358
3359} // namespace content
3360
3361#endif // CONTENT_BROWSER_RENDERER_HOST_NAVIGATION_REQUEST_H_