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

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

Issue 1137733002: Fix an off-by-one error in checking # of action context menu items in (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add thorough test + git cl format Created 5 years, 7 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 "chrome/browser/extensions/context_menu_matcher.h" 5 #include "chrome/browser/extensions/context_menu_matcher.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/app/chrome_command_ids.h" 8 #include "chrome/app/chrome_command_ids.h"
9 #include "chrome/browser/extensions/extension_util.h" 9 #include "chrome/browser/extensions/extension_util.h"
10 #include "chrome/common/extensions/api/context_menus.h" 10 #include "chrome/common/extensions/api/context_menus.h"
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 238
239 // If last item was of type radio but the current one isn't, auto-insert 239 // If last item was of type radio but the current one isn't, auto-insert
240 // a separator. The converse case is handled below. 240 // a separator. The converse case is handled below.
241 if (last_type == MenuItem::RADIO && 241 if (last_type == MenuItem::RADIO &&
242 item->type() != MenuItem::RADIO) { 242 item->type() != MenuItem::RADIO) {
243 menu_model->AddSeparator(ui::NORMAL_SEPARATOR); 243 menu_model->AddSeparator(ui::NORMAL_SEPARATOR);
244 last_type = MenuItem::SEPARATOR; 244 last_type = MenuItem::SEPARATOR;
245 } 245 }
246 246
247 int menu_id = ConvertToExtensionsCustomCommandId(*index); 247 int menu_id = ConvertToExtensionsCustomCommandId(*index);
248 ++(*index);
249 ++num_items;
250 // Action context menus have a limit for top level extension items to 248 // Action context menus have a limit for top level extension items to
251 // prevent control items from being pushed off the screen, since extension 249 // prevent control items from being pushed off the screen, since extension
252 // items will not be placed in a submenu. 250 // items will not be placed in a submenu.
253 const int top_level_limit = api::context_menus::ACTION_MENU_TOP_LEVEL_LIMIT; 251 const int top_level_limit = api::context_menus::ACTION_MENU_TOP_LEVEL_LIMIT;
254 if (menu_id >= extensions_context_custom_last || 252 if (menu_id >= extensions_context_custom_last ||
255 (is_action_menu_top_level && num_items >= top_level_limit)) 253 (is_action_menu_top_level && num_items >= top_level_limit))
256 return; 254 return;
257 255
256 ++(*index);
257 ++num_items;
258
258 extension_item_map_[menu_id] = item->id(); 259 extension_item_map_[menu_id] = item->id();
259 base::string16 title = item->TitleWithReplacement(selection_text, 260 base::string16 title = item->TitleWithReplacement(selection_text,
260 kMaxExtensionItemTitleLength); 261 kMaxExtensionItemTitleLength);
261 if (item->type() == MenuItem::NORMAL) { 262 if (item->type() == MenuItem::NORMAL) {
262 MenuItem::List children = 263 MenuItem::List children =
263 GetRelevantExtensionItems(item->children(), can_cross_incognito); 264 GetRelevantExtensionItems(item->children(), can_cross_incognito);
264 if (children.empty()) { 265 if (children.empty()) {
265 menu_model->AddItem(menu_id, title); 266 menu_model->AddItem(menu_id, title);
266 } else { 267 } else {
267 ui::SimpleMenuModel* submenu = new ui::SimpleMenuModel(delegate_); 268 ui::SimpleMenuModel* submenu = new ui::SimpleMenuModel(delegate_);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 DCHECK_GE(index, 0); 313 DCHECK_GE(index, 0);
313 314
314 const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id); 315 const SkBitmap& icon = menu_manager->GetIconForExtension(extension_id);
315 DCHECK(icon.width() == gfx::kFaviconSize); 316 DCHECK(icon.width() == gfx::kFaviconSize);
316 DCHECK(icon.height() == gfx::kFaviconSize); 317 DCHECK(icon.height() == gfx::kFaviconSize);
317 318
318 menu_model_->SetIcon(index, gfx::Image::CreateFrom1xBitmap(icon)); 319 menu_model_->SetIcon(index, gfx::Image::CreateFrom1xBitmap(icon));
319 } 320 }
320 321
321 } // namespace extensions 322 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698