| 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 7230b9ed6345012af57ddde9560c031f74517df6..5008e894e0a052e8fba5eea8cdc61c0897941814 100644
|
| --- a/chrome/browser/extensions/extension_context_menu_model.cc
|
| +++ b/chrome/browser/extensions/extension_context_menu_model.cc
|
| @@ -33,6 +33,7 @@
|
| #include "extensions/browser/management_policy.h"
|
| #include "extensions/browser/uninstall_reason.h"
|
| #include "extensions/common/extension.h"
|
| +#include "extensions/common/feature_switch.h"
|
| #include "grit/chromium_strings.h"
|
| #include "grit/generated_resources.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| @@ -41,6 +42,8 @@ using content::OpenURLParams;
|
| using content::Referrer;
|
| using content::WebContents;
|
| using extensions::Extension;
|
| +using extensions::ExtensionActionAPI;
|
| +using extensions::ExtensionPrefs;
|
| using extensions::MenuItem;
|
| using extensions::MenuManager;
|
|
|
| @@ -66,6 +69,29 @@ bool MenuItemMatchesAction(ExtensionContextMenuModel::ActionType type,
|
| return false;
|
| }
|
|
|
| +// Returns the id for the visibility command for the given |extension|, or -1
|
| +// if none should be shown.
|
| +int GetVisibilityStringId(Profile* profile, const Extension* extension) {
|
| + DCHECK(profile);
|
| + int string_id = -1;
|
| + if (!extensions::FeatureSwitch::extension_action_redesign()->IsEnabled()) {
|
| + // Without the toolbar redesign, we only show the visibility toggle for
|
| + // browser actions, and only give the option to hide.
|
| + if (extensions::ExtensionActionManager::Get(profile)->GetBrowserAction(
|
| + *extension)) {
|
| + string_id = IDS_EXTENSIONS_HIDE_BUTTON;
|
| + }
|
| + } else {
|
| + // With the redesign, we display "show" or "hide" based on the icon's
|
| + // visibility.
|
| + bool visible = ExtensionActionAPI::GetBrowserActionVisibility(
|
| + ExtensionPrefs::Get(profile), extension->id());
|
| + string_id =
|
| + visible ? IDS_EXTENSIONS_HIDE_BUTTON : IDS_EXTENSIONS_SHOW_BUTTON;
|
| + }
|
| + return string_id;
|
| +}
|
| +
|
| } // namespace
|
|
|
| ExtensionContextMenuModel::ExtensionContextMenuModel(const Extension* extension,
|
| @@ -177,9 +203,12 @@ void ExtensionContextMenuModel::ExecuteCommand(int command_id,
|
| DCHECK(!extensions::ManifestURL::GetOptionsPage(extension).is_empty());
|
| extensions::ExtensionTabUtil::OpenOptionsPage(extension, browser_);
|
| break;
|
| - case HIDE: {
|
| - extensions::ExtensionActionAPI::SetBrowserActionVisibility(
|
| - extensions::ExtensionPrefs::Get(profile_), extension->id(), false);
|
| + case TOGGLE_VISIBILITY: {
|
| + ExtensionPrefs* prefs = ExtensionPrefs::Get(profile_);
|
| + bool visible = ExtensionActionAPI::GetBrowserActionVisibility(
|
| + prefs, extension->id());
|
| + ExtensionActionAPI::SetBrowserActionVisibility(
|
| + prefs, extension->id(), !visible);
|
| break;
|
| }
|
| case UNINSTALL: {
|
| @@ -260,8 +289,13 @@ void ExtensionContextMenuModel::InitMenu(const Extension* extension) {
|
|
|
| AddItemWithStringId(CONFIGURE, IDS_EXTENSIONS_OPTIONS_MENU_ITEM);
|
| AddItem(UNINSTALL, l10n_util::GetStringUTF16(IDS_EXTENSIONS_UNINSTALL));
|
| - if (extension_action_manager->GetBrowserAction(*extension))
|
| - AddItemWithStringId(HIDE, IDS_EXTENSIONS_HIDE_BUTTON);
|
| +
|
| + // Add a toggle visibility (show/hide) if the extension icon is shown on the
|
| + // toolbar.
|
| + int visibility_string_id = GetVisibilityStringId(profile_, extension);
|
| + if (visibility_string_id != -1)
|
| + AddItemWithStringId(TOGGLE_VISIBILITY, visibility_string_id);
|
| +
|
| AddSeparator(ui::NORMAL_SEPARATOR);
|
| AddItemWithStringId(MANAGE, IDS_MANAGE_EXTENSION);
|
| }
|
|
|