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

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

Issue 476873002: Make hiding an extension action cause it to go to the overflow menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 6 years, 4 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 7230b9ed6345012af57ddde9560c031f74517df6..fa6863a5bba2bfc6bd7e79e9620fbc6b0fa3534f 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,28 @@ 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) {
Finnur 2014/08/19 10:18:04 nit: const Profile&
Devlin 2014/08/19 16:54:39 Sadly... can't. ExtensionActionAPI takes a non-co
+ 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 +202,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 +288,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);
}

Powered by Google App Engine
This is Rietveld 408576698