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