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

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

Issue 359493005: Extend contextMenus API to support browser/page actions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed AppendExtensionItemsImpl, minor cleanup, comments Created 6 years, 5 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/strings/utf_string_conversions.h" 5 #include "base/strings/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_util.h" 9 #include "chrome/browser/extensions/extension_util.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
(...skipping 12 matching lines...) Expand all
23 ui::SimpleMenuModel::Delegate* delegate, 23 ui::SimpleMenuModel::Delegate* delegate,
24 ui::SimpleMenuModel* menu_model, 24 ui::SimpleMenuModel* menu_model,
25 const base::Callback<bool(const MenuItem*)>& filter) 25 const base::Callback<bool(const MenuItem*)>& filter)
26 : profile_(profile), menu_model_(menu_model), delegate_(delegate), 26 : profile_(profile), menu_model_(menu_model), delegate_(delegate),
27 filter_(filter) { 27 filter_(filter) {
28 } 28 }
29 29
30 void ContextMenuMatcher::AppendExtensionItems( 30 void ContextMenuMatcher::AppendExtensionItems(
31 const MenuItem::ExtensionKey& extension_key, 31 const MenuItem::ExtensionKey& extension_key,
32 const base::string16& selection_text, 32 const base::string16& selection_text,
33 int* index) { 33 int* index,
34 bool include_icons) {
34 DCHECK_GE(*index, 0); 35 DCHECK_GE(*index, 0);
35 int max_index = 36 int max_index =
36 IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST - IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST; 37 IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST - IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST;
37 if (*index >= max_index) 38 if (*index >= max_index)
38 return; 39 return;
39 40
40 const Extension* extension = NULL; 41 const Extension* extension = NULL;
41 MenuItem::List items; 42 MenuItem::List items;
42 bool can_cross_incognito; 43 bool can_cross_incognito;
43 if (!GetRelevantExtensionTopLevelItems( 44 if (!GetRelevantExtensionTopLevelItems(
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // Now add our item(s) to the menu_model_. 80 // Now add our item(s) to the menu_model_.
80 if (submenu_items.empty()) { 81 if (submenu_items.empty()) {
81 menu_model_->AddItem(menu_id, title); 82 menu_model_->AddItem(menu_id, title);
82 } else { 83 } else {
83 ui::SimpleMenuModel* submenu = new ui::SimpleMenuModel(delegate_); 84 ui::SimpleMenuModel* submenu = new ui::SimpleMenuModel(delegate_);
84 extension_menu_models_.push_back(submenu); 85 extension_menu_models_.push_back(submenu);
85 menu_model_->AddSubMenu(menu_id, title, submenu); 86 menu_model_->AddSubMenu(menu_id, title, submenu);
86 RecursivelyAppendExtensionItems(submenu_items, can_cross_incognito, 87 RecursivelyAppendExtensionItems(submenu_items, can_cross_incognito,
87 selection_text, submenu, index); 88 selection_text, submenu, index);
88 } 89 }
89 SetExtensionIcon(extension_key.extension_id); 90 if (include_icons)
91 SetExtensionIcon(extension_key.extension_id);
90 } 92 }
91 } 93 }
92 94
93 void ContextMenuMatcher::Clear() { 95 void ContextMenuMatcher::Clear() {
94 extension_item_map_.clear(); 96 extension_item_map_.clear();
95 extension_menu_models_.clear(); 97 extension_menu_models_.clear();
96 } 98 }
97 99
98 base::string16 ContextMenuMatcher::GetTopLevelContextMenuTitle( 100 base::string16 ContextMenuMatcher::GetTopLevelContextMenuTitle(
99 const MenuItem::ExtensionKey& extension_key, 101 const MenuItem::ExtensionKey& extension_key,
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
264 DCHECK_GE(index, 0); 266 DCHECK_GE(index, 0);
265 267
266 const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id); 268 const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id);
267 DCHECK(icon.width() == gfx::kFaviconSize); 269 DCHECK(icon.width() == gfx::kFaviconSize);
268 DCHECK(icon.height() == gfx::kFaviconSize); 270 DCHECK(icon.height() == gfx::kFaviconSize);
269 271
270 menu_model_->SetIcon(index, gfx::Image::CreateFrom1xBitmap(icon)); 272 menu_model_->SetIcon(index, gfx::Image::CreateFrom1xBitmap(icon));
271 } 273 }
272 274
273 } // namespace extensions 275 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698