| 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_server.h" | 5 #include "net/proxy/proxy_server.h" |
| 6 | 6 |
| 7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/mac/foundation_util.h" | 12 #include "base/mac/foundation_util.h" |
| 13 #include "base/sys_string_conversions.h" | 13 #include "base/sys_string_conversions.h" |
| 14 | 14 |
| 15 namespace net { | 15 namespace net { |
| 16 | 16 |
| 17 // static | 17 // static |
| 18 ProxyServer ProxyServer::FromDictionary(Scheme scheme, | 18 ProxyServer ProxyServer::FromDictionary(Scheme scheme, |
| 19 CFDictionaryRef dict, | 19 CFDictionaryRef dict, |
| 20 CFStringRef host_key, | 20 CFStringRef host_key, |
| 21 CFStringRef port_key) { | 21 CFStringRef port_key) { |
| 22 if (scheme == SCHEME_INVALID || scheme == SCHEME_DIRECT) { | 22 if (scheme == SCHEME_INVALID || scheme == SCHEME_DIRECT) { |
| 23 // No hostname port to extract; we are done. | 23 // No hostname port to extract; we are done. |
| 24 return ProxyServer(scheme, HostPortPair()); | 24 return ProxyServer(scheme, HostPortPair()); |
| 25 } | 25 } |
| 26 | 26 |
| 27 CFStringRef host_ref = | 27 CFStringRef host_ref = |
| 28 (CFStringRef)base::mac::GetValueFromDictionary(dict, host_key, | 28 base::mac::CFCastStrict<CFStringRef>( |
| 29 CFStringGetTypeID()); | 29 base::mac::GetValueFromDictionary(dict, host_key, |
| 30 CFStringGetTypeID())); |
| 30 if (!host_ref) { | 31 if (!host_ref) { |
| 31 LOG(WARNING) << "Could not find expected key " | 32 LOG(WARNING) << "Could not find expected key " |
| 32 << base::SysCFStringRefToUTF8(host_key) | 33 << base::SysCFStringRefToUTF8(host_key) |
| 33 << " in the proxy dictionary"; | 34 << " in the proxy dictionary"; |
| 34 return ProxyServer(); // Invalid. | 35 return ProxyServer(); // Invalid. |
| 35 } | 36 } |
| 36 std::string host = base::SysCFStringRefToUTF8(host_ref); | 37 std::string host = base::SysCFStringRefToUTF8(host_ref); |
| 37 | 38 |
| 38 CFNumberRef port_ref = | 39 CFNumberRef port_ref = |
| 39 (CFNumberRef)base::mac::GetValueFromDictionary(dict, port_key, | 40 base::mac::CFCastStrict<CFNumberRef>( |
| 40 CFNumberGetTypeID()); | 41 base::mac::GetValueFromDictionary(dict, port_key, |
| 42 CFNumberGetTypeID())); |
| 41 int port; | 43 int port; |
| 42 if (port_ref) { | 44 if (port_ref) { |
| 43 CFNumberGetValue(port_ref, kCFNumberIntType, &port); | 45 CFNumberGetValue(port_ref, kCFNumberIntType, &port); |
| 44 } else { | 46 } else { |
| 45 port = GetDefaultPortForScheme(scheme); | 47 port = GetDefaultPortForScheme(scheme); |
| 46 } | 48 } |
| 47 | 49 |
| 48 return ProxyServer(scheme, HostPortPair(host, port)); | 50 return ProxyServer(scheme, HostPortPair(host, port)); |
| 49 } | 51 } |
| 50 | 52 |
| 51 } // namespace net | 53 } // namespace net |
| OLD | NEW |