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

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: Created 7 years, 9 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 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 } 365 }
366 366
367 void RenderViewContextMenu::AppendAllExtensionItems() { 367 void RenderViewContextMenu::AppendAllExtensionItems() {
368 extension_items_.Clear(); 368 extension_items_.Clear();
369 ExtensionService* service = 369 ExtensionService* service =
370 extensions::ExtensionSystem::Get(profile_)->extension_service(); 370 extensions::ExtensionSystem::Get(profile_)->extension_service();
371 if (!service) 371 if (!service)
372 return; // In unit-tests, we may not have an ExtensionService. 372 return; // In unit-tests, we may not have an ExtensionService.
373 MenuManager* menu_manager = service->menu_manager(); 373 MenuManager* menu_manager = service->menu_manager();
374 374
375 // Get a list of extension id's that have context menu items, and sort it by 375 string16 printable_selection_text = PrintableSelectionText();
376 // the extension's name. 376 EscapeAmpersands(&printable_selection_text);
377
378 // Get a list of extension id's that have context menu items, and sort by the
379 // top level context menu title of the extension.
377 std::set<std::string> ids = menu_manager->ExtensionIds(); 380 std::set<std::string> ids = menu_manager->ExtensionIds();
378 std::vector<std::pair<std::string, std::string> > sorted_ids; 381 std::vector<std::pair<std::string, std::string> > sorted_ids;
379 for (std::set<std::string>::iterator i = ids.begin(); i != ids.end(); ++i) { 382 for (std::set<std::string>::iterator i = ids.begin(); i != ids.end(); ++i) {
380 const Extension* extension = service->GetExtensionById(*i, false); 383 const Extension* extension = service->GetExtensionById(*i, false);
381 // Platform apps have their context menus created directly in 384 // Platform apps have their context menus created directly in
382 // AppendPlatformAppItems. 385 // AppendPlatformAppItems.
383 if (extension && !extension->is_platform_app()) 386 if (extension && !extension->is_platform_app()) {
387 std::string menu_title = extension_items_.GetTopLevelContextMenuTitle(
388 *i, printable_selection_text);
384 sorted_ids.push_back( 389 sorted_ids.push_back(
385 std::pair<std::string, std::string>(extension->name(), *i)); 390 std::pair<std::string, std::string>(menu_title, *i));
391 }
386 } 392 }
387 // TODO(asargent) - See if this works properly for i18n names (bug 32363). 393 // TODO(asargent) - See if this works properly for i18n names (bug 32363).
388 std::sort(sorted_ids.begin(), sorted_ids.end()); 394 std::sort(sorted_ids.begin(), sorted_ids.end());
389 395
390 if (sorted_ids.empty()) 396 if (sorted_ids.empty())
391 return; 397 return;
392 398
393 int index = 0; 399 int index = 0;
394 base::TimeTicks begin = base::TimeTicks::Now(); 400 base::TimeTicks begin = base::TimeTicks::Now();
395 std::vector<std::pair<std::string, std::string> >::const_iterator i; 401 std::vector<std::pair<std::string, std::string> >::const_iterator i;
396 for (i = sorted_ids.begin(); 402 for (i = sorted_ids.begin(); i != sorted_ids.end(); ++i)
397 i != sorted_ids.end(); ++i) {
398 string16 printable_selection_text = PrintableSelectionText();
399 EscapeAmpersands(&printable_selection_text);
400
401 extension_items_.AppendExtensionItems(i->second, printable_selection_text, 403 extension_items_.AppendExtensionItems(i->second, printable_selection_text,
402 &index); 404 &index);
403 }
404 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", 405 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime",
405 base::TimeTicks::Now() - begin); 406 base::TimeTicks::Now() - begin);
406 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); 407 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index);
407 } 408 }
408 409
409 void RenderViewContextMenu::InitMenu() { 410 void RenderViewContextMenu::InitMenu() {
410 if (chrome::IsRunningInForcedAppMode()) { 411 if (chrome::IsRunningInForcedAppMode()) {
411 AppendAppModeItems(); 412 AppendAppModeItems();
412 return; 413 return;
413 } 414 }
(...skipping 1476 matching lines...) Expand 10 before | Expand all | Expand 10 after
1890 source_web_contents_->GetRenderViewHost()-> 1891 source_web_contents_->GetRenderViewHost()->
1891 ExecuteMediaPlayerActionAtLocation(location, action); 1892 ExecuteMediaPlayerActionAtLocation(location, action);
1892 } 1893 }
1893 1894
1894 void RenderViewContextMenu::PluginActionAt( 1895 void RenderViewContextMenu::PluginActionAt(
1895 const gfx::Point& location, 1896 const gfx::Point& location,
1896 const WebPluginAction& action) { 1897 const WebPluginAction& action) {
1897 source_web_contents_->GetRenderViewHost()-> 1898 source_web_contents_->GetRenderViewHost()->
1898 ExecutePluginActionAtLocation(location, action); 1899 ExecutePluginActionAtLocation(location, action);
1899 } 1900 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698