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/macros.h" | 10 #include "base/macros.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 class ProxyResolverWinHttp : public ProxyResolver { | 53 class ProxyResolverWinHttp : public ProxyResolver { |
54 public: | 54 public: |
55 ProxyResolverWinHttp( | 55 ProxyResolverWinHttp( |
56 const scoped_refptr<ProxyResolverScriptData>& script_data); | 56 const scoped_refptr<ProxyResolverScriptData>& script_data); |
57 ~ProxyResolverWinHttp() override; | 57 ~ProxyResolverWinHttp() override; |
58 | 58 |
59 // ProxyResolver implementation: | 59 // ProxyResolver implementation: |
60 int GetProxyForURL(const GURL& url, | 60 int GetProxyForURL(const GURL& url, |
61 ProxyInfo* results, | 61 ProxyInfo* results, |
62 const CompletionCallback& /*callback*/, | 62 const CompletionCallback& /*callback*/, |
63 RequestHandle* /*request*/, | 63 std::unique_ptr<Request>* /*request*/, |
64 const NetLogWithSource& /*net_log*/) override; | 64 const NetLogWithSource& /*net_log*/) override; |
65 void CancelRequest(RequestHandle request) override; | |
66 | |
67 LoadState GetLoadState(RequestHandle request) const override; | |
68 | 65 |
69 private: | 66 private: |
70 bool OpenWinHttpSession(); | 67 bool OpenWinHttpSession(); |
71 void CloseWinHttpSession(); | 68 void CloseWinHttpSession(); |
72 | 69 |
73 // Proxy configuration is cached on the session handle. | 70 // Proxy configuration is cached on the session handle. |
74 HINTERNET session_handle_; | 71 HINTERNET session_handle_; |
75 | 72 |
76 const GURL pac_url_; | 73 const GURL pac_url_; |
77 | 74 |
78 DISALLOW_COPY_AND_ASSIGN(ProxyResolverWinHttp); | 75 DISALLOW_COPY_AND_ASSIGN(ProxyResolverWinHttp); |
79 }; | 76 }; |
80 | 77 |
81 ProxyResolverWinHttp::ProxyResolverWinHttp( | 78 ProxyResolverWinHttp::ProxyResolverWinHttp( |
82 const scoped_refptr<ProxyResolverScriptData>& script_data) | 79 const scoped_refptr<ProxyResolverScriptData>& script_data) |
83 : session_handle_(NULL), | 80 : session_handle_(NULL), |
84 pac_url_(script_data->type() == ProxyResolverScriptData::TYPE_AUTO_DETECT | 81 pac_url_(script_data->type() == ProxyResolverScriptData::TYPE_AUTO_DETECT |
85 ? GURL("http://wpad/wpad.dat") | 82 ? GURL("http://wpad/wpad.dat") |
86 : script_data->url()) { | 83 : script_data->url()) { |
87 } | 84 } |
88 | 85 |
89 ProxyResolverWinHttp::~ProxyResolverWinHttp() { | 86 ProxyResolverWinHttp::~ProxyResolverWinHttp() { |
90 CloseWinHttpSession(); | 87 CloseWinHttpSession(); |
91 } | 88 } |
92 | 89 |
93 int ProxyResolverWinHttp::GetProxyForURL(const GURL& query_url, | 90 int ProxyResolverWinHttp::GetProxyForURL(const GURL& query_url, |
94 ProxyInfo* results, | 91 ProxyInfo* results, |
95 const CompletionCallback& /*callback*/, | 92 const CompletionCallback& /*callback*/, |
96 RequestHandle* /*request*/, | 93 std::unique_ptr<Request>* /*request*/, |
97 const NetLogWithSource& /*net_log*/) { | 94 const NetLogWithSource& /*net_log*/) { |
98 // If we don't have a WinHTTP session, then create a new one. | 95 // If we don't have a WinHTTP session, then create a new one. |
99 if (!session_handle_ && !OpenWinHttpSession()) | 96 if (!session_handle_ && !OpenWinHttpSession()) |
100 return ERR_FAILED; | 97 return ERR_FAILED; |
101 | 98 |
102 // If we have been given an empty PAC url, then use auto-detection. | 99 // If we have been given an empty PAC url, then use auto-detection. |
103 // | 100 // |
104 // NOTE: We just use DNS-based auto-detection here like Firefox. We do this | 101 // NOTE: We just use DNS-based auto-detection here like Firefox. We do this |
105 // to avoid WinHTTP's auto-detection code, which while more featureful (it | 102 // to avoid WinHTTP's auto-detection code, which while more featureful (it |
106 // supports DHCP based auto-detection) also appears to have issues. | 103 // supports DHCP based auto-detection) also appears to have issues. |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 break; | 163 break; |
167 default: | 164 default: |
168 NOTREACHED(); | 165 NOTREACHED(); |
169 rv = ERR_FAILED; | 166 rv = ERR_FAILED; |
170 } | 167 } |
171 | 168 |
172 FreeInfo(&info); | 169 FreeInfo(&info); |
173 return rv; | 170 return rv; |
174 } | 171 } |
175 | 172 |
176 void ProxyResolverWinHttp::CancelRequest(RequestHandle request) { | |
177 // This is a synchronous ProxyResolver; no possibility for async requests. | |
178 NOTREACHED(); | |
179 } | |
180 | |
181 LoadState ProxyResolverWinHttp::GetLoadState(RequestHandle request) const { | |
182 NOTREACHED(); | |
183 return LOAD_STATE_IDLE; | |
184 } | |
185 | |
186 bool ProxyResolverWinHttp::OpenWinHttpSession() { | 173 bool ProxyResolverWinHttp::OpenWinHttpSession() { |
187 DCHECK(!session_handle_); | 174 DCHECK(!session_handle_); |
188 session_handle_ = WinHttpOpen(NULL, | 175 session_handle_ = WinHttpOpen(NULL, |
189 WINHTTP_ACCESS_TYPE_NO_PROXY, | 176 WINHTTP_ACCESS_TYPE_NO_PROXY, |
190 WINHTTP_NO_PROXY_NAME, | 177 WINHTTP_NO_PROXY_NAME, |
191 WINHTTP_NO_PROXY_BYPASS, | 178 WINHTTP_NO_PROXY_BYPASS, |
192 0); | 179 0); |
193 if (!session_handle_) | 180 if (!session_handle_) |
194 return false; | 181 return false; |
195 | 182 |
(...skipping 23 matching lines...) Expand all Loading... |
219 int ProxyResolverFactoryWinHttp::CreateProxyResolver( | 206 int ProxyResolverFactoryWinHttp::CreateProxyResolver( |
220 const scoped_refptr<ProxyResolverScriptData>& pac_script, | 207 const scoped_refptr<ProxyResolverScriptData>& pac_script, |
221 std::unique_ptr<ProxyResolver>* resolver, | 208 std::unique_ptr<ProxyResolver>* resolver, |
222 const CompletionCallback& callback, | 209 const CompletionCallback& callback, |
223 std::unique_ptr<Request>* request) { | 210 std::unique_ptr<Request>* request) { |
224 resolver->reset(new ProxyResolverWinHttp(pac_script)); | 211 resolver->reset(new ProxyResolverWinHttp(pac_script)); |
225 return OK; | 212 return OK; |
226 } | 213 } |
227 | 214 |
228 } // namespace net | 215 } // namespace net |
OLD | NEW |