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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
91 } | 91 } |
92 SetExtensionIcon(extension_id); | 92 SetExtensionIcon(extension_id); |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 void ContextMenuMatcher::Clear() { | 96 void ContextMenuMatcher::Clear() { |
97 extension_item_map_.clear(); | 97 extension_item_map_.clear(); |
98 extension_menu_models_.clear(); | 98 extension_menu_models_.clear(); |
99 } | 99 } |
100 | 100 |
101 std::string ContextMenuMatcher::GetTopLevelContextMenuTitle( | |
Yoyo Zhou
2013/02/19 19:00:50
This duplicates code in AppendExtensionItems. Can
François Beaufort
2013/02/20 11:32:06
I'm not sure about how to implement the private fu
Yoyo Zhou
2013/03/06 20:18:58
I was thinking it should take an extension_id as i
| |
102 const std::string& extension_id, | |
103 const string16& selection_text) { | |
104 ExtensionService* service = | |
105 extensions::ExtensionSystem::Get(profile_)->extension_service(); | |
106 MenuManager* manager = service->menu_manager(); | |
107 const Extension* extension = service->GetExtensionById(extension_id, false); | |
108 | |
109 // Find matching items. | |
110 const MenuItem::List* all_items = manager->MenuItems(extension_id); | |
111 if (!all_items || all_items->empty()) | |
112 // Return extension name if there are no items | |
Yoyo Zhou
2013/02/19 19:00:50
Shouldn't this function never be called for extens
François Beaufort
2013/02/20 11:32:06
Done.
| |
113 return extension->name(); | |
114 bool can_cross_incognito = service->CanCrossIncognito(extension); | |
115 MenuItem::List items = GetRelevantExtensionItems(*all_items, | |
116 can_cross_incognito); | |
117 | |
118 std::string title; | |
119 | |
120 if (items.size() > 1 || items[0]->type() != MenuItem::NORMAL) { | |
121 title = extension->name(); | |
122 } else { | |
123 MenuItem* item = items[0]; | |
124 title = UTF16ToUTF8(item->TitleWithReplacement(selection_text, | |
125 kMaxExtensionItemTitleLength)); | |
Yoyo Zhou
2013/02/19 19:00:50
nit: if you continue function arguments onto the n
François Beaufort
2013/02/20 11:32:06
Done.
| |
126 } | |
127 return title; | |
128 } | |
129 | |
101 bool ContextMenuMatcher::IsCommandIdChecked(int command_id) const { | 130 bool ContextMenuMatcher::IsCommandIdChecked(int command_id) const { |
102 MenuItem* item = GetExtensionMenuItem(command_id); | 131 MenuItem* item = GetExtensionMenuItem(command_id); |
103 if (!item) | 132 if (!item) |
104 return false; | 133 return false; |
105 return item->checked(); | 134 return item->checked(); |
106 } | 135 } |
107 | 136 |
108 bool ContextMenuMatcher::IsCommandIdEnabled(int command_id) const { | 137 bool ContextMenuMatcher::IsCommandIdEnabled(int command_id) const { |
109 MenuItem* item = GetExtensionMenuItem(command_id); | 138 MenuItem* item = GetExtensionMenuItem(command_id); |
110 if (!item) | 139 if (!item) |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
223 DCHECK_GE(index, 0); | 252 DCHECK_GE(index, 0); |
224 | 253 |
225 const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id); | 254 const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id); |
226 DCHECK(icon.width() == gfx::kFaviconSize); | 255 DCHECK(icon.width() == gfx::kFaviconSize); |
227 DCHECK(icon.height() == gfx::kFaviconSize); | 256 DCHECK(icon.height() == gfx::kFaviconSize); |
228 | 257 |
229 menu_model_->SetIcon(index, gfx::Image::CreateFrom1xBitmap(icon)); | 258 menu_model_->SetIcon(index, gfx::Image::CreateFrom1xBitmap(icon)); |
230 } | 259 } |
231 | 260 |
232 } // namespace extensions | 261 } // namespace extensions |
OLD | NEW |