| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> |
| 10 |
| 9 #include "base/callback.h" | 11 #include "base/callback.h" |
| 10 #include "base/string16.h" | 12 #include "base/string16.h" |
| 11 #include "base/threading/non_thread_safe.h" | 13 #include "base/threading/non_thread_safe.h" |
| 12 #include "net/base/auth.h" | 14 #include "net/base/auth.h" |
| 13 #include "net/base/completion_callback.h" | 15 #include "net/base/completion_callback.h" |
| 14 | 16 |
| 15 class GURL; | 17 class GURL; |
| 16 | 18 |
| 17 namespace net { | 19 namespace net { |
| 18 | 20 |
| 19 // NOTE: Layering violations! | 21 // NOTE: Layering violations! |
| 20 // We decided to accept these violations (depending | 22 // We decided to accept these violations (depending |
| 21 // on other net/ submodules from net/base/), because otherwise NetworkDelegate | 23 // on other net/ submodules from net/base/), because otherwise NetworkDelegate |
| 22 // would have to be broken up into too many smaller interfaces targeted to each | 24 // would have to be broken up into too many smaller interfaces targeted to each |
| 23 // submodule. Also, since the lower levels in net/ may callback into higher | 25 // submodule. Also, since the lower levels in net/ may callback into higher |
| 24 // levels, we may encounter dangerous casting issues. | 26 // levels, we may encounter dangerous casting issues. |
| 25 // | 27 // |
| 26 // NOTE: It is not okay to add any compile-time dependencies on symbols outside | 28 // NOTE: It is not okay to add any compile-time dependencies on symbols outside |
| 27 // of net/base here, because we have a net_base library. Forward declarations | 29 // of net/base here, because we have a net_base library. Forward declarations |
| 28 // are ok. | 30 // are ok. |
| 31 class CookieList; |
| 32 class CookieOptions; |
| 29 class HttpRequestHeaders; | 33 class HttpRequestHeaders; |
| 30 class HttpResponseHeaders; | 34 class HttpResponseHeaders; |
| 31 class URLRequest; | 35 class URLRequest; |
| 32 | 36 |
| 33 class NetworkDelegate : public base::NonThreadSafe { | 37 class NetworkDelegate : public base::NonThreadSafe { |
| 34 public: | 38 public: |
| 35 // AuthRequiredResponse indicates how a NetworkDelegate handles an | 39 // AuthRequiredResponse indicates how a NetworkDelegate handles an |
| 36 // OnAuthRequired call. It's placed in this file to prevent url_request.h | 40 // OnAuthRequired call. It's placed in this file to prevent url_request.h |
| 37 // from having to include network_delegate.h. | 41 // from having to include network_delegate.h. |
| 38 enum AuthRequiredResponse { | 42 enum AuthRequiredResponse { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 66 const GURL& new_location); | 70 const GURL& new_location); |
| 67 void NotifyResponseStarted(URLRequest* request); | 71 void NotifyResponseStarted(URLRequest* request); |
| 68 void NotifyRawBytesRead(const URLRequest& request, int bytes_read); | 72 void NotifyRawBytesRead(const URLRequest& request, int bytes_read); |
| 69 void NotifyCompleted(URLRequest* request, bool started); | 73 void NotifyCompleted(URLRequest* request, bool started); |
| 70 void NotifyURLRequestDestroyed(URLRequest* request); | 74 void NotifyURLRequestDestroyed(URLRequest* request); |
| 71 void NotifyPACScriptError(int line_number, const string16& error); | 75 void NotifyPACScriptError(int line_number, const string16& error); |
| 72 AuthRequiredResponse NotifyAuthRequired(URLRequest* request, | 76 AuthRequiredResponse NotifyAuthRequired(URLRequest* request, |
| 73 const AuthChallengeInfo& auth_info, | 77 const AuthChallengeInfo& auth_info, |
| 74 const AuthCallback& callback, | 78 const AuthCallback& callback, |
| 75 AuthCredentials* credentials); | 79 AuthCredentials* credentials); |
| 80 bool NotifyReadingCookies(const URLRequest* request, |
| 81 const CookieList& cookie_list); |
| 82 bool NotifySettingCookie(const URLRequest* request, |
| 83 const std::string& cookie_line, |
| 84 CookieOptions* options); |
| 76 | 85 |
| 77 private: | 86 private: |
| 78 // This is the interface for subclasses of NetworkDelegate to implement. This | 87 // This is the interface for subclasses of NetworkDelegate to implement. This |
| 79 // member functions will be called by the respective public notification | 88 // member functions will be called by the respective public notification |
| 80 // member function, which will perform basic sanity checking. | 89 // member function, which will perform basic sanity checking. |
| 81 | 90 |
| 82 // Called before a request is sent. Allows the delegate to rewrite the URL | 91 // Called before a request is sent. Allows the delegate to rewrite the URL |
| 83 // being fetched by modifying |new_url|. |callback| and |new_url| are valid | 92 // being fetched by modifying |new_url|. |callback| and |new_url| are valid |
| 84 // only until OnURLRequestDestroyed is called for this request. Returns a net | 93 // only until OnURLRequestDestroyed is called for this request. Returns a net |
| 85 // status code, generally either OK to continue with the request or | 94 // status code, generally either OK to continue with the request or |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 // should not be attempted. | 171 // should not be attempted. |
| 163 // - AUTH_REQUIRED_RESPONSE_IO_PENDING: The action will be decided | 172 // - AUTH_REQUIRED_RESPONSE_IO_PENDING: The action will be decided |
| 164 // asynchronously. |callback| will be invoked when the decision is made, | 173 // asynchronously. |callback| will be invoked when the decision is made, |
| 165 // and one of the other AuthRequiredResponse values will be passed in with | 174 // and one of the other AuthRequiredResponse values will be passed in with |
| 166 // the same semantics as described above. | 175 // the same semantics as described above. |
| 167 virtual AuthRequiredResponse OnAuthRequired( | 176 virtual AuthRequiredResponse OnAuthRequired( |
| 168 URLRequest* request, | 177 URLRequest* request, |
| 169 const AuthChallengeInfo& auth_info, | 178 const AuthChallengeInfo& auth_info, |
| 170 const AuthCallback& callback, | 179 const AuthCallback& callback, |
| 171 AuthCredentials* credentials) = 0; | 180 AuthCredentials* credentials) = 0; |
| 181 |
| 182 // Called when reading cookies to allow the network delegate to block access |
| 183 // to the cookie. This method will never be invoked when |
| 184 // LOAD_DO_NOT_SEND_COOKIES is specified. |
| 185 virtual bool CanGetCookies(const URLRequest* request, |
| 186 const CookieList& cookie_list) = 0; |
| 187 |
| 188 // Called when a cookie is set to allow the network delegate to block access |
| 189 // to the cookie. This method will never be invoked when |
| 190 // LOAD_DO_NOT_SAVE_COOKIES is specified. |
| 191 virtual bool CanSetCookie(const URLRequest* request, |
| 192 const std::string& cookie_line, |
| 193 CookieOptions* options) = 0; |
| 194 |
| 172 }; | 195 }; |
| 173 | 196 |
| 174 } // namespace net | 197 } // namespace net |
| 175 | 198 |
| 176 #endif // NET_BASE_NETWORK_DELEGATE_H_ | 199 #endif // NET_BASE_NETWORK_DELEGATE_H_ |
| OLD | NEW |