| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_IMPL_H_ | 5 #ifndef NET_BASE_NETWORK_DELEGATE_IMPL_H_ |
| 6 #define NET_BASE_NETWORK_DELEGATE_IMPL_H_ | 6 #define NET_BASE_NETWORK_DELEGATE_IMPL_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 class HttpRequestHeaders; | 26 class HttpRequestHeaders; |
| 27 class HttpResponseHeaders; | 27 class HttpResponseHeaders; |
| 28 class ProxyInfo; | 28 class ProxyInfo; |
| 29 class URLRequest; | 29 class URLRequest; |
| 30 | 30 |
| 31 class NET_EXPORT NetworkDelegateImpl : public NetworkDelegate { | 31 class NET_EXPORT NetworkDelegateImpl : public NetworkDelegate { |
| 32 public: | 32 public: |
| 33 ~NetworkDelegateImpl() override {} | 33 ~NetworkDelegateImpl() override {} |
| 34 | 34 |
| 35 private: | 35 private: |
| 36 // This is the interface for subclasses of NetworkDelegate to implement. These | |
| 37 // member functions will be called by the respective public notification | |
| 38 // member function, which will perform basic sanity checking. | |
| 39 | |
| 40 // Called before a request is sent. Allows the delegate to rewrite the URL | |
| 41 // being fetched by modifying |new_url|. If set, the URL must be valid. The | |
| 42 // reference fragment from the original URL is not automatically appended to | |
| 43 // |new_url|; callers are responsible for copying the reference fragment if | |
| 44 // desired. | |
| 45 // |callback| and |new_url| are valid only until OnURLRequestDestroyed is | |
| 46 // called for this request. Returns a net status code, generally either OK to | |
| 47 // continue with the request or ERR_IO_PENDING if the result is not ready yet. | |
| 48 // A status code other than OK and ERR_IO_PENDING will cancel the request and | |
| 49 // report the status code as the reason. | |
| 50 // | |
| 51 // The default implementation returns OK (continue with request). | |
| 52 int OnBeforeURLRequest(URLRequest* request, | 36 int OnBeforeURLRequest(URLRequest* request, |
| 53 const CompletionCallback& callback, | 37 const CompletionCallback& callback, |
| 54 GURL* new_url) override; | 38 GURL* new_url) override; |
| 55 | 39 |
| 56 // Called right before the network transaction starts. Allows the delegate to | |
| 57 // read/write |headers| before they get sent out. |callback| and |headers| are | |
| 58 // valid only until OnCompleted or OnURLRequestDestroyed is called for this | |
| 59 // request. | |
| 60 // See OnBeforeURLRequest for return value description. Returns OK by default. | |
| 61 int OnBeforeStartTransaction(URLRequest* request, | 40 int OnBeforeStartTransaction(URLRequest* request, |
| 62 const CompletionCallback& callback, | 41 const CompletionCallback& callback, |
| 63 HttpRequestHeaders* headers) override; | 42 HttpRequestHeaders* headers) override; |
| 64 | 43 |
| 65 // Called after a connection is established , and just before headers are sent | |
| 66 // to the destination server (i.e., not called for HTTP CONNECT requests). For | |
| 67 // non-tunneled requests using HTTP proxies, |headers| will include any | |
| 68 // proxy-specific headers as well. Allows the delegate to read/write |headers| | |
| 69 // before they get sent out. |headers| is valid only until OnCompleted or | |
| 70 // OnURLRequestDestroyed is called for this request. | |
| 71 void OnBeforeSendHeaders(URLRequest* request, | 44 void OnBeforeSendHeaders(URLRequest* request, |
| 72 const ProxyInfo& proxy_info, | 45 const ProxyInfo& proxy_info, |
| 73 const ProxyRetryInfoMap& proxy_retry_info, | 46 const ProxyRetryInfoMap& proxy_retry_info, |
| 74 HttpRequestHeaders* headers) override; | 47 HttpRequestHeaders* headers) override; |
| 75 | 48 |
| 76 // Called right before the HTTP request(s) are being sent to the network. | |
| 77 // |headers| is only valid until OnCompleted or OnURLRequestDestroyed is | |
| 78 // called for this request. | |
| 79 void OnStartTransaction(URLRequest* request, | 49 void OnStartTransaction(URLRequest* request, |
| 80 const HttpRequestHeaders& headers) override; | 50 const HttpRequestHeaders& headers) override; |
| 81 | 51 |
| 82 // Called for HTTP requests when the headers have been received. | |
| 83 // |original_response_headers| contains the headers as received over the | |
| 84 // network, these must not be modified. |override_response_headers| can be set | |
| 85 // to new values, that should be considered as overriding | |
| 86 // |original_response_headers|. | |
| 87 // If the response is a redirect, and the Location response header value is | |
| 88 // identical to |allowed_unsafe_redirect_url|, then the redirect is never | |
| 89 // blocked and the reference fragment is not copied from the original URL | |
| 90 // to the redirection target. | |
| 91 // | |
| 92 // |callback|, |original_response_headers|, and |override_response_headers| | |
| 93 // are only valid until OnURLRequestDestroyed is called for this request. | |
| 94 // See OnBeforeURLRequest for return value description. Returns OK by default. | |
| 95 int OnHeadersReceived( | 52 int OnHeadersReceived( |
| 96 URLRequest* request, | 53 URLRequest* request, |
| 97 const CompletionCallback& callback, | 54 const CompletionCallback& callback, |
| 98 const HttpResponseHeaders* original_response_headers, | 55 const HttpResponseHeaders* original_response_headers, |
| 99 scoped_refptr<HttpResponseHeaders>* override_response_headers, | 56 scoped_refptr<HttpResponseHeaders>* override_response_headers, |
| 100 GURL* allowed_unsafe_redirect_url) override; | 57 GURL* allowed_unsafe_redirect_url) override; |
| 101 | 58 |
| 102 // Called right after a redirect response code was received. | |
| 103 // |new_location| is only valid until OnURLRequestDestroyed is called for this | |
| 104 // request. | |
| 105 void OnBeforeRedirect(URLRequest* request, const GURL& new_location) override; | 59 void OnBeforeRedirect(URLRequest* request, const GURL& new_location) override; |
| 106 | 60 |
| 107 // This corresponds to URLRequestDelegate::OnResponseStarted. | |
| 108 void OnResponseStarted(URLRequest* request, int net_error) override; | 61 void OnResponseStarted(URLRequest* request, int net_error) override; |
| 109 // Deprecated. | |
| 110 // TODO(maksims): Remove this; | |
| 111 void OnResponseStarted(URLRequest* request) override; | 62 void OnResponseStarted(URLRequest* request) override; |
| 112 | 63 |
| 113 // Called when bytes are received from the network, such as after receiving | |
| 114 // headers or reading raw response bytes. This includes localhost requests. | |
| 115 // |bytes_received| is the number of bytes measured at the application layer | |
| 116 // that have been received over the network for this request since the last | |
| 117 // time OnNetworkBytesReceived was called. |bytes_received| will always be | |
| 118 // greater than 0. | |
| 119 // Currently, this is only implemented for HTTP transactions, and | |
| 120 // |bytes_received| does not include TLS overhead or TCP retransmits. | |
| 121 void OnNetworkBytesReceived(URLRequest* request, | 64 void OnNetworkBytesReceived(URLRequest* request, |
| 122 int64_t bytes_received) override; | 65 int64_t bytes_received) override; |
| 123 | 66 |
| 124 // Called when bytes are sent over the network, such as when sending request | |
| 125 // headers or uploading request body bytes. This includes localhost requests. | |
| 126 // |bytes_sent| is the number of bytes measured at the application layer that | |
| 127 // have been sent over the network for this request since the last time | |
| 128 // OnNetworkBytesSent was called. |bytes_sent| will always be greater than 0. | |
| 129 // Currently, this is only implemented for HTTP transactions, and |bytes_sent| | |
| 130 // does not include TLS overhead or TCP retransmits. | |
| 131 void OnNetworkBytesSent(URLRequest* request, int64_t bytes_sent) override; | 67 void OnNetworkBytesSent(URLRequest* request, int64_t bytes_sent) override; |
| 132 | 68 |
| 133 // Indicates that the URL request has been completed or failed. | |
| 134 // |started| indicates whether the request has been started. If false, | |
| 135 // some information like the socket address is not available. | |
| 136 void OnCompleted(URLRequest* request, bool started, int net_error) override; | 69 void OnCompleted(URLRequest* request, bool started, int net_error) override; |
| 137 // Deprecated. | |
| 138 // TODO(maksims): Remove this; | |
| 139 void OnCompleted(URLRequest* request, bool started) override; | 70 void OnCompleted(URLRequest* request, bool started) override; |
| 140 | 71 |
| 141 // Called when an URLRequest is being destroyed. Note that the request is | |
| 142 // being deleted, so it's not safe to call any methods that may result in | |
| 143 // a virtual method call. | |
| 144 void OnURLRequestDestroyed(URLRequest* request) override; | 72 void OnURLRequestDestroyed(URLRequest* request) override; |
| 145 | 73 |
| 146 // Corresponds to ProxyResolverJSBindings::OnError. | |
| 147 void OnPACScriptError(int line_number, const base::string16& error) override; | 74 void OnPACScriptError(int line_number, const base::string16& error) override; |
| 148 | 75 |
| 149 // Called when a request receives an authentication challenge | |
| 150 // specified by |auth_info|, and is unable to respond using cached | |
| 151 // credentials. |callback| and |credentials| must be non-NULL, and must | |
| 152 // be valid until OnURLRequestDestroyed is called for |request|. | |
| 153 // | |
| 154 // The following return values are allowed: | |
| 155 // - AUTH_REQUIRED_RESPONSE_NO_ACTION: |auth_info| is observed, but | |
| 156 // no action is being taken on it. | |
| 157 // - AUTH_REQUIRED_RESPONSE_SET_AUTH: |credentials| is filled in with | |
| 158 // a username and password, which should be used in a response to | |
| 159 // |auth_info|. | |
| 160 // - AUTH_REQUIRED_RESPONSE_CANCEL_AUTH: The authentication challenge | |
| 161 // should not be attempted. | |
| 162 // - AUTH_REQUIRED_RESPONSE_IO_PENDING: The action will be decided | |
| 163 // asynchronously. |callback| will be invoked when the decision is made, | |
| 164 // and one of the other AuthRequiredResponse values will be passed in with | |
| 165 // the same semantics as described above. | |
| 166 AuthRequiredResponse OnAuthRequired(URLRequest* request, | 76 AuthRequiredResponse OnAuthRequired(URLRequest* request, |
| 167 const AuthChallengeInfo& auth_info, | 77 const AuthChallengeInfo& auth_info, |
| 168 const AuthCallback& callback, | 78 const AuthCallback& callback, |
| 169 AuthCredentials* credentials) override; | 79 AuthCredentials* credentials) override; |
| 170 | 80 |
| 171 // Called when reading cookies to allow the network delegate to block access | |
| 172 // to the cookie. This method will never be invoked when | |
| 173 // LOAD_DO_NOT_SEND_COOKIES is specified. | |
| 174 bool OnCanGetCookies(const URLRequest& request, | 81 bool OnCanGetCookies(const URLRequest& request, |
| 175 const CookieList& cookie_list) override; | 82 const CookieList& cookie_list) override; |
| 176 | 83 |
| 177 // Called when a cookie is set to allow the network delegate to block access | |
| 178 // to the cookie. This method will never be invoked when | |
| 179 // LOAD_DO_NOT_SAVE_COOKIES is specified. | |
| 180 bool OnCanSetCookie(const URLRequest& request, | 84 bool OnCanSetCookie(const URLRequest& request, |
| 181 const std::string& cookie_line, | 85 const std::string& cookie_line, |
| 182 CookieOptions* options) override; | 86 CookieOptions* options) override; |
| 183 | 87 |
| 184 // Called when a file access is attempted to allow the network delegate to | |
| 185 // allow or block access to the given file path. Returns true if access is | |
| 186 // allowed. | |
| 187 bool OnCanAccessFile(const URLRequest& request, | 88 bool OnCanAccessFile(const URLRequest& request, |
| 188 const base::FilePath& path) const override; | 89 const base::FilePath& path) const override; |
| 189 | 90 |
| 190 // Returns true if the given |url| has to be requested over connection that | |
| 191 // is not tracked by the server. Usually is false, unless user privacy | |
| 192 // settings block cookies from being get or set. | |
| 193 bool OnCanEnablePrivacyMode( | 91 bool OnCanEnablePrivacyMode( |
| 194 const GURL& url, | 92 const GURL& url, |
| 195 const GURL& first_party_for_cookies) const override; | 93 const GURL& first_party_for_cookies) const override; |
| 196 | 94 |
| 197 // Returns true if the embedder has enabled experimental cookie features. | |
| 198 bool OnAreExperimentalCookieFeaturesEnabled() const override; | 95 bool OnAreExperimentalCookieFeaturesEnabled() const override; |
| 199 | 96 |
| 200 // Called when the |referrer_url| for requesting |target_url| during handling | |
| 201 // of the |request| is does not comply with the referrer policy (e.g. a | |
| 202 // secure referrer for an insecure initial target). | |
| 203 // Returns true if the request should be cancelled. Otherwise, the referrer | |
| 204 // header is stripped from the request. | |
| 205 bool OnCancelURLRequestWithPolicyViolatingReferrerHeader( | 97 bool OnCancelURLRequestWithPolicyViolatingReferrerHeader( |
| 206 const URLRequest& request, | 98 const URLRequest& request, |
| 207 const GURL& target_url, | 99 const GURL& target_url, |
| 208 const GURL& referrer_url) const override; | 100 const GURL& referrer_url) const override; |
| 209 }; | 101 }; |
| 210 | 102 |
| 211 } // namespace net | 103 } // namespace net |
| 212 | 104 |
| 213 #endif // NET_BASE_NETWORK_DELEGATE_IMPL_H_ | 105 #endif // NET_BASE_NETWORK_DELEGATE_IMPL_H_ |
| OLD | NEW |