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.
4
5 #include "net/base/network_delegate.h"
6
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"
12
13 namespace net {
14
NotifyBeforeURLRequest(URLRequest * request,const CompletionCallback & callback,GURL * new_url)15 int NetworkDelegate::NotifyBeforeURLRequest(
16 URLRequest* request, const CompletionCallback& callback,
17 GURL* new_url) {
18 DCHECK(CalledOnValidThread());
19 DCHECK(request);
20 DCHECK(!callback.is_null());
21 return OnBeforeURLRequest(request, callback, new_url);
22 }
23
NotifyResolveProxy(const GURL & url,int load_flags,const ProxyService & proxy_service,ProxyInfo * result)24 void NetworkDelegate::NotifyResolveProxy(
25 const GURL& url,
26 int load_flags,
27 const ProxyService& proxy_service,
28 ProxyInfo* result) {
29 DCHECK(CalledOnValidThread());
30 DCHECK(result);
31 OnResolveProxy(url, load_flags, proxy_service, result);
32 }
33
NotifyProxyFallback(const ProxyServer & bad_proxy,int net_error)34 void NetworkDelegate::NotifyProxyFallback(
35 const ProxyServer& bad_proxy,
36 int net_error) {
37 DCHECK(CalledOnValidThread());
38 OnProxyFallback(bad_proxy, net_error);
39 }
40
NotifyBeforeSendHeaders(URLRequest * request,const CompletionCallback & callback,HttpRequestHeaders * headers)41 int NetworkDelegate::NotifyBeforeSendHeaders(
42 URLRequest* request, const CompletionCallback& callback,
43 HttpRequestHeaders* headers) {
44 DCHECK(CalledOnValidThread());
45 DCHECK(headers);
46 DCHECK(!callback.is_null());
47 return OnBeforeSendHeaders(request, callback, headers);
48 }
49
NotifyBeforeSendProxyHeaders(URLRequest * request,const ProxyInfo & proxy_info,HttpRequestHeaders * headers)50 void NetworkDelegate::NotifyBeforeSendProxyHeaders(
51 URLRequest* request,
52 const ProxyInfo& proxy_info,
53 HttpRequestHeaders* headers) {
54 DCHECK(CalledOnValidThread());
55 DCHECK(headers);
56 OnBeforeSendProxyHeaders(request, proxy_info, headers);
57 }
58
NotifySendHeaders(URLRequest * request,const HttpRequestHeaders & headers)59 void NetworkDelegate::NotifySendHeaders(URLRequest* request,
60 const HttpRequestHeaders& headers) {
61 DCHECK(CalledOnValidThread());
62 OnSendHeaders(request, headers);
63 }
64
NotifyHeadersReceived(URLRequest * request,const CompletionCallback & callback,const HttpResponseHeaders * original_response_headers,scoped_refptr<HttpResponseHeaders> * override_response_headers,GURL * allowed_unsafe_redirect_url)65 int NetworkDelegate::NotifyHeadersReceived(
66 URLRequest* request,
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,
75 callback,
76 original_response_headers,
77 override_response_headers,
78 allowed_unsafe_redirect_url);
79 }
80
NotifyResponseStarted(URLRequest * request)81 void NetworkDelegate::NotifyResponseStarted(URLRequest* request) {
82 DCHECK(CalledOnValidThread());
83 DCHECK(request);
84 OnResponseStarted(request);
85 }
86
NotifyRawBytesRead(const URLRequest & request,int bytes_read)87 void NetworkDelegate::NotifyRawBytesRead(const URLRequest& request,
88 int bytes_read) {
89 DCHECK(CalledOnValidThread());
90 OnRawBytesRead(request, bytes_read);
91 }
92
NotifyBeforeRedirect(URLRequest * request,const GURL & new_location)93 void NetworkDelegate::NotifyBeforeRedirect(URLRequest* request,
94 const GURL& new_location) {
95 DCHECK(CalledOnValidThread());
96 DCHECK(request);
97 OnBeforeRedirect(request, new_location);
98 }
99
NotifyCompleted(URLRequest * request,bool started)100 void NetworkDelegate::NotifyCompleted(URLRequest* request, bool started) {
101 DCHECK(CalledOnValidThread());
102 DCHECK(request);
103 OnCompleted(request, started);
104 }
105
NotifyURLRequestDestroyed(URLRequest * request)106 void NetworkDelegate::NotifyURLRequestDestroyed(URLRequest* request) {
107 DCHECK(CalledOnValidThread());
108 DCHECK(request);
109 OnURLRequestDestroyed(request);
110 }
111
NotifyPACScriptError(int line_number,const base::string16 & error)112 void NetworkDelegate::NotifyPACScriptError(int line_number,
113 const base::string16& error) {
114 DCHECK(CalledOnValidThread());
115 OnPACScriptError(line_number, error);
116 }
117
NotifyAuthRequired(URLRequest * request,const AuthChallengeInfo & auth_info,const AuthCallback & callback,AuthCredentials * credentials)118 NetworkDelegate::AuthRequiredResponse NetworkDelegate::NotifyAuthRequired(
119 URLRequest* request,
120 const AuthChallengeInfo& auth_info,
121 const AuthCallback& callback,
122 AuthCredentials* credentials) {
123 DCHECK(CalledOnValidThread());
124 return OnAuthRequired(request, auth_info, callback, credentials);
125 }
126
NotifyBeforeSocketStreamConnect(SocketStream * socket,const CompletionCallback & callback)127 int NetworkDelegate::NotifyBeforeSocketStreamConnect(
128 SocketStream* socket,
129 const CompletionCallback& callback) {
130 DCHECK(CalledOnValidThread());
131 DCHECK(socket);
132 DCHECK(!callback.is_null());
133 return OnBeforeSocketStreamConnect(socket, callback);
134 }
135
CanGetCookies(const URLRequest & request,const CookieList & cookie_list)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);
141 }
142
CanSetCookie(const URLRequest & request,const std::string & cookie_line,CookieOptions * options)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);
149 }
150
CanAccessFile(const URLRequest & request,const base::FilePath & path) const151 bool NetworkDelegate::CanAccessFile(const URLRequest& request,
152 const base::FilePath& path) const {
153 DCHECK(CalledOnValidThread());
154 return OnCanAccessFile(request, path);
155 }
156
CanThrottleRequest(const URLRequest & request) const157 bool NetworkDelegate::CanThrottleRequest(const URLRequest& request) const {
158 DCHECK(CalledOnValidThread());
159 return OnCanThrottleRequest(request);
160 }
161
CanEnablePrivacyMode(const GURL & url,const GURL & first_party_for_cookies) const162 bool NetworkDelegate::CanEnablePrivacyMode(
163 const GURL& url,
164 const GURL& first_party_for_cookies) const {
165 DCHECK(CalledOnValidThread());
166 return OnCanEnablePrivacyMode(url, first_party_for_cookies);
167 }
168
CancelURLRequestWithPolicyViolatingReferrerHeader(const URLRequest & request,const GURL & target_url,const GURL & referrer_url) const169 bool NetworkDelegate::CancelURLRequestWithPolicyViolatingReferrerHeader(
170 const URLRequest& request,
171 const GURL& target_url,
172 const GURL& referrer_url) const {
173 DCHECK(CalledOnValidThread());
174 return OnCancelURLRequestWithPolicyViolatingReferrerHeader(
175 request, target_url, referrer_url);
176 }
177
OnBeforeURLRequest(URLRequest * request,const CompletionCallback & callback,GURL * new_url)178 int NetworkDelegate::OnBeforeURLRequest(URLRequest* request,
179 const CompletionCallback& callback,
180 GURL* new_url) {
181 return OK;
182 }
183
OnResolveProxy(const GURL & url,int load_flags,const ProxyService & proxy_service,ProxyInfo * result)184 void NetworkDelegate::OnResolveProxy(
185 const GURL& url,
186 int load_flags,
187 const ProxyService& proxy_service,
188 ProxyInfo* result) {
189 }
190
OnProxyFallback(const ProxyServer & bad_proxy,int net_error)191 void NetworkDelegate::OnProxyFallback(const ProxyServer& bad_proxy,
192 int net_error) {
193 }
194
OnBeforeSendHeaders(URLRequest * request,const CompletionCallback & callback,HttpRequestHeaders * headers)195 int NetworkDelegate::OnBeforeSendHeaders(URLRequest* request,
196 const CompletionCallback& callback,
197 HttpRequestHeaders* headers) {
198 return OK;
199 }
200
OnBeforeSendProxyHeaders(URLRequest * request,const ProxyInfo & proxy_info,HttpRequestHeaders * headers)201 void NetworkDelegate::OnBeforeSendProxyHeaders(
202 URLRequest* request,
203 const ProxyInfo& proxy_info,
204 HttpRequestHeaders* headers) {
205 }
206
OnSendHeaders(URLRequest * request,const HttpRequestHeaders & headers)207 void NetworkDelegate::OnSendHeaders(URLRequest* request,
208 const HttpRequestHeaders& headers) {
209 }
210
OnHeadersReceived(URLRequest * request,const CompletionCallback & callback,const HttpResponseHeaders * original_response_headers,scoped_refptr<HttpResponseHeaders> * override_response_headers,GURL * allowed_unsafe_redirect_url)211 int NetworkDelegate::OnHeadersReceived(
212 URLRequest* request,
213 const CompletionCallback& callback,
214 const HttpResponseHeaders* original_response_headers,
215 scoped_refptr<HttpResponseHeaders>* override_response_headers,
216 GURL* allowed_unsafe_redirect_url) {
217 return OK;
218 }
219
OnBeforeRedirect(URLRequest * request,const GURL & new_location)220 void NetworkDelegate::OnBeforeRedirect(URLRequest* request,
221 const GURL& new_location) {
222 }
223
OnResponseStarted(URLRequest * request)224 void NetworkDelegate::OnResponseStarted(URLRequest* request) {
225 }
226
OnRawBytesRead(const URLRequest & request,int bytes_read)227 void NetworkDelegate::OnRawBytesRead(const URLRequest& request,
228 int bytes_read) {
229 }
230
OnCompleted(URLRequest * request,bool started)231 void NetworkDelegate::OnCompleted(URLRequest* request, bool started) {
232 }
233
OnURLRequestDestroyed(URLRequest * request)234 void NetworkDelegate::OnURLRequestDestroyed(URLRequest* request) {
235 }
236
OnPACScriptError(int line_number,const base::string16 & error)237 void NetworkDelegate::OnPACScriptError(int line_number,
238 const base::string16& error) {
239 }
240
OnAuthRequired(URLRequest * request,const AuthChallengeInfo & auth_info,const AuthCallback & callback,AuthCredentials * credentials)241 NetworkDelegate::AuthRequiredResponse NetworkDelegate::OnAuthRequired(
242 URLRequest* request,
243 const AuthChallengeInfo& auth_info,
244 const AuthCallback& callback,
245 AuthCredentials* credentials) {
246 return AUTH_REQUIRED_RESPONSE_NO_ACTION;
247 }
248
OnCanGetCookies(const URLRequest & request,const CookieList & cookie_list)249 bool NetworkDelegate::OnCanGetCookies(const URLRequest& request,
250 const CookieList& cookie_list) {
251 return true;
252 }
253
OnCanSetCookie(const URLRequest & request,const std::string & cookie_line,CookieOptions * options)254 bool NetworkDelegate::OnCanSetCookie(const URLRequest& request,
255 const std::string& cookie_line,
256 CookieOptions* options) {
257 return true;
258 }
259
OnCanAccessFile(const URLRequest & request,const base::FilePath & path) const260 bool NetworkDelegate::OnCanAccessFile(const URLRequest& request,
261 const base::FilePath& path) const {
262 return false;
263 }
264
OnCanThrottleRequest(const URLRequest & request) const265 bool NetworkDelegate::OnCanThrottleRequest(const URLRequest& request) const {
266 return false;
267 }
268
OnCanEnablePrivacyMode(const GURL & url,const GURL & first_party_for_cookies) const269 bool NetworkDelegate::OnCanEnablePrivacyMode(
270 const GURL& url,
271 const GURL& first_party_for_cookies) const {
272 return false;
273 }
274
OnBeforeSocketStreamConnect(SocketStream * socket,const CompletionCallback & callback)275 int NetworkDelegate::OnBeforeSocketStreamConnect(
276 SocketStream* socket,
277 const CompletionCallback& callback) {
278 return OK;
279 }
280
OnCancelURLRequestWithPolicyViolatingReferrerHeader(const URLRequest & request,const GURL & target_url,const GURL & referrer_url) const281 bool NetworkDelegate::OnCancelURLRequestWithPolicyViolatingReferrerHeader(
282 const URLRequest& request,
283 const GURL& target_url,
284 const GURL& referrer_url) const {
285 return false;
286 }
287
288 } // namespace net
289