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

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

Issue 12299013: Fix top-level context menus sorting by name (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 9 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
===================================================================
--- chrome/browser/extensions/context_menu_matcher.cc (revision 188662)
+++ chrome/browser/extensions/context_menu_matcher.cc (working copy)
@@ -99,6 +99,33 @@
extension_menu_models_.clear();
}
+std::string ContextMenuMatcher::GetTopLevelContextMenuTitle(
+ const std::string& extension_id,
+ const string16& selection_text) {
+ ExtensionService* service =
+ extensions::ExtensionSystem::Get(profile_)->extension_service();
+ MenuManager* manager = service->menu_manager();
+ const Extension* extension = service->GetExtensionById(extension_id, false);
+
+ // Find matching items.
+ const MenuItem::List* all_items = manager->MenuItems(extension_id);
+ CHECK(all_items && !all_items->empty());
+ bool can_cross_incognito = service->CanCrossIncognito(extension);
+ MenuItem::List items = GetRelevantExtensionItems(*all_items,
+ can_cross_incognito);
+
+ std::string title;
+
+ if (items.empty() || items.size() > 1 || items[0]->type() != MenuItem::NORMAL) {
+ title = extension->name();
+ } else {
+ MenuItem* item = items[0];
+ title = UTF16ToUTF8(item->TitleWithReplacement(
+ selection_text, kMaxExtensionItemTitleLength));
+ }
+ return title;
+}
+
bool ContextMenuMatcher::IsCommandIdChecked(int command_id) const {
MenuItem* item = GetExtensionMenuItem(command_id);
if (!item)

Powered by Google App Engine
This is Rietveld 408576698