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

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

Issue 2116973002: Added "Exit full screen" to context menu. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Return the result of GetAcceleratorForCommandId. Created 4 years, 5 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 <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <set> 10 #include <set>
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 {78, -1, IDC_CONTENT_CONTEXT_OPEN_WITH5}, 299 {78, -1, IDC_CONTENT_CONTEXT_OPEN_WITH5},
300 {79, -1, IDC_CONTENT_CONTEXT_OPEN_WITH6}, 300 {79, -1, IDC_CONTENT_CONTEXT_OPEN_WITH6},
301 {80, -1, IDC_CONTENT_CONTEXT_OPEN_WITH7}, 301 {80, -1, IDC_CONTENT_CONTEXT_OPEN_WITH7},
302 {81, -1, IDC_CONTENT_CONTEXT_OPEN_WITH8}, 302 {81, -1, IDC_CONTENT_CONTEXT_OPEN_WITH8},
303 {82, -1, IDC_CONTENT_CONTEXT_OPEN_WITH9}, 303 {82, -1, IDC_CONTENT_CONTEXT_OPEN_WITH9},
304 {83, -1, IDC_CONTENT_CONTEXT_OPEN_WITH10}, 304 {83, -1, IDC_CONTENT_CONTEXT_OPEN_WITH10},
305 {84, -1, IDC_CONTENT_CONTEXT_OPEN_WITH11}, 305 {84, -1, IDC_CONTENT_CONTEXT_OPEN_WITH11},
306 {85, -1, IDC_CONTENT_CONTEXT_OPEN_WITH12}, 306 {85, -1, IDC_CONTENT_CONTEXT_OPEN_WITH12},
307 {86, -1, IDC_CONTENT_CONTEXT_OPEN_WITH13}, 307 {86, -1, IDC_CONTENT_CONTEXT_OPEN_WITH13},
308 {87, -1, IDC_CONTENT_CONTEXT_OPEN_WITH14}, 308 {87, -1, IDC_CONTENT_CONTEXT_OPEN_WITH14},
309 {88, -1, IDC_EXIT_FULLSCREEN},
sky 2016/07/07 17:00:41 Based upon most of these constants starting with I
Matt Giuca 2016/07/08 00:55:46 Done. That's a good point. Also moved the actual v
309 // Add new items here and use |enum_id| from the next line. 310 // Add new items here and use |enum_id| from the next line.
310 // Also, add new items to RenderViewContextMenuItem enum in histograms.xml. 311 // Also, add new items to RenderViewContextMenuItem enum in histograms.xml.
311 {88, -1, 0}, // Must be the last. Increment |enum_id| when new IDC 312 {89, -1, 0}, // Must be the last. Increment |enum_id| when new IDC
312 // was added. 313 // was added.
313 }; 314 };
314 315
315 // Collapses large ranges of ids before looking for UMA enum. 316 // Collapses large ranges of ids before looking for UMA enum.
316 int CollapseCommandsForUMA(int id) { 317 int CollapseCommandsForUMA(int id) {
317 DCHECK(!RenderViewContextMenu::IsContentCustomCommandId(id)); 318 DCHECK(!RenderViewContextMenu::IsContentCustomCommandId(id));
318 DCHECK(!ContextMenuMatcher::IsExtensionsCustomCommandId(id)); 319 DCHECK(!ContextMenuMatcher::IsExtensionsCustomCommandId(id));
319 320
320 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST && 321 if (id >= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_FIRST &&
321 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) { 322 id <= IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_LAST) {
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 const size_t kMappingSize = arraysize(kUmaEnumToControlId); 876 const size_t kMappingSize = arraysize(kUmaEnumToControlId);
876 UMA_HISTOGRAM_ENUMERATION("RenderViewContextMenu.Shown", enum_id, 877 UMA_HISTOGRAM_ENUMERATION("RenderViewContextMenu.Shown", enum_id,
877 kUmaEnumToControlId[kMappingSize - 1].enum_id); 878 kUmaEnumToControlId[kMappingSize - 1].enum_id);
878 } else { 879 } else {
879 // Just warning here. It's harder to maintain list of all possibly 880 // Just warning here. It's harder to maintain list of all possibly
880 // visible items than executable items. 881 // visible items than executable items.
881 DLOG(ERROR) << "Update kUmaEnumToControlId. Unhanded IDC: " << id; 882 DLOG(ERROR) << "Update kUmaEnumToControlId. Unhanded IDC: " << id;
882 } 883 }
883 } 884 }
884 885
886 bool RenderViewContextMenu::IsHTML5Fullscreen() const {
887 Browser* browser = chrome::FindBrowserWithWebContents(source_web_contents_);
888 if (!browser)
889 return false;
890
891 FullscreenController* controller =
892 browser->exclusive_access_manager()->fullscreen_controller();
893 return controller->IsTabFullscreen();
894 }
895
885 #if defined(ENABLE_PLUGINS) 896 #if defined(ENABLE_PLUGINS)
886 void RenderViewContextMenu::HandleAuthorizeAllPlugins() { 897 void RenderViewContextMenu::HandleAuthorizeAllPlugins() {
887 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins( 898 ChromePluginServiceFilter::GetInstance()->AuthorizeAllPlugins(
888 source_web_contents_, false, std::string()); 899 source_web_contents_, false, std::string());
889 } 900 }
890 #endif 901 #endif
891 902
892 void RenderViewContextMenu::AppendPrintPreviewItems() { 903 void RenderViewContextMenu::AppendPrintPreviewItems() {
893 #if defined(ENABLE_PRINT_PREVIEW) 904 #if defined(ENABLE_PRINT_PREVIEW)
894 if (!print_preview_menu_observer_.get()) { 905 if (!print_preview_menu_observer_.get()) {
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 // The "Print" menu item should always be included for plugins. If 1172 // The "Print" menu item should always be included for plugins. If
1162 // content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PRINT) 1173 // content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PRINT)
1163 // is true the item will be added inside AppendPrintItem(). Otherwise we 1174 // is true the item will be added inside AppendPrintItem(). Otherwise we
1164 // add "Print" here. 1175 // add "Print" here.
1165 if (!content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PRINT)) 1176 if (!content_type_->SupportsGroup(ContextMenuContentType::ITEM_GROUP_PRINT))
1166 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); 1177 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT);
1167 } 1178 }
1168 } 1179 }
1169 1180
1170 void RenderViewContextMenu::AppendPageItems() { 1181 void RenderViewContextMenu::AppendPageItems() {
1182 AppendExitFullscreenItem();
1183
1171 menu_model_.AddItemWithStringId(IDC_BACK, IDS_CONTENT_CONTEXT_BACK); 1184 menu_model_.AddItemWithStringId(IDC_BACK, IDS_CONTENT_CONTEXT_BACK);
1172 menu_model_.AddItemWithStringId(IDC_FORWARD, IDS_CONTENT_CONTEXT_FORWARD); 1185 menu_model_.AddItemWithStringId(IDC_FORWARD, IDS_CONTENT_CONTEXT_FORWARD);
1173 menu_model_.AddItemWithStringId(IDC_RELOAD, IDS_CONTENT_CONTEXT_RELOAD); 1186 menu_model_.AddItemWithStringId(IDC_RELOAD, IDS_CONTENT_CONTEXT_RELOAD);
1174 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); 1187 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
1175 menu_model_.AddItemWithStringId(IDC_SAVE_PAGE, 1188 menu_model_.AddItemWithStringId(IDC_SAVE_PAGE,
1176 IDS_CONTENT_CONTEXT_SAVEPAGEAS); 1189 IDS_CONTENT_CONTEXT_SAVEPAGEAS);
1177 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT); 1190 menu_model_.AddItemWithStringId(IDC_PRINT, IDS_CONTENT_CONTEXT_PRINT);
1178 AppendMediaRouterItem(); 1191 AppendMediaRouterItem();
1179 1192
1180 if (TranslateService::IsTranslatableURL(params_.page_url)) { 1193 if (TranslateService::IsTranslatableURL(params_.page_url)) {
1181 std::string locale = g_browser_process->GetApplicationLocale(); 1194 std::string locale = g_browser_process->GetApplicationLocale();
1182 locale = translate::TranslateDownloadManager::GetLanguageCode(locale); 1195 locale = translate::TranslateDownloadManager::GetLanguageCode(locale);
1183 base::string16 language = 1196 base::string16 language =
1184 l10n_util::GetDisplayNameForLocale(locale, locale, true); 1197 l10n_util::GetDisplayNameForLocale(locale, locale, true);
1185 menu_model_.AddItem( 1198 menu_model_.AddItem(
1186 IDC_CONTENT_CONTEXT_TRANSLATE, 1199 IDC_CONTENT_CONTEXT_TRANSLATE,
1187 l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_TRANSLATE, language)); 1200 l10n_util::GetStringFUTF16(IDS_CONTENT_CONTEXT_TRANSLATE, language));
1188 AddGoogleIconToLastMenuItem(&menu_model_); 1201 AddGoogleIconToLastMenuItem(&menu_model_);
1189 } 1202 }
1190 } 1203 }
1191 1204
1205 void RenderViewContextMenu::AppendExitFullscreenItem() {
1206 Browser* browser = chrome::FindBrowserWithWebContents(source_web_contents_);
1207 if (!browser)
1208 return;
1209
1210 // Only show item if in fullscreen mode.
1211 if (!browser->exclusive_access_manager()
1212 ->fullscreen_controller()
1213 ->IsControllerInitiatedFullscreen()) {
1214 return;
sky 2016/07/07 17:00:41 I had question about conditionally adding the item
Matt Giuca 2016/07/08 00:55:46 Acknowledged.
1215 }
1216
1217 menu_model_.AddItemWithStringId(IDC_EXIT_FULLSCREEN,
1218 IDS_CONTENT_CONTEXT_EXIT_FULLSCREEN);
1219 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
1220 }
1221
1192 void RenderViewContextMenu::AppendCopyItem() { 1222 void RenderViewContextMenu::AppendCopyItem() {
1193 if (menu_model_.GetItemCount()) 1223 if (menu_model_.GetItemCount())
1194 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR); 1224 menu_model_.AddSeparator(ui::NORMAL_SEPARATOR);
1195 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPY, 1225 menu_model_.AddItemWithStringId(IDC_CONTENT_CONTEXT_COPY,
1196 IDS_CONTENT_CONTEXT_COPY); 1226 IDS_CONTENT_CONTEXT_COPY);
1197 } 1227 }
1198 1228
1199 void RenderViewContextMenu::AppendPrintItem() { 1229 void RenderViewContextMenu::AppendPrintItem() {
1200 if (GetPrefs(browser_context_)->GetBoolean(prefs::kPrintingEnabled) && 1230 if (GetPrefs(browser_context_)->GetBoolean(prefs::kPrintingEnabled) &&
1201 (params_.media_type == WebContextMenuData::MediaTypeNone || 1231 (params_.media_type == WebContextMenuData::MediaTypeNone ||
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
1572 case IDC_SPELLCHECK_MENU: 1602 case IDC_SPELLCHECK_MENU:
1573 case IDC_CONTENT_CONTEXT_OPENLINKWITH: 1603 case IDC_CONTENT_CONTEXT_OPENLINKWITH:
1574 case IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS: 1604 case IDC_CONTENT_CONTEXT_PROTOCOL_HANDLER_SETTINGS:
1575 case IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD: 1605 case IDC_CONTENT_CONTEXT_FORCESAVEPASSWORD:
1576 case IDC_CONTENT_CONTEXT_GENERATEPASSWORD: 1606 case IDC_CONTENT_CONTEXT_GENERATEPASSWORD:
1577 return true; 1607 return true;
1578 1608
1579 case IDC_ROUTE_MEDIA: 1609 case IDC_ROUTE_MEDIA:
1580 return IsRouteMediaEnabled(); 1610 return IsRouteMediaEnabled();
1581 1611
1612 case IDC_EXIT_FULLSCREEN:
1613 return true;
1614
1582 default: 1615 default:
1583 NOTREACHED(); 1616 NOTREACHED();
1584 return false; 1617 return false;
1585 } 1618 }
1586 } 1619 }
1587 1620
1588 bool RenderViewContextMenu::IsCommandIdChecked(int id) const { 1621 bool RenderViewContextMenu::IsCommandIdChecked(int id) const {
1589 if (RenderViewContextMenuBase::IsCommandIdChecked(id)) 1622 if (RenderViewContextMenuBase::IsCommandIdChecked(id))
1590 return true; 1623 return true;
1591 1624
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1745 break; 1778 break;
1746 1779
1747 case IDC_PRINT: 1780 case IDC_PRINT:
1748 ExecPrint(); 1781 ExecPrint();
1749 break; 1782 break;
1750 1783
1751 case IDC_ROUTE_MEDIA: 1784 case IDC_ROUTE_MEDIA:
1752 ExecRouteMedia(); 1785 ExecRouteMedia();
1753 break; 1786 break;
1754 1787
1788 case IDC_EXIT_FULLSCREEN:
1789 ExecExitFullscreen();
1790 break;
1791
1755 case IDC_VIEW_SOURCE: 1792 case IDC_VIEW_SOURCE:
1756 embedder_web_contents_->ViewSource(); 1793 embedder_web_contents_->ViewSource();
1757 break; 1794 break;
1758 1795
1759 case IDC_CONTENT_CONTEXT_INSPECTELEMENT: 1796 case IDC_CONTENT_CONTEXT_INSPECTELEMENT:
1760 ExecInspectElement(); 1797 ExecInspectElement();
1761 break; 1798 break;
1762 1799
1763 case IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE: 1800 case IDC_CONTENT_CONTEXT_INSPECTBACKGROUNDPAGE:
1764 ExecInspectBackgroundPage(); 1801 ExecInspectBackgroundPage();
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
2182 browser_context_); 2219 browser_context_);
2183 if (params_.media_type == WebContextMenuData::MediaTypeImage && 2220 if (params_.media_type == WebContextMenuData::MediaTypeImage &&
2184 settings && settings->CanUseDataReductionProxy(params_.src_url)) { 2221 settings && settings->CanUseDataReductionProxy(params_.src_url)) {
2185 headers = data_reduction_proxy::kDataReductionPassThroughHeader; 2222 headers = data_reduction_proxy::kDataReductionPassThroughHeader;
2186 } 2223 }
2187 2224
2188 source_web_contents_->SaveFrameWithHeaders(url, referrer, headers); 2225 source_web_contents_->SaveFrameWithHeaders(url, referrer, headers);
2189 } 2226 }
2190 } 2227 }
2191 2228
2229 void RenderViewContextMenu::ExecExitFullscreen() {
2230 Browser* browser = chrome::FindBrowserWithWebContents(source_web_contents_);
2231 if (!browser) {
2232 NOTREACHED();
2233 return;
2234 }
2235
2236 browser->exclusive_access_manager()->ExitExclusiveAccess();
2237 }
2192 2238
2193 void RenderViewContextMenu::ExecCopyLinkText() { 2239 void RenderViewContextMenu::ExecCopyLinkText() {
2194 ui::ScopedClipboardWriter scw(ui::CLIPBOARD_TYPE_COPY_PASTE); 2240 ui::ScopedClipboardWriter scw(ui::CLIPBOARD_TYPE_COPY_PASTE);
2195 scw.WriteText(params_.link_text); 2241 scw.WriteText(params_.link_text);
2196 } 2242 }
2197 2243
2198 void RenderViewContextMenu::ExecCopyImageAt() { 2244 void RenderViewContextMenu::ExecCopyImageAt() {
2199 source_web_contents_->GetRenderViewHost()->CopyImageAt(params_.x, params_.y); 2245 source_web_contents_->GetRenderViewHost()->CopyImageAt(params_.x, params_.y);
2200 } 2246 }
2201 2247
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
2387 source_web_contents_->GetRenderViewHost()-> 2433 source_web_contents_->GetRenderViewHost()->
2388 ExecuteMediaPlayerActionAtLocation(location, action); 2434 ExecuteMediaPlayerActionAtLocation(location, action);
2389 } 2435 }
2390 2436
2391 void RenderViewContextMenu::PluginActionAt( 2437 void RenderViewContextMenu::PluginActionAt(
2392 const gfx::Point& location, 2438 const gfx::Point& location,
2393 const WebPluginAction& action) { 2439 const WebPluginAction& action) {
2394 source_web_contents_->GetRenderViewHost()-> 2440 source_web_contents_->GetRenderViewHost()->
2395 ExecutePluginActionAtLocation(location, action); 2441 ExecutePluginActionAtLocation(location, action);
2396 } 2442 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698