Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors |
davidben | 6b77cd7 | 2014-10-29 21:13:45 | [diff] [blame] | 2 | // 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 | |
dcheng | 40ce7b38 | 2016-04-08 23:46:13 | [diff] [blame] | 8 | #include <memory> |
tzik | 1a4dd5e | 2018-10-15 06:37:15 | [diff] [blame] | 9 | #include <string> |
| 10 | #include <vector> |
dcheng | 40ce7b38 | 2016-04-08 23:46:13 | [diff] [blame] | 11 | |
Takashi Toyoshima | 5af383aa | 2019-07-22 15:24:22 | [diff] [blame] | 12 | #include "content/browser/loader/navigation_loader_interceptor.h" |
davidben | 6b77cd7 | 2014-10-29 21:13:45 | [diff] [blame] | 13 | #include "content/common/content_export.h" |
Lei Zhang | 839f30c | 2023-03-23 22:29:49 | [diff] [blame] | 14 | #include "services/network/public/mojom/cookie_access_observer.mojom.h" |
Daniel Rubery | 6420d7430 | 2024-11-19 01:42:40 | [diff] [blame] | 15 | #include "services/network/public/mojom/device_bound_sessions.mojom-forward.h" |
Sigurd Schneider | ca5c439e | 2021-07-24 18:19:41 | [diff] [blame] | 16 | #include "services/network/public/mojom/devtools_observer.mojom-forward.h" |
Tsuyoshi Horo | bcd0b9f6 | 2023-06-28 11:35:32 | [diff] [blame] | 17 | #include "services/network/public/mojom/shared_dictionary_access_observer.mojom.h" |
Steven Valdez | a06f680c | 2023-03-21 19:00:10 | [diff] [blame] | 18 | #include "services/network/public/mojom/trust_token_access_observer.mojom-forward.h" |
Lei Zhang | 839f30c | 2023-03-23 22:29:49 | [diff] [blame] | 19 | #include "services/network/public/mojom/url_loader_network_service_observer.mojom.h" |
Min Qin | 83d0787 | 2017-10-26 23:22:41 | [diff] [blame] | 20 | |
Chong Zhang | 7607f1f | 2018-06-01 20:52:20 | [diff] [blame] | 21 | namespace net { |
| 22 | class HttpRequestHeaders; |
| 23 | } |
| 24 | |
davidben | 6b77cd7 | 2014-10-29 21:13:45 | [diff] [blame] | 25 | namespace content { |
| 26 | |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 27 | class BrowserContext; |
clamy | 1e5574e9 | 2016-09-29 16:48:44 | [diff] [blame] | 28 | class NavigationUIData; |
davidben | 6b77cd7 | 2014-10-29 21:13:45 | [diff] [blame] | 29 | class NavigationURLLoaderDelegate; |
| 30 | class NavigationURLLoaderFactory; |
Tsuyoshi Horo | d5eb761 | 2019-05-09 08:59:46 | [diff] [blame] | 31 | class PrefetchedSignedExchangeCache; |
Zhuoyu Qian | 1811ccf | 2020-01-06 06:46:54 | [diff] [blame] | 32 | class ServiceWorkerMainResourceHandle; |
jam | 0f396ee | 2017-03-01 01:34:11 | [diff] [blame] | 33 | class StoragePartition; |
davidben | 6b77cd7 | 2014-10-29 21:13:45 | [diff] [blame] | 34 | struct NavigationRequestInfo; |
| 35 | |
Arthur Hemery | 0dd6581 | 2019-08-01 14:18:45 | [diff] [blame] | 36 | // 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. |
davidben | 6b77cd7 | 2014-10-29 21:13:45 | [diff] [blame] | 40 | class CONTENT_EXPORT NavigationURLLoader { |
| 41 | public: |
Hiroki Nakagawa | 5034e196 | 2020-11-12 09:11:30 | [diff] [blame] | 42 | enum class LoaderType { |
| 43 | // Creates a regular NavigationURLLoader. |
| 44 | kRegular, |
| 45 | |
Takashi Toyoshima | 258a615 | 2021-10-06 23:07:47 | [diff] [blame] | 46 | // Creates a noop NavigationURLLoader for BackForwardCache activation. |
Hiroki Nakagawa | 6c5f39bd | 2021-07-13 00:22:36 | [diff] [blame] | 47 | kNoopForBackForwardCache, |
| 48 | |
Takashi Toyoshima | 258a615 | 2021-10-06 23:07:47 | [diff] [blame] | 49 | // Creates a noop NavigationURLLoader for Prerender activation. |
Hiroki Nakagawa | 6c5f39bd | 2021-07-13 00:22:36 | [diff] [blame] | 50 | kNoopForPrerender, |
Hiroki Nakagawa | 5034e196 | 2020-11-12 09:11:30 | [diff] [blame] | 51 | }; |
| 52 | |
davidben | 6b77cd7 | 2014-10-29 21:13:45 | [diff] [blame] | 53 | // Creates a NavigationURLLoader. The caller is responsible for ensuring that |
Takashi Toyoshima | 258a615 | 2021-10-06 23:07:47 | [diff] [blame] | 54 | // `delegate` outlives the loader. `request_body` must not be accessed on the |
davidben | 6b77cd7 | 2014-10-29 21:13:45 | [diff] [blame] | 55 | // UI thread after this point. |
| 56 | // |
Takashi Toyoshima | 258a615 | 2021-10-06 23:07:47 | [diff] [blame] | 57 | // If `loader_type` is LoaderType::kNoopForBackForwardCache or |
| 58 | // LoaderType::kNoopoForPrerender, a noop CachedNavigationURLLoader will be |
| 59 | // returned. |
Lowell Manners | 0c04d63 | 2019-08-05 10:52:02 | [diff] [blame] | 60 | // |
davidben | 6b77cd7 | 2014-10-29 21:13:45 | [diff] [blame] | 61 | // TODO(davidben): When navigation is disentangled from the loader, the |
| 62 | // request parameters should not come in as a navigation-specific |
Takashi Toyoshima | 258a615 | 2021-10-06 23:07:47 | [diff] [blame] | 63 | // 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. |
dcheng | 40ce7b38 | 2016-04-08 23:46:13 | [diff] [blame] | 66 | static std::unique_ptr<NavigationURLLoader> Create( |
Clark DuVall | fffa41e | 2019-06-25 20:27:19 | [diff] [blame] | 67 | BrowserContext* browser_context, |
jam | 0f396ee | 2017-03-01 01:34:11 | [diff] [blame] | 68 | StoragePartition* storage_partition, |
dcheng | 40ce7b38 | 2016-04-08 23:46:13 | [diff] [blame] | 69 | std::unique_ptr<NavigationRequestInfo> request_info, |
clamy | 1e5574e9 | 2016-09-29 16:48:44 | [diff] [blame] | 70 | std::unique_ptr<NavigationUIData> navigation_ui_data, |
Zhuoyu Qian | 1811ccf | 2020-01-06 06:46:54 | [diff] [blame] | 71 | ServiceWorkerMainResourceHandle* service_worker_handle, |
Tsuyoshi Horo | d5eb761 | 2019-05-09 08:59:46 | [diff] [blame] | 72 | scoped_refptr<PrefetchedSignedExchangeCache> |
| 73 | prefetched_signed_exchange_cache, |
Takashi Toyoshima | 5af383aa | 2019-07-22 15:24:22 | [diff] [blame] | 74 | NavigationURLLoaderDelegate* delegate, |
Hiroki Nakagawa | 5034e196 | 2020-11-12 09:11:30 | [diff] [blame] | 75 | LoaderType loader_type, |
Alexander Timin | 1cc31f4 | 2020-05-12 16:26:01 | [diff] [blame] | 76 | mojo::PendingRemote<network::mojom::CookieAccessObserver> cookie_observer, |
Steven Valdez | a06f680c | 2023-03-21 19:00:10 | [diff] [blame] | 77 | mojo::PendingRemote<network::mojom::TrustTokenAccessObserver> |
| 78 | trust_token_observer, |
Tsuyoshi Horo | bcd0b9f6 | 2023-06-28 11:35:32 | [diff] [blame] | 79 | mojo::PendingRemote<network::mojom::SharedDictionaryAccessObserver> |
| 80 | shared_dictionary_observer, |
Dave Tapuska | 03d6f50 | 2021-03-05 23:06:28 | [diff] [blame] | 81 | mojo::PendingRemote<network::mojom::URLLoaderNetworkServiceObserver> |
| 82 | url_loader_network_observer, |
Dave Tapuska | 2a6046a | 2021-03-01 22:42:52 | [diff] [blame] | 83 | mojo::PendingRemote<network::mojom::DevToolsObserver> devtools_observer, |
Daniel Rubery | 6420d7430 | 2024-11-19 01:42:40 | [diff] [blame] | 84 | mojo::PendingRemote<network::mojom::DeviceBoundSessionAccessObserver> |
| 85 | device_bound_session_observer, |
Takashi Toyoshima | 2e8d6101 | 2021-06-07 10:31:27 | [diff] [blame] | 86 | network::mojom::URLResponseHeadPtr cached_response_head = nullptr, |
Takashi Toyoshima | 5af383aa | 2019-07-22 15:24:22 | [diff] [blame] | 87 | std::vector<std::unique_ptr<NavigationLoaderInterceptor>> |
| 88 | initial_interceptors = {}); |
davidben | 6b77cd7 | 2014-10-29 21:13:45 | [diff] [blame] | 89 | |
Hiroki Nakagawa | 6c5f39bd | 2021-07-13 00:22:36 | [diff] [blame] | 90 | // 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 Gale | 770f3fc | 2024-04-27 00:39:58 | [diff] [blame] | 94 | // TODO(crbug.com/40188852): Update this comment for restoration from |
Hiroki Nakagawa | 6c5f39bd | 2021-07-13 00:22:36 | [diff] [blame] | 95 | // BackForwardCache when it also starts depending on the requirement. |
davidben | 6b77cd7 | 2014-10-29 21:13:45 | [diff] [blame] | 96 | static void SetFactoryForTesting(NavigationURLLoaderFactory* factory); |
| 97 | |
Peter Boström | 828b902 | 2021-09-21 02:28:43 | [diff] [blame] | 98 | NavigationURLLoader(const NavigationURLLoader&) = delete; |
| 99 | NavigationURLLoader& operator=(const NavigationURLLoader&) = delete; |
| 100 | |
davidben | 6b77cd7 | 2014-10-29 21:13:45 | [diff] [blame] | 101 | virtual ~NavigationURLLoader() {} |
| 102 | |
Hiroki Nakagawa | 6d377e4a | 2021-07-08 23:29:11 | [diff] [blame] | 103 | // Called right after the loader is constructed. |
| 104 | virtual void Start() = 0; |
| 105 | |
davidben | 6b77cd7 | 2014-10-29 21:13:45 | [diff] [blame] | 106 | // Called in response to OnRequestRedirected to continue processing the |
Tarun Bansal | bcd62c8 | 2022-01-18 17:27:38 | [diff] [blame] | 107 | // request. |
Takashi Toyoshima | eb2ba20c5 | 2020-04-27 16:34:58 | [diff] [blame] | 108 | virtual void FollowRedirect( |
Hiroshige Hayashizaki | 62ef608 | 2025-07-30 00:59:38 | [diff] [blame] | 109 | std::vector<std::string> removed_headers, |
| 110 | net::HttpRequestHeaders modified_headers, |
| 111 | net::HttpRequestHeaders modified_cors_exempt_headers) = 0; |
davidben | 6b77cd7 | 2014-10-29 21:13:45 | [diff] [blame] | 112 | |
Chris Thompson | 066eed2 | 2021-10-07 20:20:43 | [diff] [blame] | 113 | // 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 Acer | 7b99ac2 | 2024-07-23 14:57:28 | [diff] [blame] | 119 | // 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 Thompson | 066eed2 | 2021-10-07 20:20:43 | [diff] [blame] | 123 | |
sisidovski | c01b1a3 | 2023-10-12 06:42:24 | [diff] [blame] | 124 | static uint32_t GetURLLoaderOptions(bool is_outermost_main_frame); |
| 125 | |
davidben | 6b77cd7 | 2014-10-29 21:13:45 | [diff] [blame] | 126 | protected: |
| 127 | NavigationURLLoader() {} |
davidben | 6b77cd7 | 2014-10-29 21:13:45 | [diff] [blame] | 128 | }; |
| 129 | |
| 130 | } // namespace content |
| 131 | |
| 132 | #endif // CONTENT_BROWSER_LOADER_NAVIGATION_URL_LOADER_H_ |