Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5631)

Unified Diff: chrome/browser/extensions/extension_context_menu_model.cc

Issue 1140763003: [Extensions] Show enterprise policy icon in the context menu when unremovable (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Finnur's Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/extension_context_menu_model.cc
diff --git a/chrome/browser/extensions/extension_context_menu_model.cc b/chrome/browser/extensions/extension_context_menu_model.cc
index 492f0289e593af770f8ea7cffb3aa117ad9a4678..3d9e31d8d3400df330b74cbe45592859bef90fc0 100644
--- a/chrome/browser/extensions/extension_context_menu_model.cc
+++ b/chrome/browser/extensions/extension_context_menu_model.cc
@@ -107,6 +107,16 @@ int GetVisibilityStringId(
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
ExtensionContextMenuModel::ExtensionContextMenuModel(
@@ -170,11 +180,7 @@ bool ExtensionContextMenuModel::IsCommandIdEnabled(int command_id) const {
return extension_action_ &&
extension_action_->HasPopup(SessionTabHelper::IdForTab(web_contents));
} else if (command_id == UNINSTALL) {
- // Some extension types can not be uninstalled.
- extensions::ManagementPolicy* policy =
- extensions::ExtensionSystem::Get(profile_)->management_policy();
- return policy->UserMayModifySettings(extension, nullptr) &&
- !policy->MustRemainInstalled(extension, nullptr);
+ return !IsExtensionRequiredByPolicy(extension, profile_);
}
return true;
}
@@ -306,8 +312,19 @@ void ExtensionContextMenuModel::InitMenu(const Extension* extension,
if (!is_component_ || extensions::OptionsPageInfo::HasOptionsPage(extension))
AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS_MENU_ITEM);
- if (!is_component_)
- AddItem(UNINSTALL, l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL));
+ if (!is_component_) {
+ 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
// toolbar.
« no previous file with comments | « chrome/app/generated_resources.grd ('k') | chrome/browser/extensions/extension_context_menu_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698