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/url_request/url_request.h"
11
12 namespace net {
13
NotifyBeforeURLRequest(URLRequest * request,const CompletionCallback & callback,GURL * new_url)14 int NetworkDelegate::NotifyBeforeURLRequest(
15 URLRequest* request, const CompletionCallback& callback,
16 GURL* new_url) {
17 DCHECK(CalledOnValidThread());
18 DCHECK(request);
19 DCHECK(!callback.is_null());
20 return OnBeforeURLRequest(request, callback, new_url);
21 }
22
NotifyBeforeSendHeaders(URLRequest * request,const CompletionCallback & callback,HttpRequestHeaders * headers)23 int NetworkDelegate::NotifyBeforeSendHeaders(
24 URLRequest* request, const CompletionCallback& callback,
25 HttpRequestHeaders* headers) {
26 DCHECK(CalledOnValidThread());
27 DCHECK(headers);
28 DCHECK(!callback.is_null());
29 return OnBeforeSendHeaders(request, callback, headers);
30 }
31
NotifySendHeaders(URLRequest * request,const HttpRequestHeaders & headers)32 void NetworkDelegate::NotifySendHeaders(URLRequest* request,
33 const HttpRequestHeaders& headers) {
34 DCHECK(CalledOnValidThread());
35 OnSendHeaders(request, headers);
36 }
37
NotifyHeadersReceived(URLRequest * request,const CompletionCallback & callback,const HttpResponseHeaders * original_response_headers,scoped_refptr<HttpResponseHeaders> * override_response_headers,GURL * allowed_unsafe_redirect_url)38 int NetworkDelegate::NotifyHeadersReceived(
39 URLRequest* request,
40 const CompletionCallback& callback,
41 const HttpResponseHeaders* original_response_headers,
42 scoped_refptr<HttpResponseHeaders>* override_response_headers,
43 GURL* allowed_unsafe_redirect_url) {
44 DCHECK(CalledOnValidThread());
45 DCHECK(original_response_headers);
46 DCHECK(!callback.is_null());
47 return OnHeadersReceived(request,
48 callback,
49 original_response_headers,
50 override_response_headers,
51 allowed_unsafe_redirect_url);
52 }
53
NotifyResponseStarted(URLRequest * request)54 void NetworkDelegate::NotifyResponseStarted(URLRequest* request) {
55 DCHECK(CalledOnValidThread());
56 DCHECK(request);
57 OnResponseStarted(request);
58 }
59
NotifyRawBytesRead(const URLRequest & request,int bytes_read)60 void NetworkDelegate::NotifyRawBytesRead(const URLRequest& request,
61 int bytes_read) {
62 DCHECK(CalledOnValidThread());
63 OnRawBytesRead(request, bytes_read);
64 }
65
NotifyBeforeRedirect(URLRequest * request,const GURL & new_location)66 void NetworkDelegate::NotifyBeforeRedirect(URLRequest* request,
67 const GURL& new_location) {
68 DCHECK(CalledOnValidThread());
69 DCHECK(request);
70 OnBeforeRedirect(request, new_location);
71 }
72
NotifyCompleted(URLRequest * request,bool started)73 void NetworkDelegate::NotifyCompleted(URLRequest* request, bool started) {
74 DCHECK(CalledOnValidThread());
75 DCHECK(request);
76 OnCompleted(request, started);
77 }
78
NotifyURLRequestDestroyed(URLRequest * request)79 void NetworkDelegate::NotifyURLRequestDestroyed(URLRequest* request) {
80 DCHECK(CalledOnValidThread());
81 DCHECK(request);
82 OnURLRequestDestroyed(request);
83 }
84
NotifyPACScriptError(int line_number,const base::string16 & error)85 void NetworkDelegate::NotifyPACScriptError(int line_number,
86 const base::string16& error) {
87 DCHECK(CalledOnValidThread());
88 OnPACScriptError(line_number, error);
89 }
90
NotifyAuthRequired(URLRequest * request,const AuthChallengeInfo & auth_info,const AuthCallback & callback,AuthCredentials * credentials)91 NetworkDelegate::AuthRequiredResponse NetworkDelegate::NotifyAuthRequired(
92 URLRequest* request,
93 const AuthChallengeInfo& auth_info,
94 const AuthCallback& callback,
95 AuthCredentials* credentials) {
96 DCHECK(CalledOnValidThread());
97 return OnAuthRequired(request, auth_info, callback, credentials);
98 }
99
NotifyBeforeSocketStreamConnect(SocketStream * socket,const CompletionCallback & callback)100 int NetworkDelegate::NotifyBeforeSocketStreamConnect(
101 SocketStream* socket,
102 const CompletionCallback& callback) {
103 DCHECK(CalledOnValidThread());
104 DCHECK(socket);
105 DCHECK(!callback.is_null());
106 return OnBeforeSocketStreamConnect(socket, callback);
107 }
108
CanGetCookies(const URLRequest & request,const CookieList & cookie_list)109 bool NetworkDelegate::CanGetCookies(const URLRequest& request,
110 const CookieList& cookie_list) {
111 DCHECK(CalledOnValidThread());
112 DCHECK(!(request.load_flags() & net::LOAD_DO_NOT_SEND_COOKIES));
113 return OnCanGetCookies(request, cookie_list);
114 }
115
CanSetCookie(const URLRequest & request,const std::string & cookie_line,CookieOptions * options)116 bool NetworkDelegate::CanSetCookie(const URLRequest& request,
117 const std::string& cookie_line,
118 CookieOptions* options) {
119 DCHECK(CalledOnValidThread());
120 DCHECK(!(request.load_flags() & net::LOAD_DO_NOT_SAVE_COOKIES));
121 return OnCanSetCookie(request, cookie_line, options);
122 }
123
CanAccessFile(const URLRequest & request,const base::FilePath & path) const124 bool NetworkDelegate::CanAccessFile(const URLRequest& request,
125 const base::FilePath& path) const {
126 DCHECK(CalledOnValidThread());
127 return OnCanAccessFile(request, path);
128 }
129
CanThrottleRequest(const URLRequest & request) const130 bool NetworkDelegate::CanThrottleRequest(const URLRequest& request) const {
131 DCHECK(CalledOnValidThread());
132 return OnCanThrottleRequest(request);
133 }
134
CanEnablePrivacyMode(const GURL & url,const GURL & first_party_for_cookies) const135 bool NetworkDelegate::CanEnablePrivacyMode(
136 const GURL& url,
137 const GURL& first_party_for_cookies) const {
138 DCHECK(CalledOnValidThread());
139 return OnCanEnablePrivacyMode(url, first_party_for_cookies);
140 }
141
OnBeforeURLRequest(URLRequest * request,const CompletionCallback & callback,GURL * new_url)142 int NetworkDelegate::OnBeforeURLRequest(URLRequest* request,
143 const CompletionCallback& callback,
144 GURL* new_url) {
145 return OK;
146 }
147
OnBeforeSendHeaders(URLRequest * request,const CompletionCallback & callback,HttpRequestHeaders * headers)148 int NetworkDelegate::OnBeforeSendHeaders(URLRequest* request,
149 const CompletionCallback& callback,
150 HttpRequestHeaders* headers) {
151 return OK;
152 }
153
OnSendHeaders(URLRequest * request,const HttpRequestHeaders & headers)154 void NetworkDelegate::OnSendHeaders(URLRequest* request,
155 const HttpRequestHeaders& headers) {
156 }
157
OnHeadersReceived(URLRequest * request,const CompletionCallback & callback,const HttpResponseHeaders * original_response_headers,scoped_refptr<HttpResponseHeaders> * override_response_headers,GURL * allowed_unsafe_redirect_url)158 int NetworkDelegate::OnHeadersReceived(
159 URLRequest* request,
160 const CompletionCallback& callback,
161 const HttpResponseHeaders* original_response_headers,
162 scoped_refptr<HttpResponseHeaders>* override_response_headers,
163 GURL* allowed_unsafe_redirect_url) {
164 return OK;
165 }
166
OnBeforeRedirect(URLRequest * request,const GURL & new_location)167 void NetworkDelegate::OnBeforeRedirect(URLRequest* request,
168 const GURL& new_location) {
169 }
170
OnResponseStarted(URLRequest * request)171 void NetworkDelegate::OnResponseStarted(URLRequest* request) {
172 }
173
OnRawBytesRead(const URLRequest & request,int bytes_read)174 void NetworkDelegate::OnRawBytesRead(const URLRequest& request,
175 int bytes_read) {
176 }
177
OnCompleted(URLRequest * request,bool started)178 void NetworkDelegate::OnCompleted(URLRequest* request, bool started) {
179 }
180
OnURLRequestDestroyed(URLRequest * request)181 void NetworkDelegate::OnURLRequestDestroyed(URLRequest* request) {
182 }
183
OnPACScriptError(int line_number,const base::string16 & error)184 void NetworkDelegate::OnPACScriptError(int line_number,
185 const base::string16& error) {
186 }
187
OnAuthRequired(URLRequest * request,const AuthChallengeInfo & auth_info,const AuthCallback & callback,AuthCredentials * credentials)188 NetworkDelegate::AuthRequiredResponse NetworkDelegate::OnAuthRequired(
189 URLRequest* request,
190 const AuthChallengeInfo& auth_info,
191 const AuthCallback& callback,
192 AuthCredentials* credentials) {
193 return AUTH_REQUIRED_RESPONSE_NO_ACTION;
194 }
195
OnCanGetCookies(const URLRequest & request,const CookieList & cookie_list)196 bool NetworkDelegate::OnCanGetCookies(const URLRequest& request,
197 const CookieList& cookie_list) {
198 return true;
199 }
200
OnCanSetCookie(const URLRequest & request,const std::string & cookie_line,CookieOptions * options)201 bool NetworkDelegate::OnCanSetCookie(const URLRequest& request,
202 const std::string& cookie_line,
203 CookieOptions* options) {
204 return true;
205 }
206
OnCanAccessFile(const URLRequest & request,const base::FilePath & path) const207 bool NetworkDelegate::OnCanAccessFile(const URLRequest& request,
208 const base::FilePath& path) const {
209 return false;
210 }
211
OnCanThrottleRequest(const URLRequest & request) const212 bool NetworkDelegate::OnCanThrottleRequest(const URLRequest& request) const {
213 return false;
214 }
215
OnCanEnablePrivacyMode(const GURL & url,const GURL & first_party_for_cookies) const216 bool NetworkDelegate::OnCanEnablePrivacyMode(
217 const GURL& url,
218 const GURL& first_party_for_cookies) const {
219 return false;
220 }
221
OnBeforeSocketStreamConnect(SocketStream * socket,const CompletionCallback & callback)222 int NetworkDelegate::OnBeforeSocketStreamConnect(
223 SocketStream* socket,
224 const CompletionCallback& callback) {
225 return OK;
226 }
227
228 } // namespace net
229