diff options
author | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-14 09:44:28 +0000 |
---|---|---|
committer | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-14 09:44:28 +0000 |
commit | 8e2796a83c6a7e74661e9756d70073c323b5423b (patch) | |
tree | b663f2308610d1021a24f8467ac18445b7525c4a /chrome/browser/policy | |
parent | 9976d842b0bc36ebb9d0c027fa4f69f0c247c816 (diff) | |
download | chromium_src-8e2796a83c6a7e74661e9756d70073c323b5423b.zip chromium_src-8e2796a83c6a7e74661e9756d70073c323b5423b.tar.gz chromium_src-8e2796a83c6a7e74661e9756d70073c323b5423b.tar.bz2 |
Merge 135677 - Wire up the policy for controlling pinned apps in the ash launcher.
This declares the policy so the policy subsystem can enforce it and
shows it in about:policy.
BUG=chromium-os:29917
TEST=Configure pinned apps, log in as a managed user, observe that the launcher shows the pinned apps as configured.
Review URL: https://chromiumcodereview.appspot.com/10316022
TBR=mnissler@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10382147
git-svn-id: svn://svn.chromium.org/chrome/branches/1132/src@136845 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/policy')
10 files changed, 299 insertions, 15 deletions
diff --git a/chrome/browser/policy/configuration_policy_handler.cc b/chrome/browser/policy/configuration_policy_handler.cc index a8e1122..7dd32dd 100644 --- a/chrome/browser/policy/configuration_policy_handler.cc +++ b/chrome/browser/policy/configuration_policy_handler.cc @@ -26,6 +26,7 @@ #include "chrome/browser/search_engines/template_url.h" #include "chrome/common/chrome_notification_types.h" #include "chrome/common/content_settings.h" +#include "chrome/common/extensions/extension.h" #include "chrome/common/pref_names.h" #include "content/public/browser/notification_service.h" #include "grit/generated_resources.h" @@ -204,6 +205,80 @@ bool TypeCheckingPolicyHandler::CheckAndGetValue(const PolicyMap& policies, return true; } +// ExtensionListPolicyHandler implementation ----------------------------------- + +ExtensionListPolicyHandler::ExtensionListPolicyHandler(const char* policy_name, + const char* pref_path, + bool allow_wildcards) + : TypeCheckingPolicyHandler(policy_name, base::Value::TYPE_LIST), + pref_path_(pref_path), + allow_wildcards_(allow_wildcards) {} + +ExtensionListPolicyHandler::~ExtensionListPolicyHandler() {} + +bool ExtensionListPolicyHandler::CheckPolicySettings( + const PolicyMap& policies, + PolicyErrorMap* errors) { + return CheckAndGetList(policies, errors, NULL); +} + +void ExtensionListPolicyHandler::ApplyPolicySettings( + const PolicyMap& policies, + PrefValueMap* prefs) { + const Value* value = policies.GetValue(policy_name()); + if (value) + prefs->SetValue(pref_path(), value->DeepCopy()); +} + +const char* ExtensionListPolicyHandler::pref_path() const { + return pref_path_; +} + +bool ExtensionListPolicyHandler::CheckAndGetList( + const PolicyMap& policies, + PolicyErrorMap* errors, + const base::ListValue** extension_ids) { + if (extension_ids) + *extension_ids = NULL; + + const base::Value* value = NULL; + if (!CheckAndGetValue(policies, errors, &value)) + return false; + + if (!value) + return true; + + const base::ListValue* list_value = NULL; + if (!value->GetAsList(&list_value)) { + NOTREACHED(); + return false; + } + + // Check that the list contains valid extension ID strings only. + for (base::ListValue::const_iterator entry(list_value->begin()); + entry != list_value->end(); ++entry) { + std::string id; + if (!(*entry)->GetAsString(&id)) { + errors->AddError(policy_name(), + entry - list_value->begin(), + IDS_POLICY_TYPE_ERROR, + ValueTypeToString(base::Value::TYPE_STRING)); + return false; + } + if (!(allow_wildcards_ && id == "*") && !Extension::IdIsValid(id)) { + errors->AddError(policy_name(), + entry - list_value->begin(), + IDS_POLICY_VALUE_FORMAT_ERROR); + return false; + } + } + + if (extension_ids) + *extension_ids = list_value; + + return true; +} + // SimplePolicyHandler implementation ------------------------------------------ SimplePolicyHandler::SimplePolicyHandler( diff --git a/chrome/browser/policy/configuration_policy_handler.h b/chrome/browser/policy/configuration_policy_handler.h index 049e9a2..8ddf542 100644 --- a/chrome/browser/policy/configuration_policy_handler.h +++ b/chrome/browser/policy/configuration_policy_handler.h @@ -99,6 +99,35 @@ class SimplePolicyHandler : public TypeCheckingPolicyHandler { DISALLOW_COPY_AND_ASSIGN(SimplePolicyHandler); }; +// Implements additional checks for policies that are lists of extension IDs. +class ExtensionListPolicyHandler : public TypeCheckingPolicyHandler { + public: + ExtensionListPolicyHandler(const char* policy_name, + const char* pref_path, + bool allow_wildcards); + virtual ~ExtensionListPolicyHandler(); + + // ConfigurationPolicyHandler methods: + virtual bool CheckPolicySettings(const PolicyMap& policies, + PolicyErrorMap* errors) OVERRIDE; + virtual void ApplyPolicySettings(const PolicyMap& policies, + PrefValueMap* prefs) OVERRIDE; + + protected: + const char* pref_path() const; + + // Runs sanity checks on the policy value and returns it in |extension_ids|. + bool CheckAndGetList(const PolicyMap& policies, + PolicyErrorMap* errors, + const base::ListValue** extension_ids); + + private: + const char* pref_path_; + bool allow_wildcards_; + + DISALLOW_COPY_AND_ASSIGN(ExtensionListPolicyHandler); +}; + // ConfigurationPolicyHandler for the SyncDisabled policy. class SyncPolicyHandler : public TypeCheckingPolicyHandler { public: diff --git a/chrome/browser/policy/configuration_policy_handler_chromeos.cc b/chrome/browser/policy/configuration_policy_handler_chromeos.cc index 2ad2655..1f68bb5 100644 --- a/chrome/browser/policy/configuration_policy_handler_chromeos.cc +++ b/chrome/browser/policy/configuration_policy_handler_chromeos.cc @@ -13,7 +13,11 @@ #include "chrome/browser/chromeos/cros/onc_network_parser.h" #include "chrome/browser/policy/policy_error_map.h" #include "chrome/browser/policy/policy_map.h" +#include "chrome/browser/prefs/pref_value_map.h" +#include "chrome/browser/ui/views/ash/launcher/chrome_launcher_controller.h" +#include "chrome/common/pref_names.h" #include "grit/generated_resources.h" +#include "policy/policy_constants.h" namespace policy { @@ -125,4 +129,33 @@ void NetworkConfigurationPolicyHandler::StripSensitiveValues( } } +PinnedLauncherAppsPolicyHandler::PinnedLauncherAppsPolicyHandler() + : ExtensionListPolicyHandler(key::kPinnedLauncherApps, + prefs::kPinnedLauncherApps, + false) {} + +PinnedLauncherAppsPolicyHandler::~PinnedLauncherAppsPolicyHandler() {} + +void PinnedLauncherAppsPolicyHandler::ApplyPolicySettings( + const PolicyMap& policies, + PrefValueMap* prefs) { + PolicyErrorMap errors; + const base::Value* policy_value = policies.GetValue(policy_name()); + const base::ListValue* policy_list = NULL; + if (policy_value && policy_value->GetAsList(&policy_list) && policy_list) { + base::ListValue* pinned_apps_list = new base::ListValue(); + for (base::ListValue::const_iterator entry(policy_list->begin()); + entry != policy_list->end(); ++entry) { + std::string id; + if ((*entry)->GetAsString(&id)) { + base::DictionaryValue* app_dict = new base::DictionaryValue(); + app_dict->SetString(ChromeLauncherController::kPinnedAppsPrefAppIDPath, + id); + pinned_apps_list->Append(app_dict); + } + } + prefs->SetValue(pref_path(), pinned_apps_list); + } +} + } // namespace policy diff --git a/chrome/browser/policy/configuration_policy_handler_chromeos.h b/chrome/browser/policy/configuration_policy_handler_chromeos.h index eb35d97..dbe5dba5 100644 --- a/chrome/browser/policy/configuration_policy_handler_chromeos.h +++ b/chrome/browser/policy/configuration_policy_handler_chromeos.h @@ -44,6 +44,20 @@ class NetworkConfigurationPolicyHandler : public TypeCheckingPolicyHandler { DISALLOW_COPY_AND_ASSIGN(NetworkConfigurationPolicyHandler); }; +// Maps the PinnedLauncherApps policy to the corresponding pref. +class PinnedLauncherAppsPolicyHandler : public ExtensionListPolicyHandler { + public: + PinnedLauncherAppsPolicyHandler(); + virtual ~PinnedLauncherAppsPolicyHandler(); + + // ExtensionListPolicyHandler methods: + virtual void ApplyPolicySettings(const PolicyMap& policies, + PrefValueMap* prefs) OVERRIDE; + + private: + DISALLOW_COPY_AND_ASSIGN(PinnedLauncherAppsPolicyHandler); +}; + } // namespace policy #endif // CHROME_BROWSER_POLICY_CONFIGURATION_POLICY_HANDLER_CHROMEOS_H_ diff --git a/chrome/browser/policy/configuration_policy_handler_chromeos_unittest.cc b/chrome/browser/policy/configuration_policy_handler_chromeos_unittest.cc index 2a1bc43..51e8f1a 100644 --- a/chrome/browser/policy/configuration_policy_handler_chromeos_unittest.cc +++ b/chrome/browser/policy/configuration_policy_handler_chromeos_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,6 +6,9 @@ #include "chrome/browser/policy/policy_error_map.h" #include "chrome/browser/policy/policy_map.h" +#include "chrome/browser/prefs/pref_value_map.h" +#include "chrome/browser/ui/views/ash/launcher/chrome_launcher_controller.h" +#include "chrome/common/pref_names.h" #include "policy/policy_constants.h" #include "testing/gtest/include/gtest/gtest.h" @@ -109,4 +112,32 @@ TEST(NetworkConfigurationPolicyHandlerTest, Sanitization) { EXPECT_EQ(std::string::npos, sanitized_onc.find("pass")); } +TEST(PinnedLauncherAppsPolicyHandler, PrefTranslation) { + base::ListValue list; + PolicyMap policy_map; + PrefValueMap prefs; + base::ListValue expected_pinned_apps; + base::Value* value = NULL; + PinnedLauncherAppsPolicyHandler handler; + + policy_map.Set(key::kPinnedLauncherApps, POLICY_LEVEL_MANDATORY, + POLICY_SCOPE_USER, list.DeepCopy()); + handler.ApplyPolicySettings(policy_map, &prefs); + EXPECT_TRUE(prefs.GetValue(prefs::kPinnedLauncherApps, &value)); + EXPECT_TRUE(base::Value::Equals(&expected_pinned_apps, value)); + + base::StringValue entry1("abcdefghijklmnopabcdefghijklmnop"); + base::DictionaryValue* entry1_dict = new base::DictionaryValue(); + entry1_dict->Set(ChromeLauncherController::kPinnedAppsPrefAppIDPath, + entry1.DeepCopy()); + expected_pinned_apps.Append(entry1_dict); + list.Append(entry1.DeepCopy()); + policy_map.Set(key::kPinnedLauncherApps, POLICY_LEVEL_MANDATORY, + POLICY_SCOPE_USER, list.DeepCopy()); + prefs.Clear(); + handler.ApplyPolicySettings(policy_map, &prefs); + EXPECT_TRUE(prefs.GetValue(prefs::kPinnedLauncherApps, &value)); + EXPECT_TRUE(base::Value::Equals(&expected_pinned_apps, value)); +} + } // namespace policy diff --git a/chrome/browser/policy/configuration_policy_handler_list.cc b/chrome/browser/policy/configuration_policy_handler_list.cc index c5b33d7..f3664cf 100644 --- a/chrome/browser/policy/configuration_policy_handler_list.cc +++ b/chrome/browser/policy/configuration_policy_handler_list.cc @@ -78,12 +78,6 @@ const PolicyToPreferenceMapEntry kSimplePolicyMap[] = { { key::kApplicationLocaleValue, prefs::kApplicationLocale, Value::TYPE_STRING }, - { key::kExtensionInstallWhitelist, - prefs::kExtensionInstallAllowList, - Value::TYPE_LIST }, - { key::kExtensionInstallBlacklist, - prefs::kExtensionInstallDenyList, - Value::TYPE_LIST }, { key::kExtensionInstallForcelist, prefs::kExtensionInstallForceList, Value::TYPE_LIST }, @@ -331,6 +325,15 @@ ConfigurationPolicyHandlerList::ConfigurationPolicyHandlerList() { handlers_.push_back(new RestoreOnStartupPolicyHandler()); handlers_.push_back(new SyncPolicyHandler()); + handlers_.push_back( + new ExtensionListPolicyHandler(key::kExtensionInstallWhitelist, + prefs::kExtensionInstallAllowList, + false)); + handlers_.push_back( + new ExtensionListPolicyHandler(key::kExtensionInstallBlacklist, + prefs::kExtensionInstallDenyList, + true)); + #if !defined(OS_CHROMEOS) handlers_.push_back(new DownloadDirPolicyHandler()); #endif // !defined(OS_CHROMEOS) @@ -344,6 +347,7 @@ ConfigurationPolicyHandlerList::ConfigurationPolicyHandlerList() { new NetworkConfigurationPolicyHandler( key::kOpenNetworkConfiguration, chromeos::NetworkUIData::ONC_SOURCE_USER_POLICY)); + handlers_.push_back(new PinnedLauncherAppsPolicyHandler()); #endif // defined(OS_CHROMEOS) } diff --git a/chrome/browser/policy/configuration_policy_handler_unittest.cc b/chrome/browser/policy/configuration_policy_handler_unittest.cc new file mode 100644 index 0000000..17bfeaa --- /dev/null +++ b/chrome/browser/policy/configuration_policy_handler_unittest.cc @@ -0,0 +1,65 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "chrome/browser/policy/configuration_policy_handler.h" +#include "chrome/browser/policy/policy_error_map.h" +#include "chrome/browser/policy/policy_map.h" +#include "chrome/browser/prefs/pref_value_map.h" +#include "chrome/common/pref_names.h" +#include "policy/policy_constants.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace policy { + +TEST(ExtensionListPolicyHandlerTest, CheckPolicySettings) { + base::ListValue list; + PolicyMap policy_map; + PolicyErrorMap errors; + ExtensionListPolicyHandler handler(key::kExtensionInstallBlacklist, + prefs::kExtensionInstallDenyList, + true); + + policy_map.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, + POLICY_SCOPE_USER, list.DeepCopy()); + EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); + EXPECT_TRUE(errors.empty()); + + list.Append(Value::CreateStringValue("abcdefghijklmnopabcdefghijklmnop")); + policy_map.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, + POLICY_SCOPE_USER, list.DeepCopy()); + EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); + EXPECT_TRUE(errors.empty()); + + list.Append(Value::CreateStringValue("*")); + policy_map.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, + POLICY_SCOPE_USER, list.DeepCopy()); + EXPECT_TRUE(handler.CheckPolicySettings(policy_map, &errors)); + EXPECT_TRUE(errors.empty()); + + list.Append(Value::CreateStringValue("invalid")); + policy_map.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, + POLICY_SCOPE_USER, list.DeepCopy()); + EXPECT_FALSE(handler.CheckPolicySettings(policy_map, &errors)); + EXPECT_FALSE(errors.empty()); + EXPECT_FALSE(errors.GetErrors(key::kExtensionInstallBlacklist).empty()); +} + +TEST(ExtensionListPolicyHandlerTest, ApplyPolicySettings) { + base::ListValue list; + PolicyMap policy_map; + PrefValueMap prefs; + base::Value* value = NULL; + ExtensionListPolicyHandler handler(key::kExtensionInstallBlacklist, + prefs::kExtensionInstallDenyList, + false); + + list.Append(Value::CreateStringValue("abcdefghijklmnopabcdefghijklmnop")); + policy_map.Set(key::kExtensionInstallBlacklist, POLICY_LEVEL_MANDATORY, + POLICY_SCOPE_USER, list.DeepCopy()); + handler.ApplyPolicySettings(policy_map, &prefs); + EXPECT_TRUE(prefs.GetValue(prefs::kExtensionInstallDenyList, &value)); + EXPECT_TRUE(base::Value::Equals(&list, value)); +} + +} // namespace policy diff --git a/chrome/browser/policy/configuration_policy_pref_store_unittest.cc b/chrome/browser/policy/configuration_policy_pref_store_unittest.cc index c5158fd..0620c9c 100644 --- a/chrome/browser/policy/configuration_policy_pref_store_unittest.cc +++ b/chrome/browser/policy/configuration_policy_pref_store_unittest.cc @@ -91,10 +91,6 @@ INSTANTIATE_TEST_CASE_P( testing::Values( PolicyAndPref(key::kRestoreOnStartupURLs, prefs::kURLsToRestoreOnStartup), - PolicyAndPref(key::kExtensionInstallWhitelist, - prefs::kExtensionInstallAllowList), - PolicyAndPref(key::kExtensionInstallBlacklist, - prefs::kExtensionInstallDenyList), PolicyAndPref(key::kDisabledPlugins, prefs::kPluginsDisabledPlugins), PolicyAndPref(key::kDisabledPluginsExceptions, diff --git a/chrome/browser/policy/policy_error_map.cc b/chrome/browser/policy/policy_error_map.cc index 5dc54b4..a0514da 100644 --- a/chrome/browser/policy/policy_error_map.cc +++ b/chrome/browser/policy/policy_error_map.cc @@ -6,6 +6,7 @@ #include <utility> +#include "base/string_number_conversions.h" #include "base/string_util.h" #include "base/utf_string_conversions.h" #include "grit/generated_resources.h" @@ -17,24 +18,29 @@ namespace policy { struct PolicyErrorMap::PendingError { PendingError(const std::string& policy, const std::string& subkey, + int index, int message_id, const std::string& replacement) : policy(policy), subkey(subkey), + index(index), message_id(message_id), has_replacement(true), replacement(replacement) {} PendingError(const std::string& policy, const std::string& subkey, + int index, int message_id) : policy(policy), subkey(subkey), + index(index), message_id(message_id), has_replacement(false) {} std::string policy; std::string subkey; + int index; int message_id; bool has_replacement; std::string replacement; @@ -51,26 +57,39 @@ bool PolicyErrorMap::IsReady() const { } void PolicyErrorMap::AddError(const std::string& policy, int message_id) { - AddError(PendingError(policy, std::string(), message_id)); + AddError(PendingError(policy, std::string(), -1, message_id)); } void PolicyErrorMap::AddError(const std::string& policy, const std::string& subkey, int message_id) { - AddError(PendingError(policy, subkey, message_id)); + AddError(PendingError(policy, subkey, -1, message_id)); +} + +void PolicyErrorMap::AddError(const std::string& policy, + int index, + int message_id) { + AddError(PendingError(policy, std::string(), index, message_id)); } void PolicyErrorMap::AddError(const std::string& policy, int message_id, const std::string& replacement) { - AddError(PendingError(policy, std::string(), message_id, replacement)); + AddError(PendingError(policy, std::string(), -1, message_id, replacement)); } void PolicyErrorMap::AddError(const std::string& policy, const std::string& subkey, int message_id, const std::string& replacement) { - AddError(PendingError(policy, subkey, message_id, replacement)); + AddError(PendingError(policy, subkey, -1, message_id, replacement)); +} + +void PolicyErrorMap::AddError(const std::string& policy, + int index, + int message_id, + const std::string& replacement) { + AddError(PendingError(policy, std::string(), index, message_id, replacement)); } string16 PolicyErrorMap::GetErrors(const std::string& policy) { @@ -128,6 +147,10 @@ void PolicyErrorMap::Convert(const PendingError& error) { message = l10n_util::GetStringFUTF16(IDS_POLICY_SUBKEY_ERROR, ASCIIToUTF16(error.subkey), submessage); + } else if (error.index >= 0) { + message = l10n_util::GetStringFUTF16(IDS_POLICY_LIST_ENTRY_ERROR, + base::IntToString16(error.index), + submessage); } else { message = submessage; } diff --git a/chrome/browser/policy/policy_error_map.h b/chrome/browser/policy/policy_error_map.h index 8a51363..80d266a 100644 --- a/chrome/browser/policy/policy_error_map.h +++ b/chrome/browser/policy/policy_error_map.h @@ -39,6 +39,12 @@ class PolicyErrorMap { const std::string& subkey, int message_id); + // Adds an entry with key |policy|, list index |index|, and the error message + // corresponding to |message_id| in grit/generated_resources.h to the map. + void AddError(const std::string& policy, + int index, + int message_id); + // Adds an entry with key |policy| and the error message corresponding to // |message_id| in grit/generated_resources.h to the map and replaces the // placeholder within the error message with |replacement_string|. @@ -54,6 +60,14 @@ class PolicyErrorMap { int message_id, const std::string& replacement_string); + // Adds an entry with key |policy|, list index |index| and the error message + // corresponding to |message_id| in grit/generated_resources.h to the map. + // Replaces the placeholder in the error message with |replacement_string|. + void AddError(const std::string& policy, + int index, + int message_id, + const std::string& replacement_string); + // Returns all the error messages stored for |policy|, separated by a white // space. Returns an empty string if there are no errors for |policy|. string16 GetErrors(const std::string& policy); |