1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef NET_BASE_LAYERED_NETWORK_DELEGATE_H_
6 #define NET_BASE_LAYERED_NETWORK_DELEGATE_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string16.h"
10 #include "net/base/completion_callback.h"
11 #include "net/base/network_delegate.h"
12 #include "net/cookies/canonical_cookie.h"
23 class HttpRequestHeaders
;
24 class HttpResponseHeaders
;
30 // WrappingNetworkDelegate takes a |network_delegate| and extends it. When
31 // On*() is called, the On*Internal() method of this is first called and then
32 // the On*() of |network_delegate| is called. On*Internal() methods have no
33 // return values, and cannot prevent calling into the nested network delegate.
34 class NET_EXPORT LayeredNetworkDelegate
: public NetworkDelegate
{
36 explicit LayeredNetworkDelegate(
37 scoped_ptr
<NetworkDelegate
> nested_network_delegate
);
38 ~LayeredNetworkDelegate() override
;
40 // NetworkDelegate implementation:
41 int OnBeforeURLRequest(URLRequest
* request
,
42 const CompletionCallback
& callback
,
44 void OnResolveProxy(const GURL
& url
,
46 const ProxyService
& proxy_service
,
47 ProxyInfo
* result
) final
;
48 void OnProxyFallback(const ProxyServer
& bad_proxy
, int net_error
) final
;
49 int OnBeforeSendHeaders(URLRequest
* request
,
50 const CompletionCallback
& callback
,
51 HttpRequestHeaders
* headers
) final
;
52 void OnBeforeSendProxyHeaders(URLRequest
* request
,
53 const ProxyInfo
& proxy_info
,
54 HttpRequestHeaders
* headers
) final
;
55 void OnSendHeaders(URLRequest
* request
,
56 const HttpRequestHeaders
& headers
) final
;
57 int OnHeadersReceived(
59 const CompletionCallback
& callback
,
60 const HttpResponseHeaders
* original_response_headers
,
61 scoped_refptr
<HttpResponseHeaders
>* override_response_headers
,
62 GURL
* allowed_unsafe_redirect_url
) final
;
63 void OnBeforeRedirect(URLRequest
* request
, const GURL
& new_location
) final
;
64 void OnResponseStarted(URLRequest
* request
) final
;
65 void OnRawBytesRead(const URLRequest
& request
, int bytes_read
) final
;
66 void OnCompleted(URLRequest
* request
, bool started
) final
;
67 void OnURLRequestDestroyed(URLRequest
* request
) final
;
68 void OnPACScriptError(int line_number
, const base::string16
& error
) final
;
69 AuthRequiredResponse
OnAuthRequired(URLRequest
* request
,
70 const AuthChallengeInfo
& auth_info
,
71 const AuthCallback
& callback
,
72 AuthCredentials
* credentials
) final
;
73 bool OnCanGetCookies(const URLRequest
& request
,
74 const CookieList
& cookie_list
) final
;
75 bool OnCanSetCookie(const URLRequest
& request
,
76 const std::string
& cookie_line
,
77 CookieOptions
* options
) final
;
78 bool OnCanAccessFile(const URLRequest
& request
,
79 const base::FilePath
& path
) const final
;
80 bool OnCanThrottleRequest(const URLRequest
& request
) const final
;
81 bool OnCanEnablePrivacyMode(const GURL
& url
,
82 const GURL
& first_party_for_cookies
) const final
;
83 bool OnCancelURLRequestWithPolicyViolatingReferrerHeader(
84 const URLRequest
& request
,
85 const GURL
& target_url
,
86 const GURL
& referrer_url
) const final
;
89 virtual void OnBeforeURLRequestInternal(URLRequest
* request
,
90 const CompletionCallback
& callback
,
93 virtual void OnResolveProxyInternal(const GURL
& url
,
95 const ProxyService
& proxy_service
,
98 virtual void OnProxyFallbackInternal(const ProxyServer
& bad_proxy
,
101 virtual void OnBeforeSendHeadersInternal(URLRequest
* request
,
102 const CompletionCallback
& callback
,
103 HttpRequestHeaders
* headers
);
105 virtual void OnBeforeSendProxyHeadersInternal(URLRequest
* request
,
106 const ProxyInfo
& proxy_info
,
107 HttpRequestHeaders
* headers
);
109 virtual void OnSendHeadersInternal(URLRequest
* request
,
110 const HttpRequestHeaders
& headers
);
112 virtual void OnHeadersReceivedInternal(
114 const CompletionCallback
& callback
,
115 const HttpResponseHeaders
* original_response_headers
,
116 scoped_refptr
<HttpResponseHeaders
>* override_response_headers
,
117 GURL
* allowed_unsafe_redirect_url
);
119 virtual void OnBeforeRedirectInternal(URLRequest
* request
,
120 const GURL
& new_location
);
122 virtual void OnResponseStartedInternal(URLRequest
* request
);
124 virtual void OnRawBytesReadInternal(const URLRequest
& request
,
127 virtual void OnCompletedInternal(URLRequest
* request
, bool started
);
129 virtual void OnURLRequestDestroyedInternal(URLRequest
* request
);
131 virtual void OnPACScriptErrorInternal(int line_number
,
132 const base::string16
& error
);
134 virtual void OnCanGetCookiesInternal(const URLRequest
& request
,
135 const CookieList
& cookie_list
);
137 virtual void OnCanSetCookieInternal(const URLRequest
& request
,
138 const std::string
& cookie_line
,
139 CookieOptions
* options
);
141 virtual void OnAuthRequiredInternal(URLRequest
* request
,
142 const AuthChallengeInfo
& auth_info
,
143 const AuthCallback
& callback
,
144 AuthCredentials
* credentials
);
146 virtual void OnCanAccessFileInternal(const URLRequest
& request
,
147 const base::FilePath
& path
) const;
149 virtual void OnCanThrottleRequestInternal(const URLRequest
& request
) const;
151 virtual void OnCanEnablePrivacyModeInternal(
153 const GURL
& first_party_for_cookies
) const;
155 virtual void OnCancelURLRequestWithPolicyViolatingReferrerHeaderInternal(
156 const URLRequest
& request
,
157 const GURL
& target_url
,
158 const GURL
& referrer_url
) const;
161 scoped_ptr
<NetworkDelegate
> nested_network_delegate_
;
166 #endif // NET_BASE_LAYERED_NETWORK_DELEGATE_H_