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/url_request/url_request.h" 10 11 namespace net { 12 13 int NetworkDelegate::NotifyBeforeURLRequest( 14 URLRequest* request, const CompletionCallback& callback, 15 GURL* new_url) { 16 DCHECK(CalledOnValidThread()); 17 DCHECK(request); 18 DCHECK(!callback.is_null()); 19 return OnBeforeURLRequest(request, callback, new_url); 20 } 21 22 int NetworkDelegate::NotifyBeforeSendHeaders( 23 URLRequest* request, const CompletionCallback& callback, 24 HttpRequestHeaders* headers) { 25 DCHECK(CalledOnValidThread()); 26 DCHECK(headers); 27 DCHECK(!callback.is_null()); 28 return OnBeforeSendHeaders(request, callback, headers); 29 } 30 31 void NetworkDelegate::NotifySendHeaders(URLRequest* request, 32 const HttpRequestHeaders& headers) { 33 DCHECK(CalledOnValidThread()); 34 OnSendHeaders(request, headers); 35 } 36 37 int NetworkDelegate::NotifyHeadersReceived( 38 URLRequest* request, 39 const CompletionCallback& callback, 40 const HttpResponseHeaders* original_response_headers, 41 scoped_refptr<HttpResponseHeaders>* override_response_headers) { 42 DCHECK(CalledOnValidThread()); 43 DCHECK(original_response_headers); 44 DCHECK(!callback.is_null()); 45 return OnHeadersReceived(request, callback, original_response_headers, 46 override_response_headers); 47 } 48 49 void NetworkDelegate::NotifyResponseStarted(URLRequest* request) { 50 DCHECK(CalledOnValidThread()); 51 DCHECK(request); 52 OnResponseStarted(request); 53 } 54 55 void NetworkDelegate::NotifyRawBytesRead(const URLRequest& request, 56 int bytes_read) { 57 DCHECK(CalledOnValidThread()); 58 OnRawBytesRead(request, bytes_read); 59 } 60 61 void NetworkDelegate::NotifyBeforeRedirect(URLRequest* request, 62 const GURL& new_location) { 63 DCHECK(CalledOnValidThread()); 64 DCHECK(request); 65 OnBeforeRedirect(request, new_location); 66 } 67 68 void NetworkDelegate::NotifyCompleted(URLRequest* request, bool started) { 69 DCHECK(CalledOnValidThread()); 70 DCHECK(request); 71 OnCompleted(request, started); 72 } 73 74 void NetworkDelegate::NotifyURLRequestDestroyed(URLRequest* request) { 75 DCHECK(CalledOnValidThread()); 76 DCHECK(request); 77 OnURLRequestDestroyed(request); 78 } 79 80 void NetworkDelegate::NotifyPACScriptError(int line_number, 81 const base::string16& error) { 82 DCHECK(CalledOnValidThread()); 83 OnPACScriptError(line_number, error); 84 } 85 86 NetworkDelegate::AuthRequiredResponse NetworkDelegate::NotifyAuthRequired( 87 URLRequest* request, 88 const AuthChallengeInfo& auth_info, 89 const AuthCallback& callback, 90 AuthCredentials* credentials) { 91 DCHECK(CalledOnValidThread()); 92 return OnAuthRequired(request, auth_info, callback, credentials); 93 } 94 95 bool NetworkDelegate::CanGetCookies(const URLRequest& request, 96 const CookieList& cookie_list) { 97 DCHECK(CalledOnValidThread()); 98 DCHECK(!(request.load_flags() & net::LOAD_DO_NOT_SEND_COOKIES)); 99 return OnCanGetCookies(request, cookie_list); 100 } 101 102 bool NetworkDelegate::CanSetCookie(const URLRequest& request, 103 const std::string& cookie_line, 104 CookieOptions* options) { 105 DCHECK(CalledOnValidThread()); 106 DCHECK(!(request.load_flags() & net::LOAD_DO_NOT_SAVE_COOKIES)); 107 return OnCanSetCookie(request, cookie_line, options); 108 } 109 110 bool NetworkDelegate::CanAccessFile(const URLRequest& request, 111 const base::FilePath& path) const { 112 DCHECK(CalledOnValidThread()); 113 return OnCanAccessFile(request, path); 114 } 115 116 bool NetworkDelegate::CanThrottleRequest(const URLRequest& request) const { 117 DCHECK(CalledOnValidThread()); 118 return OnCanThrottleRequest(request); 119 } 120 121 bool NetworkDelegate::CanEnablePrivacyMode( 122 const GURL& url, 123 const GURL& first_party_for_cookies) const { 124 DCHECK(CalledOnValidThread()); 125 return OnCanEnablePrivacyMode(url, first_party_for_cookies); 126 } 127 128 bool NetworkDelegate::OnCanEnablePrivacyMode( 129 const GURL& url, 130 const GURL& first_party_for_cookies) const { 131 // Default implementation disables privacy mode. 132 return false; 133 } 134 135 int NetworkDelegate::NotifyBeforeSocketStreamConnect( 136 SocketStream* socket, 137 const CompletionCallback& callback) { 138 DCHECK(CalledOnValidThread()); 139 DCHECK(socket); 140 DCHECK(!callback.is_null()); 141 return OnBeforeSocketStreamConnect(socket, callback); 142 } 143 144 void NetworkDelegate::NotifyRequestWaitStateChange(const URLRequest& request, 145 RequestWaitState state) { 146 DCHECK(CalledOnValidThread()); 147 OnRequestWaitStateChange(request, state); 148 } 149 150 } // namespace net 151