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

Side by Side Diff: chrome/browser/tab_contents/render_view_context_menu.cc

Issue 12299013: Fix top-level context menus sorting by name (Closed) Base URL: https://src.chromium.org/chrome/trunk/src/
Patch Set: Addressed style guide issues Created 7 years, 6 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/tab_contents/render_view_context_menu.h" 5 #include "chrome/browser/tab_contents/render_view_context_menu.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 } 499 }
500 500
501 void RenderViewContextMenu::AppendAllExtensionItems() { 501 void RenderViewContextMenu::AppendAllExtensionItems() {
502 extension_items_.Clear(); 502 extension_items_.Clear();
503 ExtensionService* service = 503 ExtensionService* service =
504 extensions::ExtensionSystem::Get(profile_)->extension_service(); 504 extensions::ExtensionSystem::Get(profile_)->extension_service();
505 if (!service) 505 if (!service)
506 return; // In unit-tests, we may not have an ExtensionService. 506 return; // In unit-tests, we may not have an ExtensionService.
507 MenuManager* menu_manager = service->menu_manager(); 507 MenuManager* menu_manager = service->menu_manager();
508 508
509 // Get a list of extension id's that have context menu items, and sort it by 509 string16 printable_selection_text = PrintableSelectionText();
510 // the extension's name. 510 EscapeAmpersands(&printable_selection_text);
511
512 // Get a list of extension id's that have context menu items, and sort by the
513 // top level context menu title of the extension.
511 std::set<std::string> ids = menu_manager->ExtensionIds(); 514 std::set<std::string> ids = menu_manager->ExtensionIds();
512 std::vector<std::pair<std::string, std::string> > sorted_ids; 515 std::vector<std::pair<std::string, std::string> > sorted_ids;
513 for (std::set<std::string>::iterator i = ids.begin(); i != ids.end(); ++i) { 516 for (std::set<std::string>::iterator i = ids.begin(); i != ids.end(); ++i) {
514 const Extension* extension = service->GetExtensionById(*i, false); 517 const Extension* extension = service->GetExtensionById(*i, false);
515 // Platform apps have their context menus created directly in 518 // Platform apps have their context menus created directly in
516 // AppendPlatformAppItems. 519 // AppendPlatformAppItems.
517 if (extension && !extension->is_platform_app()) 520 if (extension && !extension->is_platform_app()) {
521 std::string menu_title = extension_items_.GetTopLevelContextMenuTitle(
522 *i, printable_selection_text);
518 sorted_ids.push_back( 523 sorted_ids.push_back(
519 std::pair<std::string, std::string>(extension->name(), *i)); 524 std::pair<std::string, std::string>(menu_title, *i));
525 }
520 } 526 }
521 // TODO(asargent) - See if this works properly for i18n names (bug 32363). 527 // TODO(asargent) - See if this works properly for i18n names (bug 32363).
Avi (use Gerrit) 2013/06/06 14:42:27 No, std::sort will do completely the wrong thing.
522 std::sort(sorted_ids.begin(), sorted_ids.end()); 528 std::sort(sorted_ids.begin(), sorted_ids.end());
523 529
524 if (sorted_ids.empty()) 530 if (sorted_ids.empty())
525 return; 531 return;
526 532
527 int index = 0; 533 int index = 0;
528 base::TimeTicks begin = base::TimeTicks::Now(); 534 base::TimeTicks begin = base::TimeTicks::Now();
529 std::vector<std::pair<std::string, std::string> >::const_iterator i; 535 std::vector<std::pair<std::string, std::string> >::const_iterator i;
530 for (i = sorted_ids.begin(); 536 for (i = sorted_ids.begin(); i != sorted_ids.end(); ++i)
531 i != sorted_ids.end(); ++i) {
532 string16 printable_selection_text = PrintableSelectionText();
533 EscapeAmpersands(&printable_selection_text);
534
535 extension_items_.AppendExtensionItems(i->second, printable_selection_text, 537 extension_items_.AppendExtensionItems(i->second, printable_selection_text,
536 &index); 538 &index);
537 }
538 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", 539 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime",
539 base::TimeTicks::Now() - begin); 540 base::TimeTicks::Now() - begin);
540 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); 541 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index);
541 } 542 }
542 543
543 void RenderViewContextMenu::InitMenu() { 544 void RenderViewContextMenu::InitMenu() {
544 if (chrome::IsRunningInForcedAppMode()) { 545 if (chrome::IsRunningInForcedAppMode()) {
545 AppendAppModeItems(); 546 AppendAppModeItems();
546 return; 547 return;
547 } 548 }
(...skipping 1498 matching lines...) Expand 10 before | Expand all | Expand 10 after
2046 source_web_contents_->GetRenderViewHost()-> 2047 source_web_contents_->GetRenderViewHost()->
2047 ExecuteMediaPlayerActionAtLocation(location, action); 2048 ExecuteMediaPlayerActionAtLocation(location, action);
2048 } 2049 }
2049 2050
2050 void RenderViewContextMenu::PluginActionAt( 2051 void RenderViewContextMenu::PluginActionAt(
2051 const gfx::Point& location, 2052 const gfx::Point& location,
2052 const WebPluginAction& action) { 2053 const WebPluginAction& action) {
2053 source_web_contents_->GetRenderViewHost()-> 2054 source_web_contents_->GetRenderViewHost()->
2054 ExecutePluginActionAtLocation(location, action); 2055 ExecutePluginActionAtLocation(location, action);
2055 } 2056 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698