summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhayato@chromium.org <hayato@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-10 10:37:27 +0000
committerhayato@chromium.org <hayato@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-12-10 10:37:27 +0000
commita9944f08e4c9730993d012496a688039cf48936e (patch)
tree595999cb4b26d8eb72d7c4d8033e7d71b7cffb38
parentc0ce9d8162a70abb545e3ca7376003a492b08490 (diff)
downloadchromium_src-a9944f08e4c9730993d012496a688039cf48936e.zip
chromium_src-a9944f08e4c9730993d012496a688039cf48936e.tar.gz
chromium_src-a9944f08e4c9730993d012496a688039cf48936e.tar.bz2
Separate ProxyResolverMac and ProxyConfigServiceMac into their own files and extract common utility functions into other files.
TEST=trybot and MacUtilTest in base_unittests BUG=27310 Review URL: http://codereview.chromium.org/463028 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@34243 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/mac_util.h6
-rw-r--r--base/mac_util.mm24
-rw-r--r--base/mac_util_unittest.mm17
-rw-r--r--net/net.gyp3
-rw-r--r--net/proxy/proxy_config_service_mac.cc159
-rw-r--r--net/proxy/proxy_config_service_mac.h20
-rw-r--r--net/proxy/proxy_resolver_mac.cc222
-rw-r--r--net/proxy/proxy_resolver_mac.h7
-rw-r--r--net/proxy/proxy_server.h19
-rw-r--r--net/proxy/proxy_server_mac.cc51
-rw-r--r--net/proxy/proxy_service.cc1
11 files changed, 311 insertions, 218 deletions
diff --git a/base/mac_util.h b/base/mac_util.h
index ed49e2f..7b697c9 100644
--- a/base/mac_util.h
+++ b/base/mac_util.h
@@ -92,6 +92,12 @@ FilePath GetAppBundlePath(const FilePath& exec_name);
// Set the Time Machine exclusion property for the given file.
bool SetFileBackupExclusion(const FilePath& file_path, bool exclude);
+// Utility function to pull out a value from a dictionary, check its type, and
+// return it. Returns NULL if the key is not present or of the wrong type.
+CFTypeRef GetValueFromDictionary(CFDictionaryRef dict,
+ CFStringRef key,
+ CFTypeID expected_type);
+
} // namespace mac_util
#endif // BASE_MAC_UTIL_H_
diff --git a/base/mac_util.mm b/base/mac_util.mm
index 1418453..f585233 100644
--- a/base/mac_util.mm
+++ b/base/mac_util.mm
@@ -254,5 +254,29 @@ bool SetFileBackupExclusion(const FilePath& file_path, bool exclude) {
return success;
}
+CFTypeRef GetValueFromDictionary(CFDictionaryRef dict,
+ CFStringRef key,
+ CFTypeID expected_type) {
+ CFTypeRef value = CFDictionaryGetValue(dict, key);
+ if (!value)
+ return value;
+
+ if (CFGetTypeID(value) != expected_type) {
+ scoped_cftyperef<CFStringRef> expected_type_ref(
+ CFCopyTypeIDDescription(expected_type));
+ scoped_cftyperef<CFStringRef> actual_type_ref(
+ CFCopyTypeIDDescription(CFGetTypeID(value)));
+ LOG(WARNING) << "Expected value for key "
+ << base::SysCFStringRefToUTF8(key)
+ << " to be "
+ << base::SysCFStringRefToUTF8(expected_type_ref)
+ << " but it was "
+ << base::SysCFStringRefToUTF8(actual_type_ref)
+ << " instead";
+ return NULL;
+ }
+
+ return value;
+}
} // namespace mac_util
diff --git a/base/mac_util_unittest.mm b/base/mac_util_unittest.mm
index 5e97356..9e56358 100644
--- a/base/mac_util_unittest.mm
+++ b/base/mac_util_unittest.mm
@@ -9,6 +9,7 @@
#include "base/file_path.h"
#include "base/file_util.h"
+#include "base/scoped_cftyperef.h"
#include "base/scoped_nsobject.h"
#include "base/scoped_ptr.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -125,3 +126,19 @@ TEST_F(MacUtilTest, TestExcludeFileFromBackups) {
EXPECT_TRUE(mac_util::SetFileBackupExclusion(file_path, false));
EXPECT_FALSE(CSBackupIsItemExcluded((CFURLRef)fileURL, &excludeByPath));
}
+
+TEST_F(MacUtilTest, TestGetValueFromDictionary) {
+ scoped_cftyperef<CFMutableDictionaryRef> dict(
+ CFDictionaryCreateMutable(0, 0,
+ &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks));
+ CFDictionarySetValue(dict.get(), CFSTR("key"), CFSTR("value"));
+
+ EXPECT_TRUE(CFEqual(CFSTR("value"),
+ mac_util::GetValueFromDictionary(
+ dict, CFSTR("key"), CFStringGetTypeID())));
+ EXPECT_FALSE(mac_util::GetValueFromDictionary(
+ dict, CFSTR("key"), CFNumberGetTypeID()));
+ EXPECT_FALSE(mac_util::GetValueFromDictionary(
+ dict, CFSTR("no-exist"), CFStringGetTypeID()));
+}
diff --git a/net/net.gyp b/net/net.gyp
index db853bf..f5adb65 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -376,6 +376,8 @@
'proxy/proxy_config_service_fixed.h',
'proxy/proxy_config_service_linux.cc',
'proxy/proxy_config_service_linux.h',
+ 'proxy/proxy_config_service_mac.cc',
+ 'proxy/proxy_config_service_mac.h',
'proxy/proxy_config_service_win.cc',
'proxy/proxy_config_service_win.h',
'proxy/proxy_info.cc',
@@ -396,6 +398,7 @@
'proxy/proxy_script_fetcher.cc',
'proxy/proxy_script_fetcher.h',
'proxy/proxy_server.cc',
+ 'proxy/proxy_server_mac.cc',
'proxy/proxy_server.h',
'proxy/proxy_service.cc',
'proxy/proxy_service.h',
diff --git a/net/proxy/proxy_config_service_mac.cc b/net/proxy/proxy_config_service_mac.cc
new file mode 100644
index 0000000..3359cc3
--- /dev/null
+++ b/net/proxy/proxy_config_service_mac.cc
@@ -0,0 +1,159 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/proxy/proxy_config_service_mac.h"
+
+#include <CoreFoundation/CoreFoundation.h>
+#include <SystemConfiguration/SystemConfiguration.h>
+
+#include "base/logging.h"
+#include "base/mac_util.h"
+#include "base/scoped_cftyperef.h"
+#include "base/sys_string_conversions.h"
+#include "net/base/net_errors.h"
+#include "net/proxy/proxy_config.h"
+#include "net/proxy/proxy_info.h"
+#include "net/proxy/proxy_server.h"
+
+namespace {
+
+// Utility function to pull out a boolean value from a dictionary and return it,
+// returning a default value if the key is not present.
+bool GetBoolFromDictionary(CFDictionaryRef dict,
+ CFStringRef key,
+ bool default_value) {
+ CFNumberRef number = (CFNumberRef)mac_util::GetValueFromDictionary(
+ dict, key, CFNumberGetTypeID());
+ if (!number)
+ return default_value;
+
+ int int_value;
+ if (CFNumberGetValue(number, kCFNumberIntType, &int_value))
+ return int_value;
+ else
+ return default_value;
+}
+
+} // namespace
+
+namespace net {
+
+int ProxyConfigServiceMac::GetProxyConfig(ProxyConfig* config) {
+ scoped_cftyperef<CFDictionaryRef> config_dict(
+ SCDynamicStoreCopyProxies(NULL));
+ DCHECK(config_dict);
+
+ // auto-detect
+
+ // There appears to be no UI for this configuration option, and we're not sure
+ // if Apple's proxy code even takes it into account. But the constant is in
+ // the header file so we'll use it.
+ config->auto_detect =
+ GetBoolFromDictionary(config_dict.get(),
+ kSCPropNetProxiesProxyAutoDiscoveryEnable,
+ false);
+
+ // PAC file
+
+ if (GetBoolFromDictionary(config_dict.get(),
+ kSCPropNetProxiesProxyAutoConfigEnable,
+ false)) {
+ CFStringRef pac_url_ref = (CFStringRef)mac_util::GetValueFromDictionary(
+ config_dict.get(),
+ kSCPropNetProxiesProxyAutoConfigURLString,
+ CFStringGetTypeID());
+ if (pac_url_ref)
+ config->pac_url = GURL(base::SysCFStringRefToUTF8(pac_url_ref));
+ }
+
+ // proxies (for now ftp, http, https, and SOCKS)
+
+ if (GetBoolFromDictionary(config_dict.get(),
+ kSCPropNetProxiesFTPEnable,
+ false)) {
+ ProxyServer proxy_server =
+ ProxyServer::FromDictionary(ProxyServer::SCHEME_HTTP,
+ config_dict.get(),
+ kSCPropNetProxiesFTPProxy,
+ kSCPropNetProxiesFTPPort);
+ if (proxy_server.is_valid()) {
+ config->proxy_rules.type = ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
+ config->proxy_rules.proxy_for_ftp = proxy_server;
+ }
+ }
+ if (GetBoolFromDictionary(config_dict.get(),
+ kSCPropNetProxiesHTTPEnable,
+ false)) {
+ ProxyServer proxy_server =
+ ProxyServer::FromDictionary(ProxyServer::SCHEME_HTTP,
+ config_dict.get(),
+ kSCPropNetProxiesHTTPProxy,
+ kSCPropNetProxiesHTTPPort);
+ if (proxy_server.is_valid()) {
+ config->proxy_rules.type = ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
+ config->proxy_rules.proxy_for_http = proxy_server;
+ }
+ }
+ if (GetBoolFromDictionary(config_dict.get(),
+ kSCPropNetProxiesHTTPSEnable,
+ false)) {
+ ProxyServer proxy_server =
+ ProxyServer::FromDictionary(ProxyServer::SCHEME_HTTP,
+ config_dict.get(),
+ kSCPropNetProxiesHTTPSProxy,
+ kSCPropNetProxiesHTTPSPort);
+ if (proxy_server.is_valid()) {
+ config->proxy_rules.type = ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
+ config->proxy_rules.proxy_for_https = proxy_server;
+ }
+ }
+ if (GetBoolFromDictionary(config_dict.get(),
+ kSCPropNetProxiesSOCKSEnable,
+ false)) {
+ ProxyServer proxy_server =
+ ProxyServer::FromDictionary(ProxyServer::SCHEME_SOCKS5,
+ config_dict.get(),
+ kSCPropNetProxiesSOCKSProxy,
+ kSCPropNetProxiesSOCKSPort);
+ if (proxy_server.is_valid()) {
+ config->proxy_rules.type = ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
+ config->proxy_rules.socks_proxy = proxy_server;
+ }
+ }
+
+ // proxy bypass list
+
+ CFArrayRef bypass_array_ref =
+ (CFArrayRef)mac_util::GetValueFromDictionary(
+ config_dict.get(),
+ kSCPropNetProxiesExceptionsList,
+ CFArrayGetTypeID());
+ if (bypass_array_ref) {
+ CFIndex bypass_array_count = CFArrayGetCount(bypass_array_ref);
+ for (CFIndex i = 0; i < bypass_array_count; ++i) {
+ CFStringRef bypass_item_ref =
+ (CFStringRef)CFArrayGetValueAtIndex(bypass_array_ref, i);
+ if (CFGetTypeID(bypass_item_ref) != CFStringGetTypeID()) {
+ LOG(WARNING) << "Expected value for item " << i
+ << " in the kSCPropNetProxiesExceptionsList"
+ " to be a CFStringRef but it was not";
+
+ } else {
+ config->proxy_bypass.push_back(
+ base::SysCFStringRefToUTF8(bypass_item_ref));
+ }
+ }
+ }
+
+ // proxy bypass boolean
+
+ config->proxy_bypass_local_names =
+ GetBoolFromDictionary(config_dict.get(),
+ kSCPropNetProxiesExcludeSimpleHostnames,
+ false);
+
+ return OK;
+}
+
+} // namespace net
diff --git a/net/proxy/proxy_config_service_mac.h b/net/proxy/proxy_config_service_mac.h
new file mode 100644
index 0000000..6a93228
--- /dev/null
+++ b/net/proxy/proxy_config_service_mac.h
@@ -0,0 +1,20 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_PROXY_PROXY_CONFIG_SERVICE_MAC_H_
+#define NET_PROXY_PROXY_CONFIG_SERVICE_MAC_H_
+
+#include "net/proxy/proxy_config_service.h"
+
+namespace net {
+
+class ProxyConfigServiceMac : public ProxyConfigService {
+ public:
+ // ProxyConfigService methods:
+ virtual int GetProxyConfig(ProxyConfig* config);
+};
+
+} // namespace net
+
+#endif // NET_PROXY_PROXY_CONFIG_SERVICE_MAC_H_
diff --git a/net/proxy/proxy_resolver_mac.cc b/net/proxy/proxy_resolver_mac.cc
index e3d826e..6baf78f 100644
--- a/net/proxy/proxy_resolver_mac.cc
+++ b/net/proxy/proxy_resolver_mac.cc
@@ -5,101 +5,18 @@
#include "net/proxy/proxy_resolver_mac.h"
#include <CoreFoundation/CoreFoundation.h>
-#include <CoreServices/CoreServices.h>
-#include <SystemConfiguration/SystemConfiguration.h>
+#include "base/logging.h"
+#include "base/mac_util.h"
#include "base/scoped_cftyperef.h"
#include "base/string_util.h"
#include "base/sys_string_conversions.h"
#include "net/base/net_errors.h"
-#include "net/proxy/proxy_config.h"
#include "net/proxy/proxy_info.h"
#include "net/proxy/proxy_server.h"
namespace {
-// Utility function to pull out a value from a dictionary, check its type, and
-// return it. Returns NULL if the key is not present or of the wrong type.
-CFTypeRef GetValueFromDictionary(CFDictionaryRef dict,
- CFStringRef key,
- CFTypeID expected_type) {
- CFTypeRef value = CFDictionaryGetValue(dict, key);
- if (!value)
- return value;
-
- if (CFGetTypeID(value) != expected_type) {
- scoped_cftyperef<CFStringRef> expected_type_ref(
- CFCopyTypeIDDescription(expected_type));
- scoped_cftyperef<CFStringRef> actual_type_ref(
- CFCopyTypeIDDescription(CFGetTypeID(value)));
- LOG(WARNING) << "Expected value for key "
- << base::SysCFStringRefToUTF8(key)
- << " to be "
- << base::SysCFStringRefToUTF8(expected_type_ref)
- << " but it was "
- << base::SysCFStringRefToUTF8(actual_type_ref)
- << " instead";
- return NULL;
- }
-
- return value;
-}
-
-// Utility function to pull out a boolean value from a dictionary and return it,
-// returning a default value if the key is not present.
-bool GetBoolFromDictionary(CFDictionaryRef dict,
- CFStringRef key,
- bool default_value) {
- CFNumberRef number = (CFNumberRef)GetValueFromDictionary(dict, key,
- CFNumberGetTypeID());
- if (!number)
- return default_value;
-
- int int_value;
- if (CFNumberGetValue(number, kCFNumberIntType, &int_value))
- return int_value;
- else
- return default_value;
-}
-
-// Utility function to pull out a host/port pair from a dictionary and return it
-// as a ProxyServer object. Pass in a dictionary that has a value for the host
-// key and optionally a value for the port key. In the error condition where
-// the host value is especially malformed, returns an invalid ProxyServer.
-net::ProxyServer GetProxyServerFromDictionary(net::ProxyServer::Scheme scheme,
- CFDictionaryRef dict,
- CFStringRef host_key,
- CFStringRef port_key) {
- if (scheme == net::ProxyServer::SCHEME_INVALID ||
- scheme == net::ProxyServer::SCHEME_DIRECT) {
- // No hostname port to extract; we are done.
- return net::ProxyServer(scheme, std::string(), -1);
- }
-
- CFStringRef host_ref =
- (CFStringRef)GetValueFromDictionary(dict, host_key,
- CFStringGetTypeID());
- if (!host_ref) {
- LOG(WARNING) << "Could not find expected key "
- << base::SysCFStringRefToUTF8(host_key)
- << " in the proxy dictionary";
- return net::ProxyServer(); // Invalid.
- }
- std::string host = base::SysCFStringRefToUTF8(host_ref);
-
- CFNumberRef port_ref =
- (CFNumberRef)GetValueFromDictionary(dict, port_key,
- CFNumberGetTypeID());
- int port;
- if (port_ref) {
- CFNumberGetValue(port_ref, kCFNumberIntType, &port);
- } else {
- port = net::ProxyServer::GetDefaultPortForScheme(scheme);
- }
-
- return net::ProxyServer(scheme, host, port);
-}
-
// Utility function to map a CFProxyType to a ProxyServer::Scheme.
// If the type is unknown, returns ProxyServer::SCHEME_INVALID.
net::ProxyServer::Scheme GetProxyServerScheme(CFStringRef proxy_type) {
@@ -120,7 +37,7 @@ net::ProxyServer::Scheme GetProxyServerScheme(CFStringRef proxy_type) {
void ResultCallback(void* client, CFArrayRef proxies, CFErrorRef error) {
DCHECK((proxies != NULL) == (error == NULL));
- CFTypeRef* result_ptr = (CFTypeRef*)client;
+ CFTypeRef* result_ptr = reinterpret_cast<CFTypeRef*>(client);
DCHECK(result_ptr != NULL);
DCHECK(*result_ptr == NULL);
@@ -136,123 +53,6 @@ void ResultCallback(void* client, CFArrayRef proxies, CFErrorRef error) {
namespace net {
-int ProxyConfigServiceMac::GetProxyConfig(ProxyConfig* config) {
- scoped_cftyperef<CFDictionaryRef> config_dict(
- SCDynamicStoreCopyProxies(NULL));
- DCHECK(config_dict);
-
- // auto-detect
-
- // There appears to be no UI for this configuration option, and we're not sure
- // if Apple's proxy code even takes it into account. But the constant is in
- // the header file so we'll use it.
- config->auto_detect =
- GetBoolFromDictionary(config_dict.get(),
- kSCPropNetProxiesProxyAutoDiscoveryEnable,
- false);
-
- // PAC file
-
- if (GetBoolFromDictionary(config_dict.get(),
- kSCPropNetProxiesProxyAutoConfigEnable,
- false)) {
- CFStringRef pac_url_ref =
- (CFStringRef)GetValueFromDictionary(
- config_dict.get(),
- kSCPropNetProxiesProxyAutoConfigURLString,
- CFStringGetTypeID());
- if (pac_url_ref)
- config->pac_url = GURL(base::SysCFStringRefToUTF8(pac_url_ref));
- }
-
- // proxies (for now ftp, http, https, and SOCKS)
-
- if (GetBoolFromDictionary(config_dict.get(),
- kSCPropNetProxiesFTPEnable,
- false)) {
- ProxyServer proxy_server =
- GetProxyServerFromDictionary(ProxyServer::SCHEME_HTTP,
- config_dict.get(),
- kSCPropNetProxiesFTPProxy,
- kSCPropNetProxiesFTPPort);
- if (proxy_server.is_valid()) {
- config->proxy_rules.type = ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
- config->proxy_rules.proxy_for_ftp = proxy_server;
- }
- }
- if (GetBoolFromDictionary(config_dict.get(),
- kSCPropNetProxiesHTTPEnable,
- false)) {
- ProxyServer proxy_server =
- GetProxyServerFromDictionary(ProxyServer::SCHEME_HTTP,
- config_dict.get(),
- kSCPropNetProxiesHTTPProxy,
- kSCPropNetProxiesHTTPPort);
- if (proxy_server.is_valid()) {
- config->proxy_rules.type = ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
- config->proxy_rules.proxy_for_http = proxy_server;
- }
- }
- if (GetBoolFromDictionary(config_dict.get(),
- kSCPropNetProxiesHTTPSEnable,
- false)) {
- ProxyServer proxy_server =
- GetProxyServerFromDictionary(ProxyServer::SCHEME_HTTP,
- config_dict.get(),
- kSCPropNetProxiesHTTPSProxy,
- kSCPropNetProxiesHTTPSPort);
- if (proxy_server.is_valid()) {
- config->proxy_rules.type = ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
- config->proxy_rules.proxy_for_https = proxy_server;
- }
- }
- if (GetBoolFromDictionary(config_dict.get(),
- kSCPropNetProxiesSOCKSEnable,
- false)) {
- ProxyServer proxy_server =
- GetProxyServerFromDictionary(ProxyServer::SCHEME_SOCKS5,
- config_dict.get(),
- kSCPropNetProxiesSOCKSProxy,
- kSCPropNetProxiesSOCKSPort);
- if (proxy_server.is_valid()) {
- config->proxy_rules.type = ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
- config->proxy_rules.socks_proxy = proxy_server;
- }
- }
-
- // proxy bypass list
-
- CFArrayRef bypass_array_ref =
- (CFArrayRef)GetValueFromDictionary(config_dict.get(),
- kSCPropNetProxiesExceptionsList,
- CFArrayGetTypeID());
- if (bypass_array_ref) {
- CFIndex bypass_array_count = CFArrayGetCount(bypass_array_ref);
- for (CFIndex i = 0; i < bypass_array_count; ++i) {
- CFStringRef bypass_item_ref =
- (CFStringRef)CFArrayGetValueAtIndex(bypass_array_ref, i);
- if (CFGetTypeID(bypass_item_ref) != CFStringGetTypeID()) {
- LOG(WARNING) << "Expected value for item " << i
- << " in the kSCPropNetProxiesExceptionsList"
- " to be a CFStringRef but it was not";
-
- } else {
- config->proxy_bypass.push_back(
- base::SysCFStringRefToUTF8(bypass_item_ref));
- }
- }
- }
-
- // proxy bypass boolean
-
- config->proxy_bypass_local_names =
- GetBoolFromDictionary(config_dict.get(),
- kSCPropNetProxiesExcludeSimpleHostnames,
- false);
-
- return OK;
-}
-
// Gets the proxy information for a query URL from a PAC. Implementation
// inspired by http://developer.apple.com/samplecode/CFProxySupportTool/
int ProxyResolverMac::GetProxyForURL(const GURL& query_url,
@@ -346,14 +146,14 @@ int ProxyResolverMac::GetProxyForURL(const GURL& query_url,
// PAC file, I'm going home.
CFStringRef proxy_type =
- (CFStringRef)GetValueFromDictionary(proxy_dictionary,
- kCFProxyTypeKey,
- CFStringGetTypeID());
- ProxyServer proxy_server =
- GetProxyServerFromDictionary(GetProxyServerScheme(proxy_type),
- proxy_dictionary,
- kCFProxyHostNameKey,
- kCFProxyPortNumberKey);
+ (CFStringRef)mac_util::GetValueFromDictionary(proxy_dictionary,
+ kCFProxyTypeKey,
+ CFStringGetTypeID());
+ ProxyServer proxy_server = ProxyServer::FromDictionary(
+ GetProxyServerScheme(proxy_type),
+ proxy_dictionary,
+ kCFProxyHostNameKey,
+ kCFProxyPortNumberKey);
if (!proxy_server.is_valid())
continue;
diff --git a/net/proxy/proxy_resolver_mac.h b/net/proxy/proxy_resolver_mac.h
index b96795a..6676b2f 100644
--- a/net/proxy/proxy_resolver_mac.h
+++ b/net/proxy/proxy_resolver_mac.h
@@ -9,7 +9,6 @@
#include "googleurl/src/gurl.h"
#include "net/base/net_errors.h"
-#include "net/proxy/proxy_config_service.h"
#include "net/proxy/proxy_resolver.h"
namespace net {
@@ -42,12 +41,6 @@ class ProxyResolverMac : public ProxyResolver {
GURL pac_url_;
};
-class ProxyConfigServiceMac : public ProxyConfigService {
- public:
- // ProxyConfigService methods:
- virtual int GetProxyConfig(ProxyConfig* config);
-};
-
} // namespace net
#endif // NET_PROXY_PROXY_RESOLVER_MAC_H_
diff --git a/net/proxy/proxy_server.h b/net/proxy/proxy_server.h
index eb2d275..67feccc 100644
--- a/net/proxy/proxy_server.h
+++ b/net/proxy/proxy_server.h
@@ -5,6 +5,12 @@
#ifndef NET_PROXY_PROXY_SERVER_H_
#define NET_PROXY_PROXY_SERVER_H_
+#include "build/build_config.h"
+
+#if defined(OS_MACOSX)
+#include <CoreFoundation/CoreFoundation.h>
+#endif
+
#include <string>
namespace net {
@@ -101,6 +107,19 @@ class ProxyServer {
static ProxyServer FromPacString(std::string::const_iterator pac_string_begin,
std::string::const_iterator pac_string_end);
+#if defined(OS_MACOSX)
+ // Utility function to pull out a host/port pair from a dictionary and return
+ // it as a ProxyServer object. Pass in a dictionary that has a value for the
+ // host key and optionally a value for the port key. In the error condition
+ // where the host value is especially malformed, returns an invalid
+ // ProxyServer.
+ static ProxyServer FromDictionary(Scheme scheme,
+ CFDictionaryRef dict,
+ CFStringRef host_key,
+ CFStringRef port_key);
+#endif
+
+
// Format as a PAC result entry. This does the reverse of FromPacString().
std::string ToPacString() const;
diff --git a/net/proxy/proxy_server_mac.cc b/net/proxy/proxy_server_mac.cc
new file mode 100644
index 0000000..44c21cd
--- /dev/null
+++ b/net/proxy/proxy_server_mac.cc
@@ -0,0 +1,51 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/proxy/proxy_server.h"
+
+#include <CoreFoundation/CoreFoundation.h>
+
+#include <string>
+
+#include "base/logging.h"
+#include "base/mac_util.h"
+#include "base/sys_string_conversions.h"
+
+namespace net {
+
+// static
+ProxyServer ProxyServer::FromDictionary(Scheme scheme,
+ CFDictionaryRef dict,
+ CFStringRef host_key,
+ CFStringRef port_key) {
+ if (scheme == SCHEME_INVALID || scheme == SCHEME_DIRECT) {
+ // No hostname port to extract; we are done.
+ return ProxyServer(scheme, std::string(), -1);
+ }
+
+ CFStringRef host_ref =
+ (CFStringRef)mac_util::GetValueFromDictionary(dict, host_key,
+ CFStringGetTypeID());
+ if (!host_ref) {
+ LOG(WARNING) << "Could not find expected key "
+ << base::SysCFStringRefToUTF8(host_key)
+ << " in the proxy dictionary";
+ return ProxyServer(); // Invalid.
+ }
+ std::string host = base::SysCFStringRefToUTF8(host_ref);
+
+ CFNumberRef port_ref =
+ (CFNumberRef)mac_util::GetValueFromDictionary(dict, port_key,
+ CFNumberGetTypeID());
+ int port;
+ if (port_ref) {
+ CFNumberGetValue(port_ref, kCFNumberIntType, &port);
+ } else {
+ port = GetDefaultPortForScheme(scheme);
+ }
+
+ return ProxyServer(scheme, host, port);
+}
+
+} // namespace net
diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc
index 7acde10..071415d 100644
--- a/net/proxy/proxy_service.cc
+++ b/net/proxy/proxy_service.cc
@@ -21,6 +21,7 @@
#include "net/proxy/proxy_config_service_win.h"
#include "net/proxy/proxy_resolver_winhttp.h"
#elif defined(OS_MACOSX)
+#include "net/proxy/proxy_config_service_mac.h"
#include "net/proxy/proxy_resolver_mac.h"
#elif defined(OS_LINUX)
#include "net/proxy/proxy_config_service_linux.h"