Chromium Code Reviews| 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 52924df87dc144584b2e153b05445a0a133c989c..6a93df631de94d7d7f71b6e8eee75800e9799b55 100644 | 
| --- a/chrome/browser/extensions/context_menu_matcher.cc | 
| +++ b/chrome/browser/extensions/context_menu_matcher.cc | 
| @@ -25,28 +25,22 @@ ContextMenuMatcher::ContextMenuMatcher( | 
| : profile_(profile), menu_model_(menu_model), delegate_(delegate), | 
| filter_(filter) { | 
| } | 
| - | 
| void ContextMenuMatcher::AppendExtensionItems(const std::string& extension_id, | 
| const string16& selection_text, | 
| int* index) | 
| { | 
| - ExtensionService* service = | 
| - extensions::ExtensionSystem::Get(profile_)->extension_service(); | 
| - MenuManager* manager = service->menu_manager(); | 
| - const Extension* extension = service->GetExtensionById(extension_id, false); | 
| DCHECK_GE(*index, 0); | 
| int max_index = | 
| IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST - IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST; | 
| - if (!extension || *index >= max_index) | 
| + if (*index >= max_index) | 
| return; | 
| - // Find matching items. | 
| - const MenuItem::List* all_items = manager->MenuItems(extension_id); | 
| - if (!all_items || all_items->empty()) | 
| + const Extension* extension = NULL; | 
| + MenuItem::List items; | 
| + bool can_cross_incognito; | 
| + if (!GetRelevantExtensionTopLevelItems(extension_id, &extension, | 
| + &can_cross_incognito, items)) | 
| return; | 
| - bool can_cross_incognito = service->CanCrossIncognito(extension); | 
| - MenuItem::List items = GetRelevantExtensionItems(*all_items, | 
| - can_cross_incognito); | 
| if (items.empty()) | 
| return; | 
| @@ -99,6 +93,29 @@ void ContextMenuMatcher::Clear() { | 
| extension_menu_models_.clear(); | 
| } | 
| +std::string ContextMenuMatcher::GetTopLevelContextMenuTitle( | 
| + const std::string& extension_id, | 
| + const string16& selection_text) { | 
| + const Extension* extension = NULL; | 
| + MenuItem::List items; | 
| + bool can_cross_incognito; | 
| + GetRelevantExtensionTopLevelItems(extension_id, &extension, | 
| + &can_cross_incognito, items); | 
| + | 
| + 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( | 
| 
 
Avi (use Gerrit)
2013/06/05 14:34:10
MenuItem properly follows the rule of UI strings b
 
François Beaufort
2013/06/06 09:07:37
Title is a string and not tied to the MenuItem her
 
 | 
| + selection_text, kMaxExtensionItemTitleLength)); | 
| + } | 
| + return title; | 
| +} | 
| + | 
| bool ContextMenuMatcher::IsCommandIdChecked(int command_id) const { | 
| MenuItem* item = GetExtensionMenuItem(command_id); | 
| if (!item) | 
| @@ -125,6 +142,29 @@ void ContextMenuMatcher::ExecuteCommand(int command_id, | 
| manager->ExecuteCommand(profile_, web_contents, params, item->id()); | 
| } | 
| +bool ContextMenuMatcher::GetRelevantExtensionTopLevelItems( | 
| + const std::string& extension_id, | 
| + const Extension** extension, | 
| + bool* can_cross_incognito, | 
| + MenuItem::List& items) { | 
| + ExtensionService* service = | 
| + extensions::ExtensionSystem::Get(profile_)->extension_service(); | 
| + MenuManager* manager = service->menu_manager(); | 
| + *extension = service->GetExtensionById(extension_id, false); | 
| + | 
| + if (!*extension) | 
| + return false; | 
| + | 
| + // Find matching items. | 
| + const MenuItem::List* all_items = manager->MenuItems(extension_id); | 
| + CHECK(all_items && !all_items->empty()); | 
| + *can_cross_incognito = service->CanCrossIncognito(*extension); | 
| + items = GetRelevantExtensionItems(*all_items, | 
| + can_cross_incognito); | 
| + | 
| + return true; | 
| +} | 
| + | 
| MenuItem::List ContextMenuMatcher::GetRelevantExtensionItems( | 
| const MenuItem::List& items, | 
| bool can_cross_incognito) { |