blob: 97d859398dfab6b84c83c3a4961923d40e07d87b [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"
benwells39f23ae2014-08-27 08:01:5226#include "chrome/browser/extensions/extension_util.h"
[email protected]2e9d79f2013-08-16 05:45:5627#include "chrome/browser/lifetime/application_lifetime.h"
[email protected]5d98294912012-06-27 22:57:4028#include "chrome/browser/prefs/incognito_mode_prefs.h"
[email protected]5d98294912012-06-27 22:57:4029#include "chrome/browser/profiles/profile.h"
mlermane01e6de2014-09-29 19:26:4730#include "chrome/browser/profiles/profile_manager.h"
[email protected]5d98294912012-06-27 22:57:4031#include "chrome/browser/sessions/tab_restore_service_factory.h"
[email protected]0b32f9b62012-09-17 19:08:0332#include "chrome/browser/shell_integration.h"
[email protected]3d27d272013-07-31 03:15:1633#include "chrome/browser/signin/signin_promo.h"
[email protected]5d98294912012-06-27 22:57:4034#include "chrome/browser/sync/profile_sync_service_factory.h"
Christopher Lam86b52712017-12-04 01:58:3335#include "chrome/browser/ui/apps/app_info_dialog.h"
[email protected]5d98294912012-06-27 22:57:4036#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
37#include "chrome/browser/ui/browser.h"
38#include "chrome/browser/ui/browser_commands.h"
39#include "chrome/browser/ui/browser_window.h"
40#include "chrome/browser/ui/chrome_pages.h"
Alan Cutter09965802018-03-27 07:25:2941#include "chrome/browser/ui/extensions/application_launch.h"
Christopher Lam0dbac2b2017-11-14 07:12:1042#include "chrome/browser/ui/extensions/hosted_app_browser_controller.h"
Alan Cutter0c3132302018-02-21 05:09:0243#include "chrome/browser/ui/page_info/page_info_dialog.h"
Nicolas Ouellet-payeur82eb65b2018-11-05 16:49:2744#include "chrome/browser/ui/singleton_tabs.h"
[email protected]5d98294912012-06-27 22:57:4045#include "chrome/browser/ui/tabs/tab_strip_model.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 Sandrk9669d0e2017-12-15 23:50:2080#include "ash/public/cpp/window_pin_type.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::NavigationEntry;
101using content::NavigationController;
102using 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)
[email protected]5d98294912012-06-27 22:57:40110 : browser_(browser),
Ivan Sandrk9669d0e2017-12-15 23:50:20111 command_updater_(nullptr) {
[email protected]5d98294912012-06-27 22:57:40112 browser_->tab_strip_model()->AddObserver(this);
113 PrefService* local_state = g_browser_process->local_state();
114 if (local_state) {
115 local_pref_registrar_.Init(local_state);
[email protected]9ec3ea5b2012-12-03 18:14:30116 local_pref_registrar_.Add(
117 prefs::kAllowFileSelectionDialogs,
118 base::Bind(
119 &BrowserCommandController::UpdateCommandsForFileSelectionDialogs,
120 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40121 }
122
123 profile_pref_registrar_.Init(profile()->GetPrefs());
[email protected]9ec3ea5b2012-12-03 18:14:30124 profile_pref_registrar_.Add(
Pavol Markodebb0ff2018-05-07 18:35:41125 prefs::kDevToolsAvailability,
[email protected]9ec3ea5b2012-12-03 18:14:30126 base::Bind(&BrowserCommandController::UpdateCommandsForDevTools,
127 base::Unretained(this)));
128 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32129 bookmarks::prefs::kEditBookmarksEnabled,
[email protected]9ec3ea5b2012-12-03 18:14:30130 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkEditing,
131 base::Unretained(this)));
132 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32133 bookmarks::prefs::kShowBookmarkBar,
[email protected]9ec3ea5b2012-12-03 18:14:30134 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkBar,
135 base::Unretained(this)));
136 profile_pref_registrar_.Add(
137 prefs::kIncognitoModeAvailability,
138 base::Bind(
139 &BrowserCommandController::UpdateCommandsForIncognitoAvailability,
140 base::Unretained(this)));
141 profile_pref_registrar_.Add(
142 prefs::kPrintingEnabled,
143 base::Bind(&BrowserCommandController::UpdatePrintingState,
144 base::Unretained(this)));
[email protected]32dfede2013-08-25 15:48:25145#if !defined(OS_MACOSX)
146 profile_pref_registrar_.Add(
147 prefs::kFullscreenAllowed,
148 base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode,
149 base::Unretained(this)));
150#endif
Mihai Sardarescuf87ccc12018-09-26 10:37:45151 pref_signin_allowed_.Init(
152 prefs::kSigninAllowed,
153 profile()->GetOriginalProfile()->GetPrefs(),
154 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange,
155 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40156
157 InitCommandState();
158
blundell74001adc2015-09-18 11:04:25159 sessions::TabRestoreService* tab_restore_service =
[email protected]5d98294912012-06-27 22:57:40160 TabRestoreServiceFactory::GetForProfile(profile());
161 if (tab_restore_service) {
162 tab_restore_service->AddObserver(this);
Cliff Smolinsky2c9586e2019-02-08 18:48:30163 if (!tab_restore_service->IsLoaded())
164 tab_restore_service->LoadTabsFromLastSession();
[email protected]5d98294912012-06-27 22:57:40165 }
[email protected]5d98294912012-06-27 22:57:40166}
167
168BrowserCommandController::~BrowserCommandController() {
[email protected]95e39472012-10-05 23:37:36169 // TabRestoreService may have been shutdown by the time we get here. Don't
170 // trigger creating it.
blundell74001adc2015-09-18 11:04:25171 sessions::TabRestoreService* tab_restore_service =
[email protected]95e39472012-10-05 23:37:36172 TabRestoreServiceFactory::GetForProfileIfExisting(profile());
[email protected]5d98294912012-06-27 22:57:40173 if (tab_restore_service)
174 tab_restore_service->RemoveObserver(this);
175 profile_pref_registrar_.RemoveAll();
176 local_pref_registrar_.RemoveAll();
177 browser_->tab_strip_model()->RemoveObserver(this);
178}
179
180bool BrowserCommandController::IsReservedCommandOrKey(
181 int command_id,
182 const content::NativeWebKeyboardEvent& event) {
183 // In Apps mode, no keys are reserved.
184 if (browser_->is_app())
185 return false;
186
187#if defined(OS_CHROMEOS)
[email protected]397abd32013-08-21 05:44:19188 // On Chrome OS, the top row of keys are mapped to browser actions like
189 // back/forward or refresh. We don't want web pages to be able to change the
190 // behavior of these keys. Ash handles F4 and up; this leaves us needing to
191 // reserve browser back/forward and refresh here.
[email protected]5d98294912012-06-27 22:57:40192 ui::KeyboardCode key_code =
Blink Reformat1c4d759e2017-04-09 16:34:54193 static_cast<ui::KeyboardCode>(event.windows_key_code);
[email protected]397abd32013-08-21 05:44:19194 if ((key_code == ui::VKEY_BROWSER_BACK && command_id == IDC_BACK) ||
195 (key_code == ui::VKEY_BROWSER_FORWARD && command_id == IDC_FORWARD) ||
196 (key_code == ui::VKEY_BROWSER_REFRESH && command_id == IDC_RELOAD)) {
[email protected]5d98294912012-06-27 22:57:40197 return true;
198 }
199#endif
200
zijiehe68cd3dc22017-04-07 18:50:29201 if (window()->IsFullscreen()) {
202 // In fullscreen, all commands except for IDC_FULLSCREEN and IDC_EXIT should
203 // be delivered to the web page. The intent to implement and ship can be
204 // found in http://crbug.com/680809.
205 const bool is_exit_fullscreen =
206 (command_id == IDC_EXIT || command_id == IDC_FULLSCREEN);
207#if defined(OS_MACOSX)
208 // This behavior is different on Mac OS, which has a unique user-initiated
209 // full-screen mode. According to the discussion in http://crbug.com/702251,
210 // the commands should be reserved for browser-side handling if the browser
211 // window's toolbar is visible.
212 if (window()->IsToolbarShowing()) {
213 if (command_id == IDC_FULLSCREEN)
214 return true;
215 } else {
216 return is_exit_fullscreen;
217 }
218#else
219 return is_exit_fullscreen;
220#endif
221 }
[email protected]1e2172f2014-04-01 17:32:34222
[email protected]893124a22014-04-15 00:45:28223#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]1e2172f2014-04-01 17:32:34224 // If this key was registered by the user as a content editing hotkey, then
225 // it is not reserved.
[email protected]d5bedb6d2014-04-08 10:49:32226 ui::TextEditKeyBindingsDelegateAuraLinux* delegate =
[email protected]1e2172f2014-04-01 17:32:34227 ui::GetTextEditKeyBindingsDelegate();
[email protected]47e8e7542014-04-03 07:52:42228 if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL))
[email protected]1e2172f2014-04-01 17:32:34229 return false;
230#endif
231
zijiehe13207802017-02-16 08:06:10232 return command_id == IDC_CLOSE_TAB ||
233 command_id == IDC_CLOSE_WINDOW ||
234 command_id == IDC_NEW_INCOGNITO_WINDOW ||
235 command_id == IDC_NEW_TAB ||
236 command_id == IDC_NEW_WINDOW ||
237 command_id == IDC_RESTORE_TAB ||
238 command_id == IDC_SELECT_NEXT_TAB ||
239 command_id == IDC_SELECT_PREVIOUS_TAB ||
240 command_id == IDC_EXIT;
[email protected]5d98294912012-06-27 22:57:40241}
242
[email protected]5d98294912012-06-27 22:57:40243void BrowserCommandController::TabStateChanged() {
244 UpdateCommandsForTabState();
245}
246
[email protected]d93dbd12014-08-04 23:42:53247void BrowserCommandController::ZoomStateChanged() {
248 UpdateCommandsForZoomState();
249}
250
[email protected]5d98294912012-06-27 22:57:40251void BrowserCommandController::ContentRestrictionsChanged() {
252 UpdateCommandsForContentRestrictionState();
253}
254
255void BrowserCommandController::FullscreenStateChanged() {
[email protected]32dfede2013-08-25 15:48:25256 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40257}
258
Ivan Sandrk9669d0e2017-12-15 23:50:20259#if defined(OS_CHROMEOS)
260void BrowserCommandController::LockedFullscreenStateChanged() {
261 UpdateCommandsForLockedFullscreenMode();
262}
263#endif
264
[email protected]5d98294912012-06-27 22:57:40265void BrowserCommandController::PrintingStateChanged() {
266 UpdatePrintingState();
267}
268
269void BrowserCommandController::LoadingStateChanged(bool is_loading,
270 bool force) {
271 UpdateReloadStopState(is_loading, force);
272}
273
wittman76df71db32014-12-18 23:26:58274void BrowserCommandController::ExtensionStateChanged() {
275 // Extensions may disable the bookmark editing commands.
276 UpdateCommandsForBookmarkEditing();
277}
278
[email protected]5d98294912012-06-27 22:57:40279////////////////////////////////////////////////////////////////////////////////
Ivan Sandrk9669d0e2017-12-15 23:50:20280// BrowserCommandController, CommandUpdater implementation:
[email protected]5d98294912012-06-27 22:57:40281
Ivan Sandrk9669d0e2017-12-15 23:50:20282bool BrowserCommandController::SupportsCommand(int id) const {
283 return command_updater_.SupportsCommand(id);
284}
285
286bool BrowserCommandController::IsCommandEnabled(int id) const {
287 return command_updater_.IsCommandEnabled(id);
288}
289
Edwin Joe6f6fc1e2019-02-27 20:00:37290bool BrowserCommandController::ExecuteCommand(int id,
291 base::TimeTicks time_stamp) {
292 return ExecuteCommandWithDisposition(id, WindowOpenDisposition::CURRENT_TAB,
293 time_stamp);
Ivan Sandrk9669d0e2017-12-15 23:50:20294}
295
296bool BrowserCommandController::ExecuteCommandWithDisposition(
Edwin Joe6f6fc1e2019-02-27 20:00:37297 int id,
298 WindowOpenDisposition disposition,
299 base::TimeTicks time_stamp) {
Ivan Sandrk9669d0e2017-12-15 23:50:20300 // Doesn't go through the command_updater_ to avoid dealing with having a
301 // naming collision for ExecuteCommandWithDisposition (both
302 // CommandUpdaterDelegate and CommandUpdater declare this function so we
303 // choose to not implement CommandUpdaterDelegate inside this class and
304 // therefore command_updater_ doesn't have the delegate set).
305 if (!SupportsCommand(id) || !IsCommandEnabled(id))
306 return false;
307
[email protected]5d98294912012-06-27 22:57:40308 // No commands are enabled if there is not yet any selected tab.
309 // TODO(pkasting): It seems like we should not need this, because either
310 // most/all commands should not have been enabled yet anyway or the ones that
311 // are enabled should be global, or safe themselves against having no selected
312 // tab. However, Ben says he tried removing this before and got lots of
313 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
314 // window construction. This probably could use closer examination someday.
[email protected]59253a652012-11-20 00:17:26315 if (browser_->tab_strip_model()->active_index() == TabStripModel::kNoTab)
Ivan Sandrk9669d0e2017-12-15 23:50:20316 return true;
[email protected]5d98294912012-06-27 22:57:40317
318 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command "
319 << id;
320
[email protected]5d98294912012-06-27 22:57:40321 // The order of commands in this switch statement must match the function
322 // declaration order in browser.h!
323 switch (id) {
324 // Navigation commands
325 case IDC_BACK:
326 GoBack(browser_, disposition);
327 break;
328 case IDC_FORWARD:
329 GoForward(browser_, disposition);
330 break;
331 case IDC_RELOAD:
332 Reload(browser_, disposition);
333 break;
[email protected]58e29032012-08-06 20:19:57334 case IDC_RELOAD_CLEARING_CACHE:
335 ClearCache(browser_);
Nico Webera745ef72018-01-29 23:45:57336 FALLTHROUGH;
toyoshim7dad4b1182016-04-01 14:28:05337 case IDC_RELOAD_BYPASSING_CACHE:
338 ReloadBypassingCache(browser_, disposition);
[email protected]5d98294912012-06-27 22:57:40339 break;
340 case IDC_HOME:
341 Home(browser_, disposition);
342 break;
343 case IDC_OPEN_CURRENT_URL:
344 OpenCurrentURL(browser_);
345 break;
346 case IDC_STOP:
347 Stop(browser_);
348 break;
349
350 // Window management commands
351 case IDC_NEW_WINDOW:
352 NewWindow(browser_);
353 break;
354 case IDC_NEW_INCOGNITO_WINDOW:
Orin Jaworski5e4bcd0c2018-10-16 19:35:05355 NewIncognitoWindow(profile());
[email protected]5d98294912012-06-27 22:57:40356 break;
357 case IDC_CLOSE_WINDOW:
bratell0a7406f2017-03-28 07:46:37358 base::RecordAction(base::UserMetricsAction("CloseWindowByKey"));
[email protected]04b9e692012-08-24 14:49:09359 CloseWindow(browser_);
[email protected]5d98294912012-06-27 22:57:40360 break;
Bettina Dea0a4505922017-09-28 00:53:32361 case IDC_NEW_TAB: {
362 NewTab(browser_);
363#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Catherine Chungbeb884222017-08-01 15:47:55364 // This is not in NewTab() to avoid tracking programmatic creation of new
365 // tabs by extensions.
Bettina Dea0a4505922017-09-28 00:53:32366 auto* new_tab_tracker =
367 feature_engagement::NewTabTrackerFactory::GetInstance()
368 ->GetForProfile(profile());
369
370 new_tab_tracker->OnNewTabOpened();
371 new_tab_tracker->CloseBubble();
Catherine Chungbeb884222017-08-01 15:47:55372#endif
[email protected]5d98294912012-06-27 22:57:40373 break;
Bettina Dea0a4505922017-09-28 00:53:32374 }
[email protected]5d98294912012-06-27 22:57:40375 case IDC_CLOSE_TAB:
bratell0a7406f2017-03-28 07:46:37376 base::RecordAction(base::UserMetricsAction("CloseTabByKey"));
[email protected]04b9e692012-08-24 14:49:09377 CloseTab(browser_);
[email protected]5d98294912012-06-27 22:57:40378 break;
379 case IDC_SELECT_NEXT_TAB:
bratell0a7406f2017-03-28 07:46:37380 base::RecordAction(base::UserMetricsAction("Accel_SelectNextTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37381 SelectNextTab(browser_,
382 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40383 break;
384 case IDC_SELECT_PREVIOUS_TAB:
bratell0a7406f2017-03-28 07:46:37385 base::RecordAction(base::UserMetricsAction("Accel_SelectPreviousTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37386 SelectPreviousTab(browser_,
387 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40388 break;
[email protected]5d98294912012-06-27 22:57:40389 case IDC_MOVE_TAB_NEXT:
390 MoveTabNext(browser_);
391 break;
392 case IDC_MOVE_TAB_PREVIOUS:
393 MoveTabPrevious(browser_);
394 break;
395 case IDC_SELECT_TAB_0:
396 case IDC_SELECT_TAB_1:
397 case IDC_SELECT_TAB_2:
398 case IDC_SELECT_TAB_3:
399 case IDC_SELECT_TAB_4:
400 case IDC_SELECT_TAB_5:
401 case IDC_SELECT_TAB_6:
402 case IDC_SELECT_TAB_7:
bratell0a7406f2017-03-28 07:46:37403 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37404 SelectNumberedTab(browser_, id - IDC_SELECT_TAB_0,
405 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40406 break;
407 case IDC_SELECT_LAST_TAB:
bratell0a7406f2017-03-28 07:46:37408 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37409 SelectLastTab(browser_,
410 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40411 break;
412 case IDC_DUPLICATE_TAB:
413 DuplicateTab(browser_);
414 break;
415 case IDC_RESTORE_TAB:
416 RestoreTab(browser_);
Collin Baker9bbe1d82019-03-08 01:16:27417 browser_->window()->OnTabRestored(IDC_RESTORE_TAB);
[email protected]5d98294912012-06-27 22:57:40418 break;
[email protected]5d98294912012-06-27 22:57:40419 case IDC_SHOW_AS_TAB:
420 ConvertPopupToTabbedBrowser(browser_);
421 break;
422 case IDC_FULLSCREEN:
[email protected]3f32b9b2012-07-09 16:59:28423 chrome::ToggleFullscreenMode(browser_);
[email protected]5d98294912012-06-27 22:57:40424 break;
Alan Cutter09965802018-03-27 07:25:29425 case IDC_OPEN_IN_PWA_WINDOW:
426 base::RecordAction(base::UserMetricsAction("OpenActiveTabInPwaWindow"));
427 ReparentSecureActiveTabIntoPwaWindow(browser_);
428 break;
[email protected]770c6d82012-09-06 22:21:32429
[email protected]d12cc5e2013-10-19 18:25:06430#if defined(OS_CHROMEOS)
431 case IDC_VISIT_DESKTOP_OF_LRU_USER_2:
[email protected]0c930812014-01-30 18:01:47432 case IDC_VISIT_DESKTOP_OF_LRU_USER_3:
zijiehe4dde8072017-02-13 20:38:35433 ExecuteVisitDesktopCommand(id, window()->GetNativeWindow());
[email protected]0c930812014-01-30 18:01:47434 break;
[email protected]d12cc5e2013-10-19 18:25:06435#endif
436
[email protected]893124a22014-04-15 00:45:28437#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15438 case IDC_MINIMIZE_WINDOW:
439 browser_->window()->Minimize();
440 break;
441 case IDC_MAXIMIZE_WINDOW:
442 browser_->window()->Maximize();
443 break;
444 case IDC_RESTORE_WINDOW:
445 browser_->window()->Restore();
446 break;
[email protected]af97be4c62014-02-13 14:43:34447 case IDC_USE_SYSTEM_TITLE_BAR: {
zijiehe4dde8072017-02-13 20:38:35448 PrefService* prefs = profile()->GetPrefs();
[email protected]af97be4c62014-02-13 14:43:34449 prefs->SetBoolean(prefs::kUseCustomChromeFrame,
450 !prefs->GetBoolean(prefs::kUseCustomChromeFrame));
451 break;
452 }
453#endif
454
[email protected]5d98294912012-06-27 22:57:40455#if defined(OS_MACOSX)
spqchanb8ffc7d2015-11-17 01:17:21456 case IDC_TOGGLE_FULLSCREEN_TOOLBAR:
457 chrome::ToggleFullscreenToolbar(browser_);
458 break;
spqchan2c5d541e2017-10-25 07:07:11459 case IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS: {
Robert Sesek03282612018-10-31 15:48:06460 chrome::ToggleJavaScriptFromAppleEventsAllowed(browser_);
spqchan2c5d541e2017-10-25 07:07:11461 break;
462 }
[email protected]5d98294912012-06-27 22:57:40463#endif
464 case IDC_EXIT:
465 Exit();
466 break;
467
468 // Page-related commands
469 case IDC_SAVE_PAGE:
470 SavePage(browser_);
471 break;
472 case IDC_BOOKMARK_PAGE:
Anatoly Pilikovee720922017-11-01 09:43:17473#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:14474 feature_engagement::BookmarkTrackerFactory::GetInstance()
475 ->GetForProfile(profile())
476 ->OnBookmarkAdded();
477#endif
deepak.m154a7f392014-12-15 04:41:43478 BookmarkCurrentPageAllowingExtensionOverrides(browser_);
[email protected]5d98294912012-06-27 22:57:40479 break;
[email protected]5d98294912012-06-27 22:57:40480 case IDC_BOOKMARK_ALL_TABS:
Anatoly Pilikovee720922017-11-01 09:43:17481#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:14482 feature_engagement::BookmarkTrackerFactory::GetInstance()
483 ->GetForProfile(profile())
484 ->OnBookmarkAdded();
485#endif
[email protected]5d98294912012-06-27 22:57:40486 BookmarkAllTabs(browser_);
487 break;
488 case IDC_VIEW_SOURCE:
Lukasz Anforowicze1b954d92017-10-30 21:28:06489 browser_->tab_strip_model()
490 ->GetActiveWebContents()
491 ->GetMainFrame()
492 ->ViewSource();
[email protected]5d98294912012-06-27 22:57:40493 break;
494 case IDC_EMAIL_PAGE_LOCATION:
495 EmailPageLocation(browser_);
496 break;
497 case IDC_PRINT:
498 Print(browser_);
499 break;
bondd052b5f82015-10-28 22:39:32500
Lei Zhang48a4a5262018-04-17 20:18:44501#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:55502 case IDC_BASIC_PRINT:
bratell0a7406f2017-03-28 07:46:37503 base::RecordAction(base::UserMetricsAction("Accel_Advanced_Print"));
vitalybukaf9433e42014-09-08 10:04:55504 BasicPrint(browser_);
[email protected]5d98294912012-06-27 22:57:40505 break;
Lei Zhang48a4a5262018-04-17 20:18:44506#endif // ENABLE_PRINTING
bondd052b5f82015-10-28 22:39:32507
bondd052b5f82015-10-28 22:39:32508 case IDC_SAVE_CREDIT_CARD_FOR_PAGE:
509 SaveCreditCard(browser_);
510 break;
siyua3e599eaa2018-07-13 00:23:06511 case IDC_MIGRATE_LOCAL_CREDIT_CARD_FOR_PAGE:
512 MigrateLocalCards(browser_);
513 break;
[email protected]e625b7602013-10-28 09:24:56514 case IDC_TRANSLATE_PAGE:
515 Translate(browser_);
516 break;
[email protected]4bee4432014-05-05 13:11:41517 case IDC_MANAGE_PASSWORDS_FOR_PAGE:
518 ManagePasswordsForPage(browser_);
519 break;
Tina Wang788aac22018-12-21 20:25:46520 case IDC_SEND_TO_MY_DEVICES:
521 SendToMyDevices(browser_);
522 break;
[email protected]4bee4432014-05-05 13:11:41523
[email protected]5d98294912012-06-27 22:57:40524 // Clipboard commands
525 case IDC_CUT:
[email protected]5d98294912012-06-27 22:57:40526 case IDC_COPY:
[email protected]5d98294912012-06-27 22:57:40527 case IDC_PASTE:
pkastingcd3f08bce2015-04-18 13:37:12528 CutCopyPaste(browser_, id);
[email protected]5d98294912012-06-27 22:57:40529 break;
530
531 // Find-in-page
532 case IDC_FIND:
533 Find(browser_);
534 break;
535 case IDC_FIND_NEXT:
536 FindNext(browser_);
537 break;
538 case IDC_FIND_PREVIOUS:
539 FindPrevious(browser_);
540 break;
541
542 // Zoom
543 case IDC_ZOOM_PLUS:
544 Zoom(browser_, content::PAGE_ZOOM_IN);
545 break;
546 case IDC_ZOOM_NORMAL:
547 Zoom(browser_, content::PAGE_ZOOM_RESET);
548 break;
549 case IDC_ZOOM_MINUS:
550 Zoom(browser_, content::PAGE_ZOOM_OUT);
551 break;
552
553 // Focus various bits of UI
554 case IDC_FOCUS_TOOLBAR:
bratell0a7406f2017-03-28 07:46:37555 base::RecordAction(base::UserMetricsAction("Accel_Focus_Toolbar"));
[email protected]5d98294912012-06-27 22:57:40556 FocusToolbar(browser_);
557 break;
558 case IDC_FOCUS_LOCATION:
bratell0a7406f2017-03-28 07:46:37559 base::RecordAction(base::UserMetricsAction("Accel_Focus_Location"));
[email protected]5d98294912012-06-27 22:57:40560 FocusLocationBar(browser_);
561 break;
562 case IDC_FOCUS_SEARCH:
bratell0a7406f2017-03-28 07:46:37563 base::RecordAction(base::UserMetricsAction("Accel_Focus_Search"));
[email protected]5d98294912012-06-27 22:57:40564 FocusSearch(browser_);
565 break;
566 case IDC_FOCUS_MENU_BAR:
567 FocusAppMenu(browser_);
568 break;
569 case IDC_FOCUS_BOOKMARKS:
bratell0a7406f2017-03-28 07:46:37570 base::RecordAction(base::UserMetricsAction("Accel_Focus_Bookmarks"));
[email protected]5d98294912012-06-27 22:57:40571 FocusBookmarksToolbar(browser_);
572 break;
David Tsengc0b1b642018-01-24 07:12:27573 case IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY:
574 FocusInactivePopupForAccessibility(browser_);
[email protected]822ca8c62013-04-19 00:49:15575 break;
[email protected]5d98294912012-06-27 22:57:40576 case IDC_FOCUS_NEXT_PANE:
577 FocusNextPane(browser_);
578 break;
579 case IDC_FOCUS_PREVIOUS_PANE:
580 FocusPreviousPane(browser_);
581 break;
582
583 // Show various bits of UI
584 case IDC_OPEN_FILE:
585 browser_->OpenFile();
586 break;
Alan Cutter81ac726682018-09-25 00:18:36587 case IDC_CREATE_SHORTCUT:
588 CreateBookmarkAppFromCurrentWebContents(browser_,
589 true /* force_shortcut_app */);
590 break;
591 case IDC_INSTALL_PWA:
592 CreateBookmarkAppFromCurrentWebContents(browser_,
593 false /* force_shortcut_app */);
[email protected]488e3952013-11-18 05:29:14594 break;
[email protected]5d98294912012-06-27 22:57:40595 case IDC_DEV_TOOLS:
[email protected]c934c382013-11-01 00:36:01596 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Show());
[email protected]5d98294912012-06-27 22:57:40597 break;
598 case IDC_DEV_TOOLS_CONSOLE:
einbinderdfa567b2016-12-16 01:15:52599 ToggleDevToolsWindow(browser_, DevToolsToggleAction::ShowConsolePanel());
[email protected]5d98294912012-06-27 22:57:40600 break;
[email protected]2056c3192013-10-21 22:40:51601 case IDC_DEV_TOOLS_DEVICES:
602 InspectUI::InspectDevices(browser_);
603 break;
[email protected]5d98294912012-06-27 22:57:40604 case IDC_DEV_TOOLS_INSPECT:
[email protected]c934c382013-11-01 00:36:01605 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Inspect());
[email protected]5d98294912012-06-27 22:57:40606 break;
[email protected]d16657c2012-09-03 14:25:10607 case IDC_DEV_TOOLS_TOGGLE:
[email protected]c934c382013-11-01 00:36:01608 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Toggle());
[email protected]d16657c2012-09-03 14:25:10609 break;
[email protected]5d98294912012-06-27 22:57:40610 case IDC_TASK_MANAGER:
[email protected]29c262de2013-06-22 15:39:38611 OpenTaskManager(browser_);
[email protected]5d98294912012-06-27 22:57:40612 break;
caelyn4e4e08a2015-02-04 21:27:49613#if defined(OS_CHROMEOS)
614 case IDC_TAKE_SCREENSHOT:
615 TakeScreenshot();
616 break;
617#endif
[email protected]236ad3022013-09-04 03:27:43618#if defined(GOOGLE_CHROME_BUILD)
[email protected]5d98294912012-06-27 22:57:40619 case IDC_FEEDBACK:
afakhryf4575bd2017-04-28 02:21:04620 OpenFeedbackDialog(browser_, kFeedbackSourceBrowserCommand);
[email protected]5d98294912012-06-27 22:57:40621 break;
[email protected]236ad3022013-09-04 03:27:43622#endif
[email protected]5d98294912012-06-27 22:57:40623 case IDC_SHOW_BOOKMARK_BAR:
624 ToggleBookmarkBar(browser_);
625 break;
626 case IDC_PROFILING_ENABLED:
Bryce Thomas96b07772018-11-07 03:04:15627 content::Profiling::Toggle();
[email protected]5d98294912012-06-27 22:57:40628 break;
629
630 case IDC_SHOW_BOOKMARK_MANAGER:
631 ShowBookmarkManager(browser_);
632 break;
633 case IDC_SHOW_APP_MENU:
bratell0a7406f2017-03-28 07:46:37634 base::RecordAction(base::UserMetricsAction("Accel_Show_App_Menu"));
[email protected]5d98294912012-06-27 22:57:40635 ShowAppMenu(browser_);
636 break;
637 case IDC_SHOW_AVATAR_MENU:
638 ShowAvatarMenu(browser_);
639 break;
640 case IDC_SHOW_HISTORY:
641 ShowHistory(browser_);
642 break;
643 case IDC_SHOW_DOWNLOADS:
644 ShowDownloads(browser_);
645 break;
646 case IDC_MANAGE_EXTENSIONS:
[email protected]bc9833c32013-02-28 04:05:08647 ShowExtensions(browser_, std::string());
[email protected]5d98294912012-06-27 22:57:40648 break;
649 case IDC_OPTIONS:
650 ShowSettings(browser_);
651 break;
652 case IDC_EDIT_SEARCH_ENGINES:
653 ShowSearchEngineSettings(browser_);
654 break;
655 case IDC_VIEW_PASSWORDS:
656 ShowPasswordManager(browser_);
657 break;
658 case IDC_CLEAR_BROWSING_DATA:
659 ShowClearBrowsingDataDialog(browser_);
660 break;
661 case IDC_IMPORT_SETTINGS:
662 ShowImportDialog(browser_);
663 break;
[email protected]9b7ab882012-09-10 23:46:36664 case IDC_TOGGLE_REQUEST_TABLET_SITE:
665 ToggleRequestTabletSite(browser_);
666 break;
[email protected]5d98294912012-06-27 22:57:40667 case IDC_ABOUT:
668 ShowAboutChrome(browser_);
669 break;
670 case IDC_UPGRADE_DIALOG:
671 OpenUpdateChromeDialog(browser_);
672 break;
[email protected]5d98294912012-06-27 22:57:40673 case IDC_HELP_PAGE_VIA_KEYBOARD:
674 ShowHelp(browser_, HELP_SOURCE_KEYBOARD);
675 break;
676 case IDC_HELP_PAGE_VIA_MENU:
677 ShowHelp(browser_, HELP_SOURCE_MENU);
678 break;
Bret Sepulveda2d018662017-05-18 21:31:48679 case IDC_SHOW_BETA_FORUM:
680 ShowBetaForum(browser_);
681 break;
David Roger7e25dff2019-02-07 09:03:17682#if !defined(OS_CHROMEOS)
estade8c0780f2015-08-21 23:36:41683 case IDC_SHOW_SIGNIN:
gogerald71bf6c902015-12-08 00:49:37684 ShowBrowserSigninOrSettings(
685 browser_, signin_metrics::AccessPoint::ACCESS_POINT_MENU);
estade8c0780f2015-08-21 23:36:41686 break;
David Roger7e25dff2019-02-07 09:03:17687#endif
[email protected]6bd370b2014-05-28 14:19:47688 case IDC_DISTILL_PAGE:
689 DistillCurrentPage(browser_);
690 break;
apacible45cbfc92015-09-28 22:45:41691 case IDC_ROUTE_MEDIA:
692 RouteMedia(browser_);
693 break;
Tommy Steimelc4477982017-11-29 18:07:18694 case IDC_WINDOW_MUTE_SITE:
695 MuteSite(browser_);
ellyjones0101ba02017-05-19 15:50:26696 break;
697 case IDC_WINDOW_PIN_TAB:
698 PinTab(browser_);
699 break;
Yann Dagocd13225a2019-03-07 18:39:05700 case IDC_SHOW_MANAGEMENT_PAGE: {
701 bool link_to_management_page = base::FeatureList::IsEnabled(
702 features::kLinkManagedNoticeToChromeUIManagementURL);
703 ShowSingletonTab(browser_,
704 GURL(link_to_management_page ? kChromeUIManagementURL
705 : kManagedUiLearnMoreUrl));
Nicolas Ouellet-payeur82eb65b2018-11-05 16:49:27706 break;
Yann Dagocd13225a2019-03-07 18:39:05707 }
Christopher Lam0dbac2b2017-11-14 07:12:10708 // Hosted App commands
709 case IDC_COPY_URL:
710 CopyURL(browser_);
711 break;
712 case IDC_OPEN_IN_CHROME:
713 OpenInChrome(browser_);
714 break;
715 case IDC_SITE_SETTINGS:
716 ShowSiteSettings(
717 browser_,
718 browser_->tab_strip_model()->GetActiveWebContents()->GetVisibleURL());
719 break;
Alan Cutter0c3132302018-02-21 05:09:02720 case IDC_HOSTED_APP_MENU_APP_INFO:
721 ShowPageInfoDialog(browser_->tab_strip_model()->GetActiveWebContents(),
Alan Cutter689f89a2018-03-08 05:09:54722 bubble_anchor_util::kAppMenuButton);
Christopher Lam86b52712017-12-04 01:58:33723 break;
Christopher Lam0dbac2b2017-11-14 07:12:10724
[email protected]5d98294912012-06-27 22:57:40725 default:
726 LOG(WARNING) << "Received Unimplemented Command: " << id;
727 break;
728 }
Ivan Sandrk9669d0e2017-12-15 23:50:20729
730 return true;
731}
732
733void BrowserCommandController::AddCommandObserver(int id,
734 CommandObserver* observer) {
735 command_updater_.AddCommandObserver(id, observer);
736}
737
738void BrowserCommandController::RemoveCommandObserver(
739 int id, CommandObserver* observer) {
740 command_updater_.RemoveCommandObserver(id, observer);
741}
742
743void BrowserCommandController::RemoveCommandObserver(
744 CommandObserver* observer) {
745 command_updater_.RemoveCommandObserver(observer);
746}
747
748bool BrowserCommandController::UpdateCommandEnabled(int id, bool state) {
749 if (is_locked_fullscreen_)
750 return false;
751
752 return command_updater_.UpdateCommandEnabled(id, state);
[email protected]5d98294912012-06-27 22:57:40753}
754
Mihai Sardarescuf87ccc12018-09-26 10:37:45755////////////////////////////////////////////////////////////////////////////////
756// BrowserCommandController, SigninPrefObserver implementation:
757
758void BrowserCommandController::OnSigninAllowedPrefChange() {
759 // For unit tests, we don't have a window.
760 if (!window())
761 return;
762 UpdateShowSyncState(IsShowingMainUI());
763}
764
[email protected]5d98294912012-06-27 22:57:40765// BrowserCommandController, TabStripModelObserver implementation:
766
sangwoo.ko1ae265f12018-10-18 08:30:28767void BrowserCommandController::OnTabStripModelChanged(
768 TabStripModel* tab_strip_model,
769 const TabStripModelChange& change,
770 const TabStripSelectionChange& selection) {
771 if (change.type() != TabStripModelChange::kInserted &&
772 change.type() != TabStripModelChange::kReplaced &&
773 change.type() != TabStripModelChange::kRemoved)
774 return;
[email protected]5d98294912012-06-27 22:57:40775
sangwoo.ko1ae265f12018-10-18 08:30:28776 for (const auto& delta : change.deltas()) {
777 content::WebContents* new_contents = nullptr;
778 content::WebContents* old_contents = nullptr;
779 if (change.type() == TabStripModelChange::kInserted) {
780 new_contents = delta.insert.contents;
781 } else if (change.type() == TabStripModelChange::kReplaced) {
782 new_contents = delta.replace.new_contents;
783 old_contents = delta.replace.old_contents;
784 } else {
785 old_contents = delta.remove.contents;
786 }
[email protected]5d98294912012-06-27 22:57:40787
sangwoo.ko1ae265f12018-10-18 08:30:28788 if (old_contents)
789 RemoveInterstitialObservers(old_contents);
790 if (new_contents)
791 AddInterstitialObservers(new_contents);
792 }
[email protected]5d98294912012-06-27 22:57:40793}
794
[email protected]3cac87232012-11-20 01:48:27795void BrowserCommandController::TabBlockedStateChanged(
796 content::WebContents* contents,
797 int index) {
798 PrintingStateChanged();
799 FullscreenStateChanged();
800 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:41801 UpdateCommandsForMediaRouter();
[email protected]3cac87232012-11-20 01:48:27802}
803
[email protected]5d98294912012-06-27 22:57:40804////////////////////////////////////////////////////////////////////////////////
805// BrowserCommandController, TabRestoreServiceObserver implementation:
806
807void BrowserCommandController::TabRestoreServiceChanged(
blundell74001adc2015-09-18 11:04:25808 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53809 UpdateTabRestoreCommandState();
[email protected]5d98294912012-06-27 22:57:40810}
811
812void BrowserCommandController::TabRestoreServiceDestroyed(
blundell74001adc2015-09-18 11:04:25813 sessions::TabRestoreService* service) {
[email protected]5d98294912012-06-27 22:57:40814 service->RemoveObserver(this);
815}
816
[email protected]2e9369e2014-08-15 09:12:53817void BrowserCommandController::TabRestoreServiceLoaded(
blundell74001adc2015-09-18 11:04:25818 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53819 UpdateTabRestoreCommandState();
820}
821
[email protected]5d98294912012-06-27 22:57:40822////////////////////////////////////////////////////////////////////////////////
[email protected]5d98294912012-06-27 22:57:40823// BrowserCommandController, private:
824
[email protected]20ca0382013-02-28 19:50:07825class BrowserCommandController::InterstitialObserver
826 : public content::WebContentsObserver {
827 public:
828 InterstitialObserver(BrowserCommandController* controller,
829 content::WebContents* web_contents)
830 : WebContentsObserver(web_contents),
831 controller_(controller) {
832 }
833
dcheng5dd5ff62014-10-21 12:42:38834 void DidAttachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07835 controller_->UpdateCommandsForTabState();
836 }
837
dcheng5dd5ff62014-10-21 12:42:38838 void DidDetachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07839 controller_->UpdateCommandsForTabState();
840 }
841
842 private:
843 BrowserCommandController* controller_;
844
845 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver);
846};
847
[email protected]6a414ff2013-02-27 08:22:54848bool BrowserCommandController::IsShowingMainUI() {
manukf1a116392018-10-25 16:28:24849 return browser_->SupportsWindowFeature(Browser::FEATURE_TABSTRIP);
850}
851
852bool BrowserCommandController::IsShowingLocationBar() {
853 return browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
[email protected]5d98294912012-06-27 22:57:40854}
855
856void BrowserCommandController::InitCommandState() {
857 // All browser commands whose state isn't set automagically some other way
858 // (like Back & Forward with initial page load) must have their state
859 // initialized here, otherwise they will be forever disabled.
860
Ivan Sandrk9669d0e2017-12-15 23:50:20861 if (is_locked_fullscreen_)
862 return;
863
[email protected]5d98294912012-06-27 22:57:40864 // Navigation commands
865 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true);
toyoshim7dad4b1182016-04-01 14:28:05866 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE, true);
[email protected]58e29032012-08-06 20:19:57867 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, true);
[email protected]5d98294912012-06-27 22:57:40868
869 // Window management commands
870 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true);
871 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true);
872 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true);
873 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true);
[email protected]2e9369e2014-08-15 09:12:53874 UpdateTabRestoreCommandState();
[email protected]d28d3782013-02-26 16:31:55875 command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
[email protected]5d98294912012-06-27 22:57:40876 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true);
[email protected]d12cc5e2013-10-19 18:25:06877#if defined(OS_CHROMEOS)
James Cook934abaf2017-09-19 22:21:58878 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
[email protected]d12cc5e2013-10-19 18:25:06879 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_2, true);
880 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_3, true);
881#endif
[email protected]893124a22014-04-15 00:45:28882#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15883 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
884 command_updater_.UpdateCommandEnabled(IDC_MAXIMIZE_WINDOW, true);
885 command_updater_.UpdateCommandEnabled(IDC_RESTORE_WINDOW, true);
Maksim Sisovac767592018-08-10 08:00:15886 bool use_system_title_bar = true;
887#if defined(USE_OZONE)
888 use_system_title_bar = ui::OzonePlatform::GetInstance()
889 ->GetPlatformProperties()
890 .use_system_title_bar;
891#endif
892 command_updater_.UpdateCommandEnabled(IDC_USE_SYSTEM_TITLE_BAR,
893 use_system_title_bar);
[email protected]af97be4c62014-02-13 14:43:34894#endif
Alan Cutter09965802018-03-27 07:25:29895 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW, true);
[email protected]5d98294912012-06-27 22:57:40896
897 // Page-related commands
898 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true);
[email protected]4bee4432014-05-05 13:11:41899 command_updater_.UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE, true);
Tina Wang788aac22018-12-21 20:25:46900 command_updater_.UpdateCommandEnabled(IDC_SEND_TO_MY_DEVICES, true);
[email protected]5d98294912012-06-27 22:57:40901
902 // Zoom
903 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true);
904 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true);
[email protected]d93dbd12014-08-04 23:42:53905 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, false);
[email protected]5d98294912012-06-27 22:57:40906 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
907
908 // Show various bits of UI
mlerman7831f57d2015-05-25 11:40:15909 const bool guest_session = profile()->IsGuestSession() ||
910 profile()->IsSystemProfile();
911 DCHECK(!profile()->IsSystemProfile())
912 << "Ought to never have browser for the system profile.";
[email protected]338416c02014-05-13 16:47:06913 const bool normal_window = browser_->is_type_tabbed();
[email protected]05454532013-01-22 21:09:08914 UpdateOpenFileState(&command_updater_);
[email protected]5d98294912012-06-27 22:57:40915 UpdateCommandsForDevTools();
916 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager());
[email protected]338416c02014-05-13 16:47:06917 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session);
[email protected]5d98294912012-06-27 22:57:40918 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
[email protected]674b65672014-06-02 23:21:56919 command_updater_.UpdateCommandEnabled(IDC_HELP_MENU, true);
[email protected]5d98294912012-06-27 22:57:40920 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
921 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
Bret Sepulveda2d018662017-05-18 21:31:48922 command_updater_.UpdateCommandEnabled(IDC_SHOW_BETA_FORUM, true);
[email protected]338416c02014-05-13 16:47:06923 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session);
[email protected]2f1acc212012-11-13 10:43:51924 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU,
[email protected]338416c02014-05-13 16:47:06925 !guest_session &&
[email protected]2f1acc212012-11-13 10:43:51926 !profile()->IsOffTheRecord());
tsergeant341a8272017-04-18 03:54:33927 command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA,
928 !guest_session);
[email protected]39d47592014-01-10 21:42:45929#if defined(OS_CHROMEOS)
caelyn4e4e08a2015-02-04 21:27:49930 command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true);
[email protected]338416c02014-05-13 16:47:06931#else
932 // Chrome OS uses the system tray menu to handle multi-profiles.
anthonyvd7dc985da2015-03-23 16:53:19933 if (normal_window && (guest_session || !profile()->IsOffTheRecord())) {
[email protected]338416c02014-05-13 16:47:06934 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
anthonyvd7dc985da2015-03-23 16:53:19935 }
[email protected]39d47592014-01-10 21:42:45936#endif
[email protected]5d98294912012-06-27 22:57:40937
Mihai Sardarescu2ec5205682018-09-26 09:20:05938 UpdateShowSyncState(true);
939
[email protected]5d98294912012-06-27 22:57:40940 // Navigation commands
[email protected]c9f983d2014-02-05 09:00:24941 command_updater_.UpdateCommandEnabled(
942 IDC_HOME,
benwellsc431c0ae2015-01-27 22:04:06943 normal_window ||
944 (extensions::util::IsNewBookmarkAppsEnabled() && browser_->is_app()));
[email protected]5d98294912012-06-27 22:57:40945
Christopher Lam0dbac2b2017-11-14 07:12:10946 const bool is_experimental_hosted_app =
947 extensions::HostedAppBrowserController::IsForExperimentalHostedAppBrowser(
948 browser_);
949 // Hosted app browser commands.
950 command_updater_.UpdateCommandEnabled(IDC_COPY_URL,
951 is_experimental_hosted_app);
952 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_CHROME,
953 is_experimental_hosted_app);
954 command_updater_.UpdateCommandEnabled(IDC_SITE_SETTINGS,
955 is_experimental_hosted_app);
Alan Cutter0c3132302018-02-21 05:09:02956 command_updater_.UpdateCommandEnabled(IDC_HOSTED_APP_MENU_APP_INFO,
Christopher Lam86b52712017-12-04 01:58:33957 is_experimental_hosted_app);
Christopher Lam0dbac2b2017-11-14 07:12:10958
[email protected]5d98294912012-06-27 22:57:40959 // Window management commands
[email protected]5d98294912012-06-27 22:57:40960 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window);
961 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB,
962 normal_window);
963 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window);
964 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window);
965 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window);
966 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window);
967 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window);
968 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window);
969 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window);
970 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window);
971 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window);
972 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window);
973 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window);
[email protected]5d98294912012-06-27 22:57:40974
[email protected]338416c02014-05-13 16:47:06975 // These are always enabled; the menu determines their menu item visibility.
[email protected]5d98294912012-06-27 22:57:40976 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
[email protected]5d98294912012-06-27 22:57:40977
[email protected]6bd370b2014-05-28 14:19:47978 // Distill current page.
979 command_updater_.UpdateCommandEnabled(
avi556c05022014-12-22 23:31:43980 IDC_DISTILL_PAGE, base::CommandLine::ForCurrentProcess()->HasSwitch(
981 switches::kEnableDomDistiller));
[email protected]6bd370b2014-05-28 14:19:47982
Tommy Steimelc4477982017-11-29 18:07:18983 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE, normal_window);
ellyjones0101ba02017-05-19 15:50:26984 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, normal_window);
985
[email protected]338416c02014-05-13 16:47:06986 // Initialize other commands whose state changes based on various conditions.
[email protected]32dfede2013-08-25 15:48:25987 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40988 UpdateCommandsForContentRestrictionState();
[email protected]5d98294912012-06-27 22:57:40989 UpdateCommandsForBookmarkEditing();
[email protected]5d98294912012-06-27 22:57:40990 UpdateCommandsForIncognitoAvailability();
991}
992
[email protected]05454532013-01-22 21:09:08993// static
994void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
995 CommandUpdater* command_updater,
996 Profile* profile) {
mlermane01e6de2014-09-29 19:26:47997 const bool guest_session = profile->IsGuestSession();
998 // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession().
[email protected]5d98294912012-06-27 22:57:40999 IncognitoModePrefs::Availability incognito_availability =
[email protected]05454532013-01-22 21:09:081000 IncognitoModePrefs::GetAvailability(profile->GetPrefs());
1001 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:401002 IDC_NEW_WINDOW,
1003 incognito_availability != IncognitoModePrefs::FORCED);
[email protected]05454532013-01-22 21:09:081004 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:401005 IDC_NEW_INCOGNITO_WINDOW,
mlermane01e6de2014-09-29 19:26:471006 incognito_availability != IncognitoModePrefs::DISABLED && !guest_session);
[email protected]5d98294912012-06-27 22:57:401007
[email protected]57b25292014-05-01 16:31:061008 const bool forced_incognito =
1009 incognito_availability == IncognitoModePrefs::FORCED ||
1010 guest_session; // Guest always runs in Incognito mode.
[email protected]05454532013-01-22 21:09:081011 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:401012 IDC_SHOW_BOOKMARK_MANAGER,
[email protected]57b25292014-05-01 16:31:061013 browser_defaults::bookmarks_enabled && !forced_incognito);
Devlin Cronin21dba422018-05-30 15:45:161014 extensions::ExtensionService* extension_service =
[email protected]03d25812014-06-22 19:41:551015 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]57b25292014-05-01 16:31:061016 const bool enable_extensions =
[email protected]5d98294912012-06-27 22:57:401017 extension_service && extension_service->extensions_enabled();
[email protected]5d98294912012-06-27 22:57:401018
[email protected]57b25292014-05-01 16:31:061019 // Bookmark manager and settings page/subpages are forced to open in normal
1020 // mode. For this reason we disable these commands when incognito is forced.
1021 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
1022 enable_extensions && !forced_incognito);
1023
1024 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito);
1025 command_updater->UpdateCommandEnabled(IDC_OPTIONS,
1026 !forced_incognito || guest_session);
estade8c0780f2015-08-21 23:36:411027 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito);
[email protected]05454532013-01-22 21:09:081028}
1029
1030void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
Ivan Sandrk9669d0e2017-12-15 23:50:201031 if (is_locked_fullscreen_)
1032 return;
1033
[email protected]05454532013-01-22 21:09:081034 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile());
1035
[email protected]6a414ff2013-02-27 08:22:541036 if (!IsShowingMainUI()) {
[email protected]05454532013-01-22 21:09:081037 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false);
1038 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false);
1039 }
[email protected]5d98294912012-06-27 22:57:401040}
1041
1042void BrowserCommandController::UpdateCommandsForTabState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201043 if (is_locked_fullscreen_)
1044 return;
1045
[email protected]617ee962013-01-29 20:49:121046 WebContents* current_web_contents =
1047 browser_->tab_strip_model()->GetActiveWebContents();
[email protected]1c5119c2012-09-19 00:08:571048 if (!current_web_contents) // May be NULL during tab restore.
[email protected]5d98294912012-06-27 22:57:401049 return;
[email protected]5d98294912012-06-27 22:57:401050
1051 // Navigation commands
1052 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_));
1053 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_));
1054 command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_));
toyoshim7dad4b1182016-04-01 14:28:051055 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE,
[email protected]5d98294912012-06-27 22:57:401056 CanReload(browser_));
[email protected]58e29032012-08-06 20:19:571057 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE,
1058 CanReload(browser_));
[email protected]5d98294912012-06-27 22:57:401059
1060 // Window management commands
1061 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB,
1062 !browser_->is_app() && CanDuplicateTab(browser_));
Tommy Steimelc4477982017-11-29 18:07:181063 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE,
ellyjones0101ba02017-05-19 15:50:261064 !browser_->is_app());
1065 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB,
1066 !browser_->is_app());
[email protected]5d98294912012-06-27 22:57:401067
1068 // Page-related commands
1069 window()->SetStarredState(
[email protected]1c5119c2012-09-19 00:08:571070 BookmarkTabHelper::FromWebContents(current_web_contents)->is_starred());
[email protected]5423c372012-08-22 05:50:161071 window()->ZoomChangedForActiveTab(false);
[email protected]5d98294912012-06-27 22:57:401072 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
1073 CanViewSource(browser_));
1074 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION,
1075 CanEmailPageLocation(browser_));
1076 if (browser_->is_devtools())
1077 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false);
1078
Alan Cutter81ac726682018-09-25 00:18:361079 bool can_create_bookmark_app = CanCreateBookmarkApp(browser_);
1080 command_updater_.UpdateCommandEnabled(IDC_INSTALL_PWA,
1081 can_create_bookmark_app);
1082 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUT,
1083 can_create_bookmark_app);
Alan Cutter403cebb2018-05-17 05:22:451084 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW,
Alan Cutter81ac726682018-09-25 00:18:361085 can_create_bookmark_app);
[email protected]5d98294912012-06-27 22:57:401086
[email protected]9b7ab882012-09-10 23:46:361087 command_updater_.UpdateCommandEnabled(
1088 IDC_TOGGLE_REQUEST_TABLET_SITE,
1089 CanRequestTabletSite(current_web_contents));
1090
[email protected]5d98294912012-06-27 22:57:401091 UpdateCommandsForContentRestrictionState();
1092 UpdateCommandsForBookmarkEditing();
[email protected]3cac87232012-11-20 01:48:271093 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:411094 UpdateCommandsForMediaRouter();
[email protected]d93dbd12014-08-04 23:42:531095 // Update the zoom commands when an active tab is selected.
1096 UpdateCommandsForZoomState();
1097}
1098
1099void BrowserCommandController::UpdateCommandsForZoomState() {
1100 WebContents* contents =
1101 browser_->tab_strip_model()->GetActiveWebContents();
1102 if (!contents)
1103 return;
a.sarkar.arundaadc712015-02-26 05:39:081104 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS,
1105 CanZoomIn(contents));
1106 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL,
ccameronb7c1d6c2015-03-09 17:08:241107 CanResetZoom(contents));
a.sarkar.arundaadc712015-02-26 05:39:081108 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS,
1109 CanZoomOut(contents));
[email protected]5d98294912012-06-27 22:57:401110}
1111
1112void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
1113 int restrictions = GetContentRestrictions(browser_);
1114
1115 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011116 IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY));
[email protected]5d98294912012-06-27 22:57:401117 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011118 IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT));
[email protected]5d98294912012-06-27 22:57:401119 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011120 IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE));
[email protected]5d98294912012-06-27 22:57:401121 UpdateSaveAsState();
1122 UpdatePrintingState();
1123}
1124
1125void BrowserCommandController::UpdateCommandsForDevTools() {
Ivan Sandrk9669d0e2017-12-15 23:50:201126 if (is_locked_fullscreen_)
1127 return;
1128
Pavol Marko56df0272018-07-04 17:55:041129 bool dev_tools_enabled = DevToolsWindow::AllowDevToolsFor(
1130 profile(), browser_->tab_strip_model()->GetActiveWebContents());
[email protected]5d98294912012-06-27 22:57:401131 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS,
1132 dev_tools_enabled);
1133 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE,
1134 dev_tools_enabled);
[email protected]2056c3192013-10-21 22:40:511135 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES,
1136 dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401137 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT,
1138 dev_tools_enabled);
[email protected]d16657c2012-09-03 14:25:101139 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE,
1140 dev_tools_enabled);
spqchan2c5d541e2017-10-25 07:07:111141#if defined(OS_MACOSX)
1142 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS,
1143 dev_tools_enabled);
1144#endif
[email protected]5d98294912012-06-27 22:57:401145}
1146
1147void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
Ivan Sandrk9669d0e2017-12-15 23:50:201148 if (is_locked_fullscreen_)
1149 return;
1150
[email protected]5d98294912012-06-27 22:57:401151 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE,
1152 CanBookmarkCurrentPage(browser_));
1153 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
1154 CanBookmarkAllTabs(browser_));
thestig5149d272014-10-30 07:25:291155#if defined(OS_WIN)
1156 command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN, true);
1157#endif
[email protected]5d98294912012-06-27 22:57:401158}
1159
1160void BrowserCommandController::UpdateCommandsForBookmarkBar() {
Ivan Sandrk9669d0e2017-12-15 23:50:201161 if (is_locked_fullscreen_)
1162 return;
1163
tfarina3bddbe112014-08-28 05:29:321164 command_updater_.UpdateCommandEnabled(
1165 IDC_SHOW_BOOKMARK_BAR,
1166 browser_defaults::bookmarks_enabled && !profile()->IsGuestSession() &&
mlerman7831f57d2015-05-25 11:40:151167 !profile()->IsSystemProfile() &&
tfarina3bddbe112014-08-28 05:29:321168 !profile()->GetPrefs()->IsManagedPreference(
1169 bookmarks::prefs::kShowBookmarkBar) &&
1170 IsShowingMainUI());
[email protected]5d98294912012-06-27 22:57:401171}
1172
[email protected]9ec3ea5b2012-12-03 18:14:301173void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
Ivan Sandrk9669d0e2017-12-15 23:50:201174 if (is_locked_fullscreen_)
1175 return;
1176
[email protected]9ec3ea5b2012-12-03 18:14:301177 UpdateSaveAsState();
[email protected]05454532013-01-22 21:09:081178 UpdateOpenFileState(&command_updater_);
[email protected]9ec3ea5b2012-12-03 18:14:301179}
1180
[email protected]32dfede2013-08-25 15:48:251181void BrowserCommandController::UpdateCommandsForFullscreenMode() {
Ivan Sandrk9669d0e2017-12-15 23:50:201182 if (is_locked_fullscreen_)
1183 return;
1184
zijiehe3c7af992017-02-12 20:59:401185 const bool is_fullscreen = window() && window()->IsFullscreen();
1186 const bool show_main_ui = IsShowingMainUI();
manukf1a116392018-10-25 16:28:241187 const bool show_location_bar = IsShowingLocationBar();
1188
zijiehe3c7af992017-02-12 20:59:401189 const bool main_not_fullscreen = show_main_ui && !is_fullscreen;
[email protected]5d98294912012-06-27 22:57:401190
1191 // Navigation commands
1192 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1193
1194 // Window management commands
1195 command_updater_.UpdateCommandEnabled(
1196 IDC_SHOW_AS_TAB,
zijiehe3c7af992017-02-12 20:59:401197 !browser_->is_type_tabbed() && !is_fullscreen);
[email protected]5d98294912012-06-27 22:57:401198
1199 // Focus various bits of UI
1200 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
manukf1a116392018-10-25 16:28:241201 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_location_bar);
[email protected]5d98294912012-06-27 22:57:401202 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
1203 command_updater_.UpdateCommandEnabled(
1204 IDC_FOCUS_MENU_BAR, main_not_fullscreen);
1205 command_updater_.UpdateCommandEnabled(
1206 IDC_FOCUS_NEXT_PANE, main_not_fullscreen);
1207 command_updater_.UpdateCommandEnabled(
1208 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen);
1209 command_updater_.UpdateCommandEnabled(
1210 IDC_FOCUS_BOOKMARKS, main_not_fullscreen);
[email protected]822ca8c62013-04-19 00:49:151211 command_updater_.UpdateCommandEnabled(
David Tsengc0b1b642018-01-24 07:12:271212 IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY, main_not_fullscreen);
[email protected]5d98294912012-06-27 22:57:401213
1214 // Show various bits of UI
1215 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431216#if defined(GOOGLE_CHROME_BUILD)
[email protected]5d98294912012-06-27 22:57:401217 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431218#endif
Mihai Sardarescu2ec5205682018-09-26 09:20:051219 UpdateShowSyncState(show_main_ui);
[email protected]5d98294912012-06-27 22:57:401220
[email protected]5d98294912012-06-27 22:57:401221 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
1222 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
1223 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
1224 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
Yann Dago70ca3dd2019-02-27 01:12:351225 command_updater_.UpdateCommandEnabled(IDC_SHOW_MANAGEMENT_PAGE, true);
primianod3a81ab2016-01-25 22:21:151226
1227 if (base::debug::IsProfilingSupported())
1228 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
[email protected]5d98294912012-06-27 22:57:401229
[email protected]aeafc3852014-04-29 16:51:291230#if !defined(OS_MACOSX)
zijiehe3c7af992017-02-12 20:59:401231 // Disable toggling into fullscreen mode if disallowed by pref.
1232 const bool fullscreen_enabled = is_fullscreen ||
1233 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed);
1234#else
1235 const bool fullscreen_enabled = true;
[email protected]00a1cc5b2012-11-07 13:44:511236#endif
1237
1238 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled);
spqchanb8ffc7d2015-11-17 01:17:211239 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR,
1240 fullscreen_enabled);
[email protected]5d98294912012-06-27 22:57:401241
1242 UpdateCommandsForBookmarkBar();
zijiehedb473d552017-02-24 01:13:411243 UpdateCommandsForIncognitoAvailability();
Alan Cutter167dfe82018-04-11 09:06:001244 UpdateCommandsForHostedAppAvailability();
1245}
1246
1247void BrowserCommandController::UpdateCommandsForHostedAppAvailability() {
1248 bool has_toolbar =
1249 browser_->is_type_tabbed() ||
1250 extensions::HostedAppBrowserController::IsForExperimentalHostedAppBrowser(
1251 browser_);
1252 if (window() && window()->ShouldHideUIForFullscreen())
1253 has_toolbar = false;
1254 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, has_toolbar);
1255 command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE, has_toolbar);
1256 command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE, has_toolbar);
1257 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, has_toolbar);
[email protected]5d98294912012-06-27 22:57:401258}
1259
Ivan Sandrk9669d0e2017-12-15 23:50:201260#if defined(OS_CHROMEOS)
1261namespace {
1262
1263#if DCHECK_IS_ON()
1264// Makes sure that all commands that are not whitelisted are disabled. DCHECKs
1265// otherwise. Compiled only in debug mode.
1266void NonWhitelistedCommandsAreDisabled(CommandUpdaterImpl* command_updater) {
Ivan Sandrk6ac9c9a2018-12-14 14:15:071267 constexpr int kWhitelistedIds[] = {IDC_CUT, IDC_COPY, IDC_PASTE};
Ivan Sandrk9669d0e2017-12-15 23:50:201268
1269 // Go through all the command ids, skip the whitelisted ones.
1270 for (int id : command_updater->GetAllIds()) {
Haeun Kim3f6123502018-08-26 18:03:041271 if (base::ContainsValue(kWhitelistedIds, id)) {
Ivan Sandrk9669d0e2017-12-15 23:50:201272 continue;
1273 }
1274 DCHECK(!command_updater->IsCommandEnabled(id));
1275 }
1276}
1277#endif
1278
1279} // namespace
1280
1281void BrowserCommandController::UpdateCommandsForLockedFullscreenMode() {
Ivan Sandrk9669d0e2017-12-15 23:50:201282 bool is_locked_fullscreen = ash::IsWindowTrustedPinned(browser_->window());
1283 // Sanity check to make sure this function is called only on state change.
1284 DCHECK_NE(is_locked_fullscreen, is_locked_fullscreen_);
1285 if (is_locked_fullscreen == is_locked_fullscreen_)
1286 return;
1287 is_locked_fullscreen_ = is_locked_fullscreen;
1288
1289 if (is_locked_fullscreen_) {
1290 command_updater_.DisableAllCommands();
1291 // Update the state of whitelisted commands:
1292 // IDC_CUT/IDC_COPY/IDC_PASTE,
1293 UpdateCommandsForContentRestrictionState();
Ivan Sandrk6ac9c9a2018-12-14 14:15:071294 // TODO(crbug.com/904637): Re-enable Find and Zoom in locked fullscreen.
Ivan Sandrk9669d0e2017-12-15 23:50:201295 // All other commands will be disabled (there is an early return in their
1296 // corresponding UpdateCommandsFor* functions).
1297#if DCHECK_IS_ON()
1298 NonWhitelistedCommandsAreDisabled(&command_updater_);
1299#endif
1300 } else {
1301 // Do an init call to re-initialize command state after the
1302 // DisableAllCommands.
1303 InitCommandState();
1304 }
1305}
1306#endif
1307
[email protected]5d98294912012-06-27 22:57:401308void BrowserCommandController::UpdatePrintingState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201309 if (is_locked_fullscreen_)
1310 return;
1311
[email protected]d53e4032012-06-29 18:58:341312 bool print_enabled = CanPrint(browser_);
1313 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
Lei Zhang48a4a5262018-04-17 20:18:441314#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:551315 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT,
1316 CanBasicPrint(browser_));
Lei Zhang48a4a5262018-04-17 20:18:441317#endif
[email protected]5d98294912012-06-27 22:57:401318}
1319
1320void BrowserCommandController::UpdateSaveAsState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201321 if (is_locked_fullscreen_)
1322 return;
1323
[email protected]5d98294912012-06-27 22:57:401324 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_));
1325}
1326
Mihai Sardarescu2ec5205682018-09-26 09:20:051327void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) {
1328 if (is_locked_fullscreen_)
1329 return;
1330
Mihai Sardarescuf87ccc12018-09-26 10:37:451331 command_updater_.UpdateCommandEnabled(
Mihai Sardarescu290bc882018-10-12 10:48:141332 IDC_SHOW_SIGNIN, show_main_ui && pref_signin_allowed_.GetValue());
Mihai Sardarescu2ec5205682018-09-26 09:20:051333}
1334
[email protected]05454532013-01-22 21:09:081335// static
1336void BrowserCommandController::UpdateOpenFileState(
1337 CommandUpdater* command_updater) {
[email protected]5d98294912012-06-27 22:57:401338 bool enabled = true;
1339 PrefService* local_state = g_browser_process->local_state();
1340 if (local_state)
1341 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs);
1342
[email protected]05454532013-01-22 21:09:081343 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled);
[email protected]5d98294912012-06-27 22:57:401344}
1345
1346void BrowserCommandController::UpdateReloadStopState(bool is_loading,
1347 bool force) {
Ivan Sandrk9669d0e2017-12-15 23:50:201348 if (is_locked_fullscreen_)
1349 return;
1350
[email protected]5d98294912012-06-27 22:57:401351 window()->UpdateReloadStopState(is_loading, force);
1352 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
1353}
1354
[email protected]2e9369e2014-08-15 09:12:531355void BrowserCommandController::UpdateTabRestoreCommandState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201356 if (is_locked_fullscreen_)
1357 return;
1358
blundell74001adc2015-09-18 11:04:251359 sessions::TabRestoreService* tab_restore_service =
[email protected]2e9369e2014-08-15 09:12:531360 TabRestoreServiceFactory::GetForProfile(profile());
1361 // The command is enabled if the service hasn't loaded yet to trigger loading.
1362 // The command is updated once the load completes.
1363 command_updater_.UpdateCommandEnabled(
1364 IDC_RESTORE_TAB,
1365 tab_restore_service &&
1366 (!tab_restore_service->IsLoaded() ||
1367 GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE));
1368}
1369
[email protected]3cac87232012-11-20 01:48:271370void BrowserCommandController::UpdateCommandsForFind() {
1371 TabStripModel* model = browser_->tab_strip_model();
1372 bool enabled = !model->IsTabBlocked(model->active_index()) &&
1373 !browser_->is_devtools();
1374
1375 command_updater_.UpdateCommandEnabled(IDC_FIND, enabled);
1376 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled);
1377 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled);
1378}
1379
apacible45cbfc92015-09-28 22:45:411380void BrowserCommandController::UpdateCommandsForMediaRouter() {
Ivan Sandrk9669d0e2017-12-15 23:50:201381 if (is_locked_fullscreen_)
1382 return;
1383
apacible45cbfc92015-09-28 22:45:411384 command_updater_.UpdateCommandEnabled(IDC_ROUTE_MEDIA,
1385 CanRouteMedia(browser_));
1386}
1387
[email protected]409ea2972012-11-10 19:54:431388void BrowserCommandController::AddInterstitialObservers(WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071389 interstitial_observers_.push_back(new InterstitialObserver(this, contents));
[email protected]5d98294912012-06-27 22:57:401390}
1391
1392void BrowserCommandController::RemoveInterstitialObservers(
[email protected]e89cfcb2012-11-11 14:47:241393 WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071394 for (size_t i = 0; i < interstitial_observers_.size(); i++) {
1395 if (interstitial_observers_[i]->web_contents() != contents)
1396 continue;
1397
1398 delete interstitial_observers_[i];
1399 interstitial_observers_.erase(interstitial_observers_.begin() + i);
1400 return;
1401 }
[email protected]5d98294912012-06-27 22:57:401402}
1403
1404BrowserWindow* BrowserCommandController::window() {
1405 return browser_->window();
1406}
1407
1408Profile* BrowserCommandController::profile() {
1409 return browser_->profile();
1410}
1411
[email protected]5d98294912012-06-27 22:57:401412} // namespace chrome