| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2008 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 #ifndef NET_HTTP_HTTP_TRANSACTION_WINHTTP_H__ | |
| 6 #define NET_HTTP_HTTP_TRANSACTION_WINHTTP_H__ | |
| 7 | |
| 8 #include <windows.h> | |
| 9 #include <winhttp.h> | |
| 10 | |
| 11 #include <string> | |
| 12 | |
| 13 #include "base/ref_counted.h" | |
| 14 #include "net/base/completion_callback.h" | |
| 15 #include "net/http/http_response_info.h" | |
| 16 #include "net/http/http_transaction.h" | |
| 17 #include "net/http/http_transaction_factory.h" | |
| 18 #include "net/proxy/proxy_service.h" | |
| 19 | |
| 20 namespace net { | |
| 21 | |
| 22 class UploadDataStream; | |
| 23 | |
| 24 class HttpTransactionWinHttp : public HttpTransaction { | |
| 25 class Session; // Represents a WinHttp session handle. | |
| 26 class SessionCallback; | |
| 27 public: | |
| 28 // Instantiate this class, and use it to create HttpTransaction objects. | |
| 29 class Factory : public HttpTransactionFactory { | |
| 30 public: | |
| 31 explicit Factory(ProxyService* proxy_service) | |
| 32 : session_(NULL), proxy_service_(proxy_service), is_suspended_(false) { | |
| 33 DCHECK(proxy_service); | |
| 34 } | |
| 35 ~Factory(); | |
| 36 | |
| 37 virtual HttpTransaction* CreateTransaction(); | |
| 38 virtual HttpCache* GetCache(); | |
| 39 virtual void Suspend(bool suspend); | |
| 40 | |
| 41 private: | |
| 42 Session* session_; | |
| 43 ProxyService* proxy_service_; | |
| 44 bool is_suspended_; | |
| 45 DISALLOW_EVIL_CONSTRUCTORS(Factory); | |
| 46 }; | |
| 47 | |
| 48 virtual ~HttpTransactionWinHttp(); | |
| 49 | |
| 50 // HttpTransaction methods: | |
| 51 virtual int Start(const HttpRequestInfo*, CompletionCallback*); | |
| 52 virtual int RestartIgnoringLastError(CompletionCallback*); | |
| 53 virtual int RestartWithAuth(const std::wstring&, | |
| 54 const std::wstring&, | |
| 55 CompletionCallback*); | |
| 56 virtual int Read(char*, int, CompletionCallback*); | |
| 57 virtual const HttpResponseInfo* GetResponseInfo() const; | |
| 58 virtual LoadState GetLoadState() const; | |
| 59 virtual uint64 GetUploadProgress() const; | |
| 60 | |
| 61 static void CALLBACK StatusCallback(HINTERNET handle, | |
| 62 DWORD_PTR context, | |
| 63 DWORD status, | |
| 64 LPVOID status_info, | |
| 65 DWORD status_info_len); | |
| 66 | |
| 67 // Called via the message loop in response to a WinHttp status callback. | |
| 68 void HandleStatusCallback(DWORD status, | |
| 69 DWORD_PTR result, | |
| 70 DWORD error, | |
| 71 DWORD secure_failure); | |
| 72 | |
| 73 private: | |
| 74 friend class Factory; | |
| 75 | |
| 76 // Methods ------------------------------------------------------------------ | |
| 77 | |
| 78 HttpTransactionWinHttp(Session* session, const ProxyInfo* info); | |
| 79 | |
| 80 void DoCallback(int rv); | |
| 81 int ResolveProxy(); | |
| 82 bool OpenRequest(); | |
| 83 int SendRequest(); | |
| 84 bool ReopenRequest(); | |
| 85 int Restart(CompletionCallback* callback); | |
| 86 int RestartInternal(); | |
| 87 int DidResolveProxy(); | |
| 88 int DidReceiveError(DWORD error, DWORD secure_failure); | |
| 89 int DidSendRequest(); | |
| 90 int DidWriteData(DWORD num_bytes); | |
| 91 int DidReadData(DWORD num_bytes); | |
| 92 void LogTransactionMetrics() const; | |
| 93 int DidReceiveHeaders(); | |
| 94 | |
| 95 int PopulateAuthChallenge(); | |
| 96 void ApplyAuth(); | |
| 97 | |
| 98 std::string GetRequestHeaders() const; | |
| 99 X509Certificate* GetServerCertificate() const; | |
| 100 int GetSecurityBits() const; | |
| 101 void PopulateSSLInfo(DWORD secure_failure); | |
| 102 | |
| 103 void OnProxyInfoAvailable(int result); | |
| 104 | |
| 105 // Variables ---------------------------------------------------------------- | |
| 106 | |
| 107 Session* session_; | |
| 108 const HttpRequestInfo* request_; | |
| 109 | |
| 110 // A copy of request_->load_flags that we can modify in | |
| 111 // RestartIgnoringLastError. | |
| 112 int load_flags_; | |
| 113 | |
| 114 // Optional auth data for proxy and origin server. | |
| 115 scoped_refptr<AuthData> proxy_auth_; | |
| 116 scoped_refptr<AuthData> server_auth_; | |
| 117 | |
| 118 // The key for looking up the auth data in the auth cache, consisting | |
| 119 // of the scheme, host, and port of the request URL and the realm in | |
| 120 // the auth challenge. | |
| 121 std::string proxy_auth_cache_key_; | |
| 122 std::string server_auth_cache_key_; | |
| 123 | |
| 124 // The peer of the connection. For a direct connection, this is the | |
| 125 // destination server. If we use a proxy, this is the proxy. | |
| 126 std::string connect_peer_; | |
| 127 | |
| 128 // The last error from SendRequest that occurred. Used by | |
| 129 // RestartIgnoringLastError to adjust load_flags_ to ignore this error. | |
| 130 DWORD last_error_; | |
| 131 | |
| 132 // This value is non-negative when we are streaming a response over a | |
| 133 // non-keepalive connection. We decrement this value as we receive data to | |
| 134 // allow us to discover end-of-file. This is used to workaround a bug in | |
| 135 // WinHttp (see bug 1063336). | |
| 136 int64 content_length_remaining_; | |
| 137 | |
| 138 ProxyInfo proxy_info_; | |
| 139 ProxyService::PacRequest* pac_request_; | |
| 140 CompletionCallbackImpl<HttpTransactionWinHttp> proxy_callback_; | |
| 141 | |
| 142 HttpResponseInfo response_; | |
| 143 CompletionCallback* callback_; | |
| 144 HINTERNET connect_handle_; | |
| 145 HINTERNET request_handle_; | |
| 146 scoped_refptr<SessionCallback> session_callback_; | |
| 147 scoped_ptr<UploadDataStream> upload_stream_; | |
| 148 uint64 upload_progress_; | |
| 149 | |
| 150 // True if the URL's scheme is https. | |
| 151 bool is_https_; | |
| 152 | |
| 153 // True if the SSL server doesn't support TLS but also cannot correctly | |
| 154 // negotiate with a TLS-enabled client to use SSL 3.0. The workaround is | |
| 155 // for the client to downgrade to SSL 3.0 and retry the SSL handshake. | |
| 156 bool is_tls_intolerant_; | |
| 157 | |
| 158 // True if revocation checking of the SSL server certificate is enabled. | |
| 159 bool rev_checking_enabled_; | |
| 160 | |
| 161 // A flag to indicate whether or not we already have proxy information. | |
| 162 // If false, we will attempt to resolve proxy information from the proxy | |
| 163 // service. This flag is set to true if proxy information is supplied by | |
| 164 // a client. | |
| 165 bool have_proxy_info_; | |
| 166 | |
| 167 // If WinHTTP is still using our caller's data (upload data or read buffer), | |
| 168 // we need to wait for the HANDLE_CLOSING status notification after we close | |
| 169 // the request handle. | |
| 170 // | |
| 171 // There are only five WinHTTP functions that work asynchronously (listed in | |
| 172 // the order in which they're called): | |
| 173 // WinHttpSendRequest, WinHttpWriteData, WinHttpReceiveResponse, | |
| 174 // WinHttpQueryDataAvailable, WinHttpReadData. | |
| 175 // WinHTTP is using our caller's data during the two time intervals: | |
| 176 // - From the first WinHttpWriteData call to the completion of the last | |
| 177 // WinHttpWriteData call. (We may call WinHttpWriteData multiple times.) | |
| 178 // - From the WinHttpReadData call to its completion. | |
| 179 // We set need_to_wait_for_handle_closing_ to true at the beginning of these | |
| 180 // time intervals and set it to false at the end. We're not sandwiching the | |
| 181 // intervals as tightly as possible. (To do that, we'd need to give WinHTTP | |
| 182 // worker threads access to the need_to_wait_for_handle_closing_ flag and | |
| 183 // worry about thread synchronization issues.) | |
| 184 bool need_to_wait_for_handle_closing_; | |
| 185 | |
| 186 // True if we have called WinHttpRequestThrottle::SubmitRequest but haven't | |
| 187 // called WinHttpRequestThrottle::NotifyRequestDone. | |
| 188 bool request_submitted_; | |
| 189 | |
| 190 // True if we have used the username/password embedded in the URL. | |
| 191 bool used_embedded_credentials_; | |
| 192 | |
| 193 DISALLOW_EVIL_CONSTRUCTORS(HttpTransactionWinHttp); | |
| 194 }; | |
| 195 | |
| 196 } // namespace net | |
| 197 | |
| 198 #endif // NET_HTTP_HTTP_TRANSACTION_WINHTTP_H__ | |
| 199 | |
| OLD | NEW |