OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_BASE_NETWORK_DELEGATE_H_ | 5 #ifndef NET_BASE_NETWORK_DELEGATE_H_ |
6 #define NET_BASE_NETWORK_DELEGATE_H_ | 6 #define NET_BASE_NETWORK_DELEGATE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 // desired. | 121 // desired. |
122 // |callback| and |new_url| are valid only until OnURLRequestDestroyed is | 122 // |callback| and |new_url| are valid only until OnURLRequestDestroyed is |
123 // called for this request. Returns a net status code, generally either OK to | 123 // called for this request. Returns a net status code, generally either OK to |
124 // continue with the request or ERR_IO_PENDING if the result is not ready yet. | 124 // continue with the request or ERR_IO_PENDING if the result is not ready yet. |
125 // A status code other than OK and ERR_IO_PENDING will cancel the request and | 125 // A status code other than OK and ERR_IO_PENDING will cancel the request and |
126 // report the status code as the reason. | 126 // report the status code as the reason. |
127 // | 127 // |
128 // The default implementation returns OK (continue with request). | 128 // The default implementation returns OK (continue with request). |
129 virtual int OnBeforeURLRequest(URLRequest* request, | 129 virtual int OnBeforeURLRequest(URLRequest* request, |
130 const CompletionCallback& callback, | 130 const CompletionCallback& callback, |
131 GURL* new_url); | 131 GURL* new_url) = 0; |
132 | 132 |
133 // Called as the proxy is being resolved for |url|. Allows the delegate to | 133 // Called as the proxy is being resolved for |url|. Allows the delegate to |
134 // override the proxy resolution decision made by ProxyService. The delegate | 134 // override the proxy resolution decision made by ProxyService. The delegate |
135 // may override the decision by modifying the ProxyInfo |result|. | 135 // may override the decision by modifying the ProxyInfo |result|. |
136 virtual void OnResolveProxy(const GURL& url, | 136 virtual void OnResolveProxy(const GURL& url, |
137 int load_flags, | 137 int load_flags, |
138 const ProxyService& proxy_service, | 138 const ProxyService& proxy_service, |
139 ProxyInfo* result); | 139 ProxyInfo* result) = 0; |
140 | 140 |
141 // Called when use of |bad_proxy| fails due to |net_error|. |net_error| is | 141 // Called when use of |bad_proxy| fails due to |net_error|. |net_error| is |
142 // the network error encountered, if any, and OK if the fallback was | 142 // the network error encountered, if any, and OK if the fallback was |
143 // for a reason other than a network error (e.g. the proxy service was | 143 // for a reason other than a network error (e.g. the proxy service was |
144 // explicitly directed to skip a proxy). | 144 // explicitly directed to skip a proxy). |
145 virtual void OnProxyFallback(const ProxyServer& bad_proxy, | 145 virtual void OnProxyFallback(const ProxyServer& bad_proxy, int net_error) = 0; |
146 int net_error); | |
147 | 146 |
148 // Called right before the HTTP headers are sent. Allows the delegate to | 147 // Called right before the HTTP headers are sent. Allows the delegate to |
149 // read/write |headers| before they get sent out. |callback| and |headers| are | 148 // read/write |headers| before they get sent out. |callback| and |headers| are |
150 // valid only until OnCompleted or OnURLRequestDestroyed is called for this | 149 // valid only until OnCompleted or OnURLRequestDestroyed is called for this |
151 // request. | 150 // request. |
152 // See OnBeforeURLRequest for return value description. Returns OK by default. | 151 // See OnBeforeURLRequest for return value description. Returns OK by default. |
153 virtual int OnBeforeSendHeaders(URLRequest* request, | 152 virtual int OnBeforeSendHeaders(URLRequest* request, |
154 const CompletionCallback& callback, | 153 const CompletionCallback& callback, |
155 HttpRequestHeaders* headers); | 154 HttpRequestHeaders* headers) = 0; |
156 | 155 |
157 // Called after a proxy connection. Allows the delegate to read/write | 156 // Called after a proxy connection. Allows the delegate to read/write |
158 // |headers| before they get sent out. |headers| is valid only until | 157 // |headers| before they get sent out. |headers| is valid only until |
159 // OnCompleted or OnURLRequestDestroyed is called for this request. | 158 // OnCompleted or OnURLRequestDestroyed is called for this request. |
160 virtual void OnBeforeSendProxyHeaders(URLRequest* request, | 159 virtual void OnBeforeSendProxyHeaders(URLRequest* request, |
161 const ProxyInfo& proxy_info, | 160 const ProxyInfo& proxy_info, |
162 HttpRequestHeaders* headers); | 161 HttpRequestHeaders* headers) = 0; |
163 | 162 |
164 // Called right before the HTTP request(s) are being sent to the network. | 163 // Called right before the HTTP request(s) are being sent to the network. |
165 // |headers| is only valid until OnCompleted or OnURLRequestDestroyed is | 164 // |headers| is only valid until OnCompleted or OnURLRequestDestroyed is |
166 // called for this request. | 165 // called for this request. |
167 virtual void OnSendHeaders(URLRequest* request, | 166 virtual void OnSendHeaders(URLRequest* request, |
168 const HttpRequestHeaders& headers); | 167 const HttpRequestHeaders& headers) = 0; |
169 | 168 |
170 // Called for HTTP requests when the headers have been received. | 169 // Called for HTTP requests when the headers have been received. |
171 // |original_response_headers| contains the headers as received over the | 170 // |original_response_headers| contains the headers as received over the |
172 // network, these must not be modified. |override_response_headers| can be set | 171 // network, these must not be modified. |override_response_headers| can be set |
173 // to new values, that should be considered as overriding | 172 // to new values, that should be considered as overriding |
174 // |original_response_headers|. | 173 // |original_response_headers|. |
175 // If the response is a redirect, and the Location response header value is | 174 // If the response is a redirect, and the Location response header value is |
176 // identical to |allowed_unsafe_redirect_url|, then the redirect is never | 175 // identical to |allowed_unsafe_redirect_url|, then the redirect is never |
177 // blocked and the reference fragment is not copied from the original URL | 176 // blocked and the reference fragment is not copied from the original URL |
178 // to the redirection target. | 177 // to the redirection target. |
179 // | 178 // |
180 // |callback|, |original_response_headers|, and |override_response_headers| | 179 // |callback|, |original_response_headers|, and |override_response_headers| |
181 // are only valid until OnURLRequestDestroyed is called for this request. | 180 // are only valid until OnURLRequestDestroyed is called for this request. |
182 // See OnBeforeURLRequest for return value description. Returns OK by default. | 181 // See OnBeforeURLRequest for return value description. Returns OK by default. |
183 virtual int OnHeadersReceived( | 182 virtual int OnHeadersReceived( |
184 URLRequest* request, | 183 URLRequest* request, |
185 const CompletionCallback& callback, | 184 const CompletionCallback& callback, |
186 const HttpResponseHeaders* original_response_headers, | 185 const HttpResponseHeaders* original_response_headers, |
187 scoped_refptr<HttpResponseHeaders>* override_response_headers, | 186 scoped_refptr<HttpResponseHeaders>* override_response_headers, |
188 GURL* allowed_unsafe_redirect_url); | 187 GURL* allowed_unsafe_redirect_url) = 0; |
189 | 188 |
190 // Called right after a redirect response code was received. | 189 // Called right after a redirect response code was received. |
191 // |new_location| is only valid until OnURLRequestDestroyed is called for this | 190 // |new_location| is only valid until OnURLRequestDestroyed is called for this |
192 // request. | 191 // request. |
193 virtual void OnBeforeRedirect(URLRequest* request, | 192 virtual void OnBeforeRedirect(URLRequest* request, |
194 const GURL& new_location); | 193 const GURL& new_location) = 0; |
195 | 194 |
196 // This corresponds to URLRequestDelegate::OnResponseStarted. | 195 // This corresponds to URLRequestDelegate::OnResponseStarted. |
197 virtual void OnResponseStarted(URLRequest* request); | 196 virtual void OnResponseStarted(URLRequest* request) = 0; |
198 | 197 |
199 // Called every time we read raw bytes. | 198 // Called every time we read raw bytes. |
200 virtual void OnRawBytesRead(const URLRequest& request, int bytes_read); | 199 virtual void OnRawBytesRead(const URLRequest& request, int bytes_read) = 0; |
201 | 200 |
202 // Indicates that the URL request has been completed or failed. | 201 // Indicates that the URL request has been completed or failed. |
203 // |started| indicates whether the request has been started. If false, | 202 // |started| indicates whether the request has been started. If false, |
204 // some information like the socket address is not available. | 203 // some information like the socket address is not available. |
205 virtual void OnCompleted(URLRequest* request, bool started); | 204 virtual void OnCompleted(URLRequest* request, bool started) = 0; |
206 | 205 |
207 // Called when an URLRequest is being destroyed. Note that the request is | 206 // Called when an URLRequest is being destroyed. Note that the request is |
208 // being deleted, so it's not safe to call any methods that may result in | 207 // being deleted, so it's not safe to call any methods that may result in |
209 // a virtual method call. | 208 // a virtual method call. |
210 virtual void OnURLRequestDestroyed(URLRequest* request); | 209 virtual void OnURLRequestDestroyed(URLRequest* request) = 0; |
211 | 210 |
212 // Corresponds to ProxyResolverJSBindings::OnError. | 211 // Corresponds to ProxyResolverJSBindings::OnError. |
213 virtual void OnPACScriptError(int line_number, | 212 virtual void OnPACScriptError(int line_number, |
214 const base::string16& error); | 213 const base::string16& error) = 0; |
215 | 214 |
216 // Called when a request receives an authentication challenge | 215 // Called when a request receives an authentication challenge |
217 // specified by |auth_info|, and is unable to respond using cached | 216 // specified by |auth_info|, and is unable to respond using cached |
218 // credentials. |callback| and |credentials| must be non-NULL, and must | 217 // credentials. |callback| and |credentials| must be non-NULL, and must |
219 // be valid until OnURLRequestDestroyed is called for |request|. | 218 // be valid until OnURLRequestDestroyed is called for |request|. |
220 // | 219 // |
221 // The following return values are allowed: | 220 // The following return values are allowed: |
222 // - AUTH_REQUIRED_RESPONSE_NO_ACTION: |auth_info| is observed, but | 221 // - AUTH_REQUIRED_RESPONSE_NO_ACTION: |auth_info| is observed, but |
223 // no action is being taken on it. | 222 // no action is being taken on it. |
224 // - AUTH_REQUIRED_RESPONSE_SET_AUTH: |credentials| is filled in with | 223 // - AUTH_REQUIRED_RESPONSE_SET_AUTH: |credentials| is filled in with |
225 // a username and password, which should be used in a response to | 224 // a username and password, which should be used in a response to |
226 // |auth_info|. | 225 // |auth_info|. |
227 // - AUTH_REQUIRED_RESPONSE_CANCEL_AUTH: The authentication challenge | 226 // - AUTH_REQUIRED_RESPONSE_CANCEL_AUTH: The authentication challenge |
228 // should not be attempted. | 227 // should not be attempted. |
229 // - AUTH_REQUIRED_RESPONSE_IO_PENDING: The action will be decided | 228 // - AUTH_REQUIRED_RESPONSE_IO_PENDING: The action will be decided |
230 // asynchronously. |callback| will be invoked when the decision is made, | 229 // asynchronously. |callback| will be invoked when the decision is made, |
231 // and one of the other AuthRequiredResponse values will be passed in with | 230 // and one of the other AuthRequiredResponse values will be passed in with |
232 // the same semantics as described above. | 231 // the same semantics as described above. |
233 virtual AuthRequiredResponse OnAuthRequired( | 232 virtual AuthRequiredResponse OnAuthRequired( |
234 URLRequest* request, | 233 URLRequest* request, |
235 const AuthChallengeInfo& auth_info, | 234 const AuthChallengeInfo& auth_info, |
236 const AuthCallback& callback, | 235 const AuthCallback& callback, |
237 AuthCredentials* credentials); | 236 AuthCredentials* credentials) = 0; |
238 | 237 |
239 // Called when reading cookies to allow the network delegate to block access | 238 // Called when reading cookies to allow the network delegate to block access |
240 // to the cookie. This method will never be invoked when | 239 // to the cookie. This method will never be invoked when |
241 // LOAD_DO_NOT_SEND_COOKIES is specified. | 240 // LOAD_DO_NOT_SEND_COOKIES is specified. |
242 virtual bool OnCanGetCookies(const URLRequest& request, | 241 virtual bool OnCanGetCookies(const URLRequest& request, |
243 const CookieList& cookie_list); | 242 const CookieList& cookie_list) = 0; |
244 | 243 |
245 // Called when a cookie is set to allow the network delegate to block access | 244 // Called when a cookie is set to allow the network delegate to block access |
246 // to the cookie. This method will never be invoked when | 245 // to the cookie. This method will never be invoked when |
247 // LOAD_DO_NOT_SAVE_COOKIES is specified. | 246 // LOAD_DO_NOT_SAVE_COOKIES is specified. |
248 virtual bool OnCanSetCookie(const URLRequest& request, | 247 virtual bool OnCanSetCookie(const URLRequest& request, |
249 const std::string& cookie_line, | 248 const std::string& cookie_line, |
250 CookieOptions* options); | 249 CookieOptions* options) = 0; |
251 | 250 |
252 // Called when a file access is attempted to allow the network delegate to | 251 // Called when a file access is attempted to allow the network delegate to |
253 // allow or block access to the given file path. Returns true if access is | 252 // allow or block access to the given file path. Returns true if access is |
254 // allowed. | 253 // allowed. |
255 virtual bool OnCanAccessFile(const URLRequest& request, | 254 virtual bool OnCanAccessFile(const URLRequest& request, |
256 const base::FilePath& path) const; | 255 const base::FilePath& path) const = 0; |
257 | 256 |
258 // Returns true if the given request may be rejected when the | 257 // Returns true if the given request may be rejected when the |
259 // URLRequestThrottlerManager believes the server servicing the | 258 // URLRequestThrottlerManager believes the server servicing the |
260 // request is overloaded or down. | 259 // request is overloaded or down. |
261 virtual bool OnCanThrottleRequest(const URLRequest& request) const; | 260 virtual bool OnCanThrottleRequest(const URLRequest& request) const = 0; |
262 | 261 |
263 // Returns true if the given |url| has to be requested over connection that | 262 // Returns true if the given |url| has to be requested over connection that |
264 // is not tracked by the server. Usually is false, unless user privacy | 263 // is not tracked by the server. Usually is false, unless user privacy |
265 // settings block cookies from being get or set. | 264 // settings block cookies from being get or set. |
266 virtual bool OnCanEnablePrivacyMode( | 265 virtual bool OnCanEnablePrivacyMode( |
267 const GURL& url, | 266 const GURL& url, |
268 const GURL& first_party_for_cookies) const; | 267 const GURL& first_party_for_cookies) const = 0; |
269 | 268 |
270 // Called when the |referrer_url| for requesting |target_url| during handling | 269 // Called when the |referrer_url| for requesting |target_url| during handling |
271 // of the |request| is does not comply with the referrer policy (e.g. a | 270 // of the |request| is does not comply with the referrer policy (e.g. a |
272 // secure referrer for an insecure initial target). | 271 // secure referrer for an insecure initial target). |
273 // Returns true if the request should be cancelled. Otherwise, the referrer | 272 // Returns true if the request should be cancelled. Otherwise, the referrer |
274 // header is stripped from the request. | 273 // header is stripped from the request. |
275 virtual bool OnCancelURLRequestWithPolicyViolatingReferrerHeader( | 274 virtual bool OnCancelURLRequestWithPolicyViolatingReferrerHeader( |
276 const URLRequest& request, | 275 const URLRequest& request, |
277 const GURL& target_url, | 276 const GURL& target_url, |
278 const GURL& referrer_url) const; | 277 const GURL& referrer_url) const = 0; |
279 }; | 278 }; |
280 | 279 |
281 } // namespace net | 280 } // namespace net |
282 | 281 |
283 #endif // NET_BASE_NETWORK_DELEGATE_H_ | 282 #endif // NET_BASE_NETWORK_DELEGATE_H_ |
OLD | NEW |