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 ----------------------------------- |
| 209 |
| 210 ExtensionListPolicyHandler::ExtensionListPolicyHandler(const char* policy_name, |
| 211 const char* pref_path, |
| 212 bool allow_wildcards) |
| 213 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), |
| 214 pref_path_(pref_path), |
| 215 allow_wildcards_(allow_wildcards) {} |
| 216 |
| 217 ExtensionListPolicyHandler::~ExtensionListPolicyHandler() {} |
| 218 |
| 219 bool ExtensionListPolicyHandler::CheckPolicySettings( |
| 220 const PolicyMap& policies, |
| 221 PolicyErrorMap* errors) { |
| 222 return CheckAndGetList(policies, errors, NULL); |
| 223 } |
| 224 |
| 225 void ExtensionListPolicyHandler::ApplyPolicySettings( |
| 226 const PolicyMap& policies, |
| 227 PrefValueMap* prefs) { |
| 228 const Value* value = policies.GetValue(policy_name()); |
| 229 if (value) |
| 230 prefs->SetValue(pref_path(), value->DeepCopy()); |
| 231 } |
| 232 |
| 233 const char* ExtensionListPolicyHandler::pref_path() const { |
| 234 return pref_path_; |
| 235 } |
| 236 |
| 237 bool ExtensionListPolicyHandler::CheckAndGetList( |
| 238 const PolicyMap& policies, |
| 239 PolicyErrorMap* errors, |
| 240 const base::ListValue** extension_ids) { |
| 241 if (extension_ids) |
| 242 *extension_ids = NULL; |
| 243 |
| 244 const base::Value* value = NULL; |
| 245 if (!CheckAndGetValue(policies, errors, &value)) |
| 246 return false; |
| 247 |
| 248 if (!value) |
| 249 return true; |
| 250 |
| 251 const base::ListValue* list_value = NULL; |
| 252 if (!value->GetAsList(&list_value)) { |
| 253 NOTREACHED(); |
| 254 return false; |
| 255 } |
| 256 |
| 257 // Check that the list contains valid extension ID strings only. |
| 258 for (base::ListValue::const_iterator entry(list_value->begin()); |
| 259 entry != list_value->end(); ++entry) { |
| 260 std::string id; |
| 261 if (!(*entry)->GetAsString(&id)) { |
| 262 errors->AddError(policy_name(), |
| 263 entry - list_value->begin(), |
| 264 IDS_POLICY_TYPE_ERROR, |
| 265 ValueTypeToString(base::Value::TYPE_STRING)); |
| 266 return false; |
| 267 } |
| 268 if (!(allow_wildcards_ && id == "*") && !Extension::IdIsValid(id)) { |
| 269 errors->AddError(policy_name(), |
| 270 entry - list_value->begin(), |
| 271 IDS_POLICY_VALUE_FORMAT_ERROR); |
| 272 return false; |
| 273 } |
| 274 } |
| 275 |
| 276 if (extension_ids) |
| 277 *extension_ids = list_value; |
| 278 |
| 279 return true; |
| 280 } |
| 281 |
207 // SimplePolicyHandler implementation ------------------------------------------ | 282 // SimplePolicyHandler implementation ------------------------------------------ |
208 | 283 |
209 SimplePolicyHandler::SimplePolicyHandler( | 284 SimplePolicyHandler::SimplePolicyHandler( |
210 const char* policy_name, | 285 const char* policy_name, |
211 const char* pref_path, | 286 const char* pref_path, |
212 Value::Type value_type) | 287 Value::Type value_type) |
213 : TypeCheckingPolicyHandler(policy_name, value_type), | 288 : TypeCheckingPolicyHandler(policy_name, value_type), |
214 pref_path_(pref_path) { | 289 pref_path_(pref_path) { |
215 } | 290 } |
216 | 291 |
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 errors->AddError(policy_name(), | 1145 errors->AddError(policy_name(), |
1071 IDS_POLICY_OUT_OF_RANGE_ERROR, | 1146 IDS_POLICY_OUT_OF_RANGE_ERROR, |
1072 base::IntToString(restore_value)); | 1147 base::IntToString(restore_value)); |
1073 } | 1148 } |
1074 } | 1149 } |
1075 } | 1150 } |
1076 return true; | 1151 return true; |
1077 } | 1152 } |
1078 | 1153 |
1079 } // namespace policy | 1154 } // namespace policy |
OLD | NEW |