blob: 48713d1cf998077ecde1e421211f785b2b85b819 [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"));
Alan Cutter42356022020-02-20 06:44:13466 web_app::ReparentWebAppForActiveTab(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
Joel Hockey43afbd82020-02-19 23:55:371038 // Tab management commands
1039 const bool supports_tabs =
1040 browser_->SupportsWindowFeature(Browser::FEATURE_TABSTRIP);
1041 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, supports_tabs);
1042 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, supports_tabs);
1043 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, supports_tabs);
1044 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, supports_tabs);
1045 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, supports_tabs);
1046 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, supports_tabs);
1047 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, supports_tabs);
1048 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, supports_tabs);
1049 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, supports_tabs);
1050 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, supports_tabs);
1051 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, supports_tabs);
1052 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, supports_tabs);
1053 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, supports_tabs);
[email protected]5d98294912012-06-27 22:57:401054
[email protected]338416c02014-05-13 16:47:061055 // These are always enabled; the menu determines their menu item visibility.
[email protected]5d98294912012-06-27 22:57:401056 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
[email protected]5d98294912012-06-27 22:57:401057
[email protected]6bd370b2014-05-28 14:19:471058 // Distill current page.
Aran Gilman7b6ccf5d2019-09-05 19:16:021059 command_updater_.UpdateCommandEnabled(IDC_DISTILL_PAGE,
1060 dom_distiller::IsDomDistillerEnabled());
[email protected]6bd370b2014-05-28 14:19:471061
Tommy Steimelc4477982017-11-29 18:07:181062 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE, normal_window);
ellyjones0101ba02017-05-19 15:50:261063 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, normal_window);
Connie Wan303e29e2020-01-31 18:16:561064 command_updater_.UpdateCommandEnabled(IDC_WINDOW_GROUP_TAB, normal_window);
Elly Fong-Jones2d0443cb2019-11-14 15:04:201065 command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_TABS_TO_RIGHT,
1066 normal_window);
1067 command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_OTHER_TABS,
1068 normal_window);
ellyjones0101ba02017-05-19 15:50:261069
[email protected]338416c02014-05-13 16:47:061070 // Initialize other commands whose state changes based on various conditions.
[email protected]32dfede2013-08-25 15:48:251071 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:401072 UpdateCommandsForContentRestrictionState();
[email protected]5d98294912012-06-27 22:57:401073 UpdateCommandsForBookmarkEditing();
[email protected]5d98294912012-06-27 22:57:401074 UpdateCommandsForIncognitoAvailability();
Elly Fong-Jones5e6baaf2019-10-10 23:17:141075 UpdateCommandsForTabKeyboardFocus(GetKeyboardFocusedTabIndex(browser_));
[email protected]5d98294912012-06-27 22:57:401076}
1077
[email protected]05454532013-01-22 21:09:081078// static
1079void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
1080 CommandUpdater* command_updater,
1081 Profile* profile) {
mlermane01e6de2014-09-29 19:26:471082 const bool guest_session = profile->IsGuestSession();
1083 // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession().
[email protected]5d98294912012-06-27 22:57:401084 IncognitoModePrefs::Availability incognito_availability =
[email protected]05454532013-01-22 21:09:081085 IncognitoModePrefs::GetAvailability(profile->GetPrefs());
1086 command_updater->UpdateCommandEnabled(
Aran Gilmand217b5b2019-04-11 17:45:431087 IDC_NEW_WINDOW, incognito_availability != IncognitoModePrefs::FORCED);
[email protected]05454532013-01-22 21:09:081088 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:401089 IDC_NEW_INCOGNITO_WINDOW,
mlermane01e6de2014-09-29 19:26:471090 incognito_availability != IncognitoModePrefs::DISABLED && !guest_session);
[email protected]5d98294912012-06-27 22:57:401091
[email protected]57b25292014-05-01 16:31:061092 const bool forced_incognito =
1093 incognito_availability == IncognitoModePrefs::FORCED ||
1094 guest_session; // Guest always runs in Incognito mode.
[email protected]05454532013-01-22 21:09:081095 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:401096 IDC_SHOW_BOOKMARK_MANAGER,
[email protected]57b25292014-05-01 16:31:061097 browser_defaults::bookmarks_enabled && !forced_incognito);
Devlin Cronin21dba422018-05-30 15:45:161098 extensions::ExtensionService* extension_service =
[email protected]03d25812014-06-22 19:41:551099 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]57b25292014-05-01 16:31:061100 const bool enable_extensions =
[email protected]5d98294912012-06-27 22:57:401101 extension_service && extension_service->extensions_enabled();
[email protected]5d98294912012-06-27 22:57:401102
[email protected]57b25292014-05-01 16:31:061103 // Bookmark manager and settings page/subpages are forced to open in normal
1104 // mode. For this reason we disable these commands when incognito is forced.
1105 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
1106 enable_extensions && !forced_incognito);
1107
1108 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito);
1109 command_updater->UpdateCommandEnabled(IDC_OPTIONS,
1110 !forced_incognito || guest_session);
estade8c0780f2015-08-21 23:36:411111 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito);
[email protected]05454532013-01-22 21:09:081112}
1113
1114void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
Ivan Sandrk9669d0e2017-12-15 23:50:201115 if (is_locked_fullscreen_)
1116 return;
1117
[email protected]05454532013-01-22 21:09:081118 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile());
1119
[email protected]6a414ff2013-02-27 08:22:541120 if (!IsShowingMainUI()) {
[email protected]05454532013-01-22 21:09:081121 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false);
1122 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false);
1123 }
[email protected]5d98294912012-06-27 22:57:401124}
1125
1126void BrowserCommandController::UpdateCommandsForTabState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201127 if (is_locked_fullscreen_)
1128 return;
1129
[email protected]617ee962013-01-29 20:49:121130 WebContents* current_web_contents =
1131 browser_->tab_strip_model()->GetActiveWebContents();
[email protected]1c5119c2012-09-19 00:08:571132 if (!current_web_contents) // May be NULL during tab restore.
[email protected]5d98294912012-06-27 22:57:401133 return;
[email protected]5d98294912012-06-27 22:57:401134
1135 // Navigation commands
1136 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_));
1137 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_));
1138 command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_));
toyoshim7dad4b1182016-04-01 14:28:051139 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE,
[email protected]5d98294912012-06-27 22:57:401140 CanReload(browser_));
[email protected]58e29032012-08-06 20:19:571141 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE,
1142 CanReload(browser_));
[email protected]5d98294912012-06-27 22:57:401143
1144 // Window management commands
Aran Gilmand217b5b2019-04-11 17:45:431145 command_updater_.UpdateCommandEnabled(
Joel Hockey2687ab52019-08-14 23:59:461146 IDC_DUPLICATE_TAB,
1147 !browser_->deprecated_is_app() && CanDuplicateTab(browser_));
Tommy Steimelc4477982017-11-29 18:07:181148 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE,
Joel Hockey2687ab52019-08-14 23:59:461149 !browser_->deprecated_is_app());
ellyjones0101ba02017-05-19 15:50:261150 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB,
Joel Hockey2687ab52019-08-14 23:59:461151 !browser_->deprecated_is_app());
Connie Wan303e29e2020-01-31 18:16:561152 command_updater_.UpdateCommandEnabled(IDC_WINDOW_GROUP_TAB,
1153 !browser_->deprecated_is_app());
Elly Fong-Jones2d0443cb2019-11-14 15:04:201154 command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_TABS_TO_RIGHT,
1155 CanCloseTabsToRight(browser_));
1156 command_updater_.UpdateCommandEnabled(IDC_WINDOW_CLOSE_OTHER_TABS,
1157 CanCloseOtherTabs(browser_));
Leonard Greyf13493b2019-12-19 18:12:571158 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_TO_NEW_WINDOW,
Leonard Greya8ecaa32020-01-07 20:57:411159 CanMoveActiveTabToNewWindow(browser_));
[email protected]5d98294912012-06-27 22:57:401160
1161 // Page-related commands
1162 window()->SetStarredState(
[email protected]1c5119c2012-09-19 00:08:571163 BookmarkTabHelper::FromWebContents(current_web_contents)->is_starred());
[email protected]5423c372012-08-22 05:50:161164 window()->ZoomChangedForActiveTab(false);
[email protected]5d98294912012-06-27 22:57:401165 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
1166 CanViewSource(browser_));
1167 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION,
1168 CanEmailPageLocation(browser_));
Joel Hockey2687ab52019-08-14 23:59:461169 if (browser_->is_type_devtools())
[email protected]5d98294912012-06-27 22:57:401170 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false);
1171
Glen Robertsonb9d27412020-01-09 06:48:131172 bool can_create_web_app = web_app::CanCreateWebApp(browser_);
1173 command_updater_.UpdateCommandEnabled(IDC_INSTALL_PWA, can_create_web_app);
Alan Cutter81ac726682018-09-25 00:18:361174 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUT,
Glen Robertsonb9d27412020-01-09 06:48:131175 can_create_web_app);
1176 // Note that additional logic in AppMenuModel::Build() controls the presence
1177 // of this command.
Alan Cutter403cebb2018-05-17 05:22:451178 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW,
Glen Robertsonb9d27412020-01-09 06:48:131179 web_app::CanPopOutWebApp(profile()));
[email protected]5d98294912012-06-27 22:57:401180
[email protected]9b7ab882012-09-10 23:46:361181 command_updater_.UpdateCommandEnabled(
1182 IDC_TOGGLE_REQUEST_TABLET_SITE,
1183 CanRequestTabletSite(current_web_contents));
1184
[email protected]5d98294912012-06-27 22:57:401185 UpdateCommandsForContentRestrictionState();
1186 UpdateCommandsForBookmarkEditing();
[email protected]3cac87232012-11-20 01:48:271187 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:411188 UpdateCommandsForMediaRouter();
[email protected]d93dbd12014-08-04 23:42:531189 // Update the zoom commands when an active tab is selected.
1190 UpdateCommandsForZoomState();
Elly Fong-Jones5e6baaf2019-10-10 23:17:141191 UpdateCommandsForTabKeyboardFocus(GetKeyboardFocusedTabIndex(browser_));
[email protected]d93dbd12014-08-04 23:42:531192}
1193
1194void BrowserCommandController::UpdateCommandsForZoomState() {
Aran Gilmand217b5b2019-04-11 17:45:431195 WebContents* contents = browser_->tab_strip_model()->GetActiveWebContents();
[email protected]d93dbd12014-08-04 23:42:531196 if (!contents)
1197 return;
Aran Gilmand217b5b2019-04-11 17:45:431198 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, CanZoomIn(contents));
a.sarkar.arundaadc712015-02-26 05:39:081199 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL,
ccameronb7c1d6c2015-03-09 17:08:241200 CanResetZoom(contents));
Aran Gilmand217b5b2019-04-11 17:45:431201 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, CanZoomOut(contents));
[email protected]5d98294912012-06-27 22:57:401202}
1203
1204void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
1205 int restrictions = GetContentRestrictions(browser_);
1206
1207 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011208 IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY));
[email protected]5d98294912012-06-27 22:57:401209 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011210 IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT));
[email protected]5d98294912012-06-27 22:57:401211 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011212 IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE));
[email protected]5d98294912012-06-27 22:57:401213 UpdateSaveAsState();
1214 UpdatePrintingState();
1215}
1216
1217void BrowserCommandController::UpdateCommandsForDevTools() {
Ivan Sandrk9669d0e2017-12-15 23:50:201218 if (is_locked_fullscreen_)
1219 return;
1220
Pavol Marko56df0272018-07-04 17:55:041221 bool dev_tools_enabled = DevToolsWindow::AllowDevToolsFor(
1222 profile(), browser_->tab_strip_model()->GetActiveWebContents());
Aran Gilmand217b5b2019-04-11 17:45:431223 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS, dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401224 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE,
1225 dev_tools_enabled);
[email protected]2056c3192013-10-21 22:40:511226 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES,
1227 dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401228 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT,
1229 dev_tools_enabled);
[email protected]d16657c2012-09-03 14:25:101230 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE,
1231 dev_tools_enabled);
spqchan2c5d541e2017-10-25 07:07:111232#if defined(OS_MACOSX)
1233 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS,
1234 dev_tools_enabled);
1235#endif
[email protected]5d98294912012-06-27 22:57:401236}
1237
1238void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
Ivan Sandrk9669d0e2017-12-15 23:50:201239 if (is_locked_fullscreen_)
1240 return;
1241
Peter Kasting32bb2602019-08-22 19:01:431242 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_THIS_TAB,
1243 CanBookmarkCurrentTab(browser_));
[email protected]5d98294912012-06-27 22:57:401244 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
1245 CanBookmarkAllTabs(browser_));
thestig5149d272014-10-30 07:25:291246#if defined(OS_WIN)
1247 command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN, true);
1248#endif
[email protected]5d98294912012-06-27 22:57:401249}
1250
1251void BrowserCommandController::UpdateCommandsForBookmarkBar() {
Ivan Sandrk9669d0e2017-12-15 23:50:201252 if (is_locked_fullscreen_)
1253 return;
1254
tfarina3bddbe112014-08-28 05:29:321255 command_updater_.UpdateCommandEnabled(
Aran Gilmand217b5b2019-04-11 17:45:431256 IDC_SHOW_BOOKMARK_BAR, browser_defaults::bookmarks_enabled &&
1257 !profile()->IsGuestSession() &&
1258 !profile()->IsSystemProfile() &&
1259 !profile()->GetPrefs()->IsManagedPreference(
1260 bookmarks::prefs::kShowBookmarkBar) &&
1261 IsShowingMainUI());
[email protected]5d98294912012-06-27 22:57:401262}
1263
[email protected]9ec3ea5b2012-12-03 18:14:301264void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
Ivan Sandrk9669d0e2017-12-15 23:50:201265 if (is_locked_fullscreen_)
1266 return;
1267
[email protected]9ec3ea5b2012-12-03 18:14:301268 UpdateSaveAsState();
[email protected]05454532013-01-22 21:09:081269 UpdateOpenFileState(&command_updater_);
[email protected]9ec3ea5b2012-12-03 18:14:301270}
1271
[email protected]32dfede2013-08-25 15:48:251272void BrowserCommandController::UpdateCommandsForFullscreenMode() {
Ivan Sandrk9669d0e2017-12-15 23:50:201273 if (is_locked_fullscreen_)
1274 return;
1275
zijiehe3c7af992017-02-12 20:59:401276 const bool is_fullscreen = window() && window()->IsFullscreen();
1277 const bool show_main_ui = IsShowingMainUI();
manukf1a116392018-10-25 16:28:241278 const bool show_location_bar = IsShowingLocationBar();
1279
zijiehe3c7af992017-02-12 20:59:401280 const bool main_not_fullscreen = show_main_ui && !is_fullscreen;
[email protected]5d98294912012-06-27 22:57:401281
1282 // Navigation commands
1283 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1284
1285 // Window management commands
1286 command_updater_.UpdateCommandEnabled(
Joel Hockey2687ab52019-08-14 23:59:461287 IDC_SHOW_AS_TAB, !browser_->is_type_normal() && !is_fullscreen);
[email protected]5d98294912012-06-27 22:57:401288
1289 // Focus various bits of UI
1290 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
manukf1a116392018-10-25 16:28:241291 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_location_bar);
[email protected]5d98294912012-06-27 22:57:401292 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
Aran Gilmand217b5b2019-04-11 17:45:431293 command_updater_.UpdateCommandEnabled(IDC_FOCUS_MENU_BAR,
1294 main_not_fullscreen);
1295 command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE,
1296 main_not_fullscreen);
1297 command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE,
1298 main_not_fullscreen);
1299 command_updater_.UpdateCommandEnabled(IDC_FOCUS_BOOKMARKS,
1300 main_not_fullscreen);
[email protected]822ca8c62013-04-19 00:49:151301 command_updater_.UpdateCommandEnabled(
David Tsengc0b1b642018-01-24 07:12:271302 IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY, main_not_fullscreen);
[email protected]5d98294912012-06-27 22:57:401303
1304 // Show various bits of UI
1305 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui);
Nico Weber0cc71122019-07-29 17:30:401306#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
Fabio Rocha19bf4262019-04-04 01:05:181307 command_updater_.UpdateCommandEnabled(
Joel Hockey2687ab52019-08-14 23:59:461308 IDC_FEEDBACK, show_main_ui || browser_->is_type_devtools());
[email protected]236ad3022013-09-04 03:27:431309#endif
Mihai Sardarescu2ec5205682018-09-26 09:20:051310 UpdateShowSyncState(show_main_ui);
[email protected]5d98294912012-06-27 22:57:401311
[email protected]5d98294912012-06-27 22:57:401312 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
1313 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
1314 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
1315 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
Tina Wangf09681ac2019-03-27 20:52:101316 command_updater_.UpdateCommandEnabled(IDC_SEND_TAB_TO_SELF, show_main_ui);
Tina Wangfa016992019-05-31 00:01:151317 command_updater_.UpdateCommandEnabled(IDC_SEND_TAB_TO_SELF_SINGLE_TARGET,
1318 show_main_ui);
Yann Dago70ca3dd2019-02-27 01:12:351319 command_updater_.UpdateCommandEnabled(IDC_SHOW_MANAGEMENT_PAGE, true);
primianod3a81ab2016-01-25 22:21:151320
1321 if (base::debug::IsProfilingSupported())
1322 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
[email protected]5d98294912012-06-27 22:57:401323
[email protected]aeafc3852014-04-29 16:51:291324#if !defined(OS_MACOSX)
zijiehe3c7af992017-02-12 20:59:401325 // Disable toggling into fullscreen mode if disallowed by pref.
Aran Gilmand217b5b2019-04-11 17:45:431326 const bool fullscreen_enabled =
1327 is_fullscreen ||
zijiehe3c7af992017-02-12 20:59:401328 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed);
1329#else
1330 const bool fullscreen_enabled = true;
[email protected]00a1cc5b2012-11-07 13:44:511331#endif
1332
1333 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled);
spqchanb8ffc7d2015-11-17 01:17:211334 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR,
1335 fullscreen_enabled);
[email protected]5d98294912012-06-27 22:57:401336
1337 UpdateCommandsForBookmarkBar();
zijiehedb473d552017-02-24 01:13:411338 UpdateCommandsForIncognitoAvailability();
Alan Cutter167dfe82018-04-11 09:06:001339 UpdateCommandsForHostedAppAvailability();
1340}
1341
1342void BrowserCommandController::UpdateCommandsForHostedAppAvailability() {
1343 bool has_toolbar =
Joel Hockey2687ab52019-08-14 23:59:461344 browser_->is_type_normal() ||
Alan Cutterd0bd51902019-05-22 04:15:231345 web_app::AppBrowserController::IsForWebAppBrowser(browser_);
Alan Cutter167dfe82018-04-11 09:06:001346 if (window() && window()->ShouldHideUIForFullscreen())
1347 has_toolbar = false;
1348 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, has_toolbar);
1349 command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE, has_toolbar);
1350 command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE, has_toolbar);
1351 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, has_toolbar);
[email protected]5d98294912012-06-27 22:57:401352}
1353
Ivan Sandrk9669d0e2017-12-15 23:50:201354#if defined(OS_CHROMEOS)
1355namespace {
1356
1357#if DCHECK_IS_ON()
1358// Makes sure that all commands that are not whitelisted are disabled. DCHECKs
1359// otherwise. Compiled only in debug mode.
1360void NonWhitelistedCommandsAreDisabled(CommandUpdaterImpl* command_updater) {
Ivan Sandrk6ac9c9a2018-12-14 14:15:071361 constexpr int kWhitelistedIds[] = {IDC_CUT, IDC_COPY, IDC_PASTE};
Ivan Sandrk9669d0e2017-12-15 23:50:201362
1363 // Go through all the command ids, skip the whitelisted ones.
1364 for (int id : command_updater->GetAllIds()) {
Jan Wilken Dörriea8cb56302019-06-06 18:59:361365 if (base::Contains(kWhitelistedIds, id)) {
Ivan Sandrk9669d0e2017-12-15 23:50:201366 continue;
1367 }
1368 DCHECK(!command_updater->IsCommandEnabled(id));
1369 }
1370}
1371#endif
1372
1373} // namespace
1374
1375void BrowserCommandController::UpdateCommandsForLockedFullscreenMode() {
Ivan Sandrke0e92452019-03-21 09:32:481376 bool is_locked_fullscreen =
1377 platform_util::IsBrowserLockedFullscreen(browser_);
Ivan Sandrk9669d0e2017-12-15 23:50:201378 // Sanity check to make sure this function is called only on state change.
1379 DCHECK_NE(is_locked_fullscreen, is_locked_fullscreen_);
1380 if (is_locked_fullscreen == is_locked_fullscreen_)
1381 return;
1382 is_locked_fullscreen_ = is_locked_fullscreen;
1383
1384 if (is_locked_fullscreen_) {
1385 command_updater_.DisableAllCommands();
1386 // Update the state of whitelisted commands:
1387 // IDC_CUT/IDC_COPY/IDC_PASTE,
1388 UpdateCommandsForContentRestrictionState();
Ivan Sandrk6ac9c9a2018-12-14 14:15:071389 // TODO(crbug.com/904637): Re-enable Find and Zoom in locked fullscreen.
Ivan Sandrk9669d0e2017-12-15 23:50:201390 // All other commands will be disabled (there is an early return in their
1391 // corresponding UpdateCommandsFor* functions).
1392#if DCHECK_IS_ON()
1393 NonWhitelistedCommandsAreDisabled(&command_updater_);
1394#endif
1395 } else {
1396 // Do an init call to re-initialize command state after the
1397 // DisableAllCommands.
1398 InitCommandState();
1399 }
1400}
1401#endif
1402
[email protected]5d98294912012-06-27 22:57:401403void BrowserCommandController::UpdatePrintingState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201404 if (is_locked_fullscreen_)
1405 return;
1406
[email protected]d53e4032012-06-29 18:58:341407 bool print_enabled = CanPrint(browser_);
1408 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
Lei Zhang48a4a5262018-04-17 20:18:441409#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:551410 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT,
1411 CanBasicPrint(browser_));
Lei Zhang48a4a5262018-04-17 20:18:441412#endif
[email protected]5d98294912012-06-27 22:57:401413}
1414
1415void BrowserCommandController::UpdateSaveAsState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201416 if (is_locked_fullscreen_)
1417 return;
1418
[email protected]5d98294912012-06-27 22:57:401419 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_));
1420}
1421
Mihai Sardarescu2ec5205682018-09-26 09:20:051422void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) {
1423 if (is_locked_fullscreen_)
1424 return;
1425
Mihai Sardarescuf87ccc12018-09-26 10:37:451426 command_updater_.UpdateCommandEnabled(
Mihai Sardarescu290bc882018-10-12 10:48:141427 IDC_SHOW_SIGNIN, show_main_ui && pref_signin_allowed_.GetValue());
Mihai Sardarescu2ec5205682018-09-26 09:20:051428}
1429
[email protected]05454532013-01-22 21:09:081430// static
1431void BrowserCommandController::UpdateOpenFileState(
1432 CommandUpdater* command_updater) {
[email protected]5d98294912012-06-27 22:57:401433 bool enabled = true;
1434 PrefService* local_state = g_browser_process->local_state();
1435 if (local_state)
1436 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs);
1437
[email protected]05454532013-01-22 21:09:081438 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled);
[email protected]5d98294912012-06-27 22:57:401439}
1440
1441void BrowserCommandController::UpdateReloadStopState(bool is_loading,
1442 bool force) {
Ivan Sandrk9669d0e2017-12-15 23:50:201443 if (is_locked_fullscreen_)
1444 return;
1445
[email protected]5d98294912012-06-27 22:57:401446 window()->UpdateReloadStopState(is_loading, force);
1447 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
Jeff Fisher6cc1ce7b2019-06-28 23:02:381448 UpdateCloseFindOrStop();
[email protected]5d98294912012-06-27 22:57:401449}
1450
[email protected]2e9369e2014-08-15 09:12:531451void BrowserCommandController::UpdateTabRestoreCommandState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201452 if (is_locked_fullscreen_)
1453 return;
1454
blundell74001adc2015-09-18 11:04:251455 sessions::TabRestoreService* tab_restore_service =
[email protected]2e9369e2014-08-15 09:12:531456 TabRestoreServiceFactory::GetForProfile(profile());
1457 // The command is enabled if the service hasn't loaded yet to trigger loading.
1458 // The command is updated once the load completes.
1459 command_updater_.UpdateCommandEnabled(
1460 IDC_RESTORE_TAB,
Peter Kasting32bb2602019-08-22 19:01:431461 tab_restore_service && (!tab_restore_service->IsLoaded() ||
1462 !tab_restore_service->entries().empty()));
[email protected]2e9369e2014-08-15 09:12:531463}
1464
[email protected]3cac87232012-11-20 01:48:271465void BrowserCommandController::UpdateCommandsForFind() {
1466 TabStripModel* model = browser_->tab_strip_model();
Joel Hockey2687ab52019-08-14 23:59:461467 bool enabled = !model->IsTabBlocked(model->active_index()) &&
1468 !browser_->is_type_devtools();
[email protected]3cac87232012-11-20 01:48:271469
1470 command_updater_.UpdateCommandEnabled(IDC_FIND, enabled);
1471 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled);
1472 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled);
1473}
1474
Jeff Fisher6cc1ce7b2019-06-28 23:02:381475void BrowserCommandController::UpdateCloseFindOrStop() {
1476 bool enabled = CanCloseFind(browser_) || IsCommandEnabled(IDC_STOP);
1477 command_updater_.UpdateCommandEnabled(IDC_CLOSE_FIND_OR_STOP, enabled);
1478}
1479
apacible45cbfc92015-09-28 22:45:411480void BrowserCommandController::UpdateCommandsForMediaRouter() {
Ivan Sandrk9669d0e2017-12-15 23:50:201481 if (is_locked_fullscreen_)
1482 return;
1483
apacible45cbfc92015-09-28 22:45:411484 command_updater_.UpdateCommandEnabled(IDC_ROUTE_MEDIA,
1485 CanRouteMedia(browser_));
1486}
1487
Elly Fong-Jones5e6baaf2019-10-10 23:17:141488void BrowserCommandController::UpdateCommandsForTabKeyboardFocus(
1489 base::Optional<int> target_index) {
1490 command_updater_.UpdateCommandEnabled(
1491 IDC_DUPLICATE_TARGET_TAB, !browser_->deprecated_is_app() &&
1492 target_index.has_value() &&
1493 CanDuplicateTabAt(browser_, *target_index));
1494 const bool normal_window = browser_->is_type_normal();
1495 command_updater_.UpdateCommandEnabled(
1496 IDC_MUTE_TARGET_SITE, normal_window && target_index.has_value());
1497 command_updater_.UpdateCommandEnabled(
1498 IDC_PIN_TARGET_TAB, normal_window && target_index.has_value());
Connie Wan303e29e2020-01-31 18:16:561499 command_updater_.UpdateCommandEnabled(
1500 IDC_GROUP_TARGET_TAB, normal_window && target_index.has_value());
Elly Fong-Jones5e6baaf2019-10-10 23:17:141501}
1502
[email protected]409ea2972012-11-10 19:54:431503void BrowserCommandController::AddInterstitialObservers(WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071504 interstitial_observers_.push_back(new InterstitialObserver(this, contents));
[email protected]5d98294912012-06-27 22:57:401505}
1506
1507void BrowserCommandController::RemoveInterstitialObservers(
[email protected]e89cfcb2012-11-11 14:47:241508 WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071509 for (size_t i = 0; i < interstitial_observers_.size(); i++) {
1510 if (interstitial_observers_[i]->web_contents() != contents)
1511 continue;
1512
1513 delete interstitial_observers_[i];
1514 interstitial_observers_.erase(interstitial_observers_.begin() + i);
1515 return;
1516 }
[email protected]5d98294912012-06-27 22:57:401517}
1518
1519BrowserWindow* BrowserCommandController::window() {
1520 return browser_->window();
1521}
1522
1523Profile* BrowserCommandController::profile() {
1524 return browser_->profile();
1525}
1526
[email protected]5d98294912012-06-27 22:57:401527} // namespace chrome