• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)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   DCHECK(CalledOnValidThread());
44   DCHECK(original_response_headers);
45   DCHECK(!callback.is_null());
46   return OnHeadersReceived(request, callback, original_response_headers,
47                            override_response_headers);
48 }
49 
NotifyResponseStarted(URLRequest * request)50 void NetworkDelegate::NotifyResponseStarted(URLRequest* request) {
51   DCHECK(CalledOnValidThread());
52   DCHECK(request);
53   OnResponseStarted(request);
54 }
55 
NotifyRawBytesRead(const URLRequest & request,int bytes_read)56 void NetworkDelegate::NotifyRawBytesRead(const URLRequest& request,
57                                          int bytes_read) {
58   DCHECK(CalledOnValidThread());
59   OnRawBytesRead(request, bytes_read);
60 }
61 
NotifyBeforeRedirect(URLRequest * request,const GURL & new_location)62 void NetworkDelegate::NotifyBeforeRedirect(URLRequest* request,
63                                            const GURL& new_location) {
64   DCHECK(CalledOnValidThread());
65   DCHECK(request);
66   OnBeforeRedirect(request, new_location);
67 }
68 
NotifyCompleted(URLRequest * request,bool started)69 void NetworkDelegate::NotifyCompleted(URLRequest* request, bool started) {
70   DCHECK(CalledOnValidThread());
71   DCHECK(request);
72   OnCompleted(request, started);
73 }
74 
NotifyURLRequestDestroyed(URLRequest * request)75 void NetworkDelegate::NotifyURLRequestDestroyed(URLRequest* request) {
76   DCHECK(CalledOnValidThread());
77   DCHECK(request);
78   OnURLRequestDestroyed(request);
79 }
80 
NotifyPACScriptError(int line_number,const base::string16 & error)81 void NetworkDelegate::NotifyPACScriptError(int line_number,
82                                            const base::string16& error) {
83   DCHECK(CalledOnValidThread());
84   OnPACScriptError(line_number, error);
85 }
86 
NotifyAuthRequired(URLRequest * request,const AuthChallengeInfo & auth_info,const AuthCallback & callback,AuthCredentials * credentials)87 NetworkDelegate::AuthRequiredResponse NetworkDelegate::NotifyAuthRequired(
88     URLRequest* request,
89     const AuthChallengeInfo& auth_info,
90     const AuthCallback& callback,
91     AuthCredentials* credentials) {
92   DCHECK(CalledOnValidThread());
93   return OnAuthRequired(request, auth_info, callback, credentials);
94 }
95 
NotifyBeforeSocketStreamConnect(SocketStream * socket,const CompletionCallback & callback)96 int NetworkDelegate::NotifyBeforeSocketStreamConnect(
97     SocketStream* socket,
98     const CompletionCallback& callback) {
99   DCHECK(CalledOnValidThread());
100   DCHECK(socket);
101   DCHECK(!callback.is_null());
102   return OnBeforeSocketStreamConnect(socket, callback);
103 }
104 
NotifyRequestWaitStateChange(const URLRequest & request,RequestWaitState state)105 void NetworkDelegate::NotifyRequestWaitStateChange(const URLRequest& request,
106                                                    RequestWaitState state) {
107   DCHECK(CalledOnValidThread());
108   OnRequestWaitStateChange(request, state);
109 }
110 
CanGetCookies(const URLRequest & request,const CookieList & cookie_list)111 bool NetworkDelegate::CanGetCookies(const URLRequest& request,
112                                     const CookieList& cookie_list) {
113   DCHECK(CalledOnValidThread());
114   DCHECK(!(request.load_flags() & net::LOAD_DO_NOT_SEND_COOKIES));
115   return OnCanGetCookies(request, cookie_list);
116 }
117 
CanSetCookie(const URLRequest & request,const std::string & cookie_line,CookieOptions * options)118 bool NetworkDelegate::CanSetCookie(const URLRequest& request,
119                                    const std::string& cookie_line,
120                                    CookieOptions* options) {
121   DCHECK(CalledOnValidThread());
122   DCHECK(!(request.load_flags() & net::LOAD_DO_NOT_SAVE_COOKIES));
123   return OnCanSetCookie(request, cookie_line, options);
124 }
125 
CanAccessFile(const URLRequest & request,const base::FilePath & path) const126 bool NetworkDelegate::CanAccessFile(const URLRequest& request,
127                                     const base::FilePath& path) const {
128   DCHECK(CalledOnValidThread());
129   return OnCanAccessFile(request, path);
130 }
131 
CanThrottleRequest(const URLRequest & request) const132 bool NetworkDelegate::CanThrottleRequest(const URLRequest& request) const {
133   DCHECK(CalledOnValidThread());
134   return OnCanThrottleRequest(request);
135 }
136 
CanEnablePrivacyMode(const GURL & url,const GURL & first_party_for_cookies) const137 bool NetworkDelegate::CanEnablePrivacyMode(
138     const GURL& url,
139     const GURL& first_party_for_cookies) const {
140   DCHECK(CalledOnValidThread());
141   return OnCanEnablePrivacyMode(url, first_party_for_cookies);
142 }
143 
OnBeforeURLRequest(URLRequest * request,const CompletionCallback & callback,GURL * new_url)144 int NetworkDelegate::OnBeforeURLRequest(URLRequest* request,
145                                         const CompletionCallback& callback,
146                                         GURL* new_url) {
147   return OK;
148 }
149 
OnBeforeSendHeaders(URLRequest * request,const CompletionCallback & callback,HttpRequestHeaders * headers)150 int NetworkDelegate::OnBeforeSendHeaders(URLRequest* request,
151                                          const CompletionCallback& callback,
152                                          HttpRequestHeaders* headers) {
153   return OK;
154 }
155 
OnSendHeaders(URLRequest * request,const HttpRequestHeaders & headers)156 void NetworkDelegate::OnSendHeaders(URLRequest* request,
157                                     const HttpRequestHeaders& headers) {
158 }
159 
OnHeadersReceived(URLRequest * request,const CompletionCallback & callback,const HttpResponseHeaders * original_response_headers,scoped_refptr<HttpResponseHeaders> * override_response_headers)160 int NetworkDelegate::OnHeadersReceived(
161     URLRequest* request,
162     const CompletionCallback& callback,
163     const HttpResponseHeaders* original_response_headers,
164     scoped_refptr<HttpResponseHeaders>* override_response_headers) {
165   return OK;
166 }
167 
OnBeforeRedirect(URLRequest * request,const GURL & new_location)168 void NetworkDelegate::OnBeforeRedirect(URLRequest* request,
169                                        const GURL& new_location) {
170 }
171 
OnResponseStarted(URLRequest * request)172 void NetworkDelegate::OnResponseStarted(URLRequest* request) {
173 }
174 
OnRawBytesRead(const URLRequest & request,int bytes_read)175 void NetworkDelegate::OnRawBytesRead(const URLRequest& request,
176                                      int bytes_read) {
177 }
178 
OnCompleted(URLRequest * request,bool started)179 void NetworkDelegate::OnCompleted(URLRequest* request, bool started) {
180 }
181 
OnURLRequestDestroyed(URLRequest * request)182 void NetworkDelegate::OnURLRequestDestroyed(URLRequest* request) {
183 }
184 
OnPACScriptError(int line_number,const base::string16 & error)185 void NetworkDelegate::OnPACScriptError(int line_number,
186                                        const base::string16& error) {
187 }
188 
OnAuthRequired(URLRequest * request,const AuthChallengeInfo & auth_info,const AuthCallback & callback,AuthCredentials * credentials)189 NetworkDelegate::AuthRequiredResponse NetworkDelegate::OnAuthRequired(
190     URLRequest* request,
191     const AuthChallengeInfo& auth_info,
192     const AuthCallback& callback,
193     AuthCredentials* credentials) {
194   return AUTH_REQUIRED_RESPONSE_NO_ACTION;
195 }
196 
OnCanGetCookies(const URLRequest & request,const CookieList & cookie_list)197 bool NetworkDelegate::OnCanGetCookies(const URLRequest& request,
198                                       const CookieList& cookie_list)  {
199   return true;
200 }
201 
OnCanSetCookie(const URLRequest & request,const std::string & cookie_line,CookieOptions * options)202 bool NetworkDelegate::OnCanSetCookie(const URLRequest& request,
203                                      const std::string& cookie_line,
204                                      CookieOptions* options) {
205   return true;
206 }
207 
OnCanAccessFile(const URLRequest & request,const base::FilePath & path) const208 bool NetworkDelegate::OnCanAccessFile(const URLRequest& request,
209                                       const base::FilePath& path) const  {
210   return false;
211 }
212 
OnCanThrottleRequest(const URLRequest & request) const213 bool NetworkDelegate::OnCanThrottleRequest(const URLRequest& request) const {
214   return false;
215 }
216 
OnCanEnablePrivacyMode(const GURL & url,const GURL & first_party_for_cookies) const217 bool NetworkDelegate::OnCanEnablePrivacyMode(
218     const GURL& url,
219     const GURL& first_party_for_cookies) const {
220   return false;
221 }
222 
OnBeforeSocketStreamConnect(SocketStream * socket,const CompletionCallback & callback)223 int NetworkDelegate::OnBeforeSocketStreamConnect(
224     SocketStream* socket,
225     const CompletionCallback& callback) {
226   return OK;
227 }
228 
OnRequestWaitStateChange(const URLRequest & request,RequestWaitState state)229 void NetworkDelegate::OnRequestWaitStateChange(const URLRequest& request,
230                                                RequestWaitState state) {
231 }
232 
233 }  // namespace net
234