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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 CFRunLoopRunInMode(private_runloop_mode, DBL_MAX, false); | 123 CFRunLoopRunInMode(private_runloop_mode, DBL_MAX, false); |
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 base::mac::ScopedCFTypeRef<CFArrayRef> proxy_array_ref( |
134 base::mac::ScopedCFTypeRef<CFArrayRef> proxy_array_ref((CFArrayRef)result); | 134 base::mac::CFCastStrict<CFArrayRef>(result)); |
| 135 DCHECK(proxy_array_ref != NULL); |
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 = base::mac::CFCastStrict<CFDictionaryRef>( |
145 (CFDictionaryRef)CFArrayGetValueAtIndex(proxy_array_ref.get(), i); | 146 CFArrayGetValueAtIndex(proxy_array_ref.get(), i)); |
146 DCHECK(CFGetTypeID(proxy_dictionary) == CFDictionaryGetTypeID()); | 147 DCHECK(proxy_dictionary != NULL); |
147 | 148 |
148 // The dictionary may have the following keys: | 149 // The dictionary may have the following keys: |
149 // - kCFProxyTypeKey : The type of the proxy | 150 // - kCFProxyTypeKey : The type of the proxy |
150 // - kCFProxyHostNameKey | 151 // - kCFProxyHostNameKey |
151 // - kCFProxyPortNumberKey : The meat we're after. | 152 // - kCFProxyPortNumberKey : The meat we're after. |
152 // - kCFProxyUsernameKey | 153 // - kCFProxyUsernameKey |
153 // - kCFProxyPasswordKey : Despite the existence of these keys in the | 154 // - kCFProxyPasswordKey : Despite the existence of these keys in the |
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 = | 163 CFStringRef proxy_type = base::mac::GetValueFromDictionary<CFStringRef>( |
163 (CFStringRef)base::mac::GetValueFromDictionary(proxy_dictionary, | 164 proxy_dictionary, kCFProxyTypeKey); |
164 kCFProxyTypeKey, | |
165 CFStringGetTypeID()); | |
166 ProxyServer proxy_server = ProxyServer::FromDictionary( | 165 ProxyServer proxy_server = ProxyServer::FromDictionary( |
167 GetProxyServerScheme(proxy_type), | 166 GetProxyServerScheme(proxy_type), |
168 proxy_dictionary, | 167 proxy_dictionary, |
169 kCFProxyHostNameKey, | 168 kCFProxyHostNameKey, |
170 kCFProxyPortNumberKey); | 169 kCFProxyPortNumberKey); |
171 if (!proxy_server.is_valid()) | 170 if (!proxy_server.is_valid()) |
172 continue; | 171 continue; |
173 | 172 |
174 if (!proxy_uri_list.empty()) | 173 if (!proxy_uri_list.empty()) |
175 proxy_uri_list += ";"; | 174 proxy_uri_list += ";"; |
(...skipping 26 matching lines...) Expand all Loading... |
202 } | 201 } |
203 | 202 |
204 int ProxyResolverMac::SetPacScript( | 203 int ProxyResolverMac::SetPacScript( |
205 const scoped_refptr<ProxyResolverScriptData>& script_data, | 204 const scoped_refptr<ProxyResolverScriptData>& script_data, |
206 OldCompletionCallback* /*callback*/) { | 205 OldCompletionCallback* /*callback*/) { |
207 script_data_ = script_data; | 206 script_data_ = script_data; |
208 return OK; | 207 return OK; |
209 } | 208 } |
210 | 209 |
211 } // namespace net | 210 } // namespace net |
OLD | NEW |