| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/tab_contents/render_view_context_menu.h" | 5 #include "chrome/browser/tab_contents/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" |
| 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_input.h" | 26 #include "chrome/browser/autocomplete/autocomplete_input.h" |
| 27 #include "chrome/browser/autocomplete/autocomplete_match.h" | 27 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 28 #include "chrome/browser/browser_process.h" | 28 #include "chrome/browser/browser_process.h" |
| 29 #include "chrome/browser/chrome_notification_types.h" | 29 #include "chrome/browser/chrome_notification_types.h" |
| 30 #include "chrome/browser/context_menu/context_menu_content_type_factory.h" |
| 30 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" | 31 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
| 31 #include "chrome/browser/devtools/devtools_window.h" | 32 #include "chrome/browser/devtools/devtools_window.h" |
| 32 #include "chrome/browser/download/download_service.h" | 33 #include "chrome/browser/download/download_service.h" |
| 33 #include "chrome/browser/download/download_service_factory.h" | 34 #include "chrome/browser/download/download_service_factory.h" |
| 34 #include "chrome/browser/download/download_stats.h" | 35 #include "chrome/browser/download/download_stats.h" |
| 35 #include "chrome/browser/extensions/devtools_util.h" | 36 #include "chrome/browser/extensions/devtools_util.h" |
| 36 #include "chrome/browser/extensions/extension_host.h" | 37 #include "chrome/browser/extensions/extension_host.h" |
| 37 #include "chrome/browser/extensions/extension_service.h" | 38 #include "chrome/browser/extensions/extension_service.h" |
| 38 #include "chrome/browser/google/google_util.h" | 39 #include "chrome/browser/google/google_util.h" |
| 39 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 40 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 render_frame_id_(render_frame_host->GetRoutingID()), | 408 render_frame_id_(render_frame_host->GetRoutingID()), |
| 408 profile_(Profile::FromBrowserContext( | 409 profile_(Profile::FromBrowserContext( |
| 409 source_web_contents_->GetBrowserContext())), | 410 source_web_contents_->GetBrowserContext())), |
| 410 menu_model_(this), | 411 menu_model_(this), |
| 411 extension_items_(profile_, this, &menu_model_, | 412 extension_items_(profile_, this, &menu_model_, |
| 412 base::Bind(MenuItemMatchesParams, params_)), | 413 base::Bind(MenuItemMatchesParams, params_)), |
| 413 speech_input_submenu_model_(this), | 414 speech_input_submenu_model_(this), |
| 414 protocol_handler_submenu_model_(this), | 415 protocol_handler_submenu_model_(this), |
| 415 protocol_handler_registry_( | 416 protocol_handler_registry_( |
| 416 ProtocolHandlerRegistryFactory::GetForProfile(profile_)), | 417 ProtocolHandlerRegistryFactory::GetForProfile(profile_)), |
| 417 command_executed_(false), | 418 command_executed_(false) { |
| 418 is_guest_(false) { | 419 content_type_.reset(ContextMenuContentTypeFactory::Create( |
| 419 RenderViewHost* rvh = source_web_contents_->GetRenderViewHost(); | 420 source_web_contents_, |
| 420 if (rvh && rvh->GetProcess()->IsGuest()) | 421 render_frame_host, params)); |
| 421 is_guest_ = true; | |
| 422 } | 422 } |
| 423 | 423 |
| 424 RenderViewContextMenu::~RenderViewContextMenu() { | 424 RenderViewContextMenu::~RenderViewContextMenu() { |
| 425 } | 425 } |
| 426 | 426 |
| 427 // Menu construction functions ------------------------------------------------- | 427 // Menu construction functions ------------------------------------------------- |
| 428 | 428 |
| 429 void RenderViewContextMenu::Init() { | 429 void RenderViewContextMenu::Init() { |
| 430 InitMenu(); | 430 InitMenu(); |
| 431 PlatformInit(); | 431 PlatformInit(); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 555 const std::string& id = map_ids[sorted_menu_titles[i]]; | 555 const std::string& id = map_ids[sorted_menu_titles[i]]; |
| 556 extension_items_.AppendExtensionItems(id, printable_selection_text, | 556 extension_items_.AppendExtensionItems(id, printable_selection_text, |
| 557 &index); | 557 &index); |
| 558 } | 558 } |
| 559 | 559 |
| 560 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", | 560 UMA_HISTOGRAM_TIMES("Extensions.ContextMenus_BuildTime", |
| 561 base::TimeTicks::Now() - begin); | 561 base::TimeTicks::Now() - begin); |
| 562 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); | 562 UMA_HISTOGRAM_COUNTS("Extensions.ContextMenus_ItemCount", index); |
| 563 } | 563 } |
| 564 | 564 |
| 565 void RenderViewContextMenu::AppendCurrentExtensionItems() { |
| 566 // Avoid appending extension related items when |extension| is null. This |
| 567 // happens when the panel is navigated to a url outside of the extension's |
| 568 // package. |
| 569 const Extension* extension = GetExtension(); |
| 570 if (extension) { |
| 571 // Only add extension items from this extension. |
| 572 int index = 0; |
| 573 extension_items_.AppendExtensionItems(extension->id(), |
| 574 PrintableSelectionText(), &index); |
| 575 } |
| 576 } |
| 577 |
| 565 void RenderViewContextMenu::InitMenu() { | 578 void RenderViewContextMenu::InitMenu() { |
| 566 if (chrome::IsRunningInForcedAppMode()) { | 579 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_CUSTOM)) |
| 567 AppendAppModeItems(); | 580 AppendCustomItems(); |
| 568 return; | 581 |
| 582 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PAGE)) |
| 583 AppendPageItems(); |
| 584 |
| 585 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_FRAME)) { |
| 586 DCHECK(!content_type_->SupportsGroup( |
| 587 ContextMenuContentType::ITEM_GROUP_PAGE)); |
| 588 AppendFrameItems(); |
| 569 } | 589 } |
| 570 | 590 |
| 571 extensions::ViewType view_type = | 591 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_LINK)) { |
| 572 extensions::GetViewType(source_web_contents_); | |
| 573 if (view_type == extensions::VIEW_TYPE_APP_WINDOW) { | |
| 574 AppendPlatformAppItems(); | |
| 575 return; | |
| 576 } else if (view_type == extensions::VIEW_TYPE_EXTENSION_POPUP) { | |
| 577 AppendPopupExtensionItems(); | |
| 578 return; | |
| 579 } else if (view_type == extensions::VIEW_TYPE_PANEL) { | |
| 580 AppendPanelItems(); | |
| 581 return; | |
| 582 } | |
| 583 | |
| 584 const bool has_link = !params_.unfiltered_link_url.is_empty(); | |
| 585 const bool has_selection = !params_.selection_text.empty(); | |
| 586 | |
| 587 if (AppendCustomItems()) { | |
| 588 // If there's a selection, don't early return when there are custom items, | |
| 589 // but fall through to adding the normal ones after the custom ones. | |
| 590 if (has_selection) { | |
| 591 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | |
| 592 } else { | |
| 593 // Don't add items for Pepper menu. | |
| 594 if (!params_.custom_context.is_pepper_menu) | |
| 595 AppendDeveloperItems(); | |
| 596 return; | |
| 597 } | |
| 598 } | |
| 599 | |
| 600 // When no special node or text is selected and selection has no link, | |
| 601 // show page items. | |
| 602 if (params_.media_type == WebContextMenuData::MediaTypeNone && | |
| 603 !has_link && | |
| 604 !params_.is_editable && | |
| 605 !is_guest_ && | |
| 606 !has_selection) { | |
| 607 if (!params_.page_url.is_empty()) { | |
| 608 bool is_devtools = IsDevToolsURL(params_.page_url); | |
| 609 if (!is_devtools && !IsInternalResourcesURL(params_.page_url)) { | |
| 610 AppendPageItems(); | |
| 611 // Merge in frame items if we clicked within a frame that needs them. | |
| 612 if (!params_.frame_url.is_empty()) { | |
| 613 is_devtools = IsDevToolsURL(params_.frame_url); | |
| 614 if (!is_devtools && !IsInternalResourcesURL(params_.frame_url)) { | |
| 615 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | |
| 616 AppendFrameItems(); | |
| 617 } | |
| 618 } | |
| 619 } | |
| 620 } else { | |
| 621 DCHECK(params_.frame_url.is_empty()); | |
| 622 } | |
| 623 } | |
| 624 | |
| 625 // Do not show link related items for guest. | |
| 626 if (has_link && !is_guest_) { | |
| 627 AppendLinkItems(); | 592 AppendLinkItems(); |
| 628 if (params_.media_type != WebContextMenuData::MediaTypeNone) | 593 if (params_.media_type != WebContextMenuData::MediaTypeNone) |
| 629 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | 594 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
| 630 } | 595 } |
| 631 | 596 |
| 632 switch (params_.media_type) { | 597 if (content_type_->SupportsGroup( |
| 633 case WebContextMenuData::MediaTypeNone: | 598 ContextMenuContentType::ITEM_GROUP_MEDIA_IMAGE)) { |
| 634 break; | 599 AppendImageItems(); |
| 635 case WebContextMenuData::MediaTypeImage: | |
| 636 AppendImageItems(); | |
| 637 break; | |
| 638 case WebContextMenuData::MediaTypeVideo: | |
| 639 AppendVideoItems(); | |
| 640 break; | |
| 641 case WebContextMenuData::MediaTypeAudio: | |
| 642 AppendAudioItems(); | |
| 643 break; | |
| 644 case WebContextMenuData::MediaTypePlugin: | |
| 645 AppendPluginItems(); | |
| 646 break; | |
| 647 #ifdef WEBCONTEXT_MEDIATYPEFILE_DEFINED | |
| 648 case WebContextMenuData::MediaTypeFile: | |
| 649 break; | |
| 650 #endif | |
| 651 } | 600 } |
| 652 | 601 |
| 653 if (params_.is_editable) | 602 if (content_type_->SupportsGroup( |
| 654 AppendEditableItems(); | 603 ContextMenuContentType::ITEM_GROUP_SEARCHWEBFORIMAGE)) { |
| 655 else if (has_selection) | 604 AppendSearchWebForImageItems(); |
| 656 AppendCopyItem(); | |
| 657 | |
| 658 if (!is_guest_ && has_selection) { | |
| 659 AppendSearchProvider(); | |
| 660 if (!IsDevToolsURL(params_.page_url)) | |
| 661 AppendPrintItem(); | |
| 662 } | 605 } |
| 663 | 606 |
| 664 if (!IsDevToolsURL(params_.page_url) && !is_guest_) | 607 if (content_type_->SupportsGroup( |
| 608 ContextMenuContentType::ITEM_GROUP_MEDIA_VIDEO)) { |
| 609 AppendVideoItems(); |
| 610 } |
| 611 |
| 612 if (content_type_->SupportsGroup( |
| 613 ContextMenuContentType::ITEM_GROUP_MEDIA_AUDIO)) { |
| 614 AppendAudioItems(); |
| 615 } |
| 616 |
| 617 if (content_type_->SupportsGroup( |
| 618 ContextMenuContentType::ITEM_GROUP_MEDIA_PLUGIN)) { |
| 619 AppendPluginItems(); |
| 620 } |
| 621 |
| 622 // ITEM_GROUP_MEDIA_FILE has no specific items. |
| 623 |
| 624 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_EDITABLE)) |
| 625 AppendEditableItems(); |
| 626 |
| 627 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_COPY)) { |
| 628 DCHECK(!content_type_->SupportsGroup( |
| 629 ContextMenuContentType::ITEM_GROUP_EDITABLE)); |
| 630 AppendCopyItem(); |
| 631 } |
| 632 |
| 633 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PRINT)) |
| 634 AppendPrintItem(); |
| 635 |
| 636 if (content_type_->SupportsGroup( |
| 637 ContextMenuContentType::ITEM_GROUP_ALL_EXTENSION)) { |
| 638 DCHECK(!content_type_->SupportsGroup( |
| 639 ContextMenuContentType::ITEM_GROUP_CURRENT_EXTENSION)); |
| 665 AppendAllExtensionItems(); | 640 AppendAllExtensionItems(); |
| 641 } |
| 666 | 642 |
| 667 AppendDeveloperItems(); | 643 if (content_type_->SupportsGroup( |
| 644 ContextMenuContentType::ITEM_GROUP_CURRENT_EXTENSION)) { |
| 645 DCHECK(!content_type_->SupportsGroup( |
| 646 ContextMenuContentType::ITEM_GROUP_ALL_EXTENSION)); |
| 647 AppendCurrentExtensionItems(); |
| 648 } |
| 668 | 649 |
| 669 if (!is_guest_) { | 650 if (content_type_->SupportsGroup( |
| 651 ContextMenuContentType::ITEM_GROUP_DEVELOPER)) { |
| 652 AppendDeveloperItems(); |
| 653 } |
| 654 |
| 655 if (content_type_->SupportsGroup( |
| 656 ContextMenuContentType::ITEM_GROUP_DEVTOOLS_UNPACKED_EXT)) { |
| 657 AppendDevtoolsForUnpackedExtensions(); |
| 658 } |
| 659 |
| 660 if (content_type_->SupportsGroup( |
| 661 ContextMenuContentType::ITEM_GROUP_PRINT_PREVIEW)) { |
| 662 AppendPrintPreviewItems(); |
| 663 } |
| 664 } |
| 665 |
| 666 void RenderViewContextMenu::AppendPrintPreviewItems() { |
| 670 #if defined(ENABLE_FULL_PRINTING) | 667 #if defined(ENABLE_FULL_PRINTING) |
| 671 if (!print_preview_menu_observer_.get()) { | 668 if (!print_preview_menu_observer_.get()) { |
| 672 print_preview_menu_observer_.reset( | 669 print_preview_menu_observer_.reset( |
| 673 new PrintPreviewContextMenuObserver(source_web_contents_)); | 670 new PrintPreviewContextMenuObserver(source_web_contents_)); |
| 674 } | 671 } |
| 675 | 672 |
| 676 observers_.AddObserver(print_preview_menu_observer_.get()); | 673 observers_.AddObserver(print_preview_menu_observer_.get()); |
| 677 #endif | 674 #endif |
| 678 } | |
| 679 } | 675 } |
| 680 | 676 |
| 681 const Extension* RenderViewContextMenu::GetExtension() const { | 677 const Extension* RenderViewContextMenu::GetExtension() const { |
| 682 extensions::ExtensionSystem* system = | 678 extensions::ExtensionSystem* system = |
| 683 extensions::ExtensionSystem::Get(profile_); | 679 extensions::ExtensionSystem::Get(profile_); |
| 684 // There is no process manager in some tests. | 680 // There is no process manager in some tests. |
| 685 if (!system->process_manager()) | 681 if (!system->process_manager()) |
| 686 return NULL; | 682 return NULL; |
| 687 | 683 |
| 688 return system->process_manager()->GetExtensionForRenderViewHost( | 684 return system->process_manager()->GetExtensionForRenderViewHost( |
| 689 source_web_contents_->GetRenderViewHost()); | 685 source_web_contents_->GetRenderViewHost()); |
| 690 } | 686 } |
| 691 | 687 |
| 692 void RenderViewContextMenu::AppendAppModeItems() { | |
| 693 const bool has_selection = !params_.selection_text.empty(); | |
| 694 | |
| 695 if (params_.is_editable) | |
| 696 AppendEditableItems(); | |
| 697 else if (has_selection) | |
| 698 AppendCopyItem(); | |
| 699 } | |
| 700 | |
| 701 void RenderViewContextMenu::AppendPlatformAppItems() { | |
| 702 const Extension* platform_app = GetExtension(); | |
| 703 | |
| 704 // The RVH might be for a process sandboxed from the extension. | |
| 705 if (!platform_app) | |
| 706 return; | |
| 707 | |
| 708 DCHECK(platform_app->is_platform_app()); | |
| 709 | |
| 710 const bool has_selection = !params_.selection_text.empty(); | |
| 711 | |
| 712 // Add undo/redo, cut/copy/paste etc for text fields. | |
| 713 if (params_.is_editable) | |
| 714 AppendEditableItems(); | |
| 715 else if (has_selection) | |
| 716 AppendCopyItem(); | |
| 717 | |
| 718 int index = 0; | |
| 719 extension_items_.AppendExtensionItems(platform_app->id(), | |
| 720 PrintableSelectionText(), &index); | |
| 721 | |
| 722 // Add dev tools for unpacked extensions. | |
| 723 if (extensions::Manifest::IsUnpackedLocation(platform_app->location()) || | |
| 724 CommandLine::ForCurrentProcess()->HasSwitch( | |
| 725 switches::kDebugPackedApps)) { | |
| 726 // Add a separator if there are any items already in the menu. | |
| 727 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | |
| 728 | |
| 729 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP, | |
| 730 IDS_CONTENT_CONTEXT_RELOAD_PACKAGED_APP); | |
| 731 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_RESTART_PACKAGED_APP, | |
| 732 IDS_CONTENT_CONTEXT_RESTART_APP); | |
| 733 AppendDeveloperItems(); | |
| 734 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE, | |
| 735 IDS_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE); | |
| 736 } | |
| 737 } | |
| 738 | |
| 739 void RenderViewContextMenu::AppendPopupExtensionItems() { | |
| 740 const bool has_selection = !params_.selection_text.empty(); | |
| 741 | |
| 742 if (params_.is_editable) | |
| 743 AppendEditableItems(); | |
| 744 else if (has_selection) | |
| 745 AppendCopyItem(); | |
| 746 | |
| 747 if (has_selection) | |
| 748 AppendSearchProvider(); | |
| 749 | |
| 750 AppendAllExtensionItems(); | |
| 751 AppendDeveloperItems(); | |
| 752 } | |
| 753 | |
| 754 void RenderViewContextMenu::AppendPanelItems() { | |
| 755 bool has_selection = !params_.selection_text.empty(); | |
| 756 | |
| 757 // Checking link should take precedence before checking selection since on Mac | |
| 758 // right-clicking a link will also make it selected. | |
| 759 if (params_.unfiltered_link_url.is_valid()) | |
| 760 AppendLinkItems(); | |
| 761 | |
| 762 if (params_.is_editable) | |
| 763 AppendEditableItems(); | |
| 764 else if (has_selection) | |
| 765 AppendCopyItem(); | |
| 766 | |
| 767 // Avoid appending extension related items when |extension| is null. This | |
| 768 // happens when the panel is navigated to a url outside of the extension's | |
| 769 // package. | |
| 770 const Extension* extension = GetExtension(); | |
| 771 if (extension) { | |
| 772 // Only add extension items from this extension. | |
| 773 int index = 0; | |
| 774 extension_items_.AppendExtensionItems(extension->id(), | |
| 775 PrintableSelectionText(), &index); | |
| 776 } | |
| 777 } | |
| 778 | |
| 779 void RenderViewContextMenu::AddMenuItem(int command_id, | 688 void RenderViewContextMenu::AddMenuItem(int command_id, |
| 780 const base::string16& title) { | 689 const base::string16& title) { |
| 781 menu_model_.AddItem(command_id, title); | 690 menu_model_.AddItem(command_id, title); |
| 782 } | 691 } |
| 783 | 692 |
| 784 void RenderViewContextMenu::AddCheckItem(int command_id, | 693 void RenderViewContextMenu::AddCheckItem(int command_id, |
| 785 const base::string16& title) { | 694 const base::string16& title) { |
| 786 menu_model_.AddCheckItem(command_id, title); | 695 menu_model_.AddCheckItem(command_id, title); |
| 787 } | 696 } |
| 788 | 697 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 if (!show_developer_items) | 744 if (!show_developer_items) |
| 836 return; | 745 return; |
| 837 | 746 |
| 838 // In the DevTools popup menu, "developer items" is normally the only | 747 // In the DevTools popup menu, "developer items" is normally the only |
| 839 // section, so omit the separator there. | 748 // section, so omit the separator there. |
| 840 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | 749 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
| 841 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_INSPECTELEMENT, | 750 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_INSPECTELEMENT, |
| 842 IDS_CONTENT_CONTEXT_INSPECTELEMENT); | 751 IDS_CONTENT_CONTEXT_INSPECTELEMENT); |
| 843 } | 752 } |
| 844 | 753 |
| 754 void RenderViewContextMenu::AppendDevtoolsForUnpackedExtensions() { |
| 755 // Add a separator if there are any items already in the menu. |
| 756 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
| 757 |
| 758 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP, |
| 759 IDS_CONTENT_CONTEXT_RELOAD_PACKAGED_APP); |
| 760 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_RESTART_PACKAGED_APP, |
| 761 IDS_CONTENT_CONTEXT_RESTART_APP); |
| 762 AppendDeveloperItems(); |
| 763 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE, |
| 764 IDS_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE); |
| 765 } |
| 766 |
| 845 void RenderViewContextMenu::AppendLinkItems() { | 767 void RenderViewContextMenu::AppendLinkItems() { |
| 846 if (!params_.link_url.is_empty()) { | 768 if (!params_.link_url.is_empty()) { |
| 847 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB, | 769 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB, |
| 848 IDS_CONTENT_CONTEXT_OPENLINKNEWTAB); | 770 IDS_CONTENT_CONTEXT_OPENLINKNEWTAB); |
| 849 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW, | 771 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW, |
| 850 IDS_CONTENT_CONTEXT_OPENLINKNEWWINDOW); | 772 IDS_CONTENT_CONTEXT_OPENLINKNEWWINDOW); |
| 851 if (params_.link_url.is_valid()) { | 773 if (params_.link_url.is_valid()) { |
| 852 AppendProtocolHandlerSubMenu(); | 774 AppendProtocolHandlerSubMenu(); |
| 853 } | 775 } |
| 854 | 776 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 867 | 789 |
| 868 void RenderViewContextMenu::AppendImageItems() { | 790 void RenderViewContextMenu::AppendImageItems() { |
| 869 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEIMAGEAS, | 791 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEIMAGEAS, |
| 870 IDS_CONTENT_CONTEXT_SAVEIMAGEAS); | 792 IDS_CONTENT_CONTEXT_SAVEIMAGEAS); |
| 871 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYIMAGELOCATION, | 793 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYIMAGELOCATION, |
| 872 IDS_CONTENT_CONTEXT_COPYIMAGELOCATION); | 794 IDS_CONTENT_CONTEXT_COPYIMAGELOCATION); |
| 873 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYIMAGE, | 795 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYIMAGE, |
| 874 IDS_CONTENT_CONTEXT_COPYIMAGE); | 796 IDS_CONTENT_CONTEXT_COPYIMAGE); |
| 875 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB, | 797 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB, |
| 876 IDS_CONTENT_CONTEXT_OPENIMAGENEWTAB); | 798 IDS_CONTENT_CONTEXT_OPENIMAGENEWTAB); |
| 799 } |
| 800 |
| 801 void RenderViewContextMenu::AppendSearchWebForImageItems() { |
| 877 const TemplateURL* const default_provider = | 802 const TemplateURL* const default_provider = |
| 878 TemplateURLServiceFactory::GetForProfile(profile_)-> | 803 TemplateURLServiceFactory::GetForProfile(profile_)-> |
| 879 GetDefaultSearchProvider(); | 804 GetDefaultSearchProvider(); |
| 880 if (!is_guest_ && params_.has_image_contents && default_provider && | 805 if (params_.has_image_contents && default_provider && |
| 881 !default_provider->image_url().empty() && | 806 !default_provider->image_url().empty() && |
| 882 default_provider->image_url_ref().IsValid()) { | 807 default_provider->image_url_ref().IsValid()) { |
| 883 menu_model_.AddItem( | 808 menu_model_.AddItem( |
| 884 IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE, | 809 IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE, |
| 885 l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_SEARCHWEBFORIMAGE, | 810 l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_SEARCHWEBFORIMAGE, |
| 886 default_provider->short_name())); | 811 default_provider->short_name())); |
| 887 } | 812 } |
| 888 AppendPrintItem(); | |
| 889 } | 813 } |
| 890 | 814 |
| 891 void RenderViewContextMenu::AppendAudioItems() { | 815 void RenderViewContextMenu::AppendAudioItems() { |
| 892 AppendMediaItems(); | 816 AppendMediaItems(); |
| 893 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | 817 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
| 894 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEAVAS, | 818 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEAVAS, |
| 895 IDS_CONTENT_CONTEXT_SAVEAUDIOAS); | 819 IDS_CONTENT_CONTEXT_SAVEAUDIOAS); |
| 896 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYAVLOCATION, | 820 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYAVLOCATION, |
| 897 IDS_CONTENT_CONTEXT_COPYAUDIOLOCATION); | 821 IDS_CONTENT_CONTEXT_COPYAUDIOLOCATION); |
| 898 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENAVNEWTAB, | 822 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENAVNEWTAB, |
| (...skipping 1212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2111 source_web_contents_->GetRenderViewHost()-> | 2035 source_web_contents_->GetRenderViewHost()-> |
| 2112 ExecuteMediaPlayerActionAtLocation(location, action); | 2036 ExecuteMediaPlayerActionAtLocation(location, action); |
| 2113 } | 2037 } |
| 2114 | 2038 |
| 2115 void RenderViewContextMenu::PluginActionAt( | 2039 void RenderViewContextMenu::PluginActionAt( |
| 2116 const gfx::Point& location, | 2040 const gfx::Point& location, |
| 2117 const WebPluginAction& action) { | 2041 const WebPluginAction& action) { |
| 2118 source_web_contents_->GetRenderViewHost()-> | 2042 source_web_contents_->GetRenderViewHost()-> |
| 2119 ExecutePluginActionAtLocation(location, action); | 2043 ExecutePluginActionAtLocation(location, action); |
| 2120 } | 2044 } |
| OLD | NEW |