| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 #include "chrome/common/net/url_util.h" | 59 #include "chrome/common/net/url_util.h" |
| 60 #include "chrome/common/pref_names.h" | 60 #include "chrome/common/pref_names.h" |
| 61 #include "chrome/common/render_messages.h" | 61 #include "chrome/common/render_messages.h" |
| 62 #include "chrome/common/spellcheck_messages.h" | 62 #include "chrome/common/spellcheck_messages.h" |
| 63 #include "chrome/common/url_constants.h" | 63 #include "chrome/common/url_constants.h" |
| 64 #include "chrome/grit/generated_resources.h" | 64 #include "chrome/grit/generated_resources.h" |
| 65 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" | 65 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_heade
rs.h" |
| 66 #include "components/google/core/browser/google_util.h" | 66 #include "components/google/core/browser/google_util.h" |
| 67 #include "components/metrics/proto/omnibox_input_type.pb.h" | 67 #include "components/metrics/proto/omnibox_input_type.pb.h" |
| 68 #include "components/omnibox/autocomplete_match.h" | 68 #include "components/omnibox/autocomplete_match.h" |
| 69 #include "components/password_manager/core/common/experiments.h" |
| 69 #include "components/search_engines/template_url.h" | 70 #include "components/search_engines/template_url.h" |
| 70 #include "components/search_engines/template_url_service.h" | 71 #include "components/search_engines/template_url_service.h" |
| 71 #include "components/translate/core/browser/translate_download_manager.h" | 72 #include "components/translate/core/browser/translate_download_manager.h" |
| 72 #include "components/translate/core/browser/translate_manager.h" | 73 #include "components/translate/core/browser/translate_manager.h" |
| 73 #include "components/translate/core/browser/translate_prefs.h" | 74 #include "components/translate/core/browser/translate_prefs.h" |
| 74 #include "components/user_prefs/user_prefs.h" | 75 #include "components/user_prefs/user_prefs.h" |
| 75 #include "content/public/browser/child_process_security_policy.h" | 76 #include "content/public/browser/child_process_security_policy.h" |
| 76 #include "content/public/browser/download_manager.h" | 77 #include "content/public/browser/download_manager.h" |
| 77 #include "content/public/browser/download_save_info.h" | 78 #include "content/public/browser/download_save_info.h" |
| 78 #include "content/public/browser/download_url_parameters.h" | 79 #include "content/public/browser/download_url_parameters.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 {57, IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE}, | 216 {57, IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE}, |
| 216 {58, IDC_SPELLCHECK_SUGGESTION_0}, | 217 {58, IDC_SPELLCHECK_SUGGESTION_0}, |
| 217 {59, IDC_SPELLCHECK_ADD_TO_DICTIONARY}, | 218 {59, IDC_SPELLCHECK_ADD_TO_DICTIONARY}, |
| 218 {60, IDC_SPELLPANEL_TOGGLE}, | 219 {60, IDC_SPELLPANEL_TOGGLE}, |
| 219 {61, IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB}, | 220 {61, IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB}, |
| 220 {62, IDC_WRITING_DIRECTION_MENU}, | 221 {62, IDC_WRITING_DIRECTION_MENU}, |
| 221 {63, IDC_WRITING_DIRECTION_DEFAULT}, | 222 {63, IDC_WRITING_DIRECTION_DEFAULT}, |
| 222 {64, IDC_WRITING_DIRECTION_LTR}, | 223 {64, IDC_WRITING_DIRECTION_LTR}, |
| 223 {65, IDC_WRITING_DIRECTION_RTL}, | 224 {65, IDC_WRITING_DIRECTION_RTL}, |
| 224 {66, IDC_CONTENT_CONTEXT_SHOW_ORIGINAL_IMAGE}, | 225 {66, IDC_CONTENT_CONTEXT_SHOW_ORIGINAL_IMAGE}, |
| 226 {67, IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD}, |
| 225 // Add new items here and use |enum_id| from the next line. | 227 // Add new items here and use |enum_id| from the next line. |
| 226 // Also, add new items to RenderViewContextMenuItem enum in histograms.xml. | 228 // Also, add new items to RenderViewContextMenuItem enum in histograms.xml. |
| 227 {67, 0}, // Must be the last. Increment |enum_id| when new IDC was added. | 229 {68, 0}, // Must be the last. Increment |enum_id| when new IDC was added. |
| 228 }; | 230 }; |
| 229 | 231 |
| 230 // Collapses large ranges of ids before looking for UMA enum. | 232 // Collapses large ranges of ids before looking for UMA enum. |
| 231 int CollapseCommandsForUMA(int id) { | 233 int CollapseCommandsForUMA(int id) { |
| 232 DCHECK(!RenderViewContextMenu::IsContentCustomCommandId(id)); | 234 DCHECK(!RenderViewContextMenu::IsContentCustomCommandId(id)); |
| 233 DCHECK(!ContextMenuMatcher::IsExtensionsCustomCommandId(id)); | 235 DCHECK(!ContextMenuMatcher::IsExtensionsCustomCommandId(id)); |
| 234 | 236 |
| 235 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && | 237 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && |
| 236 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { | 238 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { |
| 237 return IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST; | 239 return IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST; |
| (...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 | 624 |
| 623 if (content_type_->SupportsGroup( | 625 if (content_type_->SupportsGroup( |
| 624 ContextMenuContentType::ITEM_GROUP_DEVTOOLS_UNPACKED_EXT)) { | 626 ContextMenuContentType::ITEM_GROUP_DEVTOOLS_UNPACKED_EXT)) { |
| 625 AppendDevtoolsForUnpackedExtensions(); | 627 AppendDevtoolsForUnpackedExtensions(); |
| 626 } | 628 } |
| 627 | 629 |
| 628 if (content_type_->SupportsGroup( | 630 if (content_type_->SupportsGroup( |
| 629 ContextMenuContentType::ITEM_GROUP_PRINT_PREVIEW)) { | 631 ContextMenuContentType::ITEM_GROUP_PRINT_PREVIEW)) { |
| 630 AppendPrintPreviewItems(); | 632 AppendPrintPreviewItems(); |
| 631 } | 633 } |
| 634 |
| 635 if (content_type_->SupportsGroup( |
| 636 ContextMenuContentType::ITEM_GROUP_PASSWORD)) { |
| 637 AppendPasswordItems(); |
| 638 } |
| 632 } | 639 } |
| 633 | 640 |
| 634 Profile* RenderViewContextMenu::GetProfile() { | 641 Profile* RenderViewContextMenu::GetProfile() { |
| 635 return Profile::FromBrowserContext(browser_context_); | 642 return Profile::FromBrowserContext(browser_context_); |
| 636 } | 643 } |
| 637 | 644 |
| 638 void RenderViewContextMenu::RecordUsedItem(int id) { | 645 void RenderViewContextMenu::RecordUsedItem(int id) { |
| 639 int enum_id = FindUMAEnumValueForCommand(id); | 646 int enum_id = FindUMAEnumValueForCommand(id); |
| 640 if (enum_id != -1) { | 647 if (enum_id != -1) { |
| 641 const size_t kMappingSize = arraysize(kUmaEnumToControlId); | 648 const size_t kMappingSize = arraysize(kUmaEnumToControlId); |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1031 protocol_handler_submenu_model_.AddItem( | 1038 protocol_handler_submenu_model_.AddItem( |
| 1032 IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS, | 1039 IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS, |
| 1033 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_OPENLINKWITH_CONFIGURE)); | 1040 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_OPENLINKWITH_CONFIGURE)); |
| 1034 | 1041 |
| 1035 menu_model_.AddSubMenu( | 1042 menu_model_.AddSubMenu( |
| 1036 IDC_CONTENT_CONTEXT_OPENLINKWITH, | 1043 IDC_CONTENT_CONTEXT_OPENLINKWITH, |
| 1037 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_OPENLINKWITH), | 1044 l10n_util::GetStringUTF16(IDS_CONTENT_CONTEXT_OPENLINKWITH), |
| 1038 &protocol_handler_submenu_model_); | 1045 &protocol_handler_submenu_model_); |
| 1039 } | 1046 } |
| 1040 | 1047 |
| 1048 void RenderViewContextMenu::AppendPasswordItems() { |
| 1049 if (!password_manager::ForceSavingExperimentEnabled()) |
| 1050 return; |
| 1051 |
| 1052 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); |
| 1053 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD, |
| 1054 IDS_CONTENT_CONTEXT_FORCESAVEPASSWORD); |
| 1055 } |
| 1056 |
| 1041 // Menu delegate functions ----------------------------------------------------- | 1057 // Menu delegate functions ----------------------------------------------------- |
| 1042 | 1058 |
| 1043 bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { | 1059 bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { |
| 1044 { | 1060 { |
| 1045 bool enabled = false; | 1061 bool enabled = false; |
| 1046 if (RenderViewContextMenuBase::IsCommandIdKnown(id, &enabled)) | 1062 if (RenderViewContextMenuBase::IsCommandIdKnown(id, &enabled)) |
| 1047 return enabled; | 1063 return enabled; |
| 1048 } | 1064 } |
| 1049 | 1065 |
| 1050 CoreTabHelper* core_tab_helper = | 1066 CoreTabHelper* core_tab_helper = |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1333 | 1349 |
| 1334 case IDC_SPELLCHECK_MENU: | 1350 case IDC_SPELLCHECK_MENU: |
| 1335 return true; | 1351 return true; |
| 1336 | 1352 |
| 1337 case IDC_CONTENT_CONTEXT_OPENLINKWITH: | 1353 case IDC_CONTENT_CONTEXT_OPENLINKWITH: |
| 1338 return true; | 1354 return true; |
| 1339 | 1355 |
| 1340 case IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS: | 1356 case IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS: |
| 1341 return true; | 1357 return true; |
| 1342 | 1358 |
| 1359 case IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD: |
| 1360 return true; |
| 1361 |
| 1343 default: | 1362 default: |
| 1344 NOTREACHED(); | 1363 NOTREACHED(); |
| 1345 return false; | 1364 return false; |
| 1346 } | 1365 } |
| 1347 } | 1366 } |
| 1348 | 1367 |
| 1349 bool RenderViewContextMenu::IsCommandIdChecked(int id) const { | 1368 bool RenderViewContextMenu::IsCommandIdChecked(int id) const { |
| 1350 if (RenderViewContextMenuBase::IsCommandIdChecked(id)) | 1369 if (RenderViewContextMenuBase::IsCommandIdChecked(id)) |
| 1351 return true; | 1370 return true; |
| 1352 | 1371 |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1773 data.SetURL(params_.keyword_url.spec()); | 1792 data.SetURL(params_.keyword_url.spec()); |
| 1774 data.favicon_url = | 1793 data.favicon_url = |
| 1775 TemplateURL::GenerateFaviconURL(params_.page_url.GetOrigin()); | 1794 TemplateURL::GenerateFaviconURL(params_.page_url.GetOrigin()); |
| 1776 // Takes ownership of the TemplateURL. | 1795 // Takes ownership of the TemplateURL. |
| 1777 search_engine_tab_helper->delegate()->ConfirmAddSearchProvider( | 1796 search_engine_tab_helper->delegate()->ConfirmAddSearchProvider( |
| 1778 new TemplateURL(data), GetProfile()); | 1797 new TemplateURL(data), GetProfile()); |
| 1779 } | 1798 } |
| 1780 break; | 1799 break; |
| 1781 } | 1800 } |
| 1782 | 1801 |
| 1802 case IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD: |
| 1803 // TODO(msramek): Force-save the password. |
| 1804 break; |
| 1805 |
| 1783 default: | 1806 default: |
| 1784 NOTREACHED(); | 1807 NOTREACHED(); |
| 1785 break; | 1808 break; |
| 1786 } | 1809 } |
| 1787 } | 1810 } |
| 1788 | 1811 |
| 1789 ProtocolHandlerRegistry::ProtocolHandlerList | 1812 ProtocolHandlerRegistry::ProtocolHandlerList |
| 1790 RenderViewContextMenu::GetHandlersForLinkUrl() { | 1813 RenderViewContextMenu::GetHandlersForLinkUrl() { |
| 1791 ProtocolHandlerRegistry::ProtocolHandlerList handlers = | 1814 ProtocolHandlerRegistry::ProtocolHandlerList handlers = |
| 1792 protocol_handler_registry_->GetHandlersFor(params_.link_url.scheme()); | 1815 protocol_handler_registry_->GetHandlersFor(params_.link_url.scheme()); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1885 source_web_contents_->GetRenderViewHost()-> | 1908 source_web_contents_->GetRenderViewHost()-> |
| 1886 ExecuteMediaPlayerActionAtLocation(location, action); | 1909 ExecuteMediaPlayerActionAtLocation(location, action); |
| 1887 } | 1910 } |
| 1888 | 1911 |
| 1889 void RenderViewContextMenu::PluginActionAt( | 1912 void RenderViewContextMenu::PluginActionAt( |
| 1890 const gfx::Point& location, | 1913 const gfx::Point& location, |
| 1891 const WebPluginAction& action) { | 1914 const WebPluginAction& action) { |
| 1892 source_web_contents_->GetRenderViewHost()-> | 1915 source_web_contents_->GetRenderViewHost()-> |
| 1893 ExecutePluginActionAtLocation(location, action); | 1916 ExecutePluginActionAtLocation(location, action); |
| 1894 } | 1917 } |
| OLD | NEW |