| 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_mac.h" | 5 #include "net/proxy/proxy_resolver_mac.h" |
| 6 | 6 |
| 7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/foundation_util.h" | 10 #include "base/mac/foundation_util.h" |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 class ProxyResolverMac : public ProxyResolver { | 66 class ProxyResolverMac : public ProxyResolver { |
| 67 public: | 67 public: |
| 68 explicit ProxyResolverMac( | 68 explicit ProxyResolverMac( |
| 69 const scoped_refptr<ProxyResolverScriptData>& script_data); | 69 const scoped_refptr<ProxyResolverScriptData>& script_data); |
| 70 ~ProxyResolverMac() override; | 70 ~ProxyResolverMac() override; |
| 71 | 71 |
| 72 // ProxyResolver methods: | 72 // ProxyResolver methods: |
| 73 int GetProxyForURL(const GURL& url, | 73 int GetProxyForURL(const GURL& url, |
| 74 ProxyInfo* results, | 74 ProxyInfo* results, |
| 75 const CompletionCallback& callback, | 75 const CompletionCallback& callback, |
| 76 RequestHandle* request, | 76 scoped_ptr<Request>* request, |
| 77 const BoundNetLog& net_log) override; | 77 const BoundNetLog& net_log) override; |
| 78 | 78 |
| 79 void CancelRequest(RequestHandle request) override; | |
| 80 | |
| 81 LoadState GetLoadState(RequestHandle request) const override; | |
| 82 | |
| 83 private: | 79 private: |
| 84 const scoped_refptr<ProxyResolverScriptData> script_data_; | 80 const scoped_refptr<ProxyResolverScriptData> script_data_; |
| 85 }; | 81 }; |
| 86 | 82 |
| 87 ProxyResolverMac::ProxyResolverMac( | 83 ProxyResolverMac::ProxyResolverMac( |
| 88 const scoped_refptr<ProxyResolverScriptData>& script_data) | 84 const scoped_refptr<ProxyResolverScriptData>& script_data) |
| 89 : script_data_(script_data) { | 85 : script_data_(script_data) { |
| 90 } | 86 } |
| 91 | 87 |
| 92 ProxyResolverMac::~ProxyResolverMac() {} | 88 ProxyResolverMac::~ProxyResolverMac() {} |
| 93 | 89 |
| 94 // Gets the proxy information for a query URL from a PAC. Implementation | 90 // Gets the proxy information for a query URL from a PAC. Implementation |
| 95 // inspired by http://developer.apple.com/samplecode/CFProxySupportTool/ | 91 // inspired by http://developer.apple.com/samplecode/CFProxySupportTool/ |
| 96 int ProxyResolverMac::GetProxyForURL(const GURL& query_url, | 92 int ProxyResolverMac::GetProxyForURL(const GURL& query_url, |
| 97 ProxyInfo* results, | 93 ProxyInfo* results, |
| 98 const CompletionCallback& /*callback*/, | 94 const CompletionCallback& /*callback*/, |
| 99 RequestHandle* /*request*/, | 95 scoped_ptr<Request>* /*request*/, |
| 100 const BoundNetLog& net_log) { | 96 const BoundNetLog& net_log) { |
| 101 base::ScopedCFTypeRef<CFStringRef> query_ref( | 97 base::ScopedCFTypeRef<CFStringRef> query_ref( |
| 102 base::SysUTF8ToCFStringRef(query_url.spec())); | 98 base::SysUTF8ToCFStringRef(query_url.spec())); |
| 103 base::ScopedCFTypeRef<CFURLRef> query_url_ref( | 99 base::ScopedCFTypeRef<CFURLRef> query_url_ref( |
| 104 CFURLCreateWithString(kCFAllocatorDefault, query_ref.get(), NULL)); | 100 CFURLCreateWithString(kCFAllocatorDefault, query_ref.get(), NULL)); |
| 105 if (!query_url_ref.get()) | 101 if (!query_url_ref.get()) |
| 106 return ERR_FAILED; | 102 return ERR_FAILED; |
| 107 base::ScopedCFTypeRef<CFStringRef> pac_ref(base::SysUTF8ToCFStringRef( | 103 base::ScopedCFTypeRef<CFStringRef> pac_ref(base::SysUTF8ToCFStringRef( |
| 108 script_data_->type() == ProxyResolverScriptData::TYPE_AUTO_DETECT | 104 script_data_->type() == ProxyResolverScriptData::TYPE_AUTO_DETECT |
| 109 ? std::string() | 105 ? std::string() |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 proxy_uri_list += proxy_server.ToURI(); | 192 proxy_uri_list += proxy_server.ToURI(); |
| 197 } | 193 } |
| 198 | 194 |
| 199 if (!proxy_uri_list.empty()) | 195 if (!proxy_uri_list.empty()) |
| 200 results->UseNamedProxy(proxy_uri_list); | 196 results->UseNamedProxy(proxy_uri_list); |
| 201 // Else do nothing (results is already guaranteed to be in the default state). | 197 // Else do nothing (results is already guaranteed to be in the default state). |
| 202 | 198 |
| 203 return OK; | 199 return OK; |
| 204 } | 200 } |
| 205 | 201 |
| 206 void ProxyResolverMac::CancelRequest(RequestHandle request) { | |
| 207 NOTREACHED(); | |
| 208 } | |
| 209 | |
| 210 LoadState ProxyResolverMac::GetLoadState(RequestHandle request) const { | |
| 211 NOTREACHED(); | |
| 212 return LOAD_STATE_IDLE; | |
| 213 } | |
| 214 | |
| 215 } // namespace | 202 } // namespace |
| 216 | 203 |
| 217 ProxyResolverFactoryMac::ProxyResolverFactoryMac() | 204 ProxyResolverFactoryMac::ProxyResolverFactoryMac() |
| 218 : ProxyResolverFactory(false /*expects_pac_bytes*/) { | 205 : ProxyResolverFactory(false /*expects_pac_bytes*/) { |
| 219 } | 206 } |
| 220 | 207 |
| 221 int ProxyResolverFactoryMac::CreateProxyResolver( | 208 int ProxyResolverFactoryMac::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 ProxyResolverMac(pac_script)); | 213 resolver->reset(new ProxyResolverMac(pac_script)); |
| 227 return OK; | 214 return OK; |
| 228 } | 215 } |
| 229 | 216 |
| 230 } // namespace net | 217 } // namespace net |
| OLD | NEW |