Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(188)

Side by Side Diff: chrome/browser/extensions/context_menu_matcher.cc

Issue 12299013: Fix top-level context menus sorting by name (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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(
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 CHECK(!all_items || all_items->empty());
112 bool can_cross_incognito = service->CanCrossIncognito(extension);
113 MenuItem::List items = GetRelevantExtensionItems(*all_items,
114 can_cross_incognito);
115
116 std::string title;
117
118 if (items.empty() || items.size() > 1 || items[0]->type() != MenuItem::NORMAL) {
119 title = extension->name();
120 } else {
121 MenuItem* item = items[0];
122 title = UTF16ToUTF8(item->TitleWithReplacement(
123 selection_text, kMaxExtensionItemTitleLength));
124 }
125 return title;
126 }
127
101 bool ContextMenuMatcher::IsCommandIdChecked(int command_id) const { 128 bool ContextMenuMatcher::IsCommandIdChecked(int command_id) const {
102 MenuItem* item = GetExtensionMenuItem(command_id); 129 MenuItem* item = GetExtensionMenuItem(command_id);
103 if (!item) 130 if (!item)
104 return false; 131 return false;
105 return item->checked(); 132 return item->checked();
106 } 133 }
107 134
108 bool ContextMenuMatcher::IsCommandIdEnabled(int command_id) const { 135 bool ContextMenuMatcher::IsCommandIdEnabled(int command_id) const {
109 MenuItem* item = GetExtensionMenuItem(command_id); 136 MenuItem* item = GetExtensionMenuItem(command_id);
110 if (!item) 137 if (!item)
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 DCHECK_GE(index, 0); 250 DCHECK_GE(index, 0);
224 251
225 const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id); 252 const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id);
226 DCHECK(icon.width() == gfx::kFaviconSize); 253 DCHECK(icon.width() == gfx::kFaviconSize);
227 DCHECK(icon.height() == gfx::kFaviconSize); 254 DCHECK(icon.height() == gfx::kFaviconSize);
228 255
229 menu_model_->SetIcon(index, gfx::Image::CreateFrom1xBitmap(icon)); 256 menu_model_->SetIcon(index, gfx::Image::CreateFrom1xBitmap(icon));
230 } 257 }
231 258
232 } // namespace extensions 259 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698