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_config_service_mac.h" | 5 #include "net/proxy/proxy_config_service_mac.h" |
6 | 6 |
7 #include <CoreFoundation/CoreFoundation.h> | 7 #include <CoreFoundation/CoreFoundation.h> |
8 #include <SystemConfiguration/SystemConfiguration.h> | 8 #include <SystemConfiguration/SystemConfiguration.h> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/mac/foundation_util.h" |
11 #include "base/mac/mac_util.h" | 12 #include "base/mac/mac_util.h" |
12 #include "base/mac/scoped_cftyperef.h" | 13 #include "base/mac/scoped_cftyperef.h" |
13 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
14 #include "base/sys_string_conversions.h" | 15 #include "base/sys_string_conversions.h" |
15 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
16 #include "net/proxy/proxy_config.h" | 17 #include "net/proxy/proxy_config.h" |
17 #include "net/proxy/proxy_info.h" | 18 #include "net/proxy/proxy_info.h" |
18 #include "net/proxy/proxy_server.h" | 19 #include "net/proxy/proxy_server.h" |
19 | 20 |
20 namespace net { | 21 namespace net { |
21 | 22 |
22 namespace { | 23 namespace { |
23 | 24 |
24 const int kPollIntervalSec = 5; | 25 const int kPollIntervalSec = 5; |
25 | 26 |
26 // Utility function to pull out a boolean value from a dictionary and return it, | 27 // Utility function to pull out a boolean value from a dictionary and return it, |
27 // returning a default value if the key is not present. | 28 // returning a default value if the key is not present. |
28 bool GetBoolFromDictionary(CFDictionaryRef dict, | 29 bool GetBoolFromDictionary(CFDictionaryRef dict, |
29 CFStringRef key, | 30 CFStringRef key, |
30 bool default_value) { | 31 bool default_value) { |
31 CFNumberRef number = (CFNumberRef)base::mac::GetValueFromDictionary( | 32 CFNumberRef number = base::mac::GetValueFromDictionary<CFNumberRef>(dict, |
32 dict, key, CFNumberGetTypeID()); | 33 key); |
33 if (!number) | 34 if (!number) |
34 return default_value; | 35 return default_value; |
35 | 36 |
36 int int_value; | 37 int int_value; |
37 if (CFNumberGetValue(number, kCFNumberIntType, &int_value)) | 38 if (CFNumberGetValue(number, kCFNumberIntType, &int_value)) |
38 return int_value; | 39 return int_value; |
39 else | 40 else |
40 return default_value; | 41 return default_value; |
41 } | 42 } |
42 | 43 |
(...skipping 10 matching lines...) Expand all Loading... |
53 config->set_auto_detect( | 54 config->set_auto_detect( |
54 GetBoolFromDictionary(config_dict.get(), | 55 GetBoolFromDictionary(config_dict.get(), |
55 kSCPropNetProxiesProxyAutoDiscoveryEnable, | 56 kSCPropNetProxiesProxyAutoDiscoveryEnable, |
56 false)); | 57 false)); |
57 | 58 |
58 // PAC file | 59 // PAC file |
59 | 60 |
60 if (GetBoolFromDictionary(config_dict.get(), | 61 if (GetBoolFromDictionary(config_dict.get(), |
61 kSCPropNetProxiesProxyAutoConfigEnable, | 62 kSCPropNetProxiesProxyAutoConfigEnable, |
62 false)) { | 63 false)) { |
63 CFStringRef pac_url_ref = (CFStringRef)base::mac::GetValueFromDictionary( | 64 CFStringRef pac_url_ref = base::mac::GetValueFromDictionary<CFStringRef>( |
64 config_dict.get(), | 65 config_dict.get(), kSCPropNetProxiesProxyAutoConfigURLString); |
65 kSCPropNetProxiesProxyAutoConfigURLString, | |
66 CFStringGetTypeID()); | |
67 if (pac_url_ref) | 66 if (pac_url_ref) |
68 config->set_pac_url(GURL(base::SysCFStringRefToUTF8(pac_url_ref))); | 67 config->set_pac_url(GURL(base::SysCFStringRefToUTF8(pac_url_ref))); |
69 } | 68 } |
70 | 69 |
71 // proxies (for now ftp, http, https, and SOCKS) | 70 // proxies (for now ftp, http, https, and SOCKS) |
72 | 71 |
73 if (GetBoolFromDictionary(config_dict.get(), | 72 if (GetBoolFromDictionary(config_dict.get(), |
74 kSCPropNetProxiesFTPEnable, | 73 kSCPropNetProxiesFTPEnable, |
75 false)) { | 74 false)) { |
76 ProxyServer proxy_server = | 75 ProxyServer proxy_server = |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 kSCPropNetProxiesSOCKSPort); | 121 kSCPropNetProxiesSOCKSPort); |
123 if (proxy_server.is_valid()) { | 122 if (proxy_server.is_valid()) { |
124 config->proxy_rules().type = | 123 config->proxy_rules().type = |
125 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME; | 124 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME; |
126 config->proxy_rules().fallback_proxy = proxy_server; | 125 config->proxy_rules().fallback_proxy = proxy_server; |
127 } | 126 } |
128 } | 127 } |
129 | 128 |
130 // proxy bypass list | 129 // proxy bypass list |
131 | 130 |
132 CFArrayRef bypass_array_ref = | 131 CFArrayRef bypass_array_ref = base::mac::GetValueFromDictionary<CFArrayRef>( |
133 (CFArrayRef)base::mac::GetValueFromDictionary( | 132 config_dict.get(), kSCPropNetProxiesExceptionsList); |
134 config_dict.get(), | |
135 kSCPropNetProxiesExceptionsList, | |
136 CFArrayGetTypeID()); | |
137 if (bypass_array_ref) { | 133 if (bypass_array_ref) { |
138 CFIndex bypass_array_count = CFArrayGetCount(bypass_array_ref); | 134 CFIndex bypass_array_count = CFArrayGetCount(bypass_array_ref); |
139 for (CFIndex i = 0; i < bypass_array_count; ++i) { | 135 for (CFIndex i = 0; i < bypass_array_count; ++i) { |
140 CFStringRef bypass_item_ref = | 136 CFStringRef bypass_item_ref = base::mac::CFCast<CFStringRef>( |
141 (CFStringRef)CFArrayGetValueAtIndex(bypass_array_ref, i); | 137 CFArrayGetValueAtIndex(bypass_array_ref, i)); |
142 if (CFGetTypeID(bypass_item_ref) != CFStringGetTypeID()) { | 138 if (!bypass_item_ref) { |
143 LOG(WARNING) << "Expected value for item " << i | 139 LOG(WARNING) << "Expected value for item " << i |
144 << " in the kSCPropNetProxiesExceptionsList" | 140 << " in the kSCPropNetProxiesExceptionsList" |
145 " to be a CFStringRef but it was not"; | 141 " to be a CFStringRef but it was not"; |
146 | 142 |
147 } else { | 143 } else { |
148 config->proxy_rules().bypass_rules.AddRuleFromString( | 144 config->proxy_rules().bypass_rules.AddRuleFromString( |
149 base::SysCFStringRefToUTF8(bypass_item_ref)); | 145 base::SysCFStringRefToUTF8(bypass_item_ref)); |
150 } | 146 } |
151 } | 147 } |
152 } | 148 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 // Keep track of the last value we have seen. | 260 // Keep track of the last value we have seen. |
265 has_fetched_config_ = true; | 261 has_fetched_config_ = true; |
266 last_config_fetched_ = new_config; | 262 last_config_fetched_ = new_config; |
267 | 263 |
268 // Notify all the observers. | 264 // Notify all the observers. |
269 FOR_EACH_OBSERVER(Observer, observers_, | 265 FOR_EACH_OBSERVER(Observer, observers_, |
270 OnProxyConfigChanged(new_config, CONFIG_VALID)); | 266 OnProxyConfigChanged(new_config, CONFIG_VALID)); |
271 } | 267 } |
272 | 268 |
273 } // namespace net | 269 } // namespace net |
OLD | NEW |