blob: ea40c43659f382246a9e3c2ec2502c0f1e3396ae [file] [log] [blame]
Avi Drissman4e1b7bc32022-09-15 14:03:501// Copyright 2014 The Chromium Authors
davidben6b77cd72014-10-29 21:13:452// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "content/browser/loader/navigation_url_loader.h"
6
dcheng36b6aec92015-12-26 06:16:367#include <utility>
8
scottmg69985212017-04-12 16:47:289#include "base/command_line.h"
Minoru Chikamune99de26ca2024-02-29 06:45:2110#include "base/trace_event/trace_event.h"
Lowell Manners0c04d632019-08-05 10:52:0211#include "content/browser/loader/cached_navigation_url_loader.h"
12#include "content/browser/loader/navigation_loader_interceptor.h"
davidben6b77cd72014-10-29 21:13:4513#include "content/browser/loader/navigation_url_loader_factory.h"
arthursonzogni1fd60e62018-05-09 15:57:3214#include "content/browser/loader/navigation_url_loader_impl.h"
danakj22c9ee22020-09-16 16:37:2815#include "content/browser/renderer_host/navigation_request_info.h"
Tsuyoshi Horo0e20a6e2019-06-04 09:48:3016#include "content/browser/web_package/prefetched_signed_exchange_cache.h"
clamy1e5574e92016-09-29 16:48:4417#include "content/public/browser/navigation_ui_data.h"
Yutaka Hiranod8789f92018-01-30 09:59:5118#include "services/network/public/cpp/features.h"
davidben6b77cd72014-10-29 21:13:4519
20namespace content {
21
Daniel Bratell89560a02017-10-13 10:20:5422static NavigationURLLoaderFactory* g_loader_factory = nullptr;
davidben6b77cd72014-10-29 21:13:4523
Takashi Toyoshima258a6152021-10-06 23:07:4724// static
dcheng40ce7b382016-04-08 23:46:1325std::unique_ptr<NavigationURLLoader> NavigationURLLoader::Create(
Clark DuVallfffa41e2019-06-25 20:27:1926 BrowserContext* browser_context,
jam0f396ee2017-03-01 01:34:1127 StoragePartition* storage_partition,
dcheng40ce7b382016-04-08 23:46:1328 std::unique_ptr<NavigationRequestInfo> request_info,
clamy1e5574e92016-09-29 16:48:4429 std::unique_ptr<NavigationUIData> navigation_ui_data,
Zhuoyu Qian1811ccf2020-01-06 06:46:5430 ServiceWorkerMainResourceHandle* service_worker_handle,
Tsuyoshi Horod5eb7612019-05-09 08:59:4631 scoped_refptr<PrefetchedSignedExchangeCache>
32 prefetched_signed_exchange_cache,
Takashi Toyoshima5af383aa2019-07-22 15:24:2233 NavigationURLLoaderDelegate* delegate,
Hiroki Nakagawa5034e1962020-11-12 09:11:3034 LoaderType loader_type,
Alexander Timin1cc31f42020-05-12 16:26:0135 mojo::PendingRemote<network::mojom::CookieAccessObserver> cookie_observer,
Steven Valdeza06f680c2023-03-21 19:00:1036 mojo::PendingRemote<network::mojom::TrustTokenAccessObserver>
37 trust_token_observer,
Tsuyoshi Horobcd0b9f62023-06-28 11:35:3238 mojo::PendingRemote<network::mojom::SharedDictionaryAccessObserver>
39 shared_dictionary_observer,
Dave Tapuska03d6f502021-03-05 23:06:2840 mojo::PendingRemote<network::mojom::URLLoaderNetworkServiceObserver>
41 url_loader_network_observer,
Dave Tapuska2a6046a2021-03-01 22:42:5242 mojo::PendingRemote<network::mojom::DevToolsObserver> devtools_observer,
Daniel Rubery6420d74302024-11-19 01:42:4043 mojo::PendingRemote<network::mojom::DeviceBoundSessionAccessObserver>
44 device_bound_session_observer,
Takashi Toyoshima2e8d61012021-06-07 10:31:2745 network::mojom::URLResponseHeadPtr cached_response_head,
Takashi Toyoshima5af383aa2019-07-22 15:24:2246 std::vector<std::unique_ptr<NavigationLoaderInterceptor>>
47 initial_interceptors) {
Minoru Chikamune99de26ca2024-02-29 06:45:2148 TRACE_EVENT0("navigation", "NavigationURLLoader::Create");
Hiroki Nakagawa6c5f39bd2021-07-13 00:22:3649 // Prioritize CachedNavigationURLLoader over `g_loader_factory` even for tests
50 // as prerendered page activation needs to run synchronously and
51 // CachedNavigationURLLoader serves a fake response synchronously.
52 if (loader_type == LoaderType::kNoopForPrerender) {
53 DCHECK(cached_response_head);
54 return CachedNavigationURLLoader::Create(loader_type,
55 std::move(request_info), delegate,
56 std::move(cached_response_head));
57 }
58
Daniel Bratell89560a02017-10-13 10:20:5459 if (g_loader_factory) {
60 return g_loader_factory->CreateLoader(
Clark DuVall1df2052b2019-08-05 19:58:4661 storage_partition, std::move(request_info),
arthursonzogni7ce00b8f2019-08-22 09:37:0162 std::move(navigation_ui_data), service_worker_handle, delegate,
Hiroki Nakagawa5034e1962020-11-12 09:11:3063 loader_type);
davidben6b77cd72014-10-29 21:13:4564 }
arthursonzogni7ce00b8f2019-08-22 09:37:0165
Alison Gale770f3fc2024-04-27 00:39:5866 // TODO(crbug.com/40188852): Merge this into the kNoopForPrerender path
Hiroki Nakagawa6c5f39bd2021-07-13 00:22:3667 // above.
68 if (loader_type == LoaderType::kNoopForBackForwardCache) {
Takashi Toyoshima2e8d61012021-06-07 10:31:2769 DCHECK(cached_response_head);
Hiroki Nakagawa6c5f39bd2021-07-13 00:22:3670 return CachedNavigationURLLoader::Create(loader_type,
71 std::move(request_info), delegate,
Takashi Toyoshima2e8d61012021-06-07 10:31:2772 std::move(cached_response_head));
73 }
arthursonzogni7ce00b8f2019-08-22 09:37:0174
arthursonzogni1fd60e62018-05-09 15:57:3275 return std::make_unique<NavigationURLLoaderImpl>(
Clark DuVall1df2052b2019-08-05 19:58:4676 browser_context, storage_partition, std::move(request_info),
Adrienne Walker5b98d1ee2021-10-19 16:57:4177 std::move(navigation_ui_data), service_worker_handle,
Tsuyoshi Horod5eb7612019-05-09 08:59:4678 std::move(prefetched_signed_exchange_cache), delegate,
Steven Valdeza06f680c2023-03-21 19:00:1079 std::move(cookie_observer), std::move(trust_token_observer),
Tsuyoshi Horobcd0b9f62023-06-28 11:35:3280 std::move(shared_dictionary_observer),
Steven Valdeza06f680c2023-03-21 19:00:1081 std::move(url_loader_network_observer), std::move(devtools_observer),
Daniel Rubery6420d74302024-11-19 01:42:4082 std::move(device_bound_session_observer),
Steven Valdeza06f680c2023-03-21 19:00:1083 std::move(initial_interceptors));
davidben6b77cd72014-10-29 21:13:4584}
85
Takashi Toyoshima258a6152021-10-06 23:07:4786// static
davidben6b77cd72014-10-29 21:13:4587void NavigationURLLoader::SetFactoryForTesting(
88 NavigationURLLoaderFactory* factory) {
Daniel Bratell89560a02017-10-13 10:20:5489 DCHECK(g_loader_factory == nullptr || factory == nullptr);
90 g_loader_factory = factory;
davidben6b77cd72014-10-29 21:13:4591}
92
sisidovskic01b1a32023-10-12 06:42:2493// static
94uint32_t NavigationURLLoader::GetURLLoaderOptions(
95 bool is_outermost_main_frame) {
96 uint32_t options = network::mojom::kURLLoadOptionNone;
97
98 // Ensure that Mime sniffing works.
99 options |= network::mojom::kURLLoadOptionSniffMimeType;
100
101 if (is_outermost_main_frame) {
102 // SSLInfo is not needed on subframe or fenced frame responses because users
103 // can inspect only the certificate for the main frame when using the info
104 // bubble.
105 options |= network::mojom::kURLLoadOptionSendSSLInfoWithResponse;
106 }
107
108 // When there's a certificate error for a frame load (regardless of whether
109 // the error caused the connection to fail), SSLInfo is useful for adjusting
110 // security UI accordingly.
111 options |= network::mojom::kURLLoadOptionSendSSLInfoForCertificateError;
112
113 return options;
114}
davidben6b77cd72014-10-29 21:13:45115} // namespace content