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

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

Issue 359493005: Extend contextMenus API to support browser/page actions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed icons Created 6 years, 5 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/context_menu_matcher.cc
diff --git a/chrome/browser/extensions/context_menu_matcher.cc b/chrome/browser/extensions/context_menu_matcher.cc
index 0e7adbddbdfc61208f56cfd0c7d2a7e67421d05e..c4aecab2032973d782fcd8fe12af1e3347440d43 100644
--- a/chrome/browser/extensions/context_menu_matcher.cc
+++ b/chrome/browser/extensions/context_menu_matcher.cc
@@ -31,6 +31,80 @@ void ContextMenuMatcher::AppendExtensionItems(
const MenuItem::ExtensionKey& extension_key,
const base::string16& selection_text,
int* index) {
+ ContextMenuMatcher::AppendExtensionItemsImpl(extension_key,
+ selection_text,
+ index,
+ true);
+}
+
+void ContextMenuMatcher::AppendExtensionItemsWithoutIcons(
+ const MenuItem::ExtensionKey& extension_key,
+ const base::string16& selection_text,
+ int* index) {
+ ContextMenuMatcher::AppendExtensionItemsImpl(extension_key,
+ selection_text,
+ index,
+ false);
+}
+
+void ContextMenuMatcher::Clear() {
+ extension_item_map_.clear();
+ extension_menu_models_.clear();
+}
+
+base::string16 ContextMenuMatcher::GetTopLevelContextMenuTitle(
+ const MenuItem::ExtensionKey& extension_key,
+ const base::string16& selection_text) {
+ const Extension* extension = NULL;
+ MenuItem::List items;
+ bool can_cross_incognito;
+ GetRelevantExtensionTopLevelItems(
+ extension_key, &extension, &can_cross_incognito, items);
+
+ base::string16 title;
+
+ if (items.empty() ||
+ items.size() > 1 ||
+ items[0]->type() != MenuItem::NORMAL) {
+ title = base::UTF8ToUTF16(extension->name());
+ } else {
+ MenuItem* item = items[0];
+ title = item->TitleWithReplacement(
+ selection_text, kMaxExtensionItemTitleLength);
+ }
+ return title;
+}
+
+bool ContextMenuMatcher::IsCommandIdChecked(int command_id) const {
+ MenuItem* item = GetExtensionMenuItem(command_id);
+ if (!item)
+ return false;
+ return item->checked();
+}
+
+bool ContextMenuMatcher::IsCommandIdEnabled(int command_id) const {
+ MenuItem* item = GetExtensionMenuItem(command_id);
+ if (!item)
+ return true;
+ return item->enabled();
+}
+
+void ContextMenuMatcher::ExecuteCommand(int command_id,
+ content::WebContents* web_contents,
+ const content::ContextMenuParams& params) {
+ MenuItem* item = GetExtensionMenuItem(command_id);
+ if (!item)
+ return;
+
+ MenuManager* manager = MenuManager::Get(profile_);
+ manager->ExecuteCommand(profile_, web_contents, params, item->id());
+}
+
+void ContextMenuMatcher::AppendExtensionItemsImpl(
+ const MenuItem::ExtensionKey& extension_key,
+ const base::string16& selection_text,
+ int* index,
+ bool include_icons) {
DCHECK_GE(*index, 0);
int max_index =
IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST - IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST;
@@ -86,63 +160,11 @@ void ContextMenuMatcher::AppendExtensionItems(
RecursivelyAppendExtensionItems(submenu_items, can_cross_incognito,
selection_text, submenu, index);
}
- SetExtensionIcon(extension_key.extension_id);
+ if (include_icons)
+ SetExtensionIcon(extension_key.extension_id);
}
}
-void ContextMenuMatcher::Clear() {
- extension_item_map_.clear();
- extension_menu_models_.clear();
-}
-
-base::string16 ContextMenuMatcher::GetTopLevelContextMenuTitle(
- const MenuItem::ExtensionKey& extension_key,
- const base::string16& selection_text) {
- const Extension* extension = NULL;
- MenuItem::List items;
- bool can_cross_incognito;
- GetRelevantExtensionTopLevelItems(
- extension_key, &extension, &can_cross_incognito, items);
-
- base::string16 title;
-
- if (items.empty() ||
- items.size() > 1 ||
- items[0]->type() != MenuItem::NORMAL) {
- title = base::UTF8ToUTF16(extension->name());
- } else {
- MenuItem* item = items[0];
- title = item->TitleWithReplacement(
- selection_text, kMaxExtensionItemTitleLength);
- }
- return title;
-}
-
-bool ContextMenuMatcher::IsCommandIdChecked(int command_id) const {
- MenuItem* item = GetExtensionMenuItem(command_id);
- if (!item)
- return false;
- return item->checked();
-}
-
-bool ContextMenuMatcher::IsCommandIdEnabled(int command_id) const {
- MenuItem* item = GetExtensionMenuItem(command_id);
- if (!item)
- return true;
- return item->enabled();
-}
-
-void ContextMenuMatcher::ExecuteCommand(int command_id,
- content::WebContents* web_contents,
- const content::ContextMenuParams& params) {
- MenuItem* item = GetExtensionMenuItem(command_id);
- if (!item)
- return;
-
- MenuManager* manager = MenuManager::Get(profile_);
- manager->ExecuteCommand(profile_, web_contents, params, item->id());
-}
-
bool ContextMenuMatcher::GetRelevantExtensionTopLevelItems(
const MenuItem::ExtensionKey& extension_key,
const Extension** extension,

Powered by Google App Engine
This is Rietveld 408576698