blob: 28cf983dfc40bbef21801daa656b97d40a375fce [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"
Eric Willigers4a5f7a92019-05-10 19:19:2644#include "chrome/browser/ui/web_applications/app_browser_controller.h"
Glen Robertsonb9d27412020-01-09 06:48:1345#include "chrome/browser/ui/web_applications/web_app_dialog_utils.h"
Eric Willigerse2ca235a2019-08-17 01:01:0646#include "chrome/browser/ui/web_applications/web_app_launch_utils.h"
[email protected]2056c3192013-10-21 22:40:5147#include "chrome/browser/ui/webui/inspect_ui.h"
[email protected]3c71576ce2013-07-23 02:00:0148#include "chrome/common/content_restriction.h"
[email protected]5d98294912012-06-27 22:57:4049#include "chrome/common/pref_names.h"
Nicolas Ouellet-payeur82eb65b2018-11-05 16:49:2750#include "chrome/common/url_constants.h"
brettwe1f0af8b2015-10-09 21:30:4651#include "components/bookmarks/common/bookmark_pref_names.h"
Aran Gilman7b6ccf5d2019-09-05 19:16:0252#include "components/dom_distiller/core/dom_distiller_features.h"
Scott Violet9ae82892018-03-01 18:38:1253#include "components/feature_engagement/buildflags.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
[email protected]9c4d68332013-01-30 13:34:4170#if defined(OS_MACOSX)
71#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
Collin Baker4ab8ad82019-06-06 17:02:5490#if BUILDFLAG(ENABLE_LEGACY_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:1491#include "chrome/browser/feature_engagement/bookmark/bookmark_tracker.h"
92#include "chrome/browser/feature_engagement/bookmark/bookmark_tracker_factory.h"
Catherine Chungbeb884222017-08-01 15:47:5593#include "chrome/browser/feature_engagement/new_tab/new_tab_tracker.h"
94#include "chrome/browser/feature_engagement/new_tab/new_tab_tracker_factory.h"
95#endif
96
Maksim Sisovac767592018-08-10 08:00:1597#if defined(USE_OZONE)
Maksim Sisovb0643ebd2020-06-22 11:47:3198#include "ui/base/ui_base_features.h"
Maksim Sisovac767592018-08-10 08:00:1599#include "ui/ozone/public/ozone_platform.h"
100#endif
101
[email protected]5d98294912012-06-27 22:57:40102using content::NavigationController;
Aran Gilmand217b5b2019-04-11 17:45:43103using content::NavigationEntry;
[email protected]5d98294912012-06-27 22:57:40104using content::WebContents;
105
[email protected]5d98294912012-06-27 22:57:40106namespace chrome {
107
Dana Fried08b774a2019-05-10 18:21:48108namespace {
109
110// Ensures that - if we have not popped up an infobar to prompt the user to e.g.
111// reload the current page - that the content pane of the browser is refocused.
112void AppInfoDialogClosedCallback(content::WebContents* web_contents,
Dana Fried98c0380e2019-05-14 16:58:32113 views::Widget::ClosedReason closed_reason,
Dana Fried08b774a2019-05-10 18:21:48114 bool reload_prompt) {
115 if (reload_prompt)
116 return;
117
Dana Fried98c0380e2019-05-14 16:58:32118 // If the user clicked on something specific or focus was changed, don't
119 // override the focus.
120 if (closed_reason != views::Widget::ClosedReason::kEscKeyPressed &&
121 closed_reason != views::Widget::ClosedReason::kCloseButtonClicked) {
122 return;
123 }
124
Dana Fried08b774a2019-05-10 18:21:48125 // Ensure that the web contents handle we have is still valid. It's possible
126 // (though unlikely) that either the browser or web contents has been pulled
127 // out from underneath us.
128 Browser* const browser = chrome::FindBrowserWithWebContents(web_contents);
129 if (!browser)
130 return;
131
132 // We want to focus the active web contents, which again, might not be the
133 // original web contents (though it should be the vast majority of the time).
134 content::WebContents* const active_contents =
135 browser->tab_strip_model()->GetActiveWebContents();
136 if (active_contents)
137 active_contents->Focus();
138}
139
140} // namespace
141
[email protected]5d98294912012-06-27 22:57:40142///////////////////////////////////////////////////////////////////////////////
143// BrowserCommandController, public:
144
[email protected]338416c02014-05-13 16:47:06145BrowserCommandController::BrowserCommandController(Browser* browser)
Aran Gilmand217b5b2019-04-11 17:45:43146 : browser_(browser), command_updater_(nullptr) {
[email protected]5d98294912012-06-27 22:57:40147 browser_->tab_strip_model()->AddObserver(this);
148 PrefService* local_state = g_browser_process->local_state();
149 if (local_state) {
150 local_pref_registrar_.Init(local_state);
[email protected]9ec3ea5b2012-12-03 18:14:30151 local_pref_registrar_.Add(
152 prefs::kAllowFileSelectionDialogs,
153 base::Bind(
154 &BrowserCommandController::UpdateCommandsForFileSelectionDialogs,
155 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40156 }
157
158 profile_pref_registrar_.Init(profile()->GetPrefs());
[email protected]9ec3ea5b2012-12-03 18:14:30159 profile_pref_registrar_.Add(
Pavol Markodebb0ff2018-05-07 18:35:41160 prefs::kDevToolsAvailability,
[email protected]9ec3ea5b2012-12-03 18:14:30161 base::Bind(&BrowserCommandController::UpdateCommandsForDevTools,
162 base::Unretained(this)));
163 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32164 bookmarks::prefs::kEditBookmarksEnabled,
[email protected]9ec3ea5b2012-12-03 18:14:30165 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkEditing,
166 base::Unretained(this)));
167 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32168 bookmarks::prefs::kShowBookmarkBar,
[email protected]9ec3ea5b2012-12-03 18:14:30169 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkBar,
170 base::Unretained(this)));
171 profile_pref_registrar_.Add(
172 prefs::kIncognitoModeAvailability,
173 base::Bind(
174 &BrowserCommandController::UpdateCommandsForIncognitoAvailability,
175 base::Unretained(this)));
176 profile_pref_registrar_.Add(
177 prefs::kPrintingEnabled,
178 base::Bind(&BrowserCommandController::UpdatePrintingState,
179 base::Unretained(this)));
[email protected]32dfede2013-08-25 15:48:25180#if !defined(OS_MACOSX)
181 profile_pref_registrar_.Add(
182 prefs::kFullscreenAllowed,
183 base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode,
184 base::Unretained(this)));
185#endif
Mihai Sardarescuf87ccc12018-09-26 10:37:45186 pref_signin_allowed_.Init(
Aran Gilmand217b5b2019-04-11 17:45:43187 prefs::kSigninAllowed, profile()->GetOriginalProfile()->GetPrefs(),
Mihai Sardarescuf87ccc12018-09-26 10:37:45188 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange,
189 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40190
191 InitCommandState();
192
blundell74001adc2015-09-18 11:04:25193 sessions::TabRestoreService* tab_restore_service =
[email protected]5d98294912012-06-27 22:57:40194 TabRestoreServiceFactory::GetForProfile(profile());
195 if (tab_restore_service) {
196 tab_restore_service->AddObserver(this);
Cliff Smolinsky2c9586e2019-02-08 18:48:30197 if (!tab_restore_service->IsLoaded())
198 tab_restore_service->LoadTabsFromLastSession();
[email protected]5d98294912012-06-27 22:57:40199 }
[email protected]5d98294912012-06-27 22:57:40200}
201
202BrowserCommandController::~BrowserCommandController() {
[email protected]95e39472012-10-05 23:37:36203 // TabRestoreService may have been shutdown by the time we get here. Don't
204 // trigger creating it.
blundell74001adc2015-09-18 11:04:25205 sessions::TabRestoreService* tab_restore_service =
[email protected]95e39472012-10-05 23:37:36206 TabRestoreServiceFactory::GetForProfileIfExisting(profile());
[email protected]5d98294912012-06-27 22:57:40207 if (tab_restore_service)
208 tab_restore_service->RemoveObserver(this);
209 profile_pref_registrar_.RemoveAll();
210 local_pref_registrar_.RemoveAll();
211 browser_->tab_strip_model()->RemoveObserver(this);
212}
213
214bool BrowserCommandController::IsReservedCommandOrKey(
215 int command_id,
216 const content::NativeWebKeyboardEvent& event) {
217 // In Apps mode, no keys are reserved.
Leonard Grey345662a82020-02-07 21:20:03218 if (browser_->is_type_app() || browser_->is_type_app_popup())
[email protected]5d98294912012-06-27 22:57:40219 return false;
220
221#if defined(OS_CHROMEOS)
[email protected]397abd32013-08-21 05:44:19222 // On Chrome OS, the top row of keys are mapped to browser actions like
223 // back/forward or refresh. We don't want web pages to be able to change the
224 // behavior of these keys. Ash handles F4 and up; this leaves us needing to
225 // reserve browser back/forward and refresh here.
[email protected]5d98294912012-06-27 22:57:40226 ui::KeyboardCode key_code =
Blink Reformat1c4d759e2017-04-09 16:34:54227 static_cast<ui::KeyboardCode>(event.windows_key_code);
[email protected]397abd32013-08-21 05:44:19228 if ((key_code == ui::VKEY_BROWSER_BACK && command_id == IDC_BACK) ||
229 (key_code == ui::VKEY_BROWSER_FORWARD && command_id == IDC_FORWARD) ||
230 (key_code == ui::VKEY_BROWSER_REFRESH && command_id == IDC_RELOAD)) {
[email protected]5d98294912012-06-27 22:57:40231 return true;
232 }
233#endif
234
zijiehe68cd3dc22017-04-07 18:50:29235 if (window()->IsFullscreen()) {
236 // In fullscreen, all commands except for IDC_FULLSCREEN and IDC_EXIT should
237 // be delivered to the web page. The intent to implement and ship can be
238 // found in http://crbug.com/680809.
239 const bool is_exit_fullscreen =
240 (command_id == IDC_EXIT || command_id == IDC_FULLSCREEN);
241#if defined(OS_MACOSX)
242 // This behavior is different on Mac OS, which has a unique user-initiated
243 // full-screen mode. According to the discussion in http://crbug.com/702251,
244 // the commands should be reserved for browser-side handling if the browser
245 // window's toolbar is visible.
246 if (window()->IsToolbarShowing()) {
247 if (command_id == IDC_FULLSCREEN)
248 return true;
249 } else {
250 return is_exit_fullscreen;
251 }
252#else
253 return is_exit_fullscreen;
254#endif
255 }
[email protected]1e2172f2014-04-01 17:32:34256
[email protected]893124a22014-04-15 00:45:28257#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]1e2172f2014-04-01 17:32:34258 // If this key was registered by the user as a content editing hotkey, then
259 // it is not reserved.
[email protected]d5bedb6d2014-04-08 10:49:32260 ui::TextEditKeyBindingsDelegateAuraLinux* delegate =
[email protected]1e2172f2014-04-01 17:32:34261 ui::GetTextEditKeyBindingsDelegate();
[email protected]47e8e7542014-04-03 07:52:42262 if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL))
[email protected]1e2172f2014-04-01 17:32:34263 return false;
264#endif
265
Aran Gilmand217b5b2019-04-11 17:45:43266 return command_id == IDC_CLOSE_TAB || command_id == IDC_CLOSE_WINDOW ||
267 command_id == IDC_NEW_INCOGNITO_WINDOW || command_id == IDC_NEW_TAB ||
268 command_id == IDC_NEW_WINDOW || command_id == IDC_RESTORE_TAB ||
zijiehe13207802017-02-16 08:06:10269 command_id == IDC_SELECT_NEXT_TAB ||
Aran Gilmand217b5b2019-04-11 17:45:43270 command_id == IDC_SELECT_PREVIOUS_TAB || command_id == IDC_EXIT;
[email protected]5d98294912012-06-27 22:57:40271}
272
[email protected]5d98294912012-06-27 22:57:40273void BrowserCommandController::TabStateChanged() {
274 UpdateCommandsForTabState();
275}
276
[email protected]d93dbd12014-08-04 23:42:53277void BrowserCommandController::ZoomStateChanged() {
278 UpdateCommandsForZoomState();
279}
280
[email protected]5d98294912012-06-27 22:57:40281void BrowserCommandController::ContentRestrictionsChanged() {
282 UpdateCommandsForContentRestrictionState();
283}
284
285void BrowserCommandController::FullscreenStateChanged() {
[email protected]32dfede2013-08-25 15:48:25286 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40287}
288
Ivan Sandrk9669d0e2017-12-15 23:50:20289#if defined(OS_CHROMEOS)
290void BrowserCommandController::LockedFullscreenStateChanged() {
291 UpdateCommandsForLockedFullscreenMode();
292}
293#endif
294
[email protected]5d98294912012-06-27 22:57:40295void BrowserCommandController::PrintingStateChanged() {
296 UpdatePrintingState();
297}
298
299void BrowserCommandController::LoadingStateChanged(bool is_loading,
300 bool force) {
301 UpdateReloadStopState(is_loading, force);
302}
303
Jeff Fisher6cc1ce7b2019-06-28 23:02:38304void BrowserCommandController::FindBarVisibilityChanged() {
305 if (is_locked_fullscreen_)
306 return;
307 UpdateCloseFindOrStop();
308}
309
wittman76df71db32014-12-18 23:26:58310void BrowserCommandController::ExtensionStateChanged() {
311 // Extensions may disable the bookmark editing commands.
312 UpdateCommandsForBookmarkEditing();
313}
314
Elly Fong-Jones5e6baaf2019-10-10 23:17:14315void BrowserCommandController::TabKeyboardFocusChangedTo(
316 base::Optional<int> index) {
317 UpdateCommandsForTabKeyboardFocus(index);
318}
319
[email protected]5d98294912012-06-27 22:57:40320////////////////////////////////////////////////////////////////////////////////
Ivan Sandrk9669d0e2017-12-15 23:50:20321// BrowserCommandController, CommandUpdater implementation:
[email protected]5d98294912012-06-27 22:57:40322
Ivan Sandrk9669d0e2017-12-15 23:50:20323bool BrowserCommandController::SupportsCommand(int id) const {
324 return command_updater_.SupportsCommand(id);
325}
326
327bool BrowserCommandController::IsCommandEnabled(int id) const {
328 return command_updater_.IsCommandEnabled(id);
329}
330
Edwin Joe6f6fc1e2019-02-27 20:00:37331bool BrowserCommandController::ExecuteCommand(int id,
332 base::TimeTicks time_stamp) {
333 return ExecuteCommandWithDisposition(id, WindowOpenDisposition::CURRENT_TAB,
334 time_stamp);
Ivan Sandrk9669d0e2017-12-15 23:50:20335}
336
337bool BrowserCommandController::ExecuteCommandWithDisposition(
Edwin Joe6f6fc1e2019-02-27 20:00:37338 int id,
339 WindowOpenDisposition disposition,
340 base::TimeTicks time_stamp) {
Ivan Sandrk9669d0e2017-12-15 23:50:20341 // Doesn't go through the command_updater_ to avoid dealing with having a
342 // naming collision for ExecuteCommandWithDisposition (both
343 // CommandUpdaterDelegate and CommandUpdater declare this function so we
344 // choose to not implement CommandUpdaterDelegate inside this class and
345 // therefore command_updater_ doesn't have the delegate set).
346 if (!SupportsCommand(id) || !IsCommandEnabled(id))
347 return false;
348
[email protected]5d98294912012-06-27 22:57:40349 // No commands are enabled if there is not yet any selected tab.
350 // TODO(pkasting): It seems like we should not need this, because either
351 // most/all commands should not have been enabled yet anyway or the ones that
352 // are enabled should be global, or safe themselves against having no selected
353 // tab. However, Ben says he tried removing this before and got lots of
354 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
355 // window construction. This probably could use closer examination someday.
[email protected]59253a652012-11-20 00:17:26356 if (browser_->tab_strip_model()->active_index() == TabStripModel::kNoTab)
Ivan Sandrk9669d0e2017-12-15 23:50:20357 return true;
[email protected]5d98294912012-06-27 22:57:40358
Aran Gilmand217b5b2019-04-11 17:45:43359 DCHECK(command_updater_.IsCommandEnabled(id))
360 << "Invalid/disabled command " << id;
[email protected]5d98294912012-06-27 22:57:40361
[email protected]5d98294912012-06-27 22:57:40362 // The order of commands in this switch statement must match the function
363 // declaration order in browser.h!
364 switch (id) {
365 // Navigation commands
366 case IDC_BACK:
367 GoBack(browser_, disposition);
368 break;
369 case IDC_FORWARD:
370 GoForward(browser_, disposition);
371 break;
372 case IDC_RELOAD:
373 Reload(browser_, disposition);
374 break;
[email protected]58e29032012-08-06 20:19:57375 case IDC_RELOAD_CLEARING_CACHE:
376 ClearCache(browser_);
Nico Webera745ef72018-01-29 23:45:57377 FALLTHROUGH;
toyoshim7dad4b1182016-04-01 14:28:05378 case IDC_RELOAD_BYPASSING_CACHE:
379 ReloadBypassingCache(browser_, disposition);
[email protected]5d98294912012-06-27 22:57:40380 break;
381 case IDC_HOME:
382 Home(browser_, disposition);
383 break;
384 case IDC_OPEN_CURRENT_URL:
385 OpenCurrentURL(browser_);
386 break;
387 case IDC_STOP:
388 Stop(browser_);
389 break;
390
Aran Gilmand217b5b2019-04-11 17:45:43391 // Window management commands
[email protected]5d98294912012-06-27 22:57:40392 case IDC_NEW_WINDOW:
393 NewWindow(browser_);
394 break;
395 case IDC_NEW_INCOGNITO_WINDOW:
Orin Jaworski5e4bcd0c2018-10-16 19:35:05396 NewIncognitoWindow(profile());
[email protected]5d98294912012-06-27 22:57:40397 break;
398 case IDC_CLOSE_WINDOW:
bratell0a7406f2017-03-28 07:46:37399 base::RecordAction(base::UserMetricsAction("CloseWindowByKey"));
[email protected]04b9e692012-08-24 14:49:09400 CloseWindow(browser_);
[email protected]5d98294912012-06-27 22:57:40401 break;
Bettina Dea0a4505922017-09-28 00:53:32402 case IDC_NEW_TAB: {
403 NewTab(browser_);
Collin Baker4ab8ad82019-06-06 17:02:54404#if BUILDFLAG(ENABLE_LEGACY_DESKTOP_IN_PRODUCT_HELP)
Catherine Chungbeb884222017-08-01 15:47:55405 // This is not in NewTab() to avoid tracking programmatic creation of new
406 // tabs by extensions.
Bettina Dea0a4505922017-09-28 00:53:32407 auto* new_tab_tracker =
408 feature_engagement::NewTabTrackerFactory::GetInstance()
409 ->GetForProfile(profile());
410
411 new_tab_tracker->OnNewTabOpened();
412 new_tab_tracker->CloseBubble();
Catherine Chungbeb884222017-08-01 15:47:55413#endif
[email protected]5d98294912012-06-27 22:57:40414 break;
Bettina Dea0a4505922017-09-28 00:53:32415 }
[email protected]5d98294912012-06-27 22:57:40416 case IDC_CLOSE_TAB:
bratell0a7406f2017-03-28 07:46:37417 base::RecordAction(base::UserMetricsAction("CloseTabByKey"));
[email protected]04b9e692012-08-24 14:49:09418 CloseTab(browser_);
[email protected]5d98294912012-06-27 22:57:40419 break;
420 case IDC_SELECT_NEXT_TAB:
bratell0a7406f2017-03-28 07:46:37421 base::RecordAction(base::UserMetricsAction("Accel_SelectNextTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37422 SelectNextTab(browser_,
423 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40424 break;
425 case IDC_SELECT_PREVIOUS_TAB:
bratell0a7406f2017-03-28 07:46:37426 base::RecordAction(base::UserMetricsAction("Accel_SelectPreviousTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37427 SelectPreviousTab(browser_,
428 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40429 break;
[email protected]5d98294912012-06-27 22:57:40430 case IDC_MOVE_TAB_NEXT:
431 MoveTabNext(browser_);
432 break;
433 case IDC_MOVE_TAB_PREVIOUS:
434 MoveTabPrevious(browser_);
435 break;
436 case IDC_SELECT_TAB_0:
437 case IDC_SELECT_TAB_1:
438 case IDC_SELECT_TAB_2:
439 case IDC_SELECT_TAB_3:
440 case IDC_SELECT_TAB_4:
441 case IDC_SELECT_TAB_5:
442 case IDC_SELECT_TAB_6:
443 case IDC_SELECT_TAB_7:
bratell0a7406f2017-03-28 07:46:37444 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37445 SelectNumberedTab(browser_, id - IDC_SELECT_TAB_0,
446 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40447 break;
448 case IDC_SELECT_LAST_TAB:
bratell0a7406f2017-03-28 07:46:37449 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37450 SelectLastTab(browser_,
451 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40452 break;
453 case IDC_DUPLICATE_TAB:
454 DuplicateTab(browser_);
455 break;
456 case IDC_RESTORE_TAB:
457 RestoreTab(browser_);
Collin Baker9bbe1d82019-03-08 01:16:27458 browser_->window()->OnTabRestored(IDC_RESTORE_TAB);
[email protected]5d98294912012-06-27 22:57:40459 break;
[email protected]5d98294912012-06-27 22:57:40460 case IDC_SHOW_AS_TAB:
461 ConvertPopupToTabbedBrowser(browser_);
462 break;
463 case IDC_FULLSCREEN:
[email protected]3f32b9b2012-07-09 16:59:28464 chrome::ToggleFullscreenMode(browser_);
[email protected]5d98294912012-06-27 22:57:40465 break;
Alan Cutter09965802018-03-27 07:25:29466 case IDC_OPEN_IN_PWA_WINDOW:
467 base::RecordAction(base::UserMetricsAction("OpenActiveTabInPwaWindow"));
Alan Cutter42356022020-02-20 06:44:13468 web_app::ReparentWebAppForActiveTab(browser_);
Alan Cutter09965802018-03-27 07:25:29469 break;
Leonard Greyf13493b2019-12-19 18:12:57470 case IDC_MOVE_TAB_TO_NEW_WINDOW:
Leonard Greya8ecaa32020-01-07 20:57:41471 MoveActiveTabToNewWindow(browser_);
Leonard Greyf13493b2019-12-19 18:12:57472 break;
[email protected]770c6d82012-09-06 22:21:32473
[email protected]d12cc5e2013-10-19 18:25:06474#if defined(OS_CHROMEOS)
475 case IDC_VISIT_DESKTOP_OF_LRU_USER_2:
[email protected]0c930812014-01-30 18:01:47476 case IDC_VISIT_DESKTOP_OF_LRU_USER_3:
anina koehler038555b2020-02-24 13:30:32477 case IDC_VISIT_DESKTOP_OF_LRU_USER_4:
478 case IDC_VISIT_DESKTOP_OF_LRU_USER_5:
zijiehe4dde8072017-02-13 20:38:35479 ExecuteVisitDesktopCommand(id, window()->GetNativeWindow());
[email protected]0c930812014-01-30 18:01:47480 break;
[email protected]d12cc5e2013-10-19 18:25:06481#endif
482
[email protected]893124a22014-04-15 00:45:28483#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15484 case IDC_MINIMIZE_WINDOW:
485 browser_->window()->Minimize();
486 break;
487 case IDC_MAXIMIZE_WINDOW:
488 browser_->window()->Maximize();
489 break;
490 case IDC_RESTORE_WINDOW:
491 browser_->window()->Restore();
492 break;
[email protected]af97be4c62014-02-13 14:43:34493 case IDC_USE_SYSTEM_TITLE_BAR: {
zijiehe4dde8072017-02-13 20:38:35494 PrefService* prefs = profile()->GetPrefs();
[email protected]af97be4c62014-02-13 14:43:34495 prefs->SetBoolean(prefs::kUseCustomChromeFrame,
496 !prefs->GetBoolean(prefs::kUseCustomChromeFrame));
497 break;
498 }
499#endif
500
[email protected]5d98294912012-06-27 22:57:40501#if defined(OS_MACOSX)
spqchanb8ffc7d2015-11-17 01:17:21502 case IDC_TOGGLE_FULLSCREEN_TOOLBAR:
503 chrome::ToggleFullscreenToolbar(browser_);
504 break;
spqchan2c5d541e2017-10-25 07:07:11505 case IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS: {
Robert Sesek03282612018-10-31 15:48:06506 chrome::ToggleJavaScriptFromAppleEventsAllowed(browser_);
spqchan2c5d541e2017-10-25 07:07:11507 break;
508 }
[email protected]5d98294912012-06-27 22:57:40509#endif
510 case IDC_EXIT:
511 Exit();
512 break;
513
514 // Page-related commands
515 case IDC_SAVE_PAGE:
516 SavePage(browser_);
517 break;
Peter Kasting32bb2602019-08-22 19:01:43518 case IDC_BOOKMARK_THIS_TAB:
Collin Baker4ab8ad82019-06-06 17:02:54519#if BUILDFLAG(ENABLE_LEGACY_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:14520 feature_engagement::BookmarkTrackerFactory::GetInstance()
521 ->GetForProfile(profile())
522 ->OnBookmarkAdded();
523#endif
Devlin Croninbf700d02020-03-30 20:23:58524 BookmarkCurrentTab(browser_);
[email protected]5d98294912012-06-27 22:57:40525 break;
[email protected]5d98294912012-06-27 22:57:40526 case IDC_BOOKMARK_ALL_TABS:
Collin Baker4ab8ad82019-06-06 17:02:54527#if BUILDFLAG(ENABLE_LEGACY_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:14528 feature_engagement::BookmarkTrackerFactory::GetInstance()
529 ->GetForProfile(profile())
530 ->OnBookmarkAdded();
531#endif
[email protected]5d98294912012-06-27 22:57:40532 BookmarkAllTabs(browser_);
533 break;
534 case IDC_VIEW_SOURCE:
Lukasz Anforowicze1b954d92017-10-30 21:28:06535 browser_->tab_strip_model()
536 ->GetActiveWebContents()
537 ->GetMainFrame()
538 ->ViewSource();
[email protected]5d98294912012-06-27 22:57:40539 break;
[email protected]5d98294912012-06-27 22:57:40540 case IDC_PRINT:
541 Print(browser_);
542 break;
bondd052b5f82015-10-28 22:39:32543
Lei Zhang48a4a5262018-04-17 20:18:44544#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:55545 case IDC_BASIC_PRINT:
bratell0a7406f2017-03-28 07:46:37546 base::RecordAction(base::UserMetricsAction("Accel_Advanced_Print"));
vitalybukaf9433e42014-09-08 10:04:55547 BasicPrint(browser_);
[email protected]5d98294912012-06-27 22:57:40548 break;
Lei Zhang48a4a5262018-04-17 20:18:44549#endif // ENABLE_PRINTING
bondd052b5f82015-10-28 22:39:32550
bondd052b5f82015-10-28 22:39:32551 case IDC_SAVE_CREDIT_CARD_FOR_PAGE:
552 SaveCreditCard(browser_);
553 break;
siyua3e599eaa2018-07-13 00:23:06554 case IDC_MIGRATE_LOCAL_CREDIT_CARD_FOR_PAGE:
555 MigrateLocalCards(browser_);
556 break;
siyuac6e018d2019-10-18 01:19:30557 case IDC_SHOW_SAVE_LOCAL_CARD_SIGN_IN_PROMO_IF_APPLICABLE:
558 MaybeShowSaveLocalCardSignInPromo(browser_);
559 break;
560 case IDC_CLOSE_SIGN_IN_PROMO:
561 CloseSaveLocalCardSignInPromo(browser_);
562 break;
[email protected]e625b7602013-10-28 09:24:56563 case IDC_TRANSLATE_PAGE:
564 Translate(browser_);
565 break;
[email protected]4bee4432014-05-05 13:11:41566 case IDC_MANAGE_PASSWORDS_FOR_PAGE:
567 ManagePasswordsForPage(browser_);
568 break;
Tina Wang4c324702019-04-25 18:35:15569 case IDC_SEND_TAB_TO_SELF:
Tina Wang0e7e6e92019-05-14 21:03:03570 SendTabToSelfFromPageAction(browser_);
Tina Wang4c324702019-04-25 18:35:15571 break;
Travis Skare5193bbe12020-04-15 18:31:03572 case IDC_QRCODE_GENERATOR:
573 GenerateQRCodeFromPageAction(browser_);
574 break;
[email protected]4bee4432014-05-05 13:11:41575
[email protected]5d98294912012-06-27 22:57:40576 // Clipboard commands
577 case IDC_CUT:
[email protected]5d98294912012-06-27 22:57:40578 case IDC_COPY:
[email protected]5d98294912012-06-27 22:57:40579 case IDC_PASTE:
pkastingcd3f08bce2015-04-18 13:37:12580 CutCopyPaste(browser_, id);
[email protected]5d98294912012-06-27 22:57:40581 break;
582
583 // Find-in-page
584 case IDC_FIND:
585 Find(browser_);
586 break;
587 case IDC_FIND_NEXT:
588 FindNext(browser_);
589 break;
590 case IDC_FIND_PREVIOUS:
591 FindPrevious(browser_);
592 break;
Jeff Fisher6cc1ce7b2019-06-28 23:02:38593 case IDC_CLOSE_FIND_OR_STOP:
594 if (CanCloseFind(browser_))
595 CloseFind(browser_);
596 else if (IsCommandEnabled(IDC_STOP))
597 ExecuteCommand(IDC_STOP);
598 break;
[email protected]5d98294912012-06-27 22:57:40599
600 // Zoom
601 case IDC_ZOOM_PLUS:
602 Zoom(browser_, content::PAGE_ZOOM_IN);
603 break;
604 case IDC_ZOOM_NORMAL:
605 Zoom(browser_, content::PAGE_ZOOM_RESET);
606 break;
607 case IDC_ZOOM_MINUS:
608 Zoom(browser_, content::PAGE_ZOOM_OUT);
609 break;
610
611 // Focus various bits of UI
612 case IDC_FOCUS_TOOLBAR:
bratell0a7406f2017-03-28 07:46:37613 base::RecordAction(base::UserMetricsAction("Accel_Focus_Toolbar"));
[email protected]5d98294912012-06-27 22:57:40614 FocusToolbar(browser_);
615 break;
616 case IDC_FOCUS_LOCATION:
bratell0a7406f2017-03-28 07:46:37617 base::RecordAction(base::UserMetricsAction("Accel_Focus_Location"));
[email protected]5d98294912012-06-27 22:57:40618 FocusLocationBar(browser_);
619 break;
620 case IDC_FOCUS_SEARCH:
bratell0a7406f2017-03-28 07:46:37621 base::RecordAction(base::UserMetricsAction("Accel_Focus_Search"));
[email protected]5d98294912012-06-27 22:57:40622 FocusSearch(browser_);
623 break;
624 case IDC_FOCUS_MENU_BAR:
625 FocusAppMenu(browser_);
626 break;
627 case IDC_FOCUS_BOOKMARKS:
bratell0a7406f2017-03-28 07:46:37628 base::RecordAction(base::UserMetricsAction("Accel_Focus_Bookmarks"));
[email protected]5d98294912012-06-27 22:57:40629 FocusBookmarksToolbar(browser_);
630 break;
David Tsengc0b1b642018-01-24 07:12:27631 case IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY:
632 FocusInactivePopupForAccessibility(browser_);
[email protected]822ca8c62013-04-19 00:49:15633 break;
[email protected]5d98294912012-06-27 22:57:40634 case IDC_FOCUS_NEXT_PANE:
635 FocusNextPane(browser_);
636 break;
637 case IDC_FOCUS_PREVIOUS_PANE:
638 FocusPreviousPane(browser_);
639 break;
640
641 // Show various bits of UI
642 case IDC_OPEN_FILE:
643 browser_->OpenFile();
644 break;
Alan Cutter81ac726682018-09-25 00:18:36645 case IDC_CREATE_SHORTCUT:
Alan Cutter98844a9fa2019-06-19 21:11:40646 base::RecordAction(base::UserMetricsAction("CreateShortcut"));
Glen Robertsonb9d27412020-01-09 06:48:13647 web_app::CreateWebAppFromCurrentWebContents(
648 browser_, true /* force_shortcut_app */);
Alan Cutter81ac726682018-09-25 00:18:36649 break;
650 case IDC_INSTALL_PWA:
Alan Cutter98844a9fa2019-06-19 21:11:40651 base::RecordAction(base::UserMetricsAction("InstallWebAppFromMenu"));
Glen Robertsonb9d27412020-01-09 06:48:13652 web_app::CreateWebAppFromCurrentWebContents(
653 browser_, false /* force_shortcut_app */);
[email protected]488e3952013-11-18 05:29:14654 break;
[email protected]5d98294912012-06-27 22:57:40655 case IDC_DEV_TOOLS:
[email protected]c934c382013-11-01 00:36:01656 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Show());
[email protected]5d98294912012-06-27 22:57:40657 break;
658 case IDC_DEV_TOOLS_CONSOLE:
einbinderdfa567b2016-12-16 01:15:52659 ToggleDevToolsWindow(browser_, DevToolsToggleAction::ShowConsolePanel());
[email protected]5d98294912012-06-27 22:57:40660 break;
[email protected]2056c3192013-10-21 22:40:51661 case IDC_DEV_TOOLS_DEVICES:
662 InspectUI::InspectDevices(browser_);
663 break;
[email protected]5d98294912012-06-27 22:57:40664 case IDC_DEV_TOOLS_INSPECT:
[email protected]c934c382013-11-01 00:36:01665 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Inspect());
[email protected]5d98294912012-06-27 22:57:40666 break;
[email protected]d16657c2012-09-03 14:25:10667 case IDC_DEV_TOOLS_TOGGLE:
[email protected]c934c382013-11-01 00:36:01668 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Toggle());
[email protected]d16657c2012-09-03 14:25:10669 break;
[email protected]5d98294912012-06-27 22:57:40670 case IDC_TASK_MANAGER:
[email protected]29c262de2013-06-22 15:39:38671 OpenTaskManager(browser_);
[email protected]5d98294912012-06-27 22:57:40672 break;
caelyn4e4e08a2015-02-04 21:27:49673#if defined(OS_CHROMEOS)
674 case IDC_TAKE_SCREENSHOT:
675 TakeScreenshot();
676 break;
677#endif
Nico Weber0cc71122019-07-29 17:30:40678#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
[email protected]5d98294912012-06-27 22:57:40679 case IDC_FEEDBACK:
afakhryf4575bd2017-04-28 02:21:04680 OpenFeedbackDialog(browser_, kFeedbackSourceBrowserCommand);
[email protected]5d98294912012-06-27 22:57:40681 break;
[email protected]236ad3022013-09-04 03:27:43682#endif
[email protected]5d98294912012-06-27 22:57:40683 case IDC_SHOW_BOOKMARK_BAR:
684 ToggleBookmarkBar(browser_);
685 break;
Elly Fong-Jones2d688ae2020-03-31 20:41:47686 case IDC_SHOW_FULL_URLS:
687 ToggleShowFullURLs(browser_);
688 break;
[email protected]5d98294912012-06-27 22:57:40689 case IDC_PROFILING_ENABLED:
Bryce Thomas96b07772018-11-07 03:04:15690 content::Profiling::Toggle();
[email protected]5d98294912012-06-27 22:57:40691 break;
692
693 case IDC_SHOW_BOOKMARK_MANAGER:
694 ShowBookmarkManager(browser_);
695 break;
696 case IDC_SHOW_APP_MENU:
bratell0a7406f2017-03-28 07:46:37697 base::RecordAction(base::UserMetricsAction("Accel_Show_App_Menu"));
[email protected]5d98294912012-06-27 22:57:40698 ShowAppMenu(browser_);
699 break;
700 case IDC_SHOW_AVATAR_MENU:
701 ShowAvatarMenu(browser_);
702 break;
703 case IDC_SHOW_HISTORY:
704 ShowHistory(browser_);
705 break;
706 case IDC_SHOW_DOWNLOADS:
707 ShowDownloads(browser_);
708 break;
709 case IDC_MANAGE_EXTENSIONS:
[email protected]bc9833c32013-02-28 04:05:08710 ShowExtensions(browser_, std::string());
[email protected]5d98294912012-06-27 22:57:40711 break;
712 case IDC_OPTIONS:
713 ShowSettings(browser_);
714 break;
715 case IDC_EDIT_SEARCH_ENGINES:
716 ShowSearchEngineSettings(browser_);
717 break;
718 case IDC_VIEW_PASSWORDS:
719 ShowPasswordManager(browser_);
720 break;
721 case IDC_CLEAR_BROWSING_DATA:
722 ShowClearBrowsingDataDialog(browser_);
723 break;
724 case IDC_IMPORT_SETTINGS:
725 ShowImportDialog(browser_);
726 break;
[email protected]9b7ab882012-09-10 23:46:36727 case IDC_TOGGLE_REQUEST_TABLET_SITE:
728 ToggleRequestTabletSite(browser_);
729 break;
[email protected]5d98294912012-06-27 22:57:40730 case IDC_ABOUT:
731 ShowAboutChrome(browser_);
732 break;
733 case IDC_UPGRADE_DIALOG:
734 OpenUpdateChromeDialog(browser_);
735 break;
[email protected]5d98294912012-06-27 22:57:40736 case IDC_HELP_PAGE_VIA_KEYBOARD:
737 ShowHelp(browser_, HELP_SOURCE_KEYBOARD);
738 break;
739 case IDC_HELP_PAGE_VIA_MENU:
740 ShowHelp(browser_, HELP_SOURCE_MENU);
741 break;
Bret Sepulveda2d018662017-05-18 21:31:48742 case IDC_SHOW_BETA_FORUM:
743 ShowBetaForum(browser_);
744 break;
David Roger7e25dff2019-02-07 09:03:17745#if !defined(OS_CHROMEOS)
estade8c0780f2015-08-21 23:36:41746 case IDC_SHOW_SIGNIN:
gogerald71bf6c902015-12-08 00:49:37747 ShowBrowserSigninOrSettings(
748 browser_, signin_metrics::AccessPoint::ACCESS_POINT_MENU);
estade8c0780f2015-08-21 23:36:41749 break;
David Roger7e25dff2019-02-07 09:03:17750#endif
[email protected]6bd370b2014-05-28 14:19:47751 case IDC_DISTILL_PAGE:
Aran Gilman6586e8f2019-06-03 18:50:56752 ToggleDistilledView(browser_);
[email protected]6bd370b2014-05-28 14:19:47753 break;
apacible45cbfc92015-09-28 22:45:41754 case IDC_ROUTE_MEDIA:
Takumi Fujimotoa8bc3c92019-12-26 20:12:10755 RouteMediaInvokedFromAppMenu(browser_);
apacible45cbfc92015-09-28 22:45:41756 break;
Tommy Steimelc4477982017-11-29 18:07:18757 case IDC_WINDOW_MUTE_SITE:
758 MuteSite(browser_);
ellyjones0101ba02017-05-19 15:50:26759 break;
760 case IDC_WINDOW_PIN_TAB:
761 PinTab(browser_);
762 break;
Connie Wan303e29e2020-01-31 18:16:56763 case IDC_WINDOW_GROUP_TAB:
764 GroupTab(browser_);
765 break;
Elly Fong-Jones2d0443cb2019-11-14 15:04:20766 case IDC_WINDOW_CLOSE_TABS_TO_RIGHT:
767 CloseTabsToRight(browser_);
768 break;
769 case IDC_WINDOW_CLOSE_OTHER_TABS:
770 CloseOtherTabs(browser_);
771 break;
Yann Dagocd13225a2019-03-07 18:39:05772 case IDC_SHOW_MANAGEMENT_PAGE: {
Yann Dagoc1d1c4af2019-04-17 13:40:51773 ShowSingletonTab(browser_, GURL(kChromeUIManagementURL));
Nicolas Ouellet-payeur82eb65b2018-11-05 16:49:27774 break;
Yann Dagocd13225a2019-03-07 18:39:05775 }
Elly Fong-Jones5e6baaf2019-10-10 23:17:14776 case IDC_MUTE_TARGET_SITE:
777 MuteSiteForKeyboardFocusedTab(browser_);
778 break;
779 case IDC_PIN_TARGET_TAB:
780 PinKeyboardFocusedTab(browser_);
781 break;
Connie Wan303e29e2020-01-31 18:16:56782 case IDC_GROUP_TARGET_TAB:
783 GroupKeyboardFocusedTab(browser_);
784 break;
Elly Fong-Jones5e6baaf2019-10-10 23:17:14785 case IDC_DUPLICATE_TARGET_TAB:
786 DuplicateKeyboardFocusedTab(browser_);
787 break;
Christopher Lam0dbac2b2017-11-14 07:12:10788 // Hosted App commands
789 case IDC_COPY_URL:
790 CopyURL(browser_);
791 break;
792 case IDC_OPEN_IN_CHROME:
793 OpenInChrome(browser_);
794 break;
795 case IDC_SITE_SETTINGS:
796 ShowSiteSettings(
797 browser_,
798 browser_->tab_strip_model()->GetActiveWebContents()->GetVisibleURL());
799 break;
Alan Cuttera99d1522019-09-12 02:09:22800 case IDC_WEB_APP_MENU_APP_INFO: {
Dana Fried08b774a2019-05-10 18:21:48801 content::WebContents* const web_contents =
802 browser_->tab_strip_model()->GetActiveWebContents();
803 if (web_contents) {
804 ShowPageInfoDialog(web_contents,
805 base::BindOnce(&AppInfoDialogClosedCallback,
806 base::Unretained(web_contents)),
807 bubble_anchor_util::kAppMenuButton);
808 }
Christopher Lam86b52712017-12-04 01:58:33809 break;
Dana Fried08b774a2019-05-10 18:21:48810 }
[email protected]5d98294912012-06-27 22:57:40811 default:
812 LOG(WARNING) << "Received Unimplemented Command: " << id;
813 break;
814 }
Ivan Sandrk9669d0e2017-12-15 23:50:20815
816 return true;
817}
818
819void BrowserCommandController::AddCommandObserver(int id,
820 CommandObserver* observer) {
821 command_updater_.AddCommandObserver(id, observer);
822}
823
824void BrowserCommandController::RemoveCommandObserver(
Aran Gilmand217b5b2019-04-11 17:45:43825 int id,
826 CommandObserver* observer) {
Ivan Sandrk9669d0e2017-12-15 23:50:20827 command_updater_.RemoveCommandObserver(id, observer);
828}
829
830void BrowserCommandController::RemoveCommandObserver(
831 CommandObserver* observer) {
832 command_updater_.RemoveCommandObserver(observer);
833}
834
835bool BrowserCommandController::UpdateCommandEnabled(int id, bool state) {
836 if (is_locked_fullscreen_)
837 return false;
838
839 return command_updater_.UpdateCommandEnabled(id, state);
[email protected]5d98294912012-06-27 22:57:40840}
841
Mihai Sardarescuf87ccc12018-09-26 10:37:45842////////////////////////////////////////////////////////////////////////////////
843// BrowserCommandController, SigninPrefObserver implementation:
844
845void BrowserCommandController::OnSigninAllowedPrefChange() {
846 // For unit tests, we don't have a window.
847 if (!window())
848 return;
849 UpdateShowSyncState(IsShowingMainUI());
850}
851
[email protected]5d98294912012-06-27 22:57:40852// BrowserCommandController, TabStripModelObserver implementation:
853
sangwoo.ko1ae265f12018-10-18 08:30:28854void BrowserCommandController::OnTabStripModelChanged(
855 TabStripModel* tab_strip_model,
856 const TabStripModelChange& change,
857 const TabStripSelectionChange& selection) {
Dana Frieda391e6ce2019-05-08 00:00:20858 std::vector<content::WebContents*> new_contents;
859 std::vector<content::WebContents*> old_contents;
[email protected]5d98294912012-06-27 22:57:40860
Dana Frieda391e6ce2019-05-08 00:00:20861 switch (change.type()) {
862 case TabStripModelChange::kInserted:
863 for (const auto& contents : change.GetInsert()->contents)
864 new_contents.push_back(contents.contents);
865 break;
866 case TabStripModelChange::kReplaced: {
867 auto* replace = change.GetReplace();
868 new_contents.push_back(replace->new_contents);
869 old_contents.push_back(replace->old_contents);
870 break;
sangwoo.ko1ae265f12018-10-18 08:30:28871 }
Dana Frieda391e6ce2019-05-08 00:00:20872 case TabStripModelChange::kRemoved:
873 for (const auto& contents : change.GetRemove()->contents)
874 old_contents.push_back(contents.contents);
875 break;
876 default:
877 break;
sangwoo.ko1ae265f12018-10-18 08:30:28878 }
[email protected]5d98294912012-06-27 22:57:40879}
880
[email protected]3cac87232012-11-20 01:48:27881void BrowserCommandController::TabBlockedStateChanged(
882 content::WebContents* contents,
883 int index) {
884 PrintingStateChanged();
885 FullscreenStateChanged();
886 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:41887 UpdateCommandsForMediaRouter();
[email protected]3cac87232012-11-20 01:48:27888}
889
[email protected]5d98294912012-06-27 22:57:40890////////////////////////////////////////////////////////////////////////////////
891// BrowserCommandController, TabRestoreServiceObserver implementation:
892
893void BrowserCommandController::TabRestoreServiceChanged(
blundell74001adc2015-09-18 11:04:25894 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53895 UpdateTabRestoreCommandState();
[email protected]5d98294912012-06-27 22:57:40896}
897
898void BrowserCommandController::TabRestoreServiceDestroyed(
blundell74001adc2015-09-18 11:04:25899 sessions::TabRestoreService* service) {
[email protected]5d98294912012-06-27 22:57:40900 service->RemoveObserver(this);
901}
902
[email protected]2e9369e2014-08-15 09:12:53903void BrowserCommandController::TabRestoreServiceLoaded(
blundell74001adc2015-09-18 11:04:25904 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53905 UpdateTabRestoreCommandState();
906}
907
[email protected]5d98294912012-06-27 22:57:40908////////////////////////////////////////////////////////////////////////////////
[email protected]5d98294912012-06-27 22:57:40909// BrowserCommandController, private:
910
[email protected]6a414ff2013-02-27 08:22:54911bool BrowserCommandController::IsShowingMainUI() {
manukf1a116392018-10-25 16:28:24912 return browser_->SupportsWindowFeature(Browser::FEATURE_TABSTRIP);
913}
914
915bool BrowserCommandController::IsShowingLocationBar() {
916 return browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
[email protected]5d98294912012-06-27 22:57:40917}
918
919void BrowserCommandController::InitCommandState() {
920 // All browser commands whose state isn't set automagically some other way
921 // (like Back & Forward with initial page load) must have their state
922 // initialized here, otherwise they will be forever disabled.
923
Ivan Sandrk9669d0e2017-12-15 23:50:20924 if (is_locked_fullscreen_)
925 return;
926
[email protected]5d98294912012-06-27 22:57:40927 // Navigation commands
928 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true);
toyoshim7dad4b1182016-04-01 14:28:05929 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE, true);
[email protected]58e29032012-08-06 20:19:57930 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, true);
[email protected]5d98294912012-06-27 22:57:40931
932 // Window management commands
933 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true);
934 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true);
935 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true);
936 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true);
[email protected]2e9369e2014-08-15 09:12:53937 UpdateTabRestoreCommandState();
[email protected]d28d3782013-02-26 16:31:55938 command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
[email protected]5d98294912012-06-27 22:57:40939 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true);
[email protected]d12cc5e2013-10-19 18:25:06940#if defined(OS_CHROMEOS)
James Cook934abaf2017-09-19 22:21:58941 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
anina koehler038555b2020-02-24 13:30:32942 // The VisitDesktop command is only supported for up to 5 logged in users
943 // because that's the max number of user sessions. If that number is increased
944 // the IDC_VISIT_DESKTOP_OF_LRU_USER_ command ids should be updated as well.
945 // crbug.com/940461
946 static_assert(
947 session_manager::kMaximumNumberOfUserSessions <=
948 IDC_VISIT_DESKTOP_OF_LRU_USER_LAST -
949 IDC_VISIT_DESKTOP_OF_LRU_USER_NEXT + 2,
950 "The max number of user sessions exceeds the number of users supported.");
[email protected]d12cc5e2013-10-19 18:25:06951 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_2, true);
952 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_3, true);
anina koehler038555b2020-02-24 13:30:32953 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_4, true);
954 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_5, true);
[email protected]d12cc5e2013-10-19 18:25:06955#endif
[email protected]893124a22014-04-15 00:45:28956#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15957 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
958 command_updater_.UpdateCommandEnabled(IDC_MAXIMIZE_WINDOW, true);
959 command_updater_.UpdateCommandEnabled(IDC_RESTORE_WINDOW, true);
Maksim Sisovac767592018-08-10 08:00:15960 bool use_system_title_bar = true;
961#if defined(USE_OZONE)
Maksim Sisovb0643ebd2020-06-22 11:47:31962 if (features::IsUsingOzonePlatform()) {
963 use_system_title_bar = ui::OzonePlatform::GetInstance()
964 ->GetPlatformProperties()
965 .use_system_title_bar;
966 }
Maksim Sisovac767592018-08-10 08:00:15967#endif
968 command_updater_.UpdateCommandEnabled(IDC_USE_SYSTEM_TITLE_BAR,
969 use_system_title_bar);
[email protected]af97be4c62014-02-13 14:43:34970#endif
Alan Cutter09965802018-03-27 07:25:29971 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW, true);
[email protected]5d98294912012-06-27 22:57:40972
973 // Page-related commands
[email protected]4bee4432014-05-05 13:11:41974 command_updater_.UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE, true);
[email protected]5d98294912012-06-27 22:57:40975
976 // Zoom
977 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true);
978 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true);
[email protected]d93dbd12014-08-04 23:42:53979 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, false);
[email protected]5d98294912012-06-27 22:57:40980 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
981
982 // Show various bits of UI
Aran Gilmand217b5b2019-04-11 17:45:43983 const bool guest_session =
984 profile()->IsGuestSession() || profile()->IsSystemProfile();
mlerman7831f57d2015-05-25 11:40:15985 DCHECK(!profile()->IsSystemProfile())
986 << "Ought to never have browser for the system profile.";
Joel Hockey2687ab52019-08-14 23:59:46987 const bool normal_window = browser_->is_type_normal();
[email protected]05454532013-01-22 21:09:08988 UpdateOpenFileState(&command_updater_);
[email protected]5d98294912012-06-27 22:57:40989 UpdateCommandsForDevTools();
990 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager());
[email protected]338416c02014-05-13 16:47:06991 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session);
[email protected]5d98294912012-06-27 22:57:40992 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
[email protected]674b65672014-06-02 23:21:56993 command_updater_.UpdateCommandEnabled(IDC_HELP_MENU, true);
[email protected]5d98294912012-06-27 22:57:40994 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
995 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
Bret Sepulveda2d018662017-05-18 21:31:48996 command_updater_.UpdateCommandEnabled(IDC_SHOW_BETA_FORUM, true);
[email protected]338416c02014-05-13 16:47:06997 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session);
Aran Gilmand217b5b2019-04-11 17:45:43998 command_updater_.UpdateCommandEnabled(
999 IDC_RECENT_TABS_MENU, !guest_session && !profile()->IsOffTheRecord());
Rohit Agarwal2a2230b2019-08-21 15:53:411000 command_updater_.UpdateCommandEnabled(
1001 IDC_CLEAR_BROWSING_DATA,
1002 !guest_session && !profile()->IsIncognitoProfile());
[email protected]39d47592014-01-10 21:42:451003#if defined(OS_CHROMEOS)
caelyn4e4e08a2015-02-04 21:27:491004 command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true);
Ramin Halavatif362b7a2019-04-17 05:24:501005 // Chrome OS uses the system tray menu to handle multi-profiles. Avatar menu
1006 // is only required in incognito mode.
Ramin Halavati2394dc452019-05-21 16:21:581007 if (profile()->IsIncognitoProfile())
[email protected]338416c02014-05-13 16:47:061008 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
Ramin Halavatif362b7a2019-04-17 05:24:501009#else
1010 if (normal_window)
1011 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
[email protected]39d47592014-01-10 21:42:451012#endif
siyuac6e018d2019-10-18 01:19:301013 command_updater_.UpdateCommandEnabled(
1014 IDC_SHOW_SAVE_LOCAL_CARD_SIGN_IN_PROMO_IF_APPLICABLE, true);
1015 command_updater_.UpdateCommandEnabled(IDC_CLOSE_SIGN_IN_PROMO, true);
[email protected]5d98294912012-06-27 22:57:401016
Mihai Sardarescu2ec5205682018-09-26 09:20:051017 UpdateShowSyncState(true);
1018
[email protected]5d98294912012-06-27 22:57:401019 // Navigation commands
Joel Hockey2687ab52019-08-14 23:59:461020 command_updater_.UpdateCommandEnabled(
1021 IDC_HOME, normal_window || browser_->deprecated_is_app());
[email protected]5d98294912012-06-27 22:57:401022
Mugdha Lakhani23954ef22020-06-25 21:56:211023 const bool is_web_app_or_custom_tab =
1024#if defined(OS_CHROMEOS)
1025 browser_->is_type_custom_tab() ||
1026#endif
Alan Cutterd0bd51902019-05-22 04:15:231027 web_app::AppBrowserController::IsForWebAppBrowser(browser_);
Christopher Lam0dbac2b2017-11-14 07:12:101028 // Hosted app browser commands.
Mugdha Lakhani23954ef22020-06-25 21:56:211029 command_updater_.UpdateCommandEnabled(IDC_COPY_URL, is_web_app_or_custom_tab);
1030 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_CHROME,
1031 is_web_app_or_custom_tab);
1032 command_updater_.UpdateCommandEnabled(IDC_SITE_SETTINGS,
1033 is_web_app_or_custom_tab);
1034 command_updater_.UpdateCommandEnabled(IDC_WEB_APP_MENU_APP_INFO,
1035 is_web_app_or_custom_tab);
Christopher Lam0dbac2b2017-11-14 07:12:101036
Joel Hockey43afbd82020-02-19 23:55:371037 // Tab management commands
1038 const bool supports_tabs =
1039 browser_->SupportsWindowFeature(Browser::FEATURE_TABSTRIP);
1040 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, supports_tabs);
1041 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, supports_tabs);
1042 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, supports_tabs);
1043 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, supports_tabs);
1044 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, supports_tabs);
1045 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, supports_tabs);
1046 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, supports_tabs);
1047 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, supports_tabs);
1048 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, supports_tabs);
1049 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, supports_tabs);
1050 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, supports_tabs);
1051 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, supports_tabs);
1052 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, supports_tabs);
[email protected]5d98294912012-06-27 22:57:401053
[email protected]338416c02014-05-13 16:47:061054 // These are always enabled; the menu determines their menu item visibility.
[email protected]5d98294912012-06-27 22:57:401055 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
[email protected]5d98294912012-06-27 22:57:401056
[email protected]6bd370b2014-05-28 14:19:471057 // Distill current page.
Aran Gilman7b6ccf5d2019-09-05 19:16:021058 command_updater_.UpdateCommandEnabled(IDC_DISTILL_PAGE,
1059 dom_distiller::IsDomDistillerEnabled());
[email protected]6bd370b2014-05-28 14:19:471060
Tommy Steimelc4477982017-11-29 18:07:181061 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE, normal_window);
ellyjones0101ba02017-05-19 15:50:261062 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, normal_window);
Connie Wan303e29e2020-01-31 18:16:561063 command_updater_.UpdateCommandEnabled(IDC_WINDOW_GROUP_TAB, normal_window);
Elly Fong-Jones2d0443cb2019-11-14 15:04:201064 command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_TABS_TO_RIGHT,
1065 normal_window);
1066 command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_OTHER_TABS,
1067 normal_window);
ellyjones0101ba02017-05-19 15:50:261068
[email protected]338416c02014-05-13 16:47:061069 // Initialize other commands whose state changes based on various conditions.
[email protected]32dfede2013-08-25 15:48:251070 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:401071 UpdateCommandsForContentRestrictionState();
[email protected]5d98294912012-06-27 22:57:401072 UpdateCommandsForBookmarkEditing();
[email protected]5d98294912012-06-27 22:57:401073 UpdateCommandsForIncognitoAvailability();
Elly Fong-Jones5e6baaf2019-10-10 23:17:141074 UpdateCommandsForTabKeyboardFocus(GetKeyboardFocusedTabIndex(browser_));
[email protected]5d98294912012-06-27 22:57:401075}
1076
[email protected]05454532013-01-22 21:09:081077// static
1078void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
1079 CommandUpdater* command_updater,
1080 Profile* profile) {
mlermane01e6de2014-09-29 19:26:471081 const bool guest_session = profile->IsGuestSession();
1082 // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession().
[email protected]5d98294912012-06-27 22:57:401083 IncognitoModePrefs::Availability incognito_availability =
[email protected]05454532013-01-22 21:09:081084 IncognitoModePrefs::GetAvailability(profile->GetPrefs());
1085 command_updater->UpdateCommandEnabled(
Aran Gilmand217b5b2019-04-11 17:45:431086 IDC_NEW_WINDOW, incognito_availability != IncognitoModePrefs::FORCED);
[email protected]05454532013-01-22 21:09:081087 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:401088 IDC_NEW_INCOGNITO_WINDOW,
mlermane01e6de2014-09-29 19:26:471089 incognito_availability != IncognitoModePrefs::DISABLED && !guest_session);
[email protected]5d98294912012-06-27 22:57:401090
[email protected]57b25292014-05-01 16:31:061091 const bool forced_incognito =
1092 incognito_availability == IncognitoModePrefs::FORCED ||
1093 guest_session; // Guest always runs in Incognito mode.
[email protected]05454532013-01-22 21:09:081094 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:401095 IDC_SHOW_BOOKMARK_MANAGER,
[email protected]57b25292014-05-01 16:31:061096 browser_defaults::bookmarks_enabled && !forced_incognito);
Devlin Cronin21dba422018-05-30 15:45:161097 extensions::ExtensionService* extension_service =
[email protected]03d25812014-06-22 19:41:551098 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]57b25292014-05-01 16:31:061099 const bool enable_extensions =
[email protected]5d98294912012-06-27 22:57:401100 extension_service && extension_service->extensions_enabled();
[email protected]5d98294912012-06-27 22:57:401101
Elly Fong-Jones2d688ae2020-03-31 20:41:471102 command_updater->UpdateCommandEnabled(
1103 IDC_SHOW_FULL_URLS,
1104 base::FeatureList::IsEnabled(omnibox::kOmniboxContextMenuShowFullUrls));
1105
[email protected]57b25292014-05-01 16:31:061106 // Bookmark manager and settings page/subpages are forced to open in normal
1107 // mode. For this reason we disable these commands when incognito is forced.
1108 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
1109 enable_extensions && !forced_incognito);
1110
1111 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito);
1112 command_updater->UpdateCommandEnabled(IDC_OPTIONS,
1113 !forced_incognito || guest_session);
estade8c0780f2015-08-21 23:36:411114 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito);
[email protected]05454532013-01-22 21:09:081115}
1116
1117void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
Ivan Sandrk9669d0e2017-12-15 23:50:201118 if (is_locked_fullscreen_)
1119 return;
1120
[email protected]05454532013-01-22 21:09:081121 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile());
1122
[email protected]6a414ff2013-02-27 08:22:541123 if (!IsShowingMainUI()) {
[email protected]05454532013-01-22 21:09:081124 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false);
1125 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false);
1126 }
[email protected]5d98294912012-06-27 22:57:401127}
1128
1129void BrowserCommandController::UpdateCommandsForTabState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201130 if (is_locked_fullscreen_)
1131 return;
1132
[email protected]617ee962013-01-29 20:49:121133 WebContents* current_web_contents =
1134 browser_->tab_strip_model()->GetActiveWebContents();
[email protected]1c5119c2012-09-19 00:08:571135 if (!current_web_contents) // May be NULL during tab restore.
[email protected]5d98294912012-06-27 22:57:401136 return;
[email protected]5d98294912012-06-27 22:57:401137
1138 // Navigation commands
1139 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_));
1140 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_));
1141 command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_));
toyoshim7dad4b1182016-04-01 14:28:051142 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE,
[email protected]5d98294912012-06-27 22:57:401143 CanReload(browser_));
[email protected]58e29032012-08-06 20:19:571144 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE,
1145 CanReload(browser_));
[email protected]5d98294912012-06-27 22:57:401146
1147 // Window management commands
Aran Gilmand217b5b2019-04-11 17:45:431148 command_updater_.UpdateCommandEnabled(
Joel Hockey2687ab52019-08-14 23:59:461149 IDC_DUPLICATE_TAB,
1150 !browser_->deprecated_is_app() && CanDuplicateTab(browser_));
Tommy Steimelc4477982017-11-29 18:07:181151 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE,
Joel Hockey2687ab52019-08-14 23:59:461152 !browser_->deprecated_is_app());
ellyjones0101ba02017-05-19 15:50:261153 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB,
Joel Hockey2687ab52019-08-14 23:59:461154 !browser_->deprecated_is_app());
Connie Wan303e29e2020-01-31 18:16:561155 command_updater_.UpdateCommandEnabled(IDC_WINDOW_GROUP_TAB,
1156 !browser_->deprecated_is_app());
Elly Fong-Jones2d0443cb2019-11-14 15:04:201157 command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_TABS_TO_RIGHT,
1158 CanCloseTabsToRight(browser_));
1159 command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_OTHER_TABS,
1160 CanCloseOtherTabs(browser_));
Leonard Greyf13493b2019-12-19 18:12:571161 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_TO_NEW_WINDOW,
Leonard Greya8ecaa32020-01-07 20:57:411162 CanMoveActiveTabToNewWindow(browser_));
[email protected]5d98294912012-06-27 22:57:401163
1164 // Page-related commands
1165 window()->SetStarredState(
[email protected]1c5119c2012-09-19 00:08:571166 BookmarkTabHelper::FromWebContents(current_web_contents)->is_starred());
[email protected]5423c372012-08-22 05:50:161167 window()->ZoomChangedForActiveTab(false);
[email protected]5d98294912012-06-27 22:57:401168 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
1169 CanViewSource(browser_));
Joel Hockey2687ab52019-08-14 23:59:461170 if (browser_->is_type_devtools())
[email protected]5d98294912012-06-27 22:57:401171 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false);
1172
Glen Robertsonb9d27412020-01-09 06:48:131173 bool can_create_web_app = web_app::CanCreateWebApp(browser_);
1174 command_updater_.UpdateCommandEnabled(IDC_INSTALL_PWA, can_create_web_app);
Alan Cutter81ac726682018-09-25 00:18:361175 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUT,
Glen Robertsonb9d27412020-01-09 06:48:131176 can_create_web_app);
1177 // Note that additional logic in AppMenuModel::Build() controls the presence
1178 // of this command.
Alan Cutter403cebb2018-05-17 05:22:451179 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW,
Glen Robertsonb9d27412020-01-09 06:48:131180 web_app::CanPopOutWebApp(profile()));
[email protected]5d98294912012-06-27 22:57:401181
[email protected]9b7ab882012-09-10 23:46:361182 command_updater_.UpdateCommandEnabled(
1183 IDC_TOGGLE_REQUEST_TABLET_SITE,
1184 CanRequestTabletSite(current_web_contents));
1185
[email protected]5d98294912012-06-27 22:57:401186 UpdateCommandsForContentRestrictionState();
1187 UpdateCommandsForBookmarkEditing();
[email protected]3cac87232012-11-20 01:48:271188 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:411189 UpdateCommandsForMediaRouter();
[email protected]d93dbd12014-08-04 23:42:531190 // Update the zoom commands when an active tab is selected.
1191 UpdateCommandsForZoomState();
Elly Fong-Jones5e6baaf2019-10-10 23:17:141192 UpdateCommandsForTabKeyboardFocus(GetKeyboardFocusedTabIndex(browser_));
[email protected]d93dbd12014-08-04 23:42:531193}
1194
1195void BrowserCommandController::UpdateCommandsForZoomState() {
Aran Gilmand217b5b2019-04-11 17:45:431196 WebContents* contents = browser_->tab_strip_model()->GetActiveWebContents();
[email protected]d93dbd12014-08-04 23:42:531197 if (!contents)
1198 return;
Aran Gilmand217b5b2019-04-11 17:45:431199 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, CanZoomIn(contents));
a.sarkar.arundaadc712015-02-26 05:39:081200 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL,
ccameronb7c1d6c2015-03-09 17:08:241201 CanResetZoom(contents));
Aran Gilmand217b5b2019-04-11 17:45:431202 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, CanZoomOut(contents));
[email protected]5d98294912012-06-27 22:57:401203}
1204
1205void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
1206 int restrictions = GetContentRestrictions(browser_);
1207
1208 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011209 IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY));
[email protected]5d98294912012-06-27 22:57:401210 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011211 IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT));
[email protected]5d98294912012-06-27 22:57:401212 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011213 IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE));
[email protected]5d98294912012-06-27 22:57:401214 UpdateSaveAsState();
1215 UpdatePrintingState();
1216}
1217
1218void BrowserCommandController::UpdateCommandsForDevTools() {
Ivan Sandrk9669d0e2017-12-15 23:50:201219 if (is_locked_fullscreen_)
1220 return;
1221
Pavol Marko56df0272018-07-04 17:55:041222 bool dev_tools_enabled = DevToolsWindow::AllowDevToolsFor(
1223 profile(), browser_->tab_strip_model()->GetActiveWebContents());
Aran Gilmand217b5b2019-04-11 17:45:431224 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS, dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401225 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE,
1226 dev_tools_enabled);
[email protected]2056c3192013-10-21 22:40:511227 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES,
1228 dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401229 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT,
1230 dev_tools_enabled);
[email protected]d16657c2012-09-03 14:25:101231 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE,
1232 dev_tools_enabled);
spqchan2c5d541e2017-10-25 07:07:111233#if defined(OS_MACOSX)
1234 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS,
1235 dev_tools_enabled);
1236#endif
[email protected]5d98294912012-06-27 22:57:401237}
1238
1239void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
Ivan Sandrk9669d0e2017-12-15 23:50:201240 if (is_locked_fullscreen_)
1241 return;
1242
Peter Kasting32bb2602019-08-22 19:01:431243 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_THIS_TAB,
1244 CanBookmarkCurrentTab(browser_));
[email protected]5d98294912012-06-27 22:57:401245 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
1246 CanBookmarkAllTabs(browser_));
thestig5149d272014-10-30 07:25:291247#if defined(OS_WIN)
1248 command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN, true);
1249#endif
[email protected]5d98294912012-06-27 22:57:401250}
1251
1252void BrowserCommandController::UpdateCommandsForBookmarkBar() {
Ivan Sandrk9669d0e2017-12-15 23:50:201253 if (is_locked_fullscreen_)
1254 return;
1255
tfarina3bddbe112014-08-28 05:29:321256 command_updater_.UpdateCommandEnabled(
Aran Gilmand217b5b2019-04-11 17:45:431257 IDC_SHOW_BOOKMARK_BAR, browser_defaults::bookmarks_enabled &&
1258 !profile()->IsGuestSession() &&
1259 !profile()->IsSystemProfile() &&
1260 !profile()->GetPrefs()->IsManagedPreference(
1261 bookmarks::prefs::kShowBookmarkBar) &&
1262 IsShowingMainUI());
[email protected]5d98294912012-06-27 22:57:401263}
1264
[email protected]9ec3ea5b2012-12-03 18:14:301265void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
Ivan Sandrk9669d0e2017-12-15 23:50:201266 if (is_locked_fullscreen_)
1267 return;
1268
[email protected]9ec3ea5b2012-12-03 18:14:301269 UpdateSaveAsState();
[email protected]05454532013-01-22 21:09:081270 UpdateOpenFileState(&command_updater_);
[email protected]9ec3ea5b2012-12-03 18:14:301271}
1272
[email protected]32dfede2013-08-25 15:48:251273void BrowserCommandController::UpdateCommandsForFullscreenMode() {
Ivan Sandrk9669d0e2017-12-15 23:50:201274 if (is_locked_fullscreen_)
1275 return;
1276
zijiehe3c7af992017-02-12 20:59:401277 const bool is_fullscreen = window() && window()->IsFullscreen();
1278 const bool show_main_ui = IsShowingMainUI();
manukf1a116392018-10-25 16:28:241279 const bool show_location_bar = IsShowingLocationBar();
1280
zijiehe3c7af992017-02-12 20:59:401281 const bool main_not_fullscreen = show_main_ui && !is_fullscreen;
[email protected]5d98294912012-06-27 22:57:401282
1283 // Navigation commands
1284 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1285
1286 // Window management commands
1287 command_updater_.UpdateCommandEnabled(
Joel Hockey2687ab52019-08-14 23:59:461288 IDC_SHOW_AS_TAB, !browser_->is_type_normal() && !is_fullscreen);
[email protected]5d98294912012-06-27 22:57:401289
1290 // Focus various bits of UI
1291 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
manukf1a116392018-10-25 16:28:241292 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_location_bar);
[email protected]5d98294912012-06-27 22:57:401293 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
Aran Gilmand217b5b2019-04-11 17:45:431294 command_updater_.UpdateCommandEnabled(IDC_FOCUS_MENU_BAR,
1295 main_not_fullscreen);
1296 command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE,
1297 main_not_fullscreen);
1298 command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE,
1299 main_not_fullscreen);
1300 command_updater_.UpdateCommandEnabled(IDC_FOCUS_BOOKMARKS,
1301 main_not_fullscreen);
[email protected]822ca8c62013-04-19 00:49:151302 command_updater_.UpdateCommandEnabled(
David Tsengc0b1b642018-01-24 07:12:271303 IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY, main_not_fullscreen);
[email protected]5d98294912012-06-27 22:57:401304
1305 // Show various bits of UI
1306 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui);
Nico Weber0cc71122019-07-29 17:30:401307#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
Fabio Rocha19bf4262019-04-04 01:05:181308 command_updater_.UpdateCommandEnabled(
Joel Hockey2687ab52019-08-14 23:59:461309 IDC_FEEDBACK, show_main_ui || browser_->is_type_devtools());
[email protected]236ad3022013-09-04 03:27:431310#endif
Mihai Sardarescu2ec5205682018-09-26 09:20:051311 UpdateShowSyncState(show_main_ui);
[email protected]5d98294912012-06-27 22:57:401312
[email protected]5d98294912012-06-27 22:57:401313 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
1314 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
1315 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
Travis Skare5193bbe12020-04-15 18:31:031316 command_updater_.UpdateCommandEnabled(IDC_QRCODE_GENERATOR, show_main_ui);
[email protected]5d98294912012-06-27 22:57:401317 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
Tina Wangf09681ac2019-03-27 20:52:101318 command_updater_.UpdateCommandEnabled(IDC_SEND_TAB_TO_SELF, show_main_ui);
Tina Wangfa016992019-05-31 00:01:151319 command_updater_.UpdateCommandEnabled(IDC_SEND_TAB_TO_SELF_SINGLE_TARGET,
1320 show_main_ui);
Yann Dago70ca3dd2019-02-27 01:12:351321 command_updater_.UpdateCommandEnabled(IDC_SHOW_MANAGEMENT_PAGE, true);
primianod3a81ab2016-01-25 22:21:151322
1323 if (base::debug::IsProfilingSupported())
1324 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
[email protected]5d98294912012-06-27 22:57:401325
[email protected]aeafc3852014-04-29 16:51:291326#if !defined(OS_MACOSX)
zijiehe3c7af992017-02-12 20:59:401327 // Disable toggling into fullscreen mode if disallowed by pref.
Aran Gilmand217b5b2019-04-11 17:45:431328 const bool fullscreen_enabled =
1329 is_fullscreen ||
zijiehe3c7af992017-02-12 20:59:401330 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed);
1331#else
1332 const bool fullscreen_enabled = true;
[email protected]00a1cc5b2012-11-07 13:44:511333#endif
1334
1335 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled);
spqchanb8ffc7d2015-11-17 01:17:211336 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR,
1337 fullscreen_enabled);
[email protected]5d98294912012-06-27 22:57:401338
1339 UpdateCommandsForBookmarkBar();
zijiehedb473d552017-02-24 01:13:411340 UpdateCommandsForIncognitoAvailability();
Alan Cutter167dfe82018-04-11 09:06:001341 UpdateCommandsForHostedAppAvailability();
1342}
1343
1344void BrowserCommandController::UpdateCommandsForHostedAppAvailability() {
1345 bool has_toolbar =
Joel Hockey2687ab52019-08-14 23:59:461346 browser_->is_type_normal() ||
Alan Cutterd0bd51902019-05-22 04:15:231347 web_app::AppBrowserController::IsForWebAppBrowser(browser_);
Alan Cutter167dfe82018-04-11 09:06:001348 if (window() && window()->ShouldHideUIForFullscreen())
1349 has_toolbar = false;
1350 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, has_toolbar);
1351 command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE, has_toolbar);
1352 command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE, has_toolbar);
1353 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, has_toolbar);
[email protected]5d98294912012-06-27 22:57:401354}
1355
Ivan Sandrk9669d0e2017-12-15 23:50:201356#if defined(OS_CHROMEOS)
1357namespace {
1358
1359#if DCHECK_IS_ON()
1360// Makes sure that all commands that are not whitelisted are disabled. DCHECKs
1361// otherwise. Compiled only in debug mode.
1362void NonWhitelistedCommandsAreDisabled(CommandUpdaterImpl* command_updater) {
Ivan Sandrk6ac9c9a2018-12-14 14:15:071363 constexpr int kWhitelistedIds[] = {IDC_CUT, IDC_COPY, IDC_PASTE};
Ivan Sandrk9669d0e2017-12-15 23:50:201364
1365 // Go through all the command ids, skip the whitelisted ones.
1366 for (int id : command_updater->GetAllIds()) {
Jan Wilken Dörriea8cb56302019-06-06 18:59:361367 if (base::Contains(kWhitelistedIds, id)) {
Ivan Sandrk9669d0e2017-12-15 23:50:201368 continue;
1369 }
1370 DCHECK(!command_updater->IsCommandEnabled(id));
1371 }
1372}
1373#endif
1374
1375} // namespace
1376
1377void BrowserCommandController::UpdateCommandsForLockedFullscreenMode() {
Ivan Sandrke0e92452019-03-21 09:32:481378 bool is_locked_fullscreen =
1379 platform_util::IsBrowserLockedFullscreen(browser_);
Ivan Sandrk9669d0e2017-12-15 23:50:201380 // Sanity check to make sure this function is called only on state change.
1381 DCHECK_NE(is_locked_fullscreen, is_locked_fullscreen_);
1382 if (is_locked_fullscreen == is_locked_fullscreen_)
1383 return;
1384 is_locked_fullscreen_ = is_locked_fullscreen;
1385
1386 if (is_locked_fullscreen_) {
1387 command_updater_.DisableAllCommands();
1388 // Update the state of whitelisted commands:
1389 // IDC_CUT/IDC_COPY/IDC_PASTE,
1390 UpdateCommandsForContentRestrictionState();
Ivan Sandrk6ac9c9a2018-12-14 14:15:071391 // TODO(crbug.com/904637): Re-enable Find and Zoom in locked fullscreen.
Ivan Sandrk9669d0e2017-12-15 23:50:201392 // All other commands will be disabled (there is an early return in their
1393 // corresponding UpdateCommandsFor* functions).
1394#if DCHECK_IS_ON()
1395 NonWhitelistedCommandsAreDisabled(&command_updater_);
1396#endif
1397 } else {
1398 // Do an init call to re-initialize command state after the
1399 // DisableAllCommands.
1400 InitCommandState();
1401 }
1402}
1403#endif
1404
[email protected]5d98294912012-06-27 22:57:401405void BrowserCommandController::UpdatePrintingState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201406 if (is_locked_fullscreen_)
1407 return;
1408
[email protected]d53e4032012-06-29 18:58:341409 bool print_enabled = CanPrint(browser_);
1410 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
Lei Zhang48a4a5262018-04-17 20:18:441411#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:551412 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT,
1413 CanBasicPrint(browser_));
Lei Zhang48a4a5262018-04-17 20:18:441414#endif
[email protected]5d98294912012-06-27 22:57:401415}
1416
1417void BrowserCommandController::UpdateSaveAsState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201418 if (is_locked_fullscreen_)
1419 return;
1420
[email protected]5d98294912012-06-27 22:57:401421 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_));
1422}
1423
Mihai Sardarescu2ec5205682018-09-26 09:20:051424void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) {
1425 if (is_locked_fullscreen_)
1426 return;
1427
Mihai Sardarescuf87ccc12018-09-26 10:37:451428 command_updater_.UpdateCommandEnabled(
Mihai Sardarescu290bc882018-10-12 10:48:141429 IDC_SHOW_SIGNIN, show_main_ui && pref_signin_allowed_.GetValue());
Mihai Sardarescu2ec5205682018-09-26 09:20:051430}
1431
[email protected]05454532013-01-22 21:09:081432// static
1433void BrowserCommandController::UpdateOpenFileState(
1434 CommandUpdater* command_updater) {
[email protected]5d98294912012-06-27 22:57:401435 bool enabled = true;
1436 PrefService* local_state = g_browser_process->local_state();
1437 if (local_state)
1438 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs);
1439
[email protected]05454532013-01-22 21:09:081440 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled);
[email protected]5d98294912012-06-27 22:57:401441}
1442
1443void BrowserCommandController::UpdateReloadStopState(bool is_loading,
1444 bool force) {
Ivan Sandrk9669d0e2017-12-15 23:50:201445 if (is_locked_fullscreen_)
1446 return;
1447
[email protected]5d98294912012-06-27 22:57:401448 window()->UpdateReloadStopState(is_loading, force);
1449 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
Jeff Fisher6cc1ce7b2019-06-28 23:02:381450 UpdateCloseFindOrStop();
[email protected]5d98294912012-06-27 22:57:401451}
1452
[email protected]2e9369e2014-08-15 09:12:531453void BrowserCommandController::UpdateTabRestoreCommandState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201454 if (is_locked_fullscreen_)
1455 return;
1456
blundell74001adc2015-09-18 11:04:251457 sessions::TabRestoreService* tab_restore_service =
[email protected]2e9369e2014-08-15 09:12:531458 TabRestoreServiceFactory::GetForProfile(profile());
1459 // The command is enabled if the service hasn't loaded yet to trigger loading.
1460 // The command is updated once the load completes.
1461 command_updater_.UpdateCommandEnabled(
1462 IDC_RESTORE_TAB,
Peter Kasting32bb2602019-08-22 19:01:431463 tab_restore_service && (!tab_restore_service->IsLoaded() ||
1464 !tab_restore_service->entries().empty()));
[email protected]2e9369e2014-08-15 09:12:531465}
1466
[email protected]3cac87232012-11-20 01:48:271467void BrowserCommandController::UpdateCommandsForFind() {
1468 TabStripModel* model = browser_->tab_strip_model();
Joel Hockey2687ab52019-08-14 23:59:461469 bool enabled = !model->IsTabBlocked(model->active_index()) &&
1470 !browser_->is_type_devtools();
[email protected]3cac87232012-11-20 01:48:271471
1472 command_updater_.UpdateCommandEnabled(IDC_FIND, enabled);
1473 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled);
1474 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled);
1475}
1476
Jeff Fisher6cc1ce7b2019-06-28 23:02:381477void BrowserCommandController::UpdateCloseFindOrStop() {
1478 bool enabled = CanCloseFind(browser_) || IsCommandEnabled(IDC_STOP);
1479 command_updater_.UpdateCommandEnabled(IDC_CLOSE_FIND_OR_STOP, enabled);
1480}
1481
apacible45cbfc92015-09-28 22:45:411482void BrowserCommandController::UpdateCommandsForMediaRouter() {
Ivan Sandrk9669d0e2017-12-15 23:50:201483 if (is_locked_fullscreen_)
1484 return;
1485
apacible45cbfc92015-09-28 22:45:411486 command_updater_.UpdateCommandEnabled(IDC_ROUTE_MEDIA,
1487 CanRouteMedia(browser_));
1488}
1489
Elly Fong-Jones5e6baaf2019-10-10 23:17:141490void BrowserCommandController::UpdateCommandsForTabKeyboardFocus(
1491 base::Optional<int> target_index) {
1492 command_updater_.UpdateCommandEnabled(
1493 IDC_DUPLICATE_TARGET_TAB, !browser_->deprecated_is_app() &&
1494 target_index.has_value() &&
1495 CanDuplicateTabAt(browser_, *target_index));
1496 const bool normal_window = browser_->is_type_normal();
1497 command_updater_.UpdateCommandEnabled(
1498 IDC_MUTE_TARGET_SITE, normal_window && target_index.has_value());
1499 command_updater_.UpdateCommandEnabled(
1500 IDC_PIN_TARGET_TAB, normal_window && target_index.has_value());
Connie Wan303e29e2020-01-31 18:16:561501 command_updater_.UpdateCommandEnabled(
1502 IDC_GROUP_TARGET_TAB, normal_window && target_index.has_value());
Elly Fong-Jones5e6baaf2019-10-10 23:17:141503}
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