diff options
author | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-07 18:36:53 +0000 |
---|---|---|
committer | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-05-07 18:36:53 +0000 |
commit | 2ea51dfb8f6d582008e504e515b7394e8e5cb673 (patch) | |
tree | 82272f33348b16f09be5dd4975ffb9ce40029eaf | |
parent | eb649c445164b92c6e040a327b9a959fbf600649 (diff) | |
download | chromium_src-2ea51dfb8f6d582008e504e515b7394e8e5cb673.zip chromium_src-2ea51dfb8f6d582008e504e515b7394e8e5cb673.tar.gz chromium_src-2ea51dfb8f6d582008e504e515b7394e8e5cb673.tar.bz2 |
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
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@135677 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/app/generated_resources.grd | 8 | ||||
-rw-r--r-- | chrome/app/policy/policy_templates.json | 19 | ||||
-rw-r--r-- | chrome/browser/policy/configuration_policy_handler.cc | 75 | ||||
-rw-r--r-- | chrome/browser/policy/configuration_policy_handler.h | 29 | ||||
-rw-r--r-- | chrome/browser/policy/configuration_policy_handler_chromeos.cc | 33 | ||||
-rw-r--r-- | chrome/browser/policy/configuration_policy_handler_chromeos.h | 14 | ||||
-rw-r--r-- | chrome/browser/policy/configuration_policy_handler_chromeos_unittest.cc | 33 | ||||
-rw-r--r-- | chrome/browser/policy/configuration_policy_handler_list.cc | 16 | ||||
-rw-r--r-- | chrome/browser/policy/configuration_policy_handler_unittest.cc | 65 | ||||
-rw-r--r-- | chrome/browser/policy/configuration_policy_pref_store_unittest.cc | 4 | ||||
-rw-r--r-- | chrome/browser/policy/policy_error_map.cc | 31 | ||||
-rw-r--r-- | chrome/browser/policy/policy_error_map.h | 14 | ||||
-rw-r--r-- | chrome/chrome_tests.gypi | 1 | ||||
-rwxr-xr-x | chrome/test/functional/policy_test_cases.py | 1 |
14 files changed, 326 insertions, 17 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd index 467635d..b621bb6 100644 --- a/chrome/app/generated_resources.grd +++ b/chrome/app/generated_resources.grd @@ -4906,7 +4906,10 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_POLICY_OUT_OF_RANGE_ERROR" desc="The text displayed in the status column when a policy value is out of range."> Value is out of range <ph name="VALUE">$1<ex>10</ex></ph>. </message> - <message name="IDS_POLICY_DEFAULT_SEARCH_DISABLED" desc="The text displayed in the status column when a policy value has been ignored because default search has been disabled."> + <message name="IDS_POLICY_VALUE_FORMAT_ERROR" desc="The text displayed in the status column when a policy value doesn't match the expected format."> + Value doesn't match format. + </message> + <message name="IDS_POLICY_DEFAULT_SEARCH_DISABLED" desc="The text displayed in the status column when a policy value has been ignored because default search has been disabled."> Ignored because default search is disabled by policy. </message> <message name="IDS_POLICY_NOT_SPECIFIED_ERROR" desc="The text displayed in the status column when a policy value should have been specified but wasn't."> @@ -4915,6 +4918,9 @@ Keep your key file in a safe place. You will need it to create new versions of y <message name="IDS_POLICY_SUBKEY_ERROR" desc="The text displayed in the status column for errors in a subkey of a policy."> Key "<ph name="SUBKEY">$1<ex>ProxyMode</ex></ph>": <ph name="ERROR">$2<ex>Must be specified.</ex></ph> </message> + <message name="IDS_POLICY_LIST_ENTRY_ERROR" desc="The text displayed in the status column for errors in list entry in a policy."> + List entry "<ph name="ENTRY_INDEX">$1<ex>3</ex></ph>": <ph name="ERROR">$2<ex>Value is out of range.</ex></ph> + </message> <message name="IDS_POLICY_INVALID_SEARCH_URL_ERROR" desc="The text displayed in the status column when a the URL given for DefaultSearchProviderSearchURL is invalid."> Invalid search URL. </message> diff --git a/chrome/app/policy/policy_templates.json b/chrome/app/policy/policy_templates.json index 8936fb9..cc01449 100644 --- a/chrome/app/policy/policy_templates.json +++ b/chrome/app/policy/policy_templates.json @@ -112,7 +112,7 @@ # persistent IDs for all fields (but not for groups!) are needed. These are # specified by the 'id' keys of each policy. NEVER CHANGE EXISTING IDs, # because doing so would break the deployed wire format! -# For your editing convenience: highest ID currently used: 143 +# For your editing convenience: highest ID currently used: 144 # # Placeholders: # The following placeholder strings are automatically substituted: @@ -2637,6 +2637,23 @@ }, ], }, + { + 'name': 'PinnedLauncherApps', + 'type': 'list', + 'supported_on': ['chrome_os:20-' ], + 'features': { + 'dynamic_refresh': True, + 'can_be_recommended': True, + }, + 'example_value': ['pjkljhegncpnkpknbcohdijeoejaedia'], + 'id': 144, + 'caption': '''List of pinned apps to show in the launcher''', + 'desc': '''Lists the application identifiers <ph name="PRODUCT_OS_NAME">$2<ex>Google Chrome OS</ex></ph> shows as pinned apps in the launcher bar. + + If this policy is configured, the set of applications is fixed and can't be changed by the user. + + If this policy is left unset, the user may change the list of pinned apps in the launcher.''', + }, ], 'messages': { # Messages that are not associated to any policies. 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); diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index 1f4336e..2cb4b1b 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1401,6 +1401,7 @@ 'browser/policy/cloud_policy_subsystem_unittest.cc', 'browser/policy/config_dir_policy_provider_unittest.cc', 'browser/policy/configuration_policy_handler_chromeos_unittest.cc', + 'browser/policy/configuration_policy_handler_unittest.cc', 'browser/policy/configuration_policy_pref_store_unittest.cc', 'browser/policy/configuration_policy_provider_mac_unittest.cc', 'browser/policy/configuration_policy_provider_test.cc', diff --git a/chrome/test/functional/policy_test_cases.py b/chrome/test/functional/policy_test_cases.py index 319c452..78bf2b9 100755 --- a/chrome/test/functional/policy_test_cases.py +++ b/chrome/test/functional/policy_test_cases.py @@ -247,6 +247,7 @@ class PolicyPrefsTestCases(object): 'GDataDisabled': (None, True, [], ['chromeos']), 'GDataDisabledOverCellular': (None, True, [], ['chromeos']), + 'PinnedLauncherApps': (None, [], [], ['chromeos']), # ChromeOS Device policies: 'DevicePolicyRefreshRate': (None, 300000, [], ['chromeos']), |