OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/chromeos/net/onc_utils.h" | 5 #include "chrome/browser/chromeos/net/onc_utils.h" |
6 | 6 |
7 #include "base/values.h" | 7 #include "base/values.h" |
8 #include "chrome/browser/chromeos/cros/network_ui_data.h" | |
9 #include "chrome/browser/chromeos/proxy_config_service_impl.h" | 8 #include "chrome/browser/chromeos/proxy_config_service_impl.h" |
10 #include "chrome/browser/prefs/proxy_config_dictionary.h" | 9 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
11 #include "chromeos/network/onc/onc_signature.h" | |
12 #include "chromeos/network/onc/onc_utils.h" | 10 #include "chromeos/network/onc/onc_utils.h" |
13 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
14 #include "net/proxy/proxy_server.h" | 12 #include "net/proxy/proxy_server.h" |
15 | 13 |
16 namespace chromeos { | 14 namespace chromeos { |
17 namespace onc { | 15 namespace onc { |
18 | 16 |
19 namespace { | 17 namespace { |
20 | 18 |
21 net::ProxyServer ConvertOncProxyLocationToHostPort( | 19 net::ProxyServer ConvertOncProxyLocationToHostPort( |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 ConvertOncExcludeDomainsToBypassRules(*exclude_domains)); | 116 ConvertOncExcludeDomainsToBypassRules(*exclude_domains)); |
119 } | 117 } |
120 proxy_dict.reset(ProxyConfigDictionary::CreateFixedServers( | 118 proxy_dict.reset(ProxyConfigDictionary::CreateFixedServers( |
121 manual_spec, bypass_rules.ToString())); | 119 manual_spec, bypass_rules.ToString())); |
122 } else { | 120 } else { |
123 NOTREACHED(); | 121 NOTREACHED(); |
124 } | 122 } |
125 return proxy_dict.Pass(); | 123 return proxy_dict.Pass(); |
126 } | 124 } |
127 | 125 |
128 namespace { | |
129 | |
130 void TranslateClientCertType(const std::string& client_cert_type, | |
131 NetworkUIData* ui_data) { | |
132 ClientCertType type; | |
133 if (client_cert_type == certificate::kNone) { | |
134 type = CLIENT_CERT_TYPE_NONE; | |
135 } else if (client_cert_type == certificate::kRef) { | |
136 type = CLIENT_CERT_TYPE_REF; | |
137 } else if (client_cert_type == certificate::kPattern) { | |
138 type = CLIENT_CERT_TYPE_PATTERN; | |
139 } else { | |
140 type = CLIENT_CERT_TYPE_NONE; | |
141 NOTREACHED(); | |
142 } | |
143 | |
144 ui_data->set_certificate_type(type); | |
145 } | |
146 | |
147 void TranslateCertificatePattern(const base::DictionaryValue& onc_object, | |
148 NetworkUIData* ui_data) { | |
149 CertificatePattern pattern; | |
150 bool success = pattern.CopyFromDictionary(onc_object); | |
151 DCHECK(success); | |
152 ui_data->set_certificate_pattern(pattern); | |
153 } | |
154 | |
155 void TranslateEAP(const base::DictionaryValue& eap, | |
156 NetworkUIData* ui_data) { | |
157 std::string client_cert_type; | |
158 if (eap.GetStringWithoutPathExpansion(eap::kClientCertType, | |
159 &client_cert_type)) { | |
160 TranslateClientCertType(client_cert_type, ui_data); | |
161 } | |
162 } | |
163 | |
164 void TranslateIPsec(const base::DictionaryValue& ipsec, | |
165 NetworkUIData* ui_data) { | |
166 std::string client_cert_type; | |
167 if (ipsec.GetStringWithoutPathExpansion(vpn::kClientCertType, | |
168 &client_cert_type)) { | |
169 TranslateClientCertType(client_cert_type, ui_data); | |
170 } | |
171 } | |
172 | |
173 void TranslateOpenVPN(const base::DictionaryValue& openvpn, | |
174 NetworkUIData* ui_data) { | |
175 std::string client_cert_type; | |
176 if (openvpn.GetStringWithoutPathExpansion(vpn::kClientCertType, | |
177 &client_cert_type)) { | |
178 TranslateClientCertType(client_cert_type, ui_data); | |
179 } | |
180 } | |
181 | |
182 void TranslateONCHierarchy(const OncValueSignature& signature, | |
183 const base::DictionaryValue& onc_object, | |
184 NetworkUIData* ui_data) { | |
185 if (&signature == &kCertificatePatternSignature) | |
186 TranslateCertificatePattern(onc_object, ui_data); | |
187 else if (&signature == &kEAPSignature) | |
188 TranslateEAP(onc_object, ui_data); | |
189 else if (&signature == &kIPsecSignature) | |
190 TranslateIPsec(onc_object, ui_data); | |
191 else if (&signature == &kOpenVPNSignature) | |
192 TranslateOpenVPN(onc_object, ui_data); | |
193 | |
194 // Recurse into nested objects. | |
195 for (base::DictionaryValue::Iterator it(onc_object); !it.IsAtEnd(); | |
196 it.Advance()) { | |
197 const base::DictionaryValue* inner_object; | |
198 if (!it.value().GetAsDictionary(&inner_object)) | |
199 continue; | |
200 | |
201 const OncFieldSignature* field_signature = | |
202 GetFieldSignature(signature, it.key()); | |
203 | |
204 TranslateONCHierarchy(*field_signature->value_signature, *inner_object, | |
205 ui_data); | |
206 } | |
207 } | |
208 | |
209 } // namespace | |
210 | |
211 scoped_ptr<NetworkUIData> CreateUIData( | |
212 ONCSource onc_source, | |
213 const base::DictionaryValue& onc_network) { | |
214 scoped_ptr<NetworkUIData> ui_data(new NetworkUIData()); | |
215 TranslateONCHierarchy(kNetworkConfigurationSignature, onc_network, | |
216 ui_data.get()); | |
217 | |
218 ui_data->set_onc_source(onc_source); | |
219 | |
220 return ui_data.Pass(); | |
221 } | |
222 | |
223 } // namespace onc | 126 } // namespace onc |
224 } // namespace chromeos | 127 } // namespace chromeos |
OLD | NEW |