blob: 378a33d23ae9e435a1c18ae65337c9b48739c668 [file] [log] [blame]
[email protected]5d98294912012-06-27 22:57:401// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/ui/browser_command_controller.h"
6
avi655876a2015-12-25 07:18:157#include <stddef.h>
8
pmonette9c1457f2015-11-19 20:29:319#include <string>
10
Sebastien Marchandf1349f52019-01-25 03:16:4111#include "base/bind.h"
[email protected]488e3952013-11-18 05:29:1412#include "base/command_line.h"
Scott Violet44165792018-02-22 02:08:0813#include "base/debug/debugging_buildflags.h"
primianod3a81ab2016-01-25 22:21:1514#include "base/debug/profiler.h"
avi655876a2015-12-25 07:18:1515#include "base/macros.h"
bratell0a7406f2017-03-28 07:46:3716#include "base/metrics/user_metrics.h"
Haeun Kim3f6123502018-08-26 18:03:0417#include "base/stl_util.h"
avi655876a2015-12-25 07:18:1518#include "build/build_config.h"
[email protected]5d98294912012-06-27 22:57:4019#include "chrome/app/chrome_command_ids.h"
20#include "chrome/browser/browser_process.h"
[email protected]dcc8fbc2013-07-12 00:54:0921#include "chrome/browser/chrome_notification_types.h"
[email protected]5d98294912012-06-27 22:57:4022#include "chrome/browser/defaults.h"
Pavol Marko56df0272018-07-04 17:55:0423#include "chrome/browser/devtools/devtools_window.h"
[email protected]5d98294912012-06-27 22:57:4024#include "chrome/browser/extensions/extension_service.h"
[email protected]2e9d79f2013-08-16 05:45:5625#include "chrome/browser/lifetime/application_lifetime.h"
[email protected]5d98294912012-06-27 22:57:4026#include "chrome/browser/prefs/incognito_mode_prefs.h"
[email protected]5d98294912012-06-27 22:57:4027#include "chrome/browser/profiles/profile.h"
mlermane01e6de2014-09-29 19:26:4728#include "chrome/browser/profiles/profile_manager.h"
[email protected]5d98294912012-06-27 22:57:4029#include "chrome/browser/sessions/tab_restore_service_factory.h"
[email protected]0b32f9b62012-09-17 19:08:0330#include "chrome/browser/shell_integration.h"
[email protected]3d27d272013-07-31 03:15:1631#include "chrome/browser/signin/signin_promo.h"
[email protected]5d98294912012-06-27 22:57:4032#include "chrome/browser/sync/profile_sync_service_factory.h"
Christopher Lam86b52712017-12-04 01:58:3333#include "chrome/browser/ui/apps/app_info_dialog.h"
[email protected]5d98294912012-06-27 22:57:4034#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
35#include "chrome/browser/ui/browser.h"
36#include "chrome/browser/ui/browser_commands.h"
37#include "chrome/browser/ui/browser_window.h"
38#include "chrome/browser/ui/chrome_pages.h"
Alan Cutter09965802018-03-27 07:25:2939#include "chrome/browser/ui/extensions/application_launch.h"
Christopher Lam0dbac2b2017-11-14 07:12:1040#include "chrome/browser/ui/extensions/hosted_app_browser_controller.h"
Alan Cutter0c3132302018-02-21 05:09:0241#include "chrome/browser/ui/page_info/page_info_dialog.h"
Nicolas Ouellet-payeur82eb65b2018-11-05 16:49:2742#include "chrome/browser/ui/singleton_tabs.h"
[email protected]5d98294912012-06-27 22:57:4043#include "chrome/browser/ui/tabs/tab_strip_model.h"
Yining Wang234ad3272019-04-08 18:47:2744#include "chrome/browser/ui/web_app_browser_controller.h"
[email protected]2056c3192013-10-21 22:40:5145#include "chrome/browser/ui/webui/inspect_ui.h"
[email protected]3c71576ce2013-07-23 02:00:0146#include "chrome/common/content_restriction.h"
[email protected]5d98294912012-06-27 22:57:4047#include "chrome/common/pref_names.h"
Nicolas Ouellet-payeur82eb65b2018-11-05 16:49:2748#include "chrome/common/url_constants.h"
brettwe1f0af8b2015-10-09 21:30:4649#include "components/bookmarks/common/bookmark_pref_names.h"
sdefresne0f2ef352015-07-27 19:18:0050#include "components/dom_distiller/core/dom_distiller_switches.h"
Scott Violet9ae82892018-03-01 18:38:1251#include "components/feature_engagement/buildflags.h"
brettwb1fc1b82016-02-02 00:19:0852#include "components/prefs/pref_service.h"
blundella08c5dd2015-09-18 06:14:1653#include "components/sessions/core/tab_restore_service.h"
David Rogera6c88122017-10-25 13:02:4654#include "components/signin/core/browser/signin_pref_names.h"
[email protected]5d98294912012-06-27 22:57:4055#include "content/public/browser/native_web_keyboard_event.h"
56#include "content/public/browser/navigation_controller.h"
57#include "content/public/browser/navigation_entry.h"
Lukasz Anforowicze1b954d92017-10-30 21:28:0658#include "content/public/browser/render_frame_host.h"
[email protected]5d98294912012-06-27 22:57:4059#include "content/public/browser/web_contents.h"
[email protected]20ca0382013-02-28 19:50:0760#include "content/public/browser/web_contents_observer.h"
Bryce Thomas96b07772018-11-07 03:04:1561#include "content/public/common/profiling.h"
bend32292b2016-10-07 00:21:5862#include "content/public/common/service_manager_connection.h"
[email protected]5d98294912012-06-27 22:57:4063#include "content/public/common/url_constants.h"
[email protected]03d25812014-06-22 19:41:5564#include "extensions/browser/extension_system.h"
Scott Violet318a55f2018-03-30 19:08:1965#include "printing/buildflags/buildflags.h"
[email protected]7e9acd082013-09-17 23:31:1666#include "ui/events/keycodes/keyboard_codes.h"
[email protected]5d98294912012-06-27 22:57:4067
[email protected]9c4d68332013-01-30 13:34:4168#if defined(OS_MACOSX)
69#include "chrome/browser/ui/browser_commands_mac.h"
70#endif
71
[email protected]5d98294912012-06-27 22:57:4072#if defined(OS_WIN)
[email protected]a43ed002013-02-05 19:47:5473#include "base/win/windows_version.h"
[email protected]2d0f80f2013-11-01 22:47:1874#include "content/public/browser/gpu_data_manager.h"
[email protected]5d98294912012-06-27 22:57:4075#endif
76
[email protected]d12cc5e2013-10-19 18:25:0677#if defined(OS_CHROMEOS)
Ivan Sandrke0e92452019-03-21 09:32:4878#include "chrome/browser/platform_util.h"
[email protected]0c930812014-01-30 18:01:4779#include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h"
caelyn4e4e08a2015-02-04 21:27:4980#include "chrome/browser/ui/browser_commands_chromeos.h"
[email protected]d12cc5e2013-10-19 18:25:0681#endif
82
[email protected]d5bedb6d2014-04-08 10:49:3283#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
karandeepbe6200332016-06-21 12:26:1084#include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h"
[email protected]1e2172f2014-04-01 17:32:3485#endif
86
Bettina Deaf3dac202017-09-16 20:53:2287#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:1488#include "chrome/browser/feature_engagement/bookmark/bookmark_tracker.h"
89#include "chrome/browser/feature_engagement/bookmark/bookmark_tracker_factory.h"
Catherine Chungbeb884222017-08-01 15:47:5590#include "chrome/browser/feature_engagement/new_tab/new_tab_tracker.h"
91#include "chrome/browser/feature_engagement/new_tab/new_tab_tracker_factory.h"
92#endif
93
Maksim Sisovac767592018-08-10 08:00:1594#if defined(USE_OZONE)
95#include "ui/ozone/public/ozone_platform.h"
96#endif
97
[email protected]5d98294912012-06-27 22:57:4098using content::NavigationController;
Aran Gilmand217b5b2019-04-11 17:45:4399using content::NavigationEntry;
[email protected]5d98294912012-06-27 22:57:40100using content::WebContents;
101
[email protected]5d98294912012-06-27 22:57:40102namespace chrome {
103
104///////////////////////////////////////////////////////////////////////////////
105// BrowserCommandController, public:
106
[email protected]338416c02014-05-13 16:47:06107BrowserCommandController::BrowserCommandController(Browser* browser)
Aran Gilmand217b5b2019-04-11 17:45:43108 : browser_(browser), command_updater_(nullptr) {
[email protected]5d98294912012-06-27 22:57:40109 browser_->tab_strip_model()->AddObserver(this);
110 PrefService* local_state = g_browser_process->local_state();
111 if (local_state) {
112 local_pref_registrar_.Init(local_state);
[email protected]9ec3ea5b2012-12-03 18:14:30113 local_pref_registrar_.Add(
114 prefs::kAllowFileSelectionDialogs,
115 base::Bind(
116 &BrowserCommandController::UpdateCommandsForFileSelectionDialogs,
117 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40118 }
119
120 profile_pref_registrar_.Init(profile()->GetPrefs());
[email protected]9ec3ea5b2012-12-03 18:14:30121 profile_pref_registrar_.Add(
Pavol Markodebb0ff2018-05-07 18:35:41122 prefs::kDevToolsAvailability,
[email protected]9ec3ea5b2012-12-03 18:14:30123 base::Bind(&BrowserCommandController::UpdateCommandsForDevTools,
124 base::Unretained(this)));
125 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32126 bookmarks::prefs::kEditBookmarksEnabled,
[email protected]9ec3ea5b2012-12-03 18:14:30127 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkEditing,
128 base::Unretained(this)));
129 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32130 bookmarks::prefs::kShowBookmarkBar,
[email protected]9ec3ea5b2012-12-03 18:14:30131 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkBar,
132 base::Unretained(this)));
133 profile_pref_registrar_.Add(
134 prefs::kIncognitoModeAvailability,
135 base::Bind(
136 &BrowserCommandController::UpdateCommandsForIncognitoAvailability,
137 base::Unretained(this)));
138 profile_pref_registrar_.Add(
139 prefs::kPrintingEnabled,
140 base::Bind(&BrowserCommandController::UpdatePrintingState,
141 base::Unretained(this)));
[email protected]32dfede2013-08-25 15:48:25142#if !defined(OS_MACOSX)
143 profile_pref_registrar_.Add(
144 prefs::kFullscreenAllowed,
145 base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode,
146 base::Unretained(this)));
147#endif
Mihai Sardarescuf87ccc12018-09-26 10:37:45148 pref_signin_allowed_.Init(
Aran Gilmand217b5b2019-04-11 17:45:43149 prefs::kSigninAllowed, profile()->GetOriginalProfile()->GetPrefs(),
Mihai Sardarescuf87ccc12018-09-26 10:37:45150 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange,
151 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40152
153 InitCommandState();
154
blundell74001adc2015-09-18 11:04:25155 sessions::TabRestoreService* tab_restore_service =
[email protected]5d98294912012-06-27 22:57:40156 TabRestoreServiceFactory::GetForProfile(profile());
157 if (tab_restore_service) {
158 tab_restore_service->AddObserver(this);
Cliff Smolinsky2c9586e2019-02-08 18:48:30159 if (!tab_restore_service->IsLoaded())
160 tab_restore_service->LoadTabsFromLastSession();
[email protected]5d98294912012-06-27 22:57:40161 }
[email protected]5d98294912012-06-27 22:57:40162}
163
164BrowserCommandController::~BrowserCommandController() {
[email protected]95e39472012-10-05 23:37:36165 // TabRestoreService may have been shutdown by the time we get here. Don't
166 // trigger creating it.
blundell74001adc2015-09-18 11:04:25167 sessions::TabRestoreService* tab_restore_service =
[email protected]95e39472012-10-05 23:37:36168 TabRestoreServiceFactory::GetForProfileIfExisting(profile());
[email protected]5d98294912012-06-27 22:57:40169 if (tab_restore_service)
170 tab_restore_service->RemoveObserver(this);
171 profile_pref_registrar_.RemoveAll();
172 local_pref_registrar_.RemoveAll();
173 browser_->tab_strip_model()->RemoveObserver(this);
174}
175
176bool BrowserCommandController::IsReservedCommandOrKey(
177 int command_id,
178 const content::NativeWebKeyboardEvent& event) {
179 // In Apps mode, no keys are reserved.
180 if (browser_->is_app())
181 return false;
182
183#if defined(OS_CHROMEOS)
[email protected]397abd32013-08-21 05:44:19184 // On Chrome OS, the top row of keys are mapped to browser actions like
185 // back/forward or refresh. We don't want web pages to be able to change the
186 // behavior of these keys. Ash handles F4 and up; this leaves us needing to
187 // reserve browser back/forward and refresh here.
[email protected]5d98294912012-06-27 22:57:40188 ui::KeyboardCode key_code =
Blink Reformat1c4d759e2017-04-09 16:34:54189 static_cast<ui::KeyboardCode>(event.windows_key_code);
[email protected]397abd32013-08-21 05:44:19190 if ((key_code == ui::VKEY_BROWSER_BACK && command_id == IDC_BACK) ||
191 (key_code == ui::VKEY_BROWSER_FORWARD && command_id == IDC_FORWARD) ||
192 (key_code == ui::VKEY_BROWSER_REFRESH && command_id == IDC_RELOAD)) {
[email protected]5d98294912012-06-27 22:57:40193 return true;
194 }
195#endif
196
zijiehe68cd3dc22017-04-07 18:50:29197 if (window()->IsFullscreen()) {
198 // In fullscreen, all commands except for IDC_FULLSCREEN and IDC_EXIT should
199 // be delivered to the web page. The intent to implement and ship can be
200 // found in http://crbug.com/680809.
201 const bool is_exit_fullscreen =
202 (command_id == IDC_EXIT || command_id == IDC_FULLSCREEN);
203#if defined(OS_MACOSX)
204 // This behavior is different on Mac OS, which has a unique user-initiated
205 // full-screen mode. According to the discussion in http://crbug.com/702251,
206 // the commands should be reserved for browser-side handling if the browser
207 // window's toolbar is visible.
208 if (window()->IsToolbarShowing()) {
209 if (command_id == IDC_FULLSCREEN)
210 return true;
211 } else {
212 return is_exit_fullscreen;
213 }
214#else
215 return is_exit_fullscreen;
216#endif
217 }
[email protected]1e2172f2014-04-01 17:32:34218
[email protected]893124a22014-04-15 00:45:28219#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]1e2172f2014-04-01 17:32:34220 // If this key was registered by the user as a content editing hotkey, then
221 // it is not reserved.
[email protected]d5bedb6d2014-04-08 10:49:32222 ui::TextEditKeyBindingsDelegateAuraLinux* delegate =
[email protected]1e2172f2014-04-01 17:32:34223 ui::GetTextEditKeyBindingsDelegate();
[email protected]47e8e7542014-04-03 07:52:42224 if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL))
[email protected]1e2172f2014-04-01 17:32:34225 return false;
226#endif
227
Aran Gilmand217b5b2019-04-11 17:45:43228 return command_id == IDC_CLOSE_TAB || command_id == IDC_CLOSE_WINDOW ||
229 command_id == IDC_NEW_INCOGNITO_WINDOW || command_id == IDC_NEW_TAB ||
230 command_id == IDC_NEW_WINDOW || command_id == IDC_RESTORE_TAB ||
zijiehe13207802017-02-16 08:06:10231 command_id == IDC_SELECT_NEXT_TAB ||
Aran Gilmand217b5b2019-04-11 17:45:43232 command_id == IDC_SELECT_PREVIOUS_TAB || command_id == IDC_EXIT;
[email protected]5d98294912012-06-27 22:57:40233}
234
[email protected]5d98294912012-06-27 22:57:40235void BrowserCommandController::TabStateChanged() {
236 UpdateCommandsForTabState();
237}
238
[email protected]d93dbd12014-08-04 23:42:53239void BrowserCommandController::ZoomStateChanged() {
240 UpdateCommandsForZoomState();
241}
242
[email protected]5d98294912012-06-27 22:57:40243void BrowserCommandController::ContentRestrictionsChanged() {
244 UpdateCommandsForContentRestrictionState();
245}
246
247void BrowserCommandController::FullscreenStateChanged() {
[email protected]32dfede2013-08-25 15:48:25248 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40249}
250
Ivan Sandrk9669d0e2017-12-15 23:50:20251#if defined(OS_CHROMEOS)
252void BrowserCommandController::LockedFullscreenStateChanged() {
253 UpdateCommandsForLockedFullscreenMode();
254}
255#endif
256
[email protected]5d98294912012-06-27 22:57:40257void BrowserCommandController::PrintingStateChanged() {
258 UpdatePrintingState();
259}
260
261void BrowserCommandController::LoadingStateChanged(bool is_loading,
262 bool force) {
263 UpdateReloadStopState(is_loading, force);
264}
265
wittman76df71db32014-12-18 23:26:58266void BrowserCommandController::ExtensionStateChanged() {
267 // Extensions may disable the bookmark editing commands.
268 UpdateCommandsForBookmarkEditing();
269}
270
[email protected]5d98294912012-06-27 22:57:40271////////////////////////////////////////////////////////////////////////////////
Ivan Sandrk9669d0e2017-12-15 23:50:20272// BrowserCommandController, CommandUpdater implementation:
[email protected]5d98294912012-06-27 22:57:40273
Ivan Sandrk9669d0e2017-12-15 23:50:20274bool BrowserCommandController::SupportsCommand(int id) const {
275 return command_updater_.SupportsCommand(id);
276}
277
278bool BrowserCommandController::IsCommandEnabled(int id) const {
279 return command_updater_.IsCommandEnabled(id);
280}
281
Edwin Joe6f6fc1e2019-02-27 20:00:37282bool BrowserCommandController::ExecuteCommand(int id,
283 base::TimeTicks time_stamp) {
284 return ExecuteCommandWithDisposition(id, WindowOpenDisposition::CURRENT_TAB,
285 time_stamp);
Ivan Sandrk9669d0e2017-12-15 23:50:20286}
287
288bool BrowserCommandController::ExecuteCommandWithDisposition(
Edwin Joe6f6fc1e2019-02-27 20:00:37289 int id,
290 WindowOpenDisposition disposition,
291 base::TimeTicks time_stamp) {
Ivan Sandrk9669d0e2017-12-15 23:50:20292 // Doesn't go through the command_updater_ to avoid dealing with having a
293 // naming collision for ExecuteCommandWithDisposition (both
294 // CommandUpdaterDelegate and CommandUpdater declare this function so we
295 // choose to not implement CommandUpdaterDelegate inside this class and
296 // therefore command_updater_ doesn't have the delegate set).
297 if (!SupportsCommand(id) || !IsCommandEnabled(id))
298 return false;
299
[email protected]5d98294912012-06-27 22:57:40300 // No commands are enabled if there is not yet any selected tab.
301 // TODO(pkasting): It seems like we should not need this, because either
302 // most/all commands should not have been enabled yet anyway or the ones that
303 // are enabled should be global, or safe themselves against having no selected
304 // tab. However, Ben says he tried removing this before and got lots of
305 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
306 // window construction. This probably could use closer examination someday.
[email protected]59253a652012-11-20 00:17:26307 if (browser_->tab_strip_model()->active_index() == TabStripModel::kNoTab)
Ivan Sandrk9669d0e2017-12-15 23:50:20308 return true;
[email protected]5d98294912012-06-27 22:57:40309
Aran Gilmand217b5b2019-04-11 17:45:43310 DCHECK(command_updater_.IsCommandEnabled(id))
311 << "Invalid/disabled command " << id;
[email protected]5d98294912012-06-27 22:57:40312
[email protected]5d98294912012-06-27 22:57:40313 // The order of commands in this switch statement must match the function
314 // declaration order in browser.h!
315 switch (id) {
316 // Navigation commands
317 case IDC_BACK:
318 GoBack(browser_, disposition);
319 break;
320 case IDC_FORWARD:
321 GoForward(browser_, disposition);
322 break;
323 case IDC_RELOAD:
324 Reload(browser_, disposition);
325 break;
[email protected]58e29032012-08-06 20:19:57326 case IDC_RELOAD_CLEARING_CACHE:
327 ClearCache(browser_);
Nico Webera745ef72018-01-29 23:45:57328 FALLTHROUGH;
toyoshim7dad4b1182016-04-01 14:28:05329 case IDC_RELOAD_BYPASSING_CACHE:
330 ReloadBypassingCache(browser_, disposition);
[email protected]5d98294912012-06-27 22:57:40331 break;
332 case IDC_HOME:
333 Home(browser_, disposition);
334 break;
335 case IDC_OPEN_CURRENT_URL:
336 OpenCurrentURL(browser_);
337 break;
338 case IDC_STOP:
339 Stop(browser_);
340 break;
341
Aran Gilmand217b5b2019-04-11 17:45:43342 // Window management commands
[email protected]5d98294912012-06-27 22:57:40343 case IDC_NEW_WINDOW:
344 NewWindow(browser_);
345 break;
346 case IDC_NEW_INCOGNITO_WINDOW:
Orin Jaworski5e4bcd0c2018-10-16 19:35:05347 NewIncognitoWindow(profile());
[email protected]5d98294912012-06-27 22:57:40348 break;
349 case IDC_CLOSE_WINDOW:
bratell0a7406f2017-03-28 07:46:37350 base::RecordAction(base::UserMetricsAction("CloseWindowByKey"));
[email protected]04b9e692012-08-24 14:49:09351 CloseWindow(browser_);
[email protected]5d98294912012-06-27 22:57:40352 break;
Bettina Dea0a4505922017-09-28 00:53:32353 case IDC_NEW_TAB: {
354 NewTab(browser_);
355#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Catherine Chungbeb884222017-08-01 15:47:55356 // This is not in NewTab() to avoid tracking programmatic creation of new
357 // tabs by extensions.
Bettina Dea0a4505922017-09-28 00:53:32358 auto* new_tab_tracker =
359 feature_engagement::NewTabTrackerFactory::GetInstance()
360 ->GetForProfile(profile());
361
362 new_tab_tracker->OnNewTabOpened();
363 new_tab_tracker->CloseBubble();
Catherine Chungbeb884222017-08-01 15:47:55364#endif
[email protected]5d98294912012-06-27 22:57:40365 break;
Bettina Dea0a4505922017-09-28 00:53:32366 }
[email protected]5d98294912012-06-27 22:57:40367 case IDC_CLOSE_TAB:
bratell0a7406f2017-03-28 07:46:37368 base::RecordAction(base::UserMetricsAction("CloseTabByKey"));
[email protected]04b9e692012-08-24 14:49:09369 CloseTab(browser_);
[email protected]5d98294912012-06-27 22:57:40370 break;
371 case IDC_SELECT_NEXT_TAB:
bratell0a7406f2017-03-28 07:46:37372 base::RecordAction(base::UserMetricsAction("Accel_SelectNextTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37373 SelectNextTab(browser_,
374 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40375 break;
376 case IDC_SELECT_PREVIOUS_TAB:
bratell0a7406f2017-03-28 07:46:37377 base::RecordAction(base::UserMetricsAction("Accel_SelectPreviousTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37378 SelectPreviousTab(browser_,
379 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40380 break;
[email protected]5d98294912012-06-27 22:57:40381 case IDC_MOVE_TAB_NEXT:
382 MoveTabNext(browser_);
383 break;
384 case IDC_MOVE_TAB_PREVIOUS:
385 MoveTabPrevious(browser_);
386 break;
387 case IDC_SELECT_TAB_0:
388 case IDC_SELECT_TAB_1:
389 case IDC_SELECT_TAB_2:
390 case IDC_SELECT_TAB_3:
391 case IDC_SELECT_TAB_4:
392 case IDC_SELECT_TAB_5:
393 case IDC_SELECT_TAB_6:
394 case IDC_SELECT_TAB_7:
bratell0a7406f2017-03-28 07:46:37395 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37396 SelectNumberedTab(browser_, id - IDC_SELECT_TAB_0,
397 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40398 break;
399 case IDC_SELECT_LAST_TAB:
bratell0a7406f2017-03-28 07:46:37400 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
Edwin Joe6f6fc1e2019-02-27 20:00:37401 SelectLastTab(browser_,
402 {TabStripModel::GestureType::kKeyboard, time_stamp});
[email protected]5d98294912012-06-27 22:57:40403 break;
404 case IDC_DUPLICATE_TAB:
405 DuplicateTab(browser_);
406 break;
407 case IDC_RESTORE_TAB:
408 RestoreTab(browser_);
Collin Baker9bbe1d82019-03-08 01:16:27409 browser_->window()->OnTabRestored(IDC_RESTORE_TAB);
[email protected]5d98294912012-06-27 22:57:40410 break;
[email protected]5d98294912012-06-27 22:57:40411 case IDC_SHOW_AS_TAB:
412 ConvertPopupToTabbedBrowser(browser_);
413 break;
414 case IDC_FULLSCREEN:
[email protected]3f32b9b2012-07-09 16:59:28415 chrome::ToggleFullscreenMode(browser_);
[email protected]5d98294912012-06-27 22:57:40416 break;
Alan Cutter09965802018-03-27 07:25:29417 case IDC_OPEN_IN_PWA_WINDOW:
418 base::RecordAction(base::UserMetricsAction("OpenActiveTabInPwaWindow"));
419 ReparentSecureActiveTabIntoPwaWindow(browser_);
420 break;
[email protected]770c6d82012-09-06 22:21:32421
[email protected]d12cc5e2013-10-19 18:25:06422#if defined(OS_CHROMEOS)
423 case IDC_VISIT_DESKTOP_OF_LRU_USER_2:
[email protected]0c930812014-01-30 18:01:47424 case IDC_VISIT_DESKTOP_OF_LRU_USER_3:
zijiehe4dde8072017-02-13 20:38:35425 ExecuteVisitDesktopCommand(id, window()->GetNativeWindow());
[email protected]0c930812014-01-30 18:01:47426 break;
[email protected]d12cc5e2013-10-19 18:25:06427#endif
428
[email protected]893124a22014-04-15 00:45:28429#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15430 case IDC_MINIMIZE_WINDOW:
431 browser_->window()->Minimize();
432 break;
433 case IDC_MAXIMIZE_WINDOW:
434 browser_->window()->Maximize();
435 break;
436 case IDC_RESTORE_WINDOW:
437 browser_->window()->Restore();
438 break;
[email protected]af97be4c62014-02-13 14:43:34439 case IDC_USE_SYSTEM_TITLE_BAR: {
zijiehe4dde8072017-02-13 20:38:35440 PrefService* prefs = profile()->GetPrefs();
[email protected]af97be4c62014-02-13 14:43:34441 prefs->SetBoolean(prefs::kUseCustomChromeFrame,
442 !prefs->GetBoolean(prefs::kUseCustomChromeFrame));
443 break;
444 }
445#endif
446
[email protected]5d98294912012-06-27 22:57:40447#if defined(OS_MACOSX)
spqchanb8ffc7d2015-11-17 01:17:21448 case IDC_TOGGLE_FULLSCREEN_TOOLBAR:
449 chrome::ToggleFullscreenToolbar(browser_);
450 break;
spqchan2c5d541e2017-10-25 07:07:11451 case IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS: {
Robert Sesek03282612018-10-31 15:48:06452 chrome::ToggleJavaScriptFromAppleEventsAllowed(browser_);
spqchan2c5d541e2017-10-25 07:07:11453 break;
454 }
[email protected]5d98294912012-06-27 22:57:40455#endif
456 case IDC_EXIT:
457 Exit();
458 break;
459
460 // Page-related commands
461 case IDC_SAVE_PAGE:
462 SavePage(browser_);
463 break;
464 case IDC_BOOKMARK_PAGE:
Anatoly Pilikovee720922017-11-01 09:43:17465#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:14466 feature_engagement::BookmarkTrackerFactory::GetInstance()
467 ->GetForProfile(profile())
468 ->OnBookmarkAdded();
469#endif
deepak.m154a7f392014-12-15 04:41:43470 BookmarkCurrentPageAllowingExtensionOverrides(browser_);
[email protected]5d98294912012-06-27 22:57:40471 break;
[email protected]5d98294912012-06-27 22:57:40472 case IDC_BOOKMARK_ALL_TABS:
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
[email protected]5d98294912012-06-27 22:57:40478 BookmarkAllTabs(browser_);
479 break;
480 case IDC_VIEW_SOURCE:
Lukasz Anforowicze1b954d92017-10-30 21:28:06481 browser_->tab_strip_model()
482 ->GetActiveWebContents()
483 ->GetMainFrame()
484 ->ViewSource();
[email protected]5d98294912012-06-27 22:57:40485 break;
486 case IDC_EMAIL_PAGE_LOCATION:
487 EmailPageLocation(browser_);
488 break;
489 case IDC_PRINT:
490 Print(browser_);
491 break;
bondd052b5f82015-10-28 22:39:32492
Lei Zhang48a4a5262018-04-17 20:18:44493#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:55494 case IDC_BASIC_PRINT:
bratell0a7406f2017-03-28 07:46:37495 base::RecordAction(base::UserMetricsAction("Accel_Advanced_Print"));
vitalybukaf9433e42014-09-08 10:04:55496 BasicPrint(browser_);
[email protected]5d98294912012-06-27 22:57:40497 break;
Lei Zhang48a4a5262018-04-17 20:18:44498#endif // ENABLE_PRINTING
bondd052b5f82015-10-28 22:39:32499
bondd052b5f82015-10-28 22:39:32500 case IDC_SAVE_CREDIT_CARD_FOR_PAGE:
501 SaveCreditCard(browser_);
502 break;
siyua3e599eaa2018-07-13 00:23:06503 case IDC_MIGRATE_LOCAL_CREDIT_CARD_FOR_PAGE:
504 MigrateLocalCards(browser_);
505 break;
[email protected]e625b7602013-10-28 09:24:56506 case IDC_TRANSLATE_PAGE:
507 Translate(browser_);
508 break;
[email protected]4bee4432014-05-05 13:11:41509 case IDC_MANAGE_PASSWORDS_FOR_PAGE:
510 ManagePasswordsForPage(browser_);
511 break;
[email protected]4bee4432014-05-05 13:11:41512
[email protected]5d98294912012-06-27 22:57:40513 // Clipboard commands
514 case IDC_CUT:
[email protected]5d98294912012-06-27 22:57:40515 case IDC_COPY:
[email protected]5d98294912012-06-27 22:57:40516 case IDC_PASTE:
pkastingcd3f08bce2015-04-18 13:37:12517 CutCopyPaste(browser_, id);
[email protected]5d98294912012-06-27 22:57:40518 break;
519
520 // Find-in-page
521 case IDC_FIND:
522 Find(browser_);
523 break;
524 case IDC_FIND_NEXT:
525 FindNext(browser_);
526 break;
527 case IDC_FIND_PREVIOUS:
528 FindPrevious(browser_);
529 break;
530
531 // Zoom
532 case IDC_ZOOM_PLUS:
533 Zoom(browser_, content::PAGE_ZOOM_IN);
534 break;
535 case IDC_ZOOM_NORMAL:
536 Zoom(browser_, content::PAGE_ZOOM_RESET);
537 break;
538 case IDC_ZOOM_MINUS:
539 Zoom(browser_, content::PAGE_ZOOM_OUT);
540 break;
541
542 // Focus various bits of UI
543 case IDC_FOCUS_TOOLBAR:
bratell0a7406f2017-03-28 07:46:37544 base::RecordAction(base::UserMetricsAction("Accel_Focus_Toolbar"));
[email protected]5d98294912012-06-27 22:57:40545 FocusToolbar(browser_);
546 break;
547 case IDC_FOCUS_LOCATION:
bratell0a7406f2017-03-28 07:46:37548 base::RecordAction(base::UserMetricsAction("Accel_Focus_Location"));
[email protected]5d98294912012-06-27 22:57:40549 FocusLocationBar(browser_);
550 break;
551 case IDC_FOCUS_SEARCH:
bratell0a7406f2017-03-28 07:46:37552 base::RecordAction(base::UserMetricsAction("Accel_Focus_Search"));
[email protected]5d98294912012-06-27 22:57:40553 FocusSearch(browser_);
554 break;
555 case IDC_FOCUS_MENU_BAR:
556 FocusAppMenu(browser_);
557 break;
558 case IDC_FOCUS_BOOKMARKS:
bratell0a7406f2017-03-28 07:46:37559 base::RecordAction(base::UserMetricsAction("Accel_Focus_Bookmarks"));
[email protected]5d98294912012-06-27 22:57:40560 FocusBookmarksToolbar(browser_);
561 break;
David Tsengc0b1b642018-01-24 07:12:27562 case IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY:
563 FocusInactivePopupForAccessibility(browser_);
[email protected]822ca8c62013-04-19 00:49:15564 break;
[email protected]5d98294912012-06-27 22:57:40565 case IDC_FOCUS_NEXT_PANE:
566 FocusNextPane(browser_);
567 break;
568 case IDC_FOCUS_PREVIOUS_PANE:
569 FocusPreviousPane(browser_);
570 break;
571
572 // Show various bits of UI
573 case IDC_OPEN_FILE:
574 browser_->OpenFile();
575 break;
Alan Cutter81ac726682018-09-25 00:18:36576 case IDC_CREATE_SHORTCUT:
577 CreateBookmarkAppFromCurrentWebContents(browser_,
578 true /* force_shortcut_app */);
579 break;
580 case IDC_INSTALL_PWA:
581 CreateBookmarkAppFromCurrentWebContents(browser_,
582 false /* force_shortcut_app */);
[email protected]488e3952013-11-18 05:29:14583 break;
[email protected]5d98294912012-06-27 22:57:40584 case IDC_DEV_TOOLS:
[email protected]c934c382013-11-01 00:36:01585 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Show());
[email protected]5d98294912012-06-27 22:57:40586 break;
587 case IDC_DEV_TOOLS_CONSOLE:
einbinderdfa567b2016-12-16 01:15:52588 ToggleDevToolsWindow(browser_, DevToolsToggleAction::ShowConsolePanel());
[email protected]5d98294912012-06-27 22:57:40589 break;
[email protected]2056c3192013-10-21 22:40:51590 case IDC_DEV_TOOLS_DEVICES:
591 InspectUI::InspectDevices(browser_);
592 break;
[email protected]5d98294912012-06-27 22:57:40593 case IDC_DEV_TOOLS_INSPECT:
[email protected]c934c382013-11-01 00:36:01594 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Inspect());
[email protected]5d98294912012-06-27 22:57:40595 break;
[email protected]d16657c2012-09-03 14:25:10596 case IDC_DEV_TOOLS_TOGGLE:
[email protected]c934c382013-11-01 00:36:01597 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Toggle());
[email protected]d16657c2012-09-03 14:25:10598 break;
[email protected]5d98294912012-06-27 22:57:40599 case IDC_TASK_MANAGER:
[email protected]29c262de2013-06-22 15:39:38600 OpenTaskManager(browser_);
[email protected]5d98294912012-06-27 22:57:40601 break;
caelyn4e4e08a2015-02-04 21:27:49602#if defined(OS_CHROMEOS)
603 case IDC_TAKE_SCREENSHOT:
604 TakeScreenshot();
605 break;
606#endif
[email protected]236ad3022013-09-04 03:27:43607#if defined(GOOGLE_CHROME_BUILD)
[email protected]5d98294912012-06-27 22:57:40608 case IDC_FEEDBACK:
afakhryf4575bd2017-04-28 02:21:04609 OpenFeedbackDialog(browser_, kFeedbackSourceBrowserCommand);
[email protected]5d98294912012-06-27 22:57:40610 break;
[email protected]236ad3022013-09-04 03:27:43611#endif
[email protected]5d98294912012-06-27 22:57:40612 case IDC_SHOW_BOOKMARK_BAR:
613 ToggleBookmarkBar(browser_);
614 break;
615 case IDC_PROFILING_ENABLED:
Bryce Thomas96b07772018-11-07 03:04:15616 content::Profiling::Toggle();
[email protected]5d98294912012-06-27 22:57:40617 break;
618
619 case IDC_SHOW_BOOKMARK_MANAGER:
620 ShowBookmarkManager(browser_);
621 break;
622 case IDC_SHOW_APP_MENU:
bratell0a7406f2017-03-28 07:46:37623 base::RecordAction(base::UserMetricsAction("Accel_Show_App_Menu"));
[email protected]5d98294912012-06-27 22:57:40624 ShowAppMenu(browser_);
625 break;
626 case IDC_SHOW_AVATAR_MENU:
627 ShowAvatarMenu(browser_);
628 break;
629 case IDC_SHOW_HISTORY:
630 ShowHistory(browser_);
631 break;
632 case IDC_SHOW_DOWNLOADS:
633 ShowDownloads(browser_);
634 break;
635 case IDC_MANAGE_EXTENSIONS:
[email protected]bc9833c32013-02-28 04:05:08636 ShowExtensions(browser_, std::string());
[email protected]5d98294912012-06-27 22:57:40637 break;
638 case IDC_OPTIONS:
639 ShowSettings(browser_);
640 break;
641 case IDC_EDIT_SEARCH_ENGINES:
642 ShowSearchEngineSettings(browser_);
643 break;
644 case IDC_VIEW_PASSWORDS:
645 ShowPasswordManager(browser_);
646 break;
647 case IDC_CLEAR_BROWSING_DATA:
648 ShowClearBrowsingDataDialog(browser_);
649 break;
650 case IDC_IMPORT_SETTINGS:
651 ShowImportDialog(browser_);
652 break;
[email protected]9b7ab882012-09-10 23:46:36653 case IDC_TOGGLE_REQUEST_TABLET_SITE:
654 ToggleRequestTabletSite(browser_);
655 break;
[email protected]5d98294912012-06-27 22:57:40656 case IDC_ABOUT:
657 ShowAboutChrome(browser_);
658 break;
659 case IDC_UPGRADE_DIALOG:
660 OpenUpdateChromeDialog(browser_);
661 break;
[email protected]5d98294912012-06-27 22:57:40662 case IDC_HELP_PAGE_VIA_KEYBOARD:
663 ShowHelp(browser_, HELP_SOURCE_KEYBOARD);
664 break;
665 case IDC_HELP_PAGE_VIA_MENU:
666 ShowHelp(browser_, HELP_SOURCE_MENU);
667 break;
Bret Sepulveda2d018662017-05-18 21:31:48668 case IDC_SHOW_BETA_FORUM:
669 ShowBetaForum(browser_);
670 break;
David Roger7e25dff2019-02-07 09:03:17671#if !defined(OS_CHROMEOS)
estade8c0780f2015-08-21 23:36:41672 case IDC_SHOW_SIGNIN:
gogerald71bf6c902015-12-08 00:49:37673 ShowBrowserSigninOrSettings(
674 browser_, signin_metrics::AccessPoint::ACCESS_POINT_MENU);
estade8c0780f2015-08-21 23:36:41675 break;
David Roger7e25dff2019-02-07 09:03:17676#endif
[email protected]6bd370b2014-05-28 14:19:47677 case IDC_DISTILL_PAGE:
678 DistillCurrentPage(browser_);
679 break;
apacible45cbfc92015-09-28 22:45:41680 case IDC_ROUTE_MEDIA:
681 RouteMedia(browser_);
682 break;
Tommy Steimelc4477982017-11-29 18:07:18683 case IDC_WINDOW_MUTE_SITE:
684 MuteSite(browser_);
ellyjones0101ba02017-05-19 15:50:26685 break;
686 case IDC_WINDOW_PIN_TAB:
687 PinTab(browser_);
688 break;
Yann Dagocd13225a2019-03-07 18:39:05689 case IDC_SHOW_MANAGEMENT_PAGE: {
Yann Dagoc1d1c4af2019-04-17 13:40:51690 ShowSingletonTab(browser_, GURL(kChromeUIManagementURL));
Nicolas Ouellet-payeur82eb65b2018-11-05 16:49:27691 break;
Yann Dagocd13225a2019-03-07 18:39:05692 }
Christopher Lam0dbac2b2017-11-14 07:12:10693 // Hosted App commands
694 case IDC_COPY_URL:
695 CopyURL(browser_);
696 break;
697 case IDC_OPEN_IN_CHROME:
698 OpenInChrome(browser_);
699 break;
700 case IDC_SITE_SETTINGS:
701 ShowSiteSettings(
702 browser_,
703 browser_->tab_strip_model()->GetActiveWebContents()->GetVisibleURL());
704 break;
Alan Cutter0c3132302018-02-21 05:09:02705 case IDC_HOSTED_APP_MENU_APP_INFO:
706 ShowPageInfoDialog(browser_->tab_strip_model()->GetActiveWebContents(),
Alan Cutter689f89a2018-03-08 05:09:54707 bubble_anchor_util::kAppMenuButton);
Christopher Lam86b52712017-12-04 01:58:33708 break;
Christopher Lam0dbac2b2017-11-14 07:12:10709
[email protected]5d98294912012-06-27 22:57:40710 default:
711 LOG(WARNING) << "Received Unimplemented Command: " << id;
712 break;
713 }
Ivan Sandrk9669d0e2017-12-15 23:50:20714
715 return true;
716}
717
718void BrowserCommandController::AddCommandObserver(int id,
719 CommandObserver* observer) {
720 command_updater_.AddCommandObserver(id, observer);
721}
722
723void BrowserCommandController::RemoveCommandObserver(
Aran Gilmand217b5b2019-04-11 17:45:43724 int id,
725 CommandObserver* observer) {
Ivan Sandrk9669d0e2017-12-15 23:50:20726 command_updater_.RemoveCommandObserver(id, observer);
727}
728
729void BrowserCommandController::RemoveCommandObserver(
730 CommandObserver* observer) {
731 command_updater_.RemoveCommandObserver(observer);
732}
733
734bool BrowserCommandController::UpdateCommandEnabled(int id, bool state) {
735 if (is_locked_fullscreen_)
736 return false;
737
738 return command_updater_.UpdateCommandEnabled(id, state);
[email protected]5d98294912012-06-27 22:57:40739}
740
Mihai Sardarescuf87ccc12018-09-26 10:37:45741////////////////////////////////////////////////////////////////////////////////
742// BrowserCommandController, SigninPrefObserver implementation:
743
744void BrowserCommandController::OnSigninAllowedPrefChange() {
745 // For unit tests, we don't have a window.
746 if (!window())
747 return;
748 UpdateShowSyncState(IsShowingMainUI());
749}
750
[email protected]5d98294912012-06-27 22:57:40751// BrowserCommandController, TabStripModelObserver implementation:
752
sangwoo.ko1ae265f12018-10-18 08:30:28753void BrowserCommandController::OnTabStripModelChanged(
754 TabStripModel* tab_strip_model,
755 const TabStripModelChange& change,
756 const TabStripSelectionChange& selection) {
757 if (change.type() != TabStripModelChange::kInserted &&
758 change.type() != TabStripModelChange::kReplaced &&
759 change.type() != TabStripModelChange::kRemoved)
760 return;
[email protected]5d98294912012-06-27 22:57:40761
sangwoo.ko1ae265f12018-10-18 08:30:28762 for (const auto& delta : change.deltas()) {
763 content::WebContents* new_contents = nullptr;
764 content::WebContents* old_contents = nullptr;
765 if (change.type() == TabStripModelChange::kInserted) {
766 new_contents = delta.insert.contents;
767 } else if (change.type() == TabStripModelChange::kReplaced) {
768 new_contents = delta.replace.new_contents;
769 old_contents = delta.replace.old_contents;
770 } else {
771 old_contents = delta.remove.contents;
772 }
[email protected]5d98294912012-06-27 22:57:40773
sangwoo.ko1ae265f12018-10-18 08:30:28774 if (old_contents)
775 RemoveInterstitialObservers(old_contents);
776 if (new_contents)
777 AddInterstitialObservers(new_contents);
778 }
[email protected]5d98294912012-06-27 22:57:40779}
780
[email protected]3cac87232012-11-20 01:48:27781void BrowserCommandController::TabBlockedStateChanged(
782 content::WebContents* contents,
783 int index) {
784 PrintingStateChanged();
785 FullscreenStateChanged();
786 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:41787 UpdateCommandsForMediaRouter();
[email protected]3cac87232012-11-20 01:48:27788}
789
[email protected]5d98294912012-06-27 22:57:40790////////////////////////////////////////////////////////////////////////////////
791// BrowserCommandController, TabRestoreServiceObserver implementation:
792
793void BrowserCommandController::TabRestoreServiceChanged(
blundell74001adc2015-09-18 11:04:25794 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53795 UpdateTabRestoreCommandState();
[email protected]5d98294912012-06-27 22:57:40796}
797
798void BrowserCommandController::TabRestoreServiceDestroyed(
blundell74001adc2015-09-18 11:04:25799 sessions::TabRestoreService* service) {
[email protected]5d98294912012-06-27 22:57:40800 service->RemoveObserver(this);
801}
802
[email protected]2e9369e2014-08-15 09:12:53803void BrowserCommandController::TabRestoreServiceLoaded(
blundell74001adc2015-09-18 11:04:25804 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53805 UpdateTabRestoreCommandState();
806}
807
[email protected]5d98294912012-06-27 22:57:40808////////////////////////////////////////////////////////////////////////////////
[email protected]5d98294912012-06-27 22:57:40809// BrowserCommandController, private:
810
[email protected]20ca0382013-02-28 19:50:07811class BrowserCommandController::InterstitialObserver
812 : public content::WebContentsObserver {
813 public:
814 InterstitialObserver(BrowserCommandController* controller,
815 content::WebContents* web_contents)
Aran Gilmand217b5b2019-04-11 17:45:43816 : WebContentsObserver(web_contents), controller_(controller) {}
[email protected]20ca0382013-02-28 19:50:07817
dcheng5dd5ff62014-10-21 12:42:38818 void DidAttachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07819 controller_->UpdateCommandsForTabState();
820 }
821
dcheng5dd5ff62014-10-21 12:42:38822 void DidDetachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07823 controller_->UpdateCommandsForTabState();
824 }
825
826 private:
827 BrowserCommandController* controller_;
828
829 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver);
830};
831
[email protected]6a414ff2013-02-27 08:22:54832bool BrowserCommandController::IsShowingMainUI() {
manukf1a116392018-10-25 16:28:24833 return browser_->SupportsWindowFeature(Browser::FEATURE_TABSTRIP);
834}
835
836bool BrowserCommandController::IsShowingLocationBar() {
837 return browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
[email protected]5d98294912012-06-27 22:57:40838}
839
840void BrowserCommandController::InitCommandState() {
841 // All browser commands whose state isn't set automagically some other way
842 // (like Back & Forward with initial page load) must have their state
843 // initialized here, otherwise they will be forever disabled.
844
Ivan Sandrk9669d0e2017-12-15 23:50:20845 if (is_locked_fullscreen_)
846 return;
847
[email protected]5d98294912012-06-27 22:57:40848 // Navigation commands
849 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true);
toyoshim7dad4b1182016-04-01 14:28:05850 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE, true);
[email protected]58e29032012-08-06 20:19:57851 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, true);
[email protected]5d98294912012-06-27 22:57:40852
853 // Window management commands
854 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true);
855 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true);
856 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true);
857 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true);
[email protected]2e9369e2014-08-15 09:12:53858 UpdateTabRestoreCommandState();
[email protected]d28d3782013-02-26 16:31:55859 command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
[email protected]5d98294912012-06-27 22:57:40860 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true);
[email protected]d12cc5e2013-10-19 18:25:06861#if defined(OS_CHROMEOS)
James Cook934abaf2017-09-19 22:21:58862 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
[email protected]d12cc5e2013-10-19 18:25:06863 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_2, true);
864 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_3, true);
865#endif
[email protected]893124a22014-04-15 00:45:28866#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15867 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
868 command_updater_.UpdateCommandEnabled(IDC_MAXIMIZE_WINDOW, true);
869 command_updater_.UpdateCommandEnabled(IDC_RESTORE_WINDOW, true);
Maksim Sisovac767592018-08-10 08:00:15870 bool use_system_title_bar = true;
871#if defined(USE_OZONE)
872 use_system_title_bar = ui::OzonePlatform::GetInstance()
873 ->GetPlatformProperties()
874 .use_system_title_bar;
875#endif
876 command_updater_.UpdateCommandEnabled(IDC_USE_SYSTEM_TITLE_BAR,
877 use_system_title_bar);
[email protected]af97be4c62014-02-13 14:43:34878#endif
Alan Cutter09965802018-03-27 07:25:29879 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW, true);
[email protected]5d98294912012-06-27 22:57:40880
881 // Page-related commands
882 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true);
[email protected]4bee4432014-05-05 13:11:41883 command_updater_.UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE, true);
[email protected]5d98294912012-06-27 22:57:40884
885 // Zoom
886 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true);
887 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true);
[email protected]d93dbd12014-08-04 23:42:53888 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, false);
[email protected]5d98294912012-06-27 22:57:40889 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
890
891 // Show various bits of UI
Aran Gilmand217b5b2019-04-11 17:45:43892 const bool guest_session =
893 profile()->IsGuestSession() || profile()->IsSystemProfile();
mlerman7831f57d2015-05-25 11:40:15894 DCHECK(!profile()->IsSystemProfile())
895 << "Ought to never have browser for the system profile.";
[email protected]338416c02014-05-13 16:47:06896 const bool normal_window = browser_->is_type_tabbed();
[email protected]05454532013-01-22 21:09:08897 UpdateOpenFileState(&command_updater_);
[email protected]5d98294912012-06-27 22:57:40898 UpdateCommandsForDevTools();
899 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager());
[email protected]338416c02014-05-13 16:47:06900 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session);
[email protected]5d98294912012-06-27 22:57:40901 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
[email protected]674b65672014-06-02 23:21:56902 command_updater_.UpdateCommandEnabled(IDC_HELP_MENU, true);
[email protected]5d98294912012-06-27 22:57:40903 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
904 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
Bret Sepulveda2d018662017-05-18 21:31:48905 command_updater_.UpdateCommandEnabled(IDC_SHOW_BETA_FORUM, true);
[email protected]338416c02014-05-13 16:47:06906 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session);
Aran Gilmand217b5b2019-04-11 17:45:43907 command_updater_.UpdateCommandEnabled(
908 IDC_RECENT_TABS_MENU, !guest_session && !profile()->IsOffTheRecord());
tsergeant341a8272017-04-18 03:54:33909 command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA,
910 !guest_session);
[email protected]39d47592014-01-10 21:42:45911#if defined(OS_CHROMEOS)
caelyn4e4e08a2015-02-04 21:27:49912 command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true);
Ramin Halavatif362b7a2019-04-17 05:24:50913 // Chrome OS uses the system tray menu to handle multi-profiles. Avatar menu
914 // is only required in incognito mode.
915 if (profile()->IsIncognito())
[email protected]338416c02014-05-13 16:47:06916 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
Ramin Halavatif362b7a2019-04-17 05:24:50917#else
918 if (normal_window)
919 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
[email protected]39d47592014-01-10 21:42:45920#endif
[email protected]5d98294912012-06-27 22:57:40921
Mihai Sardarescu2ec5205682018-09-26 09:20:05922 UpdateShowSyncState(true);
923
[email protected]5d98294912012-06-27 22:57:40924 // Navigation commands
Christopher Camerone1385742019-04-05 20:37:25925 command_updater_.UpdateCommandEnabled(IDC_HOME,
926 normal_window || browser_->is_app());
[email protected]5d98294912012-06-27 22:57:40927
Christopher Lam0dbac2b2017-11-14 07:12:10928 const bool is_experimental_hosted_app =
Yining Wang9ba7465f32019-04-12 19:58:24929 WebAppBrowserController::IsForExperimentalWebAppBrowser(browser_);
Christopher Lam0dbac2b2017-11-14 07:12:10930 // Hosted app browser commands.
931 command_updater_.UpdateCommandEnabled(IDC_COPY_URL,
932 is_experimental_hosted_app);
933 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_CHROME,
934 is_experimental_hosted_app);
935 command_updater_.UpdateCommandEnabled(IDC_SITE_SETTINGS,
936 is_experimental_hosted_app);
Alan Cutter0c3132302018-02-21 05:09:02937 command_updater_.UpdateCommandEnabled(IDC_HOSTED_APP_MENU_APP_INFO,
Christopher Lam86b52712017-12-04 01:58:33938 is_experimental_hosted_app);
Christopher Lam0dbac2b2017-11-14 07:12:10939
[email protected]5d98294912012-06-27 22:57:40940 // Window management commands
[email protected]5d98294912012-06-27 22:57:40941 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window);
Aran Gilmand217b5b2019-04-11 17:45:43942 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB, normal_window);
[email protected]5d98294912012-06-27 22:57:40943 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window);
944 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window);
945 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window);
946 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window);
947 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window);
948 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window);
949 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window);
950 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window);
951 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window);
952 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window);
953 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window);
[email protected]5d98294912012-06-27 22:57:40954
[email protected]338416c02014-05-13 16:47:06955 // These are always enabled; the menu determines their menu item visibility.
[email protected]5d98294912012-06-27 22:57:40956 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
[email protected]5d98294912012-06-27 22:57:40957
[email protected]6bd370b2014-05-28 14:19:47958 // Distill current page.
959 command_updater_.UpdateCommandEnabled(
avi556c05022014-12-22 23:31:43960 IDC_DISTILL_PAGE, base::CommandLine::ForCurrentProcess()->HasSwitch(
961 switches::kEnableDomDistiller));
[email protected]6bd370b2014-05-28 14:19:47962
Tommy Steimelc4477982017-11-29 18:07:18963 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE, normal_window);
ellyjones0101ba02017-05-19 15:50:26964 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, normal_window);
965
[email protected]338416c02014-05-13 16:47:06966 // Initialize other commands whose state changes based on various conditions.
[email protected]32dfede2013-08-25 15:48:25967 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40968 UpdateCommandsForContentRestrictionState();
[email protected]5d98294912012-06-27 22:57:40969 UpdateCommandsForBookmarkEditing();
[email protected]5d98294912012-06-27 22:57:40970 UpdateCommandsForIncognitoAvailability();
971}
972
[email protected]05454532013-01-22 21:09:08973// static
974void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
975 CommandUpdater* command_updater,
976 Profile* profile) {
mlermane01e6de2014-09-29 19:26:47977 const bool guest_session = profile->IsGuestSession();
978 // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession().
[email protected]5d98294912012-06-27 22:57:40979 IncognitoModePrefs::Availability incognito_availability =
[email protected]05454532013-01-22 21:09:08980 IncognitoModePrefs::GetAvailability(profile->GetPrefs());
981 command_updater->UpdateCommandEnabled(
Aran Gilmand217b5b2019-04-11 17:45:43982 IDC_NEW_WINDOW, incognito_availability != IncognitoModePrefs::FORCED);
[email protected]05454532013-01-22 21:09:08983 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40984 IDC_NEW_INCOGNITO_WINDOW,
mlermane01e6de2014-09-29 19:26:47985 incognito_availability != IncognitoModePrefs::DISABLED && !guest_session);
[email protected]5d98294912012-06-27 22:57:40986
[email protected]57b25292014-05-01 16:31:06987 const bool forced_incognito =
988 incognito_availability == IncognitoModePrefs::FORCED ||
989 guest_session; // Guest always runs in Incognito mode.
[email protected]05454532013-01-22 21:09:08990 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40991 IDC_SHOW_BOOKMARK_MANAGER,
[email protected]57b25292014-05-01 16:31:06992 browser_defaults::bookmarks_enabled && !forced_incognito);
Devlin Cronin21dba422018-05-30 15:45:16993 extensions::ExtensionService* extension_service =
[email protected]03d25812014-06-22 19:41:55994 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]57b25292014-05-01 16:31:06995 const bool enable_extensions =
[email protected]5d98294912012-06-27 22:57:40996 extension_service && extension_service->extensions_enabled();
[email protected]5d98294912012-06-27 22:57:40997
[email protected]57b25292014-05-01 16:31:06998 // Bookmark manager and settings page/subpages are forced to open in normal
999 // mode. For this reason we disable these commands when incognito is forced.
1000 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
1001 enable_extensions && !forced_incognito);
1002
1003 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito);
1004 command_updater->UpdateCommandEnabled(IDC_OPTIONS,
1005 !forced_incognito || guest_session);
estade8c0780f2015-08-21 23:36:411006 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito);
[email protected]05454532013-01-22 21:09:081007}
1008
1009void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
Ivan Sandrk9669d0e2017-12-15 23:50:201010 if (is_locked_fullscreen_)
1011 return;
1012
[email protected]05454532013-01-22 21:09:081013 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile());
1014
[email protected]6a414ff2013-02-27 08:22:541015 if (!IsShowingMainUI()) {
[email protected]05454532013-01-22 21:09:081016 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false);
1017 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false);
1018 }
[email protected]5d98294912012-06-27 22:57:401019}
1020
1021void BrowserCommandController::UpdateCommandsForTabState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201022 if (is_locked_fullscreen_)
1023 return;
1024
[email protected]617ee962013-01-29 20:49:121025 WebContents* current_web_contents =
1026 browser_->tab_strip_model()->GetActiveWebContents();
[email protected]1c5119c2012-09-19 00:08:571027 if (!current_web_contents) // May be NULL during tab restore.
[email protected]5d98294912012-06-27 22:57:401028 return;
[email protected]5d98294912012-06-27 22:57:401029
1030 // Navigation commands
1031 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_));
1032 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_));
1033 command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_));
toyoshim7dad4b1182016-04-01 14:28:051034 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE,
[email protected]5d98294912012-06-27 22:57:401035 CanReload(browser_));
[email protected]58e29032012-08-06 20:19:571036 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE,
1037 CanReload(browser_));
[email protected]5d98294912012-06-27 22:57:401038
1039 // Window management commands
Aran Gilmand217b5b2019-04-11 17:45:431040 command_updater_.UpdateCommandEnabled(
1041 IDC_DUPLICATE_TAB, !browser_->is_app() && CanDuplicateTab(browser_));
Tommy Steimelc4477982017-11-29 18:07:181042 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE,
ellyjones0101ba02017-05-19 15:50:261043 !browser_->is_app());
1044 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB,
1045 !browser_->is_app());
[email protected]5d98294912012-06-27 22:57:401046
1047 // Page-related commands
1048 window()->SetStarredState(
[email protected]1c5119c2012-09-19 00:08:571049 BookmarkTabHelper::FromWebContents(current_web_contents)->is_starred());
[email protected]5423c372012-08-22 05:50:161050 window()->ZoomChangedForActiveTab(false);
[email protected]5d98294912012-06-27 22:57:401051 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
1052 CanViewSource(browser_));
1053 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION,
1054 CanEmailPageLocation(browser_));
1055 if (browser_->is_devtools())
1056 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false);
1057
Alan Cutter81ac726682018-09-25 00:18:361058 bool can_create_bookmark_app = CanCreateBookmarkApp(browser_);
1059 command_updater_.UpdateCommandEnabled(IDC_INSTALL_PWA,
1060 can_create_bookmark_app);
1061 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUT,
1062 can_create_bookmark_app);
Alan Cutter403cebb2018-05-17 05:22:451063 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW,
Alan Cutter81ac726682018-09-25 00:18:361064 can_create_bookmark_app);
[email protected]5d98294912012-06-27 22:57:401065
[email protected]9b7ab882012-09-10 23:46:361066 command_updater_.UpdateCommandEnabled(
1067 IDC_TOGGLE_REQUEST_TABLET_SITE,
1068 CanRequestTabletSite(current_web_contents));
1069
[email protected]5d98294912012-06-27 22:57:401070 UpdateCommandsForContentRestrictionState();
1071 UpdateCommandsForBookmarkEditing();
[email protected]3cac87232012-11-20 01:48:271072 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:411073 UpdateCommandsForMediaRouter();
[email protected]d93dbd12014-08-04 23:42:531074 // Update the zoom commands when an active tab is selected.
1075 UpdateCommandsForZoomState();
1076}
1077
1078void BrowserCommandController::UpdateCommandsForZoomState() {
Aran Gilmand217b5b2019-04-11 17:45:431079 WebContents* contents = browser_->tab_strip_model()->GetActiveWebContents();
[email protected]d93dbd12014-08-04 23:42:531080 if (!contents)
1081 return;
Aran Gilmand217b5b2019-04-11 17:45:431082 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, CanZoomIn(contents));
a.sarkar.arundaadc712015-02-26 05:39:081083 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL,
ccameronb7c1d6c2015-03-09 17:08:241084 CanResetZoom(contents));
Aran Gilmand217b5b2019-04-11 17:45:431085 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, CanZoomOut(contents));
[email protected]5d98294912012-06-27 22:57:401086}
1087
1088void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
1089 int restrictions = GetContentRestrictions(browser_);
1090
1091 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011092 IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY));
[email protected]5d98294912012-06-27 22:57:401093 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011094 IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT));
[email protected]5d98294912012-06-27 22:57:401095 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011096 IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE));
[email protected]5d98294912012-06-27 22:57:401097 UpdateSaveAsState();
1098 UpdatePrintingState();
1099}
1100
1101void BrowserCommandController::UpdateCommandsForDevTools() {
Ivan Sandrk9669d0e2017-12-15 23:50:201102 if (is_locked_fullscreen_)
1103 return;
1104
Pavol Marko56df0272018-07-04 17:55:041105 bool dev_tools_enabled = DevToolsWindow::AllowDevToolsFor(
1106 profile(), browser_->tab_strip_model()->GetActiveWebContents());
Aran Gilmand217b5b2019-04-11 17:45:431107 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS, dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401108 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE,
1109 dev_tools_enabled);
[email protected]2056c3192013-10-21 22:40:511110 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES,
1111 dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401112 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT,
1113 dev_tools_enabled);
[email protected]d16657c2012-09-03 14:25:101114 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE,
1115 dev_tools_enabled);
spqchan2c5d541e2017-10-25 07:07:111116#if defined(OS_MACOSX)
1117 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS,
1118 dev_tools_enabled);
1119#endif
[email protected]5d98294912012-06-27 22:57:401120}
1121
1122void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
Ivan Sandrk9669d0e2017-12-15 23:50:201123 if (is_locked_fullscreen_)
1124 return;
1125
[email protected]5d98294912012-06-27 22:57:401126 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE,
1127 CanBookmarkCurrentPage(browser_));
1128 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
1129 CanBookmarkAllTabs(browser_));
thestig5149d272014-10-30 07:25:291130#if defined(OS_WIN)
1131 command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN, true);
1132#endif
[email protected]5d98294912012-06-27 22:57:401133}
1134
1135void BrowserCommandController::UpdateCommandsForBookmarkBar() {
Ivan Sandrk9669d0e2017-12-15 23:50:201136 if (is_locked_fullscreen_)
1137 return;
1138
tfarina3bddbe112014-08-28 05:29:321139 command_updater_.UpdateCommandEnabled(
Aran Gilmand217b5b2019-04-11 17:45:431140 IDC_SHOW_BOOKMARK_BAR, browser_defaults::bookmarks_enabled &&
1141 !profile()->IsGuestSession() &&
1142 !profile()->IsSystemProfile() &&
1143 !profile()->GetPrefs()->IsManagedPreference(
1144 bookmarks::prefs::kShowBookmarkBar) &&
1145 IsShowingMainUI());
[email protected]5d98294912012-06-27 22:57:401146}
1147
[email protected]9ec3ea5b2012-12-03 18:14:301148void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
Ivan Sandrk9669d0e2017-12-15 23:50:201149 if (is_locked_fullscreen_)
1150 return;
1151
[email protected]9ec3ea5b2012-12-03 18:14:301152 UpdateSaveAsState();
[email protected]05454532013-01-22 21:09:081153 UpdateOpenFileState(&command_updater_);
[email protected]9ec3ea5b2012-12-03 18:14:301154}
1155
[email protected]32dfede2013-08-25 15:48:251156void BrowserCommandController::UpdateCommandsForFullscreenMode() {
Ivan Sandrk9669d0e2017-12-15 23:50:201157 if (is_locked_fullscreen_)
1158 return;
1159
zijiehe3c7af992017-02-12 20:59:401160 const bool is_fullscreen = window() && window()->IsFullscreen();
1161 const bool show_main_ui = IsShowingMainUI();
manukf1a116392018-10-25 16:28:241162 const bool show_location_bar = IsShowingLocationBar();
1163
zijiehe3c7af992017-02-12 20:59:401164 const bool main_not_fullscreen = show_main_ui && !is_fullscreen;
[email protected]5d98294912012-06-27 22:57:401165
1166 // Navigation commands
1167 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1168
1169 // Window management commands
1170 command_updater_.UpdateCommandEnabled(
Aran Gilmand217b5b2019-04-11 17:45:431171 IDC_SHOW_AS_TAB, !browser_->is_type_tabbed() && !is_fullscreen);
[email protected]5d98294912012-06-27 22:57:401172
1173 // Focus various bits of UI
1174 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
manukf1a116392018-10-25 16:28:241175 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_location_bar);
[email protected]5d98294912012-06-27 22:57:401176 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
Aran Gilmand217b5b2019-04-11 17:45:431177 command_updater_.UpdateCommandEnabled(IDC_FOCUS_MENU_BAR,
1178 main_not_fullscreen);
1179 command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE,
1180 main_not_fullscreen);
1181 command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE,
1182 main_not_fullscreen);
1183 command_updater_.UpdateCommandEnabled(IDC_FOCUS_BOOKMARKS,
1184 main_not_fullscreen);
[email protected]822ca8c62013-04-19 00:49:151185 command_updater_.UpdateCommandEnabled(
David Tsengc0b1b642018-01-24 07:12:271186 IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY, main_not_fullscreen);
[email protected]5d98294912012-06-27 22:57:401187
1188 // Show various bits of UI
1189 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431190#if defined(GOOGLE_CHROME_BUILD)
Fabio Rocha19bf4262019-04-04 01:05:181191 command_updater_.UpdateCommandEnabled(
1192 IDC_FEEDBACK, show_main_ui || browser_->is_devtools());
[email protected]236ad3022013-09-04 03:27:431193#endif
Mihai Sardarescu2ec5205682018-09-26 09:20:051194 UpdateShowSyncState(show_main_ui);
[email protected]5d98294912012-06-27 22:57:401195
[email protected]5d98294912012-06-27 22:57:401196 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
1197 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
1198 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
1199 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
Tina Wangf09681ac2019-03-27 20:52:101200 command_updater_.UpdateCommandEnabled(IDC_SEND_TAB_TO_SELF, show_main_ui);
Yann Dago70ca3dd2019-02-27 01:12:351201 command_updater_.UpdateCommandEnabled(IDC_SHOW_MANAGEMENT_PAGE, true);
primianod3a81ab2016-01-25 22:21:151202
1203 if (base::debug::IsProfilingSupported())
1204 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
[email protected]5d98294912012-06-27 22:57:401205
[email protected]aeafc3852014-04-29 16:51:291206#if !defined(OS_MACOSX)
zijiehe3c7af992017-02-12 20:59:401207 // Disable toggling into fullscreen mode if disallowed by pref.
Aran Gilmand217b5b2019-04-11 17:45:431208 const bool fullscreen_enabled =
1209 is_fullscreen ||
zijiehe3c7af992017-02-12 20:59:401210 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed);
1211#else
1212 const bool fullscreen_enabled = true;
[email protected]00a1cc5b2012-11-07 13:44:511213#endif
1214
1215 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled);
spqchanb8ffc7d2015-11-17 01:17:211216 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR,
1217 fullscreen_enabled);
[email protected]5d98294912012-06-27 22:57:401218
1219 UpdateCommandsForBookmarkBar();
zijiehedb473d552017-02-24 01:13:411220 UpdateCommandsForIncognitoAvailability();
Alan Cutter167dfe82018-04-11 09:06:001221 UpdateCommandsForHostedAppAvailability();
1222}
1223
1224void BrowserCommandController::UpdateCommandsForHostedAppAvailability() {
1225 bool has_toolbar =
1226 browser_->is_type_tabbed() ||
Yining Wang9ba7465f32019-04-12 19:58:241227 WebAppBrowserController::IsForExperimentalWebAppBrowser(browser_);
Alan Cutter167dfe82018-04-11 09:06:001228 if (window() && window()->ShouldHideUIForFullscreen())
1229 has_toolbar = false;
1230 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, has_toolbar);
1231 command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE, has_toolbar);
1232 command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE, has_toolbar);
1233 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, has_toolbar);
[email protected]5d98294912012-06-27 22:57:401234}
1235
Ivan Sandrk9669d0e2017-12-15 23:50:201236#if defined(OS_CHROMEOS)
1237namespace {
1238
1239#if DCHECK_IS_ON()
1240// Makes sure that all commands that are not whitelisted are disabled. DCHECKs
1241// otherwise. Compiled only in debug mode.
1242void NonWhitelistedCommandsAreDisabled(CommandUpdaterImpl* command_updater) {
Ivan Sandrk6ac9c9a2018-12-14 14:15:071243 constexpr int kWhitelistedIds[] = {IDC_CUT, IDC_COPY, IDC_PASTE};
Ivan Sandrk9669d0e2017-12-15 23:50:201244
1245 // Go through all the command ids, skip the whitelisted ones.
1246 for (int id : command_updater->GetAllIds()) {
Haeun Kim3f6123502018-08-26 18:03:041247 if (base::ContainsValue(kWhitelistedIds, id)) {
Ivan Sandrk9669d0e2017-12-15 23:50:201248 continue;
1249 }
1250 DCHECK(!command_updater->IsCommandEnabled(id));
1251 }
1252}
1253#endif
1254
1255} // namespace
1256
1257void BrowserCommandController::UpdateCommandsForLockedFullscreenMode() {
Ivan Sandrke0e92452019-03-21 09:32:481258 bool is_locked_fullscreen =
1259 platform_util::IsBrowserLockedFullscreen(browser_);
Ivan Sandrk9669d0e2017-12-15 23:50:201260 // Sanity check to make sure this function is called only on state change.
1261 DCHECK_NE(is_locked_fullscreen, is_locked_fullscreen_);
1262 if (is_locked_fullscreen == is_locked_fullscreen_)
1263 return;
1264 is_locked_fullscreen_ = is_locked_fullscreen;
1265
1266 if (is_locked_fullscreen_) {
1267 command_updater_.DisableAllCommands();
1268 // Update the state of whitelisted commands:
1269 // IDC_CUT/IDC_COPY/IDC_PASTE,
1270 UpdateCommandsForContentRestrictionState();
Ivan Sandrk6ac9c9a2018-12-14 14:15:071271 // TODO(crbug.com/904637): Re-enable Find and Zoom in locked fullscreen.
Ivan Sandrk9669d0e2017-12-15 23:50:201272 // All other commands will be disabled (there is an early return in their
1273 // corresponding UpdateCommandsFor* functions).
1274#if DCHECK_IS_ON()
1275 NonWhitelistedCommandsAreDisabled(&command_updater_);
1276#endif
1277 } else {
1278 // Do an init call to re-initialize command state after the
1279 // DisableAllCommands.
1280 InitCommandState();
1281 }
1282}
1283#endif
1284
[email protected]5d98294912012-06-27 22:57:401285void BrowserCommandController::UpdatePrintingState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201286 if (is_locked_fullscreen_)
1287 return;
1288
[email protected]d53e4032012-06-29 18:58:341289 bool print_enabled = CanPrint(browser_);
1290 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
Lei Zhang48a4a5262018-04-17 20:18:441291#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:551292 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT,
1293 CanBasicPrint(browser_));
Lei Zhang48a4a5262018-04-17 20:18:441294#endif
[email protected]5d98294912012-06-27 22:57:401295}
1296
1297void BrowserCommandController::UpdateSaveAsState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201298 if (is_locked_fullscreen_)
1299 return;
1300
[email protected]5d98294912012-06-27 22:57:401301 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_));
1302}
1303
Mihai Sardarescu2ec5205682018-09-26 09:20:051304void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) {
1305 if (is_locked_fullscreen_)
1306 return;
1307
Mihai Sardarescuf87ccc12018-09-26 10:37:451308 command_updater_.UpdateCommandEnabled(
Mihai Sardarescu290bc882018-10-12 10:48:141309 IDC_SHOW_SIGNIN, show_main_ui && pref_signin_allowed_.GetValue());
Mihai Sardarescu2ec5205682018-09-26 09:20:051310}
1311
[email protected]05454532013-01-22 21:09:081312// static
1313void BrowserCommandController::UpdateOpenFileState(
1314 CommandUpdater* command_updater) {
[email protected]5d98294912012-06-27 22:57:401315 bool enabled = true;
1316 PrefService* local_state = g_browser_process->local_state();
1317 if (local_state)
1318 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs);
1319
[email protected]05454532013-01-22 21:09:081320 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled);
[email protected]5d98294912012-06-27 22:57:401321}
1322
1323void BrowserCommandController::UpdateReloadStopState(bool is_loading,
1324 bool force) {
Ivan Sandrk9669d0e2017-12-15 23:50:201325 if (is_locked_fullscreen_)
1326 return;
1327
[email protected]5d98294912012-06-27 22:57:401328 window()->UpdateReloadStopState(is_loading, force);
1329 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
1330}
1331
[email protected]2e9369e2014-08-15 09:12:531332void BrowserCommandController::UpdateTabRestoreCommandState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201333 if (is_locked_fullscreen_)
1334 return;
1335
blundell74001adc2015-09-18 11:04:251336 sessions::TabRestoreService* tab_restore_service =
[email protected]2e9369e2014-08-15 09:12:531337 TabRestoreServiceFactory::GetForProfile(profile());
1338 // The command is enabled if the service hasn't loaded yet to trigger loading.
1339 // The command is updated once the load completes.
1340 command_updater_.UpdateCommandEnabled(
1341 IDC_RESTORE_TAB,
1342 tab_restore_service &&
Aran Gilmand217b5b2019-04-11 17:45:431343 (!tab_restore_service->IsLoaded() ||
1344 GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE));
[email protected]2e9369e2014-08-15 09:12:531345}
1346
[email protected]3cac87232012-11-20 01:48:271347void BrowserCommandController::UpdateCommandsForFind() {
1348 TabStripModel* model = browser_->tab_strip_model();
Aran Gilmand217b5b2019-04-11 17:45:431349 bool enabled =
1350 !model->IsTabBlocked(model->active_index()) && !browser_->is_devtools();
[email protected]3cac87232012-11-20 01:48:271351
1352 command_updater_.UpdateCommandEnabled(IDC_FIND, enabled);
1353 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled);
1354 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled);
1355}
1356
apacible45cbfc92015-09-28 22:45:411357void BrowserCommandController::UpdateCommandsForMediaRouter() {
Ivan Sandrk9669d0e2017-12-15 23:50:201358 if (is_locked_fullscreen_)
1359 return;
1360
apacible45cbfc92015-09-28 22:45:411361 command_updater_.UpdateCommandEnabled(IDC_ROUTE_MEDIA,
1362 CanRouteMedia(browser_));
1363}
1364
[email protected]409ea2972012-11-10 19:54:431365void BrowserCommandController::AddInterstitialObservers(WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071366 interstitial_observers_.push_back(new InterstitialObserver(this, contents));
[email protected]5d98294912012-06-27 22:57:401367}
1368
1369void BrowserCommandController::RemoveInterstitialObservers(
[email protected]e89cfcb2012-11-11 14:47:241370 WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071371 for (size_t i = 0; i < interstitial_observers_.size(); i++) {
1372 if (interstitial_observers_[i]->web_contents() != contents)
1373 continue;
1374
1375 delete interstitial_observers_[i];
1376 interstitial_observers_.erase(interstitial_observers_.begin() + i);
1377 return;
1378 }
[email protected]5d98294912012-06-27 22:57:401379}
1380
1381BrowserWindow* BrowserCommandController::window() {
1382 return browser_->window();
1383}
1384
1385Profile* BrowserCommandController::profile() {
1386 return browser_->profile();
1387}
1388
[email protected]5d98294912012-06-27 22:57:401389} // namespace chrome