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

Unified Diff: chrome/browser/ui/app_list/extension_app_item.cc

Issue 10918103: Give platform apps control over launcher right-click context menu. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: implement antony's comments and rebase Created 8 years, 3 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/ui/app_list/extension_app_item.cc
diff --git a/chrome/browser/ui/app_list/extension_app_item.cc b/chrome/browser/ui/app_list/extension_app_item.cc
index da205674d66733f4c3a3b61f6a513b7e03777dcb..1b8f73c64fc72cbaef626424d24baeb1406c65c8 100644
--- a/chrome/browser/ui/app_list/extension_app_item.cc
+++ b/chrome/browser/ui/app_list/extension_app_item.cc
@@ -5,6 +5,8 @@
#include "chrome/browser/ui/app_list/extension_app_item.h"
#include "base/utf_string_conversions.h"
+#include "chrome/app/chrome_command_ids.h"
+#include "chrome/browser/extensions/context_menu_matcher.h"
#include "chrome/browser/extensions/extension_prefs.h"
#include "chrome/browser/extensions/extension_service.h"
#include "chrome/browser/extensions/extension_system.h"
@@ -19,6 +21,7 @@
#include "chrome/common/extensions/extension.h"
#include "chrome/common/extensions/extension_constants.h"
#include "chrome/common/extensions/extension_icon_set.h"
+#include "content/public/common/context_menu_params.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "ui/base/l10n/l10n_util.h"
@@ -120,6 +123,10 @@ bool IsExtensionEnabled(Profile* profile, const std::string& extension_id) {
!service->GetTerminatedExtension(extension_id);
}
+bool MenuItemHasLauncherContext(const extensions::MenuItem* item) {
+ return item->contexts().Contains(extensions::MenuItem::LAUNCHER);
+}
+
} // namespace
ExtensionAppItem::ExtensionAppItem(Profile* profile,
@@ -214,6 +221,9 @@ bool ExtensionAppItem::IsCommandIdChecked(int command_id) const {
if (command_id >= LAUNCH_TYPE_START && command_id < LAUNCH_TYPE_LAST) {
return static_cast<int>(GetExtensionLaunchType(profile_, extension_id_)) +
LAUNCH_TYPE_START == command_id;
+ } else if (command_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST &&
+ command_id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) {
+ return extension_menu_items_->IsCommandIdChecked(command_id);
}
return false;
}
@@ -234,6 +244,9 @@ bool ExtensionAppItem::IsCommandIdEnabled(int command_id) const {
} else if (command_id == DETAILS) {
const Extension* extension = GetExtension();
return extension && extension->from_webstore();
+ } else if (command_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST &&
+ command_id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) {
+ return extension_menu_items_->IsCommandIdEnabled(command_id);
}
return true;
}
@@ -264,6 +277,10 @@ void ExtensionAppItem::ExecuteCommand(int command_id) {
StartExtensionUninstall();
} else if (command_id == DETAILS) {
ShowExtensionDetails();
+ } else if (command_id >= IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST &&
+ command_id <= IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST) {
+ extension_menu_items_->ExecuteCommand(command_id,
+ content::ContextMenuParams());
}
}
@@ -294,9 +311,16 @@ ui::MenuModel* ExtensionAppItem::GetContextMenuModel() {
if (!context_menu_model_.get()) {
context_menu_model_.reset(new ui::SimpleMenuModel(this));
+ extension_menu_items_.reset(new extensions::ContextMenuMatcher(
+ profile_, this, context_menu_model_.get(),
+ base::Bind(MenuItemHasLauncherContext)));
+
context_menu_model_->AddItem(LAUNCH, UTF8ToUTF16(title()));
// Talk extension isn't an app and so doesn't support most launch options.
if (!IsTalkExtension()) {
+ int index = 0;
+ extension_menu_items_->AppendExtensionItems(extension_id_, string16(),
+ &index);
context_menu_model_->AddSeparator(ui::NORMAL_SEPARATOR);
context_menu_model_->AddItemWithStringId(
TOGGLE_PIN,

Powered by Google App Engine
This is Rietveld 408576698