blob: 0649a4c51e2dd601b147b5b3a6ffaca3ed0f7670 [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
[email protected]488e3952013-11-18 05:29:1411#include "base/command_line.h"
Scott Violet44165792018-02-22 02:08:0812#include "base/debug/debugging_buildflags.h"
primianod3a81ab2016-01-25 22:21:1513#include "base/debug/profiler.h"
avi655876a2015-12-25 07:18:1514#include "base/macros.h"
bratell0a7406f2017-03-28 07:46:3715#include "base/metrics/user_metrics.h"
Haeun Kim3f6123502018-08-26 18:03:0416#include "base/stl_util.h"
avi655876a2015-12-25 07:18:1517#include "build/build_config.h"
[email protected]5d98294912012-06-27 22:57:4018#include "chrome/app/chrome_command_ids.h"
19#include "chrome/browser/browser_process.h"
[email protected]dcc8fbc2013-07-12 00:54:0920#include "chrome/browser/chrome_notification_types.h"
[email protected]5d98294912012-06-27 22:57:4021#include "chrome/browser/defaults.h"
Pavol Marko56df0272018-07-04 17:55:0422#include "chrome/browser/devtools/devtools_window.h"
[email protected]5d98294912012-06-27 22:57:4023#include "chrome/browser/extensions/extension_service.h"
benwells39f23ae2014-08-27 08:01:5224#include "chrome/browser/extensions/extension_util.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"
[email protected]5d98294912012-06-27 22:57:4042#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]2056c3192013-10-21 22:40:5143#include "chrome/browser/ui/webui/inspect_ui.h"
[email protected]3c71576ce2013-07-23 02:00:0144#include "chrome/common/content_restriction.h"
[email protected]5d98294912012-06-27 22:57:4045#include "chrome/common/pref_names.h"
46#include "chrome/common/profiling.h"
brettwe1f0af8b2015-10-09 21:30:4647#include "components/bookmarks/common/bookmark_pref_names.h"
sdefresne0f2ef352015-07-27 19:18:0048#include "components/dom_distiller/core/dom_distiller_switches.h"
Scott Violet9ae82892018-03-01 18:38:1249#include "components/feature_engagement/buildflags.h"
brettwb1fc1b82016-02-02 00:19:0850#include "components/prefs/pref_service.h"
blundella08c5dd2015-09-18 06:14:1651#include "components/sessions/core/tab_restore_service.h"
David Rogera6c88122017-10-25 13:02:4652#include "components/signin/core/browser/signin_pref_names.h"
[email protected]5d98294912012-06-27 22:57:4053#include "content/public/browser/native_web_keyboard_event.h"
54#include "content/public/browser/navigation_controller.h"
55#include "content/public/browser/navigation_entry.h"
Lukasz Anforowicze1b954d92017-10-30 21:28:0656#include "content/public/browser/render_frame_host.h"
[email protected]5d98294912012-06-27 22:57:4057#include "content/public/browser/web_contents.h"
[email protected]20ca0382013-02-28 19:50:0758#include "content/public/browser/web_contents_observer.h"
bend32292b2016-10-07 00:21:5859#include "content/public/common/service_manager_connection.h"
[email protected]5d98294912012-06-27 22:57:4060#include "content/public/common/url_constants.h"
[email protected]03d25812014-06-22 19:41:5561#include "extensions/browser/extension_system.h"
Scott Violet318a55f2018-03-30 19:08:1962#include "printing/buildflags/buildflags.h"
[email protected]7e9acd082013-09-17 23:31:1663#include "ui/events/keycodes/keyboard_codes.h"
[email protected]5d98294912012-06-27 22:57:4064
[email protected]9c4d68332013-01-30 13:34:4165#if defined(OS_MACOSX)
66#include "chrome/browser/ui/browser_commands_mac.h"
67#endif
68
[email protected]5d98294912012-06-27 22:57:4069#if defined(OS_WIN)
[email protected]a43ed002013-02-05 19:47:5470#include "base/win/windows_version.h"
[email protected]2d0f80f2013-11-01 22:47:1871#include "content/public/browser/gpu_data_manager.h"
[email protected]5d98294912012-06-27 22:57:4072#endif
73
[email protected]d12cc5e2013-10-19 18:25:0674#if defined(OS_CHROMEOS)
Ivan Sandrk9669d0e2017-12-15 23:50:2075#include "ash/public/cpp/window_pin_type.h"
[email protected]0c930812014-01-30 18:01:4776#include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h"
caelyn4e4e08a2015-02-04 21:27:4977#include "chrome/browser/ui/browser_commands_chromeos.h"
[email protected]d12cc5e2013-10-19 18:25:0678#endif
79
[email protected]d5bedb6d2014-04-08 10:49:3280#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
karandeepbe6200332016-06-21 12:26:1081#include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h"
[email protected]1e2172f2014-04-01 17:32:3482#endif
83
Bettina Deaf3dac202017-09-16 20:53:2284#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:1485#include "chrome/browser/feature_engagement/bookmark/bookmark_tracker.h"
86#include "chrome/browser/feature_engagement/bookmark/bookmark_tracker_factory.h"
Catherine Chungbeb884222017-08-01 15:47:5587#include "chrome/browser/feature_engagement/new_tab/new_tab_tracker.h"
88#include "chrome/browser/feature_engagement/new_tab/new_tab_tracker_factory.h"
89#endif
90
Maksim Sisovac767592018-08-10 08:00:1591#if defined(USE_OZONE)
92#include "ui/ozone/public/ozone_platform.h"
93#endif
94
[email protected]5d98294912012-06-27 22:57:4095using content::NavigationEntry;
96using content::NavigationController;
97using content::WebContents;
98
[email protected]5d98294912012-06-27 22:57:4099namespace chrome {
100
101///////////////////////////////////////////////////////////////////////////////
102// BrowserCommandController, public:
103
[email protected]338416c02014-05-13 16:47:06104BrowserCommandController::BrowserCommandController(Browser* browser)
[email protected]5d98294912012-06-27 22:57:40105 : browser_(browser),
Ivan Sandrk9669d0e2017-12-15 23:50:20106 command_updater_(nullptr) {
[email protected]5d98294912012-06-27 22:57:40107 browser_->tab_strip_model()->AddObserver(this);
108 PrefService* local_state = g_browser_process->local_state();
109 if (local_state) {
110 local_pref_registrar_.Init(local_state);
[email protected]9ec3ea5b2012-12-03 18:14:30111 local_pref_registrar_.Add(
112 prefs::kAllowFileSelectionDialogs,
113 base::Bind(
114 &BrowserCommandController::UpdateCommandsForFileSelectionDialogs,
115 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40116 }
117
118 profile_pref_registrar_.Init(profile()->GetPrefs());
[email protected]9ec3ea5b2012-12-03 18:14:30119 profile_pref_registrar_.Add(
Pavol Markodebb0ff2018-05-07 18:35:41120 prefs::kDevToolsAvailability,
[email protected]9ec3ea5b2012-12-03 18:14:30121 base::Bind(&BrowserCommandController::UpdateCommandsForDevTools,
122 base::Unretained(this)));
123 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32124 bookmarks::prefs::kEditBookmarksEnabled,
[email protected]9ec3ea5b2012-12-03 18:14:30125 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkEditing,
126 base::Unretained(this)));
127 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32128 bookmarks::prefs::kShowBookmarkBar,
[email protected]9ec3ea5b2012-12-03 18:14:30129 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkBar,
130 base::Unretained(this)));
131 profile_pref_registrar_.Add(
132 prefs::kIncognitoModeAvailability,
133 base::Bind(
134 &BrowserCommandController::UpdateCommandsForIncognitoAvailability,
135 base::Unretained(this)));
136 profile_pref_registrar_.Add(
137 prefs::kPrintingEnabled,
138 base::Bind(&BrowserCommandController::UpdatePrintingState,
139 base::Unretained(this)));
[email protected]32dfede2013-08-25 15:48:25140#if !defined(OS_MACOSX)
141 profile_pref_registrar_.Add(
142 prefs::kFullscreenAllowed,
143 base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode,
144 base::Unretained(this)));
145#endif
Mihai Sardarescuf87ccc12018-09-26 10:37:45146 pref_signin_allowed_.Init(
147 prefs::kSigninAllowed,
148 profile()->GetOriginalProfile()->GetPrefs(),
149 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange,
150 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40151
152 InitCommandState();
153
blundell74001adc2015-09-18 11:04:25154 sessions::TabRestoreService* tab_restore_service =
[email protected]5d98294912012-06-27 22:57:40155 TabRestoreServiceFactory::GetForProfile(profile());
156 if (tab_restore_service) {
157 tab_restore_service->AddObserver(this);
158 TabRestoreServiceChanged(tab_restore_service);
159 }
[email protected]5d98294912012-06-27 22:57:40160}
161
162BrowserCommandController::~BrowserCommandController() {
[email protected]95e39472012-10-05 23:37:36163 // TabRestoreService may have been shutdown by the time we get here. Don't
164 // trigger creating it.
blundell74001adc2015-09-18 11:04:25165 sessions::TabRestoreService* tab_restore_service =
[email protected]95e39472012-10-05 23:37:36166 TabRestoreServiceFactory::GetForProfileIfExisting(profile());
[email protected]5d98294912012-06-27 22:57:40167 if (tab_restore_service)
168 tab_restore_service->RemoveObserver(this);
169 profile_pref_registrar_.RemoveAll();
170 local_pref_registrar_.RemoveAll();
171 browser_->tab_strip_model()->RemoveObserver(this);
[email protected]5d98294912012-06-27 22:57:40172}
173
174bool BrowserCommandController::IsReservedCommandOrKey(
175 int command_id,
176 const content::NativeWebKeyboardEvent& event) {
177 // In Apps mode, no keys are reserved.
178 if (browser_->is_app())
179 return false;
180
181#if defined(OS_CHROMEOS)
[email protected]397abd32013-08-21 05:44:19182 // On Chrome OS, the top row of keys are mapped to browser actions like
183 // back/forward or refresh. We don't want web pages to be able to change the
184 // behavior of these keys. Ash handles F4 and up; this leaves us needing to
185 // reserve browser back/forward and refresh here.
[email protected]5d98294912012-06-27 22:57:40186 ui::KeyboardCode key_code =
Blink Reformat1c4d759e2017-04-09 16:34:54187 static_cast<ui::KeyboardCode>(event.windows_key_code);
[email protected]397abd32013-08-21 05:44:19188 if ((key_code == ui::VKEY_BROWSER_BACK && command_id == IDC_BACK) ||
189 (key_code == ui::VKEY_BROWSER_FORWARD && command_id == IDC_FORWARD) ||
190 (key_code == ui::VKEY_BROWSER_REFRESH && command_id == IDC_RELOAD)) {
[email protected]5d98294912012-06-27 22:57:40191 return true;
192 }
193#endif
194
zijiehe68cd3dc22017-04-07 18:50:29195 if (window()->IsFullscreen()) {
196 // In fullscreen, all commands except for IDC_FULLSCREEN and IDC_EXIT should
197 // be delivered to the web page. The intent to implement and ship can be
198 // found in http://crbug.com/680809.
199 const bool is_exit_fullscreen =
200 (command_id == IDC_EXIT || command_id == IDC_FULLSCREEN);
201#if defined(OS_MACOSX)
202 // This behavior is different on Mac OS, which has a unique user-initiated
203 // full-screen mode. According to the discussion in http://crbug.com/702251,
204 // the commands should be reserved for browser-side handling if the browser
205 // window's toolbar is visible.
206 if (window()->IsToolbarShowing()) {
207 if (command_id == IDC_FULLSCREEN)
208 return true;
209 } else {
210 return is_exit_fullscreen;
211 }
212#else
213 return is_exit_fullscreen;
214#endif
215 }
[email protected]1e2172f2014-04-01 17:32:34216
[email protected]893124a22014-04-15 00:45:28217#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]1e2172f2014-04-01 17:32:34218 // If this key was registered by the user as a content editing hotkey, then
219 // it is not reserved.
[email protected]d5bedb6d2014-04-08 10:49:32220 ui::TextEditKeyBindingsDelegateAuraLinux* delegate =
[email protected]1e2172f2014-04-01 17:32:34221 ui::GetTextEditKeyBindingsDelegate();
[email protected]47e8e7542014-04-03 07:52:42222 if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL))
[email protected]1e2172f2014-04-01 17:32:34223 return false;
224#endif
225
zijiehe13207802017-02-16 08:06:10226 return command_id == IDC_CLOSE_TAB ||
227 command_id == IDC_CLOSE_WINDOW ||
228 command_id == IDC_NEW_INCOGNITO_WINDOW ||
229 command_id == IDC_NEW_TAB ||
230 command_id == IDC_NEW_WINDOW ||
231 command_id == IDC_RESTORE_TAB ||
232 command_id == IDC_SELECT_NEXT_TAB ||
233 command_id == IDC_SELECT_PREVIOUS_TAB ||
234 command_id == IDC_EXIT;
[email protected]5d98294912012-06-27 22:57:40235}
236
[email protected]5d98294912012-06-27 22:57:40237void BrowserCommandController::TabStateChanged() {
238 UpdateCommandsForTabState();
239}
240
[email protected]d93dbd12014-08-04 23:42:53241void BrowserCommandController::ZoomStateChanged() {
242 UpdateCommandsForZoomState();
243}
244
[email protected]5d98294912012-06-27 22:57:40245void BrowserCommandController::ContentRestrictionsChanged() {
246 UpdateCommandsForContentRestrictionState();
247}
248
249void BrowserCommandController::FullscreenStateChanged() {
[email protected]32dfede2013-08-25 15:48:25250 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40251}
252
Ivan Sandrk9669d0e2017-12-15 23:50:20253#if defined(OS_CHROMEOS)
254void BrowserCommandController::LockedFullscreenStateChanged() {
255 UpdateCommandsForLockedFullscreenMode();
256}
257#endif
258
[email protected]5d98294912012-06-27 22:57:40259void BrowserCommandController::PrintingStateChanged() {
260 UpdatePrintingState();
261}
262
263void BrowserCommandController::LoadingStateChanged(bool is_loading,
264 bool force) {
265 UpdateReloadStopState(is_loading, force);
266}
267
wittman76df71db32014-12-18 23:26:58268void BrowserCommandController::ExtensionStateChanged() {
269 // Extensions may disable the bookmark editing commands.
270 UpdateCommandsForBookmarkEditing();
271}
272
[email protected]5d98294912012-06-27 22:57:40273////////////////////////////////////////////////////////////////////////////////
Ivan Sandrk9669d0e2017-12-15 23:50:20274// BrowserCommandController, CommandUpdater implementation:
[email protected]5d98294912012-06-27 22:57:40275
Ivan Sandrk9669d0e2017-12-15 23:50:20276bool BrowserCommandController::SupportsCommand(int id) const {
277 return command_updater_.SupportsCommand(id);
278}
279
280bool BrowserCommandController::IsCommandEnabled(int id) const {
281 return command_updater_.IsCommandEnabled(id);
282}
283
284bool BrowserCommandController::ExecuteCommand(int id) {
285 return ExecuteCommandWithDisposition(id, WindowOpenDisposition::CURRENT_TAB);
286}
287
288bool BrowserCommandController::ExecuteCommandWithDisposition(
289 int id, WindowOpenDisposition disposition) {
290 // Doesn't go through the command_updater_ to avoid dealing with having a
291 // naming collision for ExecuteCommandWithDisposition (both
292 // CommandUpdaterDelegate and CommandUpdater declare this function so we
293 // choose to not implement CommandUpdaterDelegate inside this class and
294 // therefore command_updater_ doesn't have the delegate set).
295 if (!SupportsCommand(id) || !IsCommandEnabled(id))
296 return false;
297
[email protected]5d98294912012-06-27 22:57:40298 // No commands are enabled if there is not yet any selected tab.
299 // TODO(pkasting): It seems like we should not need this, because either
300 // most/all commands should not have been enabled yet anyway or the ones that
301 // are enabled should be global, or safe themselves against having no selected
302 // tab. However, Ben says he tried removing this before and got lots of
303 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
304 // window construction. This probably could use closer examination someday.
[email protected]59253a652012-11-20 00:17:26305 if (browser_->tab_strip_model()->active_index() == TabStripModel::kNoTab)
Ivan Sandrk9669d0e2017-12-15 23:50:20306 return true;
[email protected]5d98294912012-06-27 22:57:40307
308 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command "
309 << id;
310
[email protected]5d98294912012-06-27 22:57:40311 // The order of commands in this switch statement must match the function
312 // declaration order in browser.h!
313 switch (id) {
314 // Navigation commands
[email protected]5d98294912012-06-27 22:57:40315 case IDC_BACK:
[email protected]5d98294912012-06-27 22:57:40316 GoBack(browser_, disposition);
317 break;
[email protected]5d98294912012-06-27 22:57:40318 case IDC_FORWARD:
[email protected]5d98294912012-06-27 22:57:40319 GoForward(browser_, disposition);
320 break;
321 case IDC_RELOAD:
322 Reload(browser_, disposition);
323 break;
[email protected]58e29032012-08-06 20:19:57324 case IDC_RELOAD_CLEARING_CACHE:
325 ClearCache(browser_);
Nico Webera745ef72018-01-29 23:45:57326 FALLTHROUGH;
toyoshim7dad4b1182016-04-01 14:28:05327 case IDC_RELOAD_BYPASSING_CACHE:
328 ReloadBypassingCache(browser_, disposition);
[email protected]5d98294912012-06-27 22:57:40329 break;
330 case IDC_HOME:
331 Home(browser_, disposition);
332 break;
333 case IDC_OPEN_CURRENT_URL:
334 OpenCurrentURL(browser_);
335 break;
336 case IDC_STOP:
337 Stop(browser_);
338 break;
339
340 // Window management commands
341 case IDC_NEW_WINDOW:
342 NewWindow(browser_);
343 break;
344 case IDC_NEW_INCOGNITO_WINDOW:
345 NewIncognitoWindow(browser_);
346 break;
347 case IDC_CLOSE_WINDOW:
bratell0a7406f2017-03-28 07:46:37348 base::RecordAction(base::UserMetricsAction("CloseWindowByKey"));
[email protected]04b9e692012-08-24 14:49:09349 CloseWindow(browser_);
[email protected]5d98294912012-06-27 22:57:40350 break;
Bettina Dea0a4505922017-09-28 00:53:32351 case IDC_NEW_TAB: {
352 NewTab(browser_);
353#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Catherine Chungbeb884222017-08-01 15:47:55354 // This is not in NewTab() to avoid tracking programmatic creation of new
355 // tabs by extensions.
Bettina Dea0a4505922017-09-28 00:53:32356 auto* new_tab_tracker =
357 feature_engagement::NewTabTrackerFactory::GetInstance()
358 ->GetForProfile(profile());
359
360 new_tab_tracker->OnNewTabOpened();
361 new_tab_tracker->CloseBubble();
Catherine Chungbeb884222017-08-01 15:47:55362#endif
[email protected]5d98294912012-06-27 22:57:40363 break;
Bettina Dea0a4505922017-09-28 00:53:32364 }
[email protected]5d98294912012-06-27 22:57:40365 case IDC_CLOSE_TAB:
bratell0a7406f2017-03-28 07:46:37366 base::RecordAction(base::UserMetricsAction("CloseTabByKey"));
[email protected]04b9e692012-08-24 14:49:09367 CloseTab(browser_);
[email protected]5d98294912012-06-27 22:57:40368 break;
369 case IDC_SELECT_NEXT_TAB:
bratell0a7406f2017-03-28 07:46:37370 base::RecordAction(base::UserMetricsAction("Accel_SelectNextTab"));
[email protected]5d98294912012-06-27 22:57:40371 SelectNextTab(browser_);
372 break;
373 case IDC_SELECT_PREVIOUS_TAB:
bratell0a7406f2017-03-28 07:46:37374 base::RecordAction(base::UserMetricsAction("Accel_SelectPreviousTab"));
[email protected]5d98294912012-06-27 22:57:40375 SelectPreviousTab(browser_);
376 break;
[email protected]5d98294912012-06-27 22:57:40377 case IDC_MOVE_TAB_NEXT:
378 MoveTabNext(browser_);
379 break;
380 case IDC_MOVE_TAB_PREVIOUS:
381 MoveTabPrevious(browser_);
382 break;
383 case IDC_SELECT_TAB_0:
384 case IDC_SELECT_TAB_1:
385 case IDC_SELECT_TAB_2:
386 case IDC_SELECT_TAB_3:
387 case IDC_SELECT_TAB_4:
388 case IDC_SELECT_TAB_5:
389 case IDC_SELECT_TAB_6:
390 case IDC_SELECT_TAB_7:
bratell0a7406f2017-03-28 07:46:37391 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
[email protected]5d98294912012-06-27 22:57:40392 SelectNumberedTab(browser_, id - IDC_SELECT_TAB_0);
393 break;
394 case IDC_SELECT_LAST_TAB:
bratell0a7406f2017-03-28 07:46:37395 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
[email protected]5d98294912012-06-27 22:57:40396 SelectLastTab(browser_);
397 break;
398 case IDC_DUPLICATE_TAB:
399 DuplicateTab(browser_);
400 break;
401 case IDC_RESTORE_TAB:
402 RestoreTab(browser_);
403 break;
[email protected]5d98294912012-06-27 22:57:40404 case IDC_SHOW_AS_TAB:
405 ConvertPopupToTabbedBrowser(browser_);
406 break;
407 case IDC_FULLSCREEN:
[email protected]3f32b9b2012-07-09 16:59:28408 chrome::ToggleFullscreenMode(browser_);
[email protected]5d98294912012-06-27 22:57:40409 break;
Alan Cutter09965802018-03-27 07:25:29410 case IDC_OPEN_IN_PWA_WINDOW:
411 base::RecordAction(base::UserMetricsAction("OpenActiveTabInPwaWindow"));
412 ReparentSecureActiveTabIntoPwaWindow(browser_);
413 break;
[email protected]770c6d82012-09-06 22:21:32414
[email protected]d12cc5e2013-10-19 18:25:06415#if defined(OS_CHROMEOS)
416 case IDC_VISIT_DESKTOP_OF_LRU_USER_2:
[email protected]0c930812014-01-30 18:01:47417 case IDC_VISIT_DESKTOP_OF_LRU_USER_3:
zijiehe4dde8072017-02-13 20:38:35418 ExecuteVisitDesktopCommand(id, window()->GetNativeWindow());
[email protected]0c930812014-01-30 18:01:47419 break;
[email protected]d12cc5e2013-10-19 18:25:06420#endif
421
[email protected]893124a22014-04-15 00:45:28422#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15423 case IDC_MINIMIZE_WINDOW:
424 browser_->window()->Minimize();
425 break;
426 case IDC_MAXIMIZE_WINDOW:
427 browser_->window()->Maximize();
428 break;
429 case IDC_RESTORE_WINDOW:
430 browser_->window()->Restore();
431 break;
[email protected]af97be4c62014-02-13 14:43:34432 case IDC_USE_SYSTEM_TITLE_BAR: {
zijiehe4dde8072017-02-13 20:38:35433 PrefService* prefs = profile()->GetPrefs();
[email protected]af97be4c62014-02-13 14:43:34434 prefs->SetBoolean(prefs::kUseCustomChromeFrame,
435 !prefs->GetBoolean(prefs::kUseCustomChromeFrame));
436 break;
437 }
438#endif
439
[email protected]5d98294912012-06-27 22:57:40440#if defined(OS_MACOSX)
spqchanb8ffc7d2015-11-17 01:17:21441 case IDC_TOGGLE_FULLSCREEN_TOOLBAR:
442 chrome::ToggleFullscreenToolbar(browser_);
443 break;
spqchan2c5d541e2017-10-25 07:07:11444 case IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS: {
445 PrefService* prefs = profile()->GetPrefs();
446 prefs->SetBoolean(prefs::kAllowJavascriptAppleEvents,
447 !prefs->GetBoolean(prefs::kAllowJavascriptAppleEvents));
448 break;
449 }
[email protected]5d98294912012-06-27 22:57:40450#endif
451 case IDC_EXIT:
452 Exit();
453 break;
454
455 // Page-related commands
456 case IDC_SAVE_PAGE:
457 SavePage(browser_);
458 break;
459 case IDC_BOOKMARK_PAGE:
Anatoly Pilikovee720922017-11-01 09:43:17460#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:14461 feature_engagement::BookmarkTrackerFactory::GetInstance()
462 ->GetForProfile(profile())
463 ->OnBookmarkAdded();
464#endif
deepak.m154a7f392014-12-15 04:41:43465 BookmarkCurrentPageAllowingExtensionOverrides(browser_);
[email protected]5d98294912012-06-27 22:57:40466 break;
[email protected]5d98294912012-06-27 22:57:40467 case IDC_BOOKMARK_ALL_TABS:
Anatoly Pilikovee720922017-11-01 09:43:17468#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:14469 feature_engagement::BookmarkTrackerFactory::GetInstance()
470 ->GetForProfile(profile())
471 ->OnBookmarkAdded();
472#endif
[email protected]5d98294912012-06-27 22:57:40473 BookmarkAllTabs(browser_);
474 break;
475 case IDC_VIEW_SOURCE:
Lukasz Anforowicze1b954d92017-10-30 21:28:06476 browser_->tab_strip_model()
477 ->GetActiveWebContents()
478 ->GetMainFrame()
479 ->ViewSource();
[email protected]5d98294912012-06-27 22:57:40480 break;
481 case IDC_EMAIL_PAGE_LOCATION:
482 EmailPageLocation(browser_);
483 break;
484 case IDC_PRINT:
485 Print(browser_);
486 break;
bondd052b5f82015-10-28 22:39:32487
Lei Zhang48a4a5262018-04-17 20:18:44488#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:55489 case IDC_BASIC_PRINT:
bratell0a7406f2017-03-28 07:46:37490 base::RecordAction(base::UserMetricsAction("Accel_Advanced_Print"));
vitalybukaf9433e42014-09-08 10:04:55491 BasicPrint(browser_);
[email protected]5d98294912012-06-27 22:57:40492 break;
Lei Zhang48a4a5262018-04-17 20:18:44493#endif // ENABLE_PRINTING
bondd052b5f82015-10-28 22:39:32494
bondd052b5f82015-10-28 22:39:32495 case IDC_SAVE_CREDIT_CARD_FOR_PAGE:
496 SaveCreditCard(browser_);
497 break;
siyua3e599eaa2018-07-13 00:23:06498 case IDC_MIGRATE_LOCAL_CREDIT_CARD_FOR_PAGE:
499 MigrateLocalCards(browser_);
500 break;
[email protected]e625b7602013-10-28 09:24:56501 case IDC_TRANSLATE_PAGE:
502 Translate(browser_);
503 break;
[email protected]4bee4432014-05-05 13:11:41504 case IDC_MANAGE_PASSWORDS_FOR_PAGE:
505 ManagePasswordsForPage(browser_);
506 break;
507
[email protected]5d98294912012-06-27 22:57:40508 // Clipboard commands
509 case IDC_CUT:
[email protected]5d98294912012-06-27 22:57:40510 case IDC_COPY:
[email protected]5d98294912012-06-27 22:57:40511 case IDC_PASTE:
pkastingcd3f08bce2015-04-18 13:37:12512 CutCopyPaste(browser_, id);
[email protected]5d98294912012-06-27 22:57:40513 break;
514
515 // Find-in-page
516 case IDC_FIND:
517 Find(browser_);
518 break;
519 case IDC_FIND_NEXT:
520 FindNext(browser_);
521 break;
522 case IDC_FIND_PREVIOUS:
523 FindPrevious(browser_);
524 break;
525
526 // Zoom
527 case IDC_ZOOM_PLUS:
528 Zoom(browser_, content::PAGE_ZOOM_IN);
529 break;
530 case IDC_ZOOM_NORMAL:
531 Zoom(browser_, content::PAGE_ZOOM_RESET);
532 break;
533 case IDC_ZOOM_MINUS:
534 Zoom(browser_, content::PAGE_ZOOM_OUT);
535 break;
536
537 // Focus various bits of UI
538 case IDC_FOCUS_TOOLBAR:
bratell0a7406f2017-03-28 07:46:37539 base::RecordAction(base::UserMetricsAction("Accel_Focus_Toolbar"));
[email protected]5d98294912012-06-27 22:57:40540 FocusToolbar(browser_);
541 break;
542 case IDC_FOCUS_LOCATION:
bratell0a7406f2017-03-28 07:46:37543 base::RecordAction(base::UserMetricsAction("Accel_Focus_Location"));
[email protected]5d98294912012-06-27 22:57:40544 FocusLocationBar(browser_);
545 break;
546 case IDC_FOCUS_SEARCH:
bratell0a7406f2017-03-28 07:46:37547 base::RecordAction(base::UserMetricsAction("Accel_Focus_Search"));
[email protected]5d98294912012-06-27 22:57:40548 FocusSearch(browser_);
549 break;
550 case IDC_FOCUS_MENU_BAR:
551 FocusAppMenu(browser_);
552 break;
553 case IDC_FOCUS_BOOKMARKS:
bratell0a7406f2017-03-28 07:46:37554 base::RecordAction(base::UserMetricsAction("Accel_Focus_Bookmarks"));
[email protected]5d98294912012-06-27 22:57:40555 FocusBookmarksToolbar(browser_);
556 break;
David Tsengc0b1b642018-01-24 07:12:27557 case IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY:
558 FocusInactivePopupForAccessibility(browser_);
[email protected]822ca8c62013-04-19 00:49:15559 break;
[email protected]5d98294912012-06-27 22:57:40560 case IDC_FOCUS_NEXT_PANE:
561 FocusNextPane(browser_);
562 break;
563 case IDC_FOCUS_PREVIOUS_PANE:
564 FocusPreviousPane(browser_);
565 break;
566
567 // Show various bits of UI
568 case IDC_OPEN_FILE:
569 browser_->OpenFile();
570 break;
Alan Cutter81ac726682018-09-25 00:18:36571 case IDC_CREATE_SHORTCUT:
572 CreateBookmarkAppFromCurrentWebContents(browser_,
573 true /* force_shortcut_app */);
574 break;
575 case IDC_INSTALL_PWA:
576 CreateBookmarkAppFromCurrentWebContents(browser_,
577 false /* force_shortcut_app */);
[email protected]488e3952013-11-18 05:29:14578 break;
[email protected]5d98294912012-06-27 22:57:40579 case IDC_DEV_TOOLS:
[email protected]c934c382013-11-01 00:36:01580 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Show());
[email protected]5d98294912012-06-27 22:57:40581 break;
582 case IDC_DEV_TOOLS_CONSOLE:
einbinderdfa567b2016-12-16 01:15:52583 ToggleDevToolsWindow(browser_, DevToolsToggleAction::ShowConsolePanel());
[email protected]5d98294912012-06-27 22:57:40584 break;
[email protected]2056c3192013-10-21 22:40:51585 case IDC_DEV_TOOLS_DEVICES:
586 InspectUI::InspectDevices(browser_);
587 break;
[email protected]5d98294912012-06-27 22:57:40588 case IDC_DEV_TOOLS_INSPECT:
[email protected]c934c382013-11-01 00:36:01589 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Inspect());
[email protected]5d98294912012-06-27 22:57:40590 break;
[email protected]d16657c2012-09-03 14:25:10591 case IDC_DEV_TOOLS_TOGGLE:
[email protected]c934c382013-11-01 00:36:01592 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Toggle());
[email protected]d16657c2012-09-03 14:25:10593 break;
[email protected]5d98294912012-06-27 22:57:40594 case IDC_TASK_MANAGER:
[email protected]29c262de2013-06-22 15:39:38595 OpenTaskManager(browser_);
[email protected]5d98294912012-06-27 22:57:40596 break;
caelyn4e4e08a2015-02-04 21:27:49597#if defined(OS_CHROMEOS)
598 case IDC_TAKE_SCREENSHOT:
599 TakeScreenshot();
600 break;
601#endif
[email protected]236ad3022013-09-04 03:27:43602#if defined(GOOGLE_CHROME_BUILD)
[email protected]5d98294912012-06-27 22:57:40603 case IDC_FEEDBACK:
afakhryf4575bd2017-04-28 02:21:04604 OpenFeedbackDialog(browser_, kFeedbackSourceBrowserCommand);
[email protected]5d98294912012-06-27 22:57:40605 break;
[email protected]236ad3022013-09-04 03:27:43606#endif
[email protected]5d98294912012-06-27 22:57:40607 case IDC_SHOW_BOOKMARK_BAR:
608 ToggleBookmarkBar(browser_);
609 break;
610 case IDC_PROFILING_ENABLED:
611 Profiling::Toggle();
612 break;
613
614 case IDC_SHOW_BOOKMARK_MANAGER:
615 ShowBookmarkManager(browser_);
616 break;
617 case IDC_SHOW_APP_MENU:
bratell0a7406f2017-03-28 07:46:37618 base::RecordAction(base::UserMetricsAction("Accel_Show_App_Menu"));
[email protected]5d98294912012-06-27 22:57:40619 ShowAppMenu(browser_);
620 break;
621 case IDC_SHOW_AVATAR_MENU:
622 ShowAvatarMenu(browser_);
623 break;
[email protected]5d98294912012-06-27 22:57:40624 case IDC_SHOW_HISTORY:
625 ShowHistory(browser_);
626 break;
627 case IDC_SHOW_DOWNLOADS:
628 ShowDownloads(browser_);
629 break;
630 case IDC_MANAGE_EXTENSIONS:
[email protected]bc9833c32013-02-28 04:05:08631 ShowExtensions(browser_, std::string());
[email protected]5d98294912012-06-27 22:57:40632 break;
633 case IDC_OPTIONS:
634 ShowSettings(browser_);
635 break;
636 case IDC_EDIT_SEARCH_ENGINES:
637 ShowSearchEngineSettings(browser_);
638 break;
639 case IDC_VIEW_PASSWORDS:
640 ShowPasswordManager(browser_);
641 break;
642 case IDC_CLEAR_BROWSING_DATA:
643 ShowClearBrowsingDataDialog(browser_);
644 break;
645 case IDC_IMPORT_SETTINGS:
646 ShowImportDialog(browser_);
647 break;
[email protected]9b7ab882012-09-10 23:46:36648 case IDC_TOGGLE_REQUEST_TABLET_SITE:
649 ToggleRequestTabletSite(browser_);
650 break;
[email protected]5d98294912012-06-27 22:57:40651 case IDC_ABOUT:
652 ShowAboutChrome(browser_);
653 break;
654 case IDC_UPGRADE_DIALOG:
655 OpenUpdateChromeDialog(browser_);
656 break;
[email protected]5d98294912012-06-27 22:57:40657 case IDC_HELP_PAGE_VIA_KEYBOARD:
658 ShowHelp(browser_, HELP_SOURCE_KEYBOARD);
659 break;
660 case IDC_HELP_PAGE_VIA_MENU:
661 ShowHelp(browser_, HELP_SOURCE_MENU);
662 break;
Bret Sepulveda2d018662017-05-18 21:31:48663 case IDC_SHOW_BETA_FORUM:
664 ShowBetaForum(browser_);
665 break;
estade8c0780f2015-08-21 23:36:41666 case IDC_SHOW_SIGNIN:
gogerald71bf6c902015-12-08 00:49:37667 ShowBrowserSigninOrSettings(
668 browser_, signin_metrics::AccessPoint::ACCESS_POINT_MENU);
estade8c0780f2015-08-21 23:36:41669 break;
[email protected]6bd370b2014-05-28 14:19:47670 case IDC_DISTILL_PAGE:
671 DistillCurrentPage(browser_);
672 break;
apacible45cbfc92015-09-28 22:45:41673 case IDC_ROUTE_MEDIA:
674 RouteMedia(browser_);
675 break;
Tommy Steimelc4477982017-11-29 18:07:18676 case IDC_WINDOW_MUTE_SITE:
677 MuteSite(browser_);
ellyjones0101ba02017-05-19 15:50:26678 break;
679 case IDC_WINDOW_PIN_TAB:
680 PinTab(browser_);
681 break;
[email protected]5d98294912012-06-27 22:57:40682
Christopher Lam0dbac2b2017-11-14 07:12:10683 // Hosted App commands
684 case IDC_COPY_URL:
685 CopyURL(browser_);
686 break;
687 case IDC_OPEN_IN_CHROME:
688 OpenInChrome(browser_);
689 break;
690 case IDC_SITE_SETTINGS:
691 ShowSiteSettings(
692 browser_,
693 browser_->tab_strip_model()->GetActiveWebContents()->GetVisibleURL());
694 break;
Alan Cutter0c3132302018-02-21 05:09:02695 case IDC_HOSTED_APP_MENU_APP_INFO:
696 ShowPageInfoDialog(browser_->tab_strip_model()->GetActiveWebContents(),
Alan Cutter689f89a2018-03-08 05:09:54697 bubble_anchor_util::kAppMenuButton);
Christopher Lam86b52712017-12-04 01:58:33698 break;
Christopher Lam0dbac2b2017-11-14 07:12:10699
[email protected]5d98294912012-06-27 22:57:40700 default:
701 LOG(WARNING) << "Received Unimplemented Command: " << id;
702 break;
703 }
Ivan Sandrk9669d0e2017-12-15 23:50:20704
705 return true;
706}
707
708void BrowserCommandController::AddCommandObserver(int id,
709 CommandObserver* observer) {
710 command_updater_.AddCommandObserver(id, observer);
711}
712
713void BrowserCommandController::RemoveCommandObserver(
714 int id, CommandObserver* observer) {
715 command_updater_.RemoveCommandObserver(id, observer);
716}
717
718void BrowserCommandController::RemoveCommandObserver(
719 CommandObserver* observer) {
720 command_updater_.RemoveCommandObserver(observer);
721}
722
723bool BrowserCommandController::UpdateCommandEnabled(int id, bool state) {
724 if (is_locked_fullscreen_)
725 return false;
726
727 return command_updater_.UpdateCommandEnabled(id, state);
[email protected]5d98294912012-06-27 22:57:40728}
729
Mihai Sardarescuf87ccc12018-09-26 10:37:45730////////////////////////////////////////////////////////////////////////////////
731// BrowserCommandController, SigninPrefObserver implementation:
732
733void BrowserCommandController::OnSigninAllowedPrefChange() {
734 // For unit tests, we don't have a window.
735 if (!window())
736 return;
737 UpdateShowSyncState(IsShowingMainUI());
738}
739
[email protected]5d98294912012-06-27 22:57:40740// BrowserCommandController, TabStripModelObserver implementation:
741
pmonette9119e492016-09-20 22:14:55742void BrowserCommandController::TabInsertedAt(TabStripModel* tab_strip_model,
743 WebContents* contents,
[email protected]5d98294912012-06-27 22:57:40744 int index,
745 bool foreground) {
746 AddInterstitialObservers(contents);
747}
748
erikchen12c65582018-05-14 17:26:04749void BrowserCommandController::TabDetachedAt(WebContents* contents,
750 int index,
751 bool was_active) {
[email protected]5d98294912012-06-27 22:57:40752 RemoveInterstitialObservers(contents);
753}
754
755void BrowserCommandController::TabReplacedAt(TabStripModel* tab_strip_model,
[email protected]b624ddc2012-11-15 18:04:13756 WebContents* old_contents,
757 WebContents* new_contents,
[email protected]5d98294912012-06-27 22:57:40758 int index) {
[email protected]b624ddc2012-11-15 18:04:13759 RemoveInterstitialObservers(old_contents);
760 AddInterstitialObservers(new_contents);
[email protected]5d98294912012-06-27 22:57:40761}
762
[email protected]3cac87232012-11-20 01:48:27763void BrowserCommandController::TabBlockedStateChanged(
764 content::WebContents* contents,
765 int index) {
766 PrintingStateChanged();
767 FullscreenStateChanged();
768 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:41769 UpdateCommandsForMediaRouter();
[email protected]3cac87232012-11-20 01:48:27770}
771
[email protected]5d98294912012-06-27 22:57:40772////////////////////////////////////////////////////////////////////////////////
773// BrowserCommandController, TabRestoreServiceObserver implementation:
774
775void BrowserCommandController::TabRestoreServiceChanged(
blundell74001adc2015-09-18 11:04:25776 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53777 UpdateTabRestoreCommandState();
[email protected]5d98294912012-06-27 22:57:40778}
779
780void BrowserCommandController::TabRestoreServiceDestroyed(
blundell74001adc2015-09-18 11:04:25781 sessions::TabRestoreService* service) {
[email protected]5d98294912012-06-27 22:57:40782 service->RemoveObserver(this);
783}
784
[email protected]2e9369e2014-08-15 09:12:53785void BrowserCommandController::TabRestoreServiceLoaded(
blundell74001adc2015-09-18 11:04:25786 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53787 UpdateTabRestoreCommandState();
788}
789
[email protected]5d98294912012-06-27 22:57:40790////////////////////////////////////////////////////////////////////////////////
[email protected]5d98294912012-06-27 22:57:40791// BrowserCommandController, private:
792
[email protected]20ca0382013-02-28 19:50:07793class BrowserCommandController::InterstitialObserver
794 : public content::WebContentsObserver {
795 public:
796 InterstitialObserver(BrowserCommandController* controller,
797 content::WebContents* web_contents)
798 : WebContentsObserver(web_contents),
799 controller_(controller) {
800 }
801
dcheng5dd5ff62014-10-21 12:42:38802 void DidAttachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07803 controller_->UpdateCommandsForTabState();
804 }
805
dcheng5dd5ff62014-10-21 12:42:38806 void DidDetachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07807 controller_->UpdateCommandsForTabState();
808 }
809
810 private:
811 BrowserCommandController* controller_;
812
813 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver);
814};
815
[email protected]6a414ff2013-02-27 08:22:54816bool BrowserCommandController::IsShowingMainUI() {
817 bool should_hide_ui = window() && window()->ShouldHideUIForFullscreen();
818 return browser_->is_type_tabbed() && !should_hide_ui;
[email protected]5d98294912012-06-27 22:57:40819}
820
821void BrowserCommandController::InitCommandState() {
822 // All browser commands whose state isn't set automagically some other way
823 // (like Back & Forward with initial page load) must have their state
824 // initialized here, otherwise they will be forever disabled.
825
Ivan Sandrk9669d0e2017-12-15 23:50:20826 if (is_locked_fullscreen_)
827 return;
828
[email protected]5d98294912012-06-27 22:57:40829 // Navigation commands
830 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true);
toyoshim7dad4b1182016-04-01 14:28:05831 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE, true);
[email protected]58e29032012-08-06 20:19:57832 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, true);
[email protected]5d98294912012-06-27 22:57:40833
834 // Window management commands
835 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true);
836 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true);
837 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true);
838 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true);
[email protected]2e9369e2014-08-15 09:12:53839 UpdateTabRestoreCommandState();
[email protected]d28d3782013-02-26 16:31:55840 command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
[email protected]5d98294912012-06-27 22:57:40841 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true);
[email protected]d12cc5e2013-10-19 18:25:06842#if defined(OS_CHROMEOS)
James Cook934abaf2017-09-19 22:21:58843 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
[email protected]d12cc5e2013-10-19 18:25:06844 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_2, true);
845 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_3, true);
846#endif
[email protected]893124a22014-04-15 00:45:28847#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15848 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
849 command_updater_.UpdateCommandEnabled(IDC_MAXIMIZE_WINDOW, true);
850 command_updater_.UpdateCommandEnabled(IDC_RESTORE_WINDOW, true);
Maksim Sisovac767592018-08-10 08:00:15851 bool use_system_title_bar = true;
852#if defined(USE_OZONE)
853 use_system_title_bar = ui::OzonePlatform::GetInstance()
854 ->GetPlatformProperties()
855 .use_system_title_bar;
856#endif
857 command_updater_.UpdateCommandEnabled(IDC_USE_SYSTEM_TITLE_BAR,
858 use_system_title_bar);
[email protected]af97be4c62014-02-13 14:43:34859#endif
Alan Cutter09965802018-03-27 07:25:29860 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW, true);
[email protected]5d98294912012-06-27 22:57:40861
862 // Page-related commands
863 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true);
[email protected]4bee4432014-05-05 13:11:41864 command_updater_.UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE, true);
[email protected]5d98294912012-06-27 22:57:40865
866 // Zoom
867 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true);
868 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true);
[email protected]d93dbd12014-08-04 23:42:53869 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, false);
[email protected]5d98294912012-06-27 22:57:40870 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
871
872 // Show various bits of UI
mlerman7831f57d2015-05-25 11:40:15873 const bool guest_session = profile()->IsGuestSession() ||
874 profile()->IsSystemProfile();
875 DCHECK(!profile()->IsSystemProfile())
876 << "Ought to never have browser for the system profile.";
[email protected]338416c02014-05-13 16:47:06877 const bool normal_window = browser_->is_type_tabbed();
[email protected]05454532013-01-22 21:09:08878 UpdateOpenFileState(&command_updater_);
[email protected]5d98294912012-06-27 22:57:40879 UpdateCommandsForDevTools();
880 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager());
[email protected]338416c02014-05-13 16:47:06881 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session);
[email protected]5d98294912012-06-27 22:57:40882 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
[email protected]674b65672014-06-02 23:21:56883 command_updater_.UpdateCommandEnabled(IDC_HELP_MENU, true);
[email protected]5d98294912012-06-27 22:57:40884 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
885 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
Bret Sepulveda2d018662017-05-18 21:31:48886 command_updater_.UpdateCommandEnabled(IDC_SHOW_BETA_FORUM, true);
[email protected]338416c02014-05-13 16:47:06887 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session);
[email protected]2f1acc212012-11-13 10:43:51888 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU,
[email protected]338416c02014-05-13 16:47:06889 !guest_session &&
[email protected]2f1acc212012-11-13 10:43:51890 !profile()->IsOffTheRecord());
tsergeant341a8272017-04-18 03:54:33891 command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA,
892 !guest_session);
[email protected]39d47592014-01-10 21:42:45893#if defined(OS_CHROMEOS)
caelyn4e4e08a2015-02-04 21:27:49894 command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true);
[email protected]338416c02014-05-13 16:47:06895#else
896 // Chrome OS uses the system tray menu to handle multi-profiles.
anthonyvd7dc985da2015-03-23 16:53:19897 if (normal_window && (guest_session || !profile()->IsOffTheRecord())) {
[email protected]338416c02014-05-13 16:47:06898 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
anthonyvd7dc985da2015-03-23 16:53:19899 }
[email protected]39d47592014-01-10 21:42:45900#endif
[email protected]5d98294912012-06-27 22:57:40901
Mihai Sardarescu2ec5205682018-09-26 09:20:05902 UpdateShowSyncState(true);
903
[email protected]5d98294912012-06-27 22:57:40904 // Navigation commands
[email protected]c9f983d2014-02-05 09:00:24905 command_updater_.UpdateCommandEnabled(
906 IDC_HOME,
benwellsc431c0ae2015-01-27 22:04:06907 normal_window ||
908 (extensions::util::IsNewBookmarkAppsEnabled() && browser_->is_app()));
[email protected]5d98294912012-06-27 22:57:40909
Christopher Lam0dbac2b2017-11-14 07:12:10910 const bool is_experimental_hosted_app =
911 extensions::HostedAppBrowserController::IsForExperimentalHostedAppBrowser(
912 browser_);
913 // Hosted app browser commands.
914 command_updater_.UpdateCommandEnabled(IDC_COPY_URL,
915 is_experimental_hosted_app);
916 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_CHROME,
917 is_experimental_hosted_app);
918 command_updater_.UpdateCommandEnabled(IDC_SITE_SETTINGS,
919 is_experimental_hosted_app);
Alan Cutter0c3132302018-02-21 05:09:02920 command_updater_.UpdateCommandEnabled(IDC_HOSTED_APP_MENU_APP_INFO,
Christopher Lam86b52712017-12-04 01:58:33921 is_experimental_hosted_app);
Christopher Lam0dbac2b2017-11-14 07:12:10922
[email protected]5d98294912012-06-27 22:57:40923 // Window management commands
[email protected]5d98294912012-06-27 22:57:40924 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window);
925 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB,
926 normal_window);
927 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window);
928 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window);
929 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window);
930 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window);
931 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window);
932 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window);
933 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window);
934 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window);
935 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window);
936 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window);
937 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window);
[email protected]5d98294912012-06-27 22:57:40938
[email protected]338416c02014-05-13 16:47:06939 // These are always enabled; the menu determines their menu item visibility.
[email protected]5d98294912012-06-27 22:57:40940 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
[email protected]5d98294912012-06-27 22:57:40941
[email protected]6bd370b2014-05-28 14:19:47942 // Distill current page.
943 command_updater_.UpdateCommandEnabled(
avi556c05022014-12-22 23:31:43944 IDC_DISTILL_PAGE, base::CommandLine::ForCurrentProcess()->HasSwitch(
945 switches::kEnableDomDistiller));
[email protected]6bd370b2014-05-28 14:19:47946
Tommy Steimelc4477982017-11-29 18:07:18947 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE, normal_window);
ellyjones0101ba02017-05-19 15:50:26948 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, normal_window);
949
[email protected]338416c02014-05-13 16:47:06950 // Initialize other commands whose state changes based on various conditions.
[email protected]32dfede2013-08-25 15:48:25951 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40952 UpdateCommandsForContentRestrictionState();
[email protected]5d98294912012-06-27 22:57:40953 UpdateCommandsForBookmarkEditing();
[email protected]5d98294912012-06-27 22:57:40954 UpdateCommandsForIncognitoAvailability();
955}
956
[email protected]05454532013-01-22 21:09:08957// static
958void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
959 CommandUpdater* command_updater,
960 Profile* profile) {
mlermane01e6de2014-09-29 19:26:47961 const bool guest_session = profile->IsGuestSession();
962 // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession().
[email protected]5d98294912012-06-27 22:57:40963 IncognitoModePrefs::Availability incognito_availability =
[email protected]05454532013-01-22 21:09:08964 IncognitoModePrefs::GetAvailability(profile->GetPrefs());
965 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40966 IDC_NEW_WINDOW,
967 incognito_availability != IncognitoModePrefs::FORCED);
[email protected]05454532013-01-22 21:09:08968 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40969 IDC_NEW_INCOGNITO_WINDOW,
mlermane01e6de2014-09-29 19:26:47970 incognito_availability != IncognitoModePrefs::DISABLED && !guest_session);
[email protected]5d98294912012-06-27 22:57:40971
[email protected]57b25292014-05-01 16:31:06972 const bool forced_incognito =
973 incognito_availability == IncognitoModePrefs::FORCED ||
974 guest_session; // Guest always runs in Incognito mode.
[email protected]05454532013-01-22 21:09:08975 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40976 IDC_SHOW_BOOKMARK_MANAGER,
[email protected]57b25292014-05-01 16:31:06977 browser_defaults::bookmarks_enabled && !forced_incognito);
Devlin Cronin21dba422018-05-30 15:45:16978 extensions::ExtensionService* extension_service =
[email protected]03d25812014-06-22 19:41:55979 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]57b25292014-05-01 16:31:06980 const bool enable_extensions =
[email protected]5d98294912012-06-27 22:57:40981 extension_service && extension_service->extensions_enabled();
[email protected]5d98294912012-06-27 22:57:40982
[email protected]57b25292014-05-01 16:31:06983 // Bookmark manager and settings page/subpages are forced to open in normal
984 // mode. For this reason we disable these commands when incognito is forced.
985 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
986 enable_extensions && !forced_incognito);
987
988 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito);
989 command_updater->UpdateCommandEnabled(IDC_OPTIONS,
990 !forced_incognito || guest_session);
estade8c0780f2015-08-21 23:36:41991 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito);
[email protected]05454532013-01-22 21:09:08992}
993
994void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
Ivan Sandrk9669d0e2017-12-15 23:50:20995 if (is_locked_fullscreen_)
996 return;
997
[email protected]05454532013-01-22 21:09:08998 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile());
999
[email protected]6a414ff2013-02-27 08:22:541000 if (!IsShowingMainUI()) {
[email protected]05454532013-01-22 21:09:081001 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false);
1002 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false);
1003 }
[email protected]5d98294912012-06-27 22:57:401004}
1005
1006void BrowserCommandController::UpdateCommandsForTabState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201007 if (is_locked_fullscreen_)
1008 return;
1009
[email protected]617ee962013-01-29 20:49:121010 WebContents* current_web_contents =
1011 browser_->tab_strip_model()->GetActiveWebContents();
[email protected]1c5119c2012-09-19 00:08:571012 if (!current_web_contents) // May be NULL during tab restore.
[email protected]5d98294912012-06-27 22:57:401013 return;
[email protected]5d98294912012-06-27 22:57:401014
1015 // Navigation commands
[email protected]5d98294912012-06-27 22:57:401016 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_));
[email protected]5d98294912012-06-27 22:57:401017 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_));
1018 command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_));
toyoshim7dad4b1182016-04-01 14:28:051019 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE,
[email protected]5d98294912012-06-27 22:57:401020 CanReload(browser_));
[email protected]58e29032012-08-06 20:19:571021 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE,
1022 CanReload(browser_));
[email protected]5d98294912012-06-27 22:57:401023
1024 // Window management commands
1025 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB,
1026 !browser_->is_app() && CanDuplicateTab(browser_));
Tommy Steimelc4477982017-11-29 18:07:181027 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE,
ellyjones0101ba02017-05-19 15:50:261028 !browser_->is_app());
1029 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB,
1030 !browser_->is_app());
[email protected]5d98294912012-06-27 22:57:401031
1032 // Page-related commands
1033 window()->SetStarredState(
[email protected]1c5119c2012-09-19 00:08:571034 BookmarkTabHelper::FromWebContents(current_web_contents)->is_starred());
[email protected]5423c372012-08-22 05:50:161035 window()->ZoomChangedForActiveTab(false);
[email protected]5d98294912012-06-27 22:57:401036 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
1037 CanViewSource(browser_));
1038 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION,
1039 CanEmailPageLocation(browser_));
1040 if (browser_->is_devtools())
1041 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false);
1042
Alan Cutter81ac726682018-09-25 00:18:361043 bool can_create_bookmark_app = CanCreateBookmarkApp(browser_);
1044 command_updater_.UpdateCommandEnabled(IDC_INSTALL_PWA,
1045 can_create_bookmark_app);
1046 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUT,
1047 can_create_bookmark_app);
Alan Cutter403cebb2018-05-17 05:22:451048 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW,
Alan Cutter81ac726682018-09-25 00:18:361049 can_create_bookmark_app);
[email protected]5d98294912012-06-27 22:57:401050
[email protected]9b7ab882012-09-10 23:46:361051 command_updater_.UpdateCommandEnabled(
1052 IDC_TOGGLE_REQUEST_TABLET_SITE,
1053 CanRequestTabletSite(current_web_contents));
1054
[email protected]5d98294912012-06-27 22:57:401055 UpdateCommandsForContentRestrictionState();
1056 UpdateCommandsForBookmarkEditing();
[email protected]3cac87232012-11-20 01:48:271057 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:411058 UpdateCommandsForMediaRouter();
[email protected]d93dbd12014-08-04 23:42:531059 // Update the zoom commands when an active tab is selected.
1060 UpdateCommandsForZoomState();
1061}
1062
1063void BrowserCommandController::UpdateCommandsForZoomState() {
1064 WebContents* contents =
1065 browser_->tab_strip_model()->GetActiveWebContents();
1066 if (!contents)
1067 return;
a.sarkar.arundaadc712015-02-26 05:39:081068 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS,
1069 CanZoomIn(contents));
1070 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL,
ccameronb7c1d6c2015-03-09 17:08:241071 CanResetZoom(contents));
a.sarkar.arundaadc712015-02-26 05:39:081072 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS,
1073 CanZoomOut(contents));
[email protected]5d98294912012-06-27 22:57:401074}
1075
1076void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
1077 int restrictions = GetContentRestrictions(browser_);
1078
1079 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011080 IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY));
[email protected]5d98294912012-06-27 22:57:401081 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011082 IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT));
[email protected]5d98294912012-06-27 22:57:401083 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011084 IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE));
[email protected]5d98294912012-06-27 22:57:401085 UpdateSaveAsState();
1086 UpdatePrintingState();
1087}
1088
1089void BrowserCommandController::UpdateCommandsForDevTools() {
Ivan Sandrk9669d0e2017-12-15 23:50:201090 if (is_locked_fullscreen_)
1091 return;
1092
Pavol Marko56df0272018-07-04 17:55:041093 bool dev_tools_enabled = DevToolsWindow::AllowDevToolsFor(
1094 profile(), browser_->tab_strip_model()->GetActiveWebContents());
[email protected]5d98294912012-06-27 22:57:401095 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS,
1096 dev_tools_enabled);
1097 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE,
1098 dev_tools_enabled);
[email protected]2056c3192013-10-21 22:40:511099 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES,
1100 dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401101 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT,
1102 dev_tools_enabled);
[email protected]d16657c2012-09-03 14:25:101103 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE,
1104 dev_tools_enabled);
spqchan2c5d541e2017-10-25 07:07:111105#if defined(OS_MACOSX)
1106 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS,
1107 dev_tools_enabled);
1108#endif
[email protected]5d98294912012-06-27 22:57:401109}
1110
1111void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
Ivan Sandrk9669d0e2017-12-15 23:50:201112 if (is_locked_fullscreen_)
1113 return;
1114
[email protected]5d98294912012-06-27 22:57:401115 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE,
1116 CanBookmarkCurrentPage(browser_));
1117 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
1118 CanBookmarkAllTabs(browser_));
thestig5149d272014-10-30 07:25:291119#if defined(OS_WIN)
1120 command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN, true);
1121#endif
[email protected]5d98294912012-06-27 22:57:401122}
1123
1124void BrowserCommandController::UpdateCommandsForBookmarkBar() {
Ivan Sandrk9669d0e2017-12-15 23:50:201125 if (is_locked_fullscreen_)
1126 return;
1127
tfarina3bddbe112014-08-28 05:29:321128 command_updater_.UpdateCommandEnabled(
1129 IDC_SHOW_BOOKMARK_BAR,
1130 browser_defaults::bookmarks_enabled && !profile()->IsGuestSession() &&
mlerman7831f57d2015-05-25 11:40:151131 !profile()->IsSystemProfile() &&
tfarina3bddbe112014-08-28 05:29:321132 !profile()->GetPrefs()->IsManagedPreference(
1133 bookmarks::prefs::kShowBookmarkBar) &&
1134 IsShowingMainUI());
[email protected]5d98294912012-06-27 22:57:401135}
1136
[email protected]9ec3ea5b2012-12-03 18:14:301137void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
Ivan Sandrk9669d0e2017-12-15 23:50:201138 if (is_locked_fullscreen_)
1139 return;
1140
[email protected]9ec3ea5b2012-12-03 18:14:301141 UpdateSaveAsState();
[email protected]05454532013-01-22 21:09:081142 UpdateOpenFileState(&command_updater_);
[email protected]9ec3ea5b2012-12-03 18:14:301143}
1144
[email protected]32dfede2013-08-25 15:48:251145void BrowserCommandController::UpdateCommandsForFullscreenMode() {
Ivan Sandrk9669d0e2017-12-15 23:50:201146 if (is_locked_fullscreen_)
1147 return;
1148
zijiehe3c7af992017-02-12 20:59:401149 const bool is_fullscreen = window() && window()->IsFullscreen();
1150 const bool show_main_ui = IsShowingMainUI();
1151 const bool main_not_fullscreen = show_main_ui && !is_fullscreen;
[email protected]5d98294912012-06-27 22:57:401152
1153 // Navigation commands
1154 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1155
1156 // Window management commands
1157 command_updater_.UpdateCommandEnabled(
1158 IDC_SHOW_AS_TAB,
zijiehe3c7af992017-02-12 20:59:401159 !browser_->is_type_tabbed() && !is_fullscreen);
[email protected]5d98294912012-06-27 22:57:401160
1161 // Focus various bits of UI
1162 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
1163 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui);
1164 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
1165 command_updater_.UpdateCommandEnabled(
1166 IDC_FOCUS_MENU_BAR, main_not_fullscreen);
1167 command_updater_.UpdateCommandEnabled(
1168 IDC_FOCUS_NEXT_PANE, main_not_fullscreen);
1169 command_updater_.UpdateCommandEnabled(
1170 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen);
1171 command_updater_.UpdateCommandEnabled(
1172 IDC_FOCUS_BOOKMARKS, main_not_fullscreen);
[email protected]822ca8c62013-04-19 00:49:151173 command_updater_.UpdateCommandEnabled(
David Tsengc0b1b642018-01-24 07:12:271174 IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY, main_not_fullscreen);
[email protected]5d98294912012-06-27 22:57:401175
1176 // Show various bits of UI
1177 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431178#if defined(GOOGLE_CHROME_BUILD)
[email protected]5d98294912012-06-27 22:57:401179 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431180#endif
Mihai Sardarescu2ec5205682018-09-26 09:20:051181 UpdateShowSyncState(show_main_ui);
[email protected]5d98294912012-06-27 22:57:401182
[email protected]5d98294912012-06-27 22:57:401183 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
1184 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
1185 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
1186 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
primianod3a81ab2016-01-25 22:21:151187
1188 if (base::debug::IsProfilingSupported())
1189 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
[email protected]5d98294912012-06-27 22:57:401190
[email protected]aeafc3852014-04-29 16:51:291191#if !defined(OS_MACOSX)
zijiehe3c7af992017-02-12 20:59:401192 // Disable toggling into fullscreen mode if disallowed by pref.
1193 const bool fullscreen_enabled = is_fullscreen ||
1194 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed);
1195#else
1196 const bool fullscreen_enabled = true;
[email protected]00a1cc5b2012-11-07 13:44:511197#endif
1198
1199 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled);
spqchanb8ffc7d2015-11-17 01:17:211200 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR,
1201 fullscreen_enabled);
[email protected]5d98294912012-06-27 22:57:401202
1203 UpdateCommandsForBookmarkBar();
zijiehedb473d552017-02-24 01:13:411204 UpdateCommandsForIncognitoAvailability();
Alan Cutter167dfe82018-04-11 09:06:001205 UpdateCommandsForHostedAppAvailability();
1206}
1207
1208void BrowserCommandController::UpdateCommandsForHostedAppAvailability() {
1209 bool has_toolbar =
1210 browser_->is_type_tabbed() ||
1211 extensions::HostedAppBrowserController::IsForExperimentalHostedAppBrowser(
1212 browser_);
1213 if (window() && window()->ShouldHideUIForFullscreen())
1214 has_toolbar = false;
1215 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, has_toolbar);
1216 command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE, has_toolbar);
1217 command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE, has_toolbar);
1218 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, has_toolbar);
[email protected]5d98294912012-06-27 22:57:401219}
1220
Ivan Sandrk9669d0e2017-12-15 23:50:201221#if defined(OS_CHROMEOS)
1222namespace {
1223
1224#if DCHECK_IS_ON()
1225// Makes sure that all commands that are not whitelisted are disabled. DCHECKs
1226// otherwise. Compiled only in debug mode.
1227void NonWhitelistedCommandsAreDisabled(CommandUpdaterImpl* command_updater) {
1228 constexpr int kWhitelistedIds[] = {
1229 IDC_CUT, IDC_COPY, IDC_PASTE,
1230 IDC_FIND, IDC_FIND_NEXT, IDC_FIND_PREVIOUS,
1231 IDC_ZOOM_PLUS, IDC_ZOOM_NORMAL, IDC_ZOOM_MINUS,
1232 };
1233
1234 // Go through all the command ids, skip the whitelisted ones.
1235 for (int id : command_updater->GetAllIds()) {
Haeun Kim3f6123502018-08-26 18:03:041236 if (base::ContainsValue(kWhitelistedIds, id)) {
Ivan Sandrk9669d0e2017-12-15 23:50:201237 continue;
1238 }
1239 DCHECK(!command_updater->IsCommandEnabled(id));
1240 }
1241}
1242#endif
1243
1244} // namespace
1245
1246void BrowserCommandController::UpdateCommandsForLockedFullscreenMode() {
Ivan Sandrk9669d0e2017-12-15 23:50:201247 bool is_locked_fullscreen = ash::IsWindowTrustedPinned(browser_->window());
1248 // Sanity check to make sure this function is called only on state change.
1249 DCHECK_NE(is_locked_fullscreen, is_locked_fullscreen_);
1250 if (is_locked_fullscreen == is_locked_fullscreen_)
1251 return;
1252 is_locked_fullscreen_ = is_locked_fullscreen;
1253
1254 if (is_locked_fullscreen_) {
1255 command_updater_.DisableAllCommands();
1256 // Update the state of whitelisted commands:
1257 // IDC_CUT/IDC_COPY/IDC_PASTE,
1258 UpdateCommandsForContentRestrictionState();
1259 // IDC_FIND/IDC_FIND_NEXT/IDC_FIND_PREVIOUS,
1260 UpdateCommandsForFind();
1261 // IDC_ZOOM_PLUS/IDC_ZOOM_NORMAL/IDC_ZOOM_MINUS.
1262 UpdateCommandsForZoomState();
1263 // All other commands will be disabled (there is an early return in their
1264 // corresponding UpdateCommandsFor* functions).
1265#if DCHECK_IS_ON()
1266 NonWhitelistedCommandsAreDisabled(&command_updater_);
1267#endif
1268 } else {
1269 // Do an init call to re-initialize command state after the
1270 // DisableAllCommands.
1271 InitCommandState();
1272 }
1273}
1274#endif
1275
[email protected]5d98294912012-06-27 22:57:401276void BrowserCommandController::UpdatePrintingState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201277 if (is_locked_fullscreen_)
1278 return;
1279
[email protected]d53e4032012-06-29 18:58:341280 bool print_enabled = CanPrint(browser_);
1281 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
Lei Zhang48a4a5262018-04-17 20:18:441282#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:551283 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT,
1284 CanBasicPrint(browser_));
Lei Zhang48a4a5262018-04-17 20:18:441285#endif
[email protected]5d98294912012-06-27 22:57:401286}
1287
1288void BrowserCommandController::UpdateSaveAsState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201289 if (is_locked_fullscreen_)
1290 return;
1291
[email protected]5d98294912012-06-27 22:57:401292 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_));
1293}
1294
Mihai Sardarescu2ec5205682018-09-26 09:20:051295void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) {
1296 if (is_locked_fullscreen_)
1297 return;
1298
Mihai Sardarescuf87ccc12018-09-26 10:37:451299 command_updater_.UpdateCommandEnabled(
Mihai Sardarescu290bc882018-10-12 10:48:141300 IDC_SHOW_SIGNIN, show_main_ui && pref_signin_allowed_.GetValue());
Mihai Sardarescu2ec5205682018-09-26 09:20:051301}
1302
[email protected]05454532013-01-22 21:09:081303// static
1304void BrowserCommandController::UpdateOpenFileState(
1305 CommandUpdater* command_updater) {
[email protected]5d98294912012-06-27 22:57:401306 bool enabled = true;
1307 PrefService* local_state = g_browser_process->local_state();
1308 if (local_state)
1309 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs);
1310
[email protected]05454532013-01-22 21:09:081311 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled);
[email protected]5d98294912012-06-27 22:57:401312}
1313
1314void BrowserCommandController::UpdateReloadStopState(bool is_loading,
1315 bool force) {
Ivan Sandrk9669d0e2017-12-15 23:50:201316 if (is_locked_fullscreen_)
1317 return;
1318
[email protected]5d98294912012-06-27 22:57:401319 window()->UpdateReloadStopState(is_loading, force);
1320 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
1321}
1322
[email protected]2e9369e2014-08-15 09:12:531323void BrowserCommandController::UpdateTabRestoreCommandState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201324 if (is_locked_fullscreen_)
1325 return;
1326
blundell74001adc2015-09-18 11:04:251327 sessions::TabRestoreService* tab_restore_service =
[email protected]2e9369e2014-08-15 09:12:531328 TabRestoreServiceFactory::GetForProfile(profile());
1329 // The command is enabled if the service hasn't loaded yet to trigger loading.
1330 // The command is updated once the load completes.
1331 command_updater_.UpdateCommandEnabled(
1332 IDC_RESTORE_TAB,
1333 tab_restore_service &&
1334 (!tab_restore_service->IsLoaded() ||
1335 GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE));
1336}
1337
[email protected]3cac87232012-11-20 01:48:271338void BrowserCommandController::UpdateCommandsForFind() {
1339 TabStripModel* model = browser_->tab_strip_model();
1340 bool enabled = !model->IsTabBlocked(model->active_index()) &&
1341 !browser_->is_devtools();
1342
1343 command_updater_.UpdateCommandEnabled(IDC_FIND, enabled);
1344 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled);
1345 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled);
1346}
1347
apacible45cbfc92015-09-28 22:45:411348void BrowserCommandController::UpdateCommandsForMediaRouter() {
Ivan Sandrk9669d0e2017-12-15 23:50:201349 if (is_locked_fullscreen_)
1350 return;
1351
apacible45cbfc92015-09-28 22:45:411352 command_updater_.UpdateCommandEnabled(IDC_ROUTE_MEDIA,
1353 CanRouteMedia(browser_));
1354}
1355
[email protected]409ea2972012-11-10 19:54:431356void BrowserCommandController::AddInterstitialObservers(WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071357 interstitial_observers_.push_back(new InterstitialObserver(this, contents));
[email protected]5d98294912012-06-27 22:57:401358}
1359
1360void BrowserCommandController::RemoveInterstitialObservers(
[email protected]e89cfcb2012-11-11 14:47:241361 WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071362 for (size_t i = 0; i < interstitial_observers_.size(); i++) {
1363 if (interstitial_observers_[i]->web_contents() != contents)
1364 continue;
1365
1366 delete interstitial_observers_[i];
1367 interstitial_observers_.erase(interstitial_observers_.begin() + i);
1368 return;
1369 }
[email protected]5d98294912012-06-27 22:57:401370}
1371
1372BrowserWindow* BrowserCommandController::window() {
1373 return browser_->window();
1374}
1375
1376Profile* BrowserCommandController::profile() {
1377 return browser_->profile();
1378}
1379
[email protected]5d98294912012-06-27 22:57:401380} // namespace chrome