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..277f4965a0613c74917b3c88366c4c867f628b21 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) { |
} |
- |
Yoyo Zhou
2013/05/08 22:54:30
looks like this was accidentally deleted
|
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, |
Yoyo Zhou
2013/05/08 22:54:30
See https://google-styleguide.googlecode.com/svn/t
François Beaufort
2013/06/04 13:09:20
Done.
|
+ 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,27 @@ 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) { |
Yoyo Zhou
2013/05/08 22:54:30
indent +1
François Beaufort
2013/06/04 13:09:20
Done.
|
+ 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) |
@@ -125,6 +140,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, |
Yoyo Zhou
2013/05/08 22:54:30
As per the style guide, if you are modifying these
François Beaufort
2013/06/04 13:09:20
Done.
|
+ MenuItem::List& items) { |
+ ExtensionService* service = |
+ extensions::ExtensionSystem::Get(profile_)->extension_service(); |
+ MenuManager* manager = service->menu_manager(); |
+ *extension = service->GetExtensionById(extension_id, false); |
+ |
+ if (!extension) |
Yoyo Zhou
2013/05/08 22:54:30
Seems this should be *extension.
François Beaufort
2013/06/04 13:09:20
Done.
|
+ 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) { |