Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 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 | 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/histogram.h" | 10 #include "base/histogram.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 if (!session_handle_ && !OpenWinHttpSession()) | 83 if (!session_handle_ && !OpenWinHttpSession()) |
| 84 return ERR_FAILED; | 84 return ERR_FAILED; |
| 85 | 85 |
| 86 // If we have been given an empty PAC url, then use auto-detection. | 86 // If we have been given an empty PAC url, then use auto-detection. |
| 87 // | 87 // |
| 88 // NOTE: We just use DNS-based auto-detection here like Firefox. We do this | 88 // NOTE: We just use DNS-based auto-detection here like Firefox. We do this |
| 89 // to avoid WinHTTP's auto-detection code, which while more featureful (it | 89 // to avoid WinHTTP's auto-detection code, which while more featureful (it |
| 90 // supports DHCP based auto-detection) also appears to have issues. | 90 // supports DHCP based auto-detection) also appears to have issues. |
| 91 // | 91 // |
| 92 WINHTTP_AUTOPROXY_OPTIONS options = {0}; | 92 WINHTTP_AUTOPROXY_OPTIONS options = {0}; |
| 93 options.fAutoLogonIfChallenged = TRUE; | 93 options.fAutoLogonIfChallenged = FALSE; |
| 94 options.dwFlags = WINHTTP_AUTOPROXY_CONFIG_URL; | 94 options.dwFlags = WINHTTP_AUTOPROXY_CONFIG_URL; |
| 95 std::wstring pac_url_wide = ASCIIToWide(pac_url); | 95 std::wstring pac_url_wide = ASCIIToWide(pac_url); |
| 96 options.lpszAutoConfigUrl = | 96 options.lpszAutoConfigUrl = |
| 97 pac_url_wide.empty() ? L"http://wpad/wpad.dat" : pac_url_wide.c_str(); | 97 pac_url_wide.empty() ? L"http://wpad/wpad.dat" : pac_url_wide.c_str(); |
| 98 | 98 |
| 99 WINHTTP_PROXY_INFO info = {0}; | 99 WINHTTP_PROXY_INFO info = {0}; |
| 100 DCHECK(session_handle_); | 100 DCHECK(session_handle_); |
| 101 if (!CallWinHttpGetProxyForUrl( | 101 |
| 102 session_handle_, ASCIIToWide(query_url).c_str(), &options, &info)) { | 102 // Per http://msdn.microsoft.com/en-us/library/aa383153(VS.85).aspx, it is |
| 103 // necessary to first try resolving with fAutoLogonIfChallenged set to false. | |
| 104 // Otherwise, we failover to trying it with a value of true. This way we get | |
|
wtc
2008/09/09 19:03:10
Nit: "fail over", two words.
| |
| 105 // good performance in the case where WinHTTP uses an out-of-proc resolver. | |
|
wtc
2008/09/09 19:03:10
Nit: "out-of-process"
| |
| 106 // This is important for Vista and Win2k3. | |
| 107 BOOL ok = CallWinHttpGetProxyForUrl( | |
| 108 session_handle_, ASCIIToWide(query_url).c_str(), &options, &info); | |
| 109 if (!ok) { | |
| 103 DWORD error = GetLastError(); | 110 DWORD error = GetLastError(); |
| 104 LOG(ERROR) << "WinHttpGetProxyForUrl failed: " << error; | 111 LOG(ERROR) << "WinHttpGetProxyForUrl failed: " << error; |
| 105 | 112 if (ERROR_WINHTTP_LOGIN_FAILURE == error) { |
| 106 // If we got here because of RPC timeout during out of process PAC | 113 options.fAutoLogonIfChallenged = TRUE; |
| 107 // resolution, no further requests on this session are going to work. | 114 ok = CallWinHttpGetProxyForUrl( |
| 108 if ((ERROR_WINHTTP_TIMEOUT == error) || | 115 session_handle_, ASCIIToWide(query_url).c_str(), &options, &info); |
| 109 (ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR == error)) { | 116 if (!ok) { |
| 110 CloseWinHttpSession(); | 117 error = GetLastError(); |
| 118 LOG(ERROR) << "WinHttpGetProxyForUrl failed: " << error; | |
|
Nicolas Sylvain
2008/09/09 15:18:12
Can you put this line in the other "if (!ok)" unde
| |
| 119 } | |
| 111 } | 120 } |
| 112 | 121 if(!ok) { |
| 113 return ERR_FAILED; // TODO(darin): Bug 1189288: translate error code. | 122 // If we got here because of RPC timeout during out of process PAC |
| 123 // resolution, no further requests on this session are going to work. | |
| 124 if (ERROR_WINHTTP_TIMEOUT == error || | |
| 125 ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR == error) { | |
| 126 CloseWinHttpSession(); | |
| 127 } | |
| 128 return ERR_FAILED; // TODO(darin): Bug 1189288: translate error code. | |
| 129 } | |
| 114 } | 130 } |
| 115 | 131 |
| 116 int rv = OK; | 132 int rv = OK; |
| 117 | 133 |
| 118 switch (info.dwAccessType) { | 134 switch (info.dwAccessType) { |
| 119 case WINHTTP_ACCESS_TYPE_NO_PROXY: | 135 case WINHTTP_ACCESS_TYPE_NO_PROXY: |
| 120 results->UseDirect(); | 136 results->UseDirect(); |
| 121 break; | 137 break; |
| 122 case WINHTTP_ACCESS_TYPE_NAMED_PROXY: | 138 case WINHTTP_ACCESS_TYPE_NAMED_PROXY: |
| 123 results->UseNamedProxy(WideToASCII(info.lpszProxy)); | 139 results->UseNamedProxy(WideToASCII(info.lpszProxy)); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 153 | 169 |
| 154 void ProxyResolverWinHttp::CloseWinHttpSession() { | 170 void ProxyResolverWinHttp::CloseWinHttpSession() { |
| 155 if (session_handle_) { | 171 if (session_handle_) { |
| 156 WinHttpCloseHandle(session_handle_); | 172 WinHttpCloseHandle(session_handle_); |
| 157 session_handle_ = NULL; | 173 session_handle_ = NULL; |
| 158 } | 174 } |
| 159 } | 175 } |
| 160 | 176 |
| 161 } // namespace net | 177 } // namespace net |
| 162 | 178 |
| OLD | NEW |