blob: 085a0707c58f0b6afd3b95f70b591a850b2ca534 [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"
Yann Dagocd13225a2019-03-07 18:39:0515#include "base/feature_list.h"
avi655876a2015-12-25 07:18:1516#include "base/macros.h"
bratell0a7406f2017-03-28 07:46:3717#include "base/metrics/user_metrics.h"
Haeun Kim3f6123502018-08-26 18:03:0418#include "base/stl_util.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"
38#include "chrome/browser/ui/browser_window.h"
39#include "chrome/browser/ui/chrome_pages.h"
Alan Cutter09965802018-03-27 07:25:2940#include "chrome/browser/ui/extensions/application_launch.h"
Christopher Lam0dbac2b2017-11-14 07:12:1041#include "chrome/browser/ui/extensions/hosted_app_browser_controller.h"
Alan Cutter0c3132302018-02-21 05:09:0242#include "chrome/browser/ui/page_info/page_info_dialog.h"
Nicolas Ouellet-payeur82eb65b2018-11-05 16:49:2743#include "chrome/browser/ui/singleton_tabs.h"
[email protected]5d98294912012-06-27 22:57:4044#include "chrome/browser/ui/tabs/tab_strip_model.h"
Yining Wang234ad3272019-04-08 18:47:2745#include "chrome/browser/ui/web_app_browser_controller.h"
[email protected]2056c3192013-10-21 22:40:5146#include "chrome/browser/ui/webui/inspect_ui.h"
Yann Dagocd13225a2019-03-07 18:39:0547#include "chrome/common/chrome_features.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"
sdefresne0f2ef352015-07-27 19:18:0052#include "components/dom_distiller/core/dom_distiller_switches.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"
David Rogera6c88122017-10-25 13:02:4656#include "components/signin/core/browser/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
Bettina Deaf3dac202017-09-16 20:53:2289#if BUILDFLAG(ENABLE_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
106///////////////////////////////////////////////////////////////////////////////
107// BrowserCommandController, public:
108
[email protected]338416c02014-05-13 16:47:06109BrowserCommandController::BrowserCommandController(Browser* browser)
Aran Gilmand217b5b2019-04-11 17:45:43110 : browser_(browser), command_updater_(nullptr) {
[email protected]5d98294912012-06-27 22:57:40111 browser_->tab_strip_model()->AddObserver(this);
112 PrefService* local_state = g_browser_process->local_state();
113 if (local_state) {
114 local_pref_registrar_.Init(local_state);
[email protected]9ec3ea5b2012-12-03 18:14:30115 local_pref_registrar_.Add(
116 prefs::kAllowFileSelectionDialogs,
117 base::Bind(
118 &BrowserCommandController::UpdateCommandsForFileSelectionDialogs,
119 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40120 }
121
122 profile_pref_registrar_.Init(profile()->GetPrefs());
[email protected]9ec3ea5b2012-12-03 18:14:30123 profile_pref_registrar_.Add(
Pavol Markodebb0ff2018-05-07 18:35:41124 prefs::kDevToolsAvailability,
[email protected]9ec3ea5b2012-12-03 18:14:30125 base::Bind(&BrowserCommandController::UpdateCommandsForDevTools,
126 base::Unretained(this)));
127 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32128 bookmarks::prefs::kEditBookmarksEnabled,
[email protected]9ec3ea5b2012-12-03 18:14:30129 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkEditing,
130 base::Unretained(this)));
131 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32132 bookmarks::prefs::kShowBookmarkBar,
[email protected]9ec3ea5b2012-12-03 18:14:30133 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkBar,
134 base::Unretained(this)));
135 profile_pref_registrar_.Add(
136 prefs::kIncognitoModeAvailability,
137 base::Bind(
138 &BrowserCommandController::UpdateCommandsForIncognitoAvailability,
139 base::Unretained(this)));
140 profile_pref_registrar_.Add(
141 prefs::kPrintingEnabled,
142 base::Bind(&BrowserCommandController::UpdatePrintingState,
143 base::Unretained(this)));
[email protected]32dfede2013-08-25 15:48:25144#if !defined(OS_MACOSX)
145 profile_pref_registrar_.Add(
146 prefs::kFullscreenAllowed,
147 base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode,
148 base::Unretained(this)));
149#endif
Mihai Sardarescuf87ccc12018-09-26 10:37:45150 pref_signin_allowed_.Init(
Aran Gilmand217b5b2019-04-11 17:45:43151 prefs::kSigninAllowed, profile()->GetOriginalProfile()->GetPrefs(),
Mihai Sardarescuf87ccc12018-09-26 10:37:45152 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange,
153 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40154
155 InitCommandState();
156
blundell74001adc2015-09-18 11:04:25157 sessions::TabRestoreService* tab_restore_service =
[email protected]5d98294912012-06-27 22:57:40158 TabRestoreServiceFactory::GetForProfile(profile());
159 if (tab_restore_service) {
160 tab_restore_service->AddObserver(this);
Cliff Smolinsky2c9586e2019-02-08 18:48:30161 if (!tab_restore_service->IsLoaded())
162 tab_restore_service->LoadTabsFromLastSession();
[email protected]5d98294912012-06-27 22:57:40163 }
[email protected]5d98294912012-06-27 22:57:40164}
165
166BrowserCommandController::~BrowserCommandController() {
[email protected]95e39472012-10-05 23:37:36167 // TabRestoreService may have been shutdown by the time we get here. Don't
168 // trigger creating it.
blundell74001adc2015-09-18 11:04:25169 sessions::TabRestoreService* tab_restore_service =
[email protected]95e39472012-10-05 23:37:36170 TabRestoreServiceFactory::GetForProfileIfExisting(profile());
[email protected]5d98294912012-06-27 22:57:40171 if (tab_restore_service)
172 tab_restore_service->RemoveObserver(this);
173 profile_pref_registrar_.RemoveAll();
174 local_pref_registrar_.RemoveAll();
175 browser_->tab_strip_model()->RemoveObserver(this);
176}
177
178bool BrowserCommandController::IsReservedCommandOrKey(
179 int command_id,
180 const content::NativeWebKeyboardEvent& event) {
181 // In Apps mode, no keys are reserved.
182 if (browser_->is_app())
183 return false;
184
185#if defined(OS_CHROMEOS)
[email protected]397abd32013-08-21 05:44:19186 // On Chrome OS, the top row of keys are mapped to browser actions like
187 // back/forward or refresh. We don't want web pages to be able to change the
188 // behavior of these keys. Ash handles F4 and up; this leaves us needing to
189 // reserve browser back/forward and refresh here.
[email protected]5d98294912012-06-27 22:57:40190 ui::KeyboardCode key_code =
Blink Reformat1c4d759e2017-04-09 16:34:54191 static_cast<ui::KeyboardCode>(event.windows_key_code);
[email protected]397abd32013-08-21 05:44:19192 if ((key_code == ui::VKEY_BROWSER_BACK && command_id == IDC_BACK) ||
193 (key_code == ui::VKEY_BROWSER_FORWARD && command_id == IDC_FORWARD) ||
194 (key_code == ui::VKEY_BROWSER_REFRESH && command_id == IDC_RELOAD)) {
[email protected]5d98294912012-06-27 22:57:40195 return true;
196 }
197#endif
198
zijiehe68cd3dc22017-04-07 18:50:29199 if (window()->IsFullscreen()) {
200 // In fullscreen, all commands except for IDC_FULLSCREEN and IDC_EXIT should
201 // be delivered to the web page. The intent to implement and ship can be
202 // found in http://crbug.com/680809.
203 const bool is_exit_fullscreen =
204 (command_id == IDC_EXIT || command_id == IDC_FULLSCREEN);
205#if defined(OS_MACOSX)
206 // This behavior is different on Mac OS, which has a unique user-initiated
207 // full-screen mode. According to the discussion in http://crbug.com/702251,
208 // the commands should be reserved for browser-side handling if the browser
209 // window's toolbar is visible.
210 if (window()->IsToolbarShowing()) {
211 if (command_id == IDC_FULLSCREEN)
212 return true;
213 } else {
214 return is_exit_fullscreen;
215 }
216#else
217 return is_exit_fullscreen;
218#endif
219 }
[email protected]1e2172f2014-04-01 17:32:34220
[email protected]893124a22014-04-15 00:45:28221#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]1e2172f2014-04-01 17:32:34222 // If this key was registered by the user as a content editing hotkey, then
223 // it is not reserved.
[email protected]d5bedb6d2014-04-08 10:49:32224 ui::TextEditKeyBindingsDelegateAuraLinux* delegate =
[email protected]1e2172f2014-04-01 17:32:34225 ui::GetTextEditKeyBindingsDelegate();
[email protected]47e8e7542014-04-03 07:52:42226 if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL))
[email protected]1e2172f2014-04-01 17:32:34227 return false;
228#endif
229
Aran Gilmand217b5b2019-04-11 17:45:43230 return command_id == IDC_CLOSE_TAB || command_id == IDC_CLOSE_WINDOW ||
231 command_id == IDC_NEW_INCOGNITO_WINDOW || command_id == IDC_NEW_TAB ||
232 command_id == IDC_NEW_WINDOW || command_id == IDC_RESTORE_TAB ||
zijiehe13207802017-02-16 08:06:10233 command_id == IDC_SELECT_NEXT_TAB ||
Aran Gilmand217b5b2019-04-11 17:45:43234 command_id == IDC_SELECT_PREVIOUS_TAB || command_id == IDC_EXIT;
[email protected]5d98294912012-06-27 22:57:40235}
236
[email protected]5d98294912012-06-27 22:57:40237void BrowserCommandController::TabStateChanged() {
238 UpdateCommandsForTabState();
239}
240
[email protected]d93dbd12014-08-04 23:42:53241void BrowserCommandController::ZoomStateChanged() {
242 UpdateCommandsForZoomState();
243}
244
[email protected]5d98294912012-06-27 22:57:40245void BrowserCommandController::ContentRestrictionsChanged() {
246 UpdateCommandsForContentRestrictionState();
247}
248
249void BrowserCommandController::FullscreenStateChanged() {
[email protected]32dfede2013-08-25 15:48:25250 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40251}
252
Ivan Sandrk9669d0e2017-12-15 23:50:20253#if defined(OS_CHROMEOS)
254void BrowserCommandController::LockedFullscreenStateChanged() {
255 UpdateCommandsForLockedFullscreenMode();
256}
257#endif
258
[email protected]5d98294912012-06-27 22:57:40259void BrowserCommandController::PrintingStateChanged() {
260 UpdatePrintingState();
261}
262
263void BrowserCommandController::LoadingStateChanged(bool is_loading,
264 bool force) {
265 UpdateReloadStopState(is_loading, force);
266}
267
wittman76df71db32014-12-18 23:26:58268void BrowserCommandController::ExtensionStateChanged() {
269 // Extensions may disable the bookmark editing commands.
270 UpdateCommandsForBookmarkEditing();
271}
272
[email protected]5d98294912012-06-27 22:57:40273////////////////////////////////////////////////////////////////////////////////
Ivan Sandrk9669d0e2017-12-15 23:50:20274// BrowserCommandController, CommandUpdater implementation:
[email protected]5d98294912012-06-27 22:57:40275
Ivan Sandrk9669d0e2017-12-15 23:50:20276bool BrowserCommandController::SupportsCommand(int id) const {
277 return command_updater_.SupportsCommand(id);
278}
279
280bool BrowserCommandController::IsCommandEnabled(int id) const {
281 return command_updater_.IsCommandEnabled(id);
282}
283
Edwin Joe6f6fc1e2019-02-27 20:00:37284bool BrowserCommandController::ExecuteCommand(int id,
285 base::TimeTicks time_stamp) {
286 return ExecuteCommandWithDisposition(id, WindowOpenDisposition::CURRENT_TAB,
287 time_stamp);
Ivan Sandrk9669d0e2017-12-15 23:50:20288}
289
290bool BrowserCommandController::ExecuteCommandWithDisposition(
Edwin Joe6f6fc1e2019-02-27 20:00:37291 int id,
292 WindowOpenDisposition disposition,
293 base::TimeTicks time_stamp) {
Ivan Sandrk9669d0e2017-12-15 23:50:20294 // Doesn't go through the command_updater_ to avoid dealing with having a
295 // naming collision for ExecuteCommandWithDisposition (both
296 // CommandUpdaterDelegate and CommandUpdater declare this function so we
297 // choose to not implement CommandUpdaterDelegate inside this class and
298 // therefore command_updater_ doesn't have the delegate set).
299 if (!SupportsCommand(id) || !IsCommandEnabled(id))
300 return false;
301
[email protected]5d98294912012-06-27 22:57:40302 // No commands are enabled if there is not yet any selected tab.
303 // TODO(pkasting): It seems like we should not need this, because either
304 // most/all commands should not have been enabled yet anyway or the ones that
305 // are enabled should be global, or safe themselves against having no selected
306 // tab. However, Ben says he tried removing this before and got lots of
307 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
308 // window construction. This probably could use closer examination someday.
[email protected]59253a652012-11-20 00:17:26309 if (browser_->tab_strip_model()->active_index() == TabStripModel::kNoTab)
Ivan Sandrk9669d0e2017-12-15 23:50:20310 return true;
[email protected]5d98294912012-06-27 22:57:40311
Aran Gilmand217b5b2019-04-11 17:45:43312 DCHECK(command_updater_.IsCommandEnabled(id))
313 << "Invalid/disabled command " << id;
[email protected]5d98294912012-06-27 22:57:40314
[email protected]5d98294912012-06-27 22:57:40315 // The order of commands in this switch statement must match the function
316 // declaration order in browser.h!
317 switch (id) {
318 // Navigation commands
319 case IDC_BACK:
320 GoBack(browser_, disposition);
321 break;
322 case IDC_FORWARD:
323 GoForward(browser_, disposition);
324 break;
325 case IDC_RELOAD:
326 Reload(browser_, disposition);
327 break;
[email protected]58e29032012-08-06 20:19:57328 case IDC_RELOAD_CLEARING_CACHE:
329 ClearCache(browser_);
Nico Webera745ef72018-01-29 23:45:57330 FALLTHROUGH;
toyoshim7dad4b1182016-04-01 14:28:05331 case IDC_RELOAD_BYPASSING_CACHE:
332 ReloadBypassingCache(browser_, disposition);
[email protected]5d98294912012-06-27 22:57:40333 break;
334 case IDC_HOME:
335 Home(browser_, disposition);
336 break;
337 case IDC_OPEN_CURRENT_URL:
338 OpenCurrentURL(browser_);
339 break;
340 case IDC_STOP:
341 Stop(browser_);
342 break;
343
Aran Gilmand217b5b2019-04-11 17:45:43344 // Window management commands
[email protected]5d98294912012-06-27 22:57:40345 case IDC_NEW_WINDOW:
346 NewWindow(browser_);
347 break;
348 case IDC_NEW_INCOGNITO_WINDOW:
Orin Jaworski5e4bcd0c2018-10-16 19:35:05349 NewIncognitoWindow(profile());
[email protected]5d98294912012-06-27 22:57:40350 break;
351 case IDC_CLOSE_WINDOW:
bratell0a7406f2017-03-28 07:46:37352 base::RecordAction(base::UserMetricsAction("CloseWindowByKey"));
[email protected]04b9e692012-08-24 14:49:09353 CloseWindow(browser_);
[email protected]5d98294912012-06-27 22:57:40354 break;
Bettina Dea0a4505922017-09-28 00:53:32355 case IDC_NEW_TAB: {
356 NewTab(browser_);
357#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Catherine Chungbeb884222017-08-01 15:47:55358 // This is not in NewTab() to avoid tracking programmatic creation of new
359 // tabs by extensions.
Bettina Dea0a4505922017-09-28 00:53:32360 auto* new_tab_tracker =
361 feature_engagement::NewTabTrackerFactory::GetInstance()
362 ->GetForProfile(profile());
363
364 new_tab_tracker->OnNewTabOpened();
365 new_tab_tracker->CloseBubble();
Catherine Chungbeb884222017-08-01 15:47:55366#endif
[email protected]5d98294912012-06-27 22:57:40367 break;
Bettina Dea0a4505922017-09-28 00:53:32368 }
[email protected]5d98294912012-06-27 22:57:40369 case IDC_CLOSE_TAB:
bratell0a7406f2017-03-28 07:46:37370 base::RecordAction(base::UserMetricsAction("CloseTabByKey"));
[email protected]04b9e692012-08-24 14:49:09371 CloseTab(browser_);
[email protected]5d98294912012-06-27 22:57:40372 break;
373 case IDC_SELECT_NEXT_TAB:
bratell0a7406f2017-03-28 07:46:37374 base::RecordAction(base::UserMetricsAction("Accel_SelectNextTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37375 SelectNextTab(browser_,
376 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40377 break;
378 case IDC_SELECT_PREVIOUS_TAB:
bratell0a7406f2017-03-28 07:46:37379 base::RecordAction(base::UserMetricsAction("Accel_SelectPreviousTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37380 SelectPreviousTab(browser_,
381 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40382 break;
[email protected]5d98294912012-06-27 22:57:40383 case IDC_MOVE_TAB_NEXT:
384 MoveTabNext(browser_);
385 break;
386 case IDC_MOVE_TAB_PREVIOUS:
387 MoveTabPrevious(browser_);
388 break;
389 case IDC_SELECT_TAB_0:
390 case IDC_SELECT_TAB_1:
391 case IDC_SELECT_TAB_2:
392 case IDC_SELECT_TAB_3:
393 case IDC_SELECT_TAB_4:
394 case IDC_SELECT_TAB_5:
395 case IDC_SELECT_TAB_6:
396 case IDC_SELECT_TAB_7:
bratell0a7406f2017-03-28 07:46:37397 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37398 SelectNumberedTab(browser_, id - IDC_SELECT_TAB_0,
399 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40400 break;
401 case IDC_SELECT_LAST_TAB:
bratell0a7406f2017-03-28 07:46:37402 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37403 SelectLastTab(browser_,
404 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40405 break;
406 case IDC_DUPLICATE_TAB:
407 DuplicateTab(browser_);
408 break;
409 case IDC_RESTORE_TAB:
410 RestoreTab(browser_);
Collin Baker9bbe1d82019-03-08 01:16:27411 browser_->window()->OnTabRestored(IDC_RESTORE_TAB);
[email protected]5d98294912012-06-27 22:57:40412 break;
[email protected]5d98294912012-06-27 22:57:40413 case IDC_SHOW_AS_TAB:
414 ConvertPopupToTabbedBrowser(browser_);
415 break;
416 case IDC_FULLSCREEN:
[email protected]3f32b9b2012-07-09 16:59:28417 chrome::ToggleFullscreenMode(browser_);
[email protected]5d98294912012-06-27 22:57:40418 break;
Alan Cutter09965802018-03-27 07:25:29419 case IDC_OPEN_IN_PWA_WINDOW:
420 base::RecordAction(base::UserMetricsAction("OpenActiveTabInPwaWindow"));
421 ReparentSecureActiveTabIntoPwaWindow(browser_);
422 break;
[email protected]770c6d82012-09-06 22:21:32423
[email protected]d12cc5e2013-10-19 18:25:06424#if defined(OS_CHROMEOS)
425 case IDC_VISIT_DESKTOP_OF_LRU_USER_2:
[email protected]0c930812014-01-30 18:01:47426 case IDC_VISIT_DESKTOP_OF_LRU_USER_3:
zijiehe4dde8072017-02-13 20:38:35427 ExecuteVisitDesktopCommand(id, window()->GetNativeWindow());
[email protected]0c930812014-01-30 18:01:47428 break;
[email protected]d12cc5e2013-10-19 18:25:06429#endif
430
[email protected]893124a22014-04-15 00:45:28431#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15432 case IDC_MINIMIZE_WINDOW:
433 browser_->window()->Minimize();
434 break;
435 case IDC_MAXIMIZE_WINDOW:
436 browser_->window()->Maximize();
437 break;
438 case IDC_RESTORE_WINDOW:
439 browser_->window()->Restore();
440 break;
[email protected]af97be4c62014-02-13 14:43:34441 case IDC_USE_SYSTEM_TITLE_BAR: {
zijiehe4dde8072017-02-13 20:38:35442 PrefService* prefs = profile()->GetPrefs();
[email protected]af97be4c62014-02-13 14:43:34443 prefs->SetBoolean(prefs::kUseCustomChromeFrame,
444 !prefs->GetBoolean(prefs::kUseCustomChromeFrame));
445 break;
446 }
447#endif
448
[email protected]5d98294912012-06-27 22:57:40449#if defined(OS_MACOSX)
spqchanb8ffc7d2015-11-17 01:17:21450 case IDC_TOGGLE_FULLSCREEN_TOOLBAR:
451 chrome::ToggleFullscreenToolbar(browser_);
452 break;
spqchan2c5d541e2017-10-25 07:07:11453 case IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS: {
Robert Sesek03282612018-10-31 15:48:06454 chrome::ToggleJavaScriptFromAppleEventsAllowed(browser_);
spqchan2c5d541e2017-10-25 07:07:11455 break;
456 }
[email protected]5d98294912012-06-27 22:57:40457#endif
458 case IDC_EXIT:
459 Exit();
460 break;
461
462 // Page-related commands
463 case IDC_SAVE_PAGE:
464 SavePage(browser_);
465 break;
466 case IDC_BOOKMARK_PAGE:
Anatoly Pilikovee720922017-11-01 09:43:17467#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:14468 feature_engagement::BookmarkTrackerFactory::GetInstance()
469 ->GetForProfile(profile())
470 ->OnBookmarkAdded();
471#endif
deepak.m154a7f392014-12-15 04:41:43472 BookmarkCurrentPageAllowingExtensionOverrides(browser_);
[email protected]5d98294912012-06-27 22:57:40473 break;
[email protected]5d98294912012-06-27 22:57:40474 case IDC_BOOKMARK_ALL_TABS:
Anatoly Pilikovee720922017-11-01 09:43:17475#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:14476 feature_engagement::BookmarkTrackerFactory::GetInstance()
477 ->GetForProfile(profile())
478 ->OnBookmarkAdded();
479#endif
[email protected]5d98294912012-06-27 22:57:40480 BookmarkAllTabs(browser_);
481 break;
482 case IDC_VIEW_SOURCE:
Lukasz Anforowicze1b954d92017-10-30 21:28:06483 browser_->tab_strip_model()
484 ->GetActiveWebContents()
485 ->GetMainFrame()
486 ->ViewSource();
[email protected]5d98294912012-06-27 22:57:40487 break;
488 case IDC_EMAIL_PAGE_LOCATION:
489 EmailPageLocation(browser_);
490 break;
491 case IDC_PRINT:
492 Print(browser_);
493 break;
bondd052b5f82015-10-28 22:39:32494
Lei Zhang48a4a5262018-04-17 20:18:44495#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:55496 case IDC_BASIC_PRINT:
bratell0a7406f2017-03-28 07:46:37497 base::RecordAction(base::UserMetricsAction("Accel_Advanced_Print"));
vitalybukaf9433e42014-09-08 10:04:55498 BasicPrint(browser_);
[email protected]5d98294912012-06-27 22:57:40499 break;
Lei Zhang48a4a5262018-04-17 20:18:44500#endif // ENABLE_PRINTING
bondd052b5f82015-10-28 22:39:32501
bondd052b5f82015-10-28 22:39:32502 case IDC_SAVE_CREDIT_CARD_FOR_PAGE:
503 SaveCreditCard(browser_);
504 break;
siyua3e599eaa2018-07-13 00:23:06505 case IDC_MIGRATE_LOCAL_CREDIT_CARD_FOR_PAGE:
506 MigrateLocalCards(browser_);
507 break;
[email protected]e625b7602013-10-28 09:24:56508 case IDC_TRANSLATE_PAGE:
509 Translate(browser_);
510 break;
[email protected]4bee4432014-05-05 13:11:41511 case IDC_MANAGE_PASSWORDS_FOR_PAGE:
512 ManagePasswordsForPage(browser_);
513 break;
[email protected]4bee4432014-05-05 13:11:41514
[email protected]5d98294912012-06-27 22:57:40515 // Clipboard commands
516 case IDC_CUT:
[email protected]5d98294912012-06-27 22:57:40517 case IDC_COPY:
[email protected]5d98294912012-06-27 22:57:40518 case IDC_PASTE:
pkastingcd3f08bce2015-04-18 13:37:12519 CutCopyPaste(browser_, id);
[email protected]5d98294912012-06-27 22:57:40520 break;
521
522 // Find-in-page
523 case IDC_FIND:
524 Find(browser_);
525 break;
526 case IDC_FIND_NEXT:
527 FindNext(browser_);
528 break;
529 case IDC_FIND_PREVIOUS:
530 FindPrevious(browser_);
531 break;
532
533 // Zoom
534 case IDC_ZOOM_PLUS:
535 Zoom(browser_, content::PAGE_ZOOM_IN);
536 break;
537 case IDC_ZOOM_NORMAL:
538 Zoom(browser_, content::PAGE_ZOOM_RESET);
539 break;
540 case IDC_ZOOM_MINUS:
541 Zoom(browser_, content::PAGE_ZOOM_OUT);
542 break;
543
544 // Focus various bits of UI
545 case IDC_FOCUS_TOOLBAR:
bratell0a7406f2017-03-28 07:46:37546 base::RecordAction(base::UserMetricsAction("Accel_Focus_Toolbar"));
[email protected]5d98294912012-06-27 22:57:40547 FocusToolbar(browser_);
548 break;
549 case IDC_FOCUS_LOCATION:
bratell0a7406f2017-03-28 07:46:37550 base::RecordAction(base::UserMetricsAction("Accel_Focus_Location"));
[email protected]5d98294912012-06-27 22:57:40551 FocusLocationBar(browser_);
552 break;
553 case IDC_FOCUS_SEARCH:
bratell0a7406f2017-03-28 07:46:37554 base::RecordAction(base::UserMetricsAction("Accel_Focus_Search"));
[email protected]5d98294912012-06-27 22:57:40555 FocusSearch(browser_);
556 break;
557 case IDC_FOCUS_MENU_BAR:
558 FocusAppMenu(browser_);
559 break;
560 case IDC_FOCUS_BOOKMARKS:
bratell0a7406f2017-03-28 07:46:37561 base::RecordAction(base::UserMetricsAction("Accel_Focus_Bookmarks"));
[email protected]5d98294912012-06-27 22:57:40562 FocusBookmarksToolbar(browser_);
563 break;
David Tsengc0b1b642018-01-24 07:12:27564 case IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY:
565 FocusInactivePopupForAccessibility(browser_);
[email protected]822ca8c62013-04-19 00:49:15566 break;
[email protected]5d98294912012-06-27 22:57:40567 case IDC_FOCUS_NEXT_PANE:
568 FocusNextPane(browser_);
569 break;
570 case IDC_FOCUS_PREVIOUS_PANE:
571 FocusPreviousPane(browser_);
572 break;
573
574 // Show various bits of UI
575 case IDC_OPEN_FILE:
576 browser_->OpenFile();
577 break;
Alan Cutter81ac726682018-09-25 00:18:36578 case IDC_CREATE_SHORTCUT:
579 CreateBookmarkAppFromCurrentWebContents(browser_,
580 true /* force_shortcut_app */);
581 break;
582 case IDC_INSTALL_PWA:
583 CreateBookmarkAppFromCurrentWebContents(browser_,
584 false /* force_shortcut_app */);
[email protected]488e3952013-11-18 05:29:14585 break;
[email protected]5d98294912012-06-27 22:57:40586 case IDC_DEV_TOOLS:
[email protected]c934c382013-11-01 00:36:01587 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Show());
[email protected]5d98294912012-06-27 22:57:40588 break;
589 case IDC_DEV_TOOLS_CONSOLE:
einbinderdfa567b2016-12-16 01:15:52590 ToggleDevToolsWindow(browser_, DevToolsToggleAction::ShowConsolePanel());
[email protected]5d98294912012-06-27 22:57:40591 break;
[email protected]2056c3192013-10-21 22:40:51592 case IDC_DEV_TOOLS_DEVICES:
593 InspectUI::InspectDevices(browser_);
594 break;
[email protected]5d98294912012-06-27 22:57:40595 case IDC_DEV_TOOLS_INSPECT:
[email protected]c934c382013-11-01 00:36:01596 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Inspect());
[email protected]5d98294912012-06-27 22:57:40597 break;
[email protected]d16657c2012-09-03 14:25:10598 case IDC_DEV_TOOLS_TOGGLE:
[email protected]c934c382013-11-01 00:36:01599 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Toggle());
[email protected]d16657c2012-09-03 14:25:10600 break;
[email protected]5d98294912012-06-27 22:57:40601 case IDC_TASK_MANAGER:
[email protected]29c262de2013-06-22 15:39:38602 OpenTaskManager(browser_);
[email protected]5d98294912012-06-27 22:57:40603 break;
caelyn4e4e08a2015-02-04 21:27:49604#if defined(OS_CHROMEOS)
605 case IDC_TAKE_SCREENSHOT:
606 TakeScreenshot();
607 break;
608#endif
[email protected]236ad3022013-09-04 03:27:43609#if defined(GOOGLE_CHROME_BUILD)
[email protected]5d98294912012-06-27 22:57:40610 case IDC_FEEDBACK:
afakhryf4575bd2017-04-28 02:21:04611 OpenFeedbackDialog(browser_, kFeedbackSourceBrowserCommand);
[email protected]5d98294912012-06-27 22:57:40612 break;
[email protected]236ad3022013-09-04 03:27:43613#endif
[email protected]5d98294912012-06-27 22:57:40614 case IDC_SHOW_BOOKMARK_BAR:
615 ToggleBookmarkBar(browser_);
616 break;
617 case IDC_PROFILING_ENABLED:
Bryce Thomas96b07772018-11-07 03:04:15618 content::Profiling::Toggle();
[email protected]5d98294912012-06-27 22:57:40619 break;
620
621 case IDC_SHOW_BOOKMARK_MANAGER:
622 ShowBookmarkManager(browser_);
623 break;
624 case IDC_SHOW_APP_MENU:
bratell0a7406f2017-03-28 07:46:37625 base::RecordAction(base::UserMetricsAction("Accel_Show_App_Menu"));
[email protected]5d98294912012-06-27 22:57:40626 ShowAppMenu(browser_);
627 break;
628 case IDC_SHOW_AVATAR_MENU:
629 ShowAvatarMenu(browser_);
630 break;
631 case IDC_SHOW_HISTORY:
632 ShowHistory(browser_);
633 break;
634 case IDC_SHOW_DOWNLOADS:
635 ShowDownloads(browser_);
636 break;
637 case IDC_MANAGE_EXTENSIONS:
[email protected]bc9833c32013-02-28 04:05:08638 ShowExtensions(browser_, std::string());
[email protected]5d98294912012-06-27 22:57:40639 break;
640 case IDC_OPTIONS:
641 ShowSettings(browser_);
642 break;
643 case IDC_EDIT_SEARCH_ENGINES:
644 ShowSearchEngineSettings(browser_);
645 break;
646 case IDC_VIEW_PASSWORDS:
647 ShowPasswordManager(browser_);
648 break;
649 case IDC_CLEAR_BROWSING_DATA:
650 ShowClearBrowsingDataDialog(browser_);
651 break;
652 case IDC_IMPORT_SETTINGS:
653 ShowImportDialog(browser_);
654 break;
[email protected]9b7ab882012-09-10 23:46:36655 case IDC_TOGGLE_REQUEST_TABLET_SITE:
656 ToggleRequestTabletSite(browser_);
657 break;
[email protected]5d98294912012-06-27 22:57:40658 case IDC_ABOUT:
659 ShowAboutChrome(browser_);
660 break;
661 case IDC_UPGRADE_DIALOG:
662 OpenUpdateChromeDialog(browser_);
663 break;
[email protected]5d98294912012-06-27 22:57:40664 case IDC_HELP_PAGE_VIA_KEYBOARD:
665 ShowHelp(browser_, HELP_SOURCE_KEYBOARD);
666 break;
667 case IDC_HELP_PAGE_VIA_MENU:
668 ShowHelp(browser_, HELP_SOURCE_MENU);
669 break;
Bret Sepulveda2d018662017-05-18 21:31:48670 case IDC_SHOW_BETA_FORUM:
671 ShowBetaForum(browser_);
672 break;
David Roger7e25dff2019-02-07 09:03:17673#if !defined(OS_CHROMEOS)
estade8c0780f2015-08-21 23:36:41674 case IDC_SHOW_SIGNIN:
gogerald71bf6c902015-12-08 00:49:37675 ShowBrowserSigninOrSettings(
676 browser_, signin_metrics::AccessPoint::ACCESS_POINT_MENU);
estade8c0780f2015-08-21 23:36:41677 break;
David Roger7e25dff2019-02-07 09:03:17678#endif
[email protected]6bd370b2014-05-28 14:19:47679 case IDC_DISTILL_PAGE:
680 DistillCurrentPage(browser_);
681 break;
apacible45cbfc92015-09-28 22:45:41682 case IDC_ROUTE_MEDIA:
683 RouteMedia(browser_);
684 break;
Tommy Steimelc4477982017-11-29 18:07:18685 case IDC_WINDOW_MUTE_SITE:
686 MuteSite(browser_);
ellyjones0101ba02017-05-19 15:50:26687 break;
688 case IDC_WINDOW_PIN_TAB:
689 PinTab(browser_);
690 break;
Yann Dagocd13225a2019-03-07 18:39:05691 case IDC_SHOW_MANAGEMENT_PAGE: {
692 bool link_to_management_page = base::FeatureList::IsEnabled(
693 features::kLinkManagedNoticeToChromeUIManagementURL);
694 ShowSingletonTab(browser_,
695 GURL(link_to_management_page ? kChromeUIManagementURL
696 : kManagedUiLearnMoreUrl));
Nicolas Ouellet-payeur82eb65b2018-11-05 16:49:27697 break;
Yann Dagocd13225a2019-03-07 18:39:05698 }
Christopher Lam0dbac2b2017-11-14 07:12:10699 // Hosted App commands
700 case IDC_COPY_URL:
701 CopyURL(browser_);
702 break;
703 case IDC_OPEN_IN_CHROME:
704 OpenInChrome(browser_);
705 break;
706 case IDC_SITE_SETTINGS:
707 ShowSiteSettings(
708 browser_,
709 browser_->tab_strip_model()->GetActiveWebContents()->GetVisibleURL());
710 break;
Alan Cutter0c3132302018-02-21 05:09:02711 case IDC_HOSTED_APP_MENU_APP_INFO:
712 ShowPageInfoDialog(browser_->tab_strip_model()->GetActiveWebContents(),
Alan Cutter689f89a2018-03-08 05:09:54713 bubble_anchor_util::kAppMenuButton);
Christopher Lam86b52712017-12-04 01:58:33714 break;
Christopher Lam0dbac2b2017-11-14 07:12:10715
[email protected]5d98294912012-06-27 22:57:40716 default:
717 LOG(WARNING) << "Received Unimplemented Command: " << id;
718 break;
719 }
Ivan Sandrk9669d0e2017-12-15 23:50:20720
721 return true;
722}
723
724void BrowserCommandController::AddCommandObserver(int id,
725 CommandObserver* observer) {
726 command_updater_.AddCommandObserver(id, observer);
727}
728
729void BrowserCommandController::RemoveCommandObserver(
Aran Gilmand217b5b2019-04-11 17:45:43730 int id,
731 CommandObserver* observer) {
Ivan Sandrk9669d0e2017-12-15 23:50:20732 command_updater_.RemoveCommandObserver(id, observer);
733}
734
735void BrowserCommandController::RemoveCommandObserver(
736 CommandObserver* observer) {
737 command_updater_.RemoveCommandObserver(observer);
738}
739
740bool BrowserCommandController::UpdateCommandEnabled(int id, bool state) {
741 if (is_locked_fullscreen_)
742 return false;
743
744 return command_updater_.UpdateCommandEnabled(id, state);
[email protected]5d98294912012-06-27 22:57:40745}
746
Mihai Sardarescuf87ccc12018-09-26 10:37:45747////////////////////////////////////////////////////////////////////////////////
748// BrowserCommandController, SigninPrefObserver implementation:
749
750void BrowserCommandController::OnSigninAllowedPrefChange() {
751 // For unit tests, we don't have a window.
752 if (!window())
753 return;
754 UpdateShowSyncState(IsShowingMainUI());
755}
756
[email protected]5d98294912012-06-27 22:57:40757// BrowserCommandController, TabStripModelObserver implementation:
758
sangwoo.ko1ae265f12018-10-18 08:30:28759void BrowserCommandController::OnTabStripModelChanged(
760 TabStripModel* tab_strip_model,
761 const TabStripModelChange& change,
762 const TabStripSelectionChange& selection) {
763 if (change.type() != TabStripModelChange::kInserted &&
764 change.type() != TabStripModelChange::kReplaced &&
765 change.type() != TabStripModelChange::kRemoved)
766 return;
[email protected]5d98294912012-06-27 22:57:40767
sangwoo.ko1ae265f12018-10-18 08:30:28768 for (const auto& delta : change.deltas()) {
769 content::WebContents* new_contents = nullptr;
770 content::WebContents* old_contents = nullptr;
771 if (change.type() == TabStripModelChange::kInserted) {
772 new_contents = delta.insert.contents;
773 } else if (change.type() == TabStripModelChange::kReplaced) {
774 new_contents = delta.replace.new_contents;
775 old_contents = delta.replace.old_contents;
776 } else {
777 old_contents = delta.remove.contents;
778 }
[email protected]5d98294912012-06-27 22:57:40779
sangwoo.ko1ae265f12018-10-18 08:30:28780 if (old_contents)
781 RemoveInterstitialObservers(old_contents);
782 if (new_contents)
783 AddInterstitialObservers(new_contents);
784 }
[email protected]5d98294912012-06-27 22:57:40785}
786
[email protected]3cac87232012-11-20 01:48:27787void BrowserCommandController::TabBlockedStateChanged(
788 content::WebContents* contents,
789 int index) {
790 PrintingStateChanged();
791 FullscreenStateChanged();
792 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:41793 UpdateCommandsForMediaRouter();
[email protected]3cac87232012-11-20 01:48:27794}
795
[email protected]5d98294912012-06-27 22:57:40796////////////////////////////////////////////////////////////////////////////////
797// BrowserCommandController, TabRestoreServiceObserver implementation:
798
799void BrowserCommandController::TabRestoreServiceChanged(
blundell74001adc2015-09-18 11:04:25800 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53801 UpdateTabRestoreCommandState();
[email protected]5d98294912012-06-27 22:57:40802}
803
804void BrowserCommandController::TabRestoreServiceDestroyed(
blundell74001adc2015-09-18 11:04:25805 sessions::TabRestoreService* service) {
[email protected]5d98294912012-06-27 22:57:40806 service->RemoveObserver(this);
807}
808
[email protected]2e9369e2014-08-15 09:12:53809void BrowserCommandController::TabRestoreServiceLoaded(
blundell74001adc2015-09-18 11:04:25810 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53811 UpdateTabRestoreCommandState();
812}
813
[email protected]5d98294912012-06-27 22:57:40814////////////////////////////////////////////////////////////////////////////////
[email protected]5d98294912012-06-27 22:57:40815// BrowserCommandController, private:
816
[email protected]20ca0382013-02-28 19:50:07817class BrowserCommandController::InterstitialObserver
818 : public content::WebContentsObserver {
819 public:
820 InterstitialObserver(BrowserCommandController* controller,
821 content::WebContents* web_contents)
Aran Gilmand217b5b2019-04-11 17:45:43822 : WebContentsObserver(web_contents), controller_(controller) {}
[email protected]20ca0382013-02-28 19:50:07823
dcheng5dd5ff62014-10-21 12:42:38824 void DidAttachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07825 controller_->UpdateCommandsForTabState();
826 }
827
dcheng5dd5ff62014-10-21 12:42:38828 void DidDetachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07829 controller_->UpdateCommandsForTabState();
830 }
831
832 private:
833 BrowserCommandController* controller_;
834
835 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver);
836};
837
[email protected]6a414ff2013-02-27 08:22:54838bool BrowserCommandController::IsShowingMainUI() {
manukf1a116392018-10-25 16:28:24839 return browser_->SupportsWindowFeature(Browser::FEATURE_TABSTRIP);
840}
841
842bool BrowserCommandController::IsShowingLocationBar() {
843 return browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
[email protected]5d98294912012-06-27 22:57:40844}
845
846void BrowserCommandController::InitCommandState() {
847 // All browser commands whose state isn't set automagically some other way
848 // (like Back & Forward with initial page load) must have their state
849 // initialized here, otherwise they will be forever disabled.
850
Ivan Sandrk9669d0e2017-12-15 23:50:20851 if (is_locked_fullscreen_)
852 return;
853
[email protected]5d98294912012-06-27 22:57:40854 // Navigation commands
855 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true);
toyoshim7dad4b1182016-04-01 14:28:05856 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE, true);
[email protected]58e29032012-08-06 20:19:57857 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, true);
[email protected]5d98294912012-06-27 22:57:40858
859 // Window management commands
860 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true);
861 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true);
862 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true);
863 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true);
[email protected]2e9369e2014-08-15 09:12:53864 UpdateTabRestoreCommandState();
[email protected]d28d3782013-02-26 16:31:55865 command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
[email protected]5d98294912012-06-27 22:57:40866 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true);
[email protected]d12cc5e2013-10-19 18:25:06867#if defined(OS_CHROMEOS)
James Cook934abaf2017-09-19 22:21:58868 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
[email protected]d12cc5e2013-10-19 18:25:06869 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_2, true);
870 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_3, true);
871#endif
[email protected]893124a22014-04-15 00:45:28872#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15873 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
874 command_updater_.UpdateCommandEnabled(IDC_MAXIMIZE_WINDOW, true);
875 command_updater_.UpdateCommandEnabled(IDC_RESTORE_WINDOW, true);
Maksim Sisovac767592018-08-10 08:00:15876 bool use_system_title_bar = true;
877#if defined(USE_OZONE)
878 use_system_title_bar = ui::OzonePlatform::GetInstance()
879 ->GetPlatformProperties()
880 .use_system_title_bar;
881#endif
882 command_updater_.UpdateCommandEnabled(IDC_USE_SYSTEM_TITLE_BAR,
883 use_system_title_bar);
[email protected]af97be4c62014-02-13 14:43:34884#endif
Alan Cutter09965802018-03-27 07:25:29885 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW, true);
[email protected]5d98294912012-06-27 22:57:40886
887 // Page-related commands
888 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true);
[email protected]4bee4432014-05-05 13:11:41889 command_updater_.UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE, true);
[email protected]5d98294912012-06-27 22:57:40890
891 // Zoom
892 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true);
893 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true);
[email protected]d93dbd12014-08-04 23:42:53894 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, false);
[email protected]5d98294912012-06-27 22:57:40895 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
896
897 // Show various bits of UI
Aran Gilmand217b5b2019-04-11 17:45:43898 const bool guest_session =
899 profile()->IsGuestSession() || profile()->IsSystemProfile();
mlerman7831f57d2015-05-25 11:40:15900 DCHECK(!profile()->IsSystemProfile())
901 << "Ought to never have browser for the system profile.";
[email protected]338416c02014-05-13 16:47:06902 const bool normal_window = browser_->is_type_tabbed();
[email protected]05454532013-01-22 21:09:08903 UpdateOpenFileState(&command_updater_);
[email protected]5d98294912012-06-27 22:57:40904 UpdateCommandsForDevTools();
905 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager());
[email protected]338416c02014-05-13 16:47:06906 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session);
[email protected]5d98294912012-06-27 22:57:40907 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
[email protected]674b65672014-06-02 23:21:56908 command_updater_.UpdateCommandEnabled(IDC_HELP_MENU, true);
[email protected]5d98294912012-06-27 22:57:40909 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
910 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
Bret Sepulveda2d018662017-05-18 21:31:48911 command_updater_.UpdateCommandEnabled(IDC_SHOW_BETA_FORUM, true);
[email protected]338416c02014-05-13 16:47:06912 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session);
Aran Gilmand217b5b2019-04-11 17:45:43913 command_updater_.UpdateCommandEnabled(
914 IDC_RECENT_TABS_MENU, !guest_session && !profile()->IsOffTheRecord());
tsergeant341a8272017-04-18 03:54:33915 command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA,
916 !guest_session);
[email protected]39d47592014-01-10 21:42:45917#if defined(OS_CHROMEOS)
caelyn4e4e08a2015-02-04 21:27:49918 command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true);
[email protected]338416c02014-05-13 16:47:06919#else
920 // Chrome OS uses the system tray menu to handle multi-profiles.
anthonyvd7dc985da2015-03-23 16:53:19921 if (normal_window && (guest_session || !profile()->IsOffTheRecord())) {
[email protected]338416c02014-05-13 16:47:06922 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
anthonyvd7dc985da2015-03-23 16:53:19923 }
[email protected]39d47592014-01-10 21:42:45924#endif
[email protected]5d98294912012-06-27 22:57:40925
Mihai Sardarescu2ec5205682018-09-26 09:20:05926 UpdateShowSyncState(true);
927
[email protected]5d98294912012-06-27 22:57:40928 // Navigation commands
Christopher Camerone1385742019-04-05 20:37:25929 command_updater_.UpdateCommandEnabled(IDC_HOME,
930 normal_window || browser_->is_app());
[email protected]5d98294912012-06-27 22:57:40931
Christopher Lam0dbac2b2017-11-14 07:12:10932 const bool is_experimental_hosted_app =
Yining Wang234ad3272019-04-08 18:47:27933 WebAppBrowserController::IsForExperimentalHostedAppBrowser(browser_);
Christopher Lam0dbac2b2017-11-14 07:12:10934 // Hosted app browser commands.
935 command_updater_.UpdateCommandEnabled(IDC_COPY_URL,
936 is_experimental_hosted_app);
937 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_CHROME,
938 is_experimental_hosted_app);
939 command_updater_.UpdateCommandEnabled(IDC_SITE_SETTINGS,
940 is_experimental_hosted_app);
Alan Cutter0c3132302018-02-21 05:09:02941 command_updater_.UpdateCommandEnabled(IDC_HOSTED_APP_MENU_APP_INFO,
Christopher Lam86b52712017-12-04 01:58:33942 is_experimental_hosted_app);
Christopher Lam0dbac2b2017-11-14 07:12:10943
[email protected]5d98294912012-06-27 22:57:40944 // Window management commands
[email protected]5d98294912012-06-27 22:57:40945 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window);
Aran Gilmand217b5b2019-04-11 17:45:43946 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, normal_window);
[email protected]5d98294912012-06-27 22:57:40947 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window);
948 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window);
949 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window);
950 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window);
951 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window);
952 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window);
953 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window);
954 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window);
955 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window);
956 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window);
957 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window);
[email protected]5d98294912012-06-27 22:57:40958
[email protected]338416c02014-05-13 16:47:06959 // These are always enabled; the menu determines their menu item visibility.
[email protected]5d98294912012-06-27 22:57:40960 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
[email protected]5d98294912012-06-27 22:57:40961
[email protected]6bd370b2014-05-28 14:19:47962 // Distill current page.
963 command_updater_.UpdateCommandEnabled(
avi556c05022014-12-22 23:31:43964 IDC_DISTILL_PAGE, base::CommandLine::ForCurrentProcess()->HasSwitch(
965 switches::kEnableDomDistiller));
[email protected]6bd370b2014-05-28 14:19:47966
Tommy Steimelc4477982017-11-29 18:07:18967 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE, normal_window);
ellyjones0101ba02017-05-19 15:50:26968 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, normal_window);
969
[email protected]338416c02014-05-13 16:47:06970 // Initialize other commands whose state changes based on various conditions.
[email protected]32dfede2013-08-25 15:48:25971 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40972 UpdateCommandsForContentRestrictionState();
[email protected]5d98294912012-06-27 22:57:40973 UpdateCommandsForBookmarkEditing();
[email protected]5d98294912012-06-27 22:57:40974 UpdateCommandsForIncognitoAvailability();
975}
976
[email protected]05454532013-01-22 21:09:08977// static
978void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
979 CommandUpdater* command_updater,
980 Profile* profile) {
mlermane01e6de2014-09-29 19:26:47981 const bool guest_session = profile->IsGuestSession();
982 // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession().
[email protected]5d98294912012-06-27 22:57:40983 IncognitoModePrefs::Availability incognito_availability =
[email protected]05454532013-01-22 21:09:08984 IncognitoModePrefs::GetAvailability(profile->GetPrefs());
985 command_updater->UpdateCommandEnabled(
Aran Gilmand217b5b2019-04-11 17:45:43986 IDC_NEW_WINDOW, incognito_availability != IncognitoModePrefs::FORCED);
[email protected]05454532013-01-22 21:09:08987 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40988 IDC_NEW_INCOGNITO_WINDOW,
mlermane01e6de2014-09-29 19:26:47989 incognito_availability != IncognitoModePrefs::DISABLED && !guest_session);
[email protected]5d98294912012-06-27 22:57:40990
[email protected]57b25292014-05-01 16:31:06991 const bool forced_incognito =
992 incognito_availability == IncognitoModePrefs::FORCED ||
993 guest_session; // Guest always runs in Incognito mode.
[email protected]05454532013-01-22 21:09:08994 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40995 IDC_SHOW_BOOKMARK_MANAGER,
[email protected]57b25292014-05-01 16:31:06996 browser_defaults::bookmarks_enabled && !forced_incognito);
Devlin Cronin21dba422018-05-30 15:45:16997 extensions::ExtensionService* extension_service =
[email protected]03d25812014-06-22 19:41:55998 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]57b25292014-05-01 16:31:06999 const bool enable_extensions =
[email protected]5d98294912012-06-27 22:57:401000 extension_service && extension_service->extensions_enabled();
[email protected]5d98294912012-06-27 22:57:401001
[email protected]57b25292014-05-01 16:31:061002 // Bookmark manager and settings page/subpages are forced to open in normal
1003 // mode. For this reason we disable these commands when incognito is forced.
1004 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
1005 enable_extensions && !forced_incognito);
1006
1007 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito);
1008 command_updater->UpdateCommandEnabled(IDC_OPTIONS,
1009 !forced_incognito || guest_session);
estade8c0780f2015-08-21 23:36:411010 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito);
[email protected]05454532013-01-22 21:09:081011}
1012
1013void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
Ivan Sandrk9669d0e2017-12-15 23:50:201014 if (is_locked_fullscreen_)
1015 return;
1016
[email protected]05454532013-01-22 21:09:081017 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile());
1018
[email protected]6a414ff2013-02-27 08:22:541019 if (!IsShowingMainUI()) {
[email protected]05454532013-01-22 21:09:081020 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false);
1021 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false);
1022 }
[email protected]5d98294912012-06-27 22:57:401023}
1024
1025void BrowserCommandController::UpdateCommandsForTabState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201026 if (is_locked_fullscreen_)
1027 return;
1028
[email protected]617ee962013-01-29 20:49:121029 WebContents* current_web_contents =
1030 browser_->tab_strip_model()->GetActiveWebContents();
[email protected]1c5119c2012-09-19 00:08:571031 if (!current_web_contents) // May be NULL during tab restore.
[email protected]5d98294912012-06-27 22:57:401032 return;
[email protected]5d98294912012-06-27 22:57:401033
1034 // Navigation commands
1035 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_));
1036 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_));
1037 command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_));
toyoshim7dad4b1182016-04-01 14:28:051038 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE,
[email protected]5d98294912012-06-27 22:57:401039 CanReload(browser_));
[email protected]58e29032012-08-06 20:19:571040 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE,
1041 CanReload(browser_));
[email protected]5d98294912012-06-27 22:57:401042
1043 // Window management commands
Aran Gilmand217b5b2019-04-11 17:45:431044 command_updater_.UpdateCommandEnabled(
1045 IDC_DUPLICATE_TAB, !browser_->is_app() && CanDuplicateTab(browser_));
Tommy Steimelc4477982017-11-29 18:07:181046 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE,
ellyjones0101ba02017-05-19 15:50:261047 !browser_->is_app());
1048 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB,
1049 !browser_->is_app());
[email protected]5d98294912012-06-27 22:57:401050
1051 // Page-related commands
1052 window()->SetStarredState(
[email protected]1c5119c2012-09-19 00:08:571053 BookmarkTabHelper::FromWebContents(current_web_contents)->is_starred());
[email protected]5423c372012-08-22 05:50:161054 window()->ZoomChangedForActiveTab(false);
[email protected]5d98294912012-06-27 22:57:401055 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
1056 CanViewSource(browser_));
1057 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION,
1058 CanEmailPageLocation(browser_));
1059 if (browser_->is_devtools())
1060 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false);
1061
Alan Cutter81ac726682018-09-25 00:18:361062 bool can_create_bookmark_app = CanCreateBookmarkApp(browser_);
1063 command_updater_.UpdateCommandEnabled(IDC_INSTALL_PWA,
1064 can_create_bookmark_app);
1065 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUT,
1066 can_create_bookmark_app);
Alan Cutter403cebb2018-05-17 05:22:451067 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW,
Alan Cutter81ac726682018-09-25 00:18:361068 can_create_bookmark_app);
[email protected]5d98294912012-06-27 22:57:401069
[email protected]9b7ab882012-09-10 23:46:361070 command_updater_.UpdateCommandEnabled(
1071 IDC_TOGGLE_REQUEST_TABLET_SITE,
1072 CanRequestTabletSite(current_web_contents));
1073
[email protected]5d98294912012-06-27 22:57:401074 UpdateCommandsForContentRestrictionState();
1075 UpdateCommandsForBookmarkEditing();
[email protected]3cac87232012-11-20 01:48:271076 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:411077 UpdateCommandsForMediaRouter();
[email protected]d93dbd12014-08-04 23:42:531078 // Update the zoom commands when an active tab is selected.
1079 UpdateCommandsForZoomState();
1080}
1081
1082void BrowserCommandController::UpdateCommandsForZoomState() {
Aran Gilmand217b5b2019-04-11 17:45:431083 WebContents* contents = browser_->tab_strip_model()->GetActiveWebContents();
[email protected]d93dbd12014-08-04 23:42:531084 if (!contents)
1085 return;
Aran Gilmand217b5b2019-04-11 17:45:431086 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, CanZoomIn(contents));
a.sarkar.arundaadc712015-02-26 05:39:081087 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL,
ccameronb7c1d6c2015-03-09 17:08:241088 CanResetZoom(contents));
Aran Gilmand217b5b2019-04-11 17:45:431089 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, CanZoomOut(contents));
[email protected]5d98294912012-06-27 22:57:401090}
1091
1092void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
1093 int restrictions = GetContentRestrictions(browser_);
1094
1095 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011096 IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY));
[email protected]5d98294912012-06-27 22:57:401097 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011098 IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT));
[email protected]5d98294912012-06-27 22:57:401099 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011100 IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE));
[email protected]5d98294912012-06-27 22:57:401101 UpdateSaveAsState();
1102 UpdatePrintingState();
1103}
1104
1105void BrowserCommandController::UpdateCommandsForDevTools() {
Ivan Sandrk9669d0e2017-12-15 23:50:201106 if (is_locked_fullscreen_)
1107 return;
1108
Pavol Marko56df0272018-07-04 17:55:041109 bool dev_tools_enabled = DevToolsWindow::AllowDevToolsFor(
1110 profile(), browser_->tab_strip_model()->GetActiveWebContents());
Aran Gilmand217b5b2019-04-11 17:45:431111 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS, dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401112 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE,
1113 dev_tools_enabled);
[email protected]2056c3192013-10-21 22:40:511114 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES,
1115 dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401116 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT,
1117 dev_tools_enabled);
[email protected]d16657c2012-09-03 14:25:101118 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE,
1119 dev_tools_enabled);
spqchan2c5d541e2017-10-25 07:07:111120#if defined(OS_MACOSX)
1121 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS,
1122 dev_tools_enabled);
1123#endif
[email protected]5d98294912012-06-27 22:57:401124}
1125
1126void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
Ivan Sandrk9669d0e2017-12-15 23:50:201127 if (is_locked_fullscreen_)
1128 return;
1129
[email protected]5d98294912012-06-27 22:57:401130 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE,
1131 CanBookmarkCurrentPage(browser_));
1132 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
1133 CanBookmarkAllTabs(browser_));
thestig5149d272014-10-30 07:25:291134#if defined(OS_WIN)
1135 command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN, true);
1136#endif
[email protected]5d98294912012-06-27 22:57:401137}
1138
1139void BrowserCommandController::UpdateCommandsForBookmarkBar() {
Ivan Sandrk9669d0e2017-12-15 23:50:201140 if (is_locked_fullscreen_)
1141 return;
1142
tfarina3bddbe112014-08-28 05:29:321143 command_updater_.UpdateCommandEnabled(
Aran Gilmand217b5b2019-04-11 17:45:431144 IDC_SHOW_BOOKMARK_BAR, browser_defaults::bookmarks_enabled &&
1145 !profile()->IsGuestSession() &&
1146 !profile()->IsSystemProfile() &&
1147 !profile()->GetPrefs()->IsManagedPreference(
1148 bookmarks::prefs::kShowBookmarkBar) &&
1149 IsShowingMainUI());
[email protected]5d98294912012-06-27 22:57:401150}
1151
[email protected]9ec3ea5b2012-12-03 18:14:301152void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
Ivan Sandrk9669d0e2017-12-15 23:50:201153 if (is_locked_fullscreen_)
1154 return;
1155
[email protected]9ec3ea5b2012-12-03 18:14:301156 UpdateSaveAsState();
[email protected]05454532013-01-22 21:09:081157 UpdateOpenFileState(&command_updater_);
[email protected]9ec3ea5b2012-12-03 18:14:301158}
1159
[email protected]32dfede2013-08-25 15:48:251160void BrowserCommandController::UpdateCommandsForFullscreenMode() {
Ivan Sandrk9669d0e2017-12-15 23:50:201161 if (is_locked_fullscreen_)
1162 return;
1163
zijiehe3c7af992017-02-12 20:59:401164 const bool is_fullscreen = window() && window()->IsFullscreen();
1165 const bool show_main_ui = IsShowingMainUI();
manukf1a116392018-10-25 16:28:241166 const bool show_location_bar = IsShowingLocationBar();
1167
zijiehe3c7af992017-02-12 20:59:401168 const bool main_not_fullscreen = show_main_ui && !is_fullscreen;
[email protected]5d98294912012-06-27 22:57:401169
1170 // Navigation commands
1171 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1172
1173 // Window management commands
1174 command_updater_.UpdateCommandEnabled(
Aran Gilmand217b5b2019-04-11 17:45:431175 IDC_SHOW_AS_TAB, !browser_->is_type_tabbed() && !is_fullscreen);
[email protected]5d98294912012-06-27 22:57:401176
1177 // Focus various bits of UI
1178 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
manukf1a116392018-10-25 16:28:241179 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_location_bar);
[email protected]5d98294912012-06-27 22:57:401180 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
Aran Gilmand217b5b2019-04-11 17:45:431181 command_updater_.UpdateCommandEnabled(IDC_FOCUS_MENU_BAR,
1182 main_not_fullscreen);
1183 command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE,
1184 main_not_fullscreen);
1185 command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE,
1186 main_not_fullscreen);
1187 command_updater_.UpdateCommandEnabled(IDC_FOCUS_BOOKMARKS,
1188 main_not_fullscreen);
[email protected]822ca8c62013-04-19 00:49:151189 command_updater_.UpdateCommandEnabled(
David Tsengc0b1b642018-01-24 07:12:271190 IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY, main_not_fullscreen);
[email protected]5d98294912012-06-27 22:57:401191
1192 // Show various bits of UI
1193 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431194#if defined(GOOGLE_CHROME_BUILD)
Fabio Rocha19bf4262019-04-04 01:05:181195 command_updater_.UpdateCommandEnabled(
1196 IDC_FEEDBACK, show_main_ui || browser_->is_devtools());
[email protected]236ad3022013-09-04 03:27:431197#endif
Mihai Sardarescu2ec5205682018-09-26 09:20:051198 UpdateShowSyncState(show_main_ui);
[email protected]5d98294912012-06-27 22:57:401199
[email protected]5d98294912012-06-27 22:57:401200 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
1201 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
1202 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
1203 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
Tina Wangf09681ac2019-03-27 20:52:101204 command_updater_.UpdateCommandEnabled(IDC_SEND_TAB_TO_SELF, show_main_ui);
Yann Dago70ca3dd2019-02-27 01:12:351205 command_updater_.UpdateCommandEnabled(IDC_SHOW_MANAGEMENT_PAGE, true);
primianod3a81ab2016-01-25 22:21:151206
1207 if (base::debug::IsProfilingSupported())
1208 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
[email protected]5d98294912012-06-27 22:57:401209
[email protected]aeafc3852014-04-29 16:51:291210#if !defined(OS_MACOSX)
zijiehe3c7af992017-02-12 20:59:401211 // Disable toggling into fullscreen mode if disallowed by pref.
Aran Gilmand217b5b2019-04-11 17:45:431212 const bool fullscreen_enabled =
1213 is_fullscreen ||
zijiehe3c7af992017-02-12 20:59:401214 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed);
1215#else
1216 const bool fullscreen_enabled = true;
[email protected]00a1cc5b2012-11-07 13:44:511217#endif
1218
1219 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled);
spqchanb8ffc7d2015-11-17 01:17:211220 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR,
1221 fullscreen_enabled);
[email protected]5d98294912012-06-27 22:57:401222
1223 UpdateCommandsForBookmarkBar();
zijiehedb473d552017-02-24 01:13:411224 UpdateCommandsForIncognitoAvailability();
Alan Cutter167dfe82018-04-11 09:06:001225 UpdateCommandsForHostedAppAvailability();
1226}
1227
1228void BrowserCommandController::UpdateCommandsForHostedAppAvailability() {
1229 bool has_toolbar =
1230 browser_->is_type_tabbed() ||
Yining Wang234ad3272019-04-08 18:47:271231 WebAppBrowserController::IsForExperimentalHostedAppBrowser(browser_);
Alan Cutter167dfe82018-04-11 09:06:001232 if (window() && window()->ShouldHideUIForFullscreen())
1233 has_toolbar = false;
1234 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, has_toolbar);
1235 command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE, has_toolbar);
1236 command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE, has_toolbar);
1237 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, has_toolbar);
[email protected]5d98294912012-06-27 22:57:401238}
1239
Ivan Sandrk9669d0e2017-12-15 23:50:201240#if defined(OS_CHROMEOS)
1241namespace {
1242
1243#if DCHECK_IS_ON()
1244// Makes sure that all commands that are not whitelisted are disabled. DCHECKs
1245// otherwise. Compiled only in debug mode.
1246void NonWhitelistedCommandsAreDisabled(CommandUpdaterImpl* command_updater) {
Ivan Sandrk6ac9c9a2018-12-14 14:15:071247 constexpr int kWhitelistedIds[] = {IDC_CUT, IDC_COPY, IDC_PASTE};
Ivan Sandrk9669d0e2017-12-15 23:50:201248
1249 // Go through all the command ids, skip the whitelisted ones.
1250 for (int id : command_updater->GetAllIds()) {
Haeun Kim3f6123502018-08-26 18:03:041251 if (base::ContainsValue(kWhitelistedIds, id)) {
Ivan Sandrk9669d0e2017-12-15 23:50:201252 continue;
1253 }
1254 DCHECK(!command_updater->IsCommandEnabled(id));
1255 }
1256}
1257#endif
1258
1259} // namespace
1260
1261void BrowserCommandController::UpdateCommandsForLockedFullscreenMode() {
Ivan Sandrke0e92452019-03-21 09:32:481262 bool is_locked_fullscreen =
1263 platform_util::IsBrowserLockedFullscreen(browser_);
Ivan Sandrk9669d0e2017-12-15 23:50:201264 // Sanity check to make sure this function is called only on state change.
1265 DCHECK_NE(is_locked_fullscreen, is_locked_fullscreen_);
1266 if (is_locked_fullscreen == is_locked_fullscreen_)
1267 return;
1268 is_locked_fullscreen_ = is_locked_fullscreen;
1269
1270 if (is_locked_fullscreen_) {
1271 command_updater_.DisableAllCommands();
1272 // Update the state of whitelisted commands:
1273 // IDC_CUT/IDC_COPY/IDC_PASTE,
1274 UpdateCommandsForContentRestrictionState();
Ivan Sandrk6ac9c9a2018-12-14 14:15:071275 // TODO(crbug.com/904637): Re-enable Find and Zoom in locked fullscreen.
Ivan Sandrk9669d0e2017-12-15 23:50:201276 // All other commands will be disabled (there is an early return in their
1277 // corresponding UpdateCommandsFor* functions).
1278#if DCHECK_IS_ON()
1279 NonWhitelistedCommandsAreDisabled(&command_updater_);
1280#endif
1281 } else {
1282 // Do an init call to re-initialize command state after the
1283 // DisableAllCommands.
1284 InitCommandState();
1285 }
1286}
1287#endif
1288
[email protected]5d98294912012-06-27 22:57:401289void BrowserCommandController::UpdatePrintingState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201290 if (is_locked_fullscreen_)
1291 return;
1292
[email protected]d53e4032012-06-29 18:58:341293 bool print_enabled = CanPrint(browser_);
1294 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
Lei Zhang48a4a5262018-04-17 20:18:441295#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:551296 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT,
1297 CanBasicPrint(browser_));
Lei Zhang48a4a5262018-04-17 20:18:441298#endif
[email protected]5d98294912012-06-27 22:57:401299}
1300
1301void BrowserCommandController::UpdateSaveAsState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201302 if (is_locked_fullscreen_)
1303 return;
1304
[email protected]5d98294912012-06-27 22:57:401305 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_));
1306}
1307
Mihai Sardarescu2ec5205682018-09-26 09:20:051308void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) {
1309 if (is_locked_fullscreen_)
1310 return;
1311
Mihai Sardarescuf87ccc12018-09-26 10:37:451312 command_updater_.UpdateCommandEnabled(
Mihai Sardarescu290bc882018-10-12 10:48:141313 IDC_SHOW_SIGNIN, show_main_ui && pref_signin_allowed_.GetValue());
Mihai Sardarescu2ec5205682018-09-26 09:20:051314}
1315
[email protected]05454532013-01-22 21:09:081316// static
1317void BrowserCommandController::UpdateOpenFileState(
1318 CommandUpdater* command_updater) {
[email protected]5d98294912012-06-27 22:57:401319 bool enabled = true;
1320 PrefService* local_state = g_browser_process->local_state();
1321 if (local_state)
1322 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs);
1323
[email protected]05454532013-01-22 21:09:081324 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled);
[email protected]5d98294912012-06-27 22:57:401325}
1326
1327void BrowserCommandController::UpdateReloadStopState(bool is_loading,
1328 bool force) {
Ivan Sandrk9669d0e2017-12-15 23:50:201329 if (is_locked_fullscreen_)
1330 return;
1331
[email protected]5d98294912012-06-27 22:57:401332 window()->UpdateReloadStopState(is_loading, force);
1333 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
1334}
1335
[email protected]2e9369e2014-08-15 09:12:531336void BrowserCommandController::UpdateTabRestoreCommandState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201337 if (is_locked_fullscreen_)
1338 return;
1339
blundell74001adc2015-09-18 11:04:251340 sessions::TabRestoreService* tab_restore_service =
[email protected]2e9369e2014-08-15 09:12:531341 TabRestoreServiceFactory::GetForProfile(profile());
1342 // The command is enabled if the service hasn't loaded yet to trigger loading.
1343 // The command is updated once the load completes.
1344 command_updater_.UpdateCommandEnabled(
1345 IDC_RESTORE_TAB,
1346 tab_restore_service &&
Aran Gilmand217b5b2019-04-11 17:45:431347 (!tab_restore_service->IsLoaded() ||
1348 GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE));
[email protected]2e9369e2014-08-15 09:12:531349}
1350
[email protected]3cac87232012-11-20 01:48:271351void BrowserCommandController::UpdateCommandsForFind() {
1352 TabStripModel* model = browser_->tab_strip_model();
Aran Gilmand217b5b2019-04-11 17:45:431353 bool enabled =
1354 !model->IsTabBlocked(model->active_index()) && !browser_->is_devtools();
[email protected]3cac87232012-11-20 01:48:271355
1356 command_updater_.UpdateCommandEnabled(IDC_FIND, enabled);
1357 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled);
1358 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled);
1359}
1360
apacible45cbfc92015-09-28 22:45:411361void BrowserCommandController::UpdateCommandsForMediaRouter() {
Ivan Sandrk9669d0e2017-12-15 23:50:201362 if (is_locked_fullscreen_)
1363 return;
1364
apacible45cbfc92015-09-28 22:45:411365 command_updater_.UpdateCommandEnabled(IDC_ROUTE_MEDIA,
1366 CanRouteMedia(browser_));
1367}
1368
[email protected]409ea2972012-11-10 19:54:431369void BrowserCommandController::AddInterstitialObservers(WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071370 interstitial_observers_.push_back(new InterstitialObserver(this, contents));
[email protected]5d98294912012-06-27 22:57:401371}
1372
1373void BrowserCommandController::RemoveInterstitialObservers(
[email protected]e89cfcb2012-11-11 14:47:241374 WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071375 for (size_t i = 0; i < interstitial_observers_.size(); i++) {
1376 if (interstitial_observers_[i]->web_contents() != contents)
1377 continue;
1378
1379 delete interstitial_observers_[i];
1380 interstitial_observers_.erase(interstitial_observers_.begin() + i);
1381 return;
1382 }
[email protected]5d98294912012-06-27 22:57:401383}
1384
1385BrowserWindow* BrowserCommandController::window() {
1386 return browser_->window();
1387}
1388
1389Profile* BrowserCommandController::profile() {
1390 return browser_->profile();
1391}
1392
[email protected]5d98294912012-06-27 22:57:401393} // namespace chrome