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 #include "net/base/layered_network_delegate.h"
9 LayeredNetworkDelegate::LayeredNetworkDelegate(
10 scoped_ptr
<NetworkDelegate
> nested_network_delegate
)
11 : nested_network_delegate_(nested_network_delegate
.Pass()) {
14 LayeredNetworkDelegate::~LayeredNetworkDelegate() {
17 int LayeredNetworkDelegate::OnBeforeURLRequest(
19 const CompletionCallback
& callback
,
21 OnBeforeURLRequestInternal(request
, callback
, new_url
);
22 return nested_network_delegate_
->NotifyBeforeURLRequest(request
, callback
,
26 void LayeredNetworkDelegate::OnBeforeURLRequestInternal(
28 const CompletionCallback
& callback
,
32 void LayeredNetworkDelegate::OnResolveProxy(const GURL
& url
,
34 const ProxyService
& proxy_service
,
36 OnResolveProxyInternal(url
, load_flags
, proxy_service
, result
);
37 nested_network_delegate_
->NotifyResolveProxy(url
, load_flags
, proxy_service
,
41 void LayeredNetworkDelegate::OnResolveProxyInternal(
44 const ProxyService
& proxy_service
,
48 void LayeredNetworkDelegate::OnProxyFallback(const ProxyServer
& bad_proxy
,
50 OnProxyFallbackInternal(bad_proxy
, net_error
);
51 nested_network_delegate_
->NotifyProxyFallback(bad_proxy
, net_error
);
54 void LayeredNetworkDelegate::OnProxyFallbackInternal(
55 const ProxyServer
& bad_proxy
,
59 int LayeredNetworkDelegate::OnBeforeSendHeaders(
61 const CompletionCallback
& callback
,
62 HttpRequestHeaders
* headers
) {
63 OnBeforeSendHeadersInternal(request
, callback
, headers
);
64 return nested_network_delegate_
->NotifyBeforeSendHeaders(request
, callback
,
68 void LayeredNetworkDelegate::OnBeforeSendHeadersInternal(
70 const CompletionCallback
& callback
,
71 HttpRequestHeaders
* headers
) {
74 void LayeredNetworkDelegate::OnBeforeSendProxyHeaders(
76 const ProxyInfo
& proxy_info
,
77 HttpRequestHeaders
* headers
) {
78 OnBeforeSendProxyHeadersInternal(request
, proxy_info
, headers
);
79 nested_network_delegate_
->NotifyBeforeSendProxyHeaders(request
, proxy_info
,
83 void LayeredNetworkDelegate::OnBeforeSendProxyHeadersInternal(
85 const ProxyInfo
& proxy_info
,
86 HttpRequestHeaders
* headers
) {
89 void LayeredNetworkDelegate::OnSendHeaders(URLRequest
* request
,
90 const HttpRequestHeaders
& headers
) {
91 OnSendHeadersInternal(request
, headers
);
92 nested_network_delegate_
->NotifySendHeaders(request
, headers
);
95 void LayeredNetworkDelegate::OnSendHeadersInternal(
97 const HttpRequestHeaders
& headers
) {
100 int LayeredNetworkDelegate::OnHeadersReceived(
102 const CompletionCallback
& callback
,
103 const HttpResponseHeaders
* original_response_headers
,
104 scoped_refptr
<HttpResponseHeaders
>* override_response_headers
,
105 GURL
* allowed_unsafe_redirect_url
) {
106 OnHeadersReceivedInternal(request
, callback
, original_response_headers
,
107 override_response_headers
,
108 allowed_unsafe_redirect_url
);
109 return nested_network_delegate_
->NotifyHeadersReceived(
110 request
, callback
, original_response_headers
, override_response_headers
,
111 allowed_unsafe_redirect_url
);
114 void LayeredNetworkDelegate::OnHeadersReceivedInternal(
116 const CompletionCallback
& callback
,
117 const HttpResponseHeaders
* original_response_headers
,
118 scoped_refptr
<HttpResponseHeaders
>* override_response_headers
,
119 GURL
* allowed_unsafe_redirect_url
) {
122 void LayeredNetworkDelegate::OnBeforeRedirect(URLRequest
* request
,
123 const GURL
& new_location
) {
124 OnBeforeRedirectInternal(request
, new_location
);
125 nested_network_delegate_
->NotifyBeforeRedirect(request
, new_location
);
128 void LayeredNetworkDelegate::OnBeforeRedirectInternal(
130 const GURL
& new_location
) {
133 void LayeredNetworkDelegate::OnResponseStarted(URLRequest
* request
) {
134 OnResponseStartedInternal(request
);
135 nested_network_delegate_
->NotifyResponseStarted(request
);
138 void LayeredNetworkDelegate::OnResponseStartedInternal(URLRequest
* request
) {
141 void LayeredNetworkDelegate::OnNetworkBytesReceived(const URLRequest
& request
,
142 int64_t bytes_received
) {
143 OnNetworkBytesReceivedInternal(request
, bytes_received
);
144 nested_network_delegate_
->NotifyNetworkBytesReceived(request
, bytes_received
);
147 void LayeredNetworkDelegate::OnNetworkBytesReceivedInternal(
148 const URLRequest
& request
,
149 int64_t bytes_received
) {}
151 void LayeredNetworkDelegate::OnCompleted(URLRequest
* request
, bool started
) {
152 OnCompletedInternal(request
, started
);
153 nested_network_delegate_
->NotifyCompleted(request
, started
);
156 void LayeredNetworkDelegate::OnCompletedInternal(URLRequest
* request
,
160 void LayeredNetworkDelegate::OnURLRequestDestroyed(URLRequest
* request
) {
161 OnURLRequestDestroyedInternal(request
);
162 nested_network_delegate_
->NotifyURLRequestDestroyed(request
);
165 void LayeredNetworkDelegate::OnURLRequestDestroyedInternal(
166 URLRequest
* request
) {
169 void LayeredNetworkDelegate::OnURLRequestJobOrphaned(URLRequest
* request
) {
170 // This hook is only added to debug https://crbug.com/289715, so there is no
171 // need for a OnURLRequestJobOrphanedInternal hook.
172 nested_network_delegate_
->NotifyURLRequestJobOrphaned(request
);
175 void LayeredNetworkDelegate::OnPACScriptError(int line_number
,
176 const base::string16
& error
) {
177 OnPACScriptErrorInternal(line_number
, error
);
178 nested_network_delegate_
->NotifyPACScriptError(line_number
, error
);
181 void LayeredNetworkDelegate::OnPACScriptErrorInternal(
183 const base::string16
& error
) {
186 NetworkDelegate::AuthRequiredResponse
LayeredNetworkDelegate::OnAuthRequired(
188 const AuthChallengeInfo
& auth_info
,
189 const AuthCallback
& callback
,
190 AuthCredentials
* credentials
) {
191 OnAuthRequiredInternal(request
, auth_info
, callback
, credentials
);
192 return nested_network_delegate_
->NotifyAuthRequired(request
, auth_info
,
193 callback
, credentials
);
196 void LayeredNetworkDelegate::OnAuthRequiredInternal(
198 const AuthChallengeInfo
& auth_info
,
199 const AuthCallback
& callback
,
200 AuthCredentials
* credentials
) {
203 bool LayeredNetworkDelegate::OnCanGetCookies(const URLRequest
& request
,
204 const CookieList
& cookie_list
) {
205 OnCanGetCookiesInternal(request
, cookie_list
);
206 return nested_network_delegate_
->CanGetCookies(request
, cookie_list
);
209 void LayeredNetworkDelegate::OnCanGetCookiesInternal(
210 const URLRequest
& request
,
211 const CookieList
& cookie_list
) {
214 bool LayeredNetworkDelegate::OnCanSetCookie(const URLRequest
& request
,
215 const std::string
& cookie_line
,
216 CookieOptions
* options
) {
217 OnCanSetCookieInternal(request
, cookie_line
, options
);
218 return nested_network_delegate_
->CanSetCookie(request
, cookie_line
, options
);
221 void LayeredNetworkDelegate::OnCanSetCookieInternal(
222 const URLRequest
& request
,
223 const std::string
& cookie_line
,
224 CookieOptions
* options
) {
227 bool LayeredNetworkDelegate::OnCanAccessFile(const URLRequest
& request
,
228 const base::FilePath
& path
) const {
229 OnCanAccessFileInternal(request
, path
);
230 return nested_network_delegate_
->CanAccessFile(request
, path
);
233 void LayeredNetworkDelegate::OnCanAccessFileInternal(
234 const URLRequest
& request
,
235 const base::FilePath
& path
) const {
238 bool LayeredNetworkDelegate::OnCanEnablePrivacyMode(
240 const GURL
& first_party_for_cookies
) const {
241 OnCanEnablePrivacyModeInternal(url
, first_party_for_cookies
);
242 return nested_network_delegate_
->CanEnablePrivacyMode(
243 url
, first_party_for_cookies
);
246 void LayeredNetworkDelegate::OnCanEnablePrivacyModeInternal(
248 const GURL
& first_party_for_cookies
) const {
251 bool LayeredNetworkDelegate::OnFirstPartyOnlyCookieExperimentEnabled() const {
252 OnFirstPartyOnlyCookieExperimentEnabledInternal();
253 return nested_network_delegate_
->FirstPartyOnlyCookieExperimentEnabled();
256 void LayeredNetworkDelegate::OnFirstPartyOnlyCookieExperimentEnabledInternal()
260 bool LayeredNetworkDelegate::
261 OnCancelURLRequestWithPolicyViolatingReferrerHeader(
262 const URLRequest
& request
,
263 const GURL
& target_url
,
264 const GURL
& referrer_url
) const {
265 OnCancelURLRequestWithPolicyViolatingReferrerHeaderInternal(
266 request
, target_url
, referrer_url
);
267 return nested_network_delegate_
268 ->CancelURLRequestWithPolicyViolatingReferrerHeader(request
, target_url
,
272 void LayeredNetworkDelegate::
273 OnCancelURLRequestWithPolicyViolatingReferrerHeaderInternal(
274 const URLRequest
& request
,
275 const GURL
& target_url
,
276 const GURL
& referrer_url
) const {