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 27 matching lines...) Expand all Loading... |
38 } | 38 } |
39 | 39 |
40 static void FreeInfo(WINHTTP_PROXY_INFO* info) { | 40 static void FreeInfo(WINHTTP_PROXY_INFO* info) { |
41 if (info->lpszProxy) | 41 if (info->lpszProxy) |
42 GlobalFree(info->lpszProxy); | 42 GlobalFree(info->lpszProxy); |
43 if (info->lpszProxyBypass) | 43 if (info->lpszProxyBypass) |
44 GlobalFree(info->lpszProxyBypass); | 44 GlobalFree(info->lpszProxyBypass); |
45 } | 45 } |
46 | 46 |
47 ProxyResolverWinHttp::ProxyResolverWinHttp() | 47 ProxyResolverWinHttp::ProxyResolverWinHttp() |
48 : ProxyResolver(true), session_handle_(NULL) { | 48 : ProxyResolver(false /*expects_pac_bytes*/), session_handle_(NULL) { |
49 } | 49 } |
50 | 50 |
51 ProxyResolverWinHttp::~ProxyResolverWinHttp() { | 51 ProxyResolverWinHttp::~ProxyResolverWinHttp() { |
52 CloseWinHttpSession(); | 52 CloseWinHttpSession(); |
53 } | 53 } |
54 | 54 |
55 int ProxyResolverWinHttp::GetProxyForURL(const GURL& query_url, | 55 int ProxyResolverWinHttp::GetProxyForURL(const GURL& query_url, |
56 const GURL& pac_url, | 56 ProxyInfo* results, |
57 ProxyInfo* results) { | 57 CompletionCallback* /*callback*/, |
| 58 RequestHandle* /*request*/) { |
58 // If we don't have a WinHTTP session, then create a new one. | 59 // If we don't have a WinHTTP session, then create a new one. |
59 if (!session_handle_ && !OpenWinHttpSession()) | 60 if (!session_handle_ && !OpenWinHttpSession()) |
60 return ERR_FAILED; | 61 return ERR_FAILED; |
61 | 62 |
62 // If we have been given an empty PAC url, then use auto-detection. | 63 // If we have been given an empty PAC url, then use auto-detection. |
63 // | 64 // |
64 // NOTE: We just use DNS-based auto-detection here like Firefox. We do this | 65 // NOTE: We just use DNS-based auto-detection here like Firefox. We do this |
65 // to avoid WinHTTP's auto-detection code, which while more featureful (it | 66 // to avoid WinHTTP's auto-detection code, which while more featureful (it |
66 // supports DHCP based auto-detection) also appears to have issues. | 67 // supports DHCP based auto-detection) also appears to have issues. |
67 // | 68 // |
68 WINHTTP_AUTOPROXY_OPTIONS options = {0}; | 69 WINHTTP_AUTOPROXY_OPTIONS options = {0}; |
69 options.fAutoLogonIfChallenged = FALSE; | 70 options.fAutoLogonIfChallenged = FALSE; |
70 options.dwFlags = WINHTTP_AUTOPROXY_CONFIG_URL; | 71 options.dwFlags = WINHTTP_AUTOPROXY_CONFIG_URL; |
71 std::wstring pac_url_wide = ASCIIToWide(pac_url.spec()); | 72 std::wstring pac_url_wide = ASCIIToWide(pac_url_.spec()); |
72 options.lpszAutoConfigUrl = | 73 options.lpszAutoConfigUrl = |
73 pac_url_wide.empty() ? L"http://wpad/wpad.dat" : pac_url_wide.c_str(); | 74 pac_url_wide.empty() ? L"http://wpad/wpad.dat" : pac_url_wide.c_str(); |
74 | 75 |
75 WINHTTP_PROXY_INFO info = {0}; | 76 WINHTTP_PROXY_INFO info = {0}; |
76 DCHECK(session_handle_); | 77 DCHECK(session_handle_); |
77 | 78 |
78 // Per http://msdn.microsoft.com/en-us/library/aa383153(VS.85).aspx, it is | 79 // Per http://msdn.microsoft.com/en-us/library/aa383153(VS.85).aspx, it is |
79 // necessary to first try resolving with fAutoLogonIfChallenged set to false. | 80 // necessary to first try resolving with fAutoLogonIfChallenged set to false. |
80 // Otherwise, we fail over to trying it with a value of true. This way we | 81 // Otherwise, we fail over to trying it with a value of true. This way we |
81 // get good performance in the case where WinHTTP uses an out-of-process | 82 // get good performance in the case where WinHTTP uses an out-of-process |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 break; | 128 break; |
128 default: | 129 default: |
129 NOTREACHED(); | 130 NOTREACHED(); |
130 rv = ERR_FAILED; | 131 rv = ERR_FAILED; |
131 } | 132 } |
132 | 133 |
133 FreeInfo(&info); | 134 FreeInfo(&info); |
134 return rv; | 135 return rv; |
135 } | 136 } |
136 | 137 |
| 138 void ProxyResolverWinHttp::CancelRequest(RequestHandle request) { |
| 139 // This is a synchronous ProxyResolver; no possibility for async requests. |
| 140 NOTREACHED(); |
| 141 } |
| 142 |
| 143 void ProxyResolverWinHttp::SetPacScriptByUrlInternal(const GURL& pac_url) { |
| 144 pac_url_ = pac_url; |
| 145 } |
| 146 |
137 bool ProxyResolverWinHttp::OpenWinHttpSession() { | 147 bool ProxyResolverWinHttp::OpenWinHttpSession() { |
138 DCHECK(!session_handle_); | 148 DCHECK(!session_handle_); |
139 session_handle_ = WinHttpOpen(NULL, | 149 session_handle_ = WinHttpOpen(NULL, |
140 WINHTTP_ACCESS_TYPE_NO_PROXY, | 150 WINHTTP_ACCESS_TYPE_NO_PROXY, |
141 WINHTTP_NO_PROXY_NAME, | 151 WINHTTP_NO_PROXY_NAME, |
142 WINHTTP_NO_PROXY_BYPASS, | 152 WINHTTP_NO_PROXY_BYPASS, |
143 0); | 153 0); |
144 if (!session_handle_) | 154 if (!session_handle_) |
145 return false; | 155 return false; |
146 | 156 |
147 // Since this session handle will never be used for WinHTTP connections, | 157 // Since this session handle will never be used for WinHTTP connections, |
148 // these timeouts don't really mean much individually. However, WinHTTP's | 158 // these timeouts don't really mean much individually. However, WinHTTP's |
149 // out of process PAC resolution will use a combined (sum of all timeouts) | 159 // out of process PAC resolution will use a combined (sum of all timeouts) |
150 // value to wait for an RPC reply. | 160 // value to wait for an RPC reply. |
151 BOOL rv = WinHttpSetTimeouts(session_handle_, 10000, 10000, 5000, 5000); | 161 BOOL rv = WinHttpSetTimeouts(session_handle_, 10000, 10000, 5000, 5000); |
152 DCHECK(rv); | 162 DCHECK(rv); |
153 | 163 |
154 return true; | 164 return true; |
155 } | 165 } |
156 | 166 |
157 void ProxyResolverWinHttp::CloseWinHttpSession() { | 167 void ProxyResolverWinHttp::CloseWinHttpSession() { |
158 if (session_handle_) { | 168 if (session_handle_) { |
159 WinHttpCloseHandle(session_handle_); | 169 WinHttpCloseHandle(session_handle_); |
160 session_handle_ = NULL; | 170 session_handle_ = NULL; |
161 } | 171 } |
162 } | 172 } |
163 | 173 |
164 } // namespace net | 174 } // namespace net |
OLD | NEW |