Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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<base::string16> sorted_menu_titles; |
| 516 std::map<base::string16, std::string> map_ids; | |
| 513 for (std::set<std::string>::iterator i = ids.begin(); i != ids.end(); ++i) { | 517 for (std::set<std::string>::iterator i = ids.begin(); i != ids.end(); ++i) { |
| 514 const Extension* extension = service->GetExtensionById(*i, false); | 518 const Extension* extension = service->GetExtensionById(*i, false); |
| 515 // Platform apps have their context menus created directly in | 519 // Platform apps have their context menus created directly in |
| 516 // AppendPlatformAppItems. | 520 // AppendPlatformAppItems. |
| 517 if (extension && !extension->is_platform_app()) | 521 if (extension && !extension->is_platform_app()) { |
| 518 sorted_ids.push_back( | 522 base::string16 menu_title = extension_items_.GetTopLevelContextMenuTitle( |
| 519 std::pair<std::string, std::string>(extension->name(), *i)); | 523 *i, printable_selection_text); |
| 524 map_ids[menu_title] = *i; | |
| 525 sorted_menu_titles.push_back(menu_title); | |
| 526 } | |
| 520 } | 527 } |
| 521 // TODO(asargent) - See if this works properly for i18n names (bug 32363). | 528 if (sorted_menu_titles.empty()) |
| 522 std::sort(sorted_ids.begin(), sorted_ids.end()); | 529 return; |
| 523 | 530 |
| 524 if (sorted_ids.empty()) | 531 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
| 525 return; | 532 l10n_util::SortStrings16(app_locale, &sorted_menu_titles); |
|
Avi (use Gerrit)
2013/06/07 21:05:49
Whoo!
François Beaufort
2013/06/10 12:41:12
Done.
Avi (use Gerrit)
2013/06/10 14:12:28
What does "done" mean here? :)
| |
| 526 | 533 |
| 527 int index = 0; | 534 int index = 0; |
| 528 base::TimeTicks begin = base::TimeTicks::Now(); | 535 base::TimeTicks begin = base::TimeTicks::Now(); |
| 529 std::vector<std::pair<std::string, std::string> >::const_iterator i; | 536 for (size_t i = 0; i < sorted_menu_titles.size(); ++i) { |
| 530 for (i = sorted_ids.begin(); | 537 const std::string & id = map_ids[sorted_menu_titles[i]]; |
|
Avi (use Gerrit)
2013/06/07 21:05:49
no space before &
François Beaufort
2013/06/10 12:41:12
Done.
| |
| 531 i != sorted_ids.end(); ++i) { | 538 extension_items_.AppendExtensionItems(id, printable_selection_text, |
| 532 string16 printable_selection_text = PrintableSelectionText(); | |
| 533 EscapeAmpersands(&printable_selection_text); | |
| 534 | |
| 535 extension_items_.AppendExtensionItems(i->second, printable_selection_text, | |
| 536 &index); | 539 &index); |
| 537 } | 540 } |
| 541 | |
| 538 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", | 542 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", |
| 539 base::TimeTicks::Now() - begin); | 543 base::TimeTicks::Now() - begin); |
| 540 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); | 544 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); |
| 541 } | 545 } |
| 542 | 546 |
| 543 void RenderViewContextMenu::InitMenu() { | 547 void RenderViewContextMenu::InitMenu() { |
| 544 if (chrome::IsRunningInForcedAppMode()) { | 548 if (chrome::IsRunningInForcedAppMode()) { |
| 545 AppendAppModeItems(); | 549 AppendAppModeItems(); |
| 546 return; | 550 return; |
| 547 } | 551 } |
| (...skipping 1498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2046 source_web_contents_->GetRenderViewHost()-> | 2050 source_web_contents_->GetRenderViewHost()-> |
| 2047 ExecuteMediaPlayerActionAtLocation(location, action); | 2051 ExecuteMediaPlayerActionAtLocation(location, action); |
| 2048 } | 2052 } |
| 2049 | 2053 |
| 2050 void RenderViewContextMenu::PluginActionAt( | 2054 void RenderViewContextMenu::PluginActionAt( |
| 2051 const gfx::Point& location, | 2055 const gfx::Point& location, |
| 2052 const WebPluginAction& action) { | 2056 const WebPluginAction& action) { |
| 2053 source_web_contents_->GetRenderViewHost()-> | 2057 source_web_contents_->GetRenderViewHost()-> |
| 2054 ExecutePluginActionAtLocation(location, action); | 2058 ExecutePluginActionAtLocation(location, action); |
| 2055 } | 2059 } |
| OLD | NEW |