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