Chromium Code Reviews| 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()) { | |
|
vabr (Chromium)
2015/05/19 09:58:13
nit: To spare indenting, we usually do
if (!experi
msramek
2015/05/19 12:53:11
I thought that this is semantically better, as App
| |
| 1050 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); | |
| 1051 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD, | |
| 1052 IDS_CONTENT_CONTEXT_FORCESAVEPASSWORD); | |
| 1053 } | |
| 1054 } | |
| 1055 | |
| 1041 // Menu delegate functions ----------------------------------------------------- | 1056 // Menu delegate functions ----------------------------------------------------- |
| 1042 | 1057 |
| 1043 bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { | 1058 bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { |
| 1044 { | 1059 { |
| 1045 bool enabled = false; | 1060 bool enabled = false; |
| 1046 if (RenderViewContextMenuBase::IsCommandIdKnown(id, &enabled)) | 1061 if (RenderViewContextMenuBase::IsCommandIdKnown(id, &enabled)) |
| 1047 return enabled; | 1062 return enabled; |
| 1048 } | 1063 } |
| 1049 | 1064 |
| 1050 CoreTabHelper* core_tab_helper = | 1065 CoreTabHelper* core_tab_helper = |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1333 | 1348 |
| 1334 case IDC_SPELLCHECK_MENU: | 1349 case IDC_SPELLCHECK_MENU: |
| 1335 return true; | 1350 return true; |
| 1336 | 1351 |
| 1337 case IDC_CONTENT_CONTEXT_OPENLINKWITH: | 1352 case IDC_CONTENT_CONTEXT_OPENLINKWITH: |
| 1338 return true; | 1353 return true; |
| 1339 | 1354 |
| 1340 case IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS: | 1355 case IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS: |
| 1341 return true; | 1356 return true; |
| 1342 | 1357 |
| 1358 case IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD: | |
| 1359 return true; | |
| 1360 | |
| 1343 default: | 1361 default: |
| 1344 NOTREACHED(); | 1362 NOTREACHED(); |
| 1345 return false; | 1363 return false; |
| 1346 } | 1364 } |
| 1347 } | 1365 } |
| 1348 | 1366 |
| 1349 bool RenderViewContextMenu::IsCommandIdChecked(int id) const { | 1367 bool RenderViewContextMenu::IsCommandIdChecked(int id) const { |
| 1350 if (RenderViewContextMenuBase::IsCommandIdChecked(id)) | 1368 if (RenderViewContextMenuBase::IsCommandIdChecked(id)) |
| 1351 return true; | 1369 return true; |
| 1352 | 1370 |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1773 data.SetURL(params_.keyword_url.spec()); | 1791 data.SetURL(params_.keyword_url.spec()); |
| 1774 data.favicon_url = | 1792 data.favicon_url = |
| 1775 TemplateURL::GenerateFaviconURL(params_.page_url.GetOrigin()); | 1793 TemplateURL::GenerateFaviconURL(params_.page_url.GetOrigin()); |
| 1776 // Takes ownership of the TemplateURL. | 1794 // Takes ownership of the TemplateURL. |
| 1777 search_engine_tab_helper->delegate()->ConfirmAddSearchProvider( | 1795 search_engine_tab_helper->delegate()->ConfirmAddSearchProvider( |
| 1778 new TemplateURL(data), GetProfile()); | 1796 new TemplateURL(data), GetProfile()); |
| 1779 } | 1797 } |
| 1780 break; | 1798 break; |
| 1781 } | 1799 } |
| 1782 | 1800 |
| 1801 case IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD: | |
| 1802 // TODO(msramek): Force-save the password. | |
| 1803 break; | |
| 1804 | |
| 1783 default: | 1805 default: |
| 1784 NOTREACHED(); | 1806 NOTREACHED(); |
| 1785 break; | 1807 break; |
| 1786 } | 1808 } |
| 1787 } | 1809 } |
| 1788 | 1810 |
| 1789 ProtocolHandlerRegistry::ProtocolHandlerList | 1811 ProtocolHandlerRegistry::ProtocolHandlerList |
| 1790 RenderViewContextMenu::GetHandlersForLinkUrl() { | 1812 RenderViewContextMenu::GetHandlersForLinkUrl() { |
| 1791 ProtocolHandlerRegistry::ProtocolHandlerList handlers = | 1813 ProtocolHandlerRegistry::ProtocolHandlerList handlers = |
| 1792 protocol_handler_registry_->GetHandlersFor(params_.link_url.scheme()); | 1814 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()-> | 1907 source_web_contents_->GetRenderViewHost()-> |
| 1886 ExecuteMediaPlayerActionAtLocation(location, action); | 1908 ExecuteMediaPlayerActionAtLocation(location, action); |
| 1887 } | 1909 } |
| 1888 | 1910 |
| 1889 void RenderViewContextMenu::PluginActionAt( | 1911 void RenderViewContextMenu::PluginActionAt( |
| 1890 const gfx::Point& location, | 1912 const gfx::Point& location, |
| 1891 const WebPluginAction& action) { | 1913 const WebPluginAction& action) { |
| 1892 source_web_contents_->GetRenderViewHost()-> | 1914 source_web_contents_->GetRenderViewHost()-> |
| 1893 ExecutePluginActionAtLocation(location, action); | 1915 ExecutePluginActionAtLocation(location, action); |
| 1894 } | 1916 } |
| OLD | NEW |