blob: 7d2d4ba83ae7339bc66a3aec7a3aaefe2ea59927 [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#ifndef CONTENT_BROWSER_LOADER_NAVIGATION_URL_LOADER_H_
6#define CONTENT_BROWSER_LOADER_NAVIGATION_URL_LOADER_H_
7
dcheng40ce7b382016-04-08 23:46:138#include <memory>
tzik1a4dd5e2018-10-15 06:37:159#include <string>
10#include <vector>
dcheng40ce7b382016-04-08 23:46:1311
Takashi Toyoshima5af383aa2019-07-22 15:24:2212#include "content/browser/loader/navigation_loader_interceptor.h"
davidben6b77cd72014-10-29 21:13:4513#include "content/common/content_export.h"
Lei Zhang839f30c2023-03-23 22:29:4914#include "services/network/public/mojom/cookie_access_observer.mojom.h"
Daniel Rubery6420d74302024-11-19 01:42:4015#include "services/network/public/mojom/device_bound_sessions.mojom-forward.h"
Sigurd Schneiderca5c439e2021-07-24 18:19:4116#include "services/network/public/mojom/devtools_observer.mojom-forward.h"
Tsuyoshi Horobcd0b9f62023-06-28 11:35:3217#include "services/network/public/mojom/shared_dictionary_access_observer.mojom.h"
Steven Valdeza06f680c2023-03-21 19:00:1018#include "services/network/public/mojom/trust_token_access_observer.mojom-forward.h"
Lei Zhang839f30c2023-03-23 22:29:4919#include "services/network/public/mojom/url_loader_network_service_observer.mojom.h"
Min Qin83d07872017-10-26 23:22:4120
Chong Zhang7607f1f2018-06-01 20:52:2021namespace net {
22class HttpRequestHeaders;
23}
24
davidben6b77cd72014-10-29 21:13:4525namespace content {
26
Clark DuVallfffa41e2019-06-25 20:27:1927class BrowserContext;
clamy1e5574e92016-09-29 16:48:4428class NavigationUIData;
davidben6b77cd72014-10-29 21:13:4529class NavigationURLLoaderDelegate;
30class NavigationURLLoaderFactory;
Tsuyoshi Horod5eb7612019-05-09 08:59:4631class PrefetchedSignedExchangeCache;
Zhuoyu Qian1811ccf2020-01-06 06:46:5432class ServiceWorkerMainResourceHandle;
jam0f396ee2017-03-01 01:34:1133class StoragePartition;
davidben6b77cd72014-10-29 21:13:4534struct NavigationRequestInfo;
35
Arthur Hemery0dd65812019-08-01 14:18:4536// The navigation logic's UI thread entry point into the resource loading stack.
37// It exposes an interface to control the request prior to receiving the
38// response. If the NavigationURLLoader is destroyed before OnResponseStarted is
39// called, the request is aborted.
davidben6b77cd72014-10-29 21:13:4540class CONTENT_EXPORT NavigationURLLoader {
41 public:
Hiroki Nakagawa5034e1962020-11-12 09:11:3042 enum class LoaderType {
43 // Creates a regular NavigationURLLoader.
44 kRegular,
45
Takashi Toyoshima258a6152021-10-06 23:07:4746 // Creates a noop NavigationURLLoader for BackForwardCache activation.
Hiroki Nakagawa6c5f39bd2021-07-13 00:22:3647 kNoopForBackForwardCache,
48
Takashi Toyoshima258a6152021-10-06 23:07:4749 // Creates a noop NavigationURLLoader for Prerender activation.
Hiroki Nakagawa6c5f39bd2021-07-13 00:22:3650 kNoopForPrerender,
Hiroki Nakagawa5034e1962020-11-12 09:11:3051 };
52
davidben6b77cd72014-10-29 21:13:4553 // Creates a NavigationURLLoader. The caller is responsible for ensuring that
Takashi Toyoshima258a6152021-10-06 23:07:4754 // `delegate` outlives the loader. `request_body` must not be accessed on the
davidben6b77cd72014-10-29 21:13:4555 // UI thread after this point.
56 //
Takashi Toyoshima258a6152021-10-06 23:07:4757 // If `loader_type` is LoaderType::kNoopForBackForwardCache or
58 // LoaderType::kNoopoForPrerender, a noop CachedNavigationURLLoader will be
59 // returned.
Lowell Manners0c04d632019-08-05 10:52:0260 //
davidben6b77cd72014-10-29 21:13:4561 // TODO(davidben): When navigation is disentangled from the loader, the
62 // request parameters should not come in as a navigation-specific
Takashi Toyoshima258a6152021-10-06 23:07:4763 // structure. Information like `has_user_gesture` and
64 // `should_replace_current_entry` in `request_info->common_params` shouldn't
65 // be needed at this layer.
dcheng40ce7b382016-04-08 23:46:1366 static std::unique_ptr<NavigationURLLoader> Create(
Clark DuVallfffa41e2019-06-25 20:27:1967 BrowserContext* browser_context,
jam0f396ee2017-03-01 01:34:1168 StoragePartition* storage_partition,
dcheng40ce7b382016-04-08 23:46:1369 std::unique_ptr<NavigationRequestInfo> request_info,
clamy1e5574e92016-09-29 16:48:4470 std::unique_ptr<NavigationUIData> navigation_ui_data,
Zhuoyu Qian1811ccf2020-01-06 06:46:5471 ServiceWorkerMainResourceHandle* service_worker_handle,
Tsuyoshi Horod5eb7612019-05-09 08:59:4672 scoped_refptr<PrefetchedSignedExchangeCache>
73 prefetched_signed_exchange_cache,
Takashi Toyoshima5af383aa2019-07-22 15:24:2274 NavigationURLLoaderDelegate* delegate,
Hiroki Nakagawa5034e1962020-11-12 09:11:3075 LoaderType loader_type,
Alexander Timin1cc31f42020-05-12 16:26:0176 mojo::PendingRemote<network::mojom::CookieAccessObserver> cookie_observer,
Steven Valdeza06f680c2023-03-21 19:00:1077 mojo::PendingRemote<network::mojom::TrustTokenAccessObserver>
78 trust_token_observer,
Tsuyoshi Horobcd0b9f62023-06-28 11:35:3279 mojo::PendingRemote<network::mojom::SharedDictionaryAccessObserver>
80 shared_dictionary_observer,
Dave Tapuska03d6f502021-03-05 23:06:2881 mojo::PendingRemote<network::mojom::URLLoaderNetworkServiceObserver>
82 url_loader_network_observer,
Dave Tapuska2a6046a2021-03-01 22:42:5283 mojo::PendingRemote<network::mojom::DevToolsObserver> devtools_observer,
Daniel Rubery6420d74302024-11-19 01:42:4084 mojo::PendingRemote<network::mojom::DeviceBoundSessionAccessObserver>
85 device_bound_session_observer,
Takashi Toyoshima2e8d61012021-06-07 10:31:2786 network::mojom::URLResponseHeadPtr cached_response_head = nullptr,
Takashi Toyoshima5af383aa2019-07-22 15:24:2287 std::vector<std::unique_ptr<NavigationLoaderInterceptor>>
88 initial_interceptors = {});
davidben6b77cd72014-10-29 21:13:4589
Hiroki Nakagawa6c5f39bd2021-07-13 00:22:3690 // For testing purposes; sets the factory for use in testing. The factory is
91 // not used for prerendered page activation as it needs to run a specific
92 // loader to satisfy its unique requirement. See the implementation comment in
93 // NavigationURLLoader::Create() for details.
Alison Gale770f3fc2024-04-27 00:39:5894 // TODO(crbug.com/40188852): Update this comment for restoration from
Hiroki Nakagawa6c5f39bd2021-07-13 00:22:3695 // BackForwardCache when it also starts depending on the requirement.
davidben6b77cd72014-10-29 21:13:4596 static void SetFactoryForTesting(NavigationURLLoaderFactory* factory);
97
Peter Boström828b9022021-09-21 02:28:4398 NavigationURLLoader(const NavigationURLLoader&) = delete;
99 NavigationURLLoader& operator=(const NavigationURLLoader&) = delete;
100
davidben6b77cd72014-10-29 21:13:45101 virtual ~NavigationURLLoader() {}
102
Hiroki Nakagawa6d377e4a2021-07-08 23:29:11103 // Called right after the loader is constructed.
104 virtual void Start() = 0;
105
davidben6b77cd72014-10-29 21:13:45106 // Called in response to OnRequestRedirected to continue processing the
Tarun Bansalbcd62c82022-01-18 17:27:38107 // request.
Takashi Toyoshimaeb2ba20c52020-04-27 16:34:58108 virtual void FollowRedirect(
Hiroshige Hayashizaki62ef6082025-07-30 00:59:38109 std::vector<std::string> removed_headers,
110 net::HttpRequestHeaders modified_headers,
111 net::HttpRequestHeaders modified_cors_exempt_headers) = 0;
davidben6b77cd72014-10-29 21:13:45112
Chris Thompson066eed22021-10-07 20:20:43113 // Sets an overall request timeout for this navigation, which will cause the
114 // navigation to fail if it expires before the navigation commits. This is
115 // separate from any //net level timeouts. Returns `true` if the timeout was
116 // started successfully. Repeated calls will be ignored (they won't reset the
117 // timeout) and will return `false`.
118 virtual bool SetNavigationTimeout(base::TimeDelta timeout) = 0;
Mustafa Acer7b99ac22024-07-23 14:57:28119 // Cancels the request timeout for this navigation. If the navigation is still
120 // happening, it will continue as if the timer wasn't set. Otherwise, this is
121 // a no-op.
122 virtual void CancelNavigationTimeout() = 0;
Chris Thompson066eed22021-10-07 20:20:43123
sisidovskic01b1a32023-10-12 06:42:24124 static uint32_t GetURLLoaderOptions(bool is_outermost_main_frame);
125
davidben6b77cd72014-10-29 21:13:45126 protected:
127 NavigationURLLoader() {}
davidben6b77cd72014-10-29 21:13:45128};
129
130} // namespace content
131
132#endif // CONTENT_BROWSER_LOADER_NAVIGATION_URL_LOADER_H_