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

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

Issue 944533002: Context menu item to view original image when Data Saver is being used. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Sync to head Created 5 years, 10 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 13 matching lines...) Expand all
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 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 143
142 // Maps UMA enumeration to IDC. IDC could be changed so we can't use 144 // Maps UMA enumeration to IDC. IDC could be changed so we can't use
143 // just them and |UMA_HISTOGRAM_CUSTOM_ENUMERATION|. 145 // just them and |UMA_HISTOGRAM_CUSTOM_ENUMERATION|.
144 // Never change mapping or reuse |enum_id|. Always push back new items. 146 // Never change mapping or reuse |enum_id|. Always push back new items.
145 // Items that is not used any more by |RenderViewContextMenu.ExecuteCommand| 147 // Items that is not used any more by |RenderViewContextMenu.ExecuteCommand|
146 // could be deleted, but don't change the rest of |kUmaEnumToControlId|. 148 // could be deleted, but don't change the rest of |kUmaEnumToControlId|.
147 const struct UmaEnumCommandIdPair { 149 const struct UmaEnumCommandIdPair {
148 int enum_id; 150 int enum_id;
149 int control_id; 151 int control_id;
150 } kUmaEnumToControlId[] = { 152 } kUmaEnumToControlId[] = {
151 /* 153 /*
152 enum id for 0, 1 are detected using 154 enum id for 0, 1 are detected using
153 RenderViewContextMenu::IsContentCustomCommandId and 155 RenderViewContextMenu::IsContentCustomCommandId and
154 ContextMenuMatcher::IsExtensionsCustomCommandId 156 ContextMenuMatcher::IsExtensionsCustomCommandId
155 */ 157 */
156 {2, IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST}, 158 {2, IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST},
157 {3, IDC_CONTENT_CONTEXT_OPENLINKNEWTAB}, 159 {3, IDC_CONTENT_CONTEXT_OPENLINKNEWTAB},
158 {4, IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW}, 160 {4, IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW},
159 {5, IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD}, 161 {5, IDC_CONTENT_CONTEXT_OPENLINKOFFTHERECORD},
160 {6, IDC_CONTENT_CONTEXT_SAVELINKAS}, 162 {6, IDC_CONTENT_CONTEXT_SAVELINKAS},
161 {7, IDC_CONTENT_CONTEXT_SAVEAVAS}, 163 {7, IDC_CONTENT_CONTEXT_SAVEAVAS},
162 {8, IDC_CONTENT_CONTEXT_SAVEIMAGEAS}, 164 {8, IDC_CONTENT_CONTEXT_SAVEIMAGEAS},
163 {9, IDC_CONTENT_CONTEXT_COPYLINKLOCATION}, 165 {9, IDC_CONTENT_CONTEXT_COPYLINKLOCATION},
164 {10, IDC_CONTENT_CONTEXT_COPYIMAGELOCATION}, 166 {10, IDC_CONTENT_CONTEXT_COPYIMAGELOCATION},
165 {11, IDC_CONTENT_CONTEXT_COPYAVLOCATION}, 167 {11, IDC_CONTENT_CONTEXT_COPYAVLOCATION},
166 {12, IDC_CONTENT_CONTEXT_COPYIMAGE}, 168 {12, IDC_CONTENT_CONTEXT_COPYIMAGE},
167 {13, IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB}, 169 {13, IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB},
168 {14, IDC_CONTENT_CONTEXT_OPENAVNEWTAB}, 170 {14, IDC_CONTENT_CONTEXT_OPENAVNEWTAB},
169 {15, IDC_CONTENT_CONTEXT_PLAYPAUSE}, 171 {15, IDC_CONTENT_CONTEXT_PLAYPAUSE},
170 {16, IDC_CONTENT_CONTEXT_MUTE}, 172 {16, IDC_CONTENT_CONTEXT_MUTE},
171 {17, IDC_CONTENT_CONTEXT_LOOP}, 173 {17, IDC_CONTENT_CONTEXT_LOOP},
172 {18, IDC_CONTENT_CONTEXT_CONTROLS}, 174 {18, IDC_CONTENT_CONTEXT_CONTROLS},
173 {19, IDC_CONTENT_CONTEXT_ROTATECW}, 175 {19, IDC_CONTENT_CONTEXT_ROTATECW},
174 {20, IDC_CONTENT_CONTEXT_ROTATECCW}, 176 {20, IDC_CONTENT_CONTEXT_ROTATECCW},
175 {21, IDC_BACK}, 177 {21, IDC_BACK},
176 {22, IDC_FORWARD}, 178 {22, IDC_FORWARD},
177 {23, IDC_SAVE_PAGE}, 179 {23, IDC_SAVE_PAGE},
178 {24, IDC_RELOAD}, 180 {24, IDC_RELOAD},
179 {25, IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP}, 181 {25, IDC_CONTENT_CONTEXT_RELOAD_PACKAGED_APP},
180 {26, IDC_CONTENT_CONTEXT_RESTART_PACKAGED_APP}, 182 {26, IDC_CONTENT_CONTEXT_RESTART_PACKAGED_APP},
181 {27, IDC_PRINT}, 183 {27, IDC_PRINT},
182 {28, IDC_VIEW_SOURCE}, 184 {28, IDC_VIEW_SOURCE},
183 {29, IDC_CONTENT_CONTEXT_INSPECTELEMENT}, 185 {29, IDC_CONTENT_CONTEXT_INSPECTELEMENT},
184 {30, IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE}, 186 {30, IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE},
185 {31, IDC_CONTENT_CONTEXT_VIEWPAGEINFO}, 187 {31, IDC_CONTENT_CONTEXT_VIEWPAGEINFO},
186 {32, IDC_CONTENT_CONTEXT_TRANSLATE}, 188 {32, IDC_CONTENT_CONTEXT_TRANSLATE},
187 {33, IDC_CONTENT_CONTEXT_RELOADFRAME}, 189 {33, IDC_CONTENT_CONTEXT_RELOADFRAME},
188 {34, IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE}, 190 {34, IDC_CONTENT_CONTEXT_VIEWFRAMESOURCE},
189 {35, IDC_CONTENT_CONTEXT_VIEWFRAMEINFO}, 191 {35, IDC_CONTENT_CONTEXT_VIEWFRAMEINFO},
190 {36, IDC_CONTENT_CONTEXT_UNDO}, 192 {36, IDC_CONTENT_CONTEXT_UNDO},
191 {37, IDC_CONTENT_CONTEXT_REDO}, 193 {37, IDC_CONTENT_CONTEXT_REDO},
192 {38, IDC_CONTENT_CONTEXT_CUT}, 194 {38, IDC_CONTENT_CONTEXT_CUT},
193 {39, IDC_CONTENT_CONTEXT_COPY}, 195 {39, IDC_CONTENT_CONTEXT_COPY},
194 {40, IDC_CONTENT_CONTEXT_PASTE}, 196 {40, IDC_CONTENT_CONTEXT_PASTE},
195 {41, IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE}, 197 {41, IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE},
196 {42, IDC_CONTENT_CONTEXT_DELETE}, 198 {42, IDC_CONTENT_CONTEXT_DELETE},
197 {43, IDC_CONTENT_CONTEXT_SELECTALL}, 199 {43, IDC_CONTENT_CONTEXT_SELECTALL},
198 {44, IDC_CONTENT_CONTEXT_SEARCHWEBFOR}, 200 {44, IDC_CONTENT_CONTEXT_SEARCHWEBFOR},
199 {45, IDC_CONTENT_CONTEXT_GOTOURL}, 201 {45, IDC_CONTENT_CONTEXT_GOTOURL},
200 {46, IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS}, 202 {46, IDC_CONTENT_CONTEXT_LANGUAGE_SETTINGS},
201 {47, IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS}, 203 {47, IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS},
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},
212 // Add new items here and use |enum_id| from the next line. 214 {61, IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB},
213 {61, 0}, // Must be the last. Increment |enum_id| when new IDC was added. 215 // Add new items here and use |enum_id| from the next line.
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
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(params_.src_url)) {
701 menu_model_.AddItemWithStringId(
702 IDC_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB,
703 IDS_CONTENT_CONTEXT_OPEN_ORIGINAL_IMAGE_NEW_TAB);
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
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_OPEN_ORIGINAL_IMAGE_NEW_TAB:
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
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_OPEN_ORIGINAL_IMAGE_NEW_TAB:
1416 OpenURLWithExtraHeaders(
1417 params_.src_url, GetDocumentURL(params_), NEW_BACKGROUND_TAB,
1418 ui::PAGE_TRANSITION_LINK,
1419 data_reduction_proxy::kDataReductionPassThroughHeader);
1420 break;
1421
1403 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB: 1422 case IDC_CONTENT_CONTEXT_OPENIMAGENEWTAB:
1404 case IDC_CONTENT_CONTEXT_OPENAVNEWTAB: 1423 case IDC_CONTENT_CONTEXT_OPENAVNEWTAB:
1405 OpenURL(params_.src_url, 1424 OpenURL(params_.src_url,
1406 GetDocumentURL(params_), 1425 GetDocumentURL(params_),
1407 NEW_BACKGROUND_TAB, 1426 NEW_BACKGROUND_TAB,
1408 ui::PAGE_TRANSITION_LINK); 1427 ui::PAGE_TRANSITION_LINK);
1409 break; 1428 break;
1410 1429
1411 case IDC_CONTENT_CONTEXT_PLAYPAUSE: { 1430 case IDC_CONTENT_CONTEXT_PLAYPAUSE: {
1412 bool play = !!(params_.media_flags & WebContextMenuData::MediaPaused); 1431 bool play = !!(params_.media_flags & WebContextMenuData::MediaPaused);
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
1785 source_web_contents_->GetRenderViewHost()-> 1804 source_web_contents_->GetRenderViewHost()->
1786 ExecuteMediaPlayerActionAtLocation(location, action); 1805 ExecuteMediaPlayerActionAtLocation(location, action);
1787 } 1806 }
1788 1807
1789 void RenderViewContextMenu::PluginActionAt( 1808 void RenderViewContextMenu::PluginActionAt(
1790 const gfx::Point& location, 1809 const gfx::Point& location,
1791 const WebPluginAction& action) { 1810 const WebPluginAction& action) {
1792 source_web_contents_->GetRenderViewHost()-> 1811 source_web_contents_->GetRenderViewHost()->
1793 ExecutePluginActionAtLocation(location, action); 1812 ExecutePluginActionAtLocation(location, action);
1794 } 1813 }
OLDNEW
« no previous file with comments | « chrome/app/chrome_command_ids.h ('k') | chrome/browser/renderer_context_menu/render_view_context_menu_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698