| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "net/proxy/proxy_resolver_winhttp.h" | 5 #include "net/proxy/proxy_resolver_winhttp.h" |
| 6 | 6 |
| 7 #include <windows.h> | 7 #include <windows.h> |
| 8 #include <winhttp.h> | 8 #include <winhttp.h> |
| 9 | 9 |
| 10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 | 47 |
| 48 // If we have been given an empty PAC url, then use auto-detection. | 48 // If we have been given an empty PAC url, then use auto-detection. |
| 49 // | 49 // |
| 50 // NOTE: We just use DNS-based auto-detection here like Firefox. We do this | 50 // NOTE: We just use DNS-based auto-detection here like Firefox. We do this |
| 51 // to avoid WinHTTP's auto-detection code, which while more featureful (it | 51 // to avoid WinHTTP's auto-detection code, which while more featureful (it |
| 52 // supports DHCP based auto-detection) also appears to have issues. | 52 // supports DHCP based auto-detection) also appears to have issues. |
| 53 // | 53 // |
| 54 WINHTTP_AUTOPROXY_OPTIONS options = {0}; | 54 WINHTTP_AUTOPROXY_OPTIONS options = {0}; |
| 55 options.fAutoLogonIfChallenged = FALSE; | 55 options.fAutoLogonIfChallenged = FALSE; |
| 56 options.dwFlags = WINHTTP_AUTOPROXY_CONFIG_URL; | 56 options.dwFlags = WINHTTP_AUTOPROXY_CONFIG_URL; |
| 57 std::wstring pac_url_wide = base::ASCIIToWide(pac_url_.spec()); | 57 base::string16 pac_url16 = base::ASCIIToUTF16(pac_url_.spec()); |
| 58 options.lpszAutoConfigUrl = pac_url_wide.c_str(); | 58 options.lpszAutoConfigUrl = pac_url16.c_str(); |
| 59 | 59 |
| 60 WINHTTP_PROXY_INFO info = {0}; | 60 WINHTTP_PROXY_INFO info = {0}; |
| 61 DCHECK(session_handle_); | 61 DCHECK(session_handle_); |
| 62 | 62 |
| 63 // Per http://msdn.microsoft.com/en-us/library/aa383153(VS.85).aspx, it is | 63 // Per http://msdn.microsoft.com/en-us/library/aa383153(VS.85).aspx, it is |
| 64 // necessary to first try resolving with fAutoLogonIfChallenged set to false. | 64 // necessary to first try resolving with fAutoLogonIfChallenged set to false. |
| 65 // Otherwise, we fail over to trying it with a value of true. This way we | 65 // Otherwise, we fail over to trying it with a value of true. This way we |
| 66 // get good performance in the case where WinHTTP uses an out-of-process | 66 // get good performance in the case where WinHTTP uses an out-of-process |
| 67 // resolver. This is important for Vista and Win2k3. | 67 // resolver. This is important for Vista and Win2k3. |
| 68 BOOL ok = WinHttpGetProxyForUrl(session_handle_, | 68 BOOL ok = WinHttpGetProxyForUrl(session_handle_, |
| 69 base::ASCIIToWide(query_url.spec()).c_str(), | 69 base::ASCIIToUTF16(query_url.spec()).c_str(), |
| 70 &options, &info); | 70 &options, &info); |
| 71 if (!ok) { | 71 if (!ok) { |
| 72 if (ERROR_WINHTTP_LOGIN_FAILURE == GetLastError()) { | 72 if (ERROR_WINHTTP_LOGIN_FAILURE == GetLastError()) { |
| 73 options.fAutoLogonIfChallenged = TRUE; | 73 options.fAutoLogonIfChallenged = TRUE; |
| 74 ok = WinHttpGetProxyForUrl( | 74 ok = WinHttpGetProxyForUrl( |
| 75 session_handle_, base::ASCIIToWide(query_url.spec()).c_str(), | 75 session_handle_, base::ASCIIToUTF16(query_url.spec()).c_str(), |
| 76 &options, &info); | 76 &options, &info); |
| 77 } | 77 } |
| 78 if (!ok) { | 78 if (!ok) { |
| 79 DWORD error = GetLastError(); | 79 DWORD error = GetLastError(); |
| 80 // If we got here because of RPC timeout during out of process PAC | 80 // If we got here because of RPC timeout during out of process PAC |
| 81 // resolution, no further requests on this session are going to work. | 81 // resolution, no further requests on this session are going to work. |
| 82 if (ERROR_WINHTTP_TIMEOUT == error || | 82 if (ERROR_WINHTTP_TIMEOUT == error || |
| 83 ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR == error) { | 83 ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR == error) { |
| 84 CloseWinHttpSession(); | 84 CloseWinHttpSession(); |
| 85 } | 85 } |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 } | 165 } |
| 166 | 166 |
| 167 void ProxyResolverWinHttp::CloseWinHttpSession() { | 167 void ProxyResolverWinHttp::CloseWinHttpSession() { |
| 168 if (session_handle_) { | 168 if (session_handle_) { |
| 169 WinHttpCloseHandle(session_handle_); | 169 WinHttpCloseHandle(session_handle_); |
| 170 session_handle_ = NULL; | 170 session_handle_ = NULL; |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 | 173 |
| 174 } // namespace net | 174 } // namespace net |
| OLD | NEW |