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 13 matching lines...) Expand all Loading... | |
| 24 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 24 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| 25 #include "chrome/browser/browser_process.h" | 25 #include "chrome/browser/browser_process.h" |
| 26 #include "chrome/browser/chrome_notification_types.h" | 26 #include "chrome/browser/chrome_notification_types.h" |
| 27 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" | 27 #include "chrome/browser/custom_handlers/protocol_handler_registry_factory.h" |
| 28 #include "chrome/browser/devtools/devtools_window.h" | 28 #include "chrome/browser/devtools/devtools_window.h" |
| 29 #include "chrome/browser/download/download_service.h" | 29 #include "chrome/browser/download/download_service.h" |
| 30 #include "chrome/browser/download/download_service_factory.h" | 30 #include "chrome/browser/download/download_service_factory.h" |
| 31 #include "chrome/browser/download/download_stats.h" | 31 #include "chrome/browser/download/download_stats.h" |
| 32 #include "chrome/browser/extensions/devtools_util.h" | 32 #include "chrome/browser/extensions/devtools_util.h" |
| 33 #include "chrome/browser/extensions/extension_service.h" | 33 #include "chrome/browser/extensions/extension_service.h" |
| 34 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings.h" | |
| 35 #include "chrome/browser/net/spdyproxy/data_reduction_proxy_chrome_settings_fact ory.h" | |
| 34 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" | 36 #include "chrome/browser/plugins/chrome_plugin_service_filter.h" |
| 35 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 37 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 36 #include "chrome/browser/profiles/profile.h" | 38 #include "chrome/browser/profiles/profile.h" |
| 37 #include "chrome/browser/profiles/profile_io_data.h" | 39 #include "chrome/browser/profiles/profile_io_data.h" |
| 38 #include "chrome/browser/renderer_context_menu/context_menu_content_type_factory .h" | 40 #include "chrome/browser/renderer_context_menu/context_menu_content_type_factory .h" |
| 39 #include "chrome/browser/renderer_context_menu/spellchecker_submenu_observer.h" | 41 #include "chrome/browser/renderer_context_menu/spellchecker_submenu_observer.h" |
| 40 #include "chrome/browser/renderer_context_menu/spelling_menu_observer.h" | 42 #include "chrome/browser/renderer_context_menu/spelling_menu_observer.h" |
| 41 #include "chrome/browser/search/search.h" | 43 #include "chrome/browser/search/search.h" |
| 42 #include "chrome/browser/search_engines/template_url_service_factory.h" | 44 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 43 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" | 45 #include "chrome/browser/spellchecker/spellcheck_host_metrics.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 202 {48, IDC_CONTENT_CONTEXT_ADDSEARCHENGINE}, | 204 {48, IDC_CONTENT_CONTEXT_ADDSEARCHENGINE}, |
| 203 {52, IDC_CONTENT_CONTEXT_OPENLINKWITH}, | 205 {52, IDC_CONTENT_CONTEXT_OPENLINKWITH}, |
| 204 {53, IDC_CHECK_SPELLING_WHILE_TYPING}, | 206 {53, IDC_CHECK_SPELLING_WHILE_TYPING}, |
| 205 {54, IDC_SPELLCHECK_MENU}, | 207 {54, IDC_SPELLCHECK_MENU}, |
| 206 {55, IDC_CONTENT_CONTEXT_SPELLING_TOGGLE}, | 208 {55, IDC_CONTENT_CONTEXT_SPELLING_TOGGLE}, |
| 207 {56, IDC_SPELLCHECK_LANGUAGES_FIRST}, | 209 {56, IDC_SPELLCHECK_LANGUAGES_FIRST}, |
| 208 {57, IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE}, | 210 {57, IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE}, |
| 209 {58, IDC_SPELLCHECK_SUGGESTION_0}, | 211 {58, IDC_SPELLCHECK_SUGGESTION_0}, |
| 210 {59, IDC_SPELLCHECK_ADD_TO_DICTIONARY}, | 212 {59, IDC_SPELLCHECK_ADD_TO_DICTIONARY}, |
| 211 {60, IDC_SPELLPANEL_TOGGLE}, | 213 {60, IDC_SPELLPANEL_TOGGLE}, |
| 214 {61, IDC_CONTENT_CONTEXT_OPENORIGINALIMAGENEWTAB}, | |
| 212 // Add new items here and use |enum_id| from the next line. | 215 // Add new items here and use |enum_id| from the next line. |
| 213 {61, 0}, // Must be the last. Increment |enum_id| when new IDC was added. | 216 {62, 0}, // Must be the last. Increment |enum_id| when new IDC was added. |
| 214 }; | 217 }; |
| 215 | 218 |
| 216 // Collapses large ranges of ids before looking for UMA enum. | 219 // Collapses large ranges of ids before looking for UMA enum. |
| 217 int CollapseCommandsForUMA(int id) { | 220 int CollapseCommandsForUMA(int id) { |
| 218 DCHECK(!RenderViewContextMenu::IsContentCustomCommandId(id)); | 221 DCHECK(!RenderViewContextMenu::IsContentCustomCommandId(id)); |
| 219 DCHECK(!ContextMenuMatcher::IsExtensionsCustomCommandId(id)); | 222 DCHECK(!ContextMenuMatcher::IsExtensionsCustomCommandId(id)); |
| 220 | 223 |
| 221 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && | 224 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && |
| 222 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { | 225 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { |
| 223 return IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST; | 226 return IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST; |
| (...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 685 IDS_CONTENT_CONTEXT_COPYLINKLOCATION); | 688 IDS_CONTENT_CONTEXT_COPYLINKLOCATION); |
| 686 } | 689 } |
| 687 | 690 |
| 688 void RenderViewContextMenu::AppendImageItems() { | 691 void RenderViewContextMenu::AppendImageItems() { |
| 689 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEIMAGEAS, | 692 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEIMAGEAS, |
| 690 IDS_CONTENT_CONTEXT_SAVEIMAGEAS); | 693 IDS_CONTENT_CONTEXT_SAVEIMAGEAS); |
| 691 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYIMAGELOCATION, | 694 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYIMAGELOCATION, |
| 692 IDS_CONTENT_CONTEXT_COPYIMAGELOCATION); | 695 IDS_CONTENT_CONTEXT_COPYIMAGELOCATION); |
| 693 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYIMAGE, | 696 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYIMAGE, |
| 694 IDS_CONTENT_CONTEXT_COPYIMAGE); | 697 IDS_CONTENT_CONTEXT_COPYIMAGE); |
| 695 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB, | 698 if (!browser_context_->IsOffTheRecord() && |
| 696 IDS_CONTENT_CONTEXT_OPENIMAGENEWTAB); | 699 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 700 browser_context_)->CanUseDataReductionProxy( | |
| 701 params_.src_url)) { | |
| 702 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENORIGINALIMAGENEWTAB, | |
| 703 IDS_CONTENT_CONTEXT_OPENORIGINALIMAGENEWTAB); | |
| 704 } else { | |
| 705 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB, | |
| 706 IDS_CONTENT_CONTEXT_OPENIMAGENEWTAB); | |
| 707 } | |
| 697 } | 708 } |
| 698 | 709 |
| 699 void RenderViewContextMenu::AppendSearchWebForImageItems() { | 710 void RenderViewContextMenu::AppendSearchWebForImageItems() { |
| 700 TemplateURLService* service = | 711 TemplateURLService* service = |
| 701 TemplateURLServiceFactory::GetForProfile(GetProfile()); | 712 TemplateURLServiceFactory::GetForProfile(GetProfile()); |
| 702 const TemplateURL* const default_provider = | 713 const TemplateURL* const default_provider = |
| 703 service->GetDefaultSearchProvider(); | 714 service->GetDefaultSearchProvider(); |
| 704 if (params_.has_image_contents && default_provider && | 715 if (params_.has_image_contents && default_provider && |
| 705 !default_provider->image_url().empty() && | 716 !default_provider->image_url().empty() && |
| 706 default_provider->image_url_ref().IsValid(service->search_terms_data())) { | 717 default_provider->image_url_ref().IsValid(service->search_terms_data())) { |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1095 DCHECK(local_state); | 1106 DCHECK(local_state); |
| 1096 // Test if file-selection dialogs are forbidden by policy. | 1107 // Test if file-selection dialogs are forbidden by policy. |
| 1097 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs)) | 1108 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs)) |
| 1098 return false; | 1109 return false; |
| 1099 | 1110 |
| 1100 return params_.has_image_contents; | 1111 return params_.has_image_contents; |
| 1101 } | 1112 } |
| 1102 | 1113 |
| 1103 // The images shown in the most visited thumbnails can't be opened or | 1114 // The images shown in the most visited thumbnails can't be opened or |
| 1104 // searched for conventionally. | 1115 // searched for conventionally. |
| 1116 case IDC_CONTENT_CONTEXT_OPENORIGINALIMAGENEWTAB: | |
| 1105 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB: | 1117 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB: |
| 1106 case IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE: | 1118 case IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE: |
| 1107 return params_.src_url.is_valid() && | 1119 return params_.src_url.is_valid() && |
| 1108 (params_.src_url.scheme() != content::kChromeUIScheme); | 1120 (params_.src_url.scheme() != content::kChromeUIScheme); |
| 1109 | 1121 |
| 1110 case IDC_CONTENT_CONTEXT_COPYIMAGE: | 1122 case IDC_CONTENT_CONTEXT_COPYIMAGE: |
| 1111 return params_.has_image_contents; | 1123 return params_.has_image_contents; |
| 1112 | 1124 |
| 1113 // Media control commands should all be disabled if the player is in an | 1125 // Media control commands should all be disabled if the player is in an |
| 1114 // error state. | 1126 // error state. |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1393 break; | 1405 break; |
| 1394 | 1406 |
| 1395 case IDC_CONTENT_CONTEXT_COPYIMAGE: | 1407 case IDC_CONTENT_CONTEXT_COPYIMAGE: |
| 1396 CopyImageAt(params_.x, params_.y); | 1408 CopyImageAt(params_.x, params_.y); |
| 1397 break; | 1409 break; |
| 1398 | 1410 |
| 1399 case IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE: | 1411 case IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE: |
| 1400 GetImageThumbnailForSearch(); | 1412 GetImageThumbnailForSearch(); |
| 1401 break; | 1413 break; |
| 1402 | 1414 |
| 1415 case IDC_CONTENT_CONTEXT_OPENORIGINALIMAGENEWTAB: | |
| 1416 OpenURL(params_.src_url, | |
| 1417 GetDocumentURL(params_), | |
| 1418 NEW_BACKGROUND_TAB, | |
| 1419 ui::PAGE_TRANSITION_LINK, | |
| 1420 "X-PSA-Client-Options: v=1,m=1\nCache-Control: no-cache"); | |
|
Alexei Svitkine (slow)
2015/02/20 18:37:27
Hardcoding this string in context menu code is bad
Not at Google. Contact bengr
2015/02/21 00:11:16
Moved the string to drp_settings. The OpenUrl(..)
| |
| 1421 break; | |
| 1422 | |
| 1403 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB: | 1423 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB: |
| 1404 case IDC_CONTENT_CONTEXT_OPENAVNEWTAB: | 1424 case IDC_CONTENT_CONTEXT_OPENAVNEWTAB: |
| 1405 OpenURL(params_.src_url, | 1425 OpenURL(params_.src_url, |
| 1406 GetDocumentURL(params_), | 1426 GetDocumentURL(params_), |
| 1407 NEW_BACKGROUND_TAB, | 1427 NEW_BACKGROUND_TAB, |
| 1408 ui::PAGE_TRANSITION_LINK); | 1428 ui::PAGE_TRANSITION_LINK); |
| 1409 break; | 1429 break; |
| 1410 | 1430 |
| 1411 case IDC_CONTENT_CONTEXT_PLAYPAUSE: { | 1431 case IDC_CONTENT_CONTEXT_PLAYPAUSE: { |
| 1412 bool play = !!(params_.media_flags & WebContextMenuData::MediaPaused); | 1432 bool play = !!(params_.media_flags & WebContextMenuData::MediaPaused); |
| (...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1785 source_web_contents_->GetRenderViewHost()-> | 1805 source_web_contents_->GetRenderViewHost()-> |
| 1786 ExecuteMediaPlayerActionAtLocation(location, action); | 1806 ExecuteMediaPlayerActionAtLocation(location, action); |
| 1787 } | 1807 } |
| 1788 | 1808 |
| 1789 void RenderViewContextMenu::PluginActionAt( | 1809 void RenderViewContextMenu::PluginActionAt( |
| 1790 const gfx::Point& location, | 1810 const gfx::Point& location, |
| 1791 const WebPluginAction& action) { | 1811 const WebPluginAction& action) { |
| 1792 source_web_contents_->GetRenderViewHost()-> | 1812 source_web_contents_->GetRenderViewHost()-> |
| 1793 ExecutePluginActionAtLocation(location, action); | 1813 ExecutePluginActionAtLocation(location, action); |
| 1794 } | 1814 } |
| OLD | NEW |