[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 | |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 10 | #include <string> |
| 11 | |
[email protected] | c2911d7 | 2011-10-03 22:16:36 | [diff] [blame] | 12 | #include "base/callback.h" |
[email protected] | 4b35521 | 2013-06-11 10:35:19 | [diff] [blame] | 13 | #include "base/strings/string16.h" |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 14 | #include "base/threading/non_thread_safe.h" |
[email protected] | c2911d7 | 2011-10-03 22:16:36 | [diff] [blame] | 15 | #include "net/base/auth.h" |
[email protected] | 05cc4e7 | 2011-03-08 21:29:48 | [diff] [blame] | 16 | #include "net/base/completion_callback.h" |
[email protected] | 8da4b181 | 2012-07-25 13:54:38 | [diff] [blame] | 17 | #include "net/cookies/canonical_cookie.h" |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 18 | |
[email protected] | 4c76d7c | 2011-04-15 19:14:12 | [diff] [blame] | 19 | class GURL; |
| 20 | |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 21 | namespace base { |
| 22 | class FilePath; |
| 23 | } |
| 24 | |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 25 | namespace net { |
| 26 | |
| 27 | // NOTE: Layering violations! |
| 28 | // We decided to accept these violations (depending |
| 29 | // on other net/ submodules from net/base/), because otherwise NetworkDelegate |
| 30 | // would have to be broken up into too many smaller interfaces targeted to each |
| 31 | // submodule. Also, since the lower levels in net/ may callback into higher |
| 32 | // levels, we may encounter dangerous casting issues. |
| 33 | // |
| 34 | // NOTE: It is not okay to add any compile-time dependencies on symbols outside |
| 35 | // of net/base here, because we have a net_base library. Forward declarations |
| 36 | // are ok. |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 37 | class CookieOptions; |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 38 | class HttpRequestHeaders; |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 39 | class HttpResponseHeaders; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 40 | class ProxyInfo; |
[email protected] | f09f968 | 2014-08-10 01:21:39 | [diff] [blame] | 41 | class ProxyServer; |
[email protected] | 1273179 | 2014-08-14 11:45:54 | [diff] [blame] | 42 | class ProxyService; |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 43 | class URLRequest; |
| 44 | |
[email protected] | be363b2 | 2012-11-01 17:38:47 | [diff] [blame] | 45 | class NET_EXPORT NetworkDelegate : public base::NonThreadSafe { |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 46 | public: |
[email protected] | c2911d7 | 2011-10-03 22:16:36 | [diff] [blame] | 47 | // AuthRequiredResponse indicates how a NetworkDelegate handles an |
| 48 | // OnAuthRequired call. It's placed in this file to prevent url_request.h |
| 49 | // from having to include network_delegate.h. |
| 50 | enum AuthRequiredResponse { |
| 51 | AUTH_REQUIRED_RESPONSE_NO_ACTION, |
| 52 | AUTH_REQUIRED_RESPONSE_SET_AUTH, |
| 53 | AUTH_REQUIRED_RESPONSE_CANCEL_AUTH, |
| 54 | AUTH_REQUIRED_RESPONSE_IO_PENDING, |
| 55 | }; |
| 56 | typedef base::Callback<void(AuthRequiredResponse)> AuthCallback; |
| 57 | |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 58 | virtual ~NetworkDelegate() {} |
| 59 | |
| 60 | // Notification interface called by the network stack. Note that these |
| 61 | // functions mostly forward to the private virtuals. They also add some sanity |
[email protected] | 4875ba1 | 2011-03-30 22:31:51 | [diff] [blame] | 62 | // checking on parameters. See the corresponding virtuals for explanations of |
| 63 | // the methods and their arguments. |
| 64 | int NotifyBeforeURLRequest(URLRequest* request, |
[email protected] | 084262c | 2011-12-01 21:12:47 | [diff] [blame] | 65 | const CompletionCallback& callback, |
[email protected] | 4c76d7c | 2011-04-15 19:14:12 | [diff] [blame] | 66 | GURL* new_url); |
[email protected] | 1273179 | 2014-08-14 11:45:54 | [diff] [blame] | 67 | void NotifyResolveProxy(const GURL& url, |
| 68 | int load_flags, |
| 69 | const ProxyService& proxy_service, |
[email protected] | a702da7 | 2014-07-09 05:23:54 | [diff] [blame] | 70 | ProxyInfo* result); |
[email protected] | f09f968 | 2014-08-10 01:21:39 | [diff] [blame] | 71 | void NotifyProxyFallback(const ProxyServer& bad_proxy, |
[email protected] | d0483b19 | 2014-08-15 23:50:17 | [diff] [blame] | 72 | int net_error); |
[email protected] | 636eccd | 2011-06-28 12:28:01 | [diff] [blame] | 73 | int NotifyBeforeSendHeaders(URLRequest* request, |
[email protected] | 084262c | 2011-12-01 21:12:47 | [diff] [blame] | 74 | const CompletionCallback& callback, |
[email protected] | 4c76d7c | 2011-04-15 19:14:12 | [diff] [blame] | 75 | HttpRequestHeaders* headers); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 76 | void NotifyBeforeSendProxyHeaders(URLRequest* request, |
| 77 | const ProxyInfo& proxy_info, |
| 78 | HttpRequestHeaders* headers); |
[email protected] | 5796dc94 | 2011-07-14 19:26:10 | [diff] [blame] | 79 | void NotifySendHeaders(URLRequest* request, |
[email protected] | 783573b | 2011-05-13 11:05:15 | [diff] [blame] | 80 | const HttpRequestHeaders& headers); |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 81 | int NotifyHeadersReceived( |
| 82 | URLRequest* request, |
[email protected] | 084262c | 2011-12-01 21:12:47 | [diff] [blame] | 83 | const CompletionCallback& 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); |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 89 | void NotifyResponseStarted(URLRequest* request); |
sclittle | ce72c48 | 2015-08-24 20:20:59 | [diff] [blame] | 90 | void NotifyNetworkBytesReceived(const URLRequest& request, |
| 91 | int64_t bytes_received); |
sclittle | 28d558b | 2015-09-28 21:40:52 | [diff] [blame^] | 92 | void NotifyNetworkBytesSent(const URLRequest& request, int64_t bytes_sent); |
[email protected] | 9045b882 | 2012-01-13 20:35:35 | [diff] [blame] | 93 | void NotifyCompleted(URLRequest* request, bool started); |
[email protected] | 4875ba1 | 2011-03-30 22:31:51 | [diff] [blame] | 94 | void NotifyURLRequestDestroyed(URLRequest* request); |
davidben | a3ef438 | 2015-09-14 22:36:10 | [diff] [blame] | 95 | void NotifyURLRequestJobOrphaned(URLRequest* request); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 96 | void NotifyPACScriptError(int line_number, const base::string16& error); |
[email protected] | c2911d7 | 2011-10-03 22:16:36 | [diff] [blame] | 97 | AuthRequiredResponse NotifyAuthRequired(URLRequest* request, |
| 98 | const AuthChallengeInfo& auth_info, |
| 99 | const AuthCallback& callback, |
| 100 | AuthCredentials* credentials); |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 101 | bool CanGetCookies(const URLRequest& request, |
| 102 | const CookieList& cookie_list); |
| 103 | bool CanSetCookie(const URLRequest& request, |
| 104 | const std::string& cookie_line, |
| 105 | CookieOptions* options); |
| 106 | bool CanAccessFile(const URLRequest& request, |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 107 | const base::FilePath& path) const; |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 108 | bool CanEnablePrivacyMode(const GURL& url, |
| 109 | const GURL& first_party_for_cookies) const; |
[email protected] | 82a3767 | 2011-05-03 12:02:41 | [diff] [blame] | 110 | |
mkwst | 0513c9d | 2015-04-01 05:53:15 | [diff] [blame] | 111 | // TODO(mkwst): Remove this once we decide whether or not we wish to ship |
| 112 | // first-party cookies. https://crbug.com/459154 |
| 113 | bool FirstPartyOnlyCookieExperimentEnabled() const; |
| 114 | |
jochen | 0e3b3a6 | 2014-09-16 18:31:23 | [diff] [blame] | 115 | bool CancelURLRequestWithPolicyViolatingReferrerHeader( |
| 116 | const URLRequest& request, |
| 117 | const GURL& target_url, |
| 118 | const GURL& referrer_url) const; |
| 119 | |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 120 | private: |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 121 | // This is the interface for subclasses of NetworkDelegate to implement. These |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 122 | // member functions will be called by the respective public notification |
| 123 | // member function, which will perform basic sanity checking. |
| 124 | |
[email protected] | 4c76d7c | 2011-04-15 19:14:12 | [diff] [blame] | 125 | // Called before a request is sent. Allows the delegate to rewrite the URL |
[email protected] | f878230e | 2014-04-03 15:36:14 | [diff] [blame] | 126 | // being fetched by modifying |new_url|. If set, the URL must be valid. The |
| 127 | // reference fragment from the original URL is not automatically appended to |
| 128 | // |new_url|; callers are responsible for copying the reference fragment if |
| 129 | // desired. |
| 130 | // |callback| and |new_url| are valid only until OnURLRequestDestroyed is |
| 131 | // called for this request. Returns a net status code, generally either OK to |
| 132 | // continue with the request or ERR_IO_PENDING if the result is not ready yet. |
| 133 | // A status code other than OK and ERR_IO_PENDING will cancel the request and |
| 134 | // report the status code as the reason. |
[email protected] | c6c6e565 | 2013-10-29 02:40:30 | [diff] [blame] | 135 | // |
| 136 | // The default implementation returns OK (continue with request). |
[email protected] | 4875ba1 | 2011-03-30 22:31:51 | [diff] [blame] | 137 | virtual int OnBeforeURLRequest(URLRequest* request, |
[email protected] | 084262c | 2011-12-01 21:12:47 | [diff] [blame] | 138 | const CompletionCallback& callback, |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 139 | GURL* new_url) = 0; |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 140 | |
[email protected] | a702da7 | 2014-07-09 05:23:54 | [diff] [blame] | 141 | // Called as the proxy is being resolved for |url|. Allows the delegate to |
| 142 | // override the proxy resolution decision made by ProxyService. The delegate |
| 143 | // may override the decision by modifying the ProxyInfo |result|. |
| 144 | virtual void OnResolveProxy(const GURL& url, |
| 145 | int load_flags, |
[email protected] | 1273179 | 2014-08-14 11:45:54 | [diff] [blame] | 146 | const ProxyService& proxy_service, |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 147 | ProxyInfo* result) = 0; |
[email protected] | a702da7 | 2014-07-09 05:23:54 | [diff] [blame] | 148 | |
[email protected] | d0483b19 | 2014-08-15 23:50:17 | [diff] [blame] | 149 | // Called when use of |bad_proxy| fails due to |net_error|. |net_error| is |
| 150 | // the network error encountered, if any, and OK if the fallback was |
| 151 | // for a reason other than a network error (e.g. the proxy service was |
| 152 | // explicitly directed to skip a proxy). |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 153 | virtual void OnProxyFallback(const ProxyServer& bad_proxy, int net_error) = 0; |
[email protected] | f09f968 | 2014-08-10 01:21:39 | [diff] [blame] | 154 | |
[email protected] | 4875ba1 | 2011-03-30 22:31:51 | [diff] [blame] | 155 | // Called right before the HTTP headers are sent. Allows the delegate to |
[email protected] | 5aa2013 | 2011-04-27 23:11:34 | [diff] [blame] | 156 | // read/write |headers| before they get sent out. |callback| and |headers| are |
[email protected] | 9045b882 | 2012-01-13 20:35:35 | [diff] [blame] | 157 | // valid only until OnCompleted or OnURLRequestDestroyed is called for this |
| 158 | // request. |
[email protected] | c6c6e565 | 2013-10-29 02:40:30 | [diff] [blame] | 159 | // See OnBeforeURLRequest for return value description. Returns OK by default. |
[email protected] | 636eccd | 2011-06-28 12:28:01 | [diff] [blame] | 160 | virtual int OnBeforeSendHeaders(URLRequest* request, |
[email protected] | 084262c | 2011-12-01 21:12:47 | [diff] [blame] | 161 | const CompletionCallback& callback, |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 162 | HttpRequestHeaders* headers) = 0; |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 163 | |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 164 | // Called after a proxy connection. Allows the delegate to read/write |
| 165 | // |headers| before they get sent out. |headers| is valid only until |
| 166 | // OnCompleted or OnURLRequestDestroyed is called for this request. |
| 167 | virtual void OnBeforeSendProxyHeaders(URLRequest* request, |
| 168 | const ProxyInfo& proxy_info, |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 169 | HttpRequestHeaders* headers) = 0; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 170 | |
[email protected] | 5796dc94 | 2011-07-14 19:26:10 | [diff] [blame] | 171 | // Called right before the HTTP request(s) are being sent to the network. |
[email protected] | 9045b882 | 2012-01-13 20:35:35 | [diff] [blame] | 172 | // |headers| is only valid until OnCompleted or OnURLRequestDestroyed is |
| 173 | // called for this request. |
[email protected] | 5796dc94 | 2011-07-14 19:26:10 | [diff] [blame] | 174 | virtual void OnSendHeaders(URLRequest* request, |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 175 | const HttpRequestHeaders& headers) = 0; |
[email protected] | 82b4230 | 2011-04-20 16:28:16 | [diff] [blame] | 176 | |
[email protected] | c6c6e565 | 2013-10-29 02:40:30 | [diff] [blame] | 177 | // Called for HTTP requests when the headers have been received. |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 178 | // |original_response_headers| contains the headers as received over the |
| 179 | // network, these must not be modified. |override_response_headers| can be set |
| 180 | // to new values, that should be considered as overriding |
| 181 | // |original_response_headers|. |
[email protected] | f878230e | 2014-04-03 15:36:14 | [diff] [blame] | 182 | // If the response is a redirect, and the Location response header value is |
| 183 | // identical to |allowed_unsafe_redirect_url|, then the redirect is never |
| 184 | // blocked and the reference fragment is not copied from the original URL |
| 185 | // to the redirection target. |
| 186 | // |
[email protected] | 9045b882 | 2012-01-13 20:35:35 | [diff] [blame] | 187 | // |callback|, |original_response_headers|, and |override_response_headers| |
| 188 | // are only valid until OnURLRequestDestroyed is called for this request. |
[email protected] | c6c6e565 | 2013-10-29 02:40:30 | [diff] [blame] | 189 | // See OnBeforeURLRequest for return value description. Returns OK by default. |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 190 | virtual int OnHeadersReceived( |
| 191 | URLRequest* request, |
[email protected] | 084262c | 2011-12-01 21:12:47 | [diff] [blame] | 192 | const CompletionCallback& callback, |
[email protected] | 507af8f | 2012-10-20 00:42:32 | [diff] [blame] | 193 | const HttpResponseHeaders* original_response_headers, |
[email protected] | 5f71413 | 2014-03-26 10:41:16 | [diff] [blame] | 194 | scoped_refptr<HttpResponseHeaders>* override_response_headers, |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 195 | GURL* allowed_unsafe_redirect_url) = 0; |
[email protected] | ea8141e | 2011-10-05 13:12:51 | [diff] [blame] | 196 | |
[email protected] | 31b2e5f | 2011-04-20 16:58:32 | [diff] [blame] | 197 | // Called right after a redirect response code was received. |
[email protected] | 9045b882 | 2012-01-13 20:35:35 | [diff] [blame] | 198 | // |new_location| is only valid until OnURLRequestDestroyed is called for this |
| 199 | // request. |
[email protected] | 31b2e5f | 2011-04-20 16:58:32 | [diff] [blame] | 200 | virtual void OnBeforeRedirect(URLRequest* request, |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 201 | const GURL& new_location) = 0; |
[email protected] | 31b2e5f | 2011-04-20 16:58:32 | [diff] [blame] | 202 | |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 203 | // This corresponds to URLRequestDelegate::OnResponseStarted. |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 204 | virtual void OnResponseStarted(URLRequest* request) = 0; |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 205 | |
sclittle | ce72c48 | 2015-08-24 20:20:59 | [diff] [blame] | 206 | // Called when bytes are received from the network, such as after receiving |
| 207 | // headers or reading raw response bytes. This includes localhost requests. |
| 208 | // |bytes_received| is the number of bytes measured at the application layer |
| 209 | // that have been received over the network for this request since the last |
| 210 | // time OnNetworkBytesReceived was called. |bytes_received| will always be |
| 211 | // greater than 0. |
| 212 | // Currently, this is only implemented for HTTP transactions, and |
| 213 | // |bytes_received| does not include TLS overhead or TCP retransmits. |
| 214 | virtual void OnNetworkBytesReceived(const URLRequest& request, |
| 215 | int64_t bytes_received) = 0; |
[email protected] | 8523ba5 | 2011-05-22 19:00:58 | [diff] [blame] | 216 | |
sclittle | 28d558b | 2015-09-28 21:40:52 | [diff] [blame^] | 217 | // Called when bytes are sent over the network, such as when sending request |
| 218 | // headers or uploading request body bytes. This includes localhost requests. |
| 219 | // |bytes_sent| is the number of bytes measured at the application layer that |
| 220 | // have been sent over the network for this request since the last time |
| 221 | // OnNetworkBytesSent was called. |bytes_sent| will always be greater than 0. |
| 222 | // Currently, this is only implemented for HTTP transactions, and |bytes_sent| |
| 223 | // does not include TLS overhead or TCP retransmits. |
| 224 | virtual void OnNetworkBytesSent(const URLRequest& request, |
| 225 | int64_t bytes_sent) = 0; |
| 226 | |
[email protected] | 4894438 | 2011-04-23 13:28:16 | [diff] [blame] | 227 | // Indicates that the URL request has been completed or failed. |
[email protected] | 9045b882 | 2012-01-13 20:35:35 | [diff] [blame] | 228 | // |started| indicates whether the request has been started. If false, |
| 229 | // some information like the socket address is not available. |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 230 | virtual void OnCompleted(URLRequest* request, bool started) = 0; |
[email protected] | 4b50cb5 | 2011-03-10 00:29:37 | [diff] [blame] | 231 | |
[email protected] | 4875ba1 | 2011-03-30 22:31:51 | [diff] [blame] | 232 | // Called when an URLRequest is being destroyed. Note that the request is |
| 233 | // being deleted, so it's not safe to call any methods that may result in |
| 234 | // a virtual method call. |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 235 | virtual void OnURLRequestDestroyed(URLRequest* request) = 0; |
[email protected] | 4875ba1 | 2011-03-30 22:31:51 | [diff] [blame] | 236 | |
davidben | a3ef438 | 2015-09-14 22:36:10 | [diff] [blame] | 237 | // Called when the current job for |request| is orphaned. This is a temporary |
| 238 | // callback to diagnose https://crbug.com/289715 and may not be used for other |
| 239 | // purposes. Note that it may be called after OnURLRequestDestroyed. |
| 240 | // |
| 241 | // TODO(davidben): Remove this once data has been gathered. |
| 242 | virtual void OnURLRequestJobOrphaned(URLRequest* request) = 0; |
| 243 | |
[email protected] | 82a3767 | 2011-05-03 12:02:41 | [diff] [blame] | 244 | // Corresponds to ProxyResolverJSBindings::OnError. |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 245 | virtual void OnPACScriptError(int line_number, |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 246 | const base::string16& error) = 0; |
[email protected] | 7efc582d | 2011-08-03 20:46:35 | [diff] [blame] | 247 | |
[email protected] | c2911d7 | 2011-10-03 22:16:36 | [diff] [blame] | 248 | // Called when a request receives an authentication challenge |
| 249 | // specified by |auth_info|, and is unable to respond using cached |
| 250 | // credentials. |callback| and |credentials| must be non-NULL, and must |
| 251 | // be valid until OnURLRequestDestroyed is called for |request|. |
| 252 | // |
| 253 | // The following return values are allowed: |
| 254 | // - AUTH_REQUIRED_RESPONSE_NO_ACTION: |auth_info| is observed, but |
| 255 | // no action is being taken on it. |
| 256 | // - AUTH_REQUIRED_RESPONSE_SET_AUTH: |credentials| is filled in with |
| 257 | // a username and password, which should be used in a response to |
| 258 | // |auth_info|. |
| 259 | // - AUTH_REQUIRED_RESPONSE_CANCEL_AUTH: The authentication challenge |
| 260 | // should not be attempted. |
| 261 | // - AUTH_REQUIRED_RESPONSE_IO_PENDING: The action will be decided |
| 262 | // asynchronously. |callback| will be invoked when the decision is made, |
| 263 | // and one of the other AuthRequiredResponse values will be passed in with |
| 264 | // the same semantics as described above. |
| 265 | virtual AuthRequiredResponse OnAuthRequired( |
| 266 | URLRequest* request, |
| 267 | const AuthChallengeInfo& auth_info, |
| 268 | const AuthCallback& callback, |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 269 | AuthCredentials* credentials) = 0; |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 270 | |
| 271 | // Called when reading cookies to allow the network delegate to block access |
| 272 | // to the cookie. This method will never be invoked when |
| 273 | // LOAD_DO_NOT_SEND_COOKIES is specified. |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 274 | virtual bool OnCanGetCookies(const URLRequest& request, |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 275 | const CookieList& cookie_list) = 0; |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 276 | |
| 277 | // Called when a cookie is set to allow the network delegate to block access |
| 278 | // to the cookie. This method will never be invoked when |
| 279 | // LOAD_DO_NOT_SAVE_COOKIES is specified. |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 280 | virtual bool OnCanSetCookie(const URLRequest& request, |
| 281 | const std::string& cookie_line, |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 282 | CookieOptions* options) = 0; |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 283 | |
[email protected] | 4c219e2 | 2012-05-05 19:41:04 | [diff] [blame] | 284 | // Called when a file access is attempted to allow the network delegate to |
| 285 | // allow or block access to the given file path. Returns true if access is |
| 286 | // allowed. |
| 287 | virtual bool OnCanAccessFile(const URLRequest& request, |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 288 | const base::FilePath& path) const = 0; |
[email protected] | 9c8ae8c | 2012-03-09 13:13:35 | [diff] [blame] | 289 | |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 290 | // Returns true if the given |url| has to be requested over connection that |
| 291 | // is not tracked by the server. Usually is false, unless user privacy |
| 292 | // settings block cookies from being get or set. |
| 293 | virtual bool OnCanEnablePrivacyMode( |
| 294 | const GURL& url, |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 295 | const GURL& first_party_for_cookies) const = 0; |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 296 | |
mkwst | 0513c9d | 2015-04-01 05:53:15 | [diff] [blame] | 297 | // Returns true if the embedder has enabled the "first-party" cookie |
| 298 | // experiment, and false otherwise. |
| 299 | // |
| 300 | // TODO(mkwst): Remove this once we decide whether or not we wish to ship |
| 301 | // first-party cookies. https://crbug.com/459154 |
| 302 | virtual bool OnFirstPartyOnlyCookieExperimentEnabled() const = 0; |
| 303 | |
jochen | 0e3b3a6 | 2014-09-16 18:31:23 | [diff] [blame] | 304 | // Called when the |referrer_url| for requesting |target_url| during handling |
| 305 | // of the |request| is does not comply with the referrer policy (e.g. a |
| 306 | // secure referrer for an insecure initial target). |
| 307 | // Returns true if the request should be cancelled. Otherwise, the referrer |
| 308 | // header is stripped from the request. |
| 309 | virtual bool OnCancelURLRequestWithPolicyViolatingReferrerHeader( |
| 310 | const URLRequest& request, |
| 311 | const GURL& target_url, |
megjablon | c175145 | 2014-12-09 19:46:47 | [diff] [blame] | 312 | const GURL& referrer_url) const = 0; |
[email protected] | 0651b81 | 2011-02-24 00:22:50 | [diff] [blame] | 313 | }; |
| 314 | |
| 315 | } // namespace net |
| 316 | |
| 317 | #endif // NET_BASE_NETWORK_DELEGATE_H_ |