Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(233)

Side by Side Diff: chrome/browser/renderer_context_menu/render_view_context_menu.cc

Issue 1105263004: "Load image" context menu item to reload a LoFi image. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressing comments Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 {56, IDC_SPELLCHECK_LANGUAGES_FIRST}, 209 {56, IDC_SPELLCHECK_LANGUAGES_FIRST},
210 {57, IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE}, 210 {57, IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE},
211 {58, IDC_SPELLCHECK_SUGGESTION_0}, 211 {58, IDC_SPELLCHECK_SUGGESTION_0},
212 {59, IDC_SPELLCHECK_ADD_TO_DICTIONARY}, 212 {59, IDC_SPELLCHECK_ADD_TO_DICTIONARY},
213 {60, IDC_SPELLPANEL_TOGGLE}, 213 {60, IDC_SPELLPANEL_TOGGLE},
214 {61, IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB}, 214 {61, IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB},
215 {62, IDC_WRITING_DIRECTION_MENU}, 215 {62, IDC_WRITING_DIRECTION_MENU},
216 {63, IDC_WRITING_DIRECTION_DEFAULT}, 216 {63, IDC_WRITING_DIRECTION_DEFAULT},
217 {64, IDC_WRITING_DIRECTION_LTR}, 217 {64, IDC_WRITING_DIRECTION_LTR},
218 {65, IDC_WRITING_DIRECTION_RTL}, 218 {65, IDC_WRITING_DIRECTION_RTL},
219 {66, IDC_CONTENT_CONTEXT_RELOAD_ORIGINAL_IMAGE},
219 // Add new items here and use |enum_id| from the next line. 220 // Add new items here and use |enum_id| from the next line.
220 {66, 0}, // Must be the last. Increment |enum_id| when new IDC was added. 221 // Also, add new items to RenderViewContextMenuItem enum in histograms.xml.
222 {67, 0}, // Must be the last. Increment |enum_id| when new IDC was added.
221 }; 223 };
222 224
223 // Collapses large ranges of ids before looking for UMA enum. 225 // Collapses large ranges of ids before looking for UMA enum.
224 int CollapseCommandsForUMA(int id) { 226 int CollapseCommandsForUMA(int id) {
225 DCHECK(!RenderViewContextMenu::IsContentCustomCommandId(id)); 227 DCHECK(!RenderViewContextMenu::IsContentCustomCommandId(id));
226 DCHECK(!ContextMenuMatcher::IsExtensionsCustomCommandId(id)); 228 DCHECK(!ContextMenuMatcher::IsExtensionsCustomCommandId(id));
227 229
228 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && 230 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST &&
229 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { 231 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) {
230 return IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST; 232 return IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST;
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 IDS_CONTENT_CONTEXT_COPYLINKLOCATION); 693 IDS_CONTENT_CONTEXT_COPYLINKLOCATION);
692 } 694 }
693 695
694 void RenderViewContextMenu::AppendImageItems() { 696 void RenderViewContextMenu::AppendImageItems() {
695 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEIMAGEAS, 697 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_SAVEIMAGEAS,
696 IDS_CONTENT_CONTEXT_SAVEIMAGEAS); 698 IDS_CONTENT_CONTEXT_SAVEIMAGEAS);
697 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYIMAGELOCATION, 699 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYIMAGELOCATION,
698 IDS_CONTENT_CONTEXT_COPYIMAGELOCATION); 700 IDS_CONTENT_CONTEXT_COPYIMAGELOCATION);
699 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYIMAGE, 701 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPYIMAGE,
700 IDS_CONTENT_CONTEXT_COPYIMAGE); 702 IDS_CONTENT_CONTEXT_COPYIMAGE);
703 static const char lo_fi_header_key[] = "Chrome-Proxy";
jam 2015/05/15 06:52:19 ditto
megjablon 2015/05/15 20:31:08 Done.
704 static const char lo_fi_header_value[] = "q=low";
jam 2015/05/15 06:52:19 this should also be a constant shared with the ren
megjablon 2015/05/15 20:31:08 Done.
705 std::map<std::string, std::string>::const_iterator it =
706 params_.properties.find(lo_fi_header_key);
707 if (it != params_.properties.end() && it->second == lo_fi_header_value) {
708 menu_model_.AddItemWithStringId(
709 IDC_CONTENT_CONTEXT_RELOAD_ORIGINAL_IMAGE,
710 IDS_CONTENT_CONTEXT_RELOAD_ORIGINAL_IMAGE);
711 }
701 DataReductionProxyChromeSettings* settings = 712 DataReductionProxyChromeSettings* settings =
702 DataReductionProxyChromeSettingsFactory::GetForBrowserContext( 713 DataReductionProxyChromeSettingsFactory::GetForBrowserContext(
703 browser_context_); 714 browser_context_);
704 if (settings && settings->CanUseDataReductionProxy(params_.src_url)) { 715 if (settings && settings->CanUseDataReductionProxy(params_.src_url)) {
705 menu_model_.AddItemWithStringId( 716 menu_model_.AddItemWithStringId(
706 IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB, 717 IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB,
707 IDS_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB); 718 IDS_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB);
708 } else { 719 } else {
709 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB, 720 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB,
710 IDS_CONTENT_CONTEXT_OPENIMAGENEWTAB); 721 IDS_CONTENT_CONTEXT_OPENIMAGENEWTAB);
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
1111 // Test if file-selection dialogs are forbidden by policy. 1122 // Test if file-selection dialogs are forbidden by policy.
1112 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs)) 1123 if (!local_state->GetBoolean(prefs::kAllowFileSelectionDialogs))
1113 return false; 1124 return false;
1114 1125
1115 return params_.has_image_contents; 1126 return params_.has_image_contents;
1116 } 1127 }
1117 1128
1118 // The images shown in the most visited thumbnails can't be opened or 1129 // The images shown in the most visited thumbnails can't be opened or
1119 // searched for conventionally. 1130 // searched for conventionally.
1120 case IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB: 1131 case IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB:
1132 case IDC_CONTENT_CONTEXT_RELOAD_ORIGINAL_IMAGE:
1121 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB: 1133 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB:
1122 case IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE: 1134 case IDC_CONTENT_CONTEXT_SEARCHWEBFORIMAGE:
1123 return params_.src_url.is_valid() && 1135 return params_.src_url.is_valid() &&
1124 (params_.src_url.scheme() != content::kChromeUIScheme); 1136 (params_.src_url.scheme() != content::kChromeUIScheme);
1125 1137
1126 case IDC_CONTENT_CONTEXT_COPYIMAGE: 1138 case IDC_CONTENT_CONTEXT_COPYIMAGE:
1127 return params_.has_image_contents; 1139 return params_.has_image_contents;
1128 1140
1129 // Media control commands should all be disabled if the player is in an 1141 // Media control commands should all be disabled if the player is in an
1130 // error state. 1142 // error state.
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1426 GetImageThumbnailForSearch(); 1438 GetImageThumbnailForSearch();
1427 break; 1439 break;
1428 1440
1429 case IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB: 1441 case IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB:
1430 OpenURLWithExtraHeaders( 1442 OpenURLWithExtraHeaders(
1431 params_.src_url, GetDocumentURL(params_), NEW_BACKGROUND_TAB, 1443 params_.src_url, GetDocumentURL(params_), NEW_BACKGROUND_TAB,
1432 ui::PAGE_TRANSITION_LINK, 1444 ui::PAGE_TRANSITION_LINK,
1433 data_reduction_proxy::kDataReductionPassThroughHeader); 1445 data_reduction_proxy::kDataReductionPassThroughHeader);
1434 break; 1446 break;
1435 1447
1448 case IDC_CONTENT_CONTEXT_RELOAD_ORIGINAL_IMAGE:
1449 ReloadOriginalImage();
1450 break;
1451
1436 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB: 1452 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB:
1437 case IDC_CONTENT_CONTEXT_OPENAVNEWTAB: 1453 case IDC_CONTENT_CONTEXT_OPENAVNEWTAB:
1438 OpenURL(params_.src_url, 1454 OpenURL(params_.src_url,
1439 GetDocumentURL(params_), 1455 GetDocumentURL(params_),
1440 NEW_BACKGROUND_TAB, 1456 NEW_BACKGROUND_TAB,
1441 ui::PAGE_TRANSITION_LINK); 1457 ui::PAGE_TRANSITION_LINK);
1442 break; 1458 break;
1443 1459
1444 case IDC_CONTENT_CONTEXT_PLAYPAUSE: { 1460 case IDC_CONTENT_CONTEXT_PLAYPAUSE: {
1445 bool play = !!(params_.media_flags & WebContextMenuData::MediaPaused); 1461 bool play = !!(params_.media_flags & WebContextMenuData::MediaPaused);
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
1780 kMaxSelectionTextLength, 1796 kMaxSelectionTextLength,
1781 gfx::WORD_BREAK); 1797 gfx::WORD_BREAK);
1782 } 1798 }
1783 1799
1784 // Controller functions -------------------------------------------------------- 1800 // Controller functions --------------------------------------------------------
1785 1801
1786 void RenderViewContextMenu::CopyImageAt(int x, int y) { 1802 void RenderViewContextMenu::CopyImageAt(int x, int y) {
1787 source_web_contents_->GetRenderViewHost()->CopyImageAt(x, y); 1803 source_web_contents_->GetRenderViewHost()->CopyImageAt(x, y);
1788 } 1804 }
1789 1805
1806 void RenderViewContextMenu::ReloadOriginalImage() {
1807 RenderFrameHost* render_frame_host = GetRenderFrameHost();
1808 if (!render_frame_host)
1809 return;
1810 render_frame_host->Send(new ChromeViewMsg_RequestReloadImageForContextNode(
1811 render_frame_host->GetRoutingID()));
1812 }
1813
1790 void RenderViewContextMenu::GetImageThumbnailForSearch() { 1814 void RenderViewContextMenu::GetImageThumbnailForSearch() {
1791 RenderFrameHost* render_frame_host = GetRenderFrameHost(); 1815 RenderFrameHost* render_frame_host = GetRenderFrameHost();
1792 if (!render_frame_host) 1816 if (!render_frame_host)
1793 return; 1817 return;
1794 render_frame_host->Send(new ChromeViewMsg_RequestThumbnailForContextNode( 1818 render_frame_host->Send(new ChromeViewMsg_RequestThumbnailForContextNode(
1795 render_frame_host->GetRoutingID(), 1819 render_frame_host->GetRoutingID(),
1796 kImageSearchThumbnailMinSize, 1820 kImageSearchThumbnailMinSize,
1797 gfx::Size(kImageSearchThumbnailMaxWidth, 1821 gfx::Size(kImageSearchThumbnailMaxWidth,
1798 kImageSearchThumbnailMaxHeight))); 1822 kImageSearchThumbnailMaxHeight)));
1799 } 1823 }
(...skipping 18 matching lines...) Expand all
1818 source_web_contents_->GetRenderViewHost()-> 1842 source_web_contents_->GetRenderViewHost()->
1819 ExecuteMediaPlayerActionAtLocation(location, action); 1843 ExecuteMediaPlayerActionAtLocation(location, action);
1820 } 1844 }
1821 1845
1822 void RenderViewContextMenu::PluginActionAt( 1846 void RenderViewContextMenu::PluginActionAt(
1823 const gfx::Point& location, 1847 const gfx::Point& location,
1824 const WebPluginAction& action) { 1848 const WebPluginAction& action) {
1825 source_web_contents_->GetRenderViewHost()-> 1849 source_web_contents_->GetRenderViewHost()->
1826 ExecutePluginActionAtLocation(location, action); 1850 ExecutePluginActionAtLocation(location, action);
1827 } 1851 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698