15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef NET_BASE_NETWORK_DELEGATE_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define NET_BASE_NETWORK_DELEGATE_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/callback.h"
115e3f23d412006dc4db4e659864679f29341e113fTorne (Richard Coles)#include "base/strings/string16.h"
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/threading/non_thread_safe.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/auth.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/base/completion_callback.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "net/cookies/canonical_cookie.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class GURL;
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace base {
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)class FilePath;
212a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace net {
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NOTE: Layering violations!
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// We decided to accept these violations (depending
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// on other net/ submodules from net/base/), because otherwise NetworkDelegate
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// would have to be broken up into too many smaller interfaces targeted to each
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// submodule. Also, since the lower levels in net/ may callback into higher
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// levels, we may encounter dangerous casting issues.
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// NOTE: It is not okay to add any compile-time dependencies on symbols outside
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// of net/base here, because we have a net_base library. Forward declarations
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// are ok.
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class CookieOptions;
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HttpRequestHeaders;
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class HttpResponseHeaders;
38116680a4aac90f2aa7413d9095a592090648e557Ben Murdochclass ProxyInfo;
396e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)class ProxyServer;
406e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)class ProxyService;
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SocketStream;
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class URLRequest;
435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class NET_EXPORT NetworkDelegate : public base::NonThreadSafe {
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // AuthRequiredResponse indicates how a NetworkDelegate handles an
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // OnAuthRequired call. It's placed in this file to prevent url_request.h
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // from having to include network_delegate.h.
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  enum AuthRequiredResponse {
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    AUTH_REQUIRED_RESPONSE_NO_ACTION,
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    AUTH_REQUIRED_RESPONSE_SET_AUTH,
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    AUTH_REQUIRED_RESPONSE_CANCEL_AUTH,
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    AUTH_REQUIRED_RESPONSE_IO_PENDING,
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  };
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  typedef base::Callback<void(AuthRequiredResponse)> AuthCallback;
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~NetworkDelegate() {}
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Notification interface called by the network stack. Note that these
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // functions mostly forward to the private virtuals. They also add some sanity
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // checking on parameters. See the corresponding virtuals for explanations of
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // the methods and their arguments.
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int NotifyBeforeURLRequest(URLRequest* request,
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             const CompletionCallback& callback,
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             GURL* new_url);
666e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  void NotifyResolveProxy(const GURL& url,
676e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                          int load_flags,
686e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                          const ProxyService& proxy_service,
69116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                          ProxyInfo* result);
706e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  void NotifyProxyFallback(const ProxyServer& bad_proxy,
7103b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                           int net_error);
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int NotifyBeforeSendHeaders(URLRequest* request,
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              const CompletionCallback& callback,
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              HttpRequestHeaders* headers);
75116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  void NotifyBeforeSendProxyHeaders(URLRequest* request,
76116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                                    const ProxyInfo& proxy_info,
77116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                                    HttpRequestHeaders* headers);
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifySendHeaders(URLRequest* request,
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                         const HttpRequestHeaders& headers);
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int NotifyHeadersReceived(
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      URLRequest* request,
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const CompletionCallback& callback,
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const HttpResponseHeaders* original_response_headers,
84effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      scoped_refptr<HttpResponseHeaders>* override_response_headers,
85effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      GURL* allowed_unsafe_redirect_url);
865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifyBeforeRedirect(URLRequest* request,
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            const GURL& new_location);
885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifyResponseStarted(URLRequest* request);
895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifyRawBytesRead(const URLRequest& request, int bytes_read);
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifyCompleted(URLRequest* request, bool started);
915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void NotifyURLRequestDestroyed(URLRequest* request);
92c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  void NotifyPACScriptError(int line_number, const base::string16& error);
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  AuthRequiredResponse NotifyAuthRequired(URLRequest* request,
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                          const AuthChallengeInfo& auth_info,
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                          const AuthCallback& callback,
965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                          AuthCredentials* credentials);
975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool CanGetCookies(const URLRequest& request,
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                     const CookieList& cookie_list);
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool CanSetCookie(const URLRequest& request,
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    const std::string& cookie_line,
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                    CookieOptions* options);
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool CanAccessFile(const URLRequest& request,
1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                     const base::FilePath& path) const;
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool CanThrottleRequest(const URLRequest& request) const;
10590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  bool CanEnablePrivacyMode(const GURL& url,
10690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)                            const GURL& first_party_for_cookies) const;
1075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  int NotifyBeforeSocketStreamConnect(SocketStream* socket,
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                      const CompletionCallback& callback);
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1111320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  bool CancelURLRequestWithPolicyViolatingReferrerHeader(
1121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      const URLRequest& request,
1131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      const GURL& target_url,
1141320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      const GURL& referrer_url) const;
1151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This is the interface for subclasses of NetworkDelegate to implement. These
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // member functions will be called by the respective public notification
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // member function, which will perform basic sanity checking.
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called before a request is sent. Allows the delegate to rewrite the URL
122c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // being fetched by modifying |new_url|. If set, the URL must be valid. The
123c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // reference fragment from the original URL is not automatically appended to
124c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // |new_url|; callers are responsible for copying the reference fragment if
125c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // desired.
126c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // |callback| and |new_url| are valid only until OnURLRequestDestroyed is
127c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // called for this request. Returns a net status code, generally either OK to
128c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // continue with the request or ERR_IO_PENDING if the result is not ready yet.
129c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // A status code other than OK and ERR_IO_PENDING will cancel the request and
130c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // report the status code as the reason.
1311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  //
1321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // The default implementation returns OK (continue with request).
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual int OnBeforeURLRequest(URLRequest* request,
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 const CompletionCallback& callback,
1351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                 GURL* new_url);
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
137116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Called as the proxy is being resolved for |url|. Allows the delegate to
138116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // override the proxy resolution decision made by ProxyService. The delegate
139116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // may override the decision by modifying the ProxyInfo |result|.
140116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual void OnResolveProxy(const GURL& url,
141116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                              int load_flags,
1426e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)                              const ProxyService& proxy_service,
143116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                              ProxyInfo* result);
144116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
14503b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // Called when use of |bad_proxy| fails due to |net_error|. |net_error| is
14603b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // the network error encountered, if any, and OK if the fallback was
14703b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // for a reason other than a network error (e.g. the proxy service was
14803b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)  // explicitly directed to skip a proxy).
1496e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  virtual void OnProxyFallback(const ProxyServer& bad_proxy,
15003b57e008b61dfcb1fbad3aea950ae0e001748b0Torne (Richard Coles)                               int net_error);
1516e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called right before the HTTP headers are sent. Allows the delegate to
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // read/write |headers| before they get sent out. |callback| and |headers| are
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // valid only until OnCompleted or OnURLRequestDestroyed is called for this
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // request.
1561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // See OnBeforeURLRequest for return value description. Returns OK by default.
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual int OnBeforeSendHeaders(URLRequest* request,
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                  const CompletionCallback& callback,
1591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                  HttpRequestHeaders* headers);
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
161116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Called after a proxy connection. Allows the delegate to read/write
162116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // |headers| before they get sent out. |headers| is valid only until
163116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // OnCompleted or OnURLRequestDestroyed is called for this request.
164116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual void OnBeforeSendProxyHeaders(URLRequest* request,
165116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                                        const ProxyInfo& proxy_info,
166116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch                                        HttpRequestHeaders* headers);
167116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called right before the HTTP request(s) are being sent to the network.
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |headers| is only valid until OnCompleted or OnURLRequestDestroyed is
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // called for this request.
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnSendHeaders(URLRequest* request,
1721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                             const HttpRequestHeaders& headers);
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Called for HTTP requests when the headers have been received.
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |original_response_headers| contains the headers as received over the
1765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // network, these must not be modified. |override_response_headers| can be set
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to new values, that should be considered as overriding
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |original_response_headers|.
179c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // If the response is a redirect, and the Location response header value is
180c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // identical to |allowed_unsafe_redirect_url|, then the redirect is never
181c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // blocked and the reference fragment is not copied from the original URL
182c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // to the redirection target.
183c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  //
1845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |callback|, |original_response_headers|, and |override_response_headers|
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // are only valid until OnURLRequestDestroyed is called for this request.
1861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // See OnBeforeURLRequest for return value description. Returns OK by default.
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual int OnHeadersReceived(
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      URLRequest* request,
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const CompletionCallback& callback,
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const HttpResponseHeaders* original_response_headers,
191effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      scoped_refptr<HttpResponseHeaders>* override_response_headers,
192effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch      GURL* allowed_unsafe_redirect_url);
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called right after a redirect response code was received.
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |new_location| is only valid until OnURLRequestDestroyed is called for this
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // request.
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void OnBeforeRedirect(URLRequest* request,
1981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                const GURL& new_location);
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // This corresponds to URLRequestDelegate::OnResponseStarted.
2011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void OnResponseStarted(URLRequest* request);
2025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called every time we read raw bytes.
2041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void OnRawBytesRead(const URLRequest& request, int bytes_read);
2055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Indicates that the URL request has been completed or failed.
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // |started| indicates whether the request has been started. If false,
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // some information like the socket address is not available.
2091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void OnCompleted(URLRequest* request, bool started);
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called when an URLRequest is being destroyed. Note that the request is
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // being deleted, so it's not safe to call any methods that may result in
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // a virtual method call.
2141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void OnURLRequestDestroyed(URLRequest* request);
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Corresponds to ProxyResolverJSBindings::OnError.
217c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)  virtual void OnPACScriptError(int line_number,
2181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                const base::string16& error);
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called when a request receives an authentication challenge
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // specified by |auth_info|, and is unable to respond using cached
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // credentials. |callback| and |credentials| must be non-NULL, and must
2235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // be valid until OnURLRequestDestroyed is called for |request|.
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The following return values are allowed:
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //  - AUTH_REQUIRED_RESPONSE_NO_ACTION: |auth_info| is observed, but
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    no action is being taken on it.
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //  - AUTH_REQUIRED_RESPONSE_SET_AUTH: |credentials| is filled in with
2295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    a username and password, which should be used in a response to
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    |auth_info|.
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //  - AUTH_REQUIRED_RESPONSE_CANCEL_AUTH: The authentication challenge
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    should not be attempted.
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //  - AUTH_REQUIRED_RESPONSE_IO_PENDING: The action will be decided
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    asynchronously. |callback| will be invoked when the decision is made,
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    and one of the other AuthRequiredResponse values will be passed in with
2365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  //    the same semantics as described above.
2375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual AuthRequiredResponse OnAuthRequired(
2385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      URLRequest* request,
2395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const AuthChallengeInfo& auth_info,
2405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      const AuthCallback& callback,
2411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      AuthCredentials* credentials);
2425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called when reading cookies to allow the network delegate to block access
2445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to the cookie. This method will never be invoked when
2455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // LOAD_DO_NOT_SEND_COOKIES is specified.
2465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool OnCanGetCookies(const URLRequest& request,
2471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                               const CookieList& cookie_list);
2485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called when a cookie is set to allow the network delegate to block access
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // to the cookie. This method will never be invoked when
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // LOAD_DO_NOT_SAVE_COOKIES is specified.
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool OnCanSetCookie(const URLRequest& request,
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              const std::string& cookie_line,
2541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                              CookieOptions* options);
2555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called when a file access is attempted to allow the network delegate to
2575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // allow or block access to the given file path.  Returns true if access is
2585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // allowed.
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool OnCanAccessFile(const URLRequest& request,
2601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                               const base::FilePath& path) const;
2615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Returns true if the given request may be rejected when the
2635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // URLRequestThrottlerManager believes the server servicing the
2645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // request is overloaded or down.
2651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual bool OnCanThrottleRequest(const URLRequest& request) const;
2665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
26790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // Returns true if the given |url| has to be requested over connection that
26890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // is not tracked by the server. Usually is false, unless user privacy
26990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  // settings block cookies from being get or set.
27090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)  virtual bool OnCanEnablePrivacyMode(
27190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      const GURL& url,
27290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)      const GURL& first_party_for_cookies) const;
27390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Called before a SocketStream tries to connect.
2751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // See OnBeforeURLRequest for return value description. Returns OK by default.
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual int OnBeforeSocketStreamConnect(
2771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      SocketStream* socket, const CompletionCallback& callback);
2781320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
2791320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Called when the |referrer_url| for requesting |target_url| during handling
2801320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // of the |request| is does not comply with the referrer policy (e.g. a
2811320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // secure referrer for an insecure initial target).
2821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // Returns true if the request should be cancelled. Otherwise, the referrer
2831320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // header is stripped from the request.
2841320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual bool OnCancelURLRequestWithPolicyViolatingReferrerHeader(
2851320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      const URLRequest& request,
2861320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      const GURL& target_url,
2871320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      const GURL& referrer_url) const;
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace net
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // NET_BASE_NETWORK_DELEGATE_H_
293