| 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 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 } | 61 } |
| 62 | 62 |
| 63 } // namespace | 63 } // namespace |
| 64 | 64 |
| 65 namespace net { | 65 namespace net { |
| 66 | 66 |
| 67 ProxyResolverMac::ProxyResolverMac() | 67 ProxyResolverMac::ProxyResolverMac() |
| 68 : ProxyResolver(false /*expects_pac_bytes*/) { | 68 : ProxyResolver(false /*expects_pac_bytes*/) { |
| 69 } | 69 } |
| 70 | 70 |
| 71 ProxyResolverMac::~ProxyResolverMac() {} | 71 ProxyResolverMac::~ProxyResolverMac() { |
| 72 } |
| 72 | 73 |
| 73 // Gets the proxy information for a query URL from a PAC. Implementation | 74 // Gets the proxy information for a query URL from a PAC. Implementation |
| 74 // inspired by http://developer.apple.com/samplecode/CFProxySupportTool/ | 75 // inspired by http://developer.apple.com/samplecode/CFProxySupportTool/ |
| 75 int ProxyResolverMac::GetProxyForURL(const GURL& query_url, | 76 int ProxyResolverMac::GetProxyForURL(const GURL& query_url, |
| 76 ProxyInfo* results, | 77 ProxyInfo* results, |
| 77 const CompletionCallback& /*callback*/, | 78 const CompletionCallback& /*callback*/, |
| 78 RequestHandle* /*request*/, | 79 RequestHandle* /*request*/, |
| 79 const BoundNetLog& net_log) { | 80 const BoundNetLog& net_log) { |
| 80 base::ScopedCFTypeRef<CFStringRef> query_ref( | 81 base::ScopedCFTypeRef<CFStringRef> query_ref( |
| 81 base::SysUTF8ToCFStringRef(query_url.spec())); | 82 base::SysUTF8ToCFStringRef(query_url.spec())); |
| 82 base::ScopedCFTypeRef<CFURLRef> query_url_ref( | 83 base::ScopedCFTypeRef<CFURLRef> query_url_ref( |
| 83 CFURLCreateWithString(kCFAllocatorDefault, query_ref.get(), NULL)); | 84 CFURLCreateWithString(kCFAllocatorDefault, query_ref.get(), NULL)); |
| 84 if (!query_url_ref.get()) | 85 if (!query_url_ref.get()) |
| 85 return ERR_FAILED; | 86 return ERR_FAILED; |
| 86 base::ScopedCFTypeRef<CFStringRef> pac_ref(base::SysUTF8ToCFStringRef( | 87 base::ScopedCFTypeRef<CFStringRef> pac_ref(base::SysUTF8ToCFStringRef( |
| 87 script_data_->type() == ProxyResolverScriptData::TYPE_AUTO_DETECT | 88 script_data_->type() == ProxyResolverScriptData::TYPE_AUTO_DETECT |
| 88 ? std::string() | 89 ? std::string() |
| 89 : script_data_->url().spec())); | 90 : script_data_->url().spec())); |
| 90 base::ScopedCFTypeRef<CFURLRef> pac_url_ref( | 91 base::ScopedCFTypeRef<CFURLRef> pac_url_ref( |
| 91 CFURLCreateWithString(kCFAllocatorDefault, pac_ref.get(), NULL)); | 92 CFURLCreateWithString(kCFAllocatorDefault, pac_ref.get(), NULL)); |
| 92 if (!pac_url_ref.get()) | 93 if (!pac_url_ref.get()) |
| 93 return ERR_FAILED; | 94 return ERR_FAILED; |
| 94 | 95 |
| 95 // Work around <rdar://problem/5530166>. This dummy call to | 96 // Work around <rdar://problem/5530166>. This dummy call to |
| 96 // CFNetworkCopyProxiesForURL initializes some state within CFNetwork that is | 97 // CFNetworkCopyProxiesForURL initializes some state within CFNetwork that is |
| 97 // required by CFNetworkExecuteProxyAutoConfigurationURL. | 98 // required by CFNetworkExecuteProxyAutoConfigurationURL. |
| 98 | 99 |
| 99 CFArrayRef dummy_result = CFNetworkCopyProxiesForURL(query_url_ref.get(), | 100 CFArrayRef dummy_result = |
| 100 NULL); | 101 CFNetworkCopyProxiesForURL(query_url_ref.get(), NULL); |
| 101 if (dummy_result) | 102 if (dummy_result) |
| 102 CFRelease(dummy_result); | 103 CFRelease(dummy_result); |
| 103 | 104 |
| 104 // We cheat here. We need to act as if we were synchronous, so we pump the | 105 // We cheat here. We need to act as if we were synchronous, so we pump the |
| 105 // runloop ourselves. Our caller moved us to a new thread anyway, so this is | 106 // runloop ourselves. Our caller moved us to a new thread anyway, so this is |
| 106 // OK to do. (BTW, CFNetworkExecuteProxyAutoConfigurationURL returns a | 107 // OK to do. (BTW, CFNetworkExecuteProxyAutoConfigurationURL returns a |
| 107 // runloop source we need to release despite its name.) | 108 // runloop source we need to release despite its name.) |
| 108 | 109 |
| 109 CFTypeRef result = NULL; | 110 CFTypeRef result = NULL; |
| 110 CFStreamClientContext context = { 0, &result, NULL, NULL, NULL }; | 111 CFStreamClientContext context = {0, &result, NULL, NULL, NULL}; |
| 111 base::ScopedCFTypeRef<CFRunLoopSourceRef> runloop_source( | 112 base::ScopedCFTypeRef<CFRunLoopSourceRef> runloop_source( |
| 112 CFNetworkExecuteProxyAutoConfigurationURL( | 113 CFNetworkExecuteProxyAutoConfigurationURL( |
| 113 pac_url_ref.get(), query_url_ref.get(), ResultCallback, &context)); | 114 pac_url_ref.get(), query_url_ref.get(), ResultCallback, &context)); |
| 114 if (!runloop_source) | 115 if (!runloop_source) |
| 115 return ERR_FAILED; | 116 return ERR_FAILED; |
| 116 | 117 |
| 117 const CFStringRef private_runloop_mode = | 118 const CFStringRef private_runloop_mode = |
| 118 CFSTR("org.chromium.ProxyResolverMac"); | 119 CFSTR("org.chromium.ProxyResolverMac"); |
| 119 | 120 |
| 120 CFRunLoopAddSource(CFRunLoopGetCurrent(), runloop_source.get(), | 121 CFRunLoopAddSource( |
| 121 private_runloop_mode); | 122 CFRunLoopGetCurrent(), runloop_source.get(), private_runloop_mode); |
| 122 CFRunLoopRunInMode(private_runloop_mode, DBL_MAX, false); | 123 CFRunLoopRunInMode(private_runloop_mode, DBL_MAX, false); |
| 123 CFRunLoopRemoveSource(CFRunLoopGetCurrent(), runloop_source.get(), | 124 CFRunLoopRemoveSource( |
| 124 private_runloop_mode); | 125 CFRunLoopGetCurrent(), runloop_source.get(), private_runloop_mode); |
| 125 DCHECK(result != NULL); | 126 DCHECK(result != NULL); |
| 126 | 127 |
| 127 if (CFGetTypeID(result) == CFErrorGetTypeID()) { | 128 if (CFGetTypeID(result) == CFErrorGetTypeID()) { |
| 128 // TODO(avi): do something better than this | 129 // TODO(avi): do something better than this |
| 129 CFRelease(result); | 130 CFRelease(result); |
| 130 return ERR_FAILED; | 131 return ERR_FAILED; |
| 131 } | 132 } |
| 132 base::ScopedCFTypeRef<CFArrayRef> proxy_array_ref( | 133 base::ScopedCFTypeRef<CFArrayRef> proxy_array_ref( |
| 133 base::mac::CFCastStrict<CFArrayRef>(result)); | 134 base::mac::CFCastStrict<CFArrayRef>(result)); |
| 134 DCHECK(proxy_array_ref != NULL); | 135 DCHECK(proxy_array_ref != NULL); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 154 // documentation, they're never populated. Even if a | 155 // documentation, they're never populated. Even if a |
| 155 // username/password were to be set in the network | 156 // username/password were to be set in the network |
| 156 // proxy system preferences, we'd need to fetch it | 157 // proxy system preferences, we'd need to fetch it |
| 157 // from the Keychain ourselves. CFProxy is such a | 158 // from the Keychain ourselves. CFProxy is such a |
| 158 // tease. | 159 // tease. |
| 159 // - kCFProxyAutoConfigurationURLKey : If the PAC file specifies another | 160 // - kCFProxyAutoConfigurationURLKey : If the PAC file specifies another |
| 160 // PAC file, I'm going home. | 161 // PAC file, I'm going home. |
| 161 | 162 |
| 162 CFStringRef proxy_type = base::mac::GetValueFromDictionary<CFStringRef>( | 163 CFStringRef proxy_type = base::mac::GetValueFromDictionary<CFStringRef>( |
| 163 proxy_dictionary, kCFProxyTypeKey); | 164 proxy_dictionary, kCFProxyTypeKey); |
| 164 ProxyServer proxy_server = ProxyServer::FromDictionary( | 165 ProxyServer proxy_server = |
| 165 GetProxyServerScheme(proxy_type), | 166 ProxyServer::FromDictionary(GetProxyServerScheme(proxy_type), |
| 166 proxy_dictionary, | 167 proxy_dictionary, |
| 167 kCFProxyHostNameKey, | 168 kCFProxyHostNameKey, |
| 168 kCFProxyPortNumberKey); | 169 kCFProxyPortNumberKey); |
| 169 if (!proxy_server.is_valid()) | 170 if (!proxy_server.is_valid()) |
| 170 continue; | 171 continue; |
| 171 | 172 |
| 172 if (!proxy_uri_list.empty()) | 173 if (!proxy_uri_list.empty()) |
| 173 proxy_uri_list += ";"; | 174 proxy_uri_list += ";"; |
| 174 proxy_uri_list += proxy_server.ToURI(); | 175 proxy_uri_list += proxy_server.ToURI(); |
| 175 } | 176 } |
| 176 | 177 |
| 177 if (!proxy_uri_list.empty()) | 178 if (!proxy_uri_list.empty()) |
| 178 results->UseNamedProxy(proxy_uri_list); | 179 results->UseNamedProxy(proxy_uri_list); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 195 } | 196 } |
| 196 | 197 |
| 197 int ProxyResolverMac::SetPacScript( | 198 int ProxyResolverMac::SetPacScript( |
| 198 const scoped_refptr<ProxyResolverScriptData>& script_data, | 199 const scoped_refptr<ProxyResolverScriptData>& script_data, |
| 199 const CompletionCallback& /*callback*/) { | 200 const CompletionCallback& /*callback*/) { |
| 200 script_data_ = script_data; | 201 script_data_ = script_data; |
| 201 return OK; | 202 return OK; |
| 202 } | 203 } |
| 203 | 204 |
| 204 } // namespace net | 205 } // namespace net |
| OLD | NEW |