blob: ef3285a198e1b57c58cbef2a14a4498ed9923d6f [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_DELEGATE_H_
6#define CONTENT_BROWSER_LOADER_NAVIGATION_URL_LOADER_DELEGATE_H_
7
dcheng40ce7b382016-04-08 23:46:138#include <memory>
Arthur Sonzognic686e8f2024-01-11 08:36:379#include <optional>
dcheng40ce7b382016-04-08 23:46:1310
davidben6b77cd72014-10-29 21:13:4511#include "content/common/content_export.h"
Kenichi Ishibashif3f80522021-07-16 02:37:0712#include "mojo/public/cpp/bindings/pending_receiver.h"
13#include "services/network/public/mojom/early_hints.mojom-forward.h"
Ken Rockot54311e62018-02-10 19:01:5214#include "services/network/public/mojom/url_loader.mojom.h"
Kenichi Ishibashif3f80522021-07-16 02:37:0715#include "services/network/public/mojom/url_loader_factory.mojom.h"
Lucas Furukawa Gadanid661c0d2019-12-02 19:58:1616#include "services/network/public/mojom/url_response_head.mojom.h"
Yeunjoo Choi3df791a2021-02-17 07:07:2517#include "third_party/blink/public/common/navigation/navigation_policy.h"
Kenichi Ishibashif3f80522021-07-16 02:37:0718#include "url/origin.h"
davidben6b77cd72014-10-29 21:13:4519
20namespace net {
Brianna Goldsteind22b0642022-10-11 16:30:5021class NetworkAnonymizationKey;
davidben6b77cd72014-10-29 21:13:4522struct RedirectInfo;
23}
24
John Abd-El-Malek46248032018-01-17 19:11:2325namespace network {
Johannes Henkel6a43fef2018-05-17 18:41:5226struct URLLoaderCompletionStatus;
John Abd-El-Malek46248032018-01-17 19:11:2327}
28
davidben6b77cd72014-10-29 21:13:4529namespace content {
30
Kenichi Ishibashi7eb8cf62021-04-07 12:35:0531class NavigationEarlyHintsManager;
Kenichi Ishibashi1f67a2d2021-09-02 01:36:4832struct NavigationEarlyHintsManagerParams;
yzshen44341372016-11-30 21:44:1333struct GlobalRequestID;
Kinuko Yasuda250577c2017-10-29 02:51:2434struct SubresourceLoaderParams;
davidben6b77cd72014-10-29 21:13:4535
arthursonzognif34adf092018-04-24 17:06:1336// The delegate interface to NavigationURLLoader.
davidben6b77cd72014-10-29 21:13:4537class CONTENT_EXPORT NavigationURLLoaderDelegate {
38 public:
Kenichi Ishibashicf248fb2021-04-07 22:29:3539 // Conveys information related to Early Hints responses.
40 struct CONTENT_EXPORT EarlyHints {
41 EarlyHints();
42 ~EarlyHints();
43
44 EarlyHints(EarlyHints&& other);
45 EarlyHints& operator=(EarlyHints&& other);
46
47 EarlyHints(const EarlyHints& other) = delete;
48 EarlyHints& operator=(const EarlyHints& other) = delete;
49
Kenichi Ishibashi784dd402021-10-15 00:19:2450 // True when at least one preload or preconnect Link header was received
51 // during a main frame navigation.
52 bool was_resource_hints_received = false;
Kenichi Ishibashicf248fb2021-04-07 22:29:3553 // Non-null when at least one preload is actually requested.
54 std::unique_ptr<NavigationEarlyHintsManager> manager;
55 };
56
Peter Boström9b036532021-10-28 23:37:2857 NavigationURLLoaderDelegate(const NavigationURLLoaderDelegate&) = delete;
58 NavigationURLLoaderDelegate& operator=(const NavigationURLLoaderDelegate&) =
59 delete;
60
davidben6b77cd72014-10-29 21:13:4561 // Called when the request is redirected. Call FollowRedirect to continue
62 // processing the request.
Matt Menke7f615a12020-12-11 17:06:4463 //
Brianna Goldsteind22b0642022-10-11 16:30:5064 // |network_anonymization_key| is the NetworkAnonymizationKey associated with
65 // the request that was redirected, not the one that will be used if the
66 // redirect is followed.
davidben6b77cd72014-10-29 21:13:4567 virtual void OnRequestRedirected(
68 const net::RedirectInfo& redirect_info,
Brianna Goldsteind22b0642022-10-11 16:30:5069 const net::NetworkAnonymizationKey& network_anonymization_key,
Lucas Furukawa Gadanid661c0d2019-12-02 19:58:1670 network::mojom::URLResponseHeadPtr response) = 0;
davidben6b77cd72014-10-29 21:13:4571
72 // Called when the request receives its response. No further calls will be
arthursonzognif34adf092018-04-24 17:06:1373 // made to the delegate. The response body can be retrieved by implementing an
74 // URLLoaderClient and binding the |url_loader_client_endpoints|.
75 // |navigation_data| is passed to the NavigationHandle.
arthursonzogni3a4ca9f2017-12-07 17:58:3476 // |subresource_loader_params| is used in the network service only for passing
77 // necessary info to create a custom subresource loader in the renderer
Adrienne Walker144026562021-11-19 23:13:0978 // process if the navigated context is controlled by a request interceptor.
Charlie Harrison650e11422018-12-04 00:37:2679 //
80 // |is_download| is true if the request must be downloaded, if it isn't
81 // disallowed.
82 //
Matt Menke7f615a12020-12-11 17:06:4483 // Invoking this method will delete the URLLoader, so it needs to take all
84 // arguments by value.
davidben6b77cd72014-10-29 21:13:4585 virtual void OnResponseStarted(
John Abd-El-Malekb165dc52018-01-18 17:12:1886 network::mojom::URLLoaderClientEndpointsPtr url_loader_client_endpoints,
Lucas Furukawa Gadanid661c0d2019-12-02 19:58:1687 network::mojom::URLResponseHeadPtr response_head,
Minggang Wang47a78222019-06-28 17:05:4688 mojo::ScopedDataPipeConsumerHandle response_body,
Matt Menke7f615a12020-12-11 17:06:4489 GlobalRequestID request_id,
yzshen44341372016-11-30 21:44:1390 bool is_download,
Brianna Goldsteind22b0642022-10-11 16:30:5091 net::NetworkAnonymizationKey network_anonymization_key,
Hiroshige Hayashizaki9e0f2862024-02-09 16:54:0092 SubresourceLoaderParams subresource_loader_params,
Kenichi Ishibashicf248fb2021-04-07 22:29:3593 EarlyHints early_hints) = 0;
davidben6b77cd72014-10-29 21:13:4594
Johannes Henkel6a43fef2018-05-17 18:41:5295 // Called if the request fails before receving a response. Specific
96 // fields which are used: |status.error_code| holds the error code
97 // for the failure; |status.extended_error_code| holds details if
98 // available; |status.exists_in_cache| indicates a stale cache
99 // entry; |status.ssl_info| is available when |status.error_code| is
100 // a certificate error.
Carlos IL81133382017-12-06 17:18:45101 virtual void OnRequestFailed(
Johannes Henkel6a43fef2018-05-17 18:41:52102 const network::URLLoaderCompletionStatus& status) = 0;
davidben6b77cd72014-10-29 21:13:45103
Kenichi Ishibashi1f67a2d2021-09-02 01:36:48104 // Creates parameters to construct NavigationEarlyHintsManager. Returns
Arthur Sonzognic686e8f2024-01-11 08:36:37105 // std::nullopt when this delegate cannot create parameters.
106 virtual std::optional<NavigationEarlyHintsManagerParams>
Kenichi Ishibashi1f67a2d2021-09-02 01:36:48107 CreateNavigationEarlyHintsManagerParams(
Kenichi Ishibashif3f80522021-07-16 02:37:07108 const network::mojom::EarlyHints& early_hints) = 0;
109
Hiroshige Hayashizaki83cd1752025-07-31 17:46:25110 // Only for testing purpose (https://crbug.com/434182226).
111 // In non-test cases, use `OnRequestRedirected()` instead, and this method
112 // must do nothing and return `false`.
113 //
114 // Called when `NavigationURLLoaderImpl::OnReceiveRedirect()` is called.
115 // When the return value is `true` (which is only allowed in tests),
116 // `head->parsed_headers` is cleared to enforce and test the async
117 // `ParseHeaders()` path.
118 virtual bool ShouldClearParsedHeadersOnTestReceiveRedirect() = 0;
119
davidben6b77cd72014-10-29 21:13:45120 protected:
121 NavigationURLLoaderDelegate() {}
122 virtual ~NavigationURLLoaderDelegate() {}
davidben6b77cd72014-10-29 21:13:45123};
124
125} // namespace content
126
127#endif // CONTENT_BROWSER_LOADER_NAVIGATION_URL_LOADER_DELEGATE_H_