OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_BASE_NETWORK_DELEGATE_H_ | 5 #ifndef NET_BASE_NETWORK_DELEGATE_H_ |
6 #define NET_BASE_NETWORK_DELEGATE_H_ | 6 #define NET_BASE_NETWORK_DELEGATE_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/callback.h" | 10 #include "base/callback.h" |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 // member functions will be called by the respective public notification | 111 // member functions will be called by the respective public notification |
112 // member function, which will perform basic sanity checking. | 112 // member function, which will perform basic sanity checking. |
113 | 113 |
114 // Called before a request is sent. Allows the delegate to rewrite the URL | 114 // Called before a request is sent. Allows the delegate to rewrite the URL |
115 // being fetched by modifying |new_url|. |callback| and |new_url| are valid | 115 // being fetched by modifying |new_url|. |callback| and |new_url| are valid |
116 // only until OnURLRequestDestroyed is called for this request. Returns a net | 116 // only until OnURLRequestDestroyed is called for this request. Returns a net |
117 // status code, generally either OK to continue with the request or | 117 // status code, generally either OK to continue with the request or |
118 // ERR_IO_PENDING if the result is not ready yet. A status code other than OK | 118 // ERR_IO_PENDING if the result is not ready yet. A status code other than OK |
119 // and ERR_IO_PENDING will cancel the request and report the status code as | 119 // and ERR_IO_PENDING will cancel the request and report the status code as |
120 // the reason. | 120 // the reason. |
| 121 // |
| 122 // The default implementation returns OK (continue with request). |
121 virtual int OnBeforeURLRequest(URLRequest* request, | 123 virtual int OnBeforeURLRequest(URLRequest* request, |
122 const CompletionCallback& callback, | 124 const CompletionCallback& callback, |
123 GURL* new_url) = 0; | 125 GURL* new_url); |
124 | 126 |
125 // Called right before the HTTP headers are sent. Allows the delegate to | 127 // Called right before the HTTP headers are sent. Allows the delegate to |
126 // read/write |headers| before they get sent out. |callback| and |headers| are | 128 // read/write |headers| before they get sent out. |callback| and |headers| are |
127 // valid only until OnCompleted or OnURLRequestDestroyed is called for this | 129 // valid only until OnCompleted or OnURLRequestDestroyed is called for this |
128 // request. | 130 // request. |
129 // Returns a net status code. | 131 // See OnBeforeURLRequest for return value description. Returns OK by default. |
130 virtual int OnBeforeSendHeaders(URLRequest* request, | 132 virtual int OnBeforeSendHeaders(URLRequest* request, |
131 const CompletionCallback& callback, | 133 const CompletionCallback& callback, |
132 HttpRequestHeaders* headers) = 0; | 134 HttpRequestHeaders* headers); |
133 | 135 |
134 // Called right before the HTTP request(s) are being sent to the network. | 136 // Called right before the HTTP request(s) are being sent to the network. |
135 // |headers| is only valid until OnCompleted or OnURLRequestDestroyed is | 137 // |headers| is only valid until OnCompleted or OnURLRequestDestroyed is |
136 // called for this request. | 138 // called for this request. |
137 virtual void OnSendHeaders(URLRequest* request, | 139 virtual void OnSendHeaders(URLRequest* request, |
138 const HttpRequestHeaders& headers) = 0; | 140 const HttpRequestHeaders& headers); |
139 | 141 |
140 // Called for HTTP requests when the headers have been received. Returns a net | 142 // Called for HTTP requests when the headers have been received. |
141 // status code, generally either OK to continue with the request or | |
142 // ERR_IO_PENDING if the result is not ready yet. A status code other than OK | |
143 // and ERR_IO_PENDING will cancel the request and report the status code as | |
144 // the reason. | |
145 // |original_response_headers| contains the headers as received over the | 143 // |original_response_headers| contains the headers as received over the |
146 // network, these must not be modified. |override_response_headers| can be set | 144 // network, these must not be modified. |override_response_headers| can be set |
147 // to new values, that should be considered as overriding | 145 // to new values, that should be considered as overriding |
148 // |original_response_headers|. | 146 // |original_response_headers|. |
149 // |callback|, |original_response_headers|, and |override_response_headers| | 147 // |callback|, |original_response_headers|, and |override_response_headers| |
150 // are only valid until OnURLRequestDestroyed is called for this request. | 148 // are only valid until OnURLRequestDestroyed is called for this request. |
| 149 // See OnBeforeURLRequest for return value description. Returns OK by default. |
151 virtual int OnHeadersReceived( | 150 virtual int OnHeadersReceived( |
152 URLRequest* request, | 151 URLRequest* request, |
153 const CompletionCallback& callback, | 152 const CompletionCallback& callback, |
154 const HttpResponseHeaders* original_response_headers, | 153 const HttpResponseHeaders* original_response_headers, |
155 scoped_refptr<HttpResponseHeaders>* override_response_headers) = 0; | 154 scoped_refptr<HttpResponseHeaders>* override_response_headers); |
156 | 155 |
157 // Called right after a redirect response code was received. | 156 // Called right after a redirect response code was received. |
158 // |new_location| is only valid until OnURLRequestDestroyed is called for this | 157 // |new_location| is only valid until OnURLRequestDestroyed is called for this |
159 // request. | 158 // request. |
160 virtual void OnBeforeRedirect(URLRequest* request, | 159 virtual void OnBeforeRedirect(URLRequest* request, |
161 const GURL& new_location) = 0; | 160 const GURL& new_location); |
162 | 161 |
163 // This corresponds to URLRequestDelegate::OnResponseStarted. | 162 // This corresponds to URLRequestDelegate::OnResponseStarted. |
164 virtual void OnResponseStarted(URLRequest* request) = 0; | 163 virtual void OnResponseStarted(URLRequest* request); |
165 | 164 |
166 // Called every time we read raw bytes. | 165 // Called every time we read raw bytes. |
167 virtual void OnRawBytesRead(const URLRequest& request, int bytes_read) = 0; | 166 virtual void OnRawBytesRead(const URLRequest& request, int bytes_read); |
168 | 167 |
169 // Indicates that the URL request has been completed or failed. | 168 // Indicates that the URL request has been completed or failed. |
170 // |started| indicates whether the request has been started. If false, | 169 // |started| indicates whether the request has been started. If false, |
171 // some information like the socket address is not available. | 170 // some information like the socket address is not available. |
172 virtual void OnCompleted(URLRequest* request, bool started) = 0; | 171 virtual void OnCompleted(URLRequest* request, bool started); |
173 | 172 |
174 // Called when an URLRequest is being destroyed. Note that the request is | 173 // Called when an URLRequest is being destroyed. Note that the request is |
175 // being deleted, so it's not safe to call any methods that may result in | 174 // being deleted, so it's not safe to call any methods that may result in |
176 // a virtual method call. | 175 // a virtual method call. |
177 virtual void OnURLRequestDestroyed(URLRequest* request) = 0; | 176 virtual void OnURLRequestDestroyed(URLRequest* request); |
178 | 177 |
179 // Corresponds to ProxyResolverJSBindings::OnError. | 178 // Corresponds to ProxyResolverJSBindings::OnError. |
180 virtual void OnPACScriptError(int line_number, | 179 virtual void OnPACScriptError(int line_number, |
181 const base::string16& error) = 0; | 180 const base::string16& error); |
182 | 181 |
183 // Called when a request receives an authentication challenge | 182 // Called when a request receives an authentication challenge |
184 // specified by |auth_info|, and is unable to respond using cached | 183 // specified by |auth_info|, and is unable to respond using cached |
185 // credentials. |callback| and |credentials| must be non-NULL, and must | 184 // credentials. |callback| and |credentials| must be non-NULL, and must |
186 // be valid until OnURLRequestDestroyed is called for |request|. | 185 // be valid until OnURLRequestDestroyed is called for |request|. |
187 // | 186 // |
188 // The following return values are allowed: | 187 // The following return values are allowed: |
189 // - AUTH_REQUIRED_RESPONSE_NO_ACTION: |auth_info| is observed, but | 188 // - AUTH_REQUIRED_RESPONSE_NO_ACTION: |auth_info| is observed, but |
190 // no action is being taken on it. | 189 // no action is being taken on it. |
191 // - AUTH_REQUIRED_RESPONSE_SET_AUTH: |credentials| is filled in with | 190 // - AUTH_REQUIRED_RESPONSE_SET_AUTH: |credentials| is filled in with |
192 // a username and password, which should be used in a response to | 191 // a username and password, which should be used in a response to |
193 // |auth_info|. | 192 // |auth_info|. |
194 // - AUTH_REQUIRED_RESPONSE_CANCEL_AUTH: The authentication challenge | 193 // - AUTH_REQUIRED_RESPONSE_CANCEL_AUTH: The authentication challenge |
195 // should not be attempted. | 194 // should not be attempted. |
196 // - AUTH_REQUIRED_RESPONSE_IO_PENDING: The action will be decided | 195 // - AUTH_REQUIRED_RESPONSE_IO_PENDING: The action will be decided |
197 // asynchronously. |callback| will be invoked when the decision is made, | 196 // asynchronously. |callback| will be invoked when the decision is made, |
198 // and one of the other AuthRequiredResponse values will be passed in with | 197 // and one of the other AuthRequiredResponse values will be passed in with |
199 // the same semantics as described above. | 198 // the same semantics as described above. |
200 virtual AuthRequiredResponse OnAuthRequired( | 199 virtual AuthRequiredResponse OnAuthRequired( |
201 URLRequest* request, | 200 URLRequest* request, |
202 const AuthChallengeInfo& auth_info, | 201 const AuthChallengeInfo& auth_info, |
203 const AuthCallback& callback, | 202 const AuthCallback& callback, |
204 AuthCredentials* credentials) = 0; | 203 AuthCredentials* credentials); |
205 | 204 |
206 // Called when reading cookies to allow the network delegate to block access | 205 // Called when reading cookies to allow the network delegate to block access |
207 // to the cookie. This method will never be invoked when | 206 // to the cookie. This method will never be invoked when |
208 // LOAD_DO_NOT_SEND_COOKIES is specified. | 207 // LOAD_DO_NOT_SEND_COOKIES is specified. |
209 virtual bool OnCanGetCookies(const URLRequest& request, | 208 virtual bool OnCanGetCookies(const URLRequest& request, |
210 const CookieList& cookie_list) = 0; | 209 const CookieList& cookie_list); |
211 | 210 |
212 // Called when a cookie is set to allow the network delegate to block access | 211 // Called when a cookie is set to allow the network delegate to block access |
213 // to the cookie. This method will never be invoked when | 212 // to the cookie. This method will never be invoked when |
214 // LOAD_DO_NOT_SAVE_COOKIES is specified. | 213 // LOAD_DO_NOT_SAVE_COOKIES is specified. |
215 virtual bool OnCanSetCookie(const URLRequest& request, | 214 virtual bool OnCanSetCookie(const URLRequest& request, |
216 const std::string& cookie_line, | 215 const std::string& cookie_line, |
217 CookieOptions* options) = 0; | 216 CookieOptions* options); |
218 | 217 |
219 // Called when a file access is attempted to allow the network delegate to | 218 // Called when a file access is attempted to allow the network delegate to |
220 // allow or block access to the given file path. Returns true if access is | 219 // allow or block access to the given file path. Returns true if access is |
221 // allowed. | 220 // allowed. |
222 virtual bool OnCanAccessFile(const URLRequest& request, | 221 virtual bool OnCanAccessFile(const URLRequest& request, |
223 const base::FilePath& path) const = 0; | 222 const base::FilePath& path) const; |
224 | 223 |
225 // Returns true if the given request may be rejected when the | 224 // Returns true if the given request may be rejected when the |
226 // URLRequestThrottlerManager believes the server servicing the | 225 // URLRequestThrottlerManager believes the server servicing the |
227 // request is overloaded or down. | 226 // request is overloaded or down. |
228 virtual bool OnCanThrottleRequest(const URLRequest& request) const = 0; | 227 virtual bool OnCanThrottleRequest(const URLRequest& request) const; |
229 | 228 |
230 // Returns true if the given |url| has to be requested over connection that | 229 // Returns true if the given |url| has to be requested over connection that |
231 // is not tracked by the server. Usually is false, unless user privacy | 230 // is not tracked by the server. Usually is false, unless user privacy |
232 // settings block cookies from being get or set. | 231 // settings block cookies from being get or set. |
233 virtual bool OnCanEnablePrivacyMode( | 232 virtual bool OnCanEnablePrivacyMode( |
234 const GURL& url, | 233 const GURL& url, |
235 const GURL& first_party_for_cookies) const; | 234 const GURL& first_party_for_cookies) const; |
236 | 235 |
237 // Called before a SocketStream tries to connect. | 236 // Called before a SocketStream tries to connect. |
| 237 // See OnBeforeURLRequest for return value description. Returns OK by default. |
238 virtual int OnBeforeSocketStreamConnect( | 238 virtual int OnBeforeSocketStreamConnect( |
239 SocketStream* socket, const CompletionCallback& callback) = 0; | 239 SocketStream* socket, const CompletionCallback& callback); |
240 | 240 |
241 // Called when the completion of a URLRequest is blocking on a cache | 241 // Called when the completion of a URLRequest is blocking on a cache |
242 // action or a network action, or when that is no longer the case. | 242 // action or a network action, or when that is no longer the case. |
243 // REQUEST_WAIT_STATE_RESET indicates for a given URLRequest | 243 // REQUEST_WAIT_STATE_RESET indicates for a given URLRequest |
244 // cancellation of any pending waits for this request. | 244 // cancellation of any pending waits for this request. |
245 virtual void OnRequestWaitStateChange(const URLRequest& request, | 245 virtual void OnRequestWaitStateChange(const URLRequest& request, |
246 RequestWaitState state) = 0; | 246 RequestWaitState state); |
247 }; | 247 }; |
248 | 248 |
249 } // namespace net | 249 } // namespace net |
250 | 250 |
251 #endif // NET_BASE_NETWORK_DELEGATE_H_ | 251 #endif // NET_BASE_NETWORK_DELEGATE_H_ |
OLD | NEW |