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
3 // found in the LICENSE file.
5 #include "net/proxy/proxy_server.h"
7 #include <CoreFoundation/CoreFoundation.h>
11 #include "base/logging.h"
12 #include "base/mac/foundation_util.h"
13 #include "base/strings/sys_string_conversions.h"
18 ProxyServer
ProxyServer::FromDictionary(Scheme scheme
,
21 CFStringRef port_key
) {
22 if (scheme
== SCHEME_INVALID
|| scheme
== SCHEME_DIRECT
) {
23 // No hostname port to extract; we are done.
24 return ProxyServer(scheme
, HostPortPair());
27 CFStringRef host_ref
=
28 base::mac::GetValueFromDictionary
<CFStringRef
>(dict
, host_key
);
30 LOG(WARNING
) << "Could not find expected key "
31 << base::SysCFStringRefToUTF8(host_key
)
32 << " in the proxy dictionary";
33 return ProxyServer(); // Invalid.
35 std::string host
= base::SysCFStringRefToUTF8(host_ref
);
37 CFNumberRef port_ref
=
38 base::mac::GetValueFromDictionary
<CFNumberRef
>(dict
, port_key
);
41 CFNumberGetValue(port_ref
, kCFNumberIntType
, &port
);
43 port
= GetDefaultPortForScheme(scheme
);
46 return ProxyServer(scheme
, HostPortPair(host
, port
));