Chromium Code Reviews| 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 #include <CoreServices/CoreServices.h> | 8 #include <CoreServices/CoreServices.h> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 124 CFRunLoopRemoveSource(CFRunLoopGetCurrent(), runloop_source.get(), | 124 CFRunLoopRemoveSource(CFRunLoopGetCurrent(), runloop_source.get(), |
| 125 private_runloop_mode); | 125 private_runloop_mode); |
| 126 DCHECK(result != NULL); | 126 DCHECK(result != NULL); |
| 127 | 127 |
| 128 if (CFGetTypeID(result) == CFErrorGetTypeID()) { | 128 if (CFGetTypeID(result) == CFErrorGetTypeID()) { |
| 129 // TODO(avi): do something better than this | 129 // TODO(avi): do something better than this |
| 130 CFRelease(result); | 130 CFRelease(result); |
| 131 return ERR_FAILED; | 131 return ERR_FAILED; |
| 132 } | 132 } |
| 133 DCHECK(CFGetTypeID(result) == CFArrayGetTypeID()); | 133 DCHECK(CFGetTypeID(result) == CFArrayGetTypeID()); |
| 134 base::mac::ScopedCFTypeRef<CFArrayRef> proxy_array_ref((CFArrayRef)result); | 134 base::mac::ScopedCFTypeRef<CFArrayRef> proxy_array_ref( |
| 135 base::mac::CFCastStrict<CFArrayRef>(result)); | |
| 135 | 136 |
| 136 // This string will be an ordered list of <proxy-uri> entries, separated by | 137 // This string will be an ordered list of <proxy-uri> entries, separated by |
| 137 // semi-colons. It is the format that ProxyInfo::UseNamedProxy() expects. | 138 // semi-colons. It is the format that ProxyInfo::UseNamedProxy() expects. |
| 138 // proxy-uri = [<proxy-scheme>"://"]<proxy-host>":"<proxy-port> | 139 // proxy-uri = [<proxy-scheme>"://"]<proxy-host>":"<proxy-port> |
| 139 // (This also includes entries for direct connection, as "direct://"). | 140 // (This also includes entries for direct connection, as "direct://"). |
| 140 std::string proxy_uri_list; | 141 std::string proxy_uri_list; |
| 141 | 142 |
| 142 CFIndex proxy_array_count = CFArrayGetCount(proxy_array_ref.get()); | 143 CFIndex proxy_array_count = CFArrayGetCount(proxy_array_ref.get()); |
| 143 for (CFIndex i = 0; i < proxy_array_count; ++i) { | 144 for (CFIndex i = 0; i < proxy_array_count; ++i) { |
| 144 CFDictionaryRef proxy_dictionary = | 145 CFDictionaryRef proxy_dictionary = |
| 145 (CFDictionaryRef)CFArrayGetValueAtIndex(proxy_array_ref.get(), i); | 146 base::mac::CFCastStrict<CFDictionaryRef>( |
|
Ryan Sleevi
2011/11/11 00:26:42
nit: You can also re-align here and 165-168
| |
| 147 CFArrayGetValueAtIndex(proxy_array_ref.get(), i)); | |
| 146 DCHECK(CFGetTypeID(proxy_dictionary) == CFDictionaryGetTypeID()); | 148 DCHECK(CFGetTypeID(proxy_dictionary) == CFDictionaryGetTypeID()); |
| 147 | 149 |
| 148 // The dictionary may have the following keys: | 150 // The dictionary may have the following keys: |
| 149 // - kCFProxyTypeKey : The type of the proxy | 151 // - kCFProxyTypeKey : The type of the proxy |
| 150 // - kCFProxyHostNameKey | 152 // - kCFProxyHostNameKey |
| 151 // - kCFProxyPortNumberKey : The meat we're after. | 153 // - kCFProxyPortNumberKey : The meat we're after. |
| 152 // - kCFProxyUsernameKey | 154 // - kCFProxyUsernameKey |
| 153 // - kCFProxyPasswordKey : Despite the existence of these keys in the | 155 // - kCFProxyPasswordKey : Despite the existence of these keys in the |
| 154 // documentation, they're never populated. Even if a | 156 // documentation, they're never populated. Even if a |
| 155 // username/password were to be set in the network | 157 // username/password were to be set in the network |
| 156 // proxy system preferences, we'd need to fetch it | 158 // proxy system preferences, we'd need to fetch it |
| 157 // from the Keychain ourselves. CFProxy is such a | 159 // from the Keychain ourselves. CFProxy is such a |
| 158 // tease. | 160 // tease. |
| 159 // - kCFProxyAutoConfigurationURLKey : If the PAC file specifies another | 161 // - kCFProxyAutoConfigurationURLKey : If the PAC file specifies another |
| 160 // PAC file, I'm going home. | 162 // PAC file, I'm going home. |
| 161 | 163 |
| 162 CFStringRef proxy_type = | 164 CFStringRef proxy_type = |
| 163 (CFStringRef)base::mac::GetValueFromDictionary(proxy_dictionary, | 165 base::mac::CFCastStrict<CFStringRef>( |
| 164 kCFProxyTypeKey, | 166 base::mac::GetValueFromDictionary(proxy_dictionary, |
| 165 CFStringGetTypeID()); | 167 kCFProxyTypeKey, |
| 168 CFStringGetTypeID())); | |
| 166 ProxyServer proxy_server = ProxyServer::FromDictionary( | 169 ProxyServer proxy_server = ProxyServer::FromDictionary( |
| 167 GetProxyServerScheme(proxy_type), | 170 GetProxyServerScheme(proxy_type), |
| 168 proxy_dictionary, | 171 proxy_dictionary, |
| 169 kCFProxyHostNameKey, | 172 kCFProxyHostNameKey, |
| 170 kCFProxyPortNumberKey); | 173 kCFProxyPortNumberKey); |
| 171 if (!proxy_server.is_valid()) | 174 if (!proxy_server.is_valid()) |
| 172 continue; | 175 continue; |
| 173 | 176 |
| 174 if (!proxy_uri_list.empty()) | 177 if (!proxy_uri_list.empty()) |
| 175 proxy_uri_list += ";"; | 178 proxy_uri_list += ";"; |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 202 } | 205 } |
| 203 | 206 |
| 204 int ProxyResolverMac::SetPacScript( | 207 int ProxyResolverMac::SetPacScript( |
| 205 const scoped_refptr<ProxyResolverScriptData>& script_data, | 208 const scoped_refptr<ProxyResolverScriptData>& script_data, |
| 206 OldCompletionCallback* /*callback*/) { | 209 OldCompletionCallback* /*callback*/) { |
| 207 script_data_ = script_data; | 210 script_data_ = script_data; |
| 208 return OK; | 211 return OK; |
| 209 } | 212 } |
| 210 | 213 |
| 211 } // namespace net | 214 } // namespace net |
| OLD | NEW |