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/policy/configuration_policy_handler.h" | 5 #include "chrome/browser/policy/configuration_policy_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "base/string16.h" | 13 #include "base/string16.h" |
14 #include "base/string_number_conversions.h" | 14 #include "base/string_number_conversions.h" |
15 #include "base/string_util.h" | 15 #include "base/string_util.h" |
16 #include "chrome/browser/download/download_util.h" | 16 #include "chrome/browser/download/download_util.h" |
17 #include "chrome/browser/policy/configuration_policy_pref_store.h" | 17 #include "chrome/browser/policy/configuration_policy_pref_store.h" |
18 #include "chrome/browser/policy/policy_error_map.h" | 18 #include "chrome/browser/policy/policy_error_map.h" |
19 #include "chrome/browser/policy/policy_map.h" | 19 #include "chrome/browser/policy/policy_map.h" |
20 #include "chrome/browser/policy/policy_path_parser.h" | 20 #include "chrome/browser/policy/policy_path_parser.h" |
21 #include "chrome/browser/prefs/pref_value_map.h" | 21 #include "chrome/browser/prefs/pref_value_map.h" |
22 #include "chrome/browser/prefs/proxy_config_dictionary.h" | 22 #include "chrome/browser/prefs/proxy_config_dictionary.h" |
23 #include "chrome/browser/prefs/proxy_prefs.h" | 23 #include "chrome/browser/prefs/proxy_prefs.h" |
24 #include "chrome/browser/prefs/session_startup_pref.h" | 24 #include "chrome/browser/prefs/session_startup_pref.h" |
25 #include "chrome/browser/search_engines/search_terms_data.h" | 25 #include "chrome/browser/search_engines/search_terms_data.h" |
26 #include "chrome/browser/search_engines/template_url.h" | 26 #include "chrome/browser/search_engines/template_url.h" |
27 #include "chrome/common/chrome_notification_types.h" | 27 #include "chrome/common/chrome_notification_types.h" |
28 #include "chrome/common/content_settings.h" | 28 #include "chrome/common/content_settings.h" |
29 #include "chrome/common/extensions/extension.h" | |
29 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
30 #include "content/public/browser/notification_service.h" | 31 #include "content/public/browser/notification_service.h" |
31 #include "grit/generated_resources.h" | 32 #include "grit/generated_resources.h" |
32 #include "policy/policy_constants.h" | 33 #include "policy/policy_constants.h" |
33 | 34 |
34 namespace policy { | 35 namespace policy { |
35 | 36 |
36 namespace { | 37 namespace { |
37 | 38 |
38 // Helper classes -------------------------------------------------------------- | 39 // Helper classes -------------------------------------------------------------- |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 *value = policies.GetValue(policy_name_); | 198 *value = policies.GetValue(policy_name_); |
198 if (*value && !(*value)->IsType(value_type_)) { | 199 if (*value && !(*value)->IsType(value_type_)) { |
199 errors->AddError(policy_name_, | 200 errors->AddError(policy_name_, |
200 IDS_POLICY_TYPE_ERROR, | 201 IDS_POLICY_TYPE_ERROR, |
201 ValueTypeToString(value_type_)); | 202 ValueTypeToString(value_type_)); |
202 return false; | 203 return false; |
203 } | 204 } |
204 return true; | 205 return true; |
205 } | 206 } |
206 | 207 |
208 // ExtensionListPolicyHandler implementation ----------------------------------- | |
Joao da Silva
2012/05/03 18:41:22
nit: newline
Mattias Nissler (ping if slow)
2012/05/03 20:13:04
Done.
| |
209 ExtensionListPolicyHandler::ExtensionListPolicyHandler(const char* policy_name, | |
210 const char* pref_path, | |
211 bool allow_wildcards) | |
212 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), | |
213 pref_path_(pref_path), | |
214 allow_wildcards_(allow_wildcards) {} | |
215 | |
216 ExtensionListPolicyHandler::~ExtensionListPolicyHandler() {} | |
217 | |
218 bool ExtensionListPolicyHandler::CheckPolicySettings( | |
219 const PolicyMap& policies, | |
220 PolicyErrorMap* errors) { | |
221 return CheckAndGetList(policies, errors, NULL); | |
222 } | |
223 | |
224 void ExtensionListPolicyHandler::ApplyPolicySettings( | |
225 const PolicyMap& policies, | |
226 PrefValueMap* prefs) { | |
227 const Value* value = policies.GetValue(policy_name()); | |
228 if (value) | |
229 prefs->SetValue(pref_path(), value->DeepCopy()); | |
230 } | |
231 | |
232 const char* ExtensionListPolicyHandler::pref_path() const { | |
233 return pref_path_; | |
234 } | |
235 | |
236 bool ExtensionListPolicyHandler::CheckAndGetList( | |
237 const PolicyMap& policies, | |
238 PolicyErrorMap* errors, | |
239 const base::ListValue** extension_ids) { | |
240 if (extension_ids) | |
241 *extension_ids = NULL; | |
242 | |
243 const base::Value* value = NULL; | |
244 if (!CheckAndGetValue(policies, errors, &value)) | |
245 return false; | |
246 | |
247 if (!value) | |
248 return true; | |
249 | |
250 const base::ListValue* list_value = NULL; | |
251 if (!value->GetAsList(&list_value)) { | |
252 NOTREACHED(); | |
253 return false; | |
254 } | |
255 | |
256 // Check that the list contains valid extension ID strings only. | |
257 for (base::ListValue::const_iterator entry(list_value->begin()); | |
258 entry != list_value->end(); ++entry) { | |
259 std::string id; | |
260 if (!(*entry)->GetAsString(&id)) { | |
261 errors->AddError(policy_name(), | |
262 entry - list_value->begin(), | |
263 IDS_POLICY_TYPE_ERROR, | |
264 ValueTypeToString(base::Value::TYPE_STRING)); | |
265 return false; | |
266 } | |
267 if (!(allow_wildcards_ && id == "*") && !Extension::IdIsValid(id)) { | |
268 errors->AddError(policy_name(), | |
269 entry - list_value->begin(), | |
270 IDS_POLICY_VALUE_FORMAT_ERROR); | |
271 return false; | |
272 } | |
273 } | |
274 | |
275 if (extension_ids) | |
276 *extension_ids = list_value; | |
277 | |
278 return true; | |
279 } | |
280 | |
207 // SimplePolicyHandler implementation ------------------------------------------ | 281 // SimplePolicyHandler implementation ------------------------------------------ |
208 | 282 |
209 SimplePolicyHandler::SimplePolicyHandler( | 283 SimplePolicyHandler::SimplePolicyHandler( |
210 const char* policy_name, | 284 const char* policy_name, |
211 const char* pref_path, | 285 const char* pref_path, |
212 Value::Type value_type) | 286 Value::Type value_type) |
213 : TypeCheckingPolicyHandler(policy_name, value_type), | 287 : TypeCheckingPolicyHandler(policy_name, value_type), |
214 pref_path_(pref_path) { | 288 pref_path_(pref_path) { |
215 } | 289 } |
216 | 290 |
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1070 errors->AddError(policy_name(), | 1144 errors->AddError(policy_name(), |
1071 IDS_POLICY_OUT_OF_RANGE_ERROR, | 1145 IDS_POLICY_OUT_OF_RANGE_ERROR, |
1072 base::IntToString(restore_value)); | 1146 base::IntToString(restore_value)); |
1073 } | 1147 } |
1074 } | 1148 } |
1075 } | 1149 } |
1076 return true; | 1150 return true; |
1077 } | 1151 } |
1078 | 1152 |
1079 } // namespace policy | 1153 } // namespace policy |
OLD | NEW |