| 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 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 | 537 |
| 538 if (content_type_->SupportsGroup( | 538 if (content_type_->SupportsGroup( |
| 539 ContextMenuContentType::ITEM_GROUP_SEARCH_PROVIDER)) { | 539 ContextMenuContentType::ITEM_GROUP_SEARCH_PROVIDER)) { |
| 540 AppendSearchProvider(); | 540 AppendSearchProvider(); |
| 541 } | 541 } |
| 542 | 542 |
| 543 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PRINT)) | 543 if (content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PRINT)) |
| 544 AppendPrintItem(); | 544 AppendPrintItem(); |
| 545 | 545 |
| 546 if (content_type_->SupportsGroup( | 546 if (content_type_->SupportsGroup( |
| 547 ContextMenuContentType::ITEM_GROUP_MEDIA_PLUGIN)) { |
| 548 AppendRotationItems(); |
| 549 } |
| 550 |
| 551 if (content_type_->SupportsGroup( |
| 547 ContextMenuContentType::ITEM_GROUP_ALL_EXTENSION)) { | 552 ContextMenuContentType::ITEM_GROUP_ALL_EXTENSION)) { |
| 548 DCHECK(!content_type_->SupportsGroup( | 553 DCHECK(!content_type_->SupportsGroup( |
| 549 ContextMenuContentType::ITEM_GROUP_CURRENT_EXTENSION)); | 554 ContextMenuContentType::ITEM_GROUP_CURRENT_EXTENSION)); |
| 550 AppendAllExtensionItems(); | 555 AppendAllExtensionItems(); |
| 551 } | 556 } |
| 552 | 557 |
| 553 if (content_type_->SupportsGroup( | 558 if (content_type_->SupportsGroup( |
| 554 ContextMenuContentType::ITEM_GROUP_CURRENT_EXTENSION)) { | 559 ContextMenuContentType::ITEM_GROUP_CURRENT_EXTENSION)) { |
| 555 DCHECK(!content_type_->SupportsGroup( | 560 DCHECK(!content_type_->SupportsGroup( |
| 556 ContextMenuContentType::ITEM_GROUP_ALL_EXTENSION)); | 561 ContextMenuContentType::ITEM_GROUP_ALL_EXTENSION)); |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 } | 767 } |
| 763 | 768 |
| 764 void RenderViewContextMenu::AppendPluginItems() { | 769 void RenderViewContextMenu::AppendPluginItems() { |
| 765 if (params_.page_url == params_.src_url) { | 770 if (params_.page_url == params_.src_url) { |
| 766 // Full page plugin, so show page menu items. | 771 // Full page plugin, so show page menu items. |
| 767 if (params_.link_url.is_empty() && params_.selection_text.empty()) | 772 if (params_.link_url.is_empty() && params_.selection_text.empty()) |
| 768 AppendPageItems(); | 773 AppendPageItems(); |
| 769 } else { | 774 } else { |
| 770 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEAVAS, | 775 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEAVAS, |
| 771 IDS_CONTENT_CONTEXT_SAVEPAGEAS); | 776 IDS_CONTENT_CONTEXT_SAVEPAGEAS); |
| 772 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); | 777 // The "Print" menu item should always be included for plugins. If |
| 773 } | 778 // content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PRINT) |
| 774 | 779 // is true the item will be added inside AppendPrintItem(). Otherwise we |
| 775 if (params_.media_flags & WebContextMenuData::MediaCanRotate) { | 780 // add "Print" here. |
| 776 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | 781 if (!content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PRINT)) |
| 777 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ROTATECW, | 782 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); |
| 778 IDS_CONTENT_CONTEXT_ROTATECW); | |
| 779 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ROTATECCW, | |
| 780 IDS_CONTENT_CONTEXT_ROTATECCW); | |
| 781 } | 783 } |
| 782 } | 784 } |
| 783 | 785 |
| 784 void RenderViewContextMenu::AppendPageItems() { | 786 void RenderViewContextMenu::AppendPageItems() { |
| 785 menu_model_.AddItemWithStringId(IDC_BACK, IDS_CONTENT_CONTEXT_BACK); | 787 menu_model_.AddItemWithStringId(IDC_BACK, IDS_CONTENT_CONTEXT_BACK); |
| 786 menu_model_.AddItemWithStringId(IDC_FORWARD, IDS_CONTENT_CONTEXT_FORWARD); | 788 menu_model_.AddItemWithStringId(IDC_FORWARD, IDS_CONTENT_CONTEXT_FORWARD); |
| 787 menu_model_.AddItemWithStringId(IDC_RELOAD, IDS_CONTENT_CONTEXT_RELOAD); | 789 menu_model_.AddItemWithStringId(IDC_RELOAD, IDS_CONTENT_CONTEXT_RELOAD); |
| 788 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | 790 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
| 789 menu_model_.AddItemWithStringId(IDC_SAVE_PAGE, | 791 menu_model_.AddItemWithStringId(IDC_SAVE_PAGE, |
| 790 IDS_CONTENT_CONTEXT_SAVEPAGEAS); | 792 IDS_CONTENT_CONTEXT_SAVEPAGEAS); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 818 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_VIEWFRAMEINFO, | 820 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_VIEWFRAMEINFO, |
| 819 IDS_CONTENT_CONTEXT_VIEWFRAMEINFO); | 821 IDS_CONTENT_CONTEXT_VIEWFRAMEINFO); |
| 820 } | 822 } |
| 821 | 823 |
| 822 void RenderViewContextMenu::AppendCopyItem() { | 824 void RenderViewContextMenu::AppendCopyItem() { |
| 823 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPY, | 825 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPY, |
| 824 IDS_CONTENT_CONTEXT_COPY); | 826 IDS_CONTENT_CONTEXT_COPY); |
| 825 } | 827 } |
| 826 | 828 |
| 827 void RenderViewContextMenu::AppendPrintItem() { | 829 void RenderViewContextMenu::AppendPrintItem() { |
| 828 // AppendPluginItems() could have already added |IDC_PRINT| so we are | |
| 829 // skipping it here if |IDC_PRINT| is already present in the context menu. | |
| 830 if (menu_model_.GetIndexOfCommandId(IDC_PRINT) != -1) | |
| 831 return; | |
| 832 | |
| 833 if (GetPrefs(browser_context_)->GetBoolean(prefs::kPrintingEnabled) && | 830 if (GetPrefs(browser_context_)->GetBoolean(prefs::kPrintingEnabled) && |
| 834 (params_.media_type == WebContextMenuData::MediaTypeNone || | 831 (params_.media_type == WebContextMenuData::MediaTypeNone || |
| 835 params_.media_flags & WebContextMenuData::MediaCanPrint)) { | 832 params_.media_flags & WebContextMenuData::MediaCanPrint)) { |
| 836 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); | 833 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); |
| 837 } | 834 } |
| 838 } | 835 } |
| 839 | 836 |
| 837 void RenderViewContextMenu::AppendRotationItems() { |
| 838 if (params_.media_flags & WebContextMenuData::MediaCanRotate) { |
| 839 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
| 840 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ROTATECW, |
| 841 IDS_CONTENT_CONTEXT_ROTATECW); |
| 842 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_ROTATECCW, |
| 843 IDS_CONTENT_CONTEXT_ROTATECCW); |
| 844 } |
| 845 } |
| 846 |
| 840 void RenderViewContextMenu::AppendSearchProvider() { | 847 void RenderViewContextMenu::AppendSearchProvider() { |
| 841 DCHECK(browser_context_); | 848 DCHECK(browser_context_); |
| 842 | 849 |
| 843 base::TrimWhitespace(params_.selection_text, base::TRIM_ALL, | 850 base::TrimWhitespace(params_.selection_text, base::TRIM_ALL, |
| 844 ¶ms_.selection_text); | 851 ¶ms_.selection_text); |
| 845 if (params_.selection_text.empty()) | 852 if (params_.selection_text.empty()) |
| 846 return; | 853 return; |
| 847 | 854 |
| 848 base::ReplaceChars(params_.selection_text, AutocompleteMatch::kInvalidChars, | 855 base::ReplaceChars(params_.selection_text, AutocompleteMatch::kInvalidChars, |
| 849 base::ASCIIToUTF16(" "), ¶ms_.selection_text); | 856 base::ASCIIToUTF16(" "), ¶ms_.selection_text); |
| (...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1783 source_web_contents_->GetRenderViewHost()-> | 1790 source_web_contents_->GetRenderViewHost()-> |
| 1784 ExecuteMediaPlayerActionAtLocation(location, action); | 1791 ExecuteMediaPlayerActionAtLocation(location, action); |
| 1785 } | 1792 } |
| 1786 | 1793 |
| 1787 void RenderViewContextMenu::PluginActionAt( | 1794 void RenderViewContextMenu::PluginActionAt( |
| 1788 const gfx::Point& location, | 1795 const gfx::Point& location, |
| 1789 const WebPluginAction& action) { | 1796 const WebPluginAction& action) { |
| 1790 source_web_contents_->GetRenderViewHost()-> | 1797 source_web_contents_->GetRenderViewHost()-> |
| 1791 ExecutePluginActionAtLocation(location, action); | 1798 ExecutePluginActionAtLocation(location, action); |
| 1792 } | 1799 } |
| OLD | NEW |