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 |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "chrome/browser/chrome_notification_types.h" | 29 #include "chrome/browser/chrome_notification_types.h" |
30 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" | 30 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
31 #include "chrome/browser/devtools/devtools_window.h" | 31 #include "chrome/browser/devtools/devtools_window.h" |
32 #include "chrome/browser/download/download_service.h" | 32 #include "chrome/browser/download/download_service.h" |
33 #include "chrome/browser/download/download_service_factory.h" | 33 #include "chrome/browser/download/download_service_factory.h" |
34 #include "chrome/browser/download/download_stats.h" | 34 #include "chrome/browser/download/download_stats.h" |
35 #include "chrome/browser/extensions/devtools_util.h" | 35 #include "chrome/browser/extensions/devtools_util.h" |
36 #include "chrome/browser/extensions/extension_host.h" | 36 #include "chrome/browser/extensions/extension_host.h" |
37 #include "chrome/browser/extensions/extension_service.h" | 37 #include "chrome/browser/extensions/extension_service.h" |
38 #include "chrome/browser/google/google_util.h" | 38 #include "chrome/browser/google/google_util.h" |
| 39 #include "chrome/browser/guestview/webview/webview_guest.h" |
39 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 40 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
40 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 41 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
41 #include "chrome/browser/profiles/profile.h" | 42 #include "chrome/browser/profiles/profile.h" |
42 #include "chrome/browser/profiles/profile_io_data.h" | 43 #include "chrome/browser/profiles/profile_io_data.h" |
43 #include "chrome/browser/renderer_context_menu/context_menu_content_type_factory
.h" | 44 #include "chrome/browser/renderer_context_menu/context_menu_content_type_factory
.h" |
44 #include "chrome/browser/renderer_context_menu/spellchecker_submenu_observer.h" | 45 #include "chrome/browser/renderer_context_menu/spellchecker_submenu_observer.h" |
45 #include "chrome/browser/renderer_context_menu/spelling_menu_observer.h" | 46 #include "chrome/browser/renderer_context_menu/spelling_menu_observer.h" |
46 #include "chrome/browser/search/search.h" | 47 #include "chrome/browser/search/search.h" |
47 #include "chrome/browser/search_engines/search_terms_data.h" | 48 #include "chrome/browser/search_engines/search_terms_data.h" |
48 #include "chrome/browser/search_engines/template_url.h" | 49 #include "chrome/browser/search_engines/template_url.h" |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 RenderViewContextMenu::RenderViewContextMenu( | 403 RenderViewContextMenu::RenderViewContextMenu( |
403 content::RenderFrameHost* render_frame_host, | 404 content::RenderFrameHost* render_frame_host, |
404 const content::ContextMenuParams& params) | 405 const content::ContextMenuParams& params) |
405 : params_(params), | 406 : params_(params), |
406 source_web_contents_(WebContents::FromRenderFrameHost(render_frame_host)), | 407 source_web_contents_(WebContents::FromRenderFrameHost(render_frame_host)), |
407 render_process_id_(render_frame_host->GetProcess()->GetID()), | 408 render_process_id_(render_frame_host->GetProcess()->GetID()), |
408 render_frame_id_(render_frame_host->GetRoutingID()), | 409 render_frame_id_(render_frame_host->GetRoutingID()), |
409 profile_(Profile::FromBrowserContext( | 410 profile_(Profile::FromBrowserContext( |
410 source_web_contents_->GetBrowserContext())), | 411 source_web_contents_->GetBrowserContext())), |
411 menu_model_(this), | 412 menu_model_(this), |
412 extension_items_(profile_, this, &menu_model_, | 413 extension_items_(profile_, |
413 base::Bind(MenuItemMatchesParams, params_)), | 414 this, |
| 415 &menu_model_, |
| 416 base::Bind(MenuItemMatchesParams, params_)), |
414 speech_input_submenu_model_(this), | 417 speech_input_submenu_model_(this), |
415 protocol_handler_submenu_model_(this), | 418 protocol_handler_submenu_model_(this), |
416 protocol_handler_registry_( | 419 protocol_handler_registry_( |
417 ProtocolHandlerRegistryFactory::GetForProfile(profile_)), | 420 ProtocolHandlerRegistryFactory::GetForProfile(profile_)), |
418 command_executed_(false) { | 421 command_executed_(false) { |
419 content_type_.reset(ContextMenuContentTypeFactory::Create( | 422 content_type_.reset(ContextMenuContentTypeFactory::Create( |
420 source_web_contents_, | 423 source_web_contents_, |
421 render_frame_host, params)); | 424 render_frame_host, params)); |
422 } | 425 } |
423 | 426 |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 | 525 |
523 MenuManager* menu_manager = MenuManager::Get(profile_); | 526 MenuManager* menu_manager = MenuManager::Get(profile_); |
524 if (!menu_manager) | 527 if (!menu_manager) |
525 return; | 528 return; |
526 | 529 |
527 base::string16 printable_selection_text = PrintableSelectionText(); | 530 base::string16 printable_selection_text = PrintableSelectionText(); |
528 EscapeAmpersands(&printable_selection_text); | 531 EscapeAmpersands(&printable_selection_text); |
529 | 532 |
530 // Get a list of extension id's that have context menu items, and sort by the | 533 // Get a list of extension id's that have context menu items, and sort by the |
531 // top level context menu title of the extension. | 534 // top level context menu title of the extension. |
532 std::set<std::string> ids = menu_manager->ExtensionIds(); | 535 std::set<MenuItem::ExtensionKey> ids = menu_manager->ExtensionIds(); |
533 std::vector<base::string16> sorted_menu_titles; | 536 std::vector<base::string16> sorted_menu_titles; |
534 std::map<base::string16, std::string> map_ids; | 537 std::map<base::string16, std::string> map_ids; |
535 for (std::set<std::string>::iterator i = ids.begin(); i != ids.end(); ++i) { | 538 for (std::set<MenuItem::ExtensionKey>::iterator i = ids.begin(); |
536 const Extension* extension = service->GetExtensionById(*i, false); | 539 i != ids.end(); ++i) { |
| 540 const Extension* extension = service->GetExtensionById( |
| 541 i->extension_id, false); |
537 // Platform apps have their context menus created directly in | 542 // Platform apps have their context menus created directly in |
538 // AppendPlatformAppItems. | 543 // AppendPlatformAppItems. |
539 if (extension && !extension->is_platform_app()) { | 544 if (extension && !extension->is_platform_app()) { |
540 base::string16 menu_title = extension_items_.GetTopLevelContextMenuTitle( | 545 base::string16 menu_title = extension_items_.GetTopLevelContextMenuTitle( |
541 *i, printable_selection_text); | 546 *i, printable_selection_text); |
542 map_ids[menu_title] = *i; | 547 map_ids[menu_title] = i->extension_id; |
543 sorted_menu_titles.push_back(menu_title); | 548 sorted_menu_titles.push_back(menu_title); |
544 } | 549 } |
545 } | 550 } |
546 if (sorted_menu_titles.empty()) | 551 if (sorted_menu_titles.empty()) |
547 return; | 552 return; |
548 | 553 |
549 const std::string app_locale = g_browser_process->GetApplicationLocale(); | 554 const std::string app_locale = g_browser_process->GetApplicationLocale(); |
550 l10n_util::SortStrings16(app_locale, &sorted_menu_titles); | 555 l10n_util::SortStrings16(app_locale, &sorted_menu_titles); |
551 | 556 |
552 int index = 0; | 557 int index = 0; |
553 base::TimeTicks begin = base::TimeTicks::Now(); | 558 base::TimeTicks begin = base::TimeTicks::Now(); |
554 for (size_t i = 0; i < sorted_menu_titles.size(); ++i) { | 559 for (size_t i = 0; i < sorted_menu_titles.size(); ++i) { |
555 const std::string& id = map_ids[sorted_menu_titles[i]]; | 560 const std::string& id = map_ids[sorted_menu_titles[i]]; |
556 extension_items_.AppendExtensionItems(id, printable_selection_text, | 561 const MenuItem::ExtensionKey extension_key(id); |
557 &index); | 562 extension_items_.AppendExtensionItems( |
| 563 extension_key, printable_selection_text, &index); |
558 } | 564 } |
559 | 565 |
560 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", | 566 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", |
561 base::TimeTicks::Now() - begin); | 567 base::TimeTicks::Now() - begin); |
562 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); | 568 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); |
563 } | 569 } |
564 | 570 |
565 void RenderViewContextMenu::AppendCurrentExtensionItems() { | 571 void RenderViewContextMenu::AppendCurrentExtensionItems() { |
566 // Avoid appending extension related items when |extension| is null. | 572 // Avoid appending extension related items when |extension| is null. |
567 // For Panel, this happens when the panel is navigated to a url outside of the | 573 // For Panel, this happens when the panel is navigated to a url outside of the |
568 // extension's package. | 574 // extension's package. |
569 const Extension* extension = GetExtension(); | 575 const Extension* extension = GetExtension(); |
570 if (extension) { | 576 if (extension) { |
571 // Only add extension items from this extension. | 577 // Only add extension items from this extension. |
572 int index = 0; | 578 int index = 0; |
573 extension_items_.AppendExtensionItems(extension->id(), | 579 const MenuItem::ExtensionKey key( |
574 PrintableSelectionText(), &index); | 580 extension->id(), WebViewGuest::GetViewInstanceId(source_web_contents_)); |
| 581 extension_items_.AppendExtensionItems( |
| 582 key, PrintableSelectionText(), &index); |
575 } | 583 } |
576 } | 584 } |
577 | 585 |
578 void RenderViewContextMenu::InitMenu() { | 586 void RenderViewContextMenu::InitMenu() { |
579 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_CUSTOM)) { | 587 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_CUSTOM)) { |
580 AppendCustomItems(); | 588 AppendCustomItems(); |
581 | 589 |
582 const bool has_selection = !params_.selection_text.empty(); | 590 const bool has_selection = !params_.selection_text.empty(); |
583 if (has_selection) { | 591 if (has_selection) { |
584 // We will add more items if there's a selection, so add a separator. | 592 // We will add more items if there's a selection, so add a separator. |
(...skipping 1460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2045 source_web_contents_->GetRenderViewHost()-> | 2053 source_web_contents_->GetRenderViewHost()-> |
2046 ExecuteMediaPlayerActionAtLocation(location, action); | 2054 ExecuteMediaPlayerActionAtLocation(location, action); |
2047 } | 2055 } |
2048 | 2056 |
2049 void RenderViewContextMenu::PluginActionAt( | 2057 void RenderViewContextMenu::PluginActionAt( |
2050 const gfx::Point& location, | 2058 const gfx::Point& location, |
2051 const WebPluginAction& action) { | 2059 const WebPluginAction& action) { |
2052 source_web_contents_->GetRenderViewHost()-> | 2060 source_web_contents_->GetRenderViewHost()-> |
2053 ExecutePluginActionAtLocation(location, action); | 2061 ExecutePluginActionAtLocation(location, action); |
2054 } | 2062 } |
OLD | NEW |