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 524 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
556 return; | 555 return; |
557 | 556 |
558 base::string16 printable_selection_text = PrintableSelectionText(); | 557 base::string16 printable_selection_text = PrintableSelectionText(); |
559 EscapeAmpersands(&printable_selection_text); | 558 EscapeAmpersands(&printable_selection_text); |
560 | 559 |
561 // Get a list of extension id's that have context menu items, and sort by the | 560 // Get a list of extension id's that have context menu items, and sort by the |
562 // top level context menu title of the extension. | 561 // top level context menu title of the extension. |
563 std::set<MenuItem::ExtensionKey> ids = menu_manager->ExtensionIds(); | 562 std::set<MenuItem::ExtensionKey> ids = menu_manager->ExtensionIds(); |
564 std::vector<base::string16> sorted_menu_titles; | 563 std::vector<base::string16> sorted_menu_titles; |
565 std::map<base::string16, std::string> map_ids; | 564 std::map<base::string16, std::string> map_ids; |
566 for (std::set<MenuItem::ExtensionKey>::iterator i = ids.begin(); | 565 for (std::set<MenuItem::ExtensionKey>::iterator iter = ids.begin(); |
567 i != ids.end(); | 566 iter != ids.end(); |
568 ++i) { | 567 ++iter) { |
569 const Extension* extension = | 568 const Extension* extension = |
570 service->GetExtensionById(i->extension_id, false); | 569 service->GetExtensionById(iter->extension_id, false); |
571 // Platform apps have their context menus created directly in | 570 // Platform apps have their context menus created directly in |
572 // AppendPlatformAppItems. | 571 // AppendPlatformAppItems. |
573 if (extension && !extension->is_platform_app()) { | 572 if (extension && !extension->is_platform_app()) { |
574 base::string16 menu_title = extension_items_.GetTopLevelContextMenuTitle( | 573 base::string16 menu_title = extension_items_.GetTopLevelContextMenuTitle( |
575 *i, printable_selection_text); | 574 *iter, printable_selection_text); |
576 map_ids[menu_title] = i->extension_id; | 575 map_ids[menu_title] = iter->extension_id; |
577 sorted_menu_titles.push_back(menu_title); | 576 sorted_menu_titles.push_back(menu_title); |
578 } | 577 } |
579 } | 578 } |
580 if (sorted_menu_titles.empty()) | 579 if (sorted_menu_titles.empty()) |
581 return; | 580 return; |
582 | 581 |
583 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 582 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
584 l10n_util::SortStrings16(app_locale, &sorted_menu_titles); | 583 l10n_util::SortStrings16(app_locale, &sorted_menu_titles); |
585 | 584 |
586 int index = 0; | 585 int index = 0; |
587 base::TimeTicks begin = base::TimeTicks::Now(); | 586 for (std::vector<base::string16>::iterator iter = sorted_menu_titles.begin(); |
brettw
2014/08/04 20:17:47
It's not clear to me why you rewrote this loop. To
Devlin
2014/08/04 20:23:02
Greg probably did this based off my comments on si
gpdavis
2014/08/04 20:52:32
Yep, that was it. Since Devlin suggested these ch
| |
588 for (size_t i = 0; i < sorted_menu_titles.size(); ++i) { | 587 iter != sorted_menu_titles.end(); |
589 const std::string& id = map_ids[sorted_menu_titles[i]]; | 588 ++iter) { |
590 const MenuItem::ExtensionKey extension_key(id); | 589 const std::string& id = map_ids[*iter]; |
591 extension_items_.AppendExtensionItems( | 590 extension_items_.AppendExtensionItems(MenuItem::ExtensionKey(id), |
592 extension_key, printable_selection_text, &index); | 591 printable_selection_text, |
592 &index, | |
593 false); // is_action_menu | |
593 } | 594 } |
594 | |
595 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", | |
596 base::TimeTicks::Now() - begin); | |
597 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); | |
598 } | 595 } |
599 | 596 |
600 void RenderViewContextMenu::AppendCurrentExtensionItems() { | 597 void RenderViewContextMenu::AppendCurrentExtensionItems() { |
601 // Avoid appending extension related items when |extension| is null. | 598 // Avoid appending extension related items when |extension| is null. |
602 // For Panel, this happens when the panel is navigated to a url outside of the | 599 // For Panel, this happens when the panel is navigated to a url outside of the |
603 // extension's package. | 600 // extension's package. |
604 const Extension* extension = GetExtension(); | 601 const Extension* extension = GetExtension(); |
605 if (extension) { | 602 if (extension) { |
606 // Only add extension items from this extension. | 603 // Only add extension items from this extension. |
607 int index = 0; | 604 int index = 0; |
608 const MenuItem::ExtensionKey key( | 605 const MenuItem::ExtensionKey key( |
609 extension->id(), WebViewGuest::GetViewInstanceId(source_web_contents_)); | 606 extension->id(), WebViewGuest::GetViewInstanceId(source_web_contents_)); |
610 extension_items_.AppendExtensionItems( | 607 extension_items_.AppendExtensionItems(key, |
611 key, PrintableSelectionText(), &index); | 608 PrintableSelectionText(), |
609 &index, | |
610 false); // is_action_menu | |
612 } | 611 } |
613 } | 612 } |
614 | 613 |
615 void RenderViewContextMenu::InitMenu() { | 614 void RenderViewContextMenu::InitMenu() { |
616 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_CUSTOM)) { | 615 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_CUSTOM)) { |
617 AppendCustomItems(); | 616 AppendCustomItems(); |
618 | 617 |
619 const bool has_selection = !params_.selection_text.empty(); | 618 const bool has_selection = !params_.selection_text.empty(); |
620 if (has_selection) { | 619 if (has_selection) { |
621 // We will add more items if there's a selection, so add a separator. | 620 // We will add more items if there's a selection, so add a separator. |
(...skipping 1413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2035 source_web_contents_->GetRenderViewHost()-> | 2034 source_web_contents_->GetRenderViewHost()-> |
2036 ExecuteMediaPlayerActionAtLocation(location, action); | 2035 ExecuteMediaPlayerActionAtLocation(location, action); |
2037 } | 2036 } |
2038 | 2037 |
2039 void RenderViewContextMenu::PluginActionAt( | 2038 void RenderViewContextMenu::PluginActionAt( |
2040 const gfx::Point& location, | 2039 const gfx::Point& location, |
2041 const WebPluginAction& action) { | 2040 const WebPluginAction& action) { |
2042 source_web_contents_->GetRenderViewHost()-> | 2041 source_web_contents_->GetRenderViewHost()-> |
2043 ExecutePluginActionAtLocation(location, action); | 2042 ExecutePluginActionAtLocation(location, action); |
2044 } | 2043 } |
OLD | NEW |