OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
6 #include "chrome/app/chrome_command_ids.h" | 6 #include "chrome/app/chrome_command_ids.h" |
7 #include "chrome/browser/extensions/context_menu_matcher.h" | 7 #include "chrome/browser/extensions/context_menu_matcher.h" |
8 #include "chrome/browser/extensions/extension_service.h" | 8 #include "chrome/browser/extensions/extension_service.h" |
9 #include "chrome/browser/extensions/extension_system.h" | 9 #include "chrome/browser/extensions/extension_system.h" |
10 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 } | 92 } |
93 SetExtensionIcon(extension_id); | 93 SetExtensionIcon(extension_id); |
94 } | 94 } |
95 } | 95 } |
96 | 96 |
97 void ContextMenuMatcher::Clear() { | 97 void ContextMenuMatcher::Clear() { |
98 extension_item_map_.clear(); | 98 extension_item_map_.clear(); |
99 extension_menu_models_.clear(); | 99 extension_menu_models_.clear(); |
100 } | 100 } |
101 | 101 |
| 102 std::string ContextMenuMatcher::GetTopLevelContextMenuTitle( |
| 103 const std::string& extension_id, |
| 104 const string16& selection_text) { |
| 105 ExtensionService* service = |
| 106 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 107 MenuManager* manager = service->menu_manager(); |
| 108 const Extension* extension = service->GetExtensionById(extension_id, false); |
| 109 |
| 110 // Find matching items. |
| 111 const MenuItem::List* all_items = manager->MenuItems(extension_id); |
| 112 CHECK(all_items && !all_items->empty()); |
| 113 bool can_cross_incognito = service->CanCrossIncognito(extension); |
| 114 MenuItem::List items = GetRelevantExtensionItems(*all_items, |
| 115 can_cross_incognito); |
| 116 |
| 117 std::string title; |
| 118 |
| 119 if (items.empty() || items.size() > 1 || items[0]->type() != MenuItem::NORMAL)
{ |
| 120 title = extension->name(); |
| 121 } else { |
| 122 MenuItem* item = items[0]; |
| 123 title = UTF16ToUTF8(item->TitleWithReplacement( |
| 124 selection_text, kMaxExtensionItemTitleLength)); |
| 125 } |
| 126 return title; |
| 127 } |
| 128 |
102 bool ContextMenuMatcher::IsCommandIdChecked(int command_id) const { | 129 bool ContextMenuMatcher::IsCommandIdChecked(int command_id) const { |
103 MenuItem* item = GetExtensionMenuItem(command_id); | 130 MenuItem* item = GetExtensionMenuItem(command_id); |
104 if (!item) | 131 if (!item) |
105 return false; | 132 return false; |
106 return item->checked(); | 133 return item->checked(); |
107 } | 134 } |
108 | 135 |
109 bool ContextMenuMatcher::IsCommandIdEnabled(int command_id) const { | 136 bool ContextMenuMatcher::IsCommandIdEnabled(int command_id) const { |
110 MenuItem* item = GetExtensionMenuItem(command_id); | 137 MenuItem* item = GetExtensionMenuItem(command_id); |
111 if (!item) | 138 if (!item) |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 DCHECK_GE(index, 0); | 251 DCHECK_GE(index, 0); |
225 | 252 |
226 const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id); | 253 const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id); |
227 DCHECK(icon.width() == gfx::kFaviconSize); | 254 DCHECK(icon.width() == gfx::kFaviconSize); |
228 DCHECK(icon.height() == gfx::kFaviconSize); | 255 DCHECK(icon.height() == gfx::kFaviconSize); |
229 | 256 |
230 menu_model_->SetIcon(index, gfx::Image::CreateFrom1xBitmap(icon)); | 257 menu_model_->SetIcon(index, gfx::Image::CreateFrom1xBitmap(icon)); |
231 } | 258 } |
232 | 259 |
233 } // namespace extensions | 260 } // namespace extensions |
OLD | NEW |