blob: e60b51352862c56a449ec9f68507b6fdb746a1fe [file] [log] [blame]
[email protected]5d98294912012-06-27 22:57:401// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/ui/browser_command_controller.h"
6
avi655876a2015-12-25 07:18:157#include <stddef.h>
8
pmonette9c1457f2015-11-19 20:29:319#include <string>
10
Sebastien Marchandf1349f52019-01-25 03:16:4111#include "base/bind.h"
[email protected]488e3952013-11-18 05:29:1412#include "base/command_line.h"
Scott Violet44165792018-02-22 02:08:0813#include "base/debug/debugging_buildflags.h"
primianod3a81ab2016-01-25 22:21:1514#include "base/debug/profiler.h"
avi655876a2015-12-25 07:18:1515#include "base/macros.h"
bratell0a7406f2017-03-28 07:46:3716#include "base/metrics/user_metrics.h"
Haeun Kim3f6123502018-08-26 18:03:0417#include "base/stl_util.h"
Nico Weber0cc71122019-07-29 17:30:4018#include "build/branding_buildflags.h"
avi655876a2015-12-25 07:18:1519#include "build/build_config.h"
[email protected]5d98294912012-06-27 22:57:4020#include "chrome/app/chrome_command_ids.h"
21#include "chrome/browser/browser_process.h"
[email protected]dcc8fbc2013-07-12 00:54:0922#include "chrome/browser/chrome_notification_types.h"
[email protected]5d98294912012-06-27 22:57:4023#include "chrome/browser/defaults.h"
Pavol Marko56df0272018-07-04 17:55:0424#include "chrome/browser/devtools/devtools_window.h"
[email protected]5d98294912012-06-27 22:57:4025#include "chrome/browser/extensions/extension_service.h"
[email protected]2e9d79f2013-08-16 05:45:5626#include "chrome/browser/lifetime/application_lifetime.h"
[email protected]5d98294912012-06-27 22:57:4027#include "chrome/browser/prefs/incognito_mode_prefs.h"
[email protected]5d98294912012-06-27 22:57:4028#include "chrome/browser/profiles/profile.h"
mlermane01e6de2014-09-29 19:26:4729#include "chrome/browser/profiles/profile_manager.h"
[email protected]5d98294912012-06-27 22:57:4030#include "chrome/browser/sessions/tab_restore_service_factory.h"
[email protected]0b32f9b62012-09-17 19:08:0331#include "chrome/browser/shell_integration.h"
[email protected]3d27d272013-07-31 03:15:1632#include "chrome/browser/signin/signin_promo.h"
[email protected]5d98294912012-06-27 22:57:4033#include "chrome/browser/sync/profile_sync_service_factory.h"
Christopher Lam86b52712017-12-04 01:58:3334#include "chrome/browser/ui/apps/app_info_dialog.h"
[email protected]5d98294912012-06-27 22:57:4035#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
36#include "chrome/browser/ui/browser.h"
37#include "chrome/browser/ui/browser_commands.h"
Dana Fried08b774a2019-05-10 18:21:4838#include "chrome/browser/ui/browser_finder.h"
[email protected]5d98294912012-06-27 22:57:4039#include "chrome/browser/ui/browser_window.h"
40#include "chrome/browser/ui/chrome_pages.h"
Alan Cutter0c3132302018-02-21 05:09:0241#include "chrome/browser/ui/page_info/page_info_dialog.h"
Nicolas Ouellet-payeur82eb65b2018-11-05 16:49:2742#include "chrome/browser/ui/singleton_tabs.h"
[email protected]5d98294912012-06-27 22:57:4043#include "chrome/browser/ui/tabs/tab_strip_model.h"
Yuheng Huang092c72a92020-08-10 22:39:3044#include "chrome/browser/ui/ui_features.h"
Eric Willigers4a5f7a92019-05-10 19:19:2645#include "chrome/browser/ui/web_applications/app_browser_controller.h"
Glen Robertsonb9d27412020-01-09 06:48:1346#include "chrome/browser/ui/web_applications/web_app_dialog_utils.h"
Eric Willigerse2ca235a2019-08-17 01:01:0647#include "chrome/browser/ui/web_applications/web_app_launch_utils.h"
[email protected]2056c3192013-10-21 22:40:5148#include "chrome/browser/ui/webui/inspect_ui.h"
[email protected]3c71576ce2013-07-23 02:00:0149#include "chrome/common/content_restriction.h"
[email protected]5d98294912012-06-27 22:57:4050#include "chrome/common/pref_names.h"
Nicolas Ouellet-payeur82eb65b2018-11-05 16:49:2751#include "chrome/common/url_constants.h"
brettwe1f0af8b2015-10-09 21:30:4652#include "components/bookmarks/common/bookmark_pref_names.h"
Aran Gilman7b6ccf5d2019-09-05 19:16:0253#include "components/dom_distiller/core/dom_distiller_features.h"
Elly Fong-Jones2d688ae2020-03-31 20:41:4754#include "components/omnibox/common/omnibox_features.h"
brettwb1fc1b82016-02-02 00:19:0855#include "components/prefs/pref_service.h"
blundella08c5dd2015-09-18 06:14:1656#include "components/sessions/core/tab_restore_service.h"
Colin Blundell3517170e2019-07-11 08:16:3457#include "components/signin/public/base/signin_pref_names.h"
[email protected]5d98294912012-06-27 22:57:4058#include "content/public/browser/native_web_keyboard_event.h"
59#include "content/public/browser/navigation_controller.h"
60#include "content/public/browser/navigation_entry.h"
Lukasz Anforowicze1b954d92017-10-30 21:28:0661#include "content/public/browser/render_frame_host.h"
[email protected]5d98294912012-06-27 22:57:4062#include "content/public/browser/web_contents.h"
[email protected]20ca0382013-02-28 19:50:0763#include "content/public/browser/web_contents_observer.h"
Bryce Thomas96b07772018-11-07 03:04:1564#include "content/public/common/profiling.h"
[email protected]5d98294912012-06-27 22:57:4065#include "content/public/common/url_constants.h"
[email protected]03d25812014-06-22 19:41:5566#include "extensions/browser/extension_system.h"
Scott Violet318a55f2018-03-30 19:08:1967#include "printing/buildflags/buildflags.h"
[email protected]7e9acd082013-09-17 23:31:1668#include "ui/events/keycodes/keyboard_codes.h"
[email protected]5d98294912012-06-27 22:57:4069
Avi Drissman73ea864d2020-07-29 19:56:1570#if defined(OS_MAC)
[email protected]9c4d68332013-01-30 13:34:4171#include "chrome/browser/ui/browser_commands_mac.h"
72#endif
73
[email protected]5d98294912012-06-27 22:57:4074#if defined(OS_WIN)
[email protected]a43ed002013-02-05 19:47:5475#include "base/win/windows_version.h"
[email protected]2d0f80f2013-11-01 22:47:1876#include "content/public/browser/gpu_data_manager.h"
[email protected]5d98294912012-06-27 22:57:4077#endif
78
[email protected]d12cc5e2013-10-19 18:25:0679#if defined(OS_CHROMEOS)
Ivan Sandrke0e92452019-03-21 09:32:4880#include "chrome/browser/platform_util.h"
[email protected]0c930812014-01-30 18:01:4781#include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h"
caelyn4e4e08a2015-02-04 21:27:4982#include "chrome/browser/ui/browser_commands_chromeos.h"
anina koehler038555b2020-02-24 13:30:3283#include "components/session_manager/core/session_manager.h"
[email protected]d12cc5e2013-10-19 18:25:0684#endif
85
[email protected]d5bedb6d2014-04-08 10:49:3286#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Eliot Courtney830e0052020-06-16 11:43:3487#include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h" // nogncheck
[email protected]1e2172f2014-04-01 17:32:3488#endif
89
Maksim Sisovac767592018-08-10 08:00:1590#if defined(USE_OZONE)
Maksim Sisovb0643ebd2020-06-22 11:47:3191#include "ui/base/ui_base_features.h"
Maksim Sisovac767592018-08-10 08:00:1592#include "ui/ozone/public/ozone_platform.h"
93#endif
94
[email protected]5d98294912012-06-27 22:57:4095using content::NavigationController;
Aran Gilmand217b5b2019-04-11 17:45:4396using content::NavigationEntry;
[email protected]5d98294912012-06-27 22:57:4097using content::WebContents;
98
[email protected]5d98294912012-06-27 22:57:4099namespace chrome {
100
Dana Fried08b774a2019-05-10 18:21:48101namespace {
102
103// Ensures that - if we have not popped up an infobar to prompt the user to e.g.
104// reload the current page - that the content pane of the browser is refocused.
105void AppInfoDialogClosedCallback(content::WebContents* web_contents,
Dana Fried98c0380e2019-05-14 16:58:32106 views::Widget::ClosedReason closed_reason,
Dana Fried08b774a2019-05-10 18:21:48107 bool reload_prompt) {
108 if (reload_prompt)
109 return;
110
Dana Fried98c0380e2019-05-14 16:58:32111 // If the user clicked on something specific or focus was changed, don't
112 // override the focus.
113 if (closed_reason != views::Widget::ClosedReason::kEscKeyPressed &&
114 closed_reason != views::Widget::ClosedReason::kCloseButtonClicked) {
115 return;
116 }
117
Dana Fried08b774a2019-05-10 18:21:48118 // Ensure that the web contents handle we have is still valid. It's possible
119 // (though unlikely) that either the browser or web contents has been pulled
120 // out from underneath us.
121 Browser* const browser = chrome::FindBrowserWithWebContents(web_contents);
122 if (!browser)
123 return;
124
125 // We want to focus the active web contents, which again, might not be the
126 // original web contents (though it should be the vast majority of the time).
127 content::WebContents* const active_contents =
128 browser->tab_strip_model()->GetActiveWebContents();
129 if (active_contents)
130 active_contents->Focus();
131}
132
133} // namespace
134
[email protected]5d98294912012-06-27 22:57:40135///////////////////////////////////////////////////////////////////////////////
136// BrowserCommandController, public:
137
[email protected]338416c02014-05-13 16:47:06138BrowserCommandController::BrowserCommandController(Browser* browser)
Aran Gilmand217b5b2019-04-11 17:45:43139 : browser_(browser), command_updater_(nullptr) {
[email protected]5d98294912012-06-27 22:57:40140 browser_->tab_strip_model()->AddObserver(this);
141 PrefService* local_state = g_browser_process->local_state();
142 if (local_state) {
143 local_pref_registrar_.Init(local_state);
[email protected]9ec3ea5b2012-12-03 18:14:30144 local_pref_registrar_.Add(
145 prefs::kAllowFileSelectionDialogs,
146 base::Bind(
147 &BrowserCommandController::UpdateCommandsForFileSelectionDialogs,
148 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40149 }
150
151 profile_pref_registrar_.Init(profile()->GetPrefs());
[email protected]9ec3ea5b2012-12-03 18:14:30152 profile_pref_registrar_.Add(
Pavol Markodebb0ff2018-05-07 18:35:41153 prefs::kDevToolsAvailability,
[email protected]9ec3ea5b2012-12-03 18:14:30154 base::Bind(&BrowserCommandController::UpdateCommandsForDevTools,
155 base::Unretained(this)));
156 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32157 bookmarks::prefs::kEditBookmarksEnabled,
[email protected]9ec3ea5b2012-12-03 18:14:30158 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkEditing,
159 base::Unretained(this)));
160 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32161 bookmarks::prefs::kShowBookmarkBar,
[email protected]9ec3ea5b2012-12-03 18:14:30162 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkBar,
163 base::Unretained(this)));
164 profile_pref_registrar_.Add(
165 prefs::kIncognitoModeAvailability,
166 base::Bind(
167 &BrowserCommandController::UpdateCommandsForIncognitoAvailability,
168 base::Unretained(this)));
169 profile_pref_registrar_.Add(
170 prefs::kPrintingEnabled,
171 base::Bind(&BrowserCommandController::UpdatePrintingState,
172 base::Unretained(this)));
Avi Drissman73ea864d2020-07-29 19:56:15173#if !defined(OS_MAC)
[email protected]32dfede2013-08-25 15:48:25174 profile_pref_registrar_.Add(
175 prefs::kFullscreenAllowed,
176 base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode,
177 base::Unretained(this)));
178#endif
Mihai Sardarescuf87ccc12018-09-26 10:37:45179 pref_signin_allowed_.Init(
Aran Gilmand217b5b2019-04-11 17:45:43180 prefs::kSigninAllowed, profile()->GetOriginalProfile()->GetPrefs(),
Mihai Sardarescuf87ccc12018-09-26 10:37:45181 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange,
182 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40183
184 InitCommandState();
185
blundell74001adc2015-09-18 11:04:25186 sessions::TabRestoreService* tab_restore_service =
[email protected]5d98294912012-06-27 22:57:40187 TabRestoreServiceFactory::GetForProfile(profile());
188 if (tab_restore_service) {
189 tab_restore_service->AddObserver(this);
Cliff Smolinsky2c9586e2019-02-08 18:48:30190 if (!tab_restore_service->IsLoaded())
191 tab_restore_service->LoadTabsFromLastSession();
[email protected]5d98294912012-06-27 22:57:40192 }
[email protected]5d98294912012-06-27 22:57:40193}
194
195BrowserCommandController::~BrowserCommandController() {
[email protected]95e39472012-10-05 23:37:36196 // TabRestoreService may have been shutdown by the time we get here. Don't
197 // trigger creating it.
blundell74001adc2015-09-18 11:04:25198 sessions::TabRestoreService* tab_restore_service =
[email protected]95e39472012-10-05 23:37:36199 TabRestoreServiceFactory::GetForProfileIfExisting(profile());
[email protected]5d98294912012-06-27 22:57:40200 if (tab_restore_service)
201 tab_restore_service->RemoveObserver(this);
202 profile_pref_registrar_.RemoveAll();
203 local_pref_registrar_.RemoveAll();
204 browser_->tab_strip_model()->RemoveObserver(this);
205}
206
207bool BrowserCommandController::IsReservedCommandOrKey(
208 int command_id,
209 const content::NativeWebKeyboardEvent& event) {
210 // In Apps mode, no keys are reserved.
Leonard Grey345662a82020-02-07 21:20:03211 if (browser_->is_type_app() || browser_->is_type_app_popup())
[email protected]5d98294912012-06-27 22:57:40212 return false;
213
214#if defined(OS_CHROMEOS)
[email protected]397abd32013-08-21 05:44:19215 // On Chrome OS, the top row of keys are mapped to browser actions like
216 // back/forward or refresh. We don't want web pages to be able to change the
217 // behavior of these keys. Ash handles F4 and up; this leaves us needing to
218 // reserve browser back/forward and refresh here.
[email protected]5d98294912012-06-27 22:57:40219 ui::KeyboardCode key_code =
Blink Reformat1c4d759e2017-04-09 16:34:54220 static_cast<ui::KeyboardCode>(event.windows_key_code);
[email protected]397abd32013-08-21 05:44:19221 if ((key_code == ui::VKEY_BROWSER_BACK && command_id == IDC_BACK) ||
222 (key_code == ui::VKEY_BROWSER_FORWARD && command_id == IDC_FORWARD) ||
223 (key_code == ui::VKEY_BROWSER_REFRESH && command_id == IDC_RELOAD)) {
[email protected]5d98294912012-06-27 22:57:40224 return true;
225 }
226#endif
227
zijiehe68cd3dc22017-04-07 18:50:29228 if (window()->IsFullscreen()) {
229 // In fullscreen, all commands except for IDC_FULLSCREEN and IDC_EXIT should
230 // be delivered to the web page. The intent to implement and ship can be
231 // found in http://crbug.com/680809.
232 const bool is_exit_fullscreen =
233 (command_id == IDC_EXIT || command_id == IDC_FULLSCREEN);
Avi Drissman73ea864d2020-07-29 19:56:15234#if defined(OS_MAC)
zijiehe68cd3dc22017-04-07 18:50:29235 // This behavior is different on Mac OS, which has a unique user-initiated
236 // full-screen mode. According to the discussion in http://crbug.com/702251,
237 // the commands should be reserved for browser-side handling if the browser
238 // window's toolbar is visible.
239 if (window()->IsToolbarShowing()) {
240 if (command_id == IDC_FULLSCREEN)
241 return true;
242 } else {
243 return is_exit_fullscreen;
244 }
245#else
246 return is_exit_fullscreen;
247#endif
248 }
[email protected]1e2172f2014-04-01 17:32:34249
[email protected]893124a22014-04-15 00:45:28250#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]1e2172f2014-04-01 17:32:34251 // If this key was registered by the user as a content editing hotkey, then
252 // it is not reserved.
[email protected]d5bedb6d2014-04-08 10:49:32253 ui::TextEditKeyBindingsDelegateAuraLinux* delegate =
[email protected]1e2172f2014-04-01 17:32:34254 ui::GetTextEditKeyBindingsDelegate();
[email protected]47e8e7542014-04-03 07:52:42255 if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL))
[email protected]1e2172f2014-04-01 17:32:34256 return false;
257#endif
258
Aran Gilmand217b5b2019-04-11 17:45:43259 return command_id == IDC_CLOSE_TAB || command_id == IDC_CLOSE_WINDOW ||
260 command_id == IDC_NEW_INCOGNITO_WINDOW || command_id == IDC_NEW_TAB ||
261 command_id == IDC_NEW_WINDOW || command_id == IDC_RESTORE_TAB ||
zijiehe13207802017-02-16 08:06:10262 command_id == IDC_SELECT_NEXT_TAB ||
Aran Gilmand217b5b2019-04-11 17:45:43263 command_id == IDC_SELECT_PREVIOUS_TAB || command_id == IDC_EXIT;
[email protected]5d98294912012-06-27 22:57:40264}
265
[email protected]5d98294912012-06-27 22:57:40266void BrowserCommandController::TabStateChanged() {
267 UpdateCommandsForTabState();
Dominic Mazzoni1e0e51252020-10-19 19:36:18268 UpdateCommandsForWebContentsFocus();
[email protected]5d98294912012-06-27 22:57:40269}
270
[email protected]d93dbd12014-08-04 23:42:53271void BrowserCommandController::ZoomStateChanged() {
272 UpdateCommandsForZoomState();
273}
274
[email protected]5d98294912012-06-27 22:57:40275void BrowserCommandController::ContentRestrictionsChanged() {
276 UpdateCommandsForContentRestrictionState();
277}
278
279void BrowserCommandController::FullscreenStateChanged() {
[email protected]32dfede2013-08-25 15:48:25280 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40281}
282
Ivan Sandrk9669d0e2017-12-15 23:50:20283#if defined(OS_CHROMEOS)
284void BrowserCommandController::LockedFullscreenStateChanged() {
285 UpdateCommandsForLockedFullscreenMode();
286}
287#endif
288
[email protected]5d98294912012-06-27 22:57:40289void BrowserCommandController::PrintingStateChanged() {
290 UpdatePrintingState();
291}
292
293void BrowserCommandController::LoadingStateChanged(bool is_loading,
294 bool force) {
295 UpdateReloadStopState(is_loading, force);
296}
297
Jeff Fisher6cc1ce7b2019-06-28 23:02:38298void BrowserCommandController::FindBarVisibilityChanged() {
299 if (is_locked_fullscreen_)
300 return;
301 UpdateCloseFindOrStop();
302}
303
wittman76df71db32014-12-18 23:26:58304void BrowserCommandController::ExtensionStateChanged() {
305 // Extensions may disable the bookmark editing commands.
306 UpdateCommandsForBookmarkEditing();
307}
308
Elly Fong-Jones5e6baaf2019-10-10 23:17:14309void BrowserCommandController::TabKeyboardFocusChangedTo(
310 base::Optional<int> index) {
311 UpdateCommandsForTabKeyboardFocus(index);
312}
313
Dominic Mazzoni1e0e51252020-10-19 19:36:18314void BrowserCommandController::WebContentsFocusChanged() {
315 UpdateCommandsForWebContentsFocus();
316}
317
[email protected]5d98294912012-06-27 22:57:40318////////////////////////////////////////////////////////////////////////////////
Ivan Sandrk9669d0e2017-12-15 23:50:20319// BrowserCommandController, CommandUpdater implementation:
[email protected]5d98294912012-06-27 22:57:40320
Ivan Sandrk9669d0e2017-12-15 23:50:20321bool BrowserCommandController::SupportsCommand(int id) const {
322 return command_updater_.SupportsCommand(id);
323}
324
325bool BrowserCommandController::IsCommandEnabled(int id) const {
326 return command_updater_.IsCommandEnabled(id);
327}
328
Edwin Joe6f6fc1e2019-02-27 20:00:37329bool BrowserCommandController::ExecuteCommand(int id,
330 base::TimeTicks time_stamp) {
331 return ExecuteCommandWithDisposition(id, WindowOpenDisposition::CURRENT_TAB,
332 time_stamp);
Ivan Sandrk9669d0e2017-12-15 23:50:20333}
334
335bool BrowserCommandController::ExecuteCommandWithDisposition(
Edwin Joe6f6fc1e2019-02-27 20:00:37336 int id,
337 WindowOpenDisposition disposition,
338 base::TimeTicks time_stamp) {
Ivan Sandrk9669d0e2017-12-15 23:50:20339 // Doesn't go through the command_updater_ to avoid dealing with having a
340 // naming collision for ExecuteCommandWithDisposition (both
341 // CommandUpdaterDelegate and CommandUpdater declare this function so we
342 // choose to not implement CommandUpdaterDelegate inside this class and
343 // therefore command_updater_ doesn't have the delegate set).
344 if (!SupportsCommand(id) || !IsCommandEnabled(id))
345 return false;
346
[email protected]5d98294912012-06-27 22:57:40347 // No commands are enabled if there is not yet any selected tab.
348 // TODO(pkasting): It seems like we should not need this, because either
349 // most/all commands should not have been enabled yet anyway or the ones that
350 // are enabled should be global, or safe themselves against having no selected
351 // tab. However, Ben says he tried removing this before and got lots of
352 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
353 // window construction. This probably could use closer examination someday.
[email protected]59253a652012-11-20 00:17:26354 if (browser_->tab_strip_model()->active_index() == TabStripModel::kNoTab)
Ivan Sandrk9669d0e2017-12-15 23:50:20355 return true;
[email protected]5d98294912012-06-27 22:57:40356
Aran Gilmand217b5b2019-04-11 17:45:43357 DCHECK(command_updater_.IsCommandEnabled(id))
358 << "Invalid/disabled command " << id;
[email protected]5d98294912012-06-27 22:57:40359
[email protected]5d98294912012-06-27 22:57:40360 // The order of commands in this switch statement must match the function
361 // declaration order in browser.h!
362 switch (id) {
363 // Navigation commands
364 case IDC_BACK:
365 GoBack(browser_, disposition);
366 break;
367 case IDC_FORWARD:
368 GoForward(browser_, disposition);
369 break;
370 case IDC_RELOAD:
371 Reload(browser_, disposition);
372 break;
[email protected]58e29032012-08-06 20:19:57373 case IDC_RELOAD_CLEARING_CACHE:
374 ClearCache(browser_);
Nico Webera745ef72018-01-29 23:45:57375 FALLTHROUGH;
toyoshim7dad4b1182016-04-01 14:28:05376 case IDC_RELOAD_BYPASSING_CACHE:
377 ReloadBypassingCache(browser_, disposition);
[email protected]5d98294912012-06-27 22:57:40378 break;
379 case IDC_HOME:
380 Home(browser_, disposition);
381 break;
382 case IDC_OPEN_CURRENT_URL:
383 OpenCurrentURL(browser_);
384 break;
385 case IDC_STOP:
386 Stop(browser_);
387 break;
Yuheng Huang092c72a92020-08-10 22:39:30388 case IDC_TAB_SEARCH:
389 ShowTabSearch(browser_);
390 break;
[email protected]5d98294912012-06-27 22:57:40391
Aran Gilmand217b5b2019-04-11 17:45:43392 // Window management commands
[email protected]5d98294912012-06-27 22:57:40393 case IDC_NEW_WINDOW:
394 NewWindow(browser_);
395 break;
396 case IDC_NEW_INCOGNITO_WINDOW:
Orin Jaworski5e4bcd0c2018-10-16 19:35:05397 NewIncognitoWindow(profile());
[email protected]5d98294912012-06-27 22:57:40398 break;
399 case IDC_CLOSE_WINDOW:
bratell0a7406f2017-03-28 07:46:37400 base::RecordAction(base::UserMetricsAction("CloseWindowByKey"));
[email protected]04b9e692012-08-24 14:49:09401 CloseWindow(browser_);
[email protected]5d98294912012-06-27 22:57:40402 break;
Bettina Dea0a4505922017-09-28 00:53:32403 case IDC_NEW_TAB: {
404 NewTab(browser_);
[email protected]5d98294912012-06-27 22:57:40405 break;
Bettina Dea0a4505922017-09-28 00:53:32406 }
[email protected]5d98294912012-06-27 22:57:40407 case IDC_CLOSE_TAB:
bratell0a7406f2017-03-28 07:46:37408 base::RecordAction(base::UserMetricsAction("CloseTabByKey"));
[email protected]04b9e692012-08-24 14:49:09409 CloseTab(browser_);
[email protected]5d98294912012-06-27 22:57:40410 break;
411 case IDC_SELECT_NEXT_TAB:
bratell0a7406f2017-03-28 07:46:37412 base::RecordAction(base::UserMetricsAction("Accel_SelectNextTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37413 SelectNextTab(browser_,
414 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40415 break;
416 case IDC_SELECT_PREVIOUS_TAB:
bratell0a7406f2017-03-28 07:46:37417 base::RecordAction(base::UserMetricsAction("Accel_SelectPreviousTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37418 SelectPreviousTab(browser_,
419 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40420 break;
[email protected]5d98294912012-06-27 22:57:40421 case IDC_MOVE_TAB_NEXT:
422 MoveTabNext(browser_);
423 break;
424 case IDC_MOVE_TAB_PREVIOUS:
425 MoveTabPrevious(browser_);
426 break;
427 case IDC_SELECT_TAB_0:
428 case IDC_SELECT_TAB_1:
429 case IDC_SELECT_TAB_2:
430 case IDC_SELECT_TAB_3:
431 case IDC_SELECT_TAB_4:
432 case IDC_SELECT_TAB_5:
433 case IDC_SELECT_TAB_6:
434 case IDC_SELECT_TAB_7:
bratell0a7406f2017-03-28 07:46:37435 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37436 SelectNumberedTab(browser_, id - IDC_SELECT_TAB_0,
437 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40438 break;
439 case IDC_SELECT_LAST_TAB:
bratell0a7406f2017-03-28 07:46:37440 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37441 SelectLastTab(browser_,
442 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40443 break;
444 case IDC_DUPLICATE_TAB:
445 DuplicateTab(browser_);
446 break;
447 case IDC_RESTORE_TAB:
448 RestoreTab(browser_);
Collin Baker9bbe1d82019-03-08 01:16:27449 browser_->window()->OnTabRestored(IDC_RESTORE_TAB);
[email protected]5d98294912012-06-27 22:57:40450 break;
[email protected]5d98294912012-06-27 22:57:40451 case IDC_SHOW_AS_TAB:
452 ConvertPopupToTabbedBrowser(browser_);
453 break;
454 case IDC_FULLSCREEN:
[email protected]3f32b9b2012-07-09 16:59:28455 chrome::ToggleFullscreenMode(browser_);
[email protected]5d98294912012-06-27 22:57:40456 break;
Alan Cutter09965802018-03-27 07:25:29457 case IDC_OPEN_IN_PWA_WINDOW:
458 base::RecordAction(base::UserMetricsAction("OpenActiveTabInPwaWindow"));
Alan Cutter42356022020-02-20 06:44:13459 web_app::ReparentWebAppForActiveTab(browser_);
Alan Cutter09965802018-03-27 07:25:29460 break;
Leonard Greyf13493b2019-12-19 18:12:57461 case IDC_MOVE_TAB_TO_NEW_WINDOW:
Leonard Greya8ecaa32020-01-07 20:57:41462 MoveActiveTabToNewWindow(browser_);
Leonard Greyf13493b2019-12-19 18:12:57463 break;
[email protected]770c6d82012-09-06 22:21:32464
[email protected]d12cc5e2013-10-19 18:25:06465#if defined(OS_CHROMEOS)
466 case IDC_VISIT_DESKTOP_OF_LRU_USER_2:
[email protected]0c930812014-01-30 18:01:47467 case IDC_VISIT_DESKTOP_OF_LRU_USER_3:
anina koehler038555b2020-02-24 13:30:32468 case IDC_VISIT_DESKTOP_OF_LRU_USER_4:
469 case IDC_VISIT_DESKTOP_OF_LRU_USER_5:
zijiehe4dde8072017-02-13 20:38:35470 ExecuteVisitDesktopCommand(id, window()->GetNativeWindow());
[email protected]0c930812014-01-30 18:01:47471 break;
[email protected]d12cc5e2013-10-19 18:25:06472#endif
473
[email protected]893124a22014-04-15 00:45:28474#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15475 case IDC_MINIMIZE_WINDOW:
476 browser_->window()->Minimize();
477 break;
478 case IDC_MAXIMIZE_WINDOW:
479 browser_->window()->Maximize();
480 break;
481 case IDC_RESTORE_WINDOW:
482 browser_->window()->Restore();
483 break;
[email protected]af97be4c62014-02-13 14:43:34484 case IDC_USE_SYSTEM_TITLE_BAR: {
zijiehe4dde8072017-02-13 20:38:35485 PrefService* prefs = profile()->GetPrefs();
[email protected]af97be4c62014-02-13 14:43:34486 prefs->SetBoolean(prefs::kUseCustomChromeFrame,
487 !prefs->GetBoolean(prefs::kUseCustomChromeFrame));
488 break;
489 }
490#endif
491
Avi Drissman73ea864d2020-07-29 19:56:15492#if defined(OS_MAC)
spqchanb8ffc7d2015-11-17 01:17:21493 case IDC_TOGGLE_FULLSCREEN_TOOLBAR:
494 chrome::ToggleFullscreenToolbar(browser_);
495 break;
spqchan2c5d541e2017-10-25 07:07:11496 case IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS: {
Robert Sesek03282612018-10-31 15:48:06497 chrome::ToggleJavaScriptFromAppleEventsAllowed(browser_);
spqchan2c5d541e2017-10-25 07:07:11498 break;
499 }
[email protected]5d98294912012-06-27 22:57:40500#endif
501 case IDC_EXIT:
502 Exit();
503 break;
504
505 // Page-related commands
506 case IDC_SAVE_PAGE:
507 SavePage(browser_);
508 break;
Peter Kasting32bb2602019-08-22 19:01:43509 case IDC_BOOKMARK_THIS_TAB:
Devlin Croninbf700d02020-03-30 20:23:58510 BookmarkCurrentTab(browser_);
[email protected]5d98294912012-06-27 22:57:40511 break;
[email protected]5d98294912012-06-27 22:57:40512 case IDC_BOOKMARK_ALL_TABS:
[email protected]5d98294912012-06-27 22:57:40513 BookmarkAllTabs(browser_);
514 break;
515 case IDC_VIEW_SOURCE:
Lukasz Anforowicze1b954d92017-10-30 21:28:06516 browser_->tab_strip_model()
517 ->GetActiveWebContents()
518 ->GetMainFrame()
519 ->ViewSource();
[email protected]5d98294912012-06-27 22:57:40520 break;
[email protected]5d98294912012-06-27 22:57:40521 case IDC_PRINT:
522 Print(browser_);
523 break;
bondd052b5f82015-10-28 22:39:32524
Lei Zhang48a4a5262018-04-17 20:18:44525#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:55526 case IDC_BASIC_PRINT:
bratell0a7406f2017-03-28 07:46:37527 base::RecordAction(base::UserMetricsAction("Accel_Advanced_Print"));
vitalybukaf9433e42014-09-08 10:04:55528 BasicPrint(browser_);
[email protected]5d98294912012-06-27 22:57:40529 break;
Lei Zhang48a4a5262018-04-17 20:18:44530#endif // ENABLE_PRINTING
bondd052b5f82015-10-28 22:39:32531
bondd052b5f82015-10-28 22:39:32532 case IDC_SAVE_CREDIT_CARD_FOR_PAGE:
533 SaveCreditCard(browser_);
534 break;
siyua3e599eaa2018-07-13 00:23:06535 case IDC_MIGRATE_LOCAL_CREDIT_CARD_FOR_PAGE:
536 MigrateLocalCards(browser_);
537 break;
siyuac6e018d2019-10-18 01:19:30538 case IDC_SHOW_SAVE_LOCAL_CARD_SIGN_IN_PROMO_IF_APPLICABLE:
539 MaybeShowSaveLocalCardSignInPromo(browser_);
540 break;
541 case IDC_CLOSE_SIGN_IN_PROMO:
542 CloseSaveLocalCardSignInPromo(browser_);
543 break;
[email protected]e625b7602013-10-28 09:24:56544 case IDC_TRANSLATE_PAGE:
545 Translate(browser_);
546 break;
[email protected]4bee4432014-05-05 13:11:41547 case IDC_MANAGE_PASSWORDS_FOR_PAGE:
548 ManagePasswordsForPage(browser_);
549 break;
Tina Wang4c324702019-04-25 18:35:15550 case IDC_SEND_TAB_TO_SELF:
Tina Wang0e7e6e92019-05-14 21:03:03551 SendTabToSelfFromPageAction(browser_);
Tina Wang4c324702019-04-25 18:35:15552 break;
Travis Skare5193bbe12020-04-15 18:31:03553 case IDC_QRCODE_GENERATOR:
554 GenerateQRCodeFromPageAction(browser_);
555 break;
[email protected]4bee4432014-05-05 13:11:41556
[email protected]5d98294912012-06-27 22:57:40557 // Clipboard commands
558 case IDC_CUT:
[email protected]5d98294912012-06-27 22:57:40559 case IDC_COPY:
[email protected]5d98294912012-06-27 22:57:40560 case IDC_PASTE:
pkastingcd3f08bce2015-04-18 13:37:12561 CutCopyPaste(browser_, id);
[email protected]5d98294912012-06-27 22:57:40562 break;
563
564 // Find-in-page
565 case IDC_FIND:
566 Find(browser_);
567 break;
568 case IDC_FIND_NEXT:
569 FindNext(browser_);
570 break;
571 case IDC_FIND_PREVIOUS:
572 FindPrevious(browser_);
573 break;
Jeff Fisher6cc1ce7b2019-06-28 23:02:38574 case IDC_CLOSE_FIND_OR_STOP:
575 if (CanCloseFind(browser_))
576 CloseFind(browser_);
577 else if (IsCommandEnabled(IDC_STOP))
578 ExecuteCommand(IDC_STOP);
579 break;
[email protected]5d98294912012-06-27 22:57:40580
581 // Zoom
582 case IDC_ZOOM_PLUS:
583 Zoom(browser_, content::PAGE_ZOOM_IN);
584 break;
585 case IDC_ZOOM_NORMAL:
586 Zoom(browser_, content::PAGE_ZOOM_RESET);
587 break;
588 case IDC_ZOOM_MINUS:
589 Zoom(browser_, content::PAGE_ZOOM_OUT);
590 break;
591
592 // Focus various bits of UI
593 case IDC_FOCUS_TOOLBAR:
bratell0a7406f2017-03-28 07:46:37594 base::RecordAction(base::UserMetricsAction("Accel_Focus_Toolbar"));
[email protected]5d98294912012-06-27 22:57:40595 FocusToolbar(browser_);
596 break;
597 case IDC_FOCUS_LOCATION:
bratell0a7406f2017-03-28 07:46:37598 base::RecordAction(base::UserMetricsAction("Accel_Focus_Location"));
[email protected]5d98294912012-06-27 22:57:40599 FocusLocationBar(browser_);
600 break;
601 case IDC_FOCUS_SEARCH:
bratell0a7406f2017-03-28 07:46:37602 base::RecordAction(base::UserMetricsAction("Accel_Focus_Search"));
[email protected]5d98294912012-06-27 22:57:40603 FocusSearch(browser_);
604 break;
605 case IDC_FOCUS_MENU_BAR:
606 FocusAppMenu(browser_);
607 break;
608 case IDC_FOCUS_BOOKMARKS:
bratell0a7406f2017-03-28 07:46:37609 base::RecordAction(base::UserMetricsAction("Accel_Focus_Bookmarks"));
[email protected]5d98294912012-06-27 22:57:40610 FocusBookmarksToolbar(browser_);
611 break;
David Tsengc0b1b642018-01-24 07:12:27612 case IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY:
613 FocusInactivePopupForAccessibility(browser_);
[email protected]822ca8c62013-04-19 00:49:15614 break;
[email protected]5d98294912012-06-27 22:57:40615 case IDC_FOCUS_NEXT_PANE:
616 FocusNextPane(browser_);
617 break;
618 case IDC_FOCUS_PREVIOUS_PANE:
619 FocusPreviousPane(browser_);
620 break;
621
622 // Show various bits of UI
623 case IDC_OPEN_FILE:
624 browser_->OpenFile();
625 break;
Alan Cutter81ac726682018-09-25 00:18:36626 case IDC_CREATE_SHORTCUT:
Alan Cutter98844a9fa2019-06-19 21:11:40627 base::RecordAction(base::UserMetricsAction("CreateShortcut"));
Glen Robertsonb9d27412020-01-09 06:48:13628 web_app::CreateWebAppFromCurrentWebContents(
629 browser_, true /* force_shortcut_app */);
Alan Cutter81ac726682018-09-25 00:18:36630 break;
631 case IDC_INSTALL_PWA:
Alan Cutter98844a9fa2019-06-19 21:11:40632 base::RecordAction(base::UserMetricsAction("InstallWebAppFromMenu"));
Glen Robertsonb9d27412020-01-09 06:48:13633 web_app::CreateWebAppFromCurrentWebContents(
634 browser_, false /* force_shortcut_app */);
[email protected]488e3952013-11-18 05:29:14635 break;
[email protected]5d98294912012-06-27 22:57:40636 case IDC_DEV_TOOLS:
[email protected]c934c382013-11-01 00:36:01637 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Show());
[email protected]5d98294912012-06-27 22:57:40638 break;
639 case IDC_DEV_TOOLS_CONSOLE:
einbinderdfa567b2016-12-16 01:15:52640 ToggleDevToolsWindow(browser_, DevToolsToggleAction::ShowConsolePanel());
[email protected]5d98294912012-06-27 22:57:40641 break;
[email protected]2056c3192013-10-21 22:40:51642 case IDC_DEV_TOOLS_DEVICES:
643 InspectUI::InspectDevices(browser_);
644 break;
[email protected]5d98294912012-06-27 22:57:40645 case IDC_DEV_TOOLS_INSPECT:
[email protected]c934c382013-11-01 00:36:01646 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Inspect());
[email protected]5d98294912012-06-27 22:57:40647 break;
[email protected]d16657c2012-09-03 14:25:10648 case IDC_DEV_TOOLS_TOGGLE:
[email protected]c934c382013-11-01 00:36:01649 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Toggle());
[email protected]d16657c2012-09-03 14:25:10650 break;
[email protected]5d98294912012-06-27 22:57:40651 case IDC_TASK_MANAGER:
[email protected]29c262de2013-06-22 15:39:38652 OpenTaskManager(browser_);
[email protected]5d98294912012-06-27 22:57:40653 break;
caelyn4e4e08a2015-02-04 21:27:49654#if defined(OS_CHROMEOS)
655 case IDC_TAKE_SCREENSHOT:
656 TakeScreenshot();
657 break;
658#endif
Nico Weber0cc71122019-07-29 17:30:40659#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
[email protected]5d98294912012-06-27 22:57:40660 case IDC_FEEDBACK:
afakhryf4575bd2017-04-28 02:21:04661 OpenFeedbackDialog(browser_, kFeedbackSourceBrowserCommand);
[email protected]5d98294912012-06-27 22:57:40662 break;
[email protected]236ad3022013-09-04 03:27:43663#endif
[email protected]5d98294912012-06-27 22:57:40664 case IDC_SHOW_BOOKMARK_BAR:
665 ToggleBookmarkBar(browser_);
666 break;
Elly Fong-Jones2d688ae2020-03-31 20:41:47667 case IDC_SHOW_FULL_URLS:
668 ToggleShowFullURLs(browser_);
669 break;
[email protected]5d98294912012-06-27 22:57:40670 case IDC_PROFILING_ENABLED:
Bryce Thomas96b07772018-11-07 03:04:15671 content::Profiling::Toggle();
[email protected]5d98294912012-06-27 22:57:40672 break;
Dominic Mazzoni554089e2020-07-31 22:12:04673 case IDC_CARET_BROWSING_TOGGLE:
674 ToggleCaretBrowsing(browser_);
675 break;
[email protected]5d98294912012-06-27 22:57:40676
677 case IDC_SHOW_BOOKMARK_MANAGER:
678 ShowBookmarkManager(browser_);
679 break;
680 case IDC_SHOW_APP_MENU:
bratell0a7406f2017-03-28 07:46:37681 base::RecordAction(base::UserMetricsAction("Accel_Show_App_Menu"));
[email protected]5d98294912012-06-27 22:57:40682 ShowAppMenu(browser_);
683 break;
684 case IDC_SHOW_AVATAR_MENU:
685 ShowAvatarMenu(browser_);
686 break;
687 case IDC_SHOW_HISTORY:
688 ShowHistory(browser_);
689 break;
690 case IDC_SHOW_DOWNLOADS:
691 ShowDownloads(browser_);
692 break;
693 case IDC_MANAGE_EXTENSIONS:
[email protected]bc9833c32013-02-28 04:05:08694 ShowExtensions(browser_, std::string());
[email protected]5d98294912012-06-27 22:57:40695 break;
696 case IDC_OPTIONS:
697 ShowSettings(browser_);
698 break;
699 case IDC_EDIT_SEARCH_ENGINES:
700 ShowSearchEngineSettings(browser_);
701 break;
702 case IDC_VIEW_PASSWORDS:
703 ShowPasswordManager(browser_);
704 break;
705 case IDC_CLEAR_BROWSING_DATA:
706 ShowClearBrowsingDataDialog(browser_);
707 break;
708 case IDC_IMPORT_SETTINGS:
709 ShowImportDialog(browser_);
710 break;
[email protected]9b7ab882012-09-10 23:46:36711 case IDC_TOGGLE_REQUEST_TABLET_SITE:
712 ToggleRequestTabletSite(browser_);
713 break;
[email protected]5d98294912012-06-27 22:57:40714 case IDC_ABOUT:
715 ShowAboutChrome(browser_);
716 break;
717 case IDC_UPGRADE_DIALOG:
718 OpenUpdateChromeDialog(browser_);
719 break;
[email protected]5d98294912012-06-27 22:57:40720 case IDC_HELP_PAGE_VIA_KEYBOARD:
721 ShowHelp(browser_, HELP_SOURCE_KEYBOARD);
722 break;
723 case IDC_HELP_PAGE_VIA_MENU:
724 ShowHelp(browser_, HELP_SOURCE_MENU);
725 break;
Bret Sepulveda2d018662017-05-18 21:31:48726 case IDC_SHOW_BETA_FORUM:
727 ShowBetaForum(browser_);
728 break;
David Roger7e25dff2019-02-07 09:03:17729#if !defined(OS_CHROMEOS)
estade8c0780f2015-08-21 23:36:41730 case IDC_SHOW_SIGNIN:
gogerald71bf6c902015-12-08 00:49:37731 ShowBrowserSigninOrSettings(
732 browser_, signin_metrics::AccessPoint::ACCESS_POINT_MENU);
estade8c0780f2015-08-21 23:36:41733 break;
David Roger7e25dff2019-02-07 09:03:17734#endif
[email protected]6bd370b2014-05-28 14:19:47735 case IDC_DISTILL_PAGE:
Aran Gilman6586e8f2019-06-03 18:50:56736 ToggleDistilledView(browser_);
[email protected]6bd370b2014-05-28 14:19:47737 break;
apacible45cbfc92015-09-28 22:45:41738 case IDC_ROUTE_MEDIA:
Takumi Fujimotoa8bc3c92019-12-26 20:12:10739 RouteMediaInvokedFromAppMenu(browser_);
apacible45cbfc92015-09-28 22:45:41740 break;
Tommy Steimelc4477982017-11-29 18:07:18741 case IDC_WINDOW_MUTE_SITE:
742 MuteSite(browser_);
ellyjones0101ba02017-05-19 15:50:26743 break;
744 case IDC_WINDOW_PIN_TAB:
745 PinTab(browser_);
746 break;
Connie Wan303e29e2020-01-31 18:16:56747 case IDC_WINDOW_GROUP_TAB:
748 GroupTab(browser_);
749 break;
Elly Fong-Jones2d0443cb2019-11-14 15:04:20750 case IDC_WINDOW_CLOSE_TABS_TO_RIGHT:
751 CloseTabsToRight(browser_);
752 break;
753 case IDC_WINDOW_CLOSE_OTHER_TABS:
754 CloseOtherTabs(browser_);
755 break;
Yann Dagocd13225a2019-03-07 18:39:05756 case IDC_SHOW_MANAGEMENT_PAGE: {
Yann Dagoc1d1c4af2019-04-17 13:40:51757 ShowSingletonTab(browser_, GURL(kChromeUIManagementURL));
Nicolas Ouellet-payeur82eb65b2018-11-05 16:49:27758 break;
Yann Dagocd13225a2019-03-07 18:39:05759 }
Elly Fong-Jones5e6baaf2019-10-10 23:17:14760 case IDC_MUTE_TARGET_SITE:
761 MuteSiteForKeyboardFocusedTab(browser_);
762 break;
763 case IDC_PIN_TARGET_TAB:
764 PinKeyboardFocusedTab(browser_);
765 break;
Connie Wan303e29e2020-01-31 18:16:56766 case IDC_GROUP_TARGET_TAB:
767 GroupKeyboardFocusedTab(browser_);
768 break;
Elly Fong-Jones5e6baaf2019-10-10 23:17:14769 case IDC_DUPLICATE_TARGET_TAB:
770 DuplicateKeyboardFocusedTab(browser_);
771 break;
Christopher Lam0dbac2b2017-11-14 07:12:10772 // Hosted App commands
773 case IDC_COPY_URL:
774 CopyURL(browser_);
775 break;
776 case IDC_OPEN_IN_CHROME:
777 OpenInChrome(browser_);
778 break;
779 case IDC_SITE_SETTINGS:
780 ShowSiteSettings(
781 browser_,
782 browser_->tab_strip_model()->GetActiveWebContents()->GetVisibleURL());
783 break;
Alan Cuttera99d1522019-09-12 02:09:22784 case IDC_WEB_APP_MENU_APP_INFO: {
Dana Fried08b774a2019-05-10 18:21:48785 content::WebContents* const web_contents =
786 browser_->tab_strip_model()->GetActiveWebContents();
787 if (web_contents) {
788 ShowPageInfoDialog(web_contents,
789 base::BindOnce(&AppInfoDialogClosedCallback,
790 base::Unretained(web_contents)),
791 bubble_anchor_util::kAppMenuButton);
792 }
Christopher Lam86b52712017-12-04 01:58:33793 break;
Dana Fried08b774a2019-05-10 18:21:48794 }
[email protected]5d98294912012-06-27 22:57:40795 default:
796 LOG(WARNING) << "Received Unimplemented Command: " << id;
797 break;
798 }
Ivan Sandrk9669d0e2017-12-15 23:50:20799
800 return true;
801}
802
803void BrowserCommandController::AddCommandObserver(int id,
804 CommandObserver* observer) {
805 command_updater_.AddCommandObserver(id, observer);
806}
807
808void BrowserCommandController::RemoveCommandObserver(
Aran Gilmand217b5b2019-04-11 17:45:43809 int id,
810 CommandObserver* observer) {
Ivan Sandrk9669d0e2017-12-15 23:50:20811 command_updater_.RemoveCommandObserver(id, observer);
812}
813
814void BrowserCommandController::RemoveCommandObserver(
815 CommandObserver* observer) {
816 command_updater_.RemoveCommandObserver(observer);
817}
818
819bool BrowserCommandController::UpdateCommandEnabled(int id, bool state) {
820 if (is_locked_fullscreen_)
821 return false;
822
823 return command_updater_.UpdateCommandEnabled(id, state);
[email protected]5d98294912012-06-27 22:57:40824}
825
Mihai Sardarescuf87ccc12018-09-26 10:37:45826////////////////////////////////////////////////////////////////////////////////
827// BrowserCommandController, SigninPrefObserver implementation:
828
829void BrowserCommandController::OnSigninAllowedPrefChange() {
830 // For unit tests, we don't have a window.
831 if (!window())
832 return;
833 UpdateShowSyncState(IsShowingMainUI());
834}
835
[email protected]5d98294912012-06-27 22:57:40836// BrowserCommandController, TabStripModelObserver implementation:
837
sangwoo.ko1ae265f12018-10-18 08:30:28838void BrowserCommandController::OnTabStripModelChanged(
839 TabStripModel* tab_strip_model,
840 const TabStripModelChange& change,
841 const TabStripSelectionChange& selection) {
Dana Frieda391e6ce2019-05-08 00:00:20842 std::vector<content::WebContents*> new_contents;
843 std::vector<content::WebContents*> old_contents;
[email protected]5d98294912012-06-27 22:57:40844
Dana Frieda391e6ce2019-05-08 00:00:20845 switch (change.type()) {
846 case TabStripModelChange::kInserted:
847 for (const auto& contents : change.GetInsert()->contents)
848 new_contents.push_back(contents.contents);
849 break;
850 case TabStripModelChange::kReplaced: {
851 auto* replace = change.GetReplace();
852 new_contents.push_back(replace->new_contents);
853 old_contents.push_back(replace->old_contents);
854 break;
sangwoo.ko1ae265f12018-10-18 08:30:28855 }
Dana Frieda391e6ce2019-05-08 00:00:20856 case TabStripModelChange::kRemoved:
857 for (const auto& contents : change.GetRemove()->contents)
858 old_contents.push_back(contents.contents);
859 break;
860 default:
861 break;
sangwoo.ko1ae265f12018-10-18 08:30:28862 }
[email protected]5d98294912012-06-27 22:57:40863}
864
[email protected]3cac87232012-11-20 01:48:27865void BrowserCommandController::TabBlockedStateChanged(
866 content::WebContents* contents,
867 int index) {
868 PrintingStateChanged();
869 FullscreenStateChanged();
870 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:41871 UpdateCommandsForMediaRouter();
[email protected]3cac87232012-11-20 01:48:27872}
873
[email protected]5d98294912012-06-27 22:57:40874////////////////////////////////////////////////////////////////////////////////
875// BrowserCommandController, TabRestoreServiceObserver implementation:
876
877void BrowserCommandController::TabRestoreServiceChanged(
blundell74001adc2015-09-18 11:04:25878 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53879 UpdateTabRestoreCommandState();
[email protected]5d98294912012-06-27 22:57:40880}
881
882void BrowserCommandController::TabRestoreServiceDestroyed(
blundell74001adc2015-09-18 11:04:25883 sessions::TabRestoreService* service) {
[email protected]5d98294912012-06-27 22:57:40884 service->RemoveObserver(this);
885}
886
[email protected]2e9369e2014-08-15 09:12:53887void BrowserCommandController::TabRestoreServiceLoaded(
blundell74001adc2015-09-18 11:04:25888 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53889 UpdateTabRestoreCommandState();
890}
891
[email protected]5d98294912012-06-27 22:57:40892////////////////////////////////////////////////////////////////////////////////
[email protected]5d98294912012-06-27 22:57:40893// BrowserCommandController, private:
894
[email protected]6a414ff2013-02-27 08:22:54895bool BrowserCommandController::IsShowingMainUI() {
manukf1a116392018-10-25 16:28:24896 return browser_->SupportsWindowFeature(Browser::FEATURE_TABSTRIP);
897}
898
899bool BrowserCommandController::IsShowingLocationBar() {
900 return browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
[email protected]5d98294912012-06-27 22:57:40901}
902
903void BrowserCommandController::InitCommandState() {
904 // All browser commands whose state isn't set automagically some other way
905 // (like Back & Forward with initial page load) must have their state
906 // initialized here, otherwise they will be forever disabled.
907
Ivan Sandrk9669d0e2017-12-15 23:50:20908 if (is_locked_fullscreen_)
909 return;
910
[email protected]5d98294912012-06-27 22:57:40911 // Navigation commands
912 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true);
toyoshim7dad4b1182016-04-01 14:28:05913 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE, true);
[email protected]58e29032012-08-06 20:19:57914 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, true);
[email protected]5d98294912012-06-27 22:57:40915
916 // Window management commands
917 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true);
918 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true);
919 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true);
920 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true);
[email protected]2e9369e2014-08-15 09:12:53921 UpdateTabRestoreCommandState();
[email protected]d28d3782013-02-26 16:31:55922 command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
[email protected]5d98294912012-06-27 22:57:40923 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true);
[email protected]d12cc5e2013-10-19 18:25:06924#if defined(OS_CHROMEOS)
James Cook934abaf2017-09-19 22:21:58925 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
anina koehler038555b2020-02-24 13:30:32926 // The VisitDesktop command is only supported for up to 5 logged in users
927 // because that's the max number of user sessions. If that number is increased
928 // the IDC_VISIT_DESKTOP_OF_LRU_USER_ command ids should be updated as well.
929 // crbug.com/940461
930 static_assert(
931 session_manager::kMaximumNumberOfUserSessions <=
932 IDC_VISIT_DESKTOP_OF_LRU_USER_LAST -
933 IDC_VISIT_DESKTOP_OF_LRU_USER_NEXT + 2,
934 "The max number of user sessions exceeds the number of users supported.");
[email protected]d12cc5e2013-10-19 18:25:06935 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_2, true);
936 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_3, true);
anina koehler038555b2020-02-24 13:30:32937 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_4, true);
938 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_5, true);
[email protected]d12cc5e2013-10-19 18:25:06939#endif
[email protected]893124a22014-04-15 00:45:28940#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15941 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
942 command_updater_.UpdateCommandEnabled(IDC_MAXIMIZE_WINDOW, true);
943 command_updater_.UpdateCommandEnabled(IDC_RESTORE_WINDOW, true);
Maksim Sisovac767592018-08-10 08:00:15944 bool use_system_title_bar = true;
945#if defined(USE_OZONE)
Maksim Sisovb0643ebd2020-06-22 11:47:31946 if (features::IsUsingOzonePlatform()) {
947 use_system_title_bar = ui::OzonePlatform::GetInstance()
948 ->GetPlatformProperties()
949 .use_system_title_bar;
950 }
Maksim Sisovac767592018-08-10 08:00:15951#endif
952 command_updater_.UpdateCommandEnabled(IDC_USE_SYSTEM_TITLE_BAR,
953 use_system_title_bar);
[email protected]af97be4c62014-02-13 14:43:34954#endif
Alan Cutter09965802018-03-27 07:25:29955 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW, true);
[email protected]5d98294912012-06-27 22:57:40956
957 // Page-related commands
[email protected]4bee4432014-05-05 13:11:41958 command_updater_.UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE, true);
[email protected]5d98294912012-06-27 22:57:40959
960 // Zoom
961 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true);
962 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true);
[email protected]d93dbd12014-08-04 23:42:53963 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, false);
[email protected]5d98294912012-06-27 22:57:40964 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
965
966 // Show various bits of UI
Aran Gilmand217b5b2019-04-11 17:45:43967 const bool guest_session =
968 profile()->IsGuestSession() || profile()->IsSystemProfile();
mlerman7831f57d2015-05-25 11:40:15969 DCHECK(!profile()->IsSystemProfile())
970 << "Ought to never have browser for the system profile.";
Joel Hockey2687ab52019-08-14 23:59:46971 const bool normal_window = browser_->is_type_normal();
[email protected]05454532013-01-22 21:09:08972 UpdateOpenFileState(&command_updater_);
[email protected]5d98294912012-06-27 22:57:40973 UpdateCommandsForDevTools();
974 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager());
[email protected]338416c02014-05-13 16:47:06975 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session);
[email protected]5d98294912012-06-27 22:57:40976 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
[email protected]674b65672014-06-02 23:21:56977 command_updater_.UpdateCommandEnabled(IDC_HELP_MENU, true);
[email protected]5d98294912012-06-27 22:57:40978 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
979 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
Bret Sepulveda2d018662017-05-18 21:31:48980 command_updater_.UpdateCommandEnabled(IDC_SHOW_BETA_FORUM, true);
[email protected]338416c02014-05-13 16:47:06981 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session);
Aran Gilmand217b5b2019-04-11 17:45:43982 command_updater_.UpdateCommandEnabled(
983 IDC_RECENT_TABS_MENU, !guest_session && !profile()->IsOffTheRecord());
Rohit Agarwal2a2230b2019-08-21 15:53:41984 command_updater_.UpdateCommandEnabled(
985 IDC_CLEAR_BROWSING_DATA,
986 !guest_session && !profile()->IsIncognitoProfile());
[email protected]39d47592014-01-10 21:42:45987#if defined(OS_CHROMEOS)
caelyn4e4e08a2015-02-04 21:27:49988 command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true);
Ramin Halavatif362b7a2019-04-17 05:24:50989 // Chrome OS uses the system tray menu to handle multi-profiles. Avatar menu
990 // is only required in incognito mode.
Ramin Halavati2394dc452019-05-21 16:21:58991 if (profile()->IsIncognitoProfile())
[email protected]338416c02014-05-13 16:47:06992 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
Ramin Halavatif362b7a2019-04-17 05:24:50993#else
994 if (normal_window)
995 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
[email protected]39d47592014-01-10 21:42:45996#endif
siyuac6e018d2019-10-18 01:19:30997 command_updater_.UpdateCommandEnabled(
998 IDC_SHOW_SAVE_LOCAL_CARD_SIGN_IN_PROMO_IF_APPLICABLE, true);
999 command_updater_.UpdateCommandEnabled(IDC_CLOSE_SIGN_IN_PROMO, true);
Dominic Mazzoni554089e2020-07-31 22:12:041000 command_updater_.UpdateCommandEnabled(IDC_CARET_BROWSING_TOGGLE, true);
[email protected]5d98294912012-06-27 22:57:401001
Mihai Sardarescu2ec5205682018-09-26 09:20:051002 UpdateShowSyncState(true);
1003
[email protected]5d98294912012-06-27 22:57:401004 // Navigation commands
Joel Hockey2687ab52019-08-14 23:59:461005 command_updater_.UpdateCommandEnabled(
1006 IDC_HOME, normal_window || browser_->deprecated_is_app());
[email protected]5d98294912012-06-27 22:57:401007
Mugdha Lakhani23954ef22020-06-25 21:56:211008 const bool is_web_app_or_custom_tab =
1009#if defined(OS_CHROMEOS)
1010 browser_->is_type_custom_tab() ||
1011#endif
Alan Cutterd0bd51902019-05-22 04:15:231012 web_app::AppBrowserController::IsForWebAppBrowser(browser_);
Christopher Lam0dbac2b2017-11-14 07:12:101013 // Hosted app browser commands.
Mugdha Lakhani23954ef22020-06-25 21:56:211014 command_updater_.UpdateCommandEnabled(IDC_COPY_URL, is_web_app_or_custom_tab);
1015 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_CHROME,
1016 is_web_app_or_custom_tab);
1017 command_updater_.UpdateCommandEnabled(IDC_SITE_SETTINGS,
1018 is_web_app_or_custom_tab);
1019 command_updater_.UpdateCommandEnabled(IDC_WEB_APP_MENU_APP_INFO,
1020 is_web_app_or_custom_tab);
Christopher Lam0dbac2b2017-11-14 07:12:101021
Joel Hockey43afbd82020-02-19 23:55:371022 // Tab management commands
1023 const bool supports_tabs =
1024 browser_->SupportsWindowFeature(Browser::FEATURE_TABSTRIP);
1025 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, supports_tabs);
1026 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, supports_tabs);
1027 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, supports_tabs);
1028 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, supports_tabs);
1029 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, supports_tabs);
1030 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, supports_tabs);
1031 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, supports_tabs);
1032 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, supports_tabs);
1033 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, supports_tabs);
1034 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, supports_tabs);
1035 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, supports_tabs);
1036 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, supports_tabs);
1037 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, supports_tabs);
[email protected]5d98294912012-06-27 22:57:401038
[email protected]338416c02014-05-13 16:47:061039 // These are always enabled; the menu determines their menu item visibility.
[email protected]5d98294912012-06-27 22:57:401040 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
[email protected]5d98294912012-06-27 22:57:401041
[email protected]6bd370b2014-05-28 14:19:471042 // Distill current page.
Aran Gilman7b6ccf5d2019-09-05 19:16:021043 command_updater_.UpdateCommandEnabled(IDC_DISTILL_PAGE,
1044 dom_distiller::IsDomDistillerEnabled());
[email protected]6bd370b2014-05-28 14:19:471045
Tommy Steimelc4477982017-11-29 18:07:181046 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE, normal_window);
ellyjones0101ba02017-05-19 15:50:261047 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, normal_window);
Connie Wan303e29e2020-01-31 18:16:561048 command_updater_.UpdateCommandEnabled(IDC_WINDOW_GROUP_TAB, normal_window);
Elly Fong-Jones2d0443cb2019-11-14 15:04:201049 command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_TABS_TO_RIGHT,
1050 normal_window);
1051 command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_OTHER_TABS,
1052 normal_window);
ellyjones0101ba02017-05-19 15:50:261053
Yuheng Huang092c72a92020-08-10 22:39:301054 command_updater_.UpdateCommandEnabled(
1055 IDC_TAB_SEARCH, base::FeatureList::IsEnabled(features::kTabSearch) &&
1056 browser_->is_type_normal() &&
1057 !browser_->profile()->IsIncognitoProfile());
1058
[email protected]338416c02014-05-13 16:47:061059 // Initialize other commands whose state changes based on various conditions.
[email protected]32dfede2013-08-25 15:48:251060 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:401061 UpdateCommandsForContentRestrictionState();
[email protected]5d98294912012-06-27 22:57:401062 UpdateCommandsForBookmarkEditing();
[email protected]5d98294912012-06-27 22:57:401063 UpdateCommandsForIncognitoAvailability();
Elly Fong-Jones5e6baaf2019-10-10 23:17:141064 UpdateCommandsForTabKeyboardFocus(GetKeyboardFocusedTabIndex(browser_));
Dominic Mazzoni1e0e51252020-10-19 19:36:181065 UpdateCommandsForWebContentsFocus();
[email protected]5d98294912012-06-27 22:57:401066}
1067
[email protected]05454532013-01-22 21:09:081068// static
1069void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
1070 CommandUpdater* command_updater,
1071 Profile* profile) {
mlermane01e6de2014-09-29 19:26:471072 const bool guest_session = profile->IsGuestSession();
1073 // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession().
[email protected]5d98294912012-06-27 22:57:401074 IncognitoModePrefs::Availability incognito_availability =
[email protected]05454532013-01-22 21:09:081075 IncognitoModePrefs::GetAvailability(profile->GetPrefs());
1076 command_updater->UpdateCommandEnabled(
Aran Gilmand217b5b2019-04-11 17:45:431077 IDC_NEW_WINDOW, incognito_availability != IncognitoModePrefs::FORCED);
[email protected]05454532013-01-22 21:09:081078 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:401079 IDC_NEW_INCOGNITO_WINDOW,
mlermane01e6de2014-09-29 19:26:471080 incognito_availability != IncognitoModePrefs::DISABLED && !guest_session);
[email protected]5d98294912012-06-27 22:57:401081
[email protected]57b25292014-05-01 16:31:061082 const bool forced_incognito =
1083 incognito_availability == IncognitoModePrefs::FORCED ||
1084 guest_session; // Guest always runs in Incognito mode.
[email protected]05454532013-01-22 21:09:081085 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:401086 IDC_SHOW_BOOKMARK_MANAGER,
[email protected]57b25292014-05-01 16:31:061087 browser_defaults::bookmarks_enabled && !forced_incognito);
Devlin Cronin21dba422018-05-30 15:45:161088 extensions::ExtensionService* extension_service =
[email protected]03d25812014-06-22 19:41:551089 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]57b25292014-05-01 16:31:061090 const bool enable_extensions =
[email protected]5d98294912012-06-27 22:57:401091 extension_service && extension_service->extensions_enabled();
[email protected]5d98294912012-06-27 22:57:401092
Elly Fong-Jones2d688ae2020-03-31 20:41:471093 command_updater->UpdateCommandEnabled(
1094 IDC_SHOW_FULL_URLS,
1095 base::FeatureList::IsEnabled(omnibox::kOmniboxContextMenuShowFullUrls));
1096
[email protected]57b25292014-05-01 16:31:061097 // Bookmark manager and settings page/subpages are forced to open in normal
1098 // mode. For this reason we disable these commands when incognito is forced.
1099 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
1100 enable_extensions && !forced_incognito);
1101
1102 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito);
1103 command_updater->UpdateCommandEnabled(IDC_OPTIONS,
1104 !forced_incognito || guest_session);
estade8c0780f2015-08-21 23:36:411105 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito);
[email protected]05454532013-01-22 21:09:081106}
1107
1108void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
Ivan Sandrk9669d0e2017-12-15 23:50:201109 if (is_locked_fullscreen_)
1110 return;
1111
[email protected]05454532013-01-22 21:09:081112 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile());
1113
[email protected]6a414ff2013-02-27 08:22:541114 if (!IsShowingMainUI()) {
[email protected]05454532013-01-22 21:09:081115 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false);
1116 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false);
1117 }
[email protected]5d98294912012-06-27 22:57:401118}
1119
1120void BrowserCommandController::UpdateCommandsForTabState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201121 if (is_locked_fullscreen_)
1122 return;
1123
[email protected]617ee962013-01-29 20:49:121124 WebContents* current_web_contents =
1125 browser_->tab_strip_model()->GetActiveWebContents();
[email protected]1c5119c2012-09-19 00:08:571126 if (!current_web_contents) // May be NULL during tab restore.
[email protected]5d98294912012-06-27 22:57:401127 return;
[email protected]5d98294912012-06-27 22:57:401128
1129 // Navigation commands
1130 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_));
1131 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_));
1132 command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_));
toyoshim7dad4b1182016-04-01 14:28:051133 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE,
[email protected]5d98294912012-06-27 22:57:401134 CanReload(browser_));
[email protected]58e29032012-08-06 20:19:571135 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE,
1136 CanReload(browser_));
[email protected]5d98294912012-06-27 22:57:401137
1138 // Window management commands
Aran Gilmand217b5b2019-04-11 17:45:431139 command_updater_.UpdateCommandEnabled(
Joel Hockey2687ab52019-08-14 23:59:461140 IDC_DUPLICATE_TAB,
1141 !browser_->deprecated_is_app() && CanDuplicateTab(browser_));
Tommy Steimelc4477982017-11-29 18:07:181142 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE,
Joel Hockey2687ab52019-08-14 23:59:461143 !browser_->deprecated_is_app());
ellyjones0101ba02017-05-19 15:50:261144 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB,
Joel Hockey2687ab52019-08-14 23:59:461145 !browser_->deprecated_is_app());
Connie Wan303e29e2020-01-31 18:16:561146 command_updater_.UpdateCommandEnabled(IDC_WINDOW_GROUP_TAB,
1147 !browser_->deprecated_is_app());
Elly Fong-Jones2d0443cb2019-11-14 15:04:201148 command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_TABS_TO_RIGHT,
1149 CanCloseTabsToRight(browser_));
1150 command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_OTHER_TABS,
1151 CanCloseOtherTabs(browser_));
Leonard Greyf13493b2019-12-19 18:12:571152 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_TO_NEW_WINDOW,
Leonard Greya8ecaa32020-01-07 20:57:411153 CanMoveActiveTabToNewWindow(browser_));
[email protected]5d98294912012-06-27 22:57:401154
1155 // Page-related commands
1156 window()->SetStarredState(
[email protected]1c5119c2012-09-19 00:08:571157 BookmarkTabHelper::FromWebContents(current_web_contents)->is_starred());
[email protected]5423c372012-08-22 05:50:161158 window()->ZoomChangedForActiveTab(false);
[email protected]5d98294912012-06-27 22:57:401159 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
1160 CanViewSource(browser_));
Joel Hockey2687ab52019-08-14 23:59:461161 if (browser_->is_type_devtools())
[email protected]5d98294912012-06-27 22:57:401162 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false);
1163
Glen Robertsonb9d27412020-01-09 06:48:131164 bool can_create_web_app = web_app::CanCreateWebApp(browser_);
1165 command_updater_.UpdateCommandEnabled(IDC_INSTALL_PWA, can_create_web_app);
Alan Cutter81ac726682018-09-25 00:18:361166 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUT,
Glen Robertsonb9d27412020-01-09 06:48:131167 can_create_web_app);
1168 // Note that additional logic in AppMenuModel::Build() controls the presence
1169 // of this command.
Alan Cutter403cebb2018-05-17 05:22:451170 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW,
Glen Robertsonb9d27412020-01-09 06:48:131171 web_app::CanPopOutWebApp(profile()));
[email protected]5d98294912012-06-27 22:57:401172
[email protected]9b7ab882012-09-10 23:46:361173 command_updater_.UpdateCommandEnabled(
1174 IDC_TOGGLE_REQUEST_TABLET_SITE,
1175 CanRequestTabletSite(current_web_contents));
1176
[email protected]5d98294912012-06-27 22:57:401177 UpdateCommandsForContentRestrictionState();
1178 UpdateCommandsForBookmarkEditing();
[email protected]3cac87232012-11-20 01:48:271179 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:411180 UpdateCommandsForMediaRouter();
[email protected]d93dbd12014-08-04 23:42:531181 // Update the zoom commands when an active tab is selected.
1182 UpdateCommandsForZoomState();
Elly Fong-Jones5e6baaf2019-10-10 23:17:141183 UpdateCommandsForTabKeyboardFocus(GetKeyboardFocusedTabIndex(browser_));
[email protected]d93dbd12014-08-04 23:42:531184}
1185
1186void BrowserCommandController::UpdateCommandsForZoomState() {
Aran Gilmand217b5b2019-04-11 17:45:431187 WebContents* contents = browser_->tab_strip_model()->GetActiveWebContents();
[email protected]d93dbd12014-08-04 23:42:531188 if (!contents)
1189 return;
Aran Gilmand217b5b2019-04-11 17:45:431190 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, CanZoomIn(contents));
a.sarkar.arundaadc712015-02-26 05:39:081191 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL,
ccameronb7c1d6c2015-03-09 17:08:241192 CanResetZoom(contents));
Aran Gilmand217b5b2019-04-11 17:45:431193 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, CanZoomOut(contents));
[email protected]5d98294912012-06-27 22:57:401194}
1195
1196void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
1197 int restrictions = GetContentRestrictions(browser_);
1198
1199 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011200 IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY));
[email protected]5d98294912012-06-27 22:57:401201 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011202 IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT));
[email protected]5d98294912012-06-27 22:57:401203 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011204 IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE));
[email protected]5d98294912012-06-27 22:57:401205 UpdateSaveAsState();
1206 UpdatePrintingState();
1207}
1208
1209void BrowserCommandController::UpdateCommandsForDevTools() {
Ivan Sandrk9669d0e2017-12-15 23:50:201210 if (is_locked_fullscreen_)
1211 return;
1212
Pavol Marko56df0272018-07-04 17:55:041213 bool dev_tools_enabled = DevToolsWindow::AllowDevToolsFor(
1214 profile(), browser_->tab_strip_model()->GetActiveWebContents());
Aran Gilmand217b5b2019-04-11 17:45:431215 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS, dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401216 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE,
1217 dev_tools_enabled);
[email protected]2056c3192013-10-21 22:40:511218 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES,
1219 dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401220 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT,
1221 dev_tools_enabled);
[email protected]d16657c2012-09-03 14:25:101222 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE,
1223 dev_tools_enabled);
Avi Drissman73ea864d2020-07-29 19:56:151224#if defined(OS_MAC)
spqchan2c5d541e2017-10-25 07:07:111225 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS,
1226 dev_tools_enabled);
1227#endif
[email protected]5d98294912012-06-27 22:57:401228}
1229
1230void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
Ivan Sandrk9669d0e2017-12-15 23:50:201231 if (is_locked_fullscreen_)
1232 return;
1233
Peter Kasting32bb2602019-08-22 19:01:431234 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_THIS_TAB,
1235 CanBookmarkCurrentTab(browser_));
[email protected]5d98294912012-06-27 22:57:401236 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
1237 CanBookmarkAllTabs(browser_));
thestig5149d272014-10-30 07:25:291238#if defined(OS_WIN)
1239 command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN, true);
1240#endif
[email protected]5d98294912012-06-27 22:57:401241}
1242
1243void BrowserCommandController::UpdateCommandsForBookmarkBar() {
Ivan Sandrk9669d0e2017-12-15 23:50:201244 if (is_locked_fullscreen_)
1245 return;
1246
tfarina3bddbe112014-08-28 05:29:321247 command_updater_.UpdateCommandEnabled(
Aran Gilmand217b5b2019-04-11 17:45:431248 IDC_SHOW_BOOKMARK_BAR, browser_defaults::bookmarks_enabled &&
1249 !profile()->IsGuestSession() &&
1250 !profile()->IsSystemProfile() &&
1251 !profile()->GetPrefs()->IsManagedPreference(
1252 bookmarks::prefs::kShowBookmarkBar) &&
1253 IsShowingMainUI());
[email protected]5d98294912012-06-27 22:57:401254}
1255
[email protected]9ec3ea5b2012-12-03 18:14:301256void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
Ivan Sandrk9669d0e2017-12-15 23:50:201257 if (is_locked_fullscreen_)
1258 return;
1259
[email protected]9ec3ea5b2012-12-03 18:14:301260 UpdateSaveAsState();
[email protected]05454532013-01-22 21:09:081261 UpdateOpenFileState(&command_updater_);
[email protected]9ec3ea5b2012-12-03 18:14:301262}
1263
[email protected]32dfede2013-08-25 15:48:251264void BrowserCommandController::UpdateCommandsForFullscreenMode() {
Ivan Sandrk9669d0e2017-12-15 23:50:201265 if (is_locked_fullscreen_)
1266 return;
1267
zijiehe3c7af992017-02-12 20:59:401268 const bool is_fullscreen = window() && window()->IsFullscreen();
1269 const bool show_main_ui = IsShowingMainUI();
manukf1a116392018-10-25 16:28:241270 const bool show_location_bar = IsShowingLocationBar();
1271
zijiehe3c7af992017-02-12 20:59:401272 const bool main_not_fullscreen = show_main_ui && !is_fullscreen;
[email protected]5d98294912012-06-27 22:57:401273
1274 // Navigation commands
1275 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1276
1277 // Window management commands
1278 command_updater_.UpdateCommandEnabled(
Joel Hockey2687ab52019-08-14 23:59:461279 IDC_SHOW_AS_TAB, !browser_->is_type_normal() && !is_fullscreen);
[email protected]5d98294912012-06-27 22:57:401280
1281 // Focus various bits of UI
1282 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
manukf1a116392018-10-25 16:28:241283 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_location_bar);
[email protected]5d98294912012-06-27 22:57:401284 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
Aran Gilmand217b5b2019-04-11 17:45:431285 command_updater_.UpdateCommandEnabled(IDC_FOCUS_MENU_BAR,
1286 main_not_fullscreen);
1287 command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE,
1288 main_not_fullscreen);
1289 command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE,
1290 main_not_fullscreen);
1291 command_updater_.UpdateCommandEnabled(IDC_FOCUS_BOOKMARKS,
1292 main_not_fullscreen);
[email protected]822ca8c62013-04-19 00:49:151293 command_updater_.UpdateCommandEnabled(
David Tsengc0b1b642018-01-24 07:12:271294 IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY, main_not_fullscreen);
[email protected]5d98294912012-06-27 22:57:401295
1296 // Show various bits of UI
1297 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui);
Nico Weber0cc71122019-07-29 17:30:401298#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
Fabio Rocha19bf4262019-04-04 01:05:181299 command_updater_.UpdateCommandEnabled(
Joel Hockey2687ab52019-08-14 23:59:461300 IDC_FEEDBACK, show_main_ui || browser_->is_type_devtools());
[email protected]236ad3022013-09-04 03:27:431301#endif
Mihai Sardarescu2ec5205682018-09-26 09:20:051302 UpdateShowSyncState(show_main_ui);
[email protected]5d98294912012-06-27 22:57:401303
[email protected]5d98294912012-06-27 22:57:401304 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
1305 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
1306 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
Travis Skare5193bbe12020-04-15 18:31:031307 command_updater_.UpdateCommandEnabled(IDC_QRCODE_GENERATOR, show_main_ui);
[email protected]5d98294912012-06-27 22:57:401308 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
Tina Wangf09681ac2019-03-27 20:52:101309 command_updater_.UpdateCommandEnabled(IDC_SEND_TAB_TO_SELF, show_main_ui);
Tina Wangfa016992019-05-31 00:01:151310 command_updater_.UpdateCommandEnabled(IDC_SEND_TAB_TO_SELF_SINGLE_TARGET,
1311 show_main_ui);
Yann Dago70ca3dd2019-02-27 01:12:351312 command_updater_.UpdateCommandEnabled(IDC_SHOW_MANAGEMENT_PAGE, true);
primianod3a81ab2016-01-25 22:21:151313
1314 if (base::debug::IsProfilingSupported())
1315 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
[email protected]5d98294912012-06-27 22:57:401316
Avi Drissman73ea864d2020-07-29 19:56:151317#if !defined(OS_MAC)
zijiehe3c7af992017-02-12 20:59:401318 // Disable toggling into fullscreen mode if disallowed by pref.
Aran Gilmand217b5b2019-04-11 17:45:431319 const bool fullscreen_enabled =
1320 is_fullscreen ||
zijiehe3c7af992017-02-12 20:59:401321 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed);
1322#else
1323 const bool fullscreen_enabled = true;
[email protected]00a1cc5b2012-11-07 13:44:511324#endif
1325
1326 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled);
spqchanb8ffc7d2015-11-17 01:17:211327 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR,
1328 fullscreen_enabled);
[email protected]5d98294912012-06-27 22:57:401329
1330 UpdateCommandsForBookmarkBar();
zijiehedb473d552017-02-24 01:13:411331 UpdateCommandsForIncognitoAvailability();
Alan Cutter167dfe82018-04-11 09:06:001332 UpdateCommandsForHostedAppAvailability();
1333}
1334
1335void BrowserCommandController::UpdateCommandsForHostedAppAvailability() {
1336 bool has_toolbar =
Joel Hockey2687ab52019-08-14 23:59:461337 browser_->is_type_normal() ||
Alan Cutterd0bd51902019-05-22 04:15:231338 web_app::AppBrowserController::IsForWebAppBrowser(browser_);
Alan Cutter167dfe82018-04-11 09:06:001339 if (window() && window()->ShouldHideUIForFullscreen())
1340 has_toolbar = false;
1341 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, has_toolbar);
1342 command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE, has_toolbar);
1343 command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE, has_toolbar);
1344 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, has_toolbar);
[email protected]5d98294912012-06-27 22:57:401345}
1346
Ivan Sandrk9669d0e2017-12-15 23:50:201347#if defined(OS_CHROMEOS)
1348namespace {
1349
1350#if DCHECK_IS_ON()
Dana Fried88e6f472020-06-30 22:47:401351// Makes sure that all commands that are not allowlisted are disabled. DCHECKs
Ivan Sandrk9669d0e2017-12-15 23:50:201352// otherwise. Compiled only in debug mode.
Dana Fried88e6f472020-06-30 22:47:401353void NonAllowlistedCommandsAreDisabled(CommandUpdaterImpl* command_updater) {
1354 constexpr int kAllowlistedIds[] = {IDC_CUT, IDC_COPY, IDC_PASTE};
Ivan Sandrk9669d0e2017-12-15 23:50:201355
Dana Fried88e6f472020-06-30 22:47:401356 // Go through all the command ids, skip the allowlisted ones.
Ivan Sandrk9669d0e2017-12-15 23:50:201357 for (int id : command_updater->GetAllIds()) {
Dana Fried88e6f472020-06-30 22:47:401358 if (base::Contains(kAllowlistedIds, id)) {
Ivan Sandrk9669d0e2017-12-15 23:50:201359 continue;
1360 }
1361 DCHECK(!command_updater->IsCommandEnabled(id));
1362 }
1363}
1364#endif
1365
1366} // namespace
1367
1368void BrowserCommandController::UpdateCommandsForLockedFullscreenMode() {
Ivan Sandrke0e92452019-03-21 09:32:481369 bool is_locked_fullscreen =
1370 platform_util::IsBrowserLockedFullscreen(browser_);
Ivan Sandrk9669d0e2017-12-15 23:50:201371 // Sanity check to make sure this function is called only on state change.
1372 DCHECK_NE(is_locked_fullscreen, is_locked_fullscreen_);
1373 if (is_locked_fullscreen == is_locked_fullscreen_)
1374 return;
1375 is_locked_fullscreen_ = is_locked_fullscreen;
1376
1377 if (is_locked_fullscreen_) {
1378 command_updater_.DisableAllCommands();
Dana Fried88e6f472020-06-30 22:47:401379 // Update the state of allowlisted commands:
Ivan Sandrk9669d0e2017-12-15 23:50:201380 // IDC_CUT/IDC_COPY/IDC_PASTE,
1381 UpdateCommandsForContentRestrictionState();
Ivan Sandrk6ac9c9a2018-12-14 14:15:071382 // TODO(crbug.com/904637): Re-enable Find and Zoom in locked fullscreen.
Ivan Sandrk9669d0e2017-12-15 23:50:201383 // All other commands will be disabled (there is an early return in their
1384 // corresponding UpdateCommandsFor* functions).
1385#if DCHECK_IS_ON()
Dana Fried88e6f472020-06-30 22:47:401386 NonAllowlistedCommandsAreDisabled(&command_updater_);
Ivan Sandrk9669d0e2017-12-15 23:50:201387#endif
1388 } else {
1389 // Do an init call to re-initialize command state after the
1390 // DisableAllCommands.
1391 InitCommandState();
1392 }
1393}
1394#endif
1395
[email protected]5d98294912012-06-27 22:57:401396void BrowserCommandController::UpdatePrintingState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201397 if (is_locked_fullscreen_)
1398 return;
1399
[email protected]d53e4032012-06-29 18:58:341400 bool print_enabled = CanPrint(browser_);
1401 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
Lei Zhang48a4a5262018-04-17 20:18:441402#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:551403 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT,
1404 CanBasicPrint(browser_));
Lei Zhang48a4a5262018-04-17 20:18:441405#endif
[email protected]5d98294912012-06-27 22:57:401406}
1407
1408void BrowserCommandController::UpdateSaveAsState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201409 if (is_locked_fullscreen_)
1410 return;
1411
[email protected]5d98294912012-06-27 22:57:401412 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_));
1413}
1414
Mihai Sardarescu2ec5205682018-09-26 09:20:051415void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) {
1416 if (is_locked_fullscreen_)
1417 return;
1418
Mihai Sardarescuf87ccc12018-09-26 10:37:451419 command_updater_.UpdateCommandEnabled(
Mihai Sardarescu290bc882018-10-12 10:48:141420 IDC_SHOW_SIGNIN, show_main_ui && pref_signin_allowed_.GetValue());
Mihai Sardarescu2ec5205682018-09-26 09:20:051421}
1422
[email protected]05454532013-01-22 21:09:081423// static
1424void BrowserCommandController::UpdateOpenFileState(
1425 CommandUpdater* command_updater) {
[email protected]5d98294912012-06-27 22:57:401426 bool enabled = true;
1427 PrefService* local_state = g_browser_process->local_state();
1428 if (local_state)
1429 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs);
1430
[email protected]05454532013-01-22 21:09:081431 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled);
[email protected]5d98294912012-06-27 22:57:401432}
1433
1434void BrowserCommandController::UpdateReloadStopState(bool is_loading,
1435 bool force) {
Ivan Sandrk9669d0e2017-12-15 23:50:201436 if (is_locked_fullscreen_)
1437 return;
1438
[email protected]5d98294912012-06-27 22:57:401439 window()->UpdateReloadStopState(is_loading, force);
1440 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
Jeff Fisher6cc1ce7b2019-06-28 23:02:381441 UpdateCloseFindOrStop();
[email protected]5d98294912012-06-27 22:57:401442}
1443
[email protected]2e9369e2014-08-15 09:12:531444void BrowserCommandController::UpdateTabRestoreCommandState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201445 if (is_locked_fullscreen_)
1446 return;
1447
blundell74001adc2015-09-18 11:04:251448 sessions::TabRestoreService* tab_restore_service =
[email protected]2e9369e2014-08-15 09:12:531449 TabRestoreServiceFactory::GetForProfile(profile());
1450 // The command is enabled if the service hasn't loaded yet to trigger loading.
1451 // The command is updated once the load completes.
1452 command_updater_.UpdateCommandEnabled(
1453 IDC_RESTORE_TAB,
Peter Kasting32bb2602019-08-22 19:01:431454 tab_restore_service && (!tab_restore_service->IsLoaded() ||
1455 !tab_restore_service->entries().empty()));
[email protected]2e9369e2014-08-15 09:12:531456}
1457
[email protected]3cac87232012-11-20 01:48:271458void BrowserCommandController::UpdateCommandsForFind() {
1459 TabStripModel* model = browser_->tab_strip_model();
Joel Hockey2687ab52019-08-14 23:59:461460 bool enabled = !model->IsTabBlocked(model->active_index()) &&
1461 !browser_->is_type_devtools();
[email protected]3cac87232012-11-20 01:48:271462
1463 command_updater_.UpdateCommandEnabled(IDC_FIND, enabled);
1464 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled);
1465 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled);
1466}
1467
Jeff Fisher6cc1ce7b2019-06-28 23:02:381468void BrowserCommandController::UpdateCloseFindOrStop() {
1469 bool enabled = CanCloseFind(browser_) || IsCommandEnabled(IDC_STOP);
1470 command_updater_.UpdateCommandEnabled(IDC_CLOSE_FIND_OR_STOP, enabled);
1471}
1472
apacible45cbfc92015-09-28 22:45:411473void BrowserCommandController::UpdateCommandsForMediaRouter() {
Ivan Sandrk9669d0e2017-12-15 23:50:201474 if (is_locked_fullscreen_)
1475 return;
1476
apacible45cbfc92015-09-28 22:45:411477 command_updater_.UpdateCommandEnabled(IDC_ROUTE_MEDIA,
1478 CanRouteMedia(browser_));
1479}
1480
Elly Fong-Jones5e6baaf2019-10-10 23:17:141481void BrowserCommandController::UpdateCommandsForTabKeyboardFocus(
1482 base::Optional<int> target_index) {
1483 command_updater_.UpdateCommandEnabled(
1484 IDC_DUPLICATE_TARGET_TAB, !browser_->deprecated_is_app() &&
1485 target_index.has_value() &&
1486 CanDuplicateTabAt(browser_, *target_index));
1487 const bool normal_window = browser_->is_type_normal();
1488 command_updater_.UpdateCommandEnabled(
1489 IDC_MUTE_TARGET_SITE, normal_window && target_index.has_value());
1490 command_updater_.UpdateCommandEnabled(
1491 IDC_PIN_TARGET_TAB, normal_window && target_index.has_value());
Connie Wan303e29e2020-01-31 18:16:561492 command_updater_.UpdateCommandEnabled(
1493 IDC_GROUP_TARGET_TAB, normal_window && target_index.has_value());
Elly Fong-Jones5e6baaf2019-10-10 23:17:141494}
1495
Dominic Mazzoni1e0e51252020-10-19 19:36:181496void BrowserCommandController::UpdateCommandsForWebContentsFocus() {
1497#if defined(OS_MAC)
1498 // On Mac, toggling caret browsing changes whether it's enabled or not
1499 // based on web contents focus.
1500 command_updater_.UpdateCommandEnabled(IDC_CARET_BROWSING_TOGGLE,
1501 CanToggleCaretBrowsing(browser_));
1502#endif // defined(OS_MAC)
1503}
1504
[email protected]5d98294912012-06-27 22:57:401505BrowserWindow* BrowserCommandController::window() {
1506 return browser_->window();
1507}
1508
1509Profile* BrowserCommandController::profile() {
1510 return browser_->profile();
1511}
1512
[email protected]5d98294912012-06-27 22:57:401513} // namespace chrome