Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: chrome/browser/policy/configuration_policy_handler.cc

Issue 8480003: Surface error messages from ONC parsing in about:policy. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Only compile unit test for chromium os. Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "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 #include <vector> 8 #include <vector>
9 9
10 #include "base/file_path.h" 10 #include "base/file_path.h"
(...skipping 13 matching lines...) Expand all
24 #include "chrome/browser/prefs/proxy_config_dictionary.h" 24 #include "chrome/browser/prefs/proxy_config_dictionary.h"
25 #include "chrome/browser/prefs/proxy_prefs.h" 25 #include "chrome/browser/prefs/proxy_prefs.h"
26 #include "chrome/browser/search_engines/search_terms_data.h" 26 #include "chrome/browser/search_engines/search_terms_data.h"
27 #include "chrome/browser/search_engines/template_url.h" 27 #include "chrome/browser/search_engines/template_url.h"
28 #include "chrome/common/content_settings.h" 28 #include "chrome/common/content_settings.h"
29 #include "chrome/common/pref_names.h" 29 #include "chrome/common/pref_names.h"
30 #include "grit/generated_resources.h" 30 #include "grit/generated_resources.h"
31 #include "policy/configuration_policy_type.h" 31 #include "policy/configuration_policy_type.h"
32 #include "policy/policy_constants.h" 32 #include "policy/policy_constants.h"
33 33
34 #if defined(OS_CHROMEOS)
35 #include "chrome/browser/policy/configuration_policy_handler_chromeos.h"
36 #endif
37
34 namespace policy { 38 namespace policy {
35 39
36 namespace { 40 namespace {
37 41
38 // Implementations of ConfigurationPolicyHandler ------------------------------- 42 // Implementations of ConfigurationPolicyHandler -------------------------------
39 43
40 // Abstract class derived from ConfigurationPolicyHandler that should be
41 // subclassed to handle a single policy (not a combination of policies).
42 class TypeCheckingPolicyHandler : public ConfigurationPolicyHandler {
43 public:
44 TypeCheckingPolicyHandler(ConfigurationPolicyType policy_type,
45 base::Value::Type value_type);
46
47 // ConfigurationPolicyHandler methods:
48 virtual bool CheckPolicySettings(const PolicyMap* policies,
49 PolicyErrorMap* errors) OVERRIDE;
50
51 protected:
52 virtual ~TypeCheckingPolicyHandler();
53
54 ConfigurationPolicyType policy_type() const;
55
56 private:
57 // The ConfigurationPolicyType of the policy.
58 ConfigurationPolicyType policy_type_;
59
60 // The type the value of the policy should have.
61 base::Value::Type value_type_;
62
63 DISALLOW_COPY_AND_ASSIGN(TypeCheckingPolicyHandler);
64 };
65
66 // ConfigurationPolicyHandler for policies that map directly to a preference. 44 // ConfigurationPolicyHandler for policies that map directly to a preference.
67 class SimplePolicyHandler : public TypeCheckingPolicyHandler { 45 class SimplePolicyHandler : public TypeCheckingPolicyHandler {
68 public: 46 public:
69 SimplePolicyHandler(ConfigurationPolicyType policy_type, 47 SimplePolicyHandler(ConfigurationPolicyType policy_type,
70 base::Value::Type value_type, 48 base::Value::Type value_type,
71 const char* pref_path); 49 const char* pref_path);
72 virtual ~SimplePolicyHandler(); 50 virtual ~SimplePolicyHandler();
73 51
74 // ConfigurationPolicyHandler methods: 52 // ConfigurationPolicyHandler methods:
75 virtual void ApplyPolicySettings(const PolicyMap* policies, 53 virtual void ApplyPolicySettings(const PolicyMap* policies,
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 // Converts the deprecated ProxyServerMode policy value to a ProxyMode value 227 // Converts the deprecated ProxyServerMode policy value to a ProxyMode value
250 // and places the result in |mode_value|. Returns true if the conversion 228 // and places the result in |mode_value|. Returns true if the conversion
251 // succeeded and false otherwise. 229 // succeeded and false otherwise.
252 bool CheckProxyModeAndServerMode(const PolicyMap* policies, 230 bool CheckProxyModeAndServerMode(const PolicyMap* policies,
253 PolicyErrorMap* errors, 231 PolicyErrorMap* errors,
254 std::string* mode_value); 232 std::string* mode_value);
255 233
256 DISALLOW_COPY_AND_ASSIGN(ProxyPolicyHandler); 234 DISALLOW_COPY_AND_ASSIGN(ProxyPolicyHandler);
257 }; 235 };
258 236
259 // 237 // ConfigurationPolicyHandler for policies that enable/disable Javascript.
260 class JavascriptPolicyHandler : public ConfigurationPolicyHandler { 238 class JavascriptPolicyHandler : public ConfigurationPolicyHandler {
261 public: 239 public:
262 JavascriptPolicyHandler(); 240 JavascriptPolicyHandler();
263 virtual ~JavascriptPolicyHandler(); 241 virtual ~JavascriptPolicyHandler();
264 242
265 // ConfigurationPolicyHandler methods: 243 // ConfigurationPolicyHandler methods:
266 virtual bool CheckPolicySettings(const PolicyMap* policies, 244 virtual bool CheckPolicySettings(const PolicyMap* policies,
267 PolicyErrorMap* errors) OVERRIDE; 245 PolicyErrorMap* errors) OVERRIDE;
268 virtual void ApplyPolicySettings(const PolicyMap* policies, 246 virtual void ApplyPolicySettings(const PolicyMap* policies,
269 PrefValueMap* prefs) OVERRIDE; 247 PrefValueMap* prefs) OVERRIDE;
270 248
271 private: 249 private:
272 DISALLOW_COPY_AND_ASSIGN(JavascriptPolicyHandler); 250 DISALLOW_COPY_AND_ASSIGN(JavascriptPolicyHandler);
273 }; 251 };
274 252
275
276 // Helper classes -------------------------------------------------------------- 253 // Helper classes --------------------------------------------------------------
277 254
278 // Implementation of SearchTermsData just for validation. 255 // Implementation of SearchTermsData just for validation.
279 class SearchTermsDataForValidation : public SearchTermsData { 256 class SearchTermsDataForValidation : public SearchTermsData {
280 public: 257 public:
281 SearchTermsDataForValidation() {} 258 SearchTermsDataForValidation() {}
282 259
283 // Implementation of SearchTermsData. 260 // Implementation of SearchTermsData.
284 virtual std::string GoogleBaseURLValue() const { 261 virtual std::string GoogleBaseURLValue() const {
285 return "http://www.google.com/"; 262 return "http://www.google.com/";
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 "string", 508 "string",
532 "binary", 509 "binary",
533 "dictionary", 510 "dictionary",
534 "list" 511 "list"
535 }; 512 };
536 DCHECK(static_cast<size_t>(type) < arraysize(strings)); 513 DCHECK(static_cast<size_t>(type) < arraysize(strings));
537 return std::string(strings[type]); 514 return std::string(strings[type]);
538 } 515 }
539 516
540 517
541 // TypeCheckingPolicyHandler implementation ------------------------------------
542
543 TypeCheckingPolicyHandler::TypeCheckingPolicyHandler(
544 ConfigurationPolicyType policy_type,
545 Value::Type value_type)
546 : policy_type_(policy_type),
547 value_type_(value_type) {
548 }
549
550 TypeCheckingPolicyHandler::~TypeCheckingPolicyHandler() {
551 }
552
553 ConfigurationPolicyType TypeCheckingPolicyHandler::policy_type() const {
554 return policy_type_;
555 }
556
557 bool TypeCheckingPolicyHandler::CheckPolicySettings(const PolicyMap* policies,
558 PolicyErrorMap* errors) {
559 const Value* value = policies->Get(policy_type_);
560 if (value && value_type_ != value->GetType()) {
561 errors->AddError(policy_type_,
562 IDS_POLICY_TYPE_ERROR,
563 ValueTypeToString(value_type_));
564 return false;
565 }
566 return true;
567 }
568
569
570 // SimplePolicyHandler implementation ------------------------------------------ 518 // SimplePolicyHandler implementation ------------------------------------------
571 519
572 SimplePolicyHandler::SimplePolicyHandler( 520 SimplePolicyHandler::SimplePolicyHandler(
573 ConfigurationPolicyType policy_type, 521 ConfigurationPolicyType policy_type,
574 Value::Type value_type, 522 Value::Type value_type,
575 const char* pref_path) 523 const char* pref_path)
576 : TypeCheckingPolicyHandler(policy_type, value_type), 524 : TypeCheckingPolicyHandler(policy_type, value_type),
577 pref_path_(pref_path) { 525 pref_path_(pref_path) {
578 } 526 }
579 527
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
1286 // javascript globally. 1234 // javascript globally.
1287 if (!enabled) 1235 if (!enabled)
1288 setting = CONTENT_SETTING_BLOCK; 1236 setting = CONTENT_SETTING_BLOCK;
1289 } 1237 }
1290 1238
1291 if (setting != CONTENT_SETTING_DEFAULT) 1239 if (setting != CONTENT_SETTING_DEFAULT)
1292 prefs->SetValue(prefs::kManagedDefaultJavaScriptSetting, 1240 prefs->SetValue(prefs::kManagedDefaultJavaScriptSetting,
1293 Value::CreateIntegerValue(setting)); 1241 Value::CreateIntegerValue(setting));
1294 } 1242 }
1295 1243
1296
1297 } // namespace 1244 } // namespace
1298 1245
1299 1246
1300 // ConfigurationPolicyHandler implementation ----------------------------------- 1247 // ConfigurationPolicyHandler implementation -----------------------------------
1301 1248
1302 // static 1249 // static
1303 ConfigurationPolicyHandler::HandlerList* 1250 ConfigurationPolicyHandler::HandlerList*
1304 ConfigurationPolicyHandler::CreateHandlerList() { 1251 ConfigurationPolicyHandler::CreateHandlerList() {
1305 HandlerList* list = new HandlerList; 1252 HandlerList* list = new HandlerList;
1306 1253
(...skipping 10 matching lines...) Expand all
1317 list->push_back(new FileSelectionDialogsHandler()); 1264 list->push_back(new FileSelectionDialogsHandler());
1318 list->push_back(new IncognitoModePolicyHandler()); 1265 list->push_back(new IncognitoModePolicyHandler());
1319 list->push_back(new JavascriptPolicyHandler()); 1266 list->push_back(new JavascriptPolicyHandler());
1320 list->push_back(new ProxyPolicyHandler()); 1267 list->push_back(new ProxyPolicyHandler());
1321 list->push_back(new SyncPolicyHandler()); 1268 list->push_back(new SyncPolicyHandler());
1322 1269
1323 #if !defined(OS_CHROMEOS) 1270 #if !defined(OS_CHROMEOS)
1324 list->push_back(new DownloadDirPolicyHandler()); 1271 list->push_back(new DownloadDirPolicyHandler());
1325 #endif // !defined(OS_CHROME0S) 1272 #endif // !defined(OS_CHROME0S)
1326 1273
1274 #if defined(OS_CHROMEOS)
1275 list->push_back(
1276 new NetworkConfigurationPolicyHandler(
1277 kPolicyDeviceOpenNetworkConfiguration));
1278 list->push_back(
1279 new NetworkConfigurationPolicyHandler(
1280 kPolicyOpenNetworkConfiguration));
1281 #endif
1282
1327 return list; 1283 return list;
1328 } 1284 }
1329 1285
1286 // TypeCheckingPolicyHandler implementation ------------------------------------
1287
1288 TypeCheckingPolicyHandler::TypeCheckingPolicyHandler(
1289 ConfigurationPolicyType policy_type,
1290 Value::Type value_type)
1291 : policy_type_(policy_type),
1292 value_type_(value_type) {
1293 }
1294
1295 TypeCheckingPolicyHandler::~TypeCheckingPolicyHandler() {
1296 }
1297
1298 ConfigurationPolicyType TypeCheckingPolicyHandler::policy_type() const {
1299 return policy_type_;
1300 }
1301
1302 bool TypeCheckingPolicyHandler::CheckPolicySettings(const PolicyMap* policies,
1303 PolicyErrorMap* errors) {
1304 const Value* value = NULL;
1305 return CheckAndGetValue(policies, errors, &value);
1306 }
1307
1308 bool TypeCheckingPolicyHandler::CheckAndGetValue(const PolicyMap* policies,
1309 PolicyErrorMap* errors,
1310 const Value** value) {
1311 *value = policies->Get(policy_type_);
1312 if (*value && !(*value)->IsType(value_type_)) {
1313 errors->AddError(policy_type_,
1314 IDS_POLICY_TYPE_ERROR,
1315 ValueTypeToString(value_type_));
1316 return false;
1317 }
1318 return true;
1319 }
1320
1330 } // namespace policy 1321 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698