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..12f8af60059d03fb3403da67377dabf644da84ac 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) { |
| } |
| - |
|
Avi (use Gerrit)
2013/06/07 21:05:49
Please don't drop this blank line that separates f
François Beaufort
2013/06/10 12:41:12
Done.
|
| 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(); |
| } |
| +base::string16 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); |
| + |
| + base::string16 title; |
| + |
| + if (items.empty() || |
| + items.size() > 1 || |
| + items[0]->type() != MenuItem::NORMAL) { |
| + title = 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) |
| @@ -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) { |