| 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" | |
| 22 #include "chrome/app/chrome_command_ids.h" | 21 #include "chrome/app/chrome_command_ids.h" |
| 23 #include "chrome/browser/app_mode/app_mode_utils.h" | 22 #include "chrome/browser/app_mode/app_mode_utils.h" |
| 24 #include "chrome/browser/autocomplete/autocomplete_classifier.h" | 23 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 25 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 24 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| 26 #include "chrome/browser/browser_process.h" | 25 #include "chrome/browser/browser_process.h" |
| 27 #include "chrome/browser/chrome_notification_types.h" | 26 #include "chrome/browser/chrome_notification_types.h" |
| 28 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" | 27 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
| 29 #include "chrome/browser/devtools/devtools_window.h" | 28 #include "chrome/browser/devtools/devtools_window.h" |
| 30 #include "chrome/browser/download/download_service.h" | 29 #include "chrome/browser/download/download_service.h" |
| 31 #include "chrome/browser/download/download_service_factory.h" | 30 #include "chrome/browser/download/download_service_factory.h" |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 return; | 557 return; |
| 559 | 558 |
| 560 base::string16 printable_selection_text = PrintableSelectionText(); | 559 base::string16 printable_selection_text = PrintableSelectionText(); |
| 561 EscapeAmpersands(&printable_selection_text); | 560 EscapeAmpersands(&printable_selection_text); |
| 562 | 561 |
| 563 // Get a list of extension id's that have context menu items, and sort by the | 562 // Get a list of extension id's that have context menu items, and sort by the |
| 564 // top level context menu title of the extension. | 563 // top level context menu title of the extension. |
| 565 std::set<MenuItem::ExtensionKey> ids = menu_manager->ExtensionIds(); | 564 std::set<MenuItem::ExtensionKey> ids = menu_manager->ExtensionIds(); |
| 566 std::vector<base::string16> sorted_menu_titles; | 565 std::vector<base::string16> sorted_menu_titles; |
| 567 std::map<base::string16, std::string> map_ids; | 566 std::map<base::string16, std::string> map_ids; |
| 568 for (std::set<MenuItem::ExtensionKey>::iterator i = ids.begin(); | 567 for (std::set<MenuItem::ExtensionKey>::iterator iter = ids.begin(); |
| 569 i != ids.end(); | 568 iter != ids.end(); |
| 570 ++i) { | 569 ++iter) { |
| 571 const Extension* extension = | 570 const Extension* extension = |
| 572 service->GetExtensionById(i->extension_id, false); | 571 service->GetExtensionById(iter->extension_id, false); |
| 573 // Platform apps have their context menus created directly in | 572 // Platform apps have their context menus created directly in |
| 574 // AppendPlatformAppItems. | 573 // AppendPlatformAppItems. |
| 575 if (extension && !extension->is_platform_app()) { | 574 if (extension && !extension->is_platform_app()) { |
| 576 base::string16 menu_title = extension_items_.GetTopLevelContextMenuTitle( | 575 base::string16 menu_title = extension_items_.GetTopLevelContextMenuTitle( |
| 577 *i, printable_selection_text); | 576 *iter, printable_selection_text); |
| 578 map_ids[menu_title] = i->extension_id; | 577 map_ids[menu_title] = iter->extension_id; |
| 579 sorted_menu_titles.push_back(menu_title); | 578 sorted_menu_titles.push_back(menu_title); |
| 580 } | 579 } |
| 581 } | 580 } |
| 582 if (sorted_menu_titles.empty()) | 581 if (sorted_menu_titles.empty()) |
| 583 return; | 582 return; |
| 584 | 583 |
| 585 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 584 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
| 586 l10n_util::SortStrings16(app_locale, &sorted_menu_titles); | 585 l10n_util::SortStrings16(app_locale, &sorted_menu_titles); |
| 587 | 586 |
| 588 int index = 0; | 587 int index = 0; |
| 589 base::TimeTicks begin = base::TimeTicks::Now(); | |
| 590 for (size_t i = 0; i < sorted_menu_titles.size(); ++i) { | 588 for (size_t i = 0; i < sorted_menu_titles.size(); ++i) { |
| 591 const std::string& id = map_ids[sorted_menu_titles[i]]; | 589 const std::string& id = map_ids[sorted_menu_titles[i]]; |
| 592 const MenuItem::ExtensionKey extension_key(id); | 590 const MenuItem::ExtensionKey extension_key(id); |
| 593 extension_items_.AppendExtensionItems( | 591 extension_items_.AppendExtensionItems(extension_key, |
| 594 extension_key, printable_selection_text, &index); | 592 printable_selection_text, |
| 593 &index, |
| 594 false); // is_action_menu |
| 595 } | 595 } |
| 596 | |
| 597 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", | |
| 598 base::TimeTicks::Now() - begin); | |
| 599 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); | |
| 600 } | 596 } |
| 601 | 597 |
| 602 void RenderViewContextMenu::AppendCurrentExtensionItems() { | 598 void RenderViewContextMenu::AppendCurrentExtensionItems() { |
| 603 // Avoid appending extension related items when |extension| is null. | 599 // Avoid appending extension related items when |extension| is null. |
| 604 // For Panel, this happens when the panel is navigated to a url outside of the | 600 // For Panel, this happens when the panel is navigated to a url outside of the |
| 605 // extension's package. | 601 // extension's package. |
| 606 const Extension* extension = GetExtension(); | 602 const Extension* extension = GetExtension(); |
| 607 if (extension) { | 603 if (extension) { |
| 608 // Only add extension items from this extension. | 604 // Only add extension items from this extension. |
| 609 int index = 0; | 605 int index = 0; |
| 610 const MenuItem::ExtensionKey key( | 606 const MenuItem::ExtensionKey key( |
| 611 extension->id(), WebViewGuest::GetViewInstanceId(source_web_contents_)); | 607 extension->id(), WebViewGuest::GetViewInstanceId(source_web_contents_)); |
| 612 extension_items_.AppendExtensionItems( | 608 extension_items_.AppendExtensionItems(key, |
| 613 key, PrintableSelectionText(), &index); | 609 PrintableSelectionText(), |
| 610 &index, |
| 611 false); // is_action_menu |
| 614 } | 612 } |
| 615 } | 613 } |
| 616 | 614 |
| 617 void RenderViewContextMenu::InitMenu() { | 615 void RenderViewContextMenu::InitMenu() { |
| 618 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_CUSTOM)) { | 616 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_CUSTOM)) { |
| 619 AppendCustomItems(); | 617 AppendCustomItems(); |
| 620 | 618 |
| 621 const bool has_selection = !params_.selection_text.empty(); | 619 const bool has_selection = !params_.selection_text.empty(); |
| 622 if (has_selection) { | 620 if (has_selection) { |
| 623 // We will add more items if there's a selection, so add a separator. | 621 // We will add more items if there's a selection, so add a separator. |
| (...skipping 1417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2041 source_web_contents_->GetRenderViewHost()-> | 2039 source_web_contents_->GetRenderViewHost()-> |
| 2042 ExecuteMediaPlayerActionAtLocation(location, action); | 2040 ExecuteMediaPlayerActionAtLocation(location, action); |
| 2043 } | 2041 } |
| 2044 | 2042 |
| 2045 void RenderViewContextMenu::PluginActionAt( | 2043 void RenderViewContextMenu::PluginActionAt( |
| 2046 const gfx::Point& location, | 2044 const gfx::Point& location, |
| 2047 const WebPluginAction& action) { | 2045 const WebPluginAction& action) { |
| 2048 source_web_contents_->GetRenderViewHost()-> | 2046 source_web_contents_->GetRenderViewHost()-> |
| 2049 ExecutePluginActionAtLocation(location, action); | 2047 ExecutePluginActionAtLocation(location, action); |
| 2050 } | 2048 } |
| OLD | NEW |