blob: 2d6c070ad320b4f7cf70069e182aada408b9ff72 [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"
benwells39f23ae2014-08-27 08:01:5225#include "chrome/browser/extensions/extension_util.h"
[email protected]2e9d79f2013-08-16 05:45:5626#include "chrome/browser/lifetime/application_lifetime.h"
[email protected]5d98294912012-06-27 22:57:4027#include "chrome/browser/prefs/incognito_mode_prefs.h"
[email protected]5d98294912012-06-27 22:57:4028#include "chrome/browser/profiles/profile.h"
mlermane01e6de2014-09-29 19:26:4729#include "chrome/browser/profiles/profile_manager.h"
[email protected]5d98294912012-06-27 22:57:4030#include "chrome/browser/sessions/tab_restore_service_factory.h"
[email protected]0b32f9b62012-09-17 19:08:0331#include "chrome/browser/shell_integration.h"
[email protected]3d27d272013-07-31 03:15:1632#include "chrome/browser/signin/signin_promo.h"
[email protected]5d98294912012-06-27 22:57:4033#include "chrome/browser/sync/profile_sync_service_factory.h"
Christopher Lam86b52712017-12-04 01:58:3334#include "chrome/browser/ui/apps/app_info_dialog.h"
[email protected]5d98294912012-06-27 22:57:4035#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
36#include "chrome/browser/ui/browser.h"
37#include "chrome/browser/ui/browser_commands.h"
38#include "chrome/browser/ui/browser_window.h"
39#include "chrome/browser/ui/chrome_pages.h"
Alan Cutter09965802018-03-27 07:25:2940#include "chrome/browser/ui/extensions/application_launch.h"
Christopher Lam0dbac2b2017-11-14 07:12:1041#include "chrome/browser/ui/extensions/hosted_app_browser_controller.h"
Alan Cutter0c3132302018-02-21 05:09:0242#include "chrome/browser/ui/page_info/page_info_dialog.h"
Nicolas Ouellet-payeur82eb65b2018-11-05 16:49:2743#include "chrome/browser/ui/singleton_tabs.h"
[email protected]5d98294912012-06-27 22:57:4044#include "chrome/browser/ui/tabs/tab_strip_model.h"
[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 Sandrk9669d0e2017-12-15 23:50:2078#include "ash/public/cpp/window_pin_type.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::NavigationEntry;
99using content::NavigationController;
100using 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)
[email protected]5d98294912012-06-27 22:57:40108 : browser_(browser),
Ivan Sandrk9669d0e2017-12-15 23:50:20109 command_updater_(nullptr) {
[email protected]5d98294912012-06-27 22:57:40110 browser_->tab_strip_model()->AddObserver(this);
111 PrefService* local_state = g_browser_process->local_state();
112 if (local_state) {
113 local_pref_registrar_.Init(local_state);
[email protected]9ec3ea5b2012-12-03 18:14:30114 local_pref_registrar_.Add(
115 prefs::kAllowFileSelectionDialogs,
116 base::Bind(
117 &BrowserCommandController::UpdateCommandsForFileSelectionDialogs,
118 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40119 }
120
121 profile_pref_registrar_.Init(profile()->GetPrefs());
[email protected]9ec3ea5b2012-12-03 18:14:30122 profile_pref_registrar_.Add(
Pavol Markodebb0ff2018-05-07 18:35:41123 prefs::kDevToolsAvailability,
[email protected]9ec3ea5b2012-12-03 18:14:30124 base::Bind(&BrowserCommandController::UpdateCommandsForDevTools,
125 base::Unretained(this)));
126 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32127 bookmarks::prefs::kEditBookmarksEnabled,
[email protected]9ec3ea5b2012-12-03 18:14:30128 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkEditing,
129 base::Unretained(this)));
130 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32131 bookmarks::prefs::kShowBookmarkBar,
[email protected]9ec3ea5b2012-12-03 18:14:30132 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkBar,
133 base::Unretained(this)));
134 profile_pref_registrar_.Add(
135 prefs::kIncognitoModeAvailability,
136 base::Bind(
137 &BrowserCommandController::UpdateCommandsForIncognitoAvailability,
138 base::Unretained(this)));
139 profile_pref_registrar_.Add(
140 prefs::kPrintingEnabled,
141 base::Bind(&BrowserCommandController::UpdatePrintingState,
142 base::Unretained(this)));
[email protected]32dfede2013-08-25 15:48:25143#if !defined(OS_MACOSX)
144 profile_pref_registrar_.Add(
145 prefs::kFullscreenAllowed,
146 base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode,
147 base::Unretained(this)));
148#endif
Mihai Sardarescuf87ccc12018-09-26 10:37:45149 pref_signin_allowed_.Init(
150 prefs::kSigninAllowed,
151 profile()->GetOriginalProfile()->GetPrefs(),
152 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange,
153 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40154
155 InitCommandState();
156
blundell74001adc2015-09-18 11:04:25157 sessions::TabRestoreService* tab_restore_service =
[email protected]5d98294912012-06-27 22:57:40158 TabRestoreServiceFactory::GetForProfile(profile());
159 if (tab_restore_service) {
160 tab_restore_service->AddObserver(this);
161 TabRestoreServiceChanged(tab_restore_service);
162 }
[email protected]5d98294912012-06-27 22:57:40163}
164
165BrowserCommandController::~BrowserCommandController() {
[email protected]95e39472012-10-05 23:37:36166 // TabRestoreService may have been shutdown by the time we get here. Don't
167 // trigger creating it.
blundell74001adc2015-09-18 11:04:25168 sessions::TabRestoreService* tab_restore_service =
[email protected]95e39472012-10-05 23:37:36169 TabRestoreServiceFactory::GetForProfileIfExisting(profile());
[email protected]5d98294912012-06-27 22:57:40170 if (tab_restore_service)
171 tab_restore_service->RemoveObserver(this);
172 profile_pref_registrar_.RemoveAll();
173 local_pref_registrar_.RemoveAll();
174 browser_->tab_strip_model()->RemoveObserver(this);
[email protected]5d98294912012-06-27 22:57:40175}
176
177bool BrowserCommandController::IsReservedCommandOrKey(
178 int command_id,
179 const content::NativeWebKeyboardEvent& event) {
180 // In Apps mode, no keys are reserved.
181 if (browser_->is_app())
182 return false;
183
184#if defined(OS_CHROMEOS)
[email protected]397abd32013-08-21 05:44:19185 // On Chrome OS, the top row of keys are mapped to browser actions like
186 // back/forward or refresh. We don't want web pages to be able to change the
187 // behavior of these keys. Ash handles F4 and up; this leaves us needing to
188 // reserve browser back/forward and refresh here.
[email protected]5d98294912012-06-27 22:57:40189 ui::KeyboardCode key_code =
Blink Reformat1c4d759e2017-04-09 16:34:54190 static_cast<ui::KeyboardCode>(event.windows_key_code);
[email protected]397abd32013-08-21 05:44:19191 if ((key_code == ui::VKEY_BROWSER_BACK && command_id == IDC_BACK) ||
192 (key_code == ui::VKEY_BROWSER_FORWARD && command_id == IDC_FORWARD) ||
193 (key_code == ui::VKEY_BROWSER_REFRESH && command_id == IDC_RELOAD)) {
[email protected]5d98294912012-06-27 22:57:40194 return true;
195 }
196#endif
197
zijiehe68cd3dc22017-04-07 18:50:29198 if (window()->IsFullscreen()) {
199 // In fullscreen, all commands except for IDC_FULLSCREEN and IDC_EXIT should
200 // be delivered to the web page. The intent to implement and ship can be
201 // found in http://crbug.com/680809.
202 const bool is_exit_fullscreen =
203 (command_id == IDC_EXIT || command_id == IDC_FULLSCREEN);
204#if defined(OS_MACOSX)
205 // This behavior is different on Mac OS, which has a unique user-initiated
206 // full-screen mode. According to the discussion in http://crbug.com/702251,
207 // the commands should be reserved for browser-side handling if the browser
208 // window's toolbar is visible.
209 if (window()->IsToolbarShowing()) {
210 if (command_id == IDC_FULLSCREEN)
211 return true;
212 } else {
213 return is_exit_fullscreen;
214 }
215#else
216 return is_exit_fullscreen;
217#endif
218 }
[email protected]1e2172f2014-04-01 17:32:34219
[email protected]893124a22014-04-15 00:45:28220#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]1e2172f2014-04-01 17:32:34221 // If this key was registered by the user as a content editing hotkey, then
222 // it is not reserved.
[email protected]d5bedb6d2014-04-08 10:49:32223 ui::TextEditKeyBindingsDelegateAuraLinux* delegate =
[email protected]1e2172f2014-04-01 17:32:34224 ui::GetTextEditKeyBindingsDelegate();
[email protected]47e8e7542014-04-03 07:52:42225 if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL))
[email protected]1e2172f2014-04-01 17:32:34226 return false;
227#endif
228
zijiehe13207802017-02-16 08:06:10229 return command_id == IDC_CLOSE_TAB ||
230 command_id == IDC_CLOSE_WINDOW ||
231 command_id == IDC_NEW_INCOGNITO_WINDOW ||
232 command_id == IDC_NEW_TAB ||
233 command_id == IDC_NEW_WINDOW ||
234 command_id == IDC_RESTORE_TAB ||
235 command_id == IDC_SELECT_NEXT_TAB ||
236 command_id == IDC_SELECT_PREVIOUS_TAB ||
237 command_id == IDC_EXIT;
[email protected]5d98294912012-06-27 22:57:40238}
239
[email protected]5d98294912012-06-27 22:57:40240void BrowserCommandController::TabStateChanged() {
241 UpdateCommandsForTabState();
242}
243
[email protected]d93dbd12014-08-04 23:42:53244void BrowserCommandController::ZoomStateChanged() {
245 UpdateCommandsForZoomState();
246}
247
[email protected]5d98294912012-06-27 22:57:40248void BrowserCommandController::ContentRestrictionsChanged() {
249 UpdateCommandsForContentRestrictionState();
250}
251
252void BrowserCommandController::FullscreenStateChanged() {
[email protected]32dfede2013-08-25 15:48:25253 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40254}
255
Ivan Sandrk9669d0e2017-12-15 23:50:20256#if defined(OS_CHROMEOS)
257void BrowserCommandController::LockedFullscreenStateChanged() {
258 UpdateCommandsForLockedFullscreenMode();
259}
260#endif
261
[email protected]5d98294912012-06-27 22:57:40262void BrowserCommandController::PrintingStateChanged() {
263 UpdatePrintingState();
264}
265
266void BrowserCommandController::LoadingStateChanged(bool is_loading,
267 bool force) {
268 UpdateReloadStopState(is_loading, force);
269}
270
wittman76df71db32014-12-18 23:26:58271void BrowserCommandController::ExtensionStateChanged() {
272 // Extensions may disable the bookmark editing commands.
273 UpdateCommandsForBookmarkEditing();
274}
275
[email protected]5d98294912012-06-27 22:57:40276////////////////////////////////////////////////////////////////////////////////
Ivan Sandrk9669d0e2017-12-15 23:50:20277// BrowserCommandController, CommandUpdater implementation:
[email protected]5d98294912012-06-27 22:57:40278
Ivan Sandrk9669d0e2017-12-15 23:50:20279bool BrowserCommandController::SupportsCommand(int id) const {
280 return command_updater_.SupportsCommand(id);
281}
282
283bool BrowserCommandController::IsCommandEnabled(int id) const {
284 return command_updater_.IsCommandEnabled(id);
285}
286
287bool BrowserCommandController::ExecuteCommand(int id) {
288 return ExecuteCommandWithDisposition(id, WindowOpenDisposition::CURRENT_TAB);
289}
290
291bool BrowserCommandController::ExecuteCommandWithDisposition(
292 int id, WindowOpenDisposition disposition) {
293 // Doesn't go through the command_updater_ to avoid dealing with having a
294 // naming collision for ExecuteCommandWithDisposition (both
295 // CommandUpdaterDelegate and CommandUpdater declare this function so we
296 // choose to not implement CommandUpdaterDelegate inside this class and
297 // therefore command_updater_ doesn't have the delegate set).
298 if (!SupportsCommand(id) || !IsCommandEnabled(id))
299 return false;
300
[email protected]5d98294912012-06-27 22:57:40301 // No commands are enabled if there is not yet any selected tab.
302 // TODO(pkasting): It seems like we should not need this, because either
303 // most/all commands should not have been enabled yet anyway or the ones that
304 // are enabled should be global, or safe themselves against having no selected
305 // tab. However, Ben says he tried removing this before and got lots of
306 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
307 // window construction. This probably could use closer examination someday.
[email protected]59253a652012-11-20 00:17:26308 if (browser_->tab_strip_model()->active_index() == TabStripModel::kNoTab)
Ivan Sandrk9669d0e2017-12-15 23:50:20309 return true;
[email protected]5d98294912012-06-27 22:57:40310
311 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command "
312 << id;
313
[email protected]5d98294912012-06-27 22:57:40314 // The order of commands in this switch statement must match the function
315 // declaration order in browser.h!
316 switch (id) {
317 // Navigation commands
[email protected]5d98294912012-06-27 22:57:40318 case IDC_BACK:
[email protected]5d98294912012-06-27 22:57:40319 GoBack(browser_, disposition);
320 break;
[email protected]5d98294912012-06-27 22:57:40321 case IDC_FORWARD:
[email protected]5d98294912012-06-27 22:57:40322 GoForward(browser_, disposition);
323 break;
324 case IDC_RELOAD:
325 Reload(browser_, disposition);
326 break;
[email protected]58e29032012-08-06 20:19:57327 case IDC_RELOAD_CLEARING_CACHE:
328 ClearCache(browser_);
Nico Webera745ef72018-01-29 23:45:57329 FALLTHROUGH;
toyoshim7dad4b1182016-04-01 14:28:05330 case IDC_RELOAD_BYPASSING_CACHE:
331 ReloadBypassingCache(browser_, disposition);
[email protected]5d98294912012-06-27 22:57:40332 break;
333 case IDC_HOME:
334 Home(browser_, disposition);
335 break;
336 case IDC_OPEN_CURRENT_URL:
337 OpenCurrentURL(browser_);
338 break;
339 case IDC_STOP:
340 Stop(browser_);
341 break;
342
343 // Window management commands
344 case IDC_NEW_WINDOW:
345 NewWindow(browser_);
346 break;
347 case IDC_NEW_INCOGNITO_WINDOW:
Orin Jaworski5e4bcd0c2018-10-16 19:35:05348 NewIncognitoWindow(profile());
[email protected]5d98294912012-06-27 22:57:40349 break;
350 case IDC_CLOSE_WINDOW:
bratell0a7406f2017-03-28 07:46:37351 base::RecordAction(base::UserMetricsAction("CloseWindowByKey"));
[email protected]04b9e692012-08-24 14:49:09352 CloseWindow(browser_);
[email protected]5d98294912012-06-27 22:57:40353 break;
Bettina Dea0a4505922017-09-28 00:53:32354 case IDC_NEW_TAB: {
355 NewTab(browser_);
356#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Catherine Chungbeb884222017-08-01 15:47:55357 // This is not in NewTab() to avoid tracking programmatic creation of new
358 // tabs by extensions.
Bettina Dea0a4505922017-09-28 00:53:32359 auto* new_tab_tracker =
360 feature_engagement::NewTabTrackerFactory::GetInstance()
361 ->GetForProfile(profile());
362
363 new_tab_tracker->OnNewTabOpened();
364 new_tab_tracker->CloseBubble();
Catherine Chungbeb884222017-08-01 15:47:55365#endif
[email protected]5d98294912012-06-27 22:57:40366 break;
Bettina Dea0a4505922017-09-28 00:53:32367 }
[email protected]5d98294912012-06-27 22:57:40368 case IDC_CLOSE_TAB:
bratell0a7406f2017-03-28 07:46:37369 base::RecordAction(base::UserMetricsAction("CloseTabByKey"));
[email protected]04b9e692012-08-24 14:49:09370 CloseTab(browser_);
[email protected]5d98294912012-06-27 22:57:40371 break;
372 case IDC_SELECT_NEXT_TAB:
bratell0a7406f2017-03-28 07:46:37373 base::RecordAction(base::UserMetricsAction("Accel_SelectNextTab"));
[email protected]5d98294912012-06-27 22:57:40374 SelectNextTab(browser_);
375 break;
376 case IDC_SELECT_PREVIOUS_TAB:
bratell0a7406f2017-03-28 07:46:37377 base::RecordAction(base::UserMetricsAction("Accel_SelectPreviousTab"));
[email protected]5d98294912012-06-27 22:57:40378 SelectPreviousTab(browser_);
379 break;
[email protected]5d98294912012-06-27 22:57:40380 case IDC_MOVE_TAB_NEXT:
381 MoveTabNext(browser_);
382 break;
383 case IDC_MOVE_TAB_PREVIOUS:
384 MoveTabPrevious(browser_);
385 break;
386 case IDC_SELECT_TAB_0:
387 case IDC_SELECT_TAB_1:
388 case IDC_SELECT_TAB_2:
389 case IDC_SELECT_TAB_3:
390 case IDC_SELECT_TAB_4:
391 case IDC_SELECT_TAB_5:
392 case IDC_SELECT_TAB_6:
393 case IDC_SELECT_TAB_7:
bratell0a7406f2017-03-28 07:46:37394 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
[email protected]5d98294912012-06-27 22:57:40395 SelectNumberedTab(browser_, id - IDC_SELECT_TAB_0);
396 break;
397 case IDC_SELECT_LAST_TAB:
bratell0a7406f2017-03-28 07:46:37398 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
[email protected]5d98294912012-06-27 22:57:40399 SelectLastTab(browser_);
400 break;
401 case IDC_DUPLICATE_TAB:
402 DuplicateTab(browser_);
403 break;
404 case IDC_RESTORE_TAB:
405 RestoreTab(browser_);
406 break;
[email protected]5d98294912012-06-27 22:57:40407 case IDC_SHOW_AS_TAB:
408 ConvertPopupToTabbedBrowser(browser_);
409 break;
410 case IDC_FULLSCREEN:
[email protected]3f32b9b2012-07-09 16:59:28411 chrome::ToggleFullscreenMode(browser_);
[email protected]5d98294912012-06-27 22:57:40412 break;
Alan Cutter09965802018-03-27 07:25:29413 case IDC_OPEN_IN_PWA_WINDOW:
414 base::RecordAction(base::UserMetricsAction("OpenActiveTabInPwaWindow"));
415 ReparentSecureActiveTabIntoPwaWindow(browser_);
416 break;
[email protected]770c6d82012-09-06 22:21:32417
[email protected]d12cc5e2013-10-19 18:25:06418#if defined(OS_CHROMEOS)
419 case IDC_VISIT_DESKTOP_OF_LRU_USER_2:
[email protected]0c930812014-01-30 18:01:47420 case IDC_VISIT_DESKTOP_OF_LRU_USER_3:
zijiehe4dde8072017-02-13 20:38:35421 ExecuteVisitDesktopCommand(id, window()->GetNativeWindow());
[email protected]0c930812014-01-30 18:01:47422 break;
[email protected]d12cc5e2013-10-19 18:25:06423#endif
424
[email protected]893124a22014-04-15 00:45:28425#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15426 case IDC_MINIMIZE_WINDOW:
427 browser_->window()->Minimize();
428 break;
429 case IDC_MAXIMIZE_WINDOW:
430 browser_->window()->Maximize();
431 break;
432 case IDC_RESTORE_WINDOW:
433 browser_->window()->Restore();
434 break;
[email protected]af97be4c62014-02-13 14:43:34435 case IDC_USE_SYSTEM_TITLE_BAR: {
zijiehe4dde8072017-02-13 20:38:35436 PrefService* prefs = profile()->GetPrefs();
[email protected]af97be4c62014-02-13 14:43:34437 prefs->SetBoolean(prefs::kUseCustomChromeFrame,
438 !prefs->GetBoolean(prefs::kUseCustomChromeFrame));
439 break;
440 }
441#endif
442
[email protected]5d98294912012-06-27 22:57:40443#if defined(OS_MACOSX)
spqchanb8ffc7d2015-11-17 01:17:21444 case IDC_TOGGLE_FULLSCREEN_TOOLBAR:
445 chrome::ToggleFullscreenToolbar(browser_);
446 break;
spqchan2c5d541e2017-10-25 07:07:11447 case IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS: {
Robert Sesek03282612018-10-31 15:48:06448 chrome::ToggleJavaScriptFromAppleEventsAllowed(browser_);
spqchan2c5d541e2017-10-25 07:07:11449 break;
450 }
[email protected]5d98294912012-06-27 22:57:40451#endif
452 case IDC_EXIT:
453 Exit();
454 break;
455
456 // Page-related commands
457 case IDC_SAVE_PAGE:
458 SavePage(browser_);
459 break;
460 case IDC_BOOKMARK_PAGE:
Anatoly Pilikovee720922017-11-01 09:43:17461#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:14462 feature_engagement::BookmarkTrackerFactory::GetInstance()
463 ->GetForProfile(profile())
464 ->OnBookmarkAdded();
465#endif
deepak.m154a7f392014-12-15 04:41:43466 BookmarkCurrentPageAllowingExtensionOverrides(browser_);
[email protected]5d98294912012-06-27 22:57:40467 break;
[email protected]5d98294912012-06-27 22:57:40468 case IDC_BOOKMARK_ALL_TABS:
Anatoly Pilikovee720922017-11-01 09:43:17469#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:14470 feature_engagement::BookmarkTrackerFactory::GetInstance()
471 ->GetForProfile(profile())
472 ->OnBookmarkAdded();
473#endif
[email protected]5d98294912012-06-27 22:57:40474 BookmarkAllTabs(browser_);
475 break;
476 case IDC_VIEW_SOURCE:
Lukasz Anforowicze1b954d92017-10-30 21:28:06477 browser_->tab_strip_model()
478 ->GetActiveWebContents()
479 ->GetMainFrame()
480 ->ViewSource();
[email protected]5d98294912012-06-27 22:57:40481 break;
482 case IDC_EMAIL_PAGE_LOCATION:
483 EmailPageLocation(browser_);
484 break;
485 case IDC_PRINT:
486 Print(browser_);
487 break;
bondd052b5f82015-10-28 22:39:32488
Lei Zhang48a4a5262018-04-17 20:18:44489#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:55490 case IDC_BASIC_PRINT:
bratell0a7406f2017-03-28 07:46:37491 base::RecordAction(base::UserMetricsAction("Accel_Advanced_Print"));
vitalybukaf9433e42014-09-08 10:04:55492 BasicPrint(browser_);
[email protected]5d98294912012-06-27 22:57:40493 break;
Lei Zhang48a4a5262018-04-17 20:18:44494#endif // ENABLE_PRINTING
bondd052b5f82015-10-28 22:39:32495
bondd052b5f82015-10-28 22:39:32496 case IDC_SAVE_CREDIT_CARD_FOR_PAGE:
497 SaveCreditCard(browser_);
498 break;
siyua3e599eaa2018-07-13 00:23:06499 case IDC_MIGRATE_LOCAL_CREDIT_CARD_FOR_PAGE:
500 MigrateLocalCards(browser_);
501 break;
[email protected]e625b7602013-10-28 09:24:56502 case IDC_TRANSLATE_PAGE:
503 Translate(browser_);
504 break;
[email protected]4bee4432014-05-05 13:11:41505 case IDC_MANAGE_PASSWORDS_FOR_PAGE:
506 ManagePasswordsForPage(browser_);
507 break;
Tina Wang788aac22018-12-21 20:25:46508 case IDC_SEND_TO_MY_DEVICES:
509 SendToMyDevices(browser_);
510 break;
[email protected]4bee4432014-05-05 13:11:41511
[email protected]5d98294912012-06-27 22:57:40512 // Clipboard commands
513 case IDC_CUT:
[email protected]5d98294912012-06-27 22:57:40514 case IDC_COPY:
[email protected]5d98294912012-06-27 22:57:40515 case IDC_PASTE:
pkastingcd3f08bce2015-04-18 13:37:12516 CutCopyPaste(browser_, id);
[email protected]5d98294912012-06-27 22:57:40517 break;
518
519 // Find-in-page
520 case IDC_FIND:
521 Find(browser_);
522 break;
523 case IDC_FIND_NEXT:
524 FindNext(browser_);
525 break;
526 case IDC_FIND_PREVIOUS:
527 FindPrevious(browser_);
528 break;
529
530 // Zoom
531 case IDC_ZOOM_PLUS:
532 Zoom(browser_, content::PAGE_ZOOM_IN);
533 break;
534 case IDC_ZOOM_NORMAL:
535 Zoom(browser_, content::PAGE_ZOOM_RESET);
536 break;
537 case IDC_ZOOM_MINUS:
538 Zoom(browser_, content::PAGE_ZOOM_OUT);
539 break;
540
541 // Focus various bits of UI
542 case IDC_FOCUS_TOOLBAR:
bratell0a7406f2017-03-28 07:46:37543 base::RecordAction(base::UserMetricsAction("Accel_Focus_Toolbar"));
[email protected]5d98294912012-06-27 22:57:40544 FocusToolbar(browser_);
545 break;
546 case IDC_FOCUS_LOCATION:
bratell0a7406f2017-03-28 07:46:37547 base::RecordAction(base::UserMetricsAction("Accel_Focus_Location"));
[email protected]5d98294912012-06-27 22:57:40548 FocusLocationBar(browser_);
549 break;
550 case IDC_FOCUS_SEARCH:
bratell0a7406f2017-03-28 07:46:37551 base::RecordAction(base::UserMetricsAction("Accel_Focus_Search"));
[email protected]5d98294912012-06-27 22:57:40552 FocusSearch(browser_);
553 break;
554 case IDC_FOCUS_MENU_BAR:
555 FocusAppMenu(browser_);
556 break;
557 case IDC_FOCUS_BOOKMARKS:
bratell0a7406f2017-03-28 07:46:37558 base::RecordAction(base::UserMetricsAction("Accel_Focus_Bookmarks"));
[email protected]5d98294912012-06-27 22:57:40559 FocusBookmarksToolbar(browser_);
560 break;
David Tsengc0b1b642018-01-24 07:12:27561 case IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY:
562 FocusInactivePopupForAccessibility(browser_);
[email protected]822ca8c62013-04-19 00:49:15563 break;
[email protected]5d98294912012-06-27 22:57:40564 case IDC_FOCUS_NEXT_PANE:
565 FocusNextPane(browser_);
566 break;
567 case IDC_FOCUS_PREVIOUS_PANE:
568 FocusPreviousPane(browser_);
569 break;
570
571 // Show various bits of UI
572 case IDC_OPEN_FILE:
573 browser_->OpenFile();
574 break;
Alan Cutter81ac726682018-09-25 00:18:36575 case IDC_CREATE_SHORTCUT:
576 CreateBookmarkAppFromCurrentWebContents(browser_,
577 true /* force_shortcut_app */);
578 break;
579 case IDC_INSTALL_PWA:
580 CreateBookmarkAppFromCurrentWebContents(browser_,
581 false /* force_shortcut_app */);
[email protected]488e3952013-11-18 05:29:14582 break;
[email protected]5d98294912012-06-27 22:57:40583 case IDC_DEV_TOOLS:
[email protected]c934c382013-11-01 00:36:01584 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Show());
[email protected]5d98294912012-06-27 22:57:40585 break;
586 case IDC_DEV_TOOLS_CONSOLE:
einbinderdfa567b2016-12-16 01:15:52587 ToggleDevToolsWindow(browser_, DevToolsToggleAction::ShowConsolePanel());
[email protected]5d98294912012-06-27 22:57:40588 break;
[email protected]2056c3192013-10-21 22:40:51589 case IDC_DEV_TOOLS_DEVICES:
590 InspectUI::InspectDevices(browser_);
591 break;
[email protected]5d98294912012-06-27 22:57:40592 case IDC_DEV_TOOLS_INSPECT:
[email protected]c934c382013-11-01 00:36:01593 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Inspect());
[email protected]5d98294912012-06-27 22:57:40594 break;
[email protected]d16657c2012-09-03 14:25:10595 case IDC_DEV_TOOLS_TOGGLE:
[email protected]c934c382013-11-01 00:36:01596 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Toggle());
[email protected]d16657c2012-09-03 14:25:10597 break;
[email protected]5d98294912012-06-27 22:57:40598 case IDC_TASK_MANAGER:
[email protected]29c262de2013-06-22 15:39:38599 OpenTaskManager(browser_);
[email protected]5d98294912012-06-27 22:57:40600 break;
caelyn4e4e08a2015-02-04 21:27:49601#if defined(OS_CHROMEOS)
602 case IDC_TAKE_SCREENSHOT:
603 TakeScreenshot();
604 break;
605#endif
[email protected]236ad3022013-09-04 03:27:43606#if defined(GOOGLE_CHROME_BUILD)
[email protected]5d98294912012-06-27 22:57:40607 case IDC_FEEDBACK:
afakhryf4575bd2017-04-28 02:21:04608 OpenFeedbackDialog(browser_, kFeedbackSourceBrowserCommand);
[email protected]5d98294912012-06-27 22:57:40609 break;
[email protected]236ad3022013-09-04 03:27:43610#endif
[email protected]5d98294912012-06-27 22:57:40611 case IDC_SHOW_BOOKMARK_BAR:
612 ToggleBookmarkBar(browser_);
613 break;
614 case IDC_PROFILING_ENABLED:
Bryce Thomas96b07772018-11-07 03:04:15615 content::Profiling::Toggle();
[email protected]5d98294912012-06-27 22:57:40616 break;
617
618 case IDC_SHOW_BOOKMARK_MANAGER:
619 ShowBookmarkManager(browser_);
620 break;
621 case IDC_SHOW_APP_MENU:
bratell0a7406f2017-03-28 07:46:37622 base::RecordAction(base::UserMetricsAction("Accel_Show_App_Menu"));
[email protected]5d98294912012-06-27 22:57:40623 ShowAppMenu(browser_);
624 break;
625 case IDC_SHOW_AVATAR_MENU:
626 ShowAvatarMenu(browser_);
627 break;
[email protected]5d98294912012-06-27 22:57:40628 case IDC_SHOW_HISTORY:
629 ShowHistory(browser_);
630 break;
631 case IDC_SHOW_DOWNLOADS:
632 ShowDownloads(browser_);
633 break;
634 case IDC_MANAGE_EXTENSIONS:
[email protected]bc9833c32013-02-28 04:05:08635 ShowExtensions(browser_, std::string());
[email protected]5d98294912012-06-27 22:57:40636 break;
637 case IDC_OPTIONS:
638 ShowSettings(browser_);
639 break;
640 case IDC_EDIT_SEARCH_ENGINES:
641 ShowSearchEngineSettings(browser_);
642 break;
643 case IDC_VIEW_PASSWORDS:
644 ShowPasswordManager(browser_);
645 break;
646 case IDC_CLEAR_BROWSING_DATA:
647 ShowClearBrowsingDataDialog(browser_);
648 break;
649 case IDC_IMPORT_SETTINGS:
650 ShowImportDialog(browser_);
651 break;
[email protected]9b7ab882012-09-10 23:46:36652 case IDC_TOGGLE_REQUEST_TABLET_SITE:
653 ToggleRequestTabletSite(browser_);
654 break;
[email protected]5d98294912012-06-27 22:57:40655 case IDC_ABOUT:
656 ShowAboutChrome(browser_);
657 break;
658 case IDC_UPGRADE_DIALOG:
659 OpenUpdateChromeDialog(browser_);
660 break;
[email protected]5d98294912012-06-27 22:57:40661 case IDC_HELP_PAGE_VIA_KEYBOARD:
662 ShowHelp(browser_, HELP_SOURCE_KEYBOARD);
663 break;
664 case IDC_HELP_PAGE_VIA_MENU:
665 ShowHelp(browser_, HELP_SOURCE_MENU);
666 break;
Bret Sepulveda2d018662017-05-18 21:31:48667 case IDC_SHOW_BETA_FORUM:
668 ShowBetaForum(browser_);
669 break;
David Roger7e25dff2019-02-07 09:03:17670#if !defined(OS_CHROMEOS)
estade8c0780f2015-08-21 23:36:41671 case IDC_SHOW_SIGNIN:
gogerald71bf6c902015-12-08 00:49:37672 ShowBrowserSigninOrSettings(
673 browser_, signin_metrics::AccessPoint::ACCESS_POINT_MENU);
estade8c0780f2015-08-21 23:36:41674 break;
David Roger7e25dff2019-02-07 09:03:17675#endif
[email protected]6bd370b2014-05-28 14:19:47676 case IDC_DISTILL_PAGE:
677 DistillCurrentPage(browser_);
678 break;
apacible45cbfc92015-09-28 22:45:41679 case IDC_ROUTE_MEDIA:
680 RouteMedia(browser_);
681 break;
Tommy Steimelc4477982017-11-29 18:07:18682 case IDC_WINDOW_MUTE_SITE:
683 MuteSite(browser_);
ellyjones0101ba02017-05-19 15:50:26684 break;
685 case IDC_WINDOW_PIN_TAB:
686 PinTab(browser_);
687 break;
Nicolas Ouellet-payeur82eb65b2018-11-05 16:49:27688 case IDC_MANAGED_UI_HELP:
689 ShowSingletonTab(browser_, GURL(kManagedUiLearnMoreUrl));
690 break;
[email protected]5d98294912012-06-27 22:57:40691
Christopher Lam0dbac2b2017-11-14 07:12:10692 // Hosted App commands
693 case IDC_COPY_URL:
694 CopyURL(browser_);
695 break;
696 case IDC_OPEN_IN_CHROME:
697 OpenInChrome(browser_);
698 break;
699 case IDC_SITE_SETTINGS:
700 ShowSiteSettings(
701 browser_,
702 browser_->tab_strip_model()->GetActiveWebContents()->GetVisibleURL());
703 break;
Alan Cutter0c3132302018-02-21 05:09:02704 case IDC_HOSTED_APP_MENU_APP_INFO:
705 ShowPageInfoDialog(browser_->tab_strip_model()->GetActiveWebContents(),
Alan Cutter689f89a2018-03-08 05:09:54706 bubble_anchor_util::kAppMenuButton);
Christopher Lam86b52712017-12-04 01:58:33707 break;
Christopher Lam0dbac2b2017-11-14 07:12:10708
[email protected]5d98294912012-06-27 22:57:40709 default:
710 LOG(WARNING) << "Received Unimplemented Command: " << id;
711 break;
712 }
Ivan Sandrk9669d0e2017-12-15 23:50:20713
714 return true;
715}
716
717void BrowserCommandController::AddCommandObserver(int id,
718 CommandObserver* observer) {
719 command_updater_.AddCommandObserver(id, observer);
720}
721
722void BrowserCommandController::RemoveCommandObserver(
723 int id, CommandObserver* observer) {
724 command_updater_.RemoveCommandObserver(id, observer);
725}
726
727void BrowserCommandController::RemoveCommandObserver(
728 CommandObserver* observer) {
729 command_updater_.RemoveCommandObserver(observer);
730}
731
732bool BrowserCommandController::UpdateCommandEnabled(int id, bool state) {
733 if (is_locked_fullscreen_)
734 return false;
735
736 return command_updater_.UpdateCommandEnabled(id, state);
[email protected]5d98294912012-06-27 22:57:40737}
738
Mihai Sardarescuf87ccc12018-09-26 10:37:45739////////////////////////////////////////////////////////////////////////////////
740// BrowserCommandController, SigninPrefObserver implementation:
741
742void BrowserCommandController::OnSigninAllowedPrefChange() {
743 // For unit tests, we don't have a window.
744 if (!window())
745 return;
746 UpdateShowSyncState(IsShowingMainUI());
747}
748
[email protected]5d98294912012-06-27 22:57:40749// BrowserCommandController, TabStripModelObserver implementation:
750
sangwoo.ko1ae265f12018-10-18 08:30:28751void BrowserCommandController::OnTabStripModelChanged(
752 TabStripModel* tab_strip_model,
753 const TabStripModelChange& change,
754 const TabStripSelectionChange& selection) {
755 if (change.type() != TabStripModelChange::kInserted &&
756 change.type() != TabStripModelChange::kReplaced &&
757 change.type() != TabStripModelChange::kRemoved)
758 return;
[email protected]5d98294912012-06-27 22:57:40759
sangwoo.ko1ae265f12018-10-18 08:30:28760 for (const auto& delta : change.deltas()) {
761 content::WebContents* new_contents = nullptr;
762 content::WebContents* old_contents = nullptr;
763 if (change.type() == TabStripModelChange::kInserted) {
764 new_contents = delta.insert.contents;
765 } else if (change.type() == TabStripModelChange::kReplaced) {
766 new_contents = delta.replace.new_contents;
767 old_contents = delta.replace.old_contents;
768 } else {
769 old_contents = delta.remove.contents;
770 }
[email protected]5d98294912012-06-27 22:57:40771
sangwoo.ko1ae265f12018-10-18 08:30:28772 if (old_contents)
773 RemoveInterstitialObservers(old_contents);
774 if (new_contents)
775 AddInterstitialObservers(new_contents);
776 }
[email protected]5d98294912012-06-27 22:57:40777}
778
[email protected]3cac87232012-11-20 01:48:27779void BrowserCommandController::TabBlockedStateChanged(
780 content::WebContents* contents,
781 int index) {
782 PrintingStateChanged();
783 FullscreenStateChanged();
784 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:41785 UpdateCommandsForMediaRouter();
[email protected]3cac87232012-11-20 01:48:27786}
787
[email protected]5d98294912012-06-27 22:57:40788////////////////////////////////////////////////////////////////////////////////
789// BrowserCommandController, TabRestoreServiceObserver implementation:
790
791void BrowserCommandController::TabRestoreServiceChanged(
blundell74001adc2015-09-18 11:04:25792 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53793 UpdateTabRestoreCommandState();
[email protected]5d98294912012-06-27 22:57:40794}
795
796void BrowserCommandController::TabRestoreServiceDestroyed(
blundell74001adc2015-09-18 11:04:25797 sessions::TabRestoreService* service) {
[email protected]5d98294912012-06-27 22:57:40798 service->RemoveObserver(this);
799}
800
[email protected]2e9369e2014-08-15 09:12:53801void BrowserCommandController::TabRestoreServiceLoaded(
blundell74001adc2015-09-18 11:04:25802 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53803 UpdateTabRestoreCommandState();
804}
805
[email protected]5d98294912012-06-27 22:57:40806////////////////////////////////////////////////////////////////////////////////
[email protected]5d98294912012-06-27 22:57:40807// BrowserCommandController, private:
808
[email protected]20ca0382013-02-28 19:50:07809class BrowserCommandController::InterstitialObserver
810 : public content::WebContentsObserver {
811 public:
812 InterstitialObserver(BrowserCommandController* controller,
813 content::WebContents* web_contents)
814 : WebContentsObserver(web_contents),
815 controller_(controller) {
816 }
817
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);
Tina Wang788aac22018-12-21 20:25:46884 command_updater_.UpdateCommandEnabled(IDC_SEND_TO_MY_DEVICES, true);
[email protected]5d98294912012-06-27 22:57:40885
886 // Zoom
887 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true);
888 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true);
[email protected]d93dbd12014-08-04 23:42:53889 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, false);
[email protected]5d98294912012-06-27 22:57:40890 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
891
892 // Show various bits of UI
mlerman7831f57d2015-05-25 11:40:15893 const bool guest_session = profile()->IsGuestSession() ||
894 profile()->IsSystemProfile();
895 DCHECK(!profile()->IsSystemProfile())
896 << "Ought to never have browser for the system profile.";
[email protected]338416c02014-05-13 16:47:06897 const bool normal_window = browser_->is_type_tabbed();
[email protected]05454532013-01-22 21:09:08898 UpdateOpenFileState(&command_updater_);
[email protected]5d98294912012-06-27 22:57:40899 UpdateCommandsForDevTools();
900 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager());
[email protected]338416c02014-05-13 16:47:06901 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session);
[email protected]5d98294912012-06-27 22:57:40902 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
[email protected]674b65672014-06-02 23:21:56903 command_updater_.UpdateCommandEnabled(IDC_HELP_MENU, true);
[email protected]5d98294912012-06-27 22:57:40904 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
905 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
Bret Sepulveda2d018662017-05-18 21:31:48906 command_updater_.UpdateCommandEnabled(IDC_SHOW_BETA_FORUM, true);
[email protected]338416c02014-05-13 16:47:06907 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session);
[email protected]2f1acc212012-11-13 10:43:51908 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU,
[email protected]338416c02014-05-13 16:47:06909 !guest_session &&
[email protected]2f1acc212012-11-13 10:43:51910 !profile()->IsOffTheRecord());
tsergeant341a8272017-04-18 03:54:33911 command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA,
912 !guest_session);
[email protected]39d47592014-01-10 21:42:45913#if defined(OS_CHROMEOS)
caelyn4e4e08a2015-02-04 21:27:49914 command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true);
[email protected]338416c02014-05-13 16:47:06915#else
916 // Chrome OS uses the system tray menu to handle multi-profiles.
anthonyvd7dc985da2015-03-23 16:53:19917 if (normal_window && (guest_session || !profile()->IsOffTheRecord())) {
[email protected]338416c02014-05-13 16:47:06918 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
anthonyvd7dc985da2015-03-23 16:53:19919 }
[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
[email protected]c9f983d2014-02-05 09:00:24925 command_updater_.UpdateCommandEnabled(
926 IDC_HOME,
benwellsc431c0ae2015-01-27 22:04:06927 normal_window ||
928 (extensions::util::IsNewBookmarkAppsEnabled() && browser_->is_app()));
[email protected]5d98294912012-06-27 22:57:40929
Christopher Lam0dbac2b2017-11-14 07:12:10930 const bool is_experimental_hosted_app =
931 extensions::HostedAppBrowserController::IsForExperimentalHostedAppBrowser(
932 browser_);
933 // Hosted app browser commands.
934 command_updater_.UpdateCommandEnabled(IDC_COPY_URL,
935 is_experimental_hosted_app);
936 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_CHROME,
937 is_experimental_hosted_app);
938 command_updater_.UpdateCommandEnabled(IDC_SITE_SETTINGS,
939 is_experimental_hosted_app);
Alan Cutter0c3132302018-02-21 05:09:02940 command_updater_.UpdateCommandEnabled(IDC_HOSTED_APP_MENU_APP_INFO,
Christopher Lam86b52712017-12-04 01:58:33941 is_experimental_hosted_app);
Christopher Lam0dbac2b2017-11-14 07:12:10942
[email protected]5d98294912012-06-27 22:57:40943 // Window management commands
[email protected]5d98294912012-06-27 22:57:40944 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window);
945 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB,
946 normal_window);
947 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window);
948 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window);
949 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window);
950 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window);
951 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window);
952 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window);
953 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window);
954 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window);
955 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window);
956 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window);
957 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window);
[email protected]5d98294912012-06-27 22:57:40958
[email protected]338416c02014-05-13 16:47:06959 // These are always enabled; the menu determines their menu item visibility.
[email protected]5d98294912012-06-27 22:57:40960 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
[email protected]5d98294912012-06-27 22:57:40961
[email protected]6bd370b2014-05-28 14:19:47962 // Distill current page.
963 command_updater_.UpdateCommandEnabled(
avi556c05022014-12-22 23:31:43964 IDC_DISTILL_PAGE, base::CommandLine::ForCurrentProcess()->HasSwitch(
965 switches::kEnableDomDistiller));
[email protected]6bd370b2014-05-28 14:19:47966
Tommy Steimelc4477982017-11-29 18:07:18967 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE, normal_window);
ellyjones0101ba02017-05-19 15:50:26968 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, normal_window);
969
[email protected]338416c02014-05-13 16:47:06970 // Initialize other commands whose state changes based on various conditions.
[email protected]32dfede2013-08-25 15:48:25971 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40972 UpdateCommandsForContentRestrictionState();
[email protected]5d98294912012-06-27 22:57:40973 UpdateCommandsForBookmarkEditing();
[email protected]5d98294912012-06-27 22:57:40974 UpdateCommandsForIncognitoAvailability();
975}
976
[email protected]05454532013-01-22 21:09:08977// static
978void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
979 CommandUpdater* command_updater,
980 Profile* profile) {
mlermane01e6de2014-09-29 19:26:47981 const bool guest_session = profile->IsGuestSession();
982 // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession().
[email protected]5d98294912012-06-27 22:57:40983 IncognitoModePrefs::Availability incognito_availability =
[email protected]05454532013-01-22 21:09:08984 IncognitoModePrefs::GetAvailability(profile->GetPrefs());
985 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40986 IDC_NEW_WINDOW,
987 incognito_availability != IncognitoModePrefs::FORCED);
[email protected]05454532013-01-22 21:09:08988 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40989 IDC_NEW_INCOGNITO_WINDOW,
mlermane01e6de2014-09-29 19:26:47990 incognito_availability != IncognitoModePrefs::DISABLED && !guest_session);
[email protected]5d98294912012-06-27 22:57:40991
[email protected]57b25292014-05-01 16:31:06992 const bool forced_incognito =
993 incognito_availability == IncognitoModePrefs::FORCED ||
994 guest_session; // Guest always runs in Incognito mode.
[email protected]05454532013-01-22 21:09:08995 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40996 IDC_SHOW_BOOKMARK_MANAGER,
[email protected]57b25292014-05-01 16:31:06997 browser_defaults::bookmarks_enabled && !forced_incognito);
Devlin Cronin21dba422018-05-30 15:45:16998 extensions::ExtensionService* extension_service =
[email protected]03d25812014-06-22 19:41:55999 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]57b25292014-05-01 16:31:061000 const bool enable_extensions =
[email protected]5d98294912012-06-27 22:57:401001 extension_service && extension_service->extensions_enabled();
[email protected]5d98294912012-06-27 22:57:401002
[email protected]57b25292014-05-01 16:31:061003 // Bookmark manager and settings page/subpages are forced to open in normal
1004 // mode. For this reason we disable these commands when incognito is forced.
1005 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
1006 enable_extensions && !forced_incognito);
1007
1008 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito);
1009 command_updater->UpdateCommandEnabled(IDC_OPTIONS,
1010 !forced_incognito || guest_session);
estade8c0780f2015-08-21 23:36:411011 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito);
[email protected]05454532013-01-22 21:09:081012}
1013
1014void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
Ivan Sandrk9669d0e2017-12-15 23:50:201015 if (is_locked_fullscreen_)
1016 return;
1017
[email protected]05454532013-01-22 21:09:081018 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile());
1019
[email protected]6a414ff2013-02-27 08:22:541020 if (!IsShowingMainUI()) {
[email protected]05454532013-01-22 21:09:081021 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false);
1022 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false);
1023 }
[email protected]5d98294912012-06-27 22:57:401024}
1025
1026void BrowserCommandController::UpdateCommandsForTabState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201027 if (is_locked_fullscreen_)
1028 return;
1029
[email protected]617ee962013-01-29 20:49:121030 WebContents* current_web_contents =
1031 browser_->tab_strip_model()->GetActiveWebContents();
[email protected]1c5119c2012-09-19 00:08:571032 if (!current_web_contents) // May be NULL during tab restore.
[email protected]5d98294912012-06-27 22:57:401033 return;
[email protected]5d98294912012-06-27 22:57:401034
1035 // Navigation commands
[email protected]5d98294912012-06-27 22:57:401036 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_));
[email protected]5d98294912012-06-27 22:57:401037 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_));
1038 command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_));
toyoshim7dad4b1182016-04-01 14:28:051039 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE,
[email protected]5d98294912012-06-27 22:57:401040 CanReload(browser_));
[email protected]58e29032012-08-06 20:19:571041 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE,
1042 CanReload(browser_));
[email protected]5d98294912012-06-27 22:57:401043
1044 // Window management commands
1045 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB,
1046 !browser_->is_app() && CanDuplicateTab(browser_));
Tommy Steimelc4477982017-11-29 18:07:181047 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE,
ellyjones0101ba02017-05-19 15:50:261048 !browser_->is_app());
1049 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB,
1050 !browser_->is_app());
[email protected]5d98294912012-06-27 22:57:401051
1052 // Page-related commands
1053 window()->SetStarredState(
[email protected]1c5119c2012-09-19 00:08:571054 BookmarkTabHelper::FromWebContents(current_web_contents)->is_starred());
[email protected]5423c372012-08-22 05:50:161055 window()->ZoomChangedForActiveTab(false);
[email protected]5d98294912012-06-27 22:57:401056 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
1057 CanViewSource(browser_));
1058 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION,
1059 CanEmailPageLocation(browser_));
1060 if (browser_->is_devtools())
1061 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false);
1062
Alan Cutter81ac726682018-09-25 00:18:361063 bool can_create_bookmark_app = CanCreateBookmarkApp(browser_);
1064 command_updater_.UpdateCommandEnabled(IDC_INSTALL_PWA,
1065 can_create_bookmark_app);
1066 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUT,
1067 can_create_bookmark_app);
Alan Cutter403cebb2018-05-17 05:22:451068 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW,
Alan Cutter81ac726682018-09-25 00:18:361069 can_create_bookmark_app);
[email protected]5d98294912012-06-27 22:57:401070
[email protected]9b7ab882012-09-10 23:46:361071 command_updater_.UpdateCommandEnabled(
1072 IDC_TOGGLE_REQUEST_TABLET_SITE,
1073 CanRequestTabletSite(current_web_contents));
1074
[email protected]5d98294912012-06-27 22:57:401075 UpdateCommandsForContentRestrictionState();
1076 UpdateCommandsForBookmarkEditing();
[email protected]3cac87232012-11-20 01:48:271077 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:411078 UpdateCommandsForMediaRouter();
[email protected]d93dbd12014-08-04 23:42:531079 // Update the zoom commands when an active tab is selected.
1080 UpdateCommandsForZoomState();
1081}
1082
1083void BrowserCommandController::UpdateCommandsForZoomState() {
1084 WebContents* contents =
1085 browser_->tab_strip_model()->GetActiveWebContents();
1086 if (!contents)
1087 return;
a.sarkar.arundaadc712015-02-26 05:39:081088 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS,
1089 CanZoomIn(contents));
1090 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL,
ccameronb7c1d6c2015-03-09 17:08:241091 CanResetZoom(contents));
a.sarkar.arundaadc712015-02-26 05:39:081092 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS,
1093 CanZoomOut(contents));
[email protected]5d98294912012-06-27 22:57:401094}
1095
1096void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
1097 int restrictions = GetContentRestrictions(browser_);
1098
1099 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011100 IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY));
[email protected]5d98294912012-06-27 22:57:401101 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011102 IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT));
[email protected]5d98294912012-06-27 22:57:401103 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011104 IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE));
[email protected]5d98294912012-06-27 22:57:401105 UpdateSaveAsState();
1106 UpdatePrintingState();
1107}
1108
1109void BrowserCommandController::UpdateCommandsForDevTools() {
Ivan Sandrk9669d0e2017-12-15 23:50:201110 if (is_locked_fullscreen_)
1111 return;
1112
Pavol Marko56df0272018-07-04 17:55:041113 bool dev_tools_enabled = DevToolsWindow::AllowDevToolsFor(
1114 profile(), browser_->tab_strip_model()->GetActiveWebContents());
[email protected]5d98294912012-06-27 22:57:401115 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS,
1116 dev_tools_enabled);
1117 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE,
1118 dev_tools_enabled);
[email protected]2056c3192013-10-21 22:40:511119 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES,
1120 dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401121 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT,
1122 dev_tools_enabled);
[email protected]d16657c2012-09-03 14:25:101123 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE,
1124 dev_tools_enabled);
spqchan2c5d541e2017-10-25 07:07:111125#if defined(OS_MACOSX)
1126 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS,
1127 dev_tools_enabled);
1128#endif
[email protected]5d98294912012-06-27 22:57:401129}
1130
1131void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
Ivan Sandrk9669d0e2017-12-15 23:50:201132 if (is_locked_fullscreen_)
1133 return;
1134
[email protected]5d98294912012-06-27 22:57:401135 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE,
1136 CanBookmarkCurrentPage(browser_));
1137 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
1138 CanBookmarkAllTabs(browser_));
thestig5149d272014-10-30 07:25:291139#if defined(OS_WIN)
1140 command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN, true);
1141#endif
[email protected]5d98294912012-06-27 22:57:401142}
1143
1144void BrowserCommandController::UpdateCommandsForBookmarkBar() {
Ivan Sandrk9669d0e2017-12-15 23:50:201145 if (is_locked_fullscreen_)
1146 return;
1147
tfarina3bddbe112014-08-28 05:29:321148 command_updater_.UpdateCommandEnabled(
1149 IDC_SHOW_BOOKMARK_BAR,
1150 browser_defaults::bookmarks_enabled && !profile()->IsGuestSession() &&
mlerman7831f57d2015-05-25 11:40:151151 !profile()->IsSystemProfile() &&
tfarina3bddbe112014-08-28 05:29:321152 !profile()->GetPrefs()->IsManagedPreference(
1153 bookmarks::prefs::kShowBookmarkBar) &&
1154 IsShowingMainUI());
[email protected]5d98294912012-06-27 22:57:401155}
1156
[email protected]9ec3ea5b2012-12-03 18:14:301157void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
Ivan Sandrk9669d0e2017-12-15 23:50:201158 if (is_locked_fullscreen_)
1159 return;
1160
[email protected]9ec3ea5b2012-12-03 18:14:301161 UpdateSaveAsState();
[email protected]05454532013-01-22 21:09:081162 UpdateOpenFileState(&command_updater_);
[email protected]9ec3ea5b2012-12-03 18:14:301163}
1164
[email protected]32dfede2013-08-25 15:48:251165void BrowserCommandController::UpdateCommandsForFullscreenMode() {
Ivan Sandrk9669d0e2017-12-15 23:50:201166 if (is_locked_fullscreen_)
1167 return;
1168
zijiehe3c7af992017-02-12 20:59:401169 const bool is_fullscreen = window() && window()->IsFullscreen();
1170 const bool show_main_ui = IsShowingMainUI();
manukf1a116392018-10-25 16:28:241171 const bool show_location_bar = IsShowingLocationBar();
1172
zijiehe3c7af992017-02-12 20:59:401173 const bool main_not_fullscreen = show_main_ui && !is_fullscreen;
[email protected]5d98294912012-06-27 22:57:401174
1175 // Navigation commands
1176 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1177
1178 // Window management commands
1179 command_updater_.UpdateCommandEnabled(
1180 IDC_SHOW_AS_TAB,
zijiehe3c7af992017-02-12 20:59:401181 !browser_->is_type_tabbed() && !is_fullscreen);
[email protected]5d98294912012-06-27 22:57:401182
1183 // Focus various bits of UI
1184 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
manukf1a116392018-10-25 16:28:241185 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_location_bar);
[email protected]5d98294912012-06-27 22:57:401186 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
1187 command_updater_.UpdateCommandEnabled(
1188 IDC_FOCUS_MENU_BAR, main_not_fullscreen);
1189 command_updater_.UpdateCommandEnabled(
1190 IDC_FOCUS_NEXT_PANE, main_not_fullscreen);
1191 command_updater_.UpdateCommandEnabled(
1192 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen);
1193 command_updater_.UpdateCommandEnabled(
1194 IDC_FOCUS_BOOKMARKS, main_not_fullscreen);
[email protected]822ca8c62013-04-19 00:49:151195 command_updater_.UpdateCommandEnabled(
David Tsengc0b1b642018-01-24 07:12:271196 IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY, main_not_fullscreen);
[email protected]5d98294912012-06-27 22:57:401197
1198 // Show various bits of UI
1199 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431200#if defined(GOOGLE_CHROME_BUILD)
[email protected]5d98294912012-06-27 22:57:401201 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431202#endif
Mihai Sardarescu2ec5205682018-09-26 09:20:051203 UpdateShowSyncState(show_main_ui);
[email protected]5d98294912012-06-27 22:57:401204
[email protected]5d98294912012-06-27 22:57:401205 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
1206 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
1207 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
1208 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
Nicolas Ouellet-payeur82eb65b2018-11-05 16:49:271209 command_updater_.UpdateCommandEnabled(IDC_MANAGED_UI_HELP, true);
primianod3a81ab2016-01-25 22:21:151210
1211 if (base::debug::IsProfilingSupported())
1212 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
[email protected]5d98294912012-06-27 22:57:401213
[email protected]aeafc3852014-04-29 16:51:291214#if !defined(OS_MACOSX)
zijiehe3c7af992017-02-12 20:59:401215 // Disable toggling into fullscreen mode if disallowed by pref.
1216 const bool fullscreen_enabled = is_fullscreen ||
1217 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed);
1218#else
1219 const bool fullscreen_enabled = true;
[email protected]00a1cc5b2012-11-07 13:44:511220#endif
1221
1222 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled);
spqchanb8ffc7d2015-11-17 01:17:211223 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR,
1224 fullscreen_enabled);
[email protected]5d98294912012-06-27 22:57:401225
1226 UpdateCommandsForBookmarkBar();
zijiehedb473d552017-02-24 01:13:411227 UpdateCommandsForIncognitoAvailability();
Alan Cutter167dfe82018-04-11 09:06:001228 UpdateCommandsForHostedAppAvailability();
1229}
1230
1231void BrowserCommandController::UpdateCommandsForHostedAppAvailability() {
1232 bool has_toolbar =
1233 browser_->is_type_tabbed() ||
1234 extensions::HostedAppBrowserController::IsForExperimentalHostedAppBrowser(
1235 browser_);
1236 if (window() && window()->ShouldHideUIForFullscreen())
1237 has_toolbar = false;
1238 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, has_toolbar);
1239 command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE, has_toolbar);
1240 command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE, has_toolbar);
1241 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, has_toolbar);
[email protected]5d98294912012-06-27 22:57:401242}
1243
Ivan Sandrk9669d0e2017-12-15 23:50:201244#if defined(OS_CHROMEOS)
1245namespace {
1246
1247#if DCHECK_IS_ON()
1248// Makes sure that all commands that are not whitelisted are disabled. DCHECKs
1249// otherwise. Compiled only in debug mode.
1250void NonWhitelistedCommandsAreDisabled(CommandUpdaterImpl* command_updater) {
Ivan Sandrk6ac9c9a2018-12-14 14:15:071251 constexpr int kWhitelistedIds[] = {IDC_CUT, IDC_COPY, IDC_PASTE};
Ivan Sandrk9669d0e2017-12-15 23:50:201252
1253 // Go through all the command ids, skip the whitelisted ones.
1254 for (int id : command_updater->GetAllIds()) {
Haeun Kim3f6123502018-08-26 18:03:041255 if (base::ContainsValue(kWhitelistedIds, id)) {
Ivan Sandrk9669d0e2017-12-15 23:50:201256 continue;
1257 }
1258 DCHECK(!command_updater->IsCommandEnabled(id));
1259 }
1260}
1261#endif
1262
1263} // namespace
1264
1265void BrowserCommandController::UpdateCommandsForLockedFullscreenMode() {
Ivan Sandrk9669d0e2017-12-15 23:50:201266 bool is_locked_fullscreen = ash::IsWindowTrustedPinned(browser_->window());
1267 // Sanity check to make sure this function is called only on state change.
1268 DCHECK_NE(is_locked_fullscreen, is_locked_fullscreen_);
1269 if (is_locked_fullscreen == is_locked_fullscreen_)
1270 return;
1271 is_locked_fullscreen_ = is_locked_fullscreen;
1272
1273 if (is_locked_fullscreen_) {
1274 command_updater_.DisableAllCommands();
1275 // Update the state of whitelisted commands:
1276 // IDC_CUT/IDC_COPY/IDC_PASTE,
1277 UpdateCommandsForContentRestrictionState();
Ivan Sandrk6ac9c9a2018-12-14 14:15:071278 // TODO(crbug.com/904637): Re-enable Find and Zoom in locked fullscreen.
Ivan Sandrk9669d0e2017-12-15 23:50:201279 // All other commands will be disabled (there is an early return in their
1280 // corresponding UpdateCommandsFor* functions).
1281#if DCHECK_IS_ON()
1282 NonWhitelistedCommandsAreDisabled(&command_updater_);
1283#endif
1284 } else {
1285 // Do an init call to re-initialize command state after the
1286 // DisableAllCommands.
1287 InitCommandState();
1288 }
1289}
1290#endif
1291
[email protected]5d98294912012-06-27 22:57:401292void BrowserCommandController::UpdatePrintingState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201293 if (is_locked_fullscreen_)
1294 return;
1295
[email protected]d53e4032012-06-29 18:58:341296 bool print_enabled = CanPrint(browser_);
1297 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
Lei Zhang48a4a5262018-04-17 20:18:441298#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:551299 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT,
1300 CanBasicPrint(browser_));
Lei Zhang48a4a5262018-04-17 20:18:441301#endif
[email protected]5d98294912012-06-27 22:57:401302}
1303
1304void BrowserCommandController::UpdateSaveAsState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201305 if (is_locked_fullscreen_)
1306 return;
1307
[email protected]5d98294912012-06-27 22:57:401308 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_));
1309}
1310
Mihai Sardarescu2ec5205682018-09-26 09:20:051311void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) {
1312 if (is_locked_fullscreen_)
1313 return;
1314
Mihai Sardarescuf87ccc12018-09-26 10:37:451315 command_updater_.UpdateCommandEnabled(
Mihai Sardarescu290bc882018-10-12 10:48:141316 IDC_SHOW_SIGNIN, show_main_ui && pref_signin_allowed_.GetValue());
Mihai Sardarescu2ec5205682018-09-26 09:20:051317}
1318
[email protected]05454532013-01-22 21:09:081319// static
1320void BrowserCommandController::UpdateOpenFileState(
1321 CommandUpdater* command_updater) {
[email protected]5d98294912012-06-27 22:57:401322 bool enabled = true;
1323 PrefService* local_state = g_browser_process->local_state();
1324 if (local_state)
1325 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs);
1326
[email protected]05454532013-01-22 21:09:081327 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled);
[email protected]5d98294912012-06-27 22:57:401328}
1329
1330void BrowserCommandController::UpdateReloadStopState(bool is_loading,
1331 bool force) {
Ivan Sandrk9669d0e2017-12-15 23:50:201332 if (is_locked_fullscreen_)
1333 return;
1334
[email protected]5d98294912012-06-27 22:57:401335 window()->UpdateReloadStopState(is_loading, force);
1336 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
1337}
1338
[email protected]2e9369e2014-08-15 09:12:531339void BrowserCommandController::UpdateTabRestoreCommandState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201340 if (is_locked_fullscreen_)
1341 return;
1342
blundell74001adc2015-09-18 11:04:251343 sessions::TabRestoreService* tab_restore_service =
[email protected]2e9369e2014-08-15 09:12:531344 TabRestoreServiceFactory::GetForProfile(profile());
1345 // The command is enabled if the service hasn't loaded yet to trigger loading.
1346 // The command is updated once the load completes.
1347 command_updater_.UpdateCommandEnabled(
1348 IDC_RESTORE_TAB,
1349 tab_restore_service &&
1350 (!tab_restore_service->IsLoaded() ||
1351 GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE));
1352}
1353
[email protected]3cac87232012-11-20 01:48:271354void BrowserCommandController::UpdateCommandsForFind() {
1355 TabStripModel* model = browser_->tab_strip_model();
1356 bool enabled = !model->IsTabBlocked(model->active_index()) &&
1357 !browser_->is_devtools();
1358
1359 command_updater_.UpdateCommandEnabled(IDC_FIND, enabled);
1360 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled);
1361 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled);
1362}
1363
apacible45cbfc92015-09-28 22:45:411364void BrowserCommandController::UpdateCommandsForMediaRouter() {
Ivan Sandrk9669d0e2017-12-15 23:50:201365 if (is_locked_fullscreen_)
1366 return;
1367
apacible45cbfc92015-09-28 22:45:411368 command_updater_.UpdateCommandEnabled(IDC_ROUTE_MEDIA,
1369 CanRouteMedia(browser_));
1370}
1371
[email protected]409ea2972012-11-10 19:54:431372void BrowserCommandController::AddInterstitialObservers(WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071373 interstitial_observers_.push_back(new InterstitialObserver(this, contents));
[email protected]5d98294912012-06-27 22:57:401374}
1375
1376void BrowserCommandController::RemoveInterstitialObservers(
[email protected]e89cfcb2012-11-11 14:47:241377 WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071378 for (size_t i = 0; i < interstitial_observers_.size(); i++) {
1379 if (interstitial_observers_[i]->web_contents() != contents)
1380 continue;
1381
1382 delete interstitial_observers_[i];
1383 interstitial_observers_.erase(interstitial_observers_.begin() + i);
1384 return;
1385 }
[email protected]5d98294912012-06-27 22:57:401386}
1387
1388BrowserWindow* BrowserCommandController::window() {
1389 return browser_->window();
1390}
1391
1392Profile* BrowserCommandController::profile() {
1393 return browser_->profile();
1394}
1395
[email protected]5d98294912012-06-27 22:57:401396} // namespace chrome