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