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" |
wtc
2011/11/16 06:23:33
Can you see if we can remove this #include line no
| |
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::CFCastStrict<CFNumberRef>( |
32 dict, key, CFNumberGetTypeID()); | 33 base::mac::GetValueFromDictionary(dict, key, CFNumberGetTypeID())); |
Mark Mentovai
2011/11/11 17:31:50
I would only consider this a temporary measure. Ge
| |
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::CFCastStrict<CFStringRef>( |
64 config_dict.get(), | 65 base::mac::GetValueFromDictionary( |
65 kSCPropNetProxiesProxyAutoConfigURLString, | 66 config_dict.get(), |
66 CFStringGetTypeID()); | 67 kSCPropNetProxiesProxyAutoConfigURLString, |
68 CFStringGetTypeID())); | |
67 if (pac_url_ref) | 69 if (pac_url_ref) |
68 config->set_pac_url(GURL(base::SysCFStringRefToUTF8(pac_url_ref))); | 70 config->set_pac_url(GURL(base::SysCFStringRefToUTF8(pac_url_ref))); |
69 } | 71 } |
70 | 72 |
71 // proxies (for now ftp, http, https, and SOCKS) | 73 // proxies (for now ftp, http, https, and SOCKS) |
72 | 74 |
73 if (GetBoolFromDictionary(config_dict.get(), | 75 if (GetBoolFromDictionary(config_dict.get(), |
74 kSCPropNetProxiesFTPEnable, | 76 kSCPropNetProxiesFTPEnable, |
75 false)) { | 77 false)) { |
76 ProxyServer proxy_server = | 78 ProxyServer proxy_server = |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
122 kSCPropNetProxiesSOCKSPort); | 124 kSCPropNetProxiesSOCKSPort); |
123 if (proxy_server.is_valid()) { | 125 if (proxy_server.is_valid()) { |
124 config->proxy_rules().type = | 126 config->proxy_rules().type = |
125 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME; | 127 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME; |
126 config->proxy_rules().fallback_proxy = proxy_server; | 128 config->proxy_rules().fallback_proxy = proxy_server; |
127 } | 129 } |
128 } | 130 } |
129 | 131 |
130 // proxy bypass list | 132 // proxy bypass list |
131 | 133 |
132 CFArrayRef bypass_array_ref = | 134 CFArrayRef bypass_array_ref = base::mac::CFCastStrict<CFArrayRef>( |
133 (CFArrayRef)base::mac::GetValueFromDictionary( | 135 base::mac::GetValueFromDictionary( |
134 config_dict.get(), | 136 config_dict.get(), |
135 kSCPropNetProxiesExceptionsList, | 137 kSCPropNetProxiesExceptionsList, |
136 CFArrayGetTypeID()); | 138 CFArrayGetTypeID())); |
137 if (bypass_array_ref) { | 139 if (bypass_array_ref) { |
138 CFIndex bypass_array_count = CFArrayGetCount(bypass_array_ref); | 140 CFIndex bypass_array_count = CFArrayGetCount(bypass_array_ref); |
139 for (CFIndex i = 0; i < bypass_array_count; ++i) { | 141 for (CFIndex i = 0; i < bypass_array_count; ++i) { |
140 CFStringRef bypass_item_ref = | 142 CFStringRef bypass_item_ref = base::mac::CFCast<CFStringRef>( |
141 (CFStringRef)CFArrayGetValueAtIndex(bypass_array_ref, i); | 143 CFArrayGetValueAtIndex(bypass_array_ref, i)); |
142 if (CFGetTypeID(bypass_item_ref) != CFStringGetTypeID()) { | 144 if (CFGetTypeID(bypass_item_ref) != CFStringGetTypeID()) { |
Mark Mentovai
2011/11/11 17:31:50
This is wrong now. bypass_item_ref will either be
| |
143 LOG(WARNING) << "Expected value for item " << i | 145 LOG(WARNING) << "Expected value for item " << i |
144 << " in the kSCPropNetProxiesExceptionsList" | 146 << " in the kSCPropNetProxiesExceptionsList" |
145 " to be a CFStringRef but it was not"; | 147 " to be a CFStringRef but it was not"; |
146 | 148 |
147 } else { | 149 } else { |
148 config->proxy_rules().bypass_rules.AddRuleFromString( | 150 config->proxy_rules().bypass_rules.AddRuleFromString( |
149 base::SysCFStringRefToUTF8(bypass_item_ref)); | 151 base::SysCFStringRefToUTF8(bypass_item_ref)); |
150 } | 152 } |
151 } | 153 } |
152 } | 154 } |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
264 // Keep track of the last value we have seen. | 266 // Keep track of the last value we have seen. |
265 has_fetched_config_ = true; | 267 has_fetched_config_ = true; |
266 last_config_fetched_ = new_config; | 268 last_config_fetched_ = new_config; |
267 | 269 |
268 // Notify all the observers. | 270 // Notify all the observers. |
269 FOR_EACH_OBSERVER(Observer, observers_, | 271 FOR_EACH_OBSERVER(Observer, observers_, |
270 OnProxyConfigChanged(new_config, CONFIG_VALID)); | 272 OnProxyConfigChanged(new_config, CONFIG_VALID)); |
271 } | 273 } |
272 | 274 |
273 } // namespace net | 275 } // namespace net |
OLD | NEW |