Commit 11433b24 authored by rdevlin.cronin's avatar rdevlin.cronin Committed by Commit bot

[Extensions] Show enterprise policy icon in the context menu when unremovable

When an extension is force-installed by policy and cannot be removed, show the
enterprise policy icon in the context menu, and change the string from
"Remove frome Chrome..." to be "Installed by your administrator".

BUG=486228

Review URL: https://codereview.chromium.org/1140763003

Cr-Commit-Position: refs/heads/master@{#330831}
parent 01f86dbf
...@@ -5009,6 +5009,9 @@ Even if you have downloaded files from this website before, the website might ha ...@@ -5009,6 +5009,9 @@ Even if you have downloaded files from this website before, the website might ha
<message name="IDS_EXTENSIONS_OPTIONS_MENU_ITEM" desc="The text for the options menu item in context menus (sentence case)."> <message name="IDS_EXTENSIONS_OPTIONS_MENU_ITEM" desc="The text for the options menu item in context menus (sentence case).">
Options Options
</message> </message>
<message name="IDS_EXTENSIONS_INSTALLED_BY_ADMIN" desc="The text indicating that an extension has been installed by the controlling administrator (sentence case).">
Installed by your administrator
</message>
<message name="IDS_EXTENSIONS_DISABLE" desc="The link for disabling an extension (sentence case)."> <message name="IDS_EXTENSIONS_DISABLE" desc="The link for disabling an extension (sentence case).">
Disable Disable
</message> </message>
...@@ -5035,6 +5038,9 @@ Even if you have downloaded files from this website before, the website might ha ...@@ -5035,6 +5038,9 @@ Even if you have downloaded files from this website before, the website might ha
<message name="IDS_EXTENSIONS_OPTIONS_MENU_ITEM" desc="The text for the options menu item in context menus (title case)."> <message name="IDS_EXTENSIONS_OPTIONS_MENU_ITEM" desc="The text for the options menu item in context menus (title case).">
Options Options
</message> </message>
<message name="IDS_EXTENSIONS_INSTALLED_BY_ADMIN" desc="The text indicating that an extension has been installed by the controlling administrator (title case).">
Installed by Your Administrator
</message>
<message name="IDS_EXTENSIONS_DISABLE" desc="The link for disabling an extension (title case)."> <message name="IDS_EXTENSIONS_DISABLE" desc="The link for disabling an extension (title case).">
Disable Disable
</message> </message>
...@@ -107,6 +107,16 @@ int GetVisibilityStringId( ...@@ -107,6 +107,16 @@ int GetVisibilityStringId(
return string_id; return string_id;
} }
// Returns true if the given |extension| is required to remain installed by
// policy.
bool IsExtensionRequiredByPolicy(const Extension* extension,
Profile* profile) {
extensions::ManagementPolicy* policy =
extensions::ExtensionSystem::Get(profile)->management_policy();
return !policy->UserMayModifySettings(extension, nullptr) ||
policy->MustRemainInstalled(extension, nullptr);
}
} // namespace } // namespace
ExtensionContextMenuModel::ExtensionContextMenuModel( ExtensionContextMenuModel::ExtensionContextMenuModel(
...@@ -170,11 +180,7 @@ bool ExtensionContextMenuModel::IsCommandIdEnabled(int command_id) const { ...@@ -170,11 +180,7 @@ bool ExtensionContextMenuModel::IsCommandIdEnabled(int command_id) const {
return extension_action_ && return extension_action_ &&
extension_action_->HasPopup(SessionTabHelper::IdForTab(web_contents)); extension_action_->HasPopup(SessionTabHelper::IdForTab(web_contents));
} else if (command_id == UNINSTALL) { } else if (command_id == UNINSTALL) {
// Some extension types can not be uninstalled. return !IsExtensionRequiredByPolicy(extension, profile_);
extensions::ManagementPolicy* policy =
extensions::ExtensionSystem::Get(profile_)->management_policy();
return policy->UserMayModifySettings(extension, nullptr) &&
!policy->MustRemainInstalled(extension, nullptr);
} }
return true; return true;
} }
...@@ -306,8 +312,19 @@ void ExtensionContextMenuModel::InitMenu(const Extension* extension, ...@@ -306,8 +312,19 @@ void ExtensionContextMenuModel::InitMenu(const Extension* extension,
if (!is_component_ || extensions::OptionsPageInfo::HasOptionsPage(extension)) if (!is_component_ || extensions::OptionsPageInfo::HasOptionsPage(extension))
AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS_MENU_ITEM); AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS_MENU_ITEM);
if (!is_component_) if (!is_component_) {
AddItem(UNINSTALL, l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL)); bool is_required_by_policy =
IsExtensionRequiredByPolicy(extension, profile_);
int message_id = is_required_by_policy ?
IDS_EXTENSIONS_INSTALLED_BY_ADMIN : IDS_EXTENSIONS_UNINSTALL;
AddItem(UNINSTALL, l10n_util::GetStringUTF16(message_id));
if (is_required_by_policy) {
int uninstall_index = GetIndexOfCommandId(UNINSTALL);
SetIcon(uninstall_index,
ui::ResourceBundle::GetSharedInstance().GetImageNamed(
IDR_CONTROLLED_SETTING_MANDATORY));
}
}
// Add a toggle visibility (show/hide) if the extension icon is shown on the // Add a toggle visibility (show/hide) if the extension icon is shown on the
// toolbar. // toolbar.
......
...@@ -158,7 +158,7 @@ TEST_F(ExtensionContextMenuModelTest, RequiredInstallationsDisablesItems) { ...@@ -158,7 +158,7 @@ TEST_F(ExtensionContextMenuModelTest, RequiredInstallationsDisablesItems) {
system->management_policy()->UnregisterAllProviders(); system->management_policy()->UnregisterAllProviders();
// Uninstallation should be, by default, enabled. // Uninstallation should be, by default, enabled.
ASSERT_TRUE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL)); EXPECT_TRUE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL));
TestManagementPolicyProvider policy_provider( TestManagementPolicyProvider policy_provider(
TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS); TestManagementPolicyProvider::PROHIBIT_MODIFY_STATUS);
...@@ -166,7 +166,14 @@ TEST_F(ExtensionContextMenuModelTest, RequiredInstallationsDisablesItems) { ...@@ -166,7 +166,14 @@ TEST_F(ExtensionContextMenuModelTest, RequiredInstallationsDisablesItems) {
// If there's a policy provider that requires the extension stay enabled, then // If there's a policy provider that requires the extension stay enabled, then
// uninstallation should be disabled. // uninstallation should be disabled.
ASSERT_FALSE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL)); EXPECT_FALSE(menu->IsCommandIdEnabled(ExtensionContextMenuModel::UNINSTALL));
int uninstall_index =
menu->GetIndexOfCommandId(ExtensionContextMenuModel::UNINSTALL);
// There should also be an icon to visually indicate why uninstallation is
// forbidden.
gfx::Image icon;
EXPECT_TRUE(menu->GetIconAt(uninstall_index, &icon));
EXPECT_FALSE(icon.IsEmpty());
// Don't leave |policy_provider| dangling. // Don't leave |policy_provider| dangling.
system->management_policy()->UnregisterProvider(&policy_provider); system->management_policy()->UnregisterProvider(&policy_provider);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment