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" |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 return false; | 273 return false; |
274 } | 274 } |
275 } | 275 } |
276 | 276 |
277 if (extension_ids) | 277 if (extension_ids) |
278 *extension_ids = list_value; | 278 *extension_ids = list_value; |
279 | 279 |
280 return true; | 280 return true; |
281 } | 281 } |
282 | 282 |
| 283 // ExtensionURLPatternListPolicyHandler implementation ------------------------- |
| 284 |
| 285 ExtensionURLPatternListPolicyHandler::ExtensionURLPatternListPolicyHandler( |
| 286 const char* policy_name, |
| 287 const char* pref_path) |
| 288 : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), |
| 289 pref_path_(pref_path) {} |
| 290 |
| 291 ExtensionURLPatternListPolicyHandler::~ExtensionURLPatternListPolicyHandler() {} |
| 292 |
| 293 bool ExtensionURLPatternListPolicyHandler::CheckPolicySettings( |
| 294 const PolicyMap& policies, |
| 295 PolicyErrorMap* errors) { |
| 296 const base::Value* value = NULL; |
| 297 if (!CheckAndGetValue(policies, errors, &value)) |
| 298 return false; |
| 299 |
| 300 if (!value) |
| 301 return true; |
| 302 |
| 303 const base::ListValue* list_value = NULL; |
| 304 if (!value->GetAsList(&list_value)) { |
| 305 NOTREACHED(); |
| 306 return false; |
| 307 } |
| 308 |
| 309 // Check that the list contains valid URLPattern strings only. |
| 310 for (base::ListValue::const_iterator entry(list_value->begin()); |
| 311 entry != list_value->end(); ++entry) { |
| 312 std::string url_pattern_string; |
| 313 if (!(*entry)->GetAsString(&url_pattern_string)) { |
| 314 errors->AddError(policy_name(), |
| 315 entry - list_value->begin(), |
| 316 IDS_POLICY_TYPE_ERROR, |
| 317 ValueTypeToString(base::Value::TYPE_STRING)); |
| 318 return false; |
| 319 } |
| 320 |
| 321 URLPattern pattern(URLPattern::SCHEME_ALL); |
| 322 if (pattern.Parse(url_pattern_string) != URLPattern::PARSE_SUCCESS) { |
| 323 errors->AddError(policy_name(), |
| 324 entry - list_value->begin(), |
| 325 IDS_POLICY_VALUE_FORMAT_ERROR); |
| 326 return false; |
| 327 } |
| 328 } |
| 329 |
| 330 return true; |
| 331 } |
| 332 |
| 333 void ExtensionURLPatternListPolicyHandler::ApplyPolicySettings( |
| 334 const PolicyMap& policies, |
| 335 PrefValueMap* prefs) { |
| 336 const Value* value = policies.GetValue(policy_name()); |
| 337 if (value) |
| 338 prefs->SetValue(pref_path_, value->DeepCopy()); |
| 339 } |
| 340 |
283 // SimplePolicyHandler implementation ------------------------------------------ | 341 // SimplePolicyHandler implementation ------------------------------------------ |
284 | 342 |
285 SimplePolicyHandler::SimplePolicyHandler( | 343 SimplePolicyHandler::SimplePolicyHandler( |
286 const char* policy_name, | 344 const char* policy_name, |
287 const char* pref_path, | 345 const char* pref_path, |
288 Value::Type value_type) | 346 Value::Type value_type) |
289 : TypeCheckingPolicyHandler(policy_name, value_type), | 347 : TypeCheckingPolicyHandler(policy_name, value_type), |
290 pref_path_(pref_path) { | 348 pref_path_(pref_path) { |
291 } | 349 } |
292 | 350 |
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1146 errors->AddError(policy_name(), | 1204 errors->AddError(policy_name(), |
1147 IDS_POLICY_OUT_OF_RANGE_ERROR, | 1205 IDS_POLICY_OUT_OF_RANGE_ERROR, |
1148 base::IntToString(restore_value)); | 1206 base::IntToString(restore_value)); |
1149 } | 1207 } |
1150 } | 1208 } |
1151 } | 1209 } |
1152 return true; | 1210 return true; |
1153 } | 1211 } |
1154 | 1212 |
1155 } // namespace policy | 1213 } // namespace policy |
OLD | NEW |