[email protected] | 9045b882 | 2012-01-13 20:35:35 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [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 NET_BASE_NETWORK_DELEGATE_H_ |
| 6 | #define NET_BASE_NETWORK_DELEGATE_H_ |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 7 | |
sclittle | ce72c48 | 2015-08-24 20:20:59 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
Douglas Creager | 7b07ea4 | 2018-02-27 21:08:08 | [diff] [blame] | 10 | #include <set> |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 11 | #include <string> |
| 12 | |
[email protected] | c2911d7 | 2011-10-03 22:16:36 | [diff] [blame] | 13 | #include "base/callback.h" |
[email protected] | 4b35521 | 2013-06-11 10:35:19 | [diff] [blame] | 14 | #include "base/strings/string16.h" |
gab | 47aa7da | 2017-06-02 16:09:43 | [diff] [blame] | 15 | #include "base/threading/thread_checker.h" |
[email protected] | c2911d7 | 2011-10-03 22:16:36 | [diff] [blame] | 16 | #include "net/base/auth.h" |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 17 | #include "net/base/completion_once_callback.h" |
bnc | 81c46c1f | 2016-10-04 16:25:59 | [diff] [blame] | 18 | #include "net/base/net_export.h" |
[email protected] | 8da4b181 | 2012-07-25 13:54:38 | [diff] [blame] | 19 | #include "net/cookies/canonical_cookie.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 20 | #include "net/proxy_resolution/proxy_retry_info.h" |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 21 | |
[email protected] | 4c76d7c | 2011-04-15 19:14:12 | [diff] [blame] | 22 | class GURL; |
| 23 | |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 24 | namespace base { |
| 25 | class FilePath; |
| 26 | } |
| 27 | |
juliatuttle | fcf4720 | 2017-05-23 15:53:02 | [diff] [blame] | 28 | namespace url { |
| 29 | class Origin; |
| 30 | } |
| 31 | |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 32 | namespace net { |
| 33 | |
| 34 | // NOTE: Layering violations! |
| 35 | // We decided to accept these violations (depending |
| 36 | // on other net/ submodules from net/base/), because otherwise NetworkDelegate |
| 37 | // would have to be broken up into too many smaller interfaces targeted to each |
| 38 | // submodule. Also, since the lower levels in net/ may callback into higher |
| 39 | // levels, we may encounter dangerous casting issues. |
| 40 | // |
| 41 | // NOTE: It is not okay to add any compile-time dependencies on symbols outside |
| 42 | // of net/base here, because we have a net_base library. Forward declarations |
| 43 | // are ok. |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 44 | class CookieOptions; |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 45 | class HttpRequestHeaders; |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 46 | class HttpResponseHeaders; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 47 | class ProxyInfo; |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 48 | class URLRequest; |
| 49 | |
gab | 47aa7da | 2017-06-02 16:09:43 | [diff] [blame] | 50 | class NET_EXPORT NetworkDelegate { |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 51 | public: |
[email protected] | c2911d7 | 2011-10-03 22:16:36 | [diff] [blame] | 52 | // AuthRequiredResponse indicates how a NetworkDelegate handles an |
| 53 | // OnAuthRequired call. It's placed in this file to prevent url_request.h |
| 54 | // from having to include network_delegate.h. |
| 55 | enum AuthRequiredResponse { |
| 56 | AUTH_REQUIRED_RESPONSE_NO_ACTION, |
| 57 | AUTH_REQUIRED_RESPONSE_SET_AUTH, |
| 58 | AUTH_REQUIRED_RESPONSE_CANCEL_AUTH, |
| 59 | AUTH_REQUIRED_RESPONSE_IO_PENDING, |
| 60 | }; |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 61 | using AuthCallback = base::OnceCallback<void(AuthRequiredResponse)>; |
[email protected] | c2911d7 | 2011-10-03 22:16:36 | [diff] [blame] | 62 | |
gab | 47aa7da | 2017-06-02 16:09:43 | [diff] [blame] | 63 | virtual ~NetworkDelegate(); |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 64 | |
| 65 | // Notification interface called by the network stack. Note that these |
| 66 | // functions mostly forward to the private virtuals. They also add some sanity |
[email protected] | 4875ba1 | 2011-03-30 22:31:51 | [diff] [blame] | 67 | // checking on parameters. See the corresponding virtuals for explanations of |
| 68 | // the methods and their arguments. |
| 69 | int NotifyBeforeURLRequest(URLRequest* request, |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 70 | CompletionOnceCallback callback, |
[email protected] | 4c76d7c | 2011-04-15 19:14:12 | [diff] [blame] | 71 | GURL* new_url); |
ryansturm | 2343cb6 | 2016-06-15 01:09:00 | [diff] [blame] | 72 | int NotifyBeforeStartTransaction(URLRequest* request, |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 73 | CompletionOnceCallback callback, |
ryansturm | 2343cb6 | 2016-06-15 01:09:00 | [diff] [blame] | 74 | HttpRequestHeaders* headers); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 75 | void NotifyBeforeSendHeaders(URLRequest* request, |
| 76 | const ProxyInfo& proxy_info, |
| 77 | const ProxyRetryInfoMap& proxy_retry_info, |
| 78 | HttpRequestHeaders* headers); |
ryansturm | 2343cb6 | 2016-06-15 01:09:00 | [diff] [blame] | 79 | void NotifyStartTransaction(URLRequest* request, |
| 80 | const HttpRequestHeaders& headers); |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 81 | int NotifyHeadersReceived( |
| 82 | URLRequest* request, |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 83 | CompletionOnceCallback callback, |
[email protected] | 507af8f | 2012-10-20 00:42:32 | [diff] [blame] | 84 | const HttpResponseHeaders* original_response_headers, |
[email protected] | 5f71413 | 2014-03-26 10:41:16 | [diff] [blame] | 85 | scoped_refptr<HttpResponseHeaders>* override_response_headers, |
| 86 | GURL* allowed_unsafe_redirect_url); |
[email protected] | 31b2e5f | 2011-04-20 16:58:32 | [diff] [blame] | 87 | void NotifyBeforeRedirect(URLRequest* request, |
| 88 | const GURL& new_location); |
maksim.sisov | 0f4aa14 | 2016-09-05 05:55:28 | [diff] [blame] | 89 | void NotifyResponseStarted(URLRequest* request, int net_error); |
sclittle | a133de0 | 2015-11-10 23:54:21 | [diff] [blame] | 90 | void NotifyNetworkBytesReceived(URLRequest* request, int64_t bytes_received); |
| 91 | void NotifyNetworkBytesSent(URLRequest* request, int64_t bytes_sent); |
maksim.sisov | 0f4aa14 | 2016-09-05 05:55:28 | [diff] [blame] | 92 | void NotifyCompleted(URLRequest* request, bool started, int net_error); |
[email protected] | 4875ba1 | 2011-03-30 22:31:51 | [diff] [blame] | 93 | void NotifyURLRequestDestroyed(URLRequest* request); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 94 | void NotifyPACScriptError(int line_number, const base::string16& error); |
[email protected] | c2911d7 | 2011-10-03 22:16:36 | [diff] [blame] | 95 | AuthRequiredResponse NotifyAuthRequired(URLRequest* request, |
| 96 | const AuthChallengeInfo& auth_info, |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 97 | AuthCallback callback, |
[email protected] | c2911d7 | 2011-10-03 22:16:36 | [diff] [blame] | 98 | AuthCredentials* credentials); |
Clark DuVall | e873764 | 2018-08-31 17:26:34 | [diff] [blame] | 99 | bool CanGetCookies(const URLRequest& request, |
| 100 | const CookieList& cookie_list, |
| 101 | bool allowed_from_caller); |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 102 | bool CanSetCookie(const URLRequest& request, |
Victor Costan | 70f8551 | 2017-11-20 16:14:46 | [diff] [blame] | 103 | const net::CanonicalCookie& cookie, |
Clark DuVall | e873764 | 2018-08-31 17:26:34 | [diff] [blame] | 104 | CookieOptions* options, |
| 105 | bool allowed_from_caller); |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 106 | bool CanAccessFile(const URLRequest& request, |
satorux | ddac044 | 2017-05-29 06:06:18 | [diff] [blame] | 107 | const base::FilePath& original_path, |
| 108 | const base::FilePath& absolute_path) const; |
Matt Menke | 7ad78edc | 2018-11-21 19:22:57 | [diff] [blame] | 109 | bool ForcePrivacyMode(const GURL& url, const GURL& site_for_cookies) const; |
[email protected] | 82a3767 | 2011-05-03 12:02:41 | [diff] [blame] | 110 | |
jochen | 0e3b3a6 | 2014-09-16 18:31:23 | [diff] [blame] | 111 | bool CancelURLRequestWithPolicyViolatingReferrerHeader( |
| 112 | const URLRequest& request, |
| 113 | const GURL& target_url, |
| 114 | const GURL& referrer_url) const; |
| 115 | |
juliatuttle | fcf4720 | 2017-05-23 15:53:02 | [diff] [blame] | 116 | bool CanQueueReportingReport(const url::Origin& origin) const; |
Douglas Creager | 7b07ea4 | 2018-02-27 21:08:08 | [diff] [blame] | 117 | void CanSendReportingReports( |
| 118 | std::set<url::Origin> origins, |
| 119 | base::OnceCallback<void(std::set<url::Origin>)> result_callback) const; |
juliatuttle | fcf4720 | 2017-05-23 15:53:02 | [diff] [blame] | 120 | bool CanSetReportingClient(const url::Origin& origin, |
| 121 | const GURL& endpoint) const; |
| 122 | bool CanUseReportingClient(const url::Origin& origin, |
| 123 | const GURL& endpoint) const; |
| 124 | |
gab | 47aa7da | 2017-06-02 16:09:43 | [diff] [blame] | 125 | protected: |
| 126 | THREAD_CHECKER(thread_checker_); |
| 127 | |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 128 | private: |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 129 | // This is the interface for subclasses of NetworkDelegate to implement. These |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 130 | // member functions will be called by the respective public notification |
| 131 | // member function, which will perform basic sanity checking. |
mgersh | 1571517 | 2016-11-16 16:03:25 | [diff] [blame] | 132 | // |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 133 | // Note that these member functions refer to URLRequests which may be canceled |
| 134 | // or destroyed at any time. Implementations which return ERR_IO_PENDING must |
| 135 | // also implement OnURLRequestDestroyed and OnCompleted to handle cancelation. |
| 136 | // See below for details. |
| 137 | // |
mgersh | 1571517 | 2016-11-16 16:03:25 | [diff] [blame] | 138 | // (NetworkDelegateImpl has default implementations of these member functions. |
| 139 | // NetworkDelegate implementations should consider subclassing |
| 140 | // NetworkDelegateImpl.) |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 141 | |
[email protected] | 4c76d7c | 2011-04-15 19:14:12 | [diff] [blame] | 142 | // Called before a request is sent. Allows the delegate to rewrite the URL |
[email protected] | f878230e | 2014-04-03 15:36:14 | [diff] [blame] | 143 | // being fetched by modifying |new_url|. If set, the URL must be valid. The |
| 144 | // reference fragment from the original URL is not automatically appended to |
| 145 | // |new_url|; callers are responsible for copying the reference fragment if |
| 146 | // desired. |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 147 | // |
| 148 | // Returns OK to continue with the request, ERR_IO_PENDING if the result is |
| 149 | // not ready yet, and any other status code to cancel the request. If |
| 150 | // returning ERR_IO_PENDING, call |callback| when the result is ready. Note, |
| 151 | // however, that a pending operation may be cancelled by |
| 152 | // OnURLRequestDestroyed. Once cancelled, |request| and |new_url| become |
| 153 | // invalid and |callback| may not be called. |
[email protected] | c6c6e565 | 2013-10-29 02:40:30 | [diff] [blame] | 154 | // |
| 155 | // The default implementation returns OK (continue with request). |
[email protected] | 4875ba1 | 2011-03-30 22:31:51 | [diff] [blame] | 156 | virtual int OnBeforeURLRequest(URLRequest* request, |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 157 | CompletionOnceCallback callback, |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 158 | GURL* new_url) = 0; |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 159 | |
ryansturm | 2343cb6 | 2016-06-15 01:09:00 | [diff] [blame] | 160 | // Called right before the network transaction starts. Allows the delegate to |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 161 | // read/write |headers| before they get sent out. |
| 162 | // |
| 163 | // Returns OK to continue with the request, ERR_IO_PENDING if the result is |
| 164 | // not ready yet, and any other status code to cancel the request. If |
| 165 | // returning ERR_IO_PENDING, call |callback| when the result is ready. Note, |
| 166 | // however, that a pending operation may be cancelled by OnURLRequestDestroyed |
| 167 | // or OnCompleted. Once cancelled, |request| and |headers| become invalid and |
| 168 | // |callback| may not be called. |
| 169 | // |
| 170 | // The default implementation returns OK (continue with request) without |
| 171 | // modifying |headers|. |
ryansturm | 2343cb6 | 2016-06-15 01:09:00 | [diff] [blame] | 172 | virtual int OnBeforeStartTransaction(URLRequest* request, |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 173 | CompletionOnceCallback callback, |
ryansturm | 2343cb6 | 2016-06-15 01:09:00 | [diff] [blame] | 174 | HttpRequestHeaders* headers) = 0; |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 175 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 176 | // Called after a connection is established , and just before headers are sent |
| 177 | // to the destination server (i.e., not called for HTTP CONNECT requests). For |
| 178 | // non-tunneled requests using HTTP proxies, |headers| will include any |
| 179 | // proxy-specific headers as well. Allows the delegate to read/write |headers| |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 180 | // before they get sent out. |headers| is valid only for the duration of the |
| 181 | // call. |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 182 | virtual void OnBeforeSendHeaders(URLRequest* request, |
| 183 | const ProxyInfo& proxy_info, |
| 184 | const ProxyRetryInfoMap& proxy_retry_info, |
| 185 | HttpRequestHeaders* headers) = 0; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 186 | |
[email protected] | 5796dc94 | 2011-07-14 19:26:10 | [diff] [blame] | 187 | // Called right before the HTTP request(s) are being sent to the network. |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 188 | // |headers| is only valid only for the duration of the call. |
ryansturm | 2343cb6 | 2016-06-15 01:09:00 | [diff] [blame] | 189 | virtual void OnStartTransaction(URLRequest* request, |
| 190 | const HttpRequestHeaders& headers) = 0; |
[email protected] | 82b4230 | 2011-04-20 16:28:16 | [diff] [blame] | 191 | |
[email protected] | c6c6e565 | 2013-10-29 02:40:30 | [diff] [blame] | 192 | // Called for HTTP requests when the headers have been received. |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 193 | // |original_response_headers| contains the headers as received over the |
| 194 | // network, these must not be modified. |override_response_headers| can be set |
| 195 | // to new values, that should be considered as overriding |
| 196 | // |original_response_headers|. |
[email protected] | f878230e | 2014-04-03 15:36:14 | [diff] [blame] | 197 | // If the response is a redirect, and the Location response header value is |
| 198 | // identical to |allowed_unsafe_redirect_url|, then the redirect is never |
| 199 | // blocked and the reference fragment is not copied from the original URL |
| 200 | // to the redirection target. |
| 201 | // |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 202 | // Returns OK to continue with the request, ERR_IO_PENDING if the result is |
| 203 | // not ready yet, and any other status code to cancel the request. If |
| 204 | // returning ERR_IO_PENDING, call |callback| when the result is ready. Note, |
| 205 | // however, that a pending operation may be cancelled by |
| 206 | // OnURLRequestDestroyed. Once cancelled, |request|, |
| 207 | // |original_response_headers|, |override_response_headers|, and |
| 208 | // |allowed_unsafe_redirect_url| become invalid and |callback| may not be |
| 209 | // called. |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 210 | virtual int OnHeadersReceived( |
| 211 | URLRequest* request, |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 212 | CompletionOnceCallback callback, |
[email protected] | 507af8f | 2012-10-20 00:42:32 | [diff] [blame] | 213 | const HttpResponseHeaders* original_response_headers, |
[email protected] | 5f71413 | 2014-03-26 10:41:16 | [diff] [blame] | 214 | scoped_refptr<HttpResponseHeaders>* override_response_headers, |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 215 | GURL* allowed_unsafe_redirect_url) = 0; |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 216 | |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 217 | // Called right after a redirect response code was received. |new_location| is |
| 218 | // only valid for the duration of the call. |
[email protected] | 31b2e5f | 2011-04-20 16:58:32 | [diff] [blame] | 219 | virtual void OnBeforeRedirect(URLRequest* request, |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 220 | const GURL& new_location) = 0; |
[email protected] | 31b2e5f | 2011-04-20 16:58:32 | [diff] [blame] | 221 | |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 222 | // This corresponds to URLRequestDelegate::OnResponseStarted. |
David Benjamin | 9df92afb | 2018-06-12 23:25:24 | [diff] [blame] | 223 | virtual void OnResponseStarted(URLRequest* request, int net_error) = 0; |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 224 | |
sclittle | ce72c48 | 2015-08-24 20:20:59 | [diff] [blame] | 225 | // Called when bytes are received from the network, such as after receiving |
| 226 | // headers or reading raw response bytes. This includes localhost requests. |
| 227 | // |bytes_received| is the number of bytes measured at the application layer |
| 228 | // that have been received over the network for this request since the last |
| 229 | // time OnNetworkBytesReceived was called. |bytes_received| will always be |
| 230 | // greater than 0. |
| 231 | // Currently, this is only implemented for HTTP transactions, and |
| 232 | // |bytes_received| does not include TLS overhead or TCP retransmits. |
sclittle | a133de0 | 2015-11-10 23:54:21 | [diff] [blame] | 233 | virtual void OnNetworkBytesReceived(URLRequest* request, |
sclittle | ce72c48 | 2015-08-24 20:20:59 | [diff] [blame] | 234 | int64_t bytes_received) = 0; |
[email protected] | 8523ba5 | 2011-05-22 19:00:58 | [diff] [blame] | 235 | |
sclittle | 28d558b | 2015-09-28 21:40:52 | [diff] [blame] | 236 | // Called when bytes are sent over the network, such as when sending request |
| 237 | // headers or uploading request body bytes. This includes localhost requests. |
| 238 | // |bytes_sent| is the number of bytes measured at the application layer that |
| 239 | // have been sent over the network for this request since the last time |
| 240 | // OnNetworkBytesSent was called. |bytes_sent| will always be greater than 0. |
| 241 | // Currently, this is only implemented for HTTP transactions, and |bytes_sent| |
| 242 | // does not include TLS overhead or TCP retransmits. |
sclittle | a133de0 | 2015-11-10 23:54:21 | [diff] [blame] | 243 | virtual void OnNetworkBytesSent(URLRequest* request, int64_t bytes_sent) = 0; |
sclittle | 28d558b | 2015-09-28 21:40:52 | [diff] [blame] | 244 | |
[email protected] | 4894438 | 2011-04-23 13:28:16 | [diff] [blame] | 245 | // Indicates that the URL request has been completed or failed. |
[email protected] | 9045b882 | 2012-01-13 20:35:35 | [diff] [blame] | 246 | // |started| indicates whether the request has been started. If false, |
| 247 | // some information like the socket address is not available. |
David Benjamin | 9df92afb | 2018-06-12 23:25:24 | [diff] [blame] | 248 | virtual void OnCompleted(URLRequest* request, |
| 249 | bool started, |
| 250 | int net_error) = 0; |
[email protected] | 4b50cb5 | 2011-03-10 00:29:37 | [diff] [blame] | 251 | |
[email protected] | 4875ba1 | 2011-03-30 22:31:51 | [diff] [blame] | 252 | // Called when an URLRequest is being destroyed. Note that the request is |
| 253 | // being deleted, so it's not safe to call any methods that may result in |
| 254 | // a virtual method call. |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 255 | virtual void OnURLRequestDestroyed(URLRequest* request) = 0; |
[email protected] | 4875ba1 | 2011-03-30 22:31:51 | [diff] [blame] | 256 | |
[email protected] | 82a3767 | 2011-05-03 12:02:41 | [diff] [blame] | 257 | // Corresponds to ProxyResolverJSBindings::OnError. |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 258 | virtual void OnPACScriptError(int line_number, |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 259 | const base::string16& error) = 0; |
[email protected] | 7efc582d | 2011-08-03 20:46:35 | [diff] [blame] | 260 | |
[email protected] | c2911d7 | 2011-10-03 22:16:36 | [diff] [blame] | 261 | // Called when a request receives an authentication challenge |
| 262 | // specified by |auth_info|, and is unable to respond using cached |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 263 | // credentials. |callback| and |credentials| must be non-NULL. |
[email protected] | c2911d7 | 2011-10-03 22:16:36 | [diff] [blame] | 264 | // |
| 265 | // The following return values are allowed: |
| 266 | // - AUTH_REQUIRED_RESPONSE_NO_ACTION: |auth_info| is observed, but |
| 267 | // no action is being taken on it. |
| 268 | // - AUTH_REQUIRED_RESPONSE_SET_AUTH: |credentials| is filled in with |
| 269 | // a username and password, which should be used in a response to |
| 270 | // |auth_info|. |
| 271 | // - AUTH_REQUIRED_RESPONSE_CANCEL_AUTH: The authentication challenge |
| 272 | // should not be attempted. |
| 273 | // - AUTH_REQUIRED_RESPONSE_IO_PENDING: The action will be decided |
| 274 | // asynchronously. |callback| will be invoked when the decision is made, |
| 275 | // and one of the other AuthRequiredResponse values will be passed in with |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 276 | // the same semantics as described above. Note, however, that a pending |
| 277 | // operation may be cancelled by OnURLRequestDestroyed. Once cancelled, |
| 278 | // |request|, |auth_info|, and |credentials| become invalid and |callback| |
| 279 | // may not be called. |
[email protected] | c2911d7 | 2011-10-03 22:16:36 | [diff] [blame] | 280 | virtual AuthRequiredResponse OnAuthRequired( |
| 281 | URLRequest* request, |
| 282 | const AuthChallengeInfo& auth_info, |
David Benjamin | d1f287bf | 2018-06-12 01:57:20 | [diff] [blame] | 283 | AuthCallback callback, |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 284 | AuthCredentials* credentials) = 0; |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 285 | |
| 286 | // Called when reading cookies to allow the network delegate to block access |
| 287 | // to the cookie. This method will never be invoked when |
| 288 | // LOAD_DO_NOT_SEND_COOKIES is specified. |
Clark DuVall | e873764 | 2018-08-31 17:26:34 | [diff] [blame] | 289 | // The |allowed_from_caller| param is used to pass whether this operation is |
| 290 | // allowed from any higher level delegates (for example, in a |
| 291 | // LayeredNetworkDelegate). Any custom logic should be ANDed with this bool. |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 292 | virtual bool OnCanGetCookies(const URLRequest& request, |
Clark DuVall | e873764 | 2018-08-31 17:26:34 | [diff] [blame] | 293 | const CookieList& cookie_list, |
| 294 | bool allowed_from_caller) = 0; |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 295 | |
| 296 | // Called when a cookie is set to allow the network delegate to block access |
| 297 | // to the cookie. This method will never be invoked when |
| 298 | // LOAD_DO_NOT_SAVE_COOKIES is specified. |
Clark DuVall | e873764 | 2018-08-31 17:26:34 | [diff] [blame] | 299 | // The |allowed_from_caller| param is used to pass whether this operation is |
| 300 | // allowed from any higher level delegates (for example, in a |
| 301 | // LayeredNetworkDelegate). Any custom logic should be ANDed with this bool. |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 302 | virtual bool OnCanSetCookie(const URLRequest& request, |
Clark DuVall | e873764 | 2018-08-31 17:26:34 | [diff] [blame] | 303 | const CanonicalCookie& cookie, |
| 304 | CookieOptions* options, |
| 305 | bool allowed_from_caller) = 0; |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 306 | |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 307 | // Called when a file access is attempted to allow the network delegate to |
satorux | ddac044 | 2017-05-29 06:06:18 | [diff] [blame] | 308 | // allow or block access to the given file path, provided in the original |
| 309 | // and absolute forms (i.e. symbolic link is resolved). It's up to |
| 310 | // subclasses of NetworkDelegate to decide which path to use for |
| 311 | // checking. Returns true if access is allowed. |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 312 | virtual bool OnCanAccessFile(const URLRequest& request, |
satorux | ddac044 | 2017-05-29 06:06:18 | [diff] [blame] | 313 | const base::FilePath& original_path, |
| 314 | const base::FilePath& absolute_path) const = 0; |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 315 | |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 316 | // Returns true if the given |url| has to be requested over connection that |
| 317 | // is not tracked by the server. Usually is false, unless user privacy |
| 318 | // settings block cookies from being get or set. |
Matt Menke | 7ad78edc | 2018-11-21 19:22:57 | [diff] [blame] | 319 | virtual bool OnForcePrivacyMode(const GURL& url, |
| 320 | const GURL& site_for_cookies) const = 0; |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 321 | |
jochen | 0e3b3a6 | 2014-09-16 18:31:23 | [diff] [blame] | 322 | // Called when the |referrer_url| for requesting |target_url| during handling |
| 323 | // of the |request| is does not comply with the referrer policy (e.g. a |
| 324 | // secure referrer for an insecure initial target). |
| 325 | // Returns true if the request should be cancelled. Otherwise, the referrer |
| 326 | // header is stripped from the request. |
| 327 | virtual bool OnCancelURLRequestWithPolicyViolatingReferrerHeader( |
| 328 | const URLRequest& request, |
| 329 | const GURL& target_url, |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 330 | const GURL& referrer_url) const = 0; |
juliatuttle | fcf4720 | 2017-05-23 15:53:02 | [diff] [blame] | 331 | |
| 332 | virtual bool OnCanQueueReportingReport(const url::Origin& origin) const = 0; |
| 333 | |
Douglas Creager | 7b07ea4 | 2018-02-27 21:08:08 | [diff] [blame] | 334 | virtual void OnCanSendReportingReports( |
| 335 | std::set<url::Origin> origins, |
| 336 | base::OnceCallback<void(std::set<url::Origin>)> result_callback) |
| 337 | const = 0; |
juliatuttle | fcf4720 | 2017-05-23 15:53:02 | [diff] [blame] | 338 | |
| 339 | virtual bool OnCanSetReportingClient(const url::Origin& origin, |
| 340 | const GURL& endpoint) const = 0; |
| 341 | |
| 342 | virtual bool OnCanUseReportingClient(const url::Origin& origin, |
| 343 | const GURL& endpoint) const = 0; |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 344 | }; |
| 345 | |
| 346 | } // namespace net |
| 347 | |
| 348 | #endif // NET_BASE_NETWORK_DELEGATE_H_ |