1 // Copyright 2013 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CHROME_BROWSER_EXTENSIONS_POLICY_HANDLERS_H_ 6 #define CHROME_BROWSER_EXTENSIONS_POLICY_HANDLERS_H_ 7 8 #include "base/memory/scoped_ptr.h" 9 #include "base/values.h" 10 #include "components/policy/core/browser/configuration_policy_handler.h" 11 12 namespace policy { 13 class PolicyMap; 14 class PolicyErrorMap; 15 } // namespace policy 16 17 namespace extensions { 18 19 // Implements additional checks for policies that are lists of extension IDs. 20 class ExtensionListPolicyHandler 21 : public policy::TypeCheckingPolicyHandler { 22 public: 23 ExtensionListPolicyHandler(const char* policy_name, 24 const char* pref_path, 25 bool allow_wildcards); 26 virtual ~ExtensionListPolicyHandler(); 27 28 // ConfigurationPolicyHandler methods: 29 virtual bool CheckPolicySettings(const policy::PolicyMap& policies, 30 policy::PolicyErrorMap* errors) OVERRIDE; 31 virtual void ApplyPolicySettings(const policy::PolicyMap& policies, 32 PrefValueMap* prefs) OVERRIDE; 33 34 protected: 35 const char* pref_path() const; 36 37 // Runs sanity checks on the policy value and returns it in |extension_ids|. 38 bool CheckAndGetList(const policy::PolicyMap& policies, 39 policy::PolicyErrorMap* errors, 40 scoped_ptr<base::ListValue>* extension_ids); 41 42 private: 43 const char* pref_path_; 44 bool allow_wildcards_; 45 46 DISALLOW_COPY_AND_ASSIGN(ExtensionListPolicyHandler); 47 }; 48 49 class ExtensionInstallForcelistPolicyHandler 50 : public policy::TypeCheckingPolicyHandler { 51 public: 52 ExtensionInstallForcelistPolicyHandler(); 53 virtual ~ExtensionInstallForcelistPolicyHandler(); 54 55 // ConfigurationPolicyHandler methods: 56 virtual bool CheckPolicySettings(const policy::PolicyMap& policies, 57 policy::PolicyErrorMap* errors) OVERRIDE; 58 virtual void ApplyPolicySettings(const policy::PolicyMap& policies, 59 PrefValueMap* prefs) OVERRIDE; 60 61 private: 62 // Parses the data in |policy_value| and writes them to |extension_dict|. 63 bool ParseList(const base::Value* policy_value, 64 base::DictionaryValue* extension_dict, 65 policy::PolicyErrorMap* errors); 66 67 DISALLOW_COPY_AND_ASSIGN(ExtensionInstallForcelistPolicyHandler); 68 }; 69 70 // Implements additional checks for policies that are lists of extension 71 // URLPatterns. 72 class ExtensionURLPatternListPolicyHandler 73 : public policy::TypeCheckingPolicyHandler { 74 public: 75 ExtensionURLPatternListPolicyHandler(const char* policy_name, 76 const char* pref_path); 77 virtual ~ExtensionURLPatternListPolicyHandler(); 78 79 // ConfigurationPolicyHandler methods: 80 virtual bool CheckPolicySettings(const policy::PolicyMap& policies, 81 policy::PolicyErrorMap* errors) OVERRIDE; 82 virtual void ApplyPolicySettings(const policy::PolicyMap& policies, 83 PrefValueMap* prefs) OVERRIDE; 84 85 private: 86 const char* pref_path_; 87 88 DISALLOW_COPY_AND_ASSIGN(ExtensionURLPatternListPolicyHandler); 89 }; 90 91 } // namespace extensions 92 93 #endif // CHROME_BROWSER_EXTENSIONS_POLICY_HANDLERS_H_ 94