Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/renderer_context_menu/render_view_context_menu.h" | 5 #include "chrome/browser/renderer_context_menu/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 |
| 11 #include "apps/app_load_service.h" | 11 #include "apps/app_load_service.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/prefs/pref_member.h" | 15 #include "base/prefs/pref_member.h" |
| 16 #include "base/prefs/pref_service.h" | 16 #include "base/prefs/pref_service.h" |
| 17 #include "base/stl_util.h" | 17 #include "base/stl_util.h" |
| 18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
| 19 #include "base/strings/stringprintf.h" | 19 #include "base/strings/stringprintf.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/time/time.h" | 21 #include "base/time/time.h" |
|
Devlin
2014/07/15 21:25:08
nit: remove this.
gpdavis
2014/07/15 22:18:13
Nice catch! Taken care of.
| |
| 22 #include "chrome/app/chrome_command_ids.h" | 22 #include "chrome/app/chrome_command_ids.h" |
| 23 #include "chrome/browser/app_mode/app_mode_utils.h" | 23 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 24 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 24 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 25 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 25 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| 26 #include "chrome/browser/autocomplete/autocomplete_match.h" | 26 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 27 #include "chrome/browser/browser_process.h" | 27 #include "chrome/browser/browser_process.h" |
| 28 #include "chrome/browser/chrome_notification_types.h" | 28 #include "chrome/browser/chrome_notification_types.h" |
| 29 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" | 29 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
| 30 #include "chrome/browser/devtools/devtools_window.h" | 30 #include "chrome/browser/devtools/devtools_window.h" |
| 31 #include "chrome/browser/download/download_service.h" | 31 #include "chrome/browser/download/download_service.h" |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 526 return; | 526 return; |
| 527 | 527 |
| 528 base::string16 printable_selection_text = PrintableSelectionText(); | 528 base::string16 printable_selection_text = PrintableSelectionText(); |
| 529 EscapeAmpersands(&printable_selection_text); | 529 EscapeAmpersands(&printable_selection_text); |
| 530 | 530 |
| 531 // Get a list of extension id's that have context menu items, and sort by the | 531 // Get a list of extension id's that have context menu items, and sort by the |
| 532 // top level context menu title of the extension. | 532 // top level context menu title of the extension. |
| 533 std::set<MenuItem::ExtensionKey> ids = menu_manager->ExtensionIds(); | 533 std::set<MenuItem::ExtensionKey> ids = menu_manager->ExtensionIds(); |
| 534 std::vector<base::string16> sorted_menu_titles; | 534 std::vector<base::string16> sorted_menu_titles; |
| 535 std::map<base::string16, std::string> map_ids; | 535 std::map<base::string16, std::string> map_ids; |
| 536 for (std::set<MenuItem::ExtensionKey>::iterator i = ids.begin(); | 536 for (std::set<MenuItem::ExtensionKey>::iterator iter = ids.begin(); |
| 537 i != ids.end(); | 537 iter != ids.end(); |
| 538 ++i) { | 538 ++iter) { |
| 539 const Extension* extension = | 539 const Extension* extension = |
| 540 service->GetExtensionById(i->extension_id, false); | 540 service->GetExtensionById(iter->extension_id, false); |
| 541 // Platform apps have their context menus created directly in | 541 // Platform apps have their context menus created directly in |
| 542 // AppendPlatformAppItems. | 542 // AppendPlatformAppItems. |
| 543 if (extension && !extension->is_platform_app()) { | 543 if (extension && !extension->is_platform_app()) { |
| 544 base::string16 menu_title = extension_items_.GetTopLevelContextMenuTitle( | 544 base::string16 menu_title = extension_items_.GetTopLevelContextMenuTitle( |
| 545 *i, printable_selection_text); | 545 *iter, printable_selection_text); |
| 546 map_ids[menu_title] = i->extension_id; | 546 map_ids[menu_title] = iter->extension_id; |
| 547 sorted_menu_titles.push_back(menu_title); | 547 sorted_menu_titles.push_back(menu_title); |
| 548 } | 548 } |
| 549 } | 549 } |
| 550 if (sorted_menu_titles.empty()) | 550 if (sorted_menu_titles.empty()) |
| 551 return; | 551 return; |
| 552 | 552 |
| 553 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 553 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
| 554 l10n_util::SortStrings16(app_locale, &sorted_menu_titles); | 554 l10n_util::SortStrings16(app_locale, &sorted_menu_titles); |
| 555 | 555 |
| 556 int index = 0; | 556 int index = 0; |
| 557 base::TimeTicks begin = base::TimeTicks::Now(); | 557 for (std::vector<base::string16>::iterator iter = sorted_menu_titles.begin(); |
| 558 for (size_t i = 0; i < sorted_menu_titles.size(); ++i) { | 558 iter != sorted_menu_titles.end(); |
| 559 const std::string& id = map_ids[sorted_menu_titles[i]]; | 559 ++iter) { |
| 560 const MenuItem::ExtensionKey extension_key(id); | 560 const std::string& id = map_ids[*iter]; |
| 561 extension_items_.AppendExtensionItems( | 561 extension_items_.AppendExtensionItems(MenuItem::ExtensionKey(id), |
| 562 extension_key, printable_selection_text, &index); | 562 printable_selection_text, |
| 563 &index, | |
| 564 true); // include_icons | |
|
Yoyo Zhou
2014/07/15 23:35:00
nit: two spaces before // comments
gpdavis
2014/07/16 01:11:10
Done.
| |
| 563 } | 565 } |
| 564 | |
| 565 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", | |
| 566 base::TimeTicks::Now() - begin); | |
| 567 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); | |
| 568 } | 566 } |
| 569 | 567 |
| 570 void RenderViewContextMenu::AppendCurrentExtensionItems() { | 568 void RenderViewContextMenu::AppendCurrentExtensionItems() { |
| 571 // Avoid appending extension related items when |extension| is null. | 569 // Avoid appending extension related items when |extension| is null. |
| 572 // For Panel, this happens when the panel is navigated to a url outside of the | 570 // For Panel, this happens when the panel is navigated to a url outside of the |
| 573 // extension's package. | 571 // extension's package. |
| 574 const Extension* extension = GetExtension(); | 572 const Extension* extension = GetExtension(); |
| 575 if (extension) { | 573 if (extension) { |
| 576 // Only add extension items from this extension. | 574 // Only add extension items from this extension. |
| 577 int index = 0; | 575 int index = 0; |
| 578 const MenuItem::ExtensionKey key( | 576 const MenuItem::ExtensionKey key( |
| 579 extension->id(), WebViewGuest::GetViewInstanceId(source_web_contents_)); | 577 extension->id(), WebViewGuest::GetViewInstanceId(source_web_contents_)); |
| 580 extension_items_.AppendExtensionItems( | 578 extension_items_.AppendExtensionItems(key, |
| 581 key, PrintableSelectionText(), &index); | 579 PrintableSelectionText(), |
| 580 &index, | |
| 581 true); // include_icons | |
| 582 } | 582 } |
| 583 } | 583 } |
| 584 | 584 |
| 585 void RenderViewContextMenu::InitMenu() { | 585 void RenderViewContextMenu::InitMenu() { |
| 586 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_CUSTOM)) { | 586 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_CUSTOM)) { |
| 587 AppendCustomItems(); | 587 AppendCustomItems(); |
| 588 | 588 |
| 589 const bool has_selection = !params_.selection_text.empty(); | 589 const bool has_selection = !params_.selection_text.empty(); |
| 590 if (has_selection) { | 590 if (has_selection) { |
| 591 // We will add more items if there's a selection, so add a separator. | 591 // We will add more items if there's a selection, so add a separator. |
| (...skipping 1401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1993 source_web_contents_->GetRenderViewHost()-> | 1993 source_web_contents_->GetRenderViewHost()-> |
| 1994 ExecuteMediaPlayerActionAtLocation(location, action); | 1994 ExecuteMediaPlayerActionAtLocation(location, action); |
| 1995 } | 1995 } |
| 1996 | 1996 |
| 1997 void RenderViewContextMenu::PluginActionAt( | 1997 void RenderViewContextMenu::PluginActionAt( |
| 1998 const gfx::Point& location, | 1998 const gfx::Point& location, |
| 1999 const WebPluginAction& action) { | 1999 const WebPluginAction& action) { |
| 2000 source_web_contents_->GetRenderViewHost()-> | 2000 source_web_contents_->GetRenderViewHost()-> |
| 2001 ExecutePluginActionAtLocation(location, action); | 2001 ExecutePluginActionAtLocation(location, action); |
| 2002 } | 2002 } |
| OLD | NEW |