blob: 8e19fe8d31477df93b5d778626ebf5dfeee9372f [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"
brettwb1fc1b82016-02-02 00:19:0854#include "components/prefs/pref_service.h"
blundella08c5dd2015-09-18 06:14:1655#include "components/sessions/core/tab_restore_service.h"
Colin Blundell3517170e2019-07-11 08:16:3456#include "components/signin/public/base/signin_pref_names.h"
[email protected]5d98294912012-06-27 22:57:4057#include "content/public/browser/native_web_keyboard_event.h"
58#include "content/public/browser/navigation_controller.h"
59#include "content/public/browser/navigation_entry.h"
Lukasz Anforowicze1b954d92017-10-30 21:28:0660#include "content/public/browser/render_frame_host.h"
[email protected]5d98294912012-06-27 22:57:4061#include "content/public/browser/web_contents.h"
[email protected]20ca0382013-02-28 19:50:0762#include "content/public/browser/web_contents_observer.h"
Bryce Thomas96b07772018-11-07 03:04:1563#include "content/public/common/profiling.h"
bend32292b2016-10-07 00:21:5864#include "content/public/common/service_manager_connection.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"
[email protected]d12cc5e2013-10-19 18:25:0683#endif
84
[email protected]d5bedb6d2014-04-08 10:49:3285#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
karandeepbe6200332016-06-21 12:26:1086#include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h"
[email protected]1e2172f2014-04-01 17:32:3487#endif
88
Collin Baker4ab8ad82019-06-06 17:02:5489#if BUILDFLAG(ENABLE_LEGACY_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:1490#include "chrome/browser/feature_engagement/bookmark/bookmark_tracker.h"
91#include "chrome/browser/feature_engagement/bookmark/bookmark_tracker_factory.h"
Catherine Chungbeb884222017-08-01 15:47:5592#include "chrome/browser/feature_engagement/new_tab/new_tab_tracker.h"
93#include "chrome/browser/feature_engagement/new_tab/new_tab_tracker_factory.h"
94#endif
95
Maksim Sisovac767592018-08-10 08:00:1596#if defined(USE_OZONE)
97#include "ui/ozone/public/ozone_platform.h"
98#endif
99
[email protected]5d98294912012-06-27 22:57:40100using content::NavigationController;
Aran Gilmand217b5b2019-04-11 17:45:43101using content::NavigationEntry;
[email protected]5d98294912012-06-27 22:57:40102using content::WebContents;
103
[email protected]5d98294912012-06-27 22:57:40104namespace chrome {
105
Dana Fried08b774a2019-05-10 18:21:48106namespace {
107
108// Ensures that - if we have not popped up an infobar to prompt the user to e.g.
109// reload the current page - that the content pane of the browser is refocused.
110void AppInfoDialogClosedCallback(content::WebContents* web_contents,
Dana Fried98c0380e2019-05-14 16:58:32111 views::Widget::ClosedReason closed_reason,
Dana Fried08b774a2019-05-10 18:21:48112 bool reload_prompt) {
113 if (reload_prompt)
114 return;
115
Dana Fried98c0380e2019-05-14 16:58:32116 // If the user clicked on something specific or focus was changed, don't
117 // override the focus.
118 if (closed_reason != views::Widget::ClosedReason::kEscKeyPressed &&
119 closed_reason != views::Widget::ClosedReason::kCloseButtonClicked) {
120 return;
121 }
122
Dana Fried08b774a2019-05-10 18:21:48123 // Ensure that the web contents handle we have is still valid. It's possible
124 // (though unlikely) that either the browser or web contents has been pulled
125 // out from underneath us.
126 Browser* const browser = chrome::FindBrowserWithWebContents(web_contents);
127 if (!browser)
128 return;
129
130 // We want to focus the active web contents, which again, might not be the
131 // original web contents (though it should be the vast majority of the time).
132 content::WebContents* const active_contents =
133 browser->tab_strip_model()->GetActiveWebContents();
134 if (active_contents)
135 active_contents->Focus();
136}
137
138} // namespace
139
[email protected]5d98294912012-06-27 22:57:40140///////////////////////////////////////////////////////////////////////////////
141// BrowserCommandController, public:
142
[email protected]338416c02014-05-13 16:47:06143BrowserCommandController::BrowserCommandController(Browser* browser)
Aran Gilmand217b5b2019-04-11 17:45:43144 : browser_(browser), command_updater_(nullptr) {
[email protected]5d98294912012-06-27 22:57:40145 browser_->tab_strip_model()->AddObserver(this);
146 PrefService* local_state = g_browser_process->local_state();
147 if (local_state) {
148 local_pref_registrar_.Init(local_state);
[email protected]9ec3ea5b2012-12-03 18:14:30149 local_pref_registrar_.Add(
150 prefs::kAllowFileSelectionDialogs,
151 base::Bind(
152 &BrowserCommandController::UpdateCommandsForFileSelectionDialogs,
153 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40154 }
155
156 profile_pref_registrar_.Init(profile()->GetPrefs());
[email protected]9ec3ea5b2012-12-03 18:14:30157 profile_pref_registrar_.Add(
Pavol Markodebb0ff2018-05-07 18:35:41158 prefs::kDevToolsAvailability,
[email protected]9ec3ea5b2012-12-03 18:14:30159 base::Bind(&BrowserCommandController::UpdateCommandsForDevTools,
160 base::Unretained(this)));
161 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32162 bookmarks::prefs::kEditBookmarksEnabled,
[email protected]9ec3ea5b2012-12-03 18:14:30163 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkEditing,
164 base::Unretained(this)));
165 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32166 bookmarks::prefs::kShowBookmarkBar,
[email protected]9ec3ea5b2012-12-03 18:14:30167 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkBar,
168 base::Unretained(this)));
169 profile_pref_registrar_.Add(
170 prefs::kIncognitoModeAvailability,
171 base::Bind(
172 &BrowserCommandController::UpdateCommandsForIncognitoAvailability,
173 base::Unretained(this)));
174 profile_pref_registrar_.Add(
175 prefs::kPrintingEnabled,
176 base::Bind(&BrowserCommandController::UpdatePrintingState,
177 base::Unretained(this)));
[email protected]32dfede2013-08-25 15:48:25178#if !defined(OS_MACOSX)
179 profile_pref_registrar_.Add(
180 prefs::kFullscreenAllowed,
181 base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode,
182 base::Unretained(this)));
183#endif
Mihai Sardarescuf87ccc12018-09-26 10:37:45184 pref_signin_allowed_.Init(
Aran Gilmand217b5b2019-04-11 17:45:43185 prefs::kSigninAllowed, profile()->GetOriginalProfile()->GetPrefs(),
Mihai Sardarescuf87ccc12018-09-26 10:37:45186 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange,
187 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40188
189 InitCommandState();
190
blundell74001adc2015-09-18 11:04:25191 sessions::TabRestoreService* tab_restore_service =
[email protected]5d98294912012-06-27 22:57:40192 TabRestoreServiceFactory::GetForProfile(profile());
193 if (tab_restore_service) {
194 tab_restore_service->AddObserver(this);
Cliff Smolinsky2c9586e2019-02-08 18:48:30195 if (!tab_restore_service->IsLoaded())
196 tab_restore_service->LoadTabsFromLastSession();
[email protected]5d98294912012-06-27 22:57:40197 }
[email protected]5d98294912012-06-27 22:57:40198}
199
200BrowserCommandController::~BrowserCommandController() {
[email protected]95e39472012-10-05 23:37:36201 // TabRestoreService may have been shutdown by the time we get here. Don't
202 // trigger creating it.
blundell74001adc2015-09-18 11:04:25203 sessions::TabRestoreService* tab_restore_service =
[email protected]95e39472012-10-05 23:37:36204 TabRestoreServiceFactory::GetForProfileIfExisting(profile());
[email protected]5d98294912012-06-27 22:57:40205 if (tab_restore_service)
206 tab_restore_service->RemoveObserver(this);
207 profile_pref_registrar_.RemoveAll();
208 local_pref_registrar_.RemoveAll();
209 browser_->tab_strip_model()->RemoveObserver(this);
210}
211
212bool BrowserCommandController::IsReservedCommandOrKey(
213 int command_id,
214 const content::NativeWebKeyboardEvent& event) {
215 // In Apps mode, no keys are reserved.
Leonard Grey345662a82020-02-07 21:20:03216 if (browser_->is_type_app() || browser_->is_type_app_popup())
[email protected]5d98294912012-06-27 22:57:40217 return false;
218
219#if defined(OS_CHROMEOS)
[email protected]397abd32013-08-21 05:44:19220 // On Chrome OS, the top row of keys are mapped to browser actions like
221 // back/forward or refresh. We don't want web pages to be able to change the
222 // behavior of these keys. Ash handles F4 and up; this leaves us needing to
223 // reserve browser back/forward and refresh here.
[email protected]5d98294912012-06-27 22:57:40224 ui::KeyboardCode key_code =
Blink Reformat1c4d759e2017-04-09 16:34:54225 static_cast<ui::KeyboardCode>(event.windows_key_code);
[email protected]397abd32013-08-21 05:44:19226 if ((key_code == ui::VKEY_BROWSER_BACK && command_id == IDC_BACK) ||
227 (key_code == ui::VKEY_BROWSER_FORWARD && command_id == IDC_FORWARD) ||
228 (key_code == ui::VKEY_BROWSER_REFRESH && command_id == IDC_RELOAD)) {
[email protected]5d98294912012-06-27 22:57:40229 return true;
230 }
231#endif
232
zijiehe68cd3dc22017-04-07 18:50:29233 if (window()->IsFullscreen()) {
234 // In fullscreen, all commands except for IDC_FULLSCREEN and IDC_EXIT should
235 // be delivered to the web page. The intent to implement and ship can be
236 // found in http://crbug.com/680809.
237 const bool is_exit_fullscreen =
238 (command_id == IDC_EXIT || command_id == IDC_FULLSCREEN);
239#if defined(OS_MACOSX)
240 // This behavior is different on Mac OS, which has a unique user-initiated
241 // full-screen mode. According to the discussion in http://crbug.com/702251,
242 // the commands should be reserved for browser-side handling if the browser
243 // window's toolbar is visible.
244 if (window()->IsToolbarShowing()) {
245 if (command_id == IDC_FULLSCREEN)
246 return true;
247 } else {
248 return is_exit_fullscreen;
249 }
250#else
251 return is_exit_fullscreen;
252#endif
253 }
[email protected]1e2172f2014-04-01 17:32:34254
[email protected]893124a22014-04-15 00:45:28255#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]1e2172f2014-04-01 17:32:34256 // If this key was registered by the user as a content editing hotkey, then
257 // it is not reserved.
[email protected]d5bedb6d2014-04-08 10:49:32258 ui::TextEditKeyBindingsDelegateAuraLinux* delegate =
[email protected]1e2172f2014-04-01 17:32:34259 ui::GetTextEditKeyBindingsDelegate();
[email protected]47e8e7542014-04-03 07:52:42260 if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL))
[email protected]1e2172f2014-04-01 17:32:34261 return false;
262#endif
263
Aran Gilmand217b5b2019-04-11 17:45:43264 return command_id == IDC_CLOSE_TAB || command_id == IDC_CLOSE_WINDOW ||
265 command_id == IDC_NEW_INCOGNITO_WINDOW || command_id == IDC_NEW_TAB ||
266 command_id == IDC_NEW_WINDOW || command_id == IDC_RESTORE_TAB ||
zijiehe13207802017-02-16 08:06:10267 command_id == IDC_SELECT_NEXT_TAB ||
Aran Gilmand217b5b2019-04-11 17:45:43268 command_id == IDC_SELECT_PREVIOUS_TAB || command_id == IDC_EXIT;
[email protected]5d98294912012-06-27 22:57:40269}
270
[email protected]5d98294912012-06-27 22:57:40271void BrowserCommandController::TabStateChanged() {
272 UpdateCommandsForTabState();
273}
274
[email protected]d93dbd12014-08-04 23:42:53275void BrowserCommandController::ZoomStateChanged() {
276 UpdateCommandsForZoomState();
277}
278
[email protected]5d98294912012-06-27 22:57:40279void BrowserCommandController::ContentRestrictionsChanged() {
280 UpdateCommandsForContentRestrictionState();
281}
282
283void BrowserCommandController::FullscreenStateChanged() {
[email protected]32dfede2013-08-25 15:48:25284 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40285}
286
Ivan Sandrk9669d0e2017-12-15 23:50:20287#if defined(OS_CHROMEOS)
288void BrowserCommandController::LockedFullscreenStateChanged() {
289 UpdateCommandsForLockedFullscreenMode();
290}
291#endif
292
[email protected]5d98294912012-06-27 22:57:40293void BrowserCommandController::PrintingStateChanged() {
294 UpdatePrintingState();
295}
296
297void BrowserCommandController::LoadingStateChanged(bool is_loading,
298 bool force) {
299 UpdateReloadStopState(is_loading, force);
300}
301
Jeff Fisher6cc1ce7b2019-06-28 23:02:38302void BrowserCommandController::FindBarVisibilityChanged() {
303 if (is_locked_fullscreen_)
304 return;
305 UpdateCloseFindOrStop();
306}
307
wittman76df71db32014-12-18 23:26:58308void BrowserCommandController::ExtensionStateChanged() {
309 // Extensions may disable the bookmark editing commands.
310 UpdateCommandsForBookmarkEditing();
311}
312
Elly Fong-Jones5e6baaf2019-10-10 23:17:14313void BrowserCommandController::TabKeyboardFocusChangedTo(
314 base::Optional<int> index) {
315 UpdateCommandsForTabKeyboardFocus(index);
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;
388
Aran Gilmand217b5b2019-04-11 17:45:43389 // Window management commands
[email protected]5d98294912012-06-27 22:57:40390 case IDC_NEW_WINDOW:
391 NewWindow(browser_);
392 break;
393 case IDC_NEW_INCOGNITO_WINDOW:
Orin Jaworski5e4bcd0c2018-10-16 19:35:05394 NewIncognitoWindow(profile());
[email protected]5d98294912012-06-27 22:57:40395 break;
396 case IDC_CLOSE_WINDOW:
bratell0a7406f2017-03-28 07:46:37397 base::RecordAction(base::UserMetricsAction("CloseWindowByKey"));
[email protected]04b9e692012-08-24 14:49:09398 CloseWindow(browser_);
[email protected]5d98294912012-06-27 22:57:40399 break;
Bettina Dea0a4505922017-09-28 00:53:32400 case IDC_NEW_TAB: {
401 NewTab(browser_);
Collin Baker4ab8ad82019-06-06 17:02:54402#if BUILDFLAG(ENABLE_LEGACY_DESKTOP_IN_PRODUCT_HELP)
Catherine Chungbeb884222017-08-01 15:47:55403 // This is not in NewTab() to avoid tracking programmatic creation of new
404 // tabs by extensions.
Bettina Dea0a4505922017-09-28 00:53:32405 auto* new_tab_tracker =
406 feature_engagement::NewTabTrackerFactory::GetInstance()
407 ->GetForProfile(profile());
408
409 new_tab_tracker->OnNewTabOpened();
410 new_tab_tracker->CloseBubble();
Catherine Chungbeb884222017-08-01 15:47:55411#endif
[email protected]5d98294912012-06-27 22:57:40412 break;
Bettina Dea0a4505922017-09-28 00:53:32413 }
[email protected]5d98294912012-06-27 22:57:40414 case IDC_CLOSE_TAB:
bratell0a7406f2017-03-28 07:46:37415 base::RecordAction(base::UserMetricsAction("CloseTabByKey"));
[email protected]04b9e692012-08-24 14:49:09416 CloseTab(browser_);
[email protected]5d98294912012-06-27 22:57:40417 break;
418 case IDC_SELECT_NEXT_TAB:
bratell0a7406f2017-03-28 07:46:37419 base::RecordAction(base::UserMetricsAction("Accel_SelectNextTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37420 SelectNextTab(browser_,
421 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40422 break;
423 case IDC_SELECT_PREVIOUS_TAB:
bratell0a7406f2017-03-28 07:46:37424 base::RecordAction(base::UserMetricsAction("Accel_SelectPreviousTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37425 SelectPreviousTab(browser_,
426 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40427 break;
[email protected]5d98294912012-06-27 22:57:40428 case IDC_MOVE_TAB_NEXT:
429 MoveTabNext(browser_);
430 break;
431 case IDC_MOVE_TAB_PREVIOUS:
432 MoveTabPrevious(browser_);
433 break;
434 case IDC_SELECT_TAB_0:
435 case IDC_SELECT_TAB_1:
436 case IDC_SELECT_TAB_2:
437 case IDC_SELECT_TAB_3:
438 case IDC_SELECT_TAB_4:
439 case IDC_SELECT_TAB_5:
440 case IDC_SELECT_TAB_6:
441 case IDC_SELECT_TAB_7:
bratell0a7406f2017-03-28 07:46:37442 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37443 SelectNumberedTab(browser_, id - IDC_SELECT_TAB_0,
444 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40445 break;
446 case IDC_SELECT_LAST_TAB:
bratell0a7406f2017-03-28 07:46:37447 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37448 SelectLastTab(browser_,
449 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40450 break;
451 case IDC_DUPLICATE_TAB:
452 DuplicateTab(browser_);
453 break;
454 case IDC_RESTORE_TAB:
455 RestoreTab(browser_);
Collin Baker9bbe1d82019-03-08 01:16:27456 browser_->window()->OnTabRestored(IDC_RESTORE_TAB);
[email protected]5d98294912012-06-27 22:57:40457 break;
[email protected]5d98294912012-06-27 22:57:40458 case IDC_SHOW_AS_TAB:
459 ConvertPopupToTabbedBrowser(browser_);
460 break;
461 case IDC_FULLSCREEN:
[email protected]3f32b9b2012-07-09 16:59:28462 chrome::ToggleFullscreenMode(browser_);
[email protected]5d98294912012-06-27 22:57:40463 break;
Alan Cutter09965802018-03-27 07:25:29464 case IDC_OPEN_IN_PWA_WINDOW:
465 base::RecordAction(base::UserMetricsAction("OpenActiveTabInPwaWindow"));
Eric Willigerse2ca235a2019-08-17 01:01:06466 web_app::ReparentWebAppForSecureActiveTab(browser_);
Alan Cutter09965802018-03-27 07:25:29467 break;
Leonard Greyf13493b2019-12-19 18:12:57468 case IDC_MOVE_TAB_TO_NEW_WINDOW:
Leonard Greya8ecaa32020-01-07 20:57:41469 MoveActiveTabToNewWindow(browser_);
Leonard Greyf13493b2019-12-19 18:12:57470 break;
[email protected]770c6d82012-09-06 22:21:32471
[email protected]d12cc5e2013-10-19 18:25:06472#if defined(OS_CHROMEOS)
473 case IDC_VISIT_DESKTOP_OF_LRU_USER_2:
[email protected]0c930812014-01-30 18:01:47474 case IDC_VISIT_DESKTOP_OF_LRU_USER_3:
zijiehe4dde8072017-02-13 20:38:35475 ExecuteVisitDesktopCommand(id, window()->GetNativeWindow());
[email protected]0c930812014-01-30 18:01:47476 break;
[email protected]d12cc5e2013-10-19 18:25:06477#endif
478
[email protected]893124a22014-04-15 00:45:28479#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15480 case IDC_MINIMIZE_WINDOW:
481 browser_->window()->Minimize();
482 break;
483 case IDC_MAXIMIZE_WINDOW:
484 browser_->window()->Maximize();
485 break;
486 case IDC_RESTORE_WINDOW:
487 browser_->window()->Restore();
488 break;
[email protected]af97be4c62014-02-13 14:43:34489 case IDC_USE_SYSTEM_TITLE_BAR: {
zijiehe4dde8072017-02-13 20:38:35490 PrefService* prefs = profile()->GetPrefs();
[email protected]af97be4c62014-02-13 14:43:34491 prefs->SetBoolean(prefs::kUseCustomChromeFrame,
492 !prefs->GetBoolean(prefs::kUseCustomChromeFrame));
493 break;
494 }
495#endif
496
[email protected]5d98294912012-06-27 22:57:40497#if defined(OS_MACOSX)
spqchanb8ffc7d2015-11-17 01:17:21498 case IDC_TOGGLE_FULLSCREEN_TOOLBAR:
499 chrome::ToggleFullscreenToolbar(browser_);
500 break;
spqchan2c5d541e2017-10-25 07:07:11501 case IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS: {
Robert Sesek03282612018-10-31 15:48:06502 chrome::ToggleJavaScriptFromAppleEventsAllowed(browser_);
spqchan2c5d541e2017-10-25 07:07:11503 break;
504 }
[email protected]5d98294912012-06-27 22:57:40505#endif
506 case IDC_EXIT:
507 Exit();
508 break;
509
510 // Page-related commands
511 case IDC_SAVE_PAGE:
512 SavePage(browser_);
513 break;
Peter Kasting32bb2602019-08-22 19:01:43514 case IDC_BOOKMARK_THIS_TAB:
Collin Baker4ab8ad82019-06-06 17:02:54515#if BUILDFLAG(ENABLE_LEGACY_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:14516 feature_engagement::BookmarkTrackerFactory::GetInstance()
517 ->GetForProfile(profile())
518 ->OnBookmarkAdded();
519#endif
Peter Kasting32bb2602019-08-22 19:01:43520 BookmarkCurrentTabAllowingExtensionOverrides(browser_);
[email protected]5d98294912012-06-27 22:57:40521 break;
[email protected]5d98294912012-06-27 22:57:40522 case IDC_BOOKMARK_ALL_TABS:
Collin Baker4ab8ad82019-06-06 17:02:54523#if BUILDFLAG(ENABLE_LEGACY_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:14524 feature_engagement::BookmarkTrackerFactory::GetInstance()
525 ->GetForProfile(profile())
526 ->OnBookmarkAdded();
527#endif
[email protected]5d98294912012-06-27 22:57:40528 BookmarkAllTabs(browser_);
529 break;
530 case IDC_VIEW_SOURCE:
Lukasz Anforowicze1b954d92017-10-30 21:28:06531 browser_->tab_strip_model()
532 ->GetActiveWebContents()
533 ->GetMainFrame()
534 ->ViewSource();
[email protected]5d98294912012-06-27 22:57:40535 break;
536 case IDC_EMAIL_PAGE_LOCATION:
537 EmailPageLocation(browser_);
538 break;
539 case IDC_PRINT:
540 Print(browser_);
541 break;
bondd052b5f82015-10-28 22:39:32542
Lei Zhang48a4a5262018-04-17 20:18:44543#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:55544 case IDC_BASIC_PRINT:
bratell0a7406f2017-03-28 07:46:37545 base::RecordAction(base::UserMetricsAction("Accel_Advanced_Print"));
vitalybukaf9433e42014-09-08 10:04:55546 BasicPrint(browser_);
[email protected]5d98294912012-06-27 22:57:40547 break;
Lei Zhang48a4a5262018-04-17 20:18:44548#endif // ENABLE_PRINTING
bondd052b5f82015-10-28 22:39:32549
bondd052b5f82015-10-28 22:39:32550 case IDC_SAVE_CREDIT_CARD_FOR_PAGE:
551 SaveCreditCard(browser_);
552 break;
siyua3e599eaa2018-07-13 00:23:06553 case IDC_MIGRATE_LOCAL_CREDIT_CARD_FOR_PAGE:
554 MigrateLocalCards(browser_);
555 break;
siyuac6e018d2019-10-18 01:19:30556 case IDC_SHOW_SAVE_LOCAL_CARD_SIGN_IN_PROMO_IF_APPLICABLE:
557 MaybeShowSaveLocalCardSignInPromo(browser_);
558 break;
559 case IDC_CLOSE_SIGN_IN_PROMO:
560 CloseSaveLocalCardSignInPromo(browser_);
561 break;
[email protected]e625b7602013-10-28 09:24:56562 case IDC_TRANSLATE_PAGE:
563 Translate(browser_);
564 break;
[email protected]4bee4432014-05-05 13:11:41565 case IDC_MANAGE_PASSWORDS_FOR_PAGE:
566 ManagePasswordsForPage(browser_);
567 break;
Tina Wang4c324702019-04-25 18:35:15568 case IDC_SEND_TAB_TO_SELF:
Tina Wang0e7e6e92019-05-14 21:03:03569 SendTabToSelfFromPageAction(browser_);
Tina Wang4c324702019-04-25 18:35:15570 break;
[email protected]4bee4432014-05-05 13:11:41571
[email protected]5d98294912012-06-27 22:57:40572 // Clipboard commands
573 case IDC_CUT:
[email protected]5d98294912012-06-27 22:57:40574 case IDC_COPY:
[email protected]5d98294912012-06-27 22:57:40575 case IDC_PASTE:
pkastingcd3f08bce2015-04-18 13:37:12576 CutCopyPaste(browser_, id);
[email protected]5d98294912012-06-27 22:57:40577 break;
578
579 // Find-in-page
580 case IDC_FIND:
581 Find(browser_);
582 break;
583 case IDC_FIND_NEXT:
584 FindNext(browser_);
585 break;
586 case IDC_FIND_PREVIOUS:
587 FindPrevious(browser_);
588 break;
Jeff Fisher6cc1ce7b2019-06-28 23:02:38589 case IDC_CLOSE_FIND_OR_STOP:
590 if (CanCloseFind(browser_))
591 CloseFind(browser_);
592 else if (IsCommandEnabled(IDC_STOP))
593 ExecuteCommand(IDC_STOP);
594 break;
[email protected]5d98294912012-06-27 22:57:40595
596 // Zoom
597 case IDC_ZOOM_PLUS:
598 Zoom(browser_, content::PAGE_ZOOM_IN);
599 break;
600 case IDC_ZOOM_NORMAL:
601 Zoom(browser_, content::PAGE_ZOOM_RESET);
602 break;
603 case IDC_ZOOM_MINUS:
604 Zoom(browser_, content::PAGE_ZOOM_OUT);
605 break;
606
607 // Focus various bits of UI
608 case IDC_FOCUS_TOOLBAR:
bratell0a7406f2017-03-28 07:46:37609 base::RecordAction(base::UserMetricsAction("Accel_Focus_Toolbar"));
[email protected]5d98294912012-06-27 22:57:40610 FocusToolbar(browser_);
611 break;
612 case IDC_FOCUS_LOCATION:
bratell0a7406f2017-03-28 07:46:37613 base::RecordAction(base::UserMetricsAction("Accel_Focus_Location"));
[email protected]5d98294912012-06-27 22:57:40614 FocusLocationBar(browser_);
615 break;
616 case IDC_FOCUS_SEARCH:
bratell0a7406f2017-03-28 07:46:37617 base::RecordAction(base::UserMetricsAction("Accel_Focus_Search"));
[email protected]5d98294912012-06-27 22:57:40618 FocusSearch(browser_);
619 break;
620 case IDC_FOCUS_MENU_BAR:
621 FocusAppMenu(browser_);
622 break;
623 case IDC_FOCUS_BOOKMARKS:
bratell0a7406f2017-03-28 07:46:37624 base::RecordAction(base::UserMetricsAction("Accel_Focus_Bookmarks"));
[email protected]5d98294912012-06-27 22:57:40625 FocusBookmarksToolbar(browser_);
626 break;
David Tsengc0b1b642018-01-24 07:12:27627 case IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY:
628 FocusInactivePopupForAccessibility(browser_);
[email protected]822ca8c62013-04-19 00:49:15629 break;
[email protected]5d98294912012-06-27 22:57:40630 case IDC_FOCUS_NEXT_PANE:
631 FocusNextPane(browser_);
632 break;
633 case IDC_FOCUS_PREVIOUS_PANE:
634 FocusPreviousPane(browser_);
635 break;
636
637 // Show various bits of UI
638 case IDC_OPEN_FILE:
639 browser_->OpenFile();
640 break;
Alan Cutter81ac726682018-09-25 00:18:36641 case IDC_CREATE_SHORTCUT:
Alan Cutter98844a9fa2019-06-19 21:11:40642 base::RecordAction(base::UserMetricsAction("CreateShortcut"));
Glen Robertsonb9d27412020-01-09 06:48:13643 web_app::CreateWebAppFromCurrentWebContents(
644 browser_, true /* force_shortcut_app */);
Alan Cutter81ac726682018-09-25 00:18:36645 break;
646 case IDC_INSTALL_PWA:
Alan Cutter98844a9fa2019-06-19 21:11:40647 base::RecordAction(base::UserMetricsAction("InstallWebAppFromMenu"));
Glen Robertsonb9d27412020-01-09 06:48:13648 web_app::CreateWebAppFromCurrentWebContents(
649 browser_, false /* force_shortcut_app */);
[email protected]488e3952013-11-18 05:29:14650 break;
[email protected]5d98294912012-06-27 22:57:40651 case IDC_DEV_TOOLS:
[email protected]c934c382013-11-01 00:36:01652 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Show());
[email protected]5d98294912012-06-27 22:57:40653 break;
654 case IDC_DEV_TOOLS_CONSOLE:
einbinderdfa567b2016-12-16 01:15:52655 ToggleDevToolsWindow(browser_, DevToolsToggleAction::ShowConsolePanel());
[email protected]5d98294912012-06-27 22:57:40656 break;
[email protected]2056c3192013-10-21 22:40:51657 case IDC_DEV_TOOLS_DEVICES:
658 InspectUI::InspectDevices(browser_);
659 break;
[email protected]5d98294912012-06-27 22:57:40660 case IDC_DEV_TOOLS_INSPECT:
[email protected]c934c382013-11-01 00:36:01661 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Inspect());
[email protected]5d98294912012-06-27 22:57:40662 break;
[email protected]d16657c2012-09-03 14:25:10663 case IDC_DEV_TOOLS_TOGGLE:
[email protected]c934c382013-11-01 00:36:01664 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Toggle());
[email protected]d16657c2012-09-03 14:25:10665 break;
[email protected]5d98294912012-06-27 22:57:40666 case IDC_TASK_MANAGER:
[email protected]29c262de2013-06-22 15:39:38667 OpenTaskManager(browser_);
[email protected]5d98294912012-06-27 22:57:40668 break;
caelyn4e4e08a2015-02-04 21:27:49669#if defined(OS_CHROMEOS)
670 case IDC_TAKE_SCREENSHOT:
671 TakeScreenshot();
672 break;
673#endif
Nico Weber0cc71122019-07-29 17:30:40674#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
[email protected]5d98294912012-06-27 22:57:40675 case IDC_FEEDBACK:
afakhryf4575bd2017-04-28 02:21:04676 OpenFeedbackDialog(browser_, kFeedbackSourceBrowserCommand);
[email protected]5d98294912012-06-27 22:57:40677 break;
[email protected]236ad3022013-09-04 03:27:43678#endif
[email protected]5d98294912012-06-27 22:57:40679 case IDC_SHOW_BOOKMARK_BAR:
680 ToggleBookmarkBar(browser_);
681 break;
682 case IDC_PROFILING_ENABLED:
Bryce Thomas96b07772018-11-07 03:04:15683 content::Profiling::Toggle();
[email protected]5d98294912012-06-27 22:57:40684 break;
685
686 case IDC_SHOW_BOOKMARK_MANAGER:
687 ShowBookmarkManager(browser_);
688 break;
689 case IDC_SHOW_APP_MENU:
bratell0a7406f2017-03-28 07:46:37690 base::RecordAction(base::UserMetricsAction("Accel_Show_App_Menu"));
[email protected]5d98294912012-06-27 22:57:40691 ShowAppMenu(browser_);
692 break;
693 case IDC_SHOW_AVATAR_MENU:
694 ShowAvatarMenu(browser_);
695 break;
696 case IDC_SHOW_HISTORY:
697 ShowHistory(browser_);
698 break;
699 case IDC_SHOW_DOWNLOADS:
700 ShowDownloads(browser_);
701 break;
702 case IDC_MANAGE_EXTENSIONS:
[email protected]bc9833c32013-02-28 04:05:08703 ShowExtensions(browser_, std::string());
[email protected]5d98294912012-06-27 22:57:40704 break;
705 case IDC_OPTIONS:
706 ShowSettings(browser_);
707 break;
708 case IDC_EDIT_SEARCH_ENGINES:
709 ShowSearchEngineSettings(browser_);
710 break;
711 case IDC_VIEW_PASSWORDS:
712 ShowPasswordManager(browser_);
713 break;
714 case IDC_CLEAR_BROWSING_DATA:
715 ShowClearBrowsingDataDialog(browser_);
716 break;
717 case IDC_IMPORT_SETTINGS:
718 ShowImportDialog(browser_);
719 break;
[email protected]9b7ab882012-09-10 23:46:36720 case IDC_TOGGLE_REQUEST_TABLET_SITE:
721 ToggleRequestTabletSite(browser_);
722 break;
[email protected]5d98294912012-06-27 22:57:40723 case IDC_ABOUT:
724 ShowAboutChrome(browser_);
725 break;
726 case IDC_UPGRADE_DIALOG:
727 OpenUpdateChromeDialog(browser_);
728 break;
[email protected]5d98294912012-06-27 22:57:40729 case IDC_HELP_PAGE_VIA_KEYBOARD:
730 ShowHelp(browser_, HELP_SOURCE_KEYBOARD);
731 break;
732 case IDC_HELP_PAGE_VIA_MENU:
733 ShowHelp(browser_, HELP_SOURCE_MENU);
734 break;
Bret Sepulveda2d018662017-05-18 21:31:48735 case IDC_SHOW_BETA_FORUM:
736 ShowBetaForum(browser_);
737 break;
David Roger7e25dff2019-02-07 09:03:17738#if !defined(OS_CHROMEOS)
estade8c0780f2015-08-21 23:36:41739 case IDC_SHOW_SIGNIN:
gogerald71bf6c902015-12-08 00:49:37740 ShowBrowserSigninOrSettings(
741 browser_, signin_metrics::AccessPoint::ACCESS_POINT_MENU);
estade8c0780f2015-08-21 23:36:41742 break;
David Roger7e25dff2019-02-07 09:03:17743#endif
[email protected]6bd370b2014-05-28 14:19:47744 case IDC_DISTILL_PAGE:
Aran Gilman6586e8f2019-06-03 18:50:56745 ToggleDistilledView(browser_);
[email protected]6bd370b2014-05-28 14:19:47746 break;
apacible45cbfc92015-09-28 22:45:41747 case IDC_ROUTE_MEDIA:
Takumi Fujimotoa8bc3c92019-12-26 20:12:10748 RouteMediaInvokedFromAppMenu(browser_);
apacible45cbfc92015-09-28 22:45:41749 break;
Tommy Steimelc4477982017-11-29 18:07:18750 case IDC_WINDOW_MUTE_SITE:
751 MuteSite(browser_);
ellyjones0101ba02017-05-19 15:50:26752 break;
753 case IDC_WINDOW_PIN_TAB:
754 PinTab(browser_);
755 break;
Connie Wan303e29e2020-01-31 18:16:56756 case IDC_WINDOW_GROUP_TAB:
757 GroupTab(browser_);
758 break;
Elly Fong-Jones2d0443cb2019-11-14 15:04:20759 case IDC_WINDOW_CLOSE_TABS_TO_RIGHT:
760 CloseTabsToRight(browser_);
761 break;
762 case IDC_WINDOW_CLOSE_OTHER_TABS:
763 CloseOtherTabs(browser_);
764 break;
Yann Dagocd13225a2019-03-07 18:39:05765 case IDC_SHOW_MANAGEMENT_PAGE: {
Yann Dagoc1d1c4af2019-04-17 13:40:51766 ShowSingletonTab(browser_, GURL(kChromeUIManagementURL));
Nicolas Ouellet-payeur82eb65b2018-11-05 16:49:27767 break;
Yann Dagocd13225a2019-03-07 18:39:05768 }
Elly Fong-Jones5e6baaf2019-10-10 23:17:14769 case IDC_MUTE_TARGET_SITE:
770 MuteSiteForKeyboardFocusedTab(browser_);
771 break;
772 case IDC_PIN_TARGET_TAB:
773 PinKeyboardFocusedTab(browser_);
774 break;
Connie Wan303e29e2020-01-31 18:16:56775 case IDC_GROUP_TARGET_TAB:
776 GroupKeyboardFocusedTab(browser_);
777 break;
Elly Fong-Jones5e6baaf2019-10-10 23:17:14778 case IDC_DUPLICATE_TARGET_TAB:
779 DuplicateKeyboardFocusedTab(browser_);
780 break;
Christopher Lam0dbac2b2017-11-14 07:12:10781 // Hosted App commands
782 case IDC_COPY_URL:
783 CopyURL(browser_);
784 break;
785 case IDC_OPEN_IN_CHROME:
786 OpenInChrome(browser_);
787 break;
788 case IDC_SITE_SETTINGS:
789 ShowSiteSettings(
790 browser_,
791 browser_->tab_strip_model()->GetActiveWebContents()->GetVisibleURL());
792 break;
Alan Cuttera99d1522019-09-12 02:09:22793 case IDC_WEB_APP_MENU_APP_INFO: {
Dana Fried08b774a2019-05-10 18:21:48794 content::WebContents* const web_contents =
795 browser_->tab_strip_model()->GetActiveWebContents();
796 if (web_contents) {
797 ShowPageInfoDialog(web_contents,
798 base::BindOnce(&AppInfoDialogClosedCallback,
799 base::Unretained(web_contents)),
800 bubble_anchor_util::kAppMenuButton);
801 }
Christopher Lam86b52712017-12-04 01:58:33802 break;
Dana Fried08b774a2019-05-10 18:21:48803 }
[email protected]5d98294912012-06-27 22:57:40804 default:
805 LOG(WARNING) << "Received Unimplemented Command: " << id;
806 break;
807 }
Ivan Sandrk9669d0e2017-12-15 23:50:20808
809 return true;
810}
811
812void BrowserCommandController::AddCommandObserver(int id,
813 CommandObserver* observer) {
814 command_updater_.AddCommandObserver(id, observer);
815}
816
817void BrowserCommandController::RemoveCommandObserver(
Aran Gilmand217b5b2019-04-11 17:45:43818 int id,
819 CommandObserver* observer) {
Ivan Sandrk9669d0e2017-12-15 23:50:20820 command_updater_.RemoveCommandObserver(id, observer);
821}
822
823void BrowserCommandController::RemoveCommandObserver(
824 CommandObserver* observer) {
825 command_updater_.RemoveCommandObserver(observer);
826}
827
828bool BrowserCommandController::UpdateCommandEnabled(int id, bool state) {
829 if (is_locked_fullscreen_)
830 return false;
831
832 return command_updater_.UpdateCommandEnabled(id, state);
[email protected]5d98294912012-06-27 22:57:40833}
834
Mihai Sardarescuf87ccc12018-09-26 10:37:45835////////////////////////////////////////////////////////////////////////////////
836// BrowserCommandController, SigninPrefObserver implementation:
837
838void BrowserCommandController::OnSigninAllowedPrefChange() {
839 // For unit tests, we don't have a window.
840 if (!window())
841 return;
842 UpdateShowSyncState(IsShowingMainUI());
843}
844
[email protected]5d98294912012-06-27 22:57:40845// BrowserCommandController, TabStripModelObserver implementation:
846
sangwoo.ko1ae265f12018-10-18 08:30:28847void BrowserCommandController::OnTabStripModelChanged(
848 TabStripModel* tab_strip_model,
849 const TabStripModelChange& change,
850 const TabStripSelectionChange& selection) {
Dana Frieda391e6ce2019-05-08 00:00:20851 std::vector<content::WebContents*> new_contents;
852 std::vector<content::WebContents*> old_contents;
[email protected]5d98294912012-06-27 22:57:40853
Dana Frieda391e6ce2019-05-08 00:00:20854 switch (change.type()) {
855 case TabStripModelChange::kInserted:
856 for (const auto& contents : change.GetInsert()->contents)
857 new_contents.push_back(contents.contents);
858 break;
859 case TabStripModelChange::kReplaced: {
860 auto* replace = change.GetReplace();
861 new_contents.push_back(replace->new_contents);
862 old_contents.push_back(replace->old_contents);
863 break;
sangwoo.ko1ae265f12018-10-18 08:30:28864 }
Dana Frieda391e6ce2019-05-08 00:00:20865 case TabStripModelChange::kRemoved:
866 for (const auto& contents : change.GetRemove()->contents)
867 old_contents.push_back(contents.contents);
868 break;
869 default:
870 break;
sangwoo.ko1ae265f12018-10-18 08:30:28871 }
Dana Frieda391e6ce2019-05-08 00:00:20872
873 for (auto* contents : old_contents)
874 RemoveInterstitialObservers(contents);
875 for (auto* contents : new_contents)
876 AddInterstitialObservers(contents);
[email protected]5d98294912012-06-27 22:57:40877}
878
[email protected]3cac87232012-11-20 01:48:27879void BrowserCommandController::TabBlockedStateChanged(
880 content::WebContents* contents,
881 int index) {
882 PrintingStateChanged();
883 FullscreenStateChanged();
884 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:41885 UpdateCommandsForMediaRouter();
[email protected]3cac87232012-11-20 01:48:27886}
887
[email protected]5d98294912012-06-27 22:57:40888////////////////////////////////////////////////////////////////////////////////
889// BrowserCommandController, TabRestoreServiceObserver implementation:
890
891void BrowserCommandController::TabRestoreServiceChanged(
blundell74001adc2015-09-18 11:04:25892 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53893 UpdateTabRestoreCommandState();
[email protected]5d98294912012-06-27 22:57:40894}
895
896void BrowserCommandController::TabRestoreServiceDestroyed(
blundell74001adc2015-09-18 11:04:25897 sessions::TabRestoreService* service) {
[email protected]5d98294912012-06-27 22:57:40898 service->RemoveObserver(this);
899}
900
[email protected]2e9369e2014-08-15 09:12:53901void BrowserCommandController::TabRestoreServiceLoaded(
blundell74001adc2015-09-18 11:04:25902 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53903 UpdateTabRestoreCommandState();
904}
905
[email protected]5d98294912012-06-27 22:57:40906////////////////////////////////////////////////////////////////////////////////
[email protected]5d98294912012-06-27 22:57:40907// BrowserCommandController, private:
908
[email protected]20ca0382013-02-28 19:50:07909class BrowserCommandController::InterstitialObserver
910 : public content::WebContentsObserver {
911 public:
912 InterstitialObserver(BrowserCommandController* controller,
913 content::WebContents* web_contents)
Aran Gilmand217b5b2019-04-11 17:45:43914 : WebContentsObserver(web_contents), controller_(controller) {}
[email protected]20ca0382013-02-28 19:50:07915
dcheng5dd5ff62014-10-21 12:42:38916 void DidAttachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07917 controller_->UpdateCommandsForTabState();
918 }
919
dcheng5dd5ff62014-10-21 12:42:38920 void DidDetachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07921 controller_->UpdateCommandsForTabState();
922 }
923
924 private:
925 BrowserCommandController* controller_;
926
927 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver);
928};
929
[email protected]6a414ff2013-02-27 08:22:54930bool BrowserCommandController::IsShowingMainUI() {
manukf1a116392018-10-25 16:28:24931 return browser_->SupportsWindowFeature(Browser::FEATURE_TABSTRIP);
932}
933
934bool BrowserCommandController::IsShowingLocationBar() {
935 return browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
[email protected]5d98294912012-06-27 22:57:40936}
937
938void BrowserCommandController::InitCommandState() {
939 // All browser commands whose state isn't set automagically some other way
940 // (like Back & Forward with initial page load) must have their state
941 // initialized here, otherwise they will be forever disabled.
942
Ivan Sandrk9669d0e2017-12-15 23:50:20943 if (is_locked_fullscreen_)
944 return;
945
[email protected]5d98294912012-06-27 22:57:40946 // Navigation commands
947 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true);
toyoshim7dad4b1182016-04-01 14:28:05948 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE, true);
[email protected]58e29032012-08-06 20:19:57949 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, true);
[email protected]5d98294912012-06-27 22:57:40950
951 // Window management commands
952 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true);
953 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true);
954 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true);
955 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true);
[email protected]2e9369e2014-08-15 09:12:53956 UpdateTabRestoreCommandState();
[email protected]d28d3782013-02-26 16:31:55957 command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
[email protected]5d98294912012-06-27 22:57:40958 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true);
[email protected]d12cc5e2013-10-19 18:25:06959#if defined(OS_CHROMEOS)
James Cook934abaf2017-09-19 22:21:58960 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
[email protected]d12cc5e2013-10-19 18:25:06961 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_2, true);
962 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_3, true);
963#endif
[email protected]893124a22014-04-15 00:45:28964#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15965 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
966 command_updater_.UpdateCommandEnabled(IDC_MAXIMIZE_WINDOW, true);
967 command_updater_.UpdateCommandEnabled(IDC_RESTORE_WINDOW, true);
Maksim Sisovac767592018-08-10 08:00:15968 bool use_system_title_bar = true;
969#if defined(USE_OZONE)
970 use_system_title_bar = ui::OzonePlatform::GetInstance()
971 ->GetPlatformProperties()
972 .use_system_title_bar;
973#endif
974 command_updater_.UpdateCommandEnabled(IDC_USE_SYSTEM_TITLE_BAR,
975 use_system_title_bar);
[email protected]af97be4c62014-02-13 14:43:34976#endif
Alan Cutter09965802018-03-27 07:25:29977 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW, true);
[email protected]5d98294912012-06-27 22:57:40978
979 // Page-related commands
980 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true);
[email protected]4bee4432014-05-05 13:11:41981 command_updater_.UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE, true);
[email protected]5d98294912012-06-27 22:57:40982
983 // Zoom
984 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true);
985 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true);
[email protected]d93dbd12014-08-04 23:42:53986 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, false);
[email protected]5d98294912012-06-27 22:57:40987 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
988
989 // Show various bits of UI
Aran Gilmand217b5b2019-04-11 17:45:43990 const bool guest_session =
991 profile()->IsGuestSession() || profile()->IsSystemProfile();
mlerman7831f57d2015-05-25 11:40:15992 DCHECK(!profile()->IsSystemProfile())
993 << "Ought to never have browser for the system profile.";
Joel Hockey2687ab52019-08-14 23:59:46994 const bool normal_window = browser_->is_type_normal();
[email protected]05454532013-01-22 21:09:08995 UpdateOpenFileState(&command_updater_);
[email protected]5d98294912012-06-27 22:57:40996 UpdateCommandsForDevTools();
997 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager());
[email protected]338416c02014-05-13 16:47:06998 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session);
[email protected]5d98294912012-06-27 22:57:40999 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
[email protected]674b65672014-06-02 23:21:561000 command_updater_.UpdateCommandEnabled(IDC_HELP_MENU, true);
[email protected]5d98294912012-06-27 22:57:401001 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
1002 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
Bret Sepulveda2d018662017-05-18 21:31:481003 command_updater_.UpdateCommandEnabled(IDC_SHOW_BETA_FORUM, true);
[email protected]338416c02014-05-13 16:47:061004 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session);
Aran Gilmand217b5b2019-04-11 17:45:431005 command_updater_.UpdateCommandEnabled(
1006 IDC_RECENT_TABS_MENU, !guest_session && !profile()->IsOffTheRecord());
Rohit Agarwal2a2230b2019-08-21 15:53:411007 command_updater_.UpdateCommandEnabled(
1008 IDC_CLEAR_BROWSING_DATA,
1009 !guest_session && !profile()->IsIncognitoProfile());
[email protected]39d47592014-01-10 21:42:451010#if defined(OS_CHROMEOS)
caelyn4e4e08a2015-02-04 21:27:491011 command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true);
Ramin Halavatif362b7a2019-04-17 05:24:501012 // Chrome OS uses the system tray menu to handle multi-profiles. Avatar menu
1013 // is only required in incognito mode.
Ramin Halavati2394dc452019-05-21 16:21:581014 if (profile()->IsIncognitoProfile())
[email protected]338416c02014-05-13 16:47:061015 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
Ramin Halavatif362b7a2019-04-17 05:24:501016#else
1017 if (normal_window)
1018 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
[email protected]39d47592014-01-10 21:42:451019#endif
siyuac6e018d2019-10-18 01:19:301020 command_updater_.UpdateCommandEnabled(
1021 IDC_SHOW_SAVE_LOCAL_CARD_SIGN_IN_PROMO_IF_APPLICABLE, true);
1022 command_updater_.UpdateCommandEnabled(IDC_CLOSE_SIGN_IN_PROMO, true);
[email protected]5d98294912012-06-27 22:57:401023
Mihai Sardarescu2ec5205682018-09-26 09:20:051024 UpdateShowSyncState(true);
1025
[email protected]5d98294912012-06-27 22:57:401026 // Navigation commands
Joel Hockey2687ab52019-08-14 23:59:461027 command_updater_.UpdateCommandEnabled(
1028 IDC_HOME, normal_window || browser_->deprecated_is_app());
[email protected]5d98294912012-06-27 22:57:401029
Alan Cutterd0bd51902019-05-22 04:15:231030 const bool is_web_app =
1031 web_app::AppBrowserController::IsForWebAppBrowser(browser_);
Christopher Lam0dbac2b2017-11-14 07:12:101032 // Hosted app browser commands.
Alan Cutterd0bd51902019-05-22 04:15:231033 command_updater_.UpdateCommandEnabled(IDC_COPY_URL, is_web_app);
1034 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_CHROME, is_web_app);
1035 command_updater_.UpdateCommandEnabled(IDC_SITE_SETTINGS, is_web_app);
Alan Cuttera99d1522019-09-12 02:09:221036 command_updater_.UpdateCommandEnabled(IDC_WEB_APP_MENU_APP_INFO, is_web_app);
Christopher Lam0dbac2b2017-11-14 07:12:101037
[email protected]5d98294912012-06-27 22:57:401038 // Window management commands
[email protected]5d98294912012-06-27 22:57:401039 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window);
Aran Gilmand217b5b2019-04-11 17:45:431040 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, normal_window);
[email protected]5d98294912012-06-27 22:57:401041 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window);
1042 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window);
1043 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window);
1044 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window);
1045 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window);
1046 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window);
1047 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window);
1048 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window);
1049 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window);
1050 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window);
1051 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window);
[email protected]5d98294912012-06-27 22:57:401052
[email protected]338416c02014-05-13 16:47:061053 // These are always enabled; the menu determines their menu item visibility.
[email protected]5d98294912012-06-27 22:57:401054 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
[email protected]5d98294912012-06-27 22:57:401055
[email protected]6bd370b2014-05-28 14:19:471056 // Distill current page.
Aran Gilman7b6ccf5d2019-09-05 19:16:021057 command_updater_.UpdateCommandEnabled(IDC_DISTILL_PAGE,
1058 dom_distiller::IsDomDistillerEnabled());
[email protected]6bd370b2014-05-28 14:19:471059
Tommy Steimelc4477982017-11-29 18:07:181060 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE, normal_window);
ellyjones0101ba02017-05-19 15:50:261061 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, normal_window);
Connie Wan303e29e2020-01-31 18:16:561062 command_updater_.UpdateCommandEnabled(IDC_WINDOW_GROUP_TAB, normal_window);
Elly Fong-Jones2d0443cb2019-11-14 15:04:201063 command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_TABS_TO_RIGHT,
1064 normal_window);
1065 command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_OTHER_TABS,
1066 normal_window);
ellyjones0101ba02017-05-19 15:50:261067
[email protected]338416c02014-05-13 16:47:061068 // Initialize other commands whose state changes based on various conditions.
[email protected]32dfede2013-08-25 15:48:251069 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:401070 UpdateCommandsForContentRestrictionState();
[email protected]5d98294912012-06-27 22:57:401071 UpdateCommandsForBookmarkEditing();
[email protected]5d98294912012-06-27 22:57:401072 UpdateCommandsForIncognitoAvailability();
Elly Fong-Jones5e6baaf2019-10-10 23:17:141073 UpdateCommandsForTabKeyboardFocus(GetKeyboardFocusedTabIndex(browser_));
[email protected]5d98294912012-06-27 22:57:401074}
1075
[email protected]05454532013-01-22 21:09:081076// static
1077void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
1078 CommandUpdater* command_updater,
1079 Profile* profile) {
mlermane01e6de2014-09-29 19:26:471080 const bool guest_session = profile->IsGuestSession();
1081 // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession().
[email protected]5d98294912012-06-27 22:57:401082 IncognitoModePrefs::Availability incognito_availability =
[email protected]05454532013-01-22 21:09:081083 IncognitoModePrefs::GetAvailability(profile->GetPrefs());
1084 command_updater->UpdateCommandEnabled(
Aran Gilmand217b5b2019-04-11 17:45:431085 IDC_NEW_WINDOW, incognito_availability != IncognitoModePrefs::FORCED);
[email protected]05454532013-01-22 21:09:081086 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:401087 IDC_NEW_INCOGNITO_WINDOW,
mlermane01e6de2014-09-29 19:26:471088 incognito_availability != IncognitoModePrefs::DISABLED && !guest_session);
[email protected]5d98294912012-06-27 22:57:401089
[email protected]57b25292014-05-01 16:31:061090 const bool forced_incognito =
1091 incognito_availability == IncognitoModePrefs::FORCED ||
1092 guest_session; // Guest always runs in Incognito mode.
[email protected]05454532013-01-22 21:09:081093 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:401094 IDC_SHOW_BOOKMARK_MANAGER,
[email protected]57b25292014-05-01 16:31:061095 browser_defaults::bookmarks_enabled && !forced_incognito);
Devlin Cronin21dba422018-05-30 15:45:161096 extensions::ExtensionService* extension_service =
[email protected]03d25812014-06-22 19:41:551097 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]57b25292014-05-01 16:31:061098 const bool enable_extensions =
[email protected]5d98294912012-06-27 22:57:401099 extension_service && extension_service->extensions_enabled();
[email protected]5d98294912012-06-27 22:57:401100
[email protected]57b25292014-05-01 16:31:061101 // Bookmark manager and settings page/subpages are forced to open in normal
1102 // mode. For this reason we disable these commands when incognito is forced.
1103 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
1104 enable_extensions && !forced_incognito);
1105
1106 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito);
1107 command_updater->UpdateCommandEnabled(IDC_OPTIONS,
1108 !forced_incognito || guest_session);
estade8c0780f2015-08-21 23:36:411109 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito);
[email protected]05454532013-01-22 21:09:081110}
1111
1112void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
Ivan Sandrk9669d0e2017-12-15 23:50:201113 if (is_locked_fullscreen_)
1114 return;
1115
[email protected]05454532013-01-22 21:09:081116 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile());
1117
[email protected]6a414ff2013-02-27 08:22:541118 if (!IsShowingMainUI()) {
[email protected]05454532013-01-22 21:09:081119 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false);
1120 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false);
1121 }
[email protected]5d98294912012-06-27 22:57:401122}
1123
1124void BrowserCommandController::UpdateCommandsForTabState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201125 if (is_locked_fullscreen_)
1126 return;
1127
[email protected]617ee962013-01-29 20:49:121128 WebContents* current_web_contents =
1129 browser_->tab_strip_model()->GetActiveWebContents();
[email protected]1c5119c2012-09-19 00:08:571130 if (!current_web_contents) // May be NULL during tab restore.
[email protected]5d98294912012-06-27 22:57:401131 return;
[email protected]5d98294912012-06-27 22:57:401132
1133 // Navigation commands
1134 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_));
1135 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_));
1136 command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_));
toyoshim7dad4b1182016-04-01 14:28:051137 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE,
[email protected]5d98294912012-06-27 22:57:401138 CanReload(browser_));
[email protected]58e29032012-08-06 20:19:571139 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE,
1140 CanReload(browser_));
[email protected]5d98294912012-06-27 22:57:401141
1142 // Window management commands
Aran Gilmand217b5b2019-04-11 17:45:431143 command_updater_.UpdateCommandEnabled(
Joel Hockey2687ab52019-08-14 23:59:461144 IDC_DUPLICATE_TAB,
1145 !browser_->deprecated_is_app() && CanDuplicateTab(browser_));
Tommy Steimelc4477982017-11-29 18:07:181146 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE,
Joel Hockey2687ab52019-08-14 23:59:461147 !browser_->deprecated_is_app());
ellyjones0101ba02017-05-19 15:50:261148 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB,
Joel Hockey2687ab52019-08-14 23:59:461149 !browser_->deprecated_is_app());
Connie Wan303e29e2020-01-31 18:16:561150 command_updater_.UpdateCommandEnabled(IDC_WINDOW_GROUP_TAB,
1151 !browser_->deprecated_is_app());
Elly Fong-Jones2d0443cb2019-11-14 15:04:201152 command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_TABS_TO_RIGHT,
1153 CanCloseTabsToRight(browser_));
1154 command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_OTHER_TABS,
1155 CanCloseOtherTabs(browser_));
Leonard Greyf13493b2019-12-19 18:12:571156 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_TO_NEW_WINDOW,
Leonard Greya8ecaa32020-01-07 20:57:411157 CanMoveActiveTabToNewWindow(browser_));
[email protected]5d98294912012-06-27 22:57:401158
1159 // Page-related commands
1160 window()->SetStarredState(
[email protected]1c5119c2012-09-19 00:08:571161 BookmarkTabHelper::FromWebContents(current_web_contents)->is_starred());
[email protected]5423c372012-08-22 05:50:161162 window()->ZoomChangedForActiveTab(false);
[email protected]5d98294912012-06-27 22:57:401163 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
1164 CanViewSource(browser_));
1165 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION,
1166 CanEmailPageLocation(browser_));
Joel Hockey2687ab52019-08-14 23:59:461167 if (browser_->is_type_devtools())
[email protected]5d98294912012-06-27 22:57:401168 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false);
1169
Glen Robertsonb9d27412020-01-09 06:48:131170 bool can_create_web_app = web_app::CanCreateWebApp(browser_);
1171 command_updater_.UpdateCommandEnabled(IDC_INSTALL_PWA, can_create_web_app);
Alan Cutter81ac726682018-09-25 00:18:361172 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUT,
Glen Robertsonb9d27412020-01-09 06:48:131173 can_create_web_app);
1174 // Note that additional logic in AppMenuModel::Build() controls the presence
1175 // of this command.
Alan Cutter403cebb2018-05-17 05:22:451176 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW,
Glen Robertsonb9d27412020-01-09 06:48:131177 web_app::CanPopOutWebApp(profile()));
[email protected]5d98294912012-06-27 22:57:401178
[email protected]9b7ab882012-09-10 23:46:361179 command_updater_.UpdateCommandEnabled(
1180 IDC_TOGGLE_REQUEST_TABLET_SITE,
1181 CanRequestTabletSite(current_web_contents));
1182
[email protected]5d98294912012-06-27 22:57:401183 UpdateCommandsForContentRestrictionState();
1184 UpdateCommandsForBookmarkEditing();
[email protected]3cac87232012-11-20 01:48:271185 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:411186 UpdateCommandsForMediaRouter();
[email protected]d93dbd12014-08-04 23:42:531187 // Update the zoom commands when an active tab is selected.
1188 UpdateCommandsForZoomState();
Elly Fong-Jones5e6baaf2019-10-10 23:17:141189 UpdateCommandsForTabKeyboardFocus(GetKeyboardFocusedTabIndex(browser_));
[email protected]d93dbd12014-08-04 23:42:531190}
1191
1192void BrowserCommandController::UpdateCommandsForZoomState() {
Aran Gilmand217b5b2019-04-11 17:45:431193 WebContents* contents = browser_->tab_strip_model()->GetActiveWebContents();
[email protected]d93dbd12014-08-04 23:42:531194 if (!contents)
1195 return;
Aran Gilmand217b5b2019-04-11 17:45:431196 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, CanZoomIn(contents));
a.sarkar.arundaadc712015-02-26 05:39:081197 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL,
ccameronb7c1d6c2015-03-09 17:08:241198 CanResetZoom(contents));
Aran Gilmand217b5b2019-04-11 17:45:431199 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, CanZoomOut(contents));
[email protected]5d98294912012-06-27 22:57:401200}
1201
1202void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
1203 int restrictions = GetContentRestrictions(browser_);
1204
1205 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011206 IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY));
[email protected]5d98294912012-06-27 22:57:401207 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011208 IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT));
[email protected]5d98294912012-06-27 22:57:401209 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011210 IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE));
[email protected]5d98294912012-06-27 22:57:401211 UpdateSaveAsState();
1212 UpdatePrintingState();
1213}
1214
1215void BrowserCommandController::UpdateCommandsForDevTools() {
Ivan Sandrk9669d0e2017-12-15 23:50:201216 if (is_locked_fullscreen_)
1217 return;
1218
Pavol Marko56df0272018-07-04 17:55:041219 bool dev_tools_enabled = DevToolsWindow::AllowDevToolsFor(
1220 profile(), browser_->tab_strip_model()->GetActiveWebContents());
Aran Gilmand217b5b2019-04-11 17:45:431221 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS, dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401222 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE,
1223 dev_tools_enabled);
[email protected]2056c3192013-10-21 22:40:511224 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES,
1225 dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401226 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT,
1227 dev_tools_enabled);
[email protected]d16657c2012-09-03 14:25:101228 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE,
1229 dev_tools_enabled);
spqchan2c5d541e2017-10-25 07:07:111230#if defined(OS_MACOSX)
1231 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS,
1232 dev_tools_enabled);
1233#endif
[email protected]5d98294912012-06-27 22:57:401234}
1235
1236void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
Ivan Sandrk9669d0e2017-12-15 23:50:201237 if (is_locked_fullscreen_)
1238 return;
1239
Peter Kasting32bb2602019-08-22 19:01:431240 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_THIS_TAB,
1241 CanBookmarkCurrentTab(browser_));
[email protected]5d98294912012-06-27 22:57:401242 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
1243 CanBookmarkAllTabs(browser_));
thestig5149d272014-10-30 07:25:291244#if defined(OS_WIN)
1245 command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN, true);
1246#endif
[email protected]5d98294912012-06-27 22:57:401247}
1248
1249void BrowserCommandController::UpdateCommandsForBookmarkBar() {
Ivan Sandrk9669d0e2017-12-15 23:50:201250 if (is_locked_fullscreen_)
1251 return;
1252
tfarina3bddbe112014-08-28 05:29:321253 command_updater_.UpdateCommandEnabled(
Aran Gilmand217b5b2019-04-11 17:45:431254 IDC_SHOW_BOOKMARK_BAR, browser_defaults::bookmarks_enabled &&
1255 !profile()->IsGuestSession() &&
1256 !profile()->IsSystemProfile() &&
1257 !profile()->GetPrefs()->IsManagedPreference(
1258 bookmarks::prefs::kShowBookmarkBar) &&
1259 IsShowingMainUI());
[email protected]5d98294912012-06-27 22:57:401260}
1261
[email protected]9ec3ea5b2012-12-03 18:14:301262void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
Ivan Sandrk9669d0e2017-12-15 23:50:201263 if (is_locked_fullscreen_)
1264 return;
1265
[email protected]9ec3ea5b2012-12-03 18:14:301266 UpdateSaveAsState();
[email protected]05454532013-01-22 21:09:081267 UpdateOpenFileState(&command_updater_);
[email protected]9ec3ea5b2012-12-03 18:14:301268}
1269
[email protected]32dfede2013-08-25 15:48:251270void BrowserCommandController::UpdateCommandsForFullscreenMode() {
Ivan Sandrk9669d0e2017-12-15 23:50:201271 if (is_locked_fullscreen_)
1272 return;
1273
zijiehe3c7af992017-02-12 20:59:401274 const bool is_fullscreen = window() && window()->IsFullscreen();
1275 const bool show_main_ui = IsShowingMainUI();
manukf1a116392018-10-25 16:28:241276 const bool show_location_bar = IsShowingLocationBar();
1277
zijiehe3c7af992017-02-12 20:59:401278 const bool main_not_fullscreen = show_main_ui && !is_fullscreen;
[email protected]5d98294912012-06-27 22:57:401279
1280 // Navigation commands
1281 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1282
1283 // Window management commands
1284 command_updater_.UpdateCommandEnabled(
Joel Hockey2687ab52019-08-14 23:59:461285 IDC_SHOW_AS_TAB, !browser_->is_type_normal() && !is_fullscreen);
[email protected]5d98294912012-06-27 22:57:401286
1287 // Focus various bits of UI
1288 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
manukf1a116392018-10-25 16:28:241289 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_location_bar);
[email protected]5d98294912012-06-27 22:57:401290 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
Aran Gilmand217b5b2019-04-11 17:45:431291 command_updater_.UpdateCommandEnabled(IDC_FOCUS_MENU_BAR,
1292 main_not_fullscreen);
1293 command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE,
1294 main_not_fullscreen);
1295 command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE,
1296 main_not_fullscreen);
1297 command_updater_.UpdateCommandEnabled(IDC_FOCUS_BOOKMARKS,
1298 main_not_fullscreen);
[email protected]822ca8c62013-04-19 00:49:151299 command_updater_.UpdateCommandEnabled(
David Tsengc0b1b642018-01-24 07:12:271300 IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY, main_not_fullscreen);
[email protected]5d98294912012-06-27 22:57:401301
1302 // Show various bits of UI
1303 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui);
Nico Weber0cc71122019-07-29 17:30:401304#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
Fabio Rocha19bf4262019-04-04 01:05:181305 command_updater_.UpdateCommandEnabled(
Joel Hockey2687ab52019-08-14 23:59:461306 IDC_FEEDBACK, show_main_ui || browser_->is_type_devtools());
[email protected]236ad3022013-09-04 03:27:431307#endif
Mihai Sardarescu2ec5205682018-09-26 09:20:051308 UpdateShowSyncState(show_main_ui);
[email protected]5d98294912012-06-27 22:57:401309
[email protected]5d98294912012-06-27 22:57:401310 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
1311 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
1312 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
1313 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
Tina Wangf09681ac2019-03-27 20:52:101314 command_updater_.UpdateCommandEnabled(IDC_SEND_TAB_TO_SELF, show_main_ui);
Tina Wangfa016992019-05-31 00:01:151315 command_updater_.UpdateCommandEnabled(IDC_SEND_TAB_TO_SELF_SINGLE_TARGET,
1316 show_main_ui);
Yann Dago70ca3dd2019-02-27 01:12:351317 command_updater_.UpdateCommandEnabled(IDC_SHOW_MANAGEMENT_PAGE, true);
primianod3a81ab2016-01-25 22:21:151318
1319 if (base::debug::IsProfilingSupported())
1320 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
[email protected]5d98294912012-06-27 22:57:401321
[email protected]aeafc3852014-04-29 16:51:291322#if !defined(OS_MACOSX)
zijiehe3c7af992017-02-12 20:59:401323 // Disable toggling into fullscreen mode if disallowed by pref.
Aran Gilmand217b5b2019-04-11 17:45:431324 const bool fullscreen_enabled =
1325 is_fullscreen ||
zijiehe3c7af992017-02-12 20:59:401326 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed);
1327#else
1328 const bool fullscreen_enabled = true;
[email protected]00a1cc5b2012-11-07 13:44:511329#endif
1330
1331 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled);
spqchanb8ffc7d2015-11-17 01:17:211332 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR,
1333 fullscreen_enabled);
[email protected]5d98294912012-06-27 22:57:401334
1335 UpdateCommandsForBookmarkBar();
zijiehedb473d552017-02-24 01:13:411336 UpdateCommandsForIncognitoAvailability();
Alan Cutter167dfe82018-04-11 09:06:001337 UpdateCommandsForHostedAppAvailability();
1338}
1339
1340void BrowserCommandController::UpdateCommandsForHostedAppAvailability() {
1341 bool has_toolbar =
Joel Hockey2687ab52019-08-14 23:59:461342 browser_->is_type_normal() ||
Alan Cutterd0bd51902019-05-22 04:15:231343 web_app::AppBrowserController::IsForWebAppBrowser(browser_);
Alan Cutter167dfe82018-04-11 09:06:001344 if (window() && window()->ShouldHideUIForFullscreen())
1345 has_toolbar = false;
1346 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, has_toolbar);
1347 command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE, has_toolbar);
1348 command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE, has_toolbar);
1349 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, has_toolbar);
[email protected]5d98294912012-06-27 22:57:401350}
1351
Ivan Sandrk9669d0e2017-12-15 23:50:201352#if defined(OS_CHROMEOS)
1353namespace {
1354
1355#if DCHECK_IS_ON()
1356// Makes sure that all commands that are not whitelisted are disabled. DCHECKs
1357// otherwise. Compiled only in debug mode.
1358void NonWhitelistedCommandsAreDisabled(CommandUpdaterImpl* command_updater) {
Ivan Sandrk6ac9c9a2018-12-14 14:15:071359 constexpr int kWhitelistedIds[] = {IDC_CUT, IDC_COPY, IDC_PASTE};
Ivan Sandrk9669d0e2017-12-15 23:50:201360
1361 // Go through all the command ids, skip the whitelisted ones.
1362 for (int id : command_updater->GetAllIds()) {
Jan Wilken Dörriea8cb56302019-06-06 18:59:361363 if (base::Contains(kWhitelistedIds, id)) {
Ivan Sandrk9669d0e2017-12-15 23:50:201364 continue;
1365 }
1366 DCHECK(!command_updater->IsCommandEnabled(id));
1367 }
1368}
1369#endif
1370
1371} // namespace
1372
1373void BrowserCommandController::UpdateCommandsForLockedFullscreenMode() {
Ivan Sandrke0e92452019-03-21 09:32:481374 bool is_locked_fullscreen =
1375 platform_util::IsBrowserLockedFullscreen(browser_);
Ivan Sandrk9669d0e2017-12-15 23:50:201376 // Sanity check to make sure this function is called only on state change.
1377 DCHECK_NE(is_locked_fullscreen, is_locked_fullscreen_);
1378 if (is_locked_fullscreen == is_locked_fullscreen_)
1379 return;
1380 is_locked_fullscreen_ = is_locked_fullscreen;
1381
1382 if (is_locked_fullscreen_) {
1383 command_updater_.DisableAllCommands();
1384 // Update the state of whitelisted commands:
1385 // IDC_CUT/IDC_COPY/IDC_PASTE,
1386 UpdateCommandsForContentRestrictionState();
Ivan Sandrk6ac9c9a2018-12-14 14:15:071387 // TODO(crbug.com/904637): Re-enable Find and Zoom in locked fullscreen.
Ivan Sandrk9669d0e2017-12-15 23:50:201388 // All other commands will be disabled (there is an early return in their
1389 // corresponding UpdateCommandsFor* functions).
1390#if DCHECK_IS_ON()
1391 NonWhitelistedCommandsAreDisabled(&command_updater_);
1392#endif
1393 } else {
1394 // Do an init call to re-initialize command state after the
1395 // DisableAllCommands.
1396 InitCommandState();
1397 }
1398}
1399#endif
1400
[email protected]5d98294912012-06-27 22:57:401401void BrowserCommandController::UpdatePrintingState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201402 if (is_locked_fullscreen_)
1403 return;
1404
[email protected]d53e4032012-06-29 18:58:341405 bool print_enabled = CanPrint(browser_);
1406 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
Lei Zhang48a4a5262018-04-17 20:18:441407#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:551408 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT,
1409 CanBasicPrint(browser_));
Lei Zhang48a4a5262018-04-17 20:18:441410#endif
[email protected]5d98294912012-06-27 22:57:401411}
1412
1413void BrowserCommandController::UpdateSaveAsState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201414 if (is_locked_fullscreen_)
1415 return;
1416
[email protected]5d98294912012-06-27 22:57:401417 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_));
1418}
1419
Mihai Sardarescu2ec5205682018-09-26 09:20:051420void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) {
1421 if (is_locked_fullscreen_)
1422 return;
1423
Mihai Sardarescuf87ccc12018-09-26 10:37:451424 command_updater_.UpdateCommandEnabled(
Mihai Sardarescu290bc882018-10-12 10:48:141425 IDC_SHOW_SIGNIN, show_main_ui && pref_signin_allowed_.GetValue());
Mihai Sardarescu2ec5205682018-09-26 09:20:051426}
1427
[email protected]05454532013-01-22 21:09:081428// static
1429void BrowserCommandController::UpdateOpenFileState(
1430 CommandUpdater* command_updater) {
[email protected]5d98294912012-06-27 22:57:401431 bool enabled = true;
1432 PrefService* local_state = g_browser_process->local_state();
1433 if (local_state)
1434 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs);
1435
[email protected]05454532013-01-22 21:09:081436 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled);
[email protected]5d98294912012-06-27 22:57:401437}
1438
1439void BrowserCommandController::UpdateReloadStopState(bool is_loading,
1440 bool force) {
Ivan Sandrk9669d0e2017-12-15 23:50:201441 if (is_locked_fullscreen_)
1442 return;
1443
[email protected]5d98294912012-06-27 22:57:401444 window()->UpdateReloadStopState(is_loading, force);
1445 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
Jeff Fisher6cc1ce7b2019-06-28 23:02:381446 UpdateCloseFindOrStop();
[email protected]5d98294912012-06-27 22:57:401447}
1448
[email protected]2e9369e2014-08-15 09:12:531449void BrowserCommandController::UpdateTabRestoreCommandState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201450 if (is_locked_fullscreen_)
1451 return;
1452
blundell74001adc2015-09-18 11:04:251453 sessions::TabRestoreService* tab_restore_service =
[email protected]2e9369e2014-08-15 09:12:531454 TabRestoreServiceFactory::GetForProfile(profile());
1455 // The command is enabled if the service hasn't loaded yet to trigger loading.
1456 // The command is updated once the load completes.
1457 command_updater_.UpdateCommandEnabled(
1458 IDC_RESTORE_TAB,
Peter Kasting32bb2602019-08-22 19:01:431459 tab_restore_service && (!tab_restore_service->IsLoaded() ||
1460 !tab_restore_service->entries().empty()));
[email protected]2e9369e2014-08-15 09:12:531461}
1462
[email protected]3cac87232012-11-20 01:48:271463void BrowserCommandController::UpdateCommandsForFind() {
1464 TabStripModel* model = browser_->tab_strip_model();
Joel Hockey2687ab52019-08-14 23:59:461465 bool enabled = !model->IsTabBlocked(model->active_index()) &&
1466 !browser_->is_type_devtools();
[email protected]3cac87232012-11-20 01:48:271467
1468 command_updater_.UpdateCommandEnabled(IDC_FIND, enabled);
1469 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled);
1470 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled);
1471}
1472
Jeff Fisher6cc1ce7b2019-06-28 23:02:381473void BrowserCommandController::UpdateCloseFindOrStop() {
1474 bool enabled = CanCloseFind(browser_) || IsCommandEnabled(IDC_STOP);
1475 command_updater_.UpdateCommandEnabled(IDC_CLOSE_FIND_OR_STOP, enabled);
1476}
1477
apacible45cbfc92015-09-28 22:45:411478void BrowserCommandController::UpdateCommandsForMediaRouter() {
Ivan Sandrk9669d0e2017-12-15 23:50:201479 if (is_locked_fullscreen_)
1480 return;
1481
apacible45cbfc92015-09-28 22:45:411482 command_updater_.UpdateCommandEnabled(IDC_ROUTE_MEDIA,
1483 CanRouteMedia(browser_));
1484}
1485
Elly Fong-Jones5e6baaf2019-10-10 23:17:141486void BrowserCommandController::UpdateCommandsForTabKeyboardFocus(
1487 base::Optional<int> target_index) {
1488 command_updater_.UpdateCommandEnabled(
1489 IDC_DUPLICATE_TARGET_TAB, !browser_->deprecated_is_app() &&
1490 target_index.has_value() &&
1491 CanDuplicateTabAt(browser_, *target_index));
1492 const bool normal_window = browser_->is_type_normal();
1493 command_updater_.UpdateCommandEnabled(
1494 IDC_MUTE_TARGET_SITE, normal_window && target_index.has_value());
1495 command_updater_.UpdateCommandEnabled(
1496 IDC_PIN_TARGET_TAB, normal_window && target_index.has_value());
Connie Wan303e29e2020-01-31 18:16:561497 command_updater_.UpdateCommandEnabled(
1498 IDC_GROUP_TARGET_TAB, normal_window && target_index.has_value());
Elly Fong-Jones5e6baaf2019-10-10 23:17:141499}
1500
[email protected]409ea2972012-11-10 19:54:431501void BrowserCommandController::AddInterstitialObservers(WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071502 interstitial_observers_.push_back(new InterstitialObserver(this, contents));
[email protected]5d98294912012-06-27 22:57:401503}
1504
1505void BrowserCommandController::RemoveInterstitialObservers(
[email protected]e89cfcb2012-11-11 14:47:241506 WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071507 for (size_t i = 0; i < interstitial_observers_.size(); i++) {
1508 if (interstitial_observers_[i]->web_contents() != contents)
1509 continue;
1510
1511 delete interstitial_observers_[i];
1512 interstitial_observers_.erase(interstitial_observers_.begin() + i);
1513 return;
1514 }
[email protected]5d98294912012-06-27 22:57:401515}
1516
1517BrowserWindow* BrowserCommandController::window() {
1518 return browser_->window();
1519}
1520
1521Profile* BrowserCommandController::profile() {
1522 return browser_->profile();
1523}
1524
[email protected]5d98294912012-06-27 22:57:401525} // namespace chrome