diff options
Diffstat (limited to 'chrome/browser/policy/configuration_policy_handler.h')
-rw-r--r-- | chrome/browser/policy/configuration_policy_handler.h | 249 |
1 files changed, 242 insertions, 7 deletions
diff --git a/chrome/browser/policy/configuration_policy_handler.h b/chrome/browser/policy/configuration_policy_handler.h index 61423c3..375b8f9 100644 --- a/chrome/browser/policy/configuration_policy_handler.h +++ b/chrome/browser/policy/configuration_policy_handler.h @@ -9,6 +9,9 @@ #include <vector> #include "base/basictypes.h" +#include "base/values.h" +#include "chrome/browser/prefs/incognito_mode_prefs.h" +#include "policy/configuration_policy_type.h" class PrefValueMap; @@ -21,10 +24,8 @@ class PolicyMap; // their corresponding preferences, and to check whether the policies are valid. class ConfigurationPolicyHandler { public: - typedef std::vector<ConfigurationPolicyHandler*> HandlerList; - - ConfigurationPolicyHandler() {} - virtual ~ConfigurationPolicyHandler() {} + ConfigurationPolicyHandler(); + virtual ~ConfigurationPolicyHandler(); // Returns true if the policy settings handled by this // ConfigurationPolicyHandler can be applied and false otherwise. Fills @@ -38,14 +39,248 @@ class ConfigurationPolicyHandler { virtual void ApplyPolicySettings(const PolicyMap& policies, PrefValueMap* prefs) = 0; - // Creates a new HandlerList with all the known handlers and returns it. - // The new list and its elements are owned by the caller. - static HandlerList* CreateHandlerList(); + // Converts sensitive policy values to others more appropriate for displaying. + virtual void PrepareForDisplaying(PolicyMap* policies) const; private: DISALLOW_COPY_AND_ASSIGN(ConfigurationPolicyHandler); }; +// Abstract class derived from ConfigurationPolicyHandler that should be +// subclassed to handle a single policy (not a combination of policies). +class TypeCheckingPolicyHandler : public ConfigurationPolicyHandler { + public: + TypeCheckingPolicyHandler(ConfigurationPolicyType policy_type, + base::Value::Type value_type); + + // ConfigurationPolicyHandler methods: + virtual bool CheckPolicySettings(const PolicyMap& policies, + PolicyErrorMap* errors) OVERRIDE; + + protected: + virtual ~TypeCheckingPolicyHandler(); + + ConfigurationPolicyType policy_type() const; + + private: + // The ConfigurationPolicyType of the policy. + ConfigurationPolicyType policy_type_; + + // The type the value of the policy should have. + base::Value::Type value_type_; + + DISALLOW_COPY_AND_ASSIGN(TypeCheckingPolicyHandler); +}; + +// ConfigurationPolicyHandler for policies that map directly to a preference. +class SimplePolicyHandler : public TypeCheckingPolicyHandler { + public: + SimplePolicyHandler(ConfigurationPolicyType policy_type, + base::Value::Type value_type, + const char* pref_path); + virtual ~SimplePolicyHandler(); + + // ConfigurationPolicyHandler methods: + virtual void ApplyPolicySettings(const PolicyMap& policies, + PrefValueMap* prefs) OVERRIDE; + + private: + // The DictionaryValue path of the preference the policy maps to. + const char* pref_path_; + + DISALLOW_COPY_AND_ASSIGN(SimplePolicyHandler); +}; + +// ConfigurationPolicyHandler for the SyncDisabled policy. +class SyncPolicyHandler : public TypeCheckingPolicyHandler { + public: + SyncPolicyHandler(); + virtual ~SyncPolicyHandler(); + + // ConfigurationPolicyHandler methods: + virtual void ApplyPolicySettings(const PolicyMap& policies, + PrefValueMap* prefs) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(SyncPolicyHandler); +}; + +// ConfigurationPolicyHandler for the AutofillEnabled policy. +class AutofillPolicyHandler : public TypeCheckingPolicyHandler { + public: + AutofillPolicyHandler(); + virtual ~AutofillPolicyHandler(); + + // ConfigurationPolicyHandler methods: + virtual void ApplyPolicySettings(const PolicyMap& policies, + PrefValueMap* prefs) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(AutofillPolicyHandler); +}; + +// ConfigurationPolicyHandler for the DownloadDirectory policy. +class DownloadDirPolicyHandler : public TypeCheckingPolicyHandler { + public: + DownloadDirPolicyHandler(); + virtual ~DownloadDirPolicyHandler(); + + // ConfigurationPolicyHandler methods: + virtual void ApplyPolicySettings(const PolicyMap& policies, + PrefValueMap* prefs) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(DownloadDirPolicyHandler); +}; + +// ConfigurationPolicyHandler for the DiskCacheDir policy. +class DiskCacheDirPolicyHandler : public TypeCheckingPolicyHandler { + public: + explicit DiskCacheDirPolicyHandler(); + virtual ~DiskCacheDirPolicyHandler(); + + // ConfigurationPolicyHandler methods: + virtual void ApplyPolicySettings(const PolicyMap& policies, + PrefValueMap* prefs) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(DiskCacheDirPolicyHandler); +}; + +// ConfigurationPolicyHandler for the FileSelectionDialogsHandler policy. +class FileSelectionDialogsHandler : public TypeCheckingPolicyHandler { + public: + FileSelectionDialogsHandler(); + virtual ~FileSelectionDialogsHandler(); + + // ConfigurationPolicyHandler methods: + virtual void ApplyPolicySettings(const PolicyMap& policies, + PrefValueMap* prefs) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(FileSelectionDialogsHandler); +}; + +// ConfigurationPolicyHandler for the incognito mode policies. +class IncognitoModePolicyHandler : public ConfigurationPolicyHandler { + public: + IncognitoModePolicyHandler(); + virtual ~IncognitoModePolicyHandler(); + + // ConfigurationPolicyHandler methods: + virtual bool CheckPolicySettings(const PolicyMap& policies, + PolicyErrorMap* errors) OVERRIDE; + virtual void ApplyPolicySettings(const PolicyMap& policies, + PrefValueMap* prefs) OVERRIDE; + + private: + IncognitoModePrefs::Availability GetAvailabilityValueAsEnum( + const Value* availability); + + DISALLOW_COPY_AND_ASSIGN(IncognitoModePolicyHandler); +}; + +// ConfigurationPolicyHandler for the DefaultSearchEncodings policy. +class DefaultSearchEncodingsPolicyHandler : public TypeCheckingPolicyHandler { + public: + DefaultSearchEncodingsPolicyHandler(); + virtual ~DefaultSearchEncodingsPolicyHandler(); + + // ConfigurationPolicyHandler methods: + virtual void ApplyPolicySettings(const PolicyMap& policies, + PrefValueMap* prefs) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(DefaultSearchEncodingsPolicyHandler); +}; + +// ConfigurationPolicyHandler for the default search policies. +class DefaultSearchPolicyHandler : public ConfigurationPolicyHandler { + public: + DefaultSearchPolicyHandler(); + virtual ~DefaultSearchPolicyHandler(); + + // ConfigurationPolicyHandler methods: + virtual bool CheckPolicySettings(const PolicyMap& policies, + PolicyErrorMap* errors) OVERRIDE; + virtual void ApplyPolicySettings(const PolicyMap& policies, + PrefValueMap* prefs) OVERRIDE; + + private: + // Calls |CheckPolicySettings()| on each of the handlers in |handlers_| + // and returns true if all of the calls return true and false otherwise. + bool CheckIndividualPolicies(const PolicyMap& policies, + PolicyErrorMap* errors); + + // Returns true if there is a value for |policy_type| in |policies| and false + // otherwise. + bool HasDefaultSearchPolicy(const PolicyMap& policies, + ConfigurationPolicyType policy_type); + + // Returns true if any default search policies are specified in |policies| and + // false otherwise. + bool AnyDefaultSearchPoliciesSpecified(const PolicyMap& policies); + + // Returns true if the default search provider is disabled and false + // otherwise. + bool DefaultSearchProviderIsDisabled(const PolicyMap& policies); + + // Returns true if the default search URL was set and is valid and false + // otherwise. + bool DefaultSearchURLIsValid(const PolicyMap& policies); + + // Make sure that the |path| if present in |prefs_|. If not, set it to + // a blank string. + void EnsureStringPrefExists(PrefValueMap* prefs, const std::string& path); + + // The ConfigurationPolicyHandler handlers for each default search policy. + std::vector<ConfigurationPolicyHandler*> handlers_; + + DISALLOW_COPY_AND_ASSIGN(DefaultSearchPolicyHandler); +}; + +// ConfigurationPolicyHandler for the proxy policies. +class ProxyPolicyHandler : public ConfigurationPolicyHandler { + public: + ProxyPolicyHandler(); + virtual ~ProxyPolicyHandler(); + + // ConfigurationPolicyHandler methods: + virtual bool CheckPolicySettings(const PolicyMap& policies, + PolicyErrorMap* errors) OVERRIDE; + virtual void ApplyPolicySettings(const PolicyMap& policies, + PrefValueMap* prefs) OVERRIDE; + + private: + const Value* GetProxyPolicyValue(const PolicyMap& policies, + ConfigurationPolicyType policy); + + // Converts the deprecated ProxyServerMode policy value to a ProxyMode value + // and places the result in |mode_value|. Returns true if the conversion + // succeeded and false otherwise. + bool CheckProxyModeAndServerMode(const PolicyMap& policies, + PolicyErrorMap* errors, + std::string* mode_value); + + DISALLOW_COPY_AND_ASSIGN(ProxyPolicyHandler); +}; + +// +class JavascriptPolicyHandler : public ConfigurationPolicyHandler { + public: + JavascriptPolicyHandler(); + virtual ~JavascriptPolicyHandler(); + + // ConfigurationPolicyHandler methods: + virtual bool CheckPolicySettings(const PolicyMap& policies, + PolicyErrorMap* errors) OVERRIDE; + virtual void ApplyPolicySettings(const PolicyMap& policies, + PrefValueMap* prefs) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(JavascriptPolicyHandler); +}; + } // namespace policy #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_H_ |