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,
38 DCHECK(CalledOnValidThread());
39 OnProxyFallback(bad_proxy, net_error, did_fallback);
42 int NetworkDelegate::NotifyBeforeSendHeaders(
43 URLRequest* request, const CompletionCallback& callback,
44 HttpRequestHeaders* headers) {
45 DCHECK(CalledOnValidThread());
47 DCHECK(!callback.is_null());
48 return OnBeforeSendHeaders(request, callback, headers);
51 void NetworkDelegate::NotifyBeforeSendProxyHeaders(
53 const ProxyInfo& proxy_info,
54 HttpRequestHeaders* headers) {
55 DCHECK(CalledOnValidThread());
57 OnBeforeSendProxyHeaders(request, proxy_info, headers);
60 void NetworkDelegate::NotifySendHeaders(URLRequest* request,
61 const HttpRequestHeaders& headers) {
62 DCHECK(CalledOnValidThread());
63 OnSendHeaders(request, headers);
66 int NetworkDelegate::NotifyHeadersReceived(
68 const CompletionCallback& callback,
69 const HttpResponseHeaders* original_response_headers,
70 scoped_refptr<HttpResponseHeaders>* override_response_headers,
71 GURL* allowed_unsafe_redirect_url) {
72 DCHECK(CalledOnValidThread());
73 DCHECK(original_response_headers);
74 DCHECK(!callback.is_null());
75 return OnHeadersReceived(request,
77 original_response_headers,
78 override_response_headers,
79 allowed_unsafe_redirect_url);
82 void NetworkDelegate::NotifyResponseStarted(URLRequest* request) {
83 DCHECK(CalledOnValidThread());
85 OnResponseStarted(request);
88 void NetworkDelegate::NotifyRawBytesRead(const URLRequest& request,
90 DCHECK(CalledOnValidThread());
91 OnRawBytesRead(request, bytes_read);
94 void NetworkDelegate::NotifyBeforeRedirect(URLRequest* request,
95 const GURL& new_location) {
96 DCHECK(CalledOnValidThread());
98 OnBeforeRedirect(request, new_location);
101 void NetworkDelegate::NotifyCompleted(URLRequest* request, bool started) {
102 DCHECK(CalledOnValidThread());
104 OnCompleted(request, started);
107 void NetworkDelegate::NotifyURLRequestDestroyed(URLRequest* request) {
108 DCHECK(CalledOnValidThread());
110 OnURLRequestDestroyed(request);
113 void NetworkDelegate::NotifyPACScriptError(int line_number,
114 const base::string16& error) {
115 DCHECK(CalledOnValidThread());
116 OnPACScriptError(line_number, error);
119 NetworkDelegate::AuthRequiredResponse NetworkDelegate::NotifyAuthRequired(
121 const AuthChallengeInfo& auth_info,
122 const AuthCallback& callback,
123 AuthCredentials* credentials) {
124 DCHECK(CalledOnValidThread());
125 return OnAuthRequired(request, auth_info, callback, credentials);
128 int NetworkDelegate::NotifyBeforeSocketStreamConnect(
129 SocketStream* socket,
130 const CompletionCallback& callback) {
131 DCHECK(CalledOnValidThread());
133 DCHECK(!callback.is_null());
134 return OnBeforeSocketStreamConnect(socket, callback);
137 bool NetworkDelegate::CanGetCookies(const URLRequest& request,
138 const CookieList& cookie_list) {
139 DCHECK(CalledOnValidThread());
140 DCHECK(!(request.load_flags() & net::LOAD_DO_NOT_SEND_COOKIES));
141 return OnCanGetCookies(request, cookie_list);
144 bool NetworkDelegate::CanSetCookie(const URLRequest& request,
145 const std::string& cookie_line,
146 CookieOptions* options) {
147 DCHECK(CalledOnValidThread());
148 DCHECK(!(request.load_flags() & net::LOAD_DO_NOT_SAVE_COOKIES));
149 return OnCanSetCookie(request, cookie_line, options);
152 bool NetworkDelegate::CanAccessFile(const URLRequest& request,
153 const base::FilePath& path) const {
154 DCHECK(CalledOnValidThread());
155 return OnCanAccessFile(request, path);
158 bool NetworkDelegate::CanThrottleRequest(const URLRequest& request) const {
159 DCHECK(CalledOnValidThread());
160 return OnCanThrottleRequest(request);
163 bool NetworkDelegate::CanEnablePrivacyMode(
165 const GURL& first_party_for_cookies) const {
166 DCHECK(CalledOnValidThread());
167 return OnCanEnablePrivacyMode(url, first_party_for_cookies);
170 int NetworkDelegate::OnBeforeURLRequest(URLRequest* request,
171 const CompletionCallback& callback,
176 void NetworkDelegate::OnResolveProxy(
179 const ProxyService& proxy_service,
183 void NetworkDelegate::OnProxyFallback(const ProxyServer& bad_proxy,
188 int NetworkDelegate::OnBeforeSendHeaders(URLRequest* request,
189 const CompletionCallback& callback,
190 HttpRequestHeaders* headers) {
194 void NetworkDelegate::OnBeforeSendProxyHeaders(
196 const ProxyInfo& proxy_info,
197 HttpRequestHeaders* headers) {
200 void NetworkDelegate::OnSendHeaders(URLRequest* request,
201 const HttpRequestHeaders& headers) {
204 int NetworkDelegate::OnHeadersReceived(
206 const CompletionCallback& callback,
207 const HttpResponseHeaders* original_response_headers,
208 scoped_refptr<HttpResponseHeaders>* override_response_headers,
209 GURL* allowed_unsafe_redirect_url) {
213 void NetworkDelegate::OnBeforeRedirect(URLRequest* request,
214 const GURL& new_location) {
217 void NetworkDelegate::OnResponseStarted(URLRequest* request) {
220 void NetworkDelegate::OnRawBytesRead(const URLRequest& request,
224 void NetworkDelegate::OnCompleted(URLRequest* request, bool started) {
227 void NetworkDelegate::OnURLRequestDestroyed(URLRequest* request) {
230 void NetworkDelegate::OnPACScriptError(int line_number,
231 const base::string16& error) {
234 NetworkDelegate::AuthRequiredResponse NetworkDelegate::OnAuthRequired(
236 const AuthChallengeInfo& auth_info,
237 const AuthCallback& callback,
238 AuthCredentials* credentials) {
239 return AUTH_REQUIRED_RESPONSE_NO_ACTION;
242 bool NetworkDelegate::OnCanGetCookies(const URLRequest& request,
243 const CookieList& cookie_list) {
247 bool NetworkDelegate::OnCanSetCookie(const URLRequest& request,
248 const std::string& cookie_line,
249 CookieOptions* options) {
253 bool NetworkDelegate::OnCanAccessFile(const URLRequest& request,
254 const base::FilePath& path) const {
258 bool NetworkDelegate::OnCanThrottleRequest(const URLRequest& request) const {
262 bool NetworkDelegate::OnCanEnablePrivacyMode(
264 const GURL& first_party_for_cookies) const {
268 int NetworkDelegate::OnBeforeSocketStreamConnect(
269 SocketStream* socket,
270 const CompletionCallback& callback) {