diff options
Diffstat (limited to 'chrome/browser/extensions')
3 files changed, 60 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extension_function_registry.cc b/chrome/browser/extensions/extension_function_registry.cc index a0ec4ba..85311a8 100644 --- a/chrome/browser/extensions/extension_function_registry.cc +++ b/chrome/browser/extensions/extension_function_registry.cc @@ -295,6 +295,8 @@ void ExtensionFunctionRegistry::ResetFunctions() { // Managed mode. RegisterFunction<GetManagedModeFunction>(); RegisterFunction<EnterManagedModeFunction>(); + RegisterFunction<GetPolicyFunction>(); + RegisterFunction<SetPolicyFunction>(); // Management. RegisterFunction<GetAllExtensionsFunction>(); diff --git a/chrome/browser/extensions/extension_managed_mode_api.cc b/chrome/browser/extensions/extension_managed_mode_api.cc index 0e747d5..efa05f8 100644 --- a/chrome/browser/extensions/extension_managed_mode_api.cc +++ b/chrome/browser/extensions/extension_managed_mode_api.cc @@ -20,6 +20,11 @@ #include "chrome/common/pref_names.h" #include "content/public/browser/notification_details.h" +#if defined(ENABLE_CONFIGURATION_POLICY) +#include "chrome/browser/policy/managed_mode_policy_provider.h" +#include "chrome/browser/policy/managed_mode_policy_provider_factory.h" +#endif + namespace { // Event that is fired when we enter or leave managed mode. @@ -91,3 +96,33 @@ void EnterManagedModeFunction::SendResult(bool success) { result_.reset(result.release()); SendResponse(true); } + +GetPolicyFunction::~GetPolicyFunction() { } + +bool GetPolicyFunction::RunImpl() { + std::string key; + EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &key)); +#if defined(ENABLE_CONFIGURATION_POLICY) + policy::ManagedModePolicyProvider* policy_provider = + ManagedModePolicyProviderFactory::GetForProfile(profile_); + const base::Value* policy = policy_provider->GetPolicy(key); + if (policy) + result_.reset(policy->DeepCopy()); +#endif + return true; +} + +SetPolicyFunction::~SetPolicyFunction() { } + +bool SetPolicyFunction::RunImpl() { + std::string key; + EXTENSION_FUNCTION_VALIDATE(args_->GetString(0, &key)); + base::Value* value = NULL; + EXTENSION_FUNCTION_VALIDATE(args_->Get(1, &value)); +#if defined(ENABLE_CONFIGURATION_POLICY) + policy::ManagedModePolicyProvider* policy_provider = + ManagedModePolicyProviderFactory::GetForProfile(profile_); + policy_provider->SetPolicy(key, value); +#endif + return true; +} diff --git a/chrome/browser/extensions/extension_managed_mode_api.h b/chrome/browser/extensions/extension_managed_mode_api.h index 75695d5..1020189 100644 --- a/chrome/browser/extensions/extension_managed_mode_api.h +++ b/chrome/browser/extensions/extension_managed_mode_api.h @@ -60,4 +60,27 @@ class EnterManagedModeFunction : public AsyncExtensionFunction { void SendResult(bool success); }; + +class GetPolicyFunction : public SyncExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION_NAME("managedModePrivate.getPolicy") + + protected: + virtual ~GetPolicyFunction(); + + // ExtensionFunction: + virtual bool RunImpl() OVERRIDE; +}; + +class SetPolicyFunction : public SyncExtensionFunction { + public: + DECLARE_EXTENSION_FUNCTION_NAME("managedModePrivate.setPolicy") + + protected: + virtual ~SetPolicyFunction(); + + // ExtensionFunction: + virtual bool RunImpl() OVERRIDE; +}; + #endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_MANAGED_MODE_API_H_ |