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 options.lpszAutoConfigUrl = base::ASCIIToUTF16(pac_url_.spec()).c_str(); |
cpu_(ooo_6.6-7.5)
2014/11/03 17:33:27
looks buggy, the c_str() is that of a temporary st
Lei Zhang
2014/11/03 23:02:10
Whoops, undone.
| |
58 options.lpszAutoConfigUrl = pac_url_wide.c_str(); | |
59 | 58 |
60 WINHTTP_PROXY_INFO info = {0}; | 59 WINHTTP_PROXY_INFO info = {0}; |
61 DCHECK(session_handle_); | 60 DCHECK(session_handle_); |
62 | 61 |
63 // Per http://msdn.microsoft.com/en-us/library/aa383153(VS.85).aspx, it is | 62 // 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. | 63 // 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 | 64 // 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 | 65 // get good performance in the case where WinHTTP uses an out-of-process |
67 // resolver. This is important for Vista and Win2k3. | 66 // resolver. This is important for Vista and Win2k3. |
68 BOOL ok = WinHttpGetProxyForUrl(session_handle_, | 67 BOOL ok = WinHttpGetProxyForUrl(session_handle_, |
69 base::ASCIIToWide(query_url.spec()).c_str(), | 68 base::ASCIIToUTF16(query_url.spec()).c_str(), |
70 &options, &info); | 69 &options, &info); |
71 if (!ok) { | 70 if (!ok) { |
72 if (ERROR_WINHTTP_LOGIN_FAILURE == GetLastError()) { | 71 if (ERROR_WINHTTP_LOGIN_FAILURE == GetLastError()) { |
73 options.fAutoLogonIfChallenged = TRUE; | 72 options.fAutoLogonIfChallenged = TRUE; |
74 ok = WinHttpGetProxyForUrl( | 73 ok = WinHttpGetProxyForUrl( |
75 session_handle_, base::ASCIIToWide(query_url.spec()).c_str(), | 74 session_handle_, base::ASCIIToUTF16(query_url.spec()).c_str(), |
76 &options, &info); | 75 &options, &info); |
77 } | 76 } |
78 if (!ok) { | 77 if (!ok) { |
79 DWORD error = GetLastError(); | 78 DWORD error = GetLastError(); |
80 // If we got here because of RPC timeout during out of process PAC | 79 // 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. | 80 // resolution, no further requests on this session are going to work. |
82 if (ERROR_WINHTTP_TIMEOUT == error || | 81 if (ERROR_WINHTTP_TIMEOUT == error || |
83 ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR == error) { | 82 ERROR_WINHTTP_AUTO_PROXY_SERVICE_ERROR == error) { |
84 CloseWinHttpSession(); | 83 CloseWinHttpSession(); |
85 } | 84 } |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
165 } | 164 } |
166 | 165 |
167 void ProxyResolverWinHttp::CloseWinHttpSession() { | 166 void ProxyResolverWinHttp::CloseWinHttpSession() { |
168 if (session_handle_) { | 167 if (session_handle_) { |
169 WinHttpCloseHandle(session_handle_); | 168 WinHttpCloseHandle(session_handle_); |
170 session_handle_ = NULL; | 169 session_handle_ = NULL; |
171 } | 170 } |
172 } | 171 } |
173 | 172 |
174 } // namespace net | 173 } // namespace net |
OLD | NEW |