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
3 // found in the LICENSE file.
5 #include "net/base/network_delegate.h"
7 #include "base/logging.h"
8 #include "net/base/load_flags.h"
9 #include "net/base/net_errors.h"
10 #include "net/proxy/proxy_info.h"
11 #include "net/url_request/url_request.h"
15 int NetworkDelegate::NotifyBeforeURLRequest(
16 URLRequest
* request
, const CompletionCallback
& callback
,
18 DCHECK(CalledOnValidThread());
20 DCHECK(!callback
.is_null());
21 return OnBeforeURLRequest(request
, callback
, new_url
);
24 void NetworkDelegate::NotifyResolveProxy(
27 const ProxyService
& proxy_service
,
29 DCHECK(CalledOnValidThread());
31 OnResolveProxy(url
, load_flags
, proxy_service
, result
);
34 void NetworkDelegate::NotifyProxyFallback(
35 const ProxyServer
& bad_proxy
,
37 DCHECK(CalledOnValidThread());
38 OnProxyFallback(bad_proxy
, net_error
);
41 int NetworkDelegate::NotifyBeforeSendHeaders(
42 URLRequest
* request
, const CompletionCallback
& callback
,
43 HttpRequestHeaders
* headers
) {
44 DCHECK(CalledOnValidThread());
46 DCHECK(!callback
.is_null());
47 return OnBeforeSendHeaders(request
, callback
, headers
);
50 void NetworkDelegate::NotifyBeforeSendProxyHeaders(
52 const ProxyInfo
& proxy_info
,
53 HttpRequestHeaders
* headers
) {
54 DCHECK(CalledOnValidThread());
56 OnBeforeSendProxyHeaders(request
, proxy_info
, headers
);
59 void NetworkDelegate::NotifySendHeaders(URLRequest
* request
,
60 const HttpRequestHeaders
& headers
) {
61 DCHECK(CalledOnValidThread());
62 OnSendHeaders(request
, headers
);
65 int NetworkDelegate::NotifyHeadersReceived(
67 const CompletionCallback
& callback
,
68 const HttpResponseHeaders
* original_response_headers
,
69 scoped_refptr
<HttpResponseHeaders
>* override_response_headers
,
70 GURL
* allowed_unsafe_redirect_url
) {
71 DCHECK(CalledOnValidThread());
72 DCHECK(original_response_headers
);
73 DCHECK(!callback
.is_null());
74 return OnHeadersReceived(request
,
76 original_response_headers
,
77 override_response_headers
,
78 allowed_unsafe_redirect_url
);
81 void NetworkDelegate::NotifyResponseStarted(URLRequest
* request
) {
82 DCHECK(CalledOnValidThread());
84 OnResponseStarted(request
);
87 void NetworkDelegate::NotifyRawBytesRead(const URLRequest
& request
,
89 DCHECK(CalledOnValidThread());
90 OnRawBytesRead(request
, bytes_read
);
93 void NetworkDelegate::NotifyBeforeRedirect(URLRequest
* request
,
94 const GURL
& new_location
) {
95 DCHECK(CalledOnValidThread());
97 OnBeforeRedirect(request
, new_location
);
100 void NetworkDelegate::NotifyCompleted(URLRequest
* request
, bool started
) {
101 DCHECK(CalledOnValidThread());
103 OnCompleted(request
, started
);
106 void NetworkDelegate::NotifyURLRequestDestroyed(URLRequest
* request
) {
107 DCHECK(CalledOnValidThread());
109 OnURLRequestDestroyed(request
);
112 void NetworkDelegate::NotifyPACScriptError(int line_number
,
113 const base::string16
& error
) {
114 DCHECK(CalledOnValidThread());
115 OnPACScriptError(line_number
, error
);
118 NetworkDelegate::AuthRequiredResponse
NetworkDelegate::NotifyAuthRequired(
120 const AuthChallengeInfo
& auth_info
,
121 const AuthCallback
& callback
,
122 AuthCredentials
* credentials
) {
123 DCHECK(CalledOnValidThread());
124 return OnAuthRequired(request
, auth_info
, callback
, credentials
);
127 int NetworkDelegate::NotifyBeforeSocketStreamConnect(
128 SocketStream
* socket
,
129 const CompletionCallback
& callback
) {
130 DCHECK(CalledOnValidThread());
132 DCHECK(!callback
.is_null());
133 return OnBeforeSocketStreamConnect(socket
, callback
);
136 bool NetworkDelegate::CanGetCookies(const URLRequest
& request
,
137 const CookieList
& cookie_list
) {
138 DCHECK(CalledOnValidThread());
139 DCHECK(!(request
.load_flags() & net::LOAD_DO_NOT_SEND_COOKIES
));
140 return OnCanGetCookies(request
, cookie_list
);
143 bool NetworkDelegate::CanSetCookie(const URLRequest
& request
,
144 const std::string
& cookie_line
,
145 CookieOptions
* options
) {
146 DCHECK(CalledOnValidThread());
147 DCHECK(!(request
.load_flags() & net::LOAD_DO_NOT_SAVE_COOKIES
));
148 return OnCanSetCookie(request
, cookie_line
, options
);
151 bool NetworkDelegate::CanAccessFile(const URLRequest
& request
,
152 const base::FilePath
& path
) const {
153 DCHECK(CalledOnValidThread());
154 return OnCanAccessFile(request
, path
);
157 bool NetworkDelegate::CanThrottleRequest(const URLRequest
& request
) const {
158 DCHECK(CalledOnValidThread());
159 return OnCanThrottleRequest(request
);
162 bool NetworkDelegate::CanEnablePrivacyMode(
164 const GURL
& first_party_for_cookies
) const {
165 DCHECK(CalledOnValidThread());
166 return OnCanEnablePrivacyMode(url
, first_party_for_cookies
);
169 int NetworkDelegate::OnBeforeURLRequest(URLRequest
* request
,
170 const CompletionCallback
& callback
,
175 void NetworkDelegate::OnResolveProxy(
178 const ProxyService
& proxy_service
,
182 void NetworkDelegate::OnProxyFallback(const ProxyServer
& bad_proxy
,
186 int NetworkDelegate::OnBeforeSendHeaders(URLRequest
* request
,
187 const CompletionCallback
& callback
,
188 HttpRequestHeaders
* headers
) {
192 void NetworkDelegate::OnBeforeSendProxyHeaders(
194 const ProxyInfo
& proxy_info
,
195 HttpRequestHeaders
* headers
) {
198 void NetworkDelegate::OnSendHeaders(URLRequest
* request
,
199 const HttpRequestHeaders
& headers
) {
202 int NetworkDelegate::OnHeadersReceived(
204 const CompletionCallback
& callback
,
205 const HttpResponseHeaders
* original_response_headers
,
206 scoped_refptr
<HttpResponseHeaders
>* override_response_headers
,
207 GURL
* allowed_unsafe_redirect_url
) {
211 void NetworkDelegate::OnBeforeRedirect(URLRequest
* request
,
212 const GURL
& new_location
) {
215 void NetworkDelegate::OnResponseStarted(URLRequest
* request
) {
218 void NetworkDelegate::OnRawBytesRead(const URLRequest
& request
,
222 void NetworkDelegate::OnCompleted(URLRequest
* request
, bool started
) {
225 void NetworkDelegate::OnURLRequestDestroyed(URLRequest
* request
) {
228 void NetworkDelegate::OnPACScriptError(int line_number
,
229 const base::string16
& error
) {
232 NetworkDelegate::AuthRequiredResponse
NetworkDelegate::OnAuthRequired(
234 const AuthChallengeInfo
& auth_info
,
235 const AuthCallback
& callback
,
236 AuthCredentials
* credentials
) {
237 return AUTH_REQUIRED_RESPONSE_NO_ACTION
;
240 bool NetworkDelegate::OnCanGetCookies(const URLRequest
& request
,
241 const CookieList
& cookie_list
) {
245 bool NetworkDelegate::OnCanSetCookie(const URLRequest
& request
,
246 const std::string
& cookie_line
,
247 CookieOptions
* options
) {
251 bool NetworkDelegate::OnCanAccessFile(const URLRequest
& request
,
252 const base::FilePath
& path
) const {
256 bool NetworkDelegate::OnCanThrottleRequest(const URLRequest
& request
) const {
260 bool NetworkDelegate::OnCanEnablePrivacyMode(
262 const GURL
& first_party_for_cookies
) const {
266 int NetworkDelegate::OnBeforeSocketStreamConnect(
267 SocketStream
* socket
,
268 const CompletionCallback
& callback
) {