| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 55 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
| 56 #include "chrome/common/chrome_constants.h" | 56 #include "chrome/common/chrome_constants.h" |
| 57 #include "chrome/common/chrome_switches.h" | 57 #include "chrome/common/chrome_switches.h" |
| 58 #include "chrome/common/content_restriction.h" | 58 #include "chrome/common/content_restriction.h" |
| 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/google/core/browser/google_util.h" | 66 #include "components/google/core/browser/google_util.h" |
| 66 #include "components/metrics/proto/omnibox_input_type.pb.h" | 67 #include "components/metrics/proto/omnibox_input_type.pb.h" |
| 67 #include "components/omnibox/autocomplete_match.h" | 68 #include "components/omnibox/autocomplete_match.h" |
| 68 #include "components/search_engines/template_url.h" | 69 #include "components/search_engines/template_url.h" |
| 69 #include "components/search_engines/template_url_service.h" | 70 #include "components/search_engines/template_url_service.h" |
| 70 #include "components/translate/core/browser/translate_download_manager.h" | 71 #include "components/translate/core/browser/translate_download_manager.h" |
| 71 #include "components/translate/core/browser/translate_manager.h" | 72 #include "components/translate/core/browser/translate_manager.h" |
| 72 #include "components/translate/core/browser/translate_prefs.h" | 73 #include "components/translate/core/browser/translate_prefs.h" |
| 73 #include "components/user_prefs/user_prefs.h" | 74 #include "components/user_prefs/user_prefs.h" |
| 74 #include "content/public/browser/child_process_security_policy.h" | 75 #include "content/public/browser/child_process_security_policy.h" |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 {56, IDC_SPELLCHECK_LANGUAGES_FIRST}, | 214 {56, IDC_SPELLCHECK_LANGUAGES_FIRST}, |
| 214 {57, IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE}, | 215 {57, IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE}, |
| 215 {58, IDC_SPELLCHECK_SUGGESTION_0}, | 216 {58, IDC_SPELLCHECK_SUGGESTION_0}, |
| 216 {59, IDC_SPELLCHECK_ADD_TO_DICTIONARY}, | 217 {59, IDC_SPELLCHECK_ADD_TO_DICTIONARY}, |
| 217 {60, IDC_SPELLPANEL_TOGGLE}, | 218 {60, IDC_SPELLPANEL_TOGGLE}, |
| 218 {61, IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB}, | 219 {61, IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB}, |
| 219 {62, IDC_WRITING_DIRECTION_MENU}, | 220 {62, IDC_WRITING_DIRECTION_MENU}, |
| 220 {63, IDC_WRITING_DIRECTION_DEFAULT}, | 221 {63, IDC_WRITING_DIRECTION_DEFAULT}, |
| 221 {64, IDC_WRITING_DIRECTION_LTR}, | 222 {64, IDC_WRITING_DIRECTION_LTR}, |
| 222 {65, IDC_WRITING_DIRECTION_RTL}, | 223 {65, IDC_WRITING_DIRECTION_RTL}, |
| 224 {66, IDC_CONTENT_CONTEXT_RELOAD_ORIGINAL_IMAGE}, |
| 223 // Add new items here and use |enum_id| from the next line. | 225 // Add new items here and use |enum_id| from the next line. |
| 224 {66, 0}, // Must be the last. Increment |enum_id| when new IDC was added. | 226 // 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. |
| 225 }; | 228 }; |
| 226 | 229 |
| 227 // Collapses large ranges of ids before looking for UMA enum. | 230 // Collapses large ranges of ids before looking for UMA enum. |
| 228 int CollapseCommandsForUMA(int id) { | 231 int CollapseCommandsForUMA(int id) { |
| 229 DCHECK(!RenderViewContextMenu::IsContentCustomCommandId(id)); | 232 DCHECK(!RenderViewContextMenu::IsContentCustomCommandId(id)); |
| 230 DCHECK(!ContextMenuMatcher::IsExtensionsCustomCommandId(id)); | 233 DCHECK(!ContextMenuMatcher::IsExtensionsCustomCommandId(id)); |
| 231 | 234 |
| 232 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && | 235 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && |
| 233 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { | 236 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { |
| 234 return IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST; | 237 return IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST; |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 IDS_CONTENT_CONTEXT_COPYLINKLOCATION); | 737 IDS_CONTENT_CONTEXT_COPYLINKLOCATION); |
| 735 } | 738 } |
| 736 | 739 |
| 737 void RenderViewContextMenu::AppendImageItems() { | 740 void RenderViewContextMenu::AppendImageItems() { |
| 738 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEIMAGEAS, | 741 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEIMAGEAS, |
| 739 IDS_CONTENT_CONTEXT_SAVEIMAGEAS); | 742 IDS_CONTENT_CONTEXT_SAVEIMAGEAS); |
| 740 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYIMAGELOCATION, | 743 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYIMAGELOCATION, |
| 741 IDS_CONTENT_CONTEXT_COPYIMAGELOCATION); | 744 IDS_CONTENT_CONTEXT_COPYIMAGELOCATION); |
| 742 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYIMAGE, | 745 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYIMAGE, |
| 743 IDS_CONTENT_CONTEXT_COPYIMAGE); | 746 IDS_CONTENT_CONTEXT_COPYIMAGE); |
| 747 std::map<std::string, std::string>::const_iterator it = |
| 748 params_.properties.find(data_reduction_proxy::kChromeProxyHeader); |
| 749 if (it != params_.properties.end() && it->second == |
| 750 data_reduction_proxy::kChromeProxyLoFiDirective) { |
| 751 menu_model_.AddItemWithStringId( |
| 752 IDC_CONTENT_CONTEXT_RELOAD_ORIGINAL_IMAGE, |
| 753 IDS_CONTENT_CONTEXT_RELOAD_ORIGINAL_IMAGE); |
| 754 } |
| 744 DataReductionProxyChromeSettings* settings = | 755 DataReductionProxyChromeSettings* settings = |
| 745 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( | 756 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( |
| 746 browser_context_); | 757 browser_context_); |
| 747 if (settings && settings->CanUseDataReductionProxy(params_.src_url)) { | 758 if (settings && settings->CanUseDataReductionProxy(params_.src_url)) { |
| 748 menu_model_.AddItemWithStringId( | 759 menu_model_.AddItemWithStringId( |
| 749 IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB, | 760 IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB, |
| 750 IDS_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB); | 761 IDS_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB); |
| 751 } else { | 762 } else { |
| 752 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB, | 763 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB, |
| 753 IDS_CONTENT_CONTEXT_OPENIMAGENEWTAB); | 764 IDS_CONTENT_CONTEXT_OPENIMAGENEWTAB); |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 // Test if file-selection dialogs are forbidden by policy. | 1165 // Test if file-selection dialogs are forbidden by policy. |
| 1155 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs)) | 1166 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs)) |
| 1156 return false; | 1167 return false; |
| 1157 | 1168 |
| 1158 return params_.has_image_contents; | 1169 return params_.has_image_contents; |
| 1159 } | 1170 } |
| 1160 | 1171 |
| 1161 // The images shown in the most visited thumbnails can't be opened or | 1172 // The images shown in the most visited thumbnails can't be opened or |
| 1162 // searched for conventionally. | 1173 // searched for conventionally. |
| 1163 case IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB: | 1174 case IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB: |
| 1175 case IDC_CONTENT_CONTEXT_RELOAD_ORIGINAL_IMAGE: |
| 1164 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB: | 1176 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB: |
| 1165 case IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE: | 1177 case IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE: |
| 1166 return params_.src_url.is_valid() && | 1178 return params_.src_url.is_valid() && |
| 1167 (params_.src_url.scheme() != content::kChromeUIScheme); | 1179 (params_.src_url.scheme() != content::kChromeUIScheme); |
| 1168 | 1180 |
| 1169 case IDC_CONTENT_CONTEXT_COPYIMAGE: | 1181 case IDC_CONTENT_CONTEXT_COPYIMAGE: |
| 1170 return params_.has_image_contents; | 1182 return params_.has_image_contents; |
| 1171 | 1183 |
| 1172 // Media control commands should all be disabled if the player is in an | 1184 // Media control commands should all be disabled if the player is in an |
| 1173 // error state. | 1185 // error state. |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1469 GetImageThumbnailForSearch(); | 1481 GetImageThumbnailForSearch(); |
| 1470 break; | 1482 break; |
| 1471 | 1483 |
| 1472 case IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB: | 1484 case IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB: |
| 1473 OpenURLWithExtraHeaders( | 1485 OpenURLWithExtraHeaders( |
| 1474 params_.src_url, GetDocumentURL(params_), NEW_BACKGROUND_TAB, | 1486 params_.src_url, GetDocumentURL(params_), NEW_BACKGROUND_TAB, |
| 1475 ui::PAGE_TRANSITION_LINK, | 1487 ui::PAGE_TRANSITION_LINK, |
| 1476 data_reduction_proxy::kDataReductionPassThroughHeader); | 1488 data_reduction_proxy::kDataReductionPassThroughHeader); |
| 1477 break; | 1489 break; |
| 1478 | 1490 |
| 1491 case IDC_CONTENT_CONTEXT_RELOAD_ORIGINAL_IMAGE: |
| 1492 ReloadOriginalImage(); |
| 1493 break; |
| 1494 |
| 1479 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB: | 1495 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB: |
| 1480 case IDC_CONTENT_CONTEXT_OPENAVNEWTAB: | 1496 case IDC_CONTENT_CONTEXT_OPENAVNEWTAB: |
| 1481 OpenURL(params_.src_url, | 1497 OpenURL(params_.src_url, |
| 1482 GetDocumentURL(params_), | 1498 GetDocumentURL(params_), |
| 1483 NEW_BACKGROUND_TAB, | 1499 NEW_BACKGROUND_TAB, |
| 1484 ui::PAGE_TRANSITION_LINK); | 1500 ui::PAGE_TRANSITION_LINK); |
| 1485 break; | 1501 break; |
| 1486 | 1502 |
| 1487 case IDC_CONTENT_CONTEXT_PLAYPAUSE: { | 1503 case IDC_CONTENT_CONTEXT_PLAYPAUSE: { |
| 1488 bool play = !!(params_.media_flags & WebContextMenuData::MediaPaused); | 1504 bool play = !!(params_.media_flags & WebContextMenuData::MediaPaused); |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1823 kMaxSelectionTextLength, | 1839 kMaxSelectionTextLength, |
| 1824 gfx::WORD_BREAK); | 1840 gfx::WORD_BREAK); |
| 1825 } | 1841 } |
| 1826 | 1842 |
| 1827 // Controller functions -------------------------------------------------------- | 1843 // Controller functions -------------------------------------------------------- |
| 1828 | 1844 |
| 1829 void RenderViewContextMenu::CopyImageAt(int x, int y) { | 1845 void RenderViewContextMenu::CopyImageAt(int x, int y) { |
| 1830 source_web_contents_->GetRenderViewHost()->CopyImageAt(x, y); | 1846 source_web_contents_->GetRenderViewHost()->CopyImageAt(x, y); |
| 1831 } | 1847 } |
| 1832 | 1848 |
| 1849 void RenderViewContextMenu::ReloadOriginalImage() { |
| 1850 RenderFrameHost* render_frame_host = GetRenderFrameHost(); |
| 1851 if (!render_frame_host) |
| 1852 return; |
| 1853 render_frame_host->Send(new ChromeViewMsg_RequestReloadImageForContextNode( |
| 1854 render_frame_host->GetRoutingID())); |
| 1855 } |
| 1856 |
| 1833 void RenderViewContextMenu::GetImageThumbnailForSearch() { | 1857 void RenderViewContextMenu::GetImageThumbnailForSearch() { |
| 1834 RenderFrameHost* render_frame_host = GetRenderFrameHost(); | 1858 RenderFrameHost* render_frame_host = GetRenderFrameHost(); |
| 1835 if (!render_frame_host) | 1859 if (!render_frame_host) |
| 1836 return; | 1860 return; |
| 1837 render_frame_host->Send(new ChromeViewMsg_RequestThumbnailForContextNode( | 1861 render_frame_host->Send(new ChromeViewMsg_RequestThumbnailForContextNode( |
| 1838 render_frame_host->GetRoutingID(), | 1862 render_frame_host->GetRoutingID(), |
| 1839 kImageSearchThumbnailMinSize, | 1863 kImageSearchThumbnailMinSize, |
| 1840 gfx::Size(kImageSearchThumbnailMaxWidth, | 1864 gfx::Size(kImageSearchThumbnailMaxWidth, |
| 1841 kImageSearchThumbnailMaxHeight))); | 1865 kImageSearchThumbnailMaxHeight))); |
| 1842 } | 1866 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1861 source_web_contents_->GetRenderViewHost()-> | 1885 source_web_contents_->GetRenderViewHost()-> |
| 1862 ExecuteMediaPlayerActionAtLocation(location, action); | 1886 ExecuteMediaPlayerActionAtLocation(location, action); |
| 1863 } | 1887 } |
| 1864 | 1888 |
| 1865 void RenderViewContextMenu::PluginActionAt( | 1889 void RenderViewContextMenu::PluginActionAt( |
| 1866 const gfx::Point& location, | 1890 const gfx::Point& location, |
| 1867 const WebPluginAction& action) { | 1891 const WebPluginAction& action) { |
| 1868 source_web_contents_->GetRenderViewHost()-> | 1892 source_web_contents_->GetRenderViewHost()-> |
| 1869 ExecutePluginActionAtLocation(location, action); | 1893 ExecutePluginActionAtLocation(location, action); |
| 1870 } | 1894 } |
| OLD | NEW |