blob: cb6812dcef5b57d2c5eff818b05d7d5dce708652 [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:
Orin Jaworski5e4bcd0c2018-10-16 19:35:05345 NewIncognitoWindow(profile());
[email protected]5d98294912012-06-27 22:57:40346 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
sangwoo.ko1ae265f12018-10-18 08:30:28742void BrowserCommandController::OnTabStripModelChanged(
743 TabStripModel* tab_strip_model,
744 const TabStripModelChange& change,
745 const TabStripSelectionChange& selection) {
746 if (change.type() != TabStripModelChange::kInserted &&
747 change.type() != TabStripModelChange::kReplaced &&
748 change.type() != TabStripModelChange::kRemoved)
749 return;
[email protected]5d98294912012-06-27 22:57:40750
sangwoo.ko1ae265f12018-10-18 08:30:28751 for (const auto& delta : change.deltas()) {
752 content::WebContents* new_contents = nullptr;
753 content::WebContents* old_contents = nullptr;
754 if (change.type() == TabStripModelChange::kInserted) {
755 new_contents = delta.insert.contents;
756 } else if (change.type() == TabStripModelChange::kReplaced) {
757 new_contents = delta.replace.new_contents;
758 old_contents = delta.replace.old_contents;
759 } else {
760 old_contents = delta.remove.contents;
761 }
[email protected]5d98294912012-06-27 22:57:40762
sangwoo.ko1ae265f12018-10-18 08:30:28763 if (old_contents)
764 RemoveInterstitialObservers(old_contents);
765 if (new_contents)
766 AddInterstitialObservers(new_contents);
767 }
[email protected]5d98294912012-06-27 22:57:40768}
769
[email protected]3cac87232012-11-20 01:48:27770void BrowserCommandController::TabBlockedStateChanged(
771 content::WebContents* contents,
772 int index) {
773 PrintingStateChanged();
774 FullscreenStateChanged();
775 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:41776 UpdateCommandsForMediaRouter();
[email protected]3cac87232012-11-20 01:48:27777}
778
[email protected]5d98294912012-06-27 22:57:40779////////////////////////////////////////////////////////////////////////////////
780// BrowserCommandController, TabRestoreServiceObserver implementation:
781
782void BrowserCommandController::TabRestoreServiceChanged(
blundell74001adc2015-09-18 11:04:25783 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53784 UpdateTabRestoreCommandState();
[email protected]5d98294912012-06-27 22:57:40785}
786
787void BrowserCommandController::TabRestoreServiceDestroyed(
blundell74001adc2015-09-18 11:04:25788 sessions::TabRestoreService* service) {
[email protected]5d98294912012-06-27 22:57:40789 service->RemoveObserver(this);
790}
791
[email protected]2e9369e2014-08-15 09:12:53792void BrowserCommandController::TabRestoreServiceLoaded(
blundell74001adc2015-09-18 11:04:25793 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53794 UpdateTabRestoreCommandState();
795}
796
[email protected]5d98294912012-06-27 22:57:40797////////////////////////////////////////////////////////////////////////////////
[email protected]5d98294912012-06-27 22:57:40798// BrowserCommandController, private:
799
[email protected]20ca0382013-02-28 19:50:07800class BrowserCommandController::InterstitialObserver
801 : public content::WebContentsObserver {
802 public:
803 InterstitialObserver(BrowserCommandController* controller,
804 content::WebContents* web_contents)
805 : WebContentsObserver(web_contents),
806 controller_(controller) {
807 }
808
dcheng5dd5ff62014-10-21 12:42:38809 void DidAttachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07810 controller_->UpdateCommandsForTabState();
811 }
812
dcheng5dd5ff62014-10-21 12:42:38813 void DidDetachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07814 controller_->UpdateCommandsForTabState();
815 }
816
817 private:
818 BrowserCommandController* controller_;
819
820 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver);
821};
822
[email protected]6a414ff2013-02-27 08:22:54823bool BrowserCommandController::IsShowingMainUI() {
manukf1a116392018-10-25 16:28:24824 return browser_->SupportsWindowFeature(Browser::FEATURE_TABSTRIP);
825}
826
827bool BrowserCommandController::IsShowingLocationBar() {
828 return browser_->SupportsWindowFeature(Browser::FEATURE_LOCATIONBAR);
[email protected]5d98294912012-06-27 22:57:40829}
830
831void BrowserCommandController::InitCommandState() {
832 // All browser commands whose state isn't set automagically some other way
833 // (like Back & Forward with initial page load) must have their state
834 // initialized here, otherwise they will be forever disabled.
835
Ivan Sandrk9669d0e2017-12-15 23:50:20836 if (is_locked_fullscreen_)
837 return;
838
[email protected]5d98294912012-06-27 22:57:40839 // Navigation commands
840 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true);
toyoshim7dad4b1182016-04-01 14:28:05841 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE, true);
[email protected]58e29032012-08-06 20:19:57842 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, true);
[email protected]5d98294912012-06-27 22:57:40843
844 // Window management commands
845 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true);
846 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true);
847 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true);
848 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true);
[email protected]2e9369e2014-08-15 09:12:53849 UpdateTabRestoreCommandState();
[email protected]d28d3782013-02-26 16:31:55850 command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
[email protected]5d98294912012-06-27 22:57:40851 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true);
[email protected]d12cc5e2013-10-19 18:25:06852#if defined(OS_CHROMEOS)
James Cook934abaf2017-09-19 22:21:58853 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
[email protected]d12cc5e2013-10-19 18:25:06854 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_2, true);
855 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_3, true);
856#endif
[email protected]893124a22014-04-15 00:45:28857#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15858 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
859 command_updater_.UpdateCommandEnabled(IDC_MAXIMIZE_WINDOW, true);
860 command_updater_.UpdateCommandEnabled(IDC_RESTORE_WINDOW, true);
Maksim Sisovac767592018-08-10 08:00:15861 bool use_system_title_bar = true;
862#if defined(USE_OZONE)
863 use_system_title_bar = ui::OzonePlatform::GetInstance()
864 ->GetPlatformProperties()
865 .use_system_title_bar;
866#endif
867 command_updater_.UpdateCommandEnabled(IDC_USE_SYSTEM_TITLE_BAR,
868 use_system_title_bar);
[email protected]af97be4c62014-02-13 14:43:34869#endif
Alan Cutter09965802018-03-27 07:25:29870 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW, true);
[email protected]5d98294912012-06-27 22:57:40871
872 // Page-related commands
873 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true);
[email protected]4bee4432014-05-05 13:11:41874 command_updater_.UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE, true);
[email protected]5d98294912012-06-27 22:57:40875
876 // Zoom
877 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true);
878 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true);
[email protected]d93dbd12014-08-04 23:42:53879 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, false);
[email protected]5d98294912012-06-27 22:57:40880 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
881
882 // Show various bits of UI
mlerman7831f57d2015-05-25 11:40:15883 const bool guest_session = profile()->IsGuestSession() ||
884 profile()->IsSystemProfile();
885 DCHECK(!profile()->IsSystemProfile())
886 << "Ought to never have browser for the system profile.";
[email protected]338416c02014-05-13 16:47:06887 const bool normal_window = browser_->is_type_tabbed();
[email protected]05454532013-01-22 21:09:08888 UpdateOpenFileState(&command_updater_);
[email protected]5d98294912012-06-27 22:57:40889 UpdateCommandsForDevTools();
890 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager());
[email protected]338416c02014-05-13 16:47:06891 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session);
[email protected]5d98294912012-06-27 22:57:40892 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
[email protected]674b65672014-06-02 23:21:56893 command_updater_.UpdateCommandEnabled(IDC_HELP_MENU, true);
[email protected]5d98294912012-06-27 22:57:40894 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
895 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
Bret Sepulveda2d018662017-05-18 21:31:48896 command_updater_.UpdateCommandEnabled(IDC_SHOW_BETA_FORUM, true);
[email protected]338416c02014-05-13 16:47:06897 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session);
[email protected]2f1acc212012-11-13 10:43:51898 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU,
[email protected]338416c02014-05-13 16:47:06899 !guest_session &&
[email protected]2f1acc212012-11-13 10:43:51900 !profile()->IsOffTheRecord());
tsergeant341a8272017-04-18 03:54:33901 command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA,
902 !guest_session);
[email protected]39d47592014-01-10 21:42:45903#if defined(OS_CHROMEOS)
caelyn4e4e08a2015-02-04 21:27:49904 command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true);
[email protected]338416c02014-05-13 16:47:06905#else
906 // Chrome OS uses the system tray menu to handle multi-profiles.
anthonyvd7dc985da2015-03-23 16:53:19907 if (normal_window && (guest_session || !profile()->IsOffTheRecord())) {
[email protected]338416c02014-05-13 16:47:06908 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
anthonyvd7dc985da2015-03-23 16:53:19909 }
[email protected]39d47592014-01-10 21:42:45910#endif
[email protected]5d98294912012-06-27 22:57:40911
Mihai Sardarescu2ec5205682018-09-26 09:20:05912 UpdateShowSyncState(true);
913
[email protected]5d98294912012-06-27 22:57:40914 // Navigation commands
[email protected]c9f983d2014-02-05 09:00:24915 command_updater_.UpdateCommandEnabled(
916 IDC_HOME,
benwellsc431c0ae2015-01-27 22:04:06917 normal_window ||
918 (extensions::util::IsNewBookmarkAppsEnabled() && browser_->is_app()));
[email protected]5d98294912012-06-27 22:57:40919
Christopher Lam0dbac2b2017-11-14 07:12:10920 const bool is_experimental_hosted_app =
921 extensions::HostedAppBrowserController::IsForExperimentalHostedAppBrowser(
922 browser_);
923 // Hosted app browser commands.
924 command_updater_.UpdateCommandEnabled(IDC_COPY_URL,
925 is_experimental_hosted_app);
926 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_CHROME,
927 is_experimental_hosted_app);
928 command_updater_.UpdateCommandEnabled(IDC_SITE_SETTINGS,
929 is_experimental_hosted_app);
Alan Cutter0c3132302018-02-21 05:09:02930 command_updater_.UpdateCommandEnabled(IDC_HOSTED_APP_MENU_APP_INFO,
Christopher Lam86b52712017-12-04 01:58:33931 is_experimental_hosted_app);
Christopher Lam0dbac2b2017-11-14 07:12:10932
[email protected]5d98294912012-06-27 22:57:40933 // Window management commands
[email protected]5d98294912012-06-27 22:57:40934 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window);
935 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB,
936 normal_window);
937 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window);
938 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window);
939 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window);
940 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window);
941 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window);
942 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window);
943 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window);
944 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window);
945 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window);
946 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window);
947 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window);
[email protected]5d98294912012-06-27 22:57:40948
[email protected]338416c02014-05-13 16:47:06949 // These are always enabled; the menu determines their menu item visibility.
[email protected]5d98294912012-06-27 22:57:40950 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
[email protected]5d98294912012-06-27 22:57:40951
[email protected]6bd370b2014-05-28 14:19:47952 // Distill current page.
953 command_updater_.UpdateCommandEnabled(
avi556c05022014-12-22 23:31:43954 IDC_DISTILL_PAGE, base::CommandLine::ForCurrentProcess()->HasSwitch(
955 switches::kEnableDomDistiller));
[email protected]6bd370b2014-05-28 14:19:47956
Tommy Steimelc4477982017-11-29 18:07:18957 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE, normal_window);
ellyjones0101ba02017-05-19 15:50:26958 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, normal_window);
959
[email protected]338416c02014-05-13 16:47:06960 // Initialize other commands whose state changes based on various conditions.
[email protected]32dfede2013-08-25 15:48:25961 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40962 UpdateCommandsForContentRestrictionState();
[email protected]5d98294912012-06-27 22:57:40963 UpdateCommandsForBookmarkEditing();
[email protected]5d98294912012-06-27 22:57:40964 UpdateCommandsForIncognitoAvailability();
965}
966
[email protected]05454532013-01-22 21:09:08967// static
968void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
969 CommandUpdater* command_updater,
970 Profile* profile) {
mlermane01e6de2014-09-29 19:26:47971 const bool guest_session = profile->IsGuestSession();
972 // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession().
[email protected]5d98294912012-06-27 22:57:40973 IncognitoModePrefs::Availability incognito_availability =
[email protected]05454532013-01-22 21:09:08974 IncognitoModePrefs::GetAvailability(profile->GetPrefs());
975 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40976 IDC_NEW_WINDOW,
977 incognito_availability != IncognitoModePrefs::FORCED);
[email protected]05454532013-01-22 21:09:08978 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40979 IDC_NEW_INCOGNITO_WINDOW,
mlermane01e6de2014-09-29 19:26:47980 incognito_availability != IncognitoModePrefs::DISABLED && !guest_session);
[email protected]5d98294912012-06-27 22:57:40981
[email protected]57b25292014-05-01 16:31:06982 const bool forced_incognito =
983 incognito_availability == IncognitoModePrefs::FORCED ||
984 guest_session; // Guest always runs in Incognito mode.
[email protected]05454532013-01-22 21:09:08985 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40986 IDC_SHOW_BOOKMARK_MANAGER,
[email protected]57b25292014-05-01 16:31:06987 browser_defaults::bookmarks_enabled && !forced_incognito);
Devlin Cronin21dba422018-05-30 15:45:16988 extensions::ExtensionService* extension_service =
[email protected]03d25812014-06-22 19:41:55989 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]57b25292014-05-01 16:31:06990 const bool enable_extensions =
[email protected]5d98294912012-06-27 22:57:40991 extension_service && extension_service->extensions_enabled();
[email protected]5d98294912012-06-27 22:57:40992
[email protected]57b25292014-05-01 16:31:06993 // Bookmark manager and settings page/subpages are forced to open in normal
994 // mode. For this reason we disable these commands when incognito is forced.
995 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
996 enable_extensions && !forced_incognito);
997
998 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito);
999 command_updater->UpdateCommandEnabled(IDC_OPTIONS,
1000 !forced_incognito || guest_session);
estade8c0780f2015-08-21 23:36:411001 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito);
[email protected]05454532013-01-22 21:09:081002}
1003
1004void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
Ivan Sandrk9669d0e2017-12-15 23:50:201005 if (is_locked_fullscreen_)
1006 return;
1007
[email protected]05454532013-01-22 21:09:081008 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile());
1009
[email protected]6a414ff2013-02-27 08:22:541010 if (!IsShowingMainUI()) {
[email protected]05454532013-01-22 21:09:081011 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false);
1012 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false);
1013 }
[email protected]5d98294912012-06-27 22:57:401014}
1015
1016void BrowserCommandController::UpdateCommandsForTabState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201017 if (is_locked_fullscreen_)
1018 return;
1019
[email protected]617ee962013-01-29 20:49:121020 WebContents* current_web_contents =
1021 browser_->tab_strip_model()->GetActiveWebContents();
[email protected]1c5119c2012-09-19 00:08:571022 if (!current_web_contents) // May be NULL during tab restore.
[email protected]5d98294912012-06-27 22:57:401023 return;
[email protected]5d98294912012-06-27 22:57:401024
1025 // Navigation commands
[email protected]5d98294912012-06-27 22:57:401026 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_));
[email protected]5d98294912012-06-27 22:57:401027 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_));
1028 command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_));
toyoshim7dad4b1182016-04-01 14:28:051029 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE,
[email protected]5d98294912012-06-27 22:57:401030 CanReload(browser_));
[email protected]58e29032012-08-06 20:19:571031 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE,
1032 CanReload(browser_));
[email protected]5d98294912012-06-27 22:57:401033
1034 // Window management commands
1035 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB,
1036 !browser_->is_app() && CanDuplicateTab(browser_));
Tommy Steimelc4477982017-11-29 18:07:181037 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE,
ellyjones0101ba02017-05-19 15:50:261038 !browser_->is_app());
1039 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB,
1040 !browser_->is_app());
[email protected]5d98294912012-06-27 22:57:401041
1042 // Page-related commands
1043 window()->SetStarredState(
[email protected]1c5119c2012-09-19 00:08:571044 BookmarkTabHelper::FromWebContents(current_web_contents)->is_starred());
[email protected]5423c372012-08-22 05:50:161045 window()->ZoomChangedForActiveTab(false);
[email protected]5d98294912012-06-27 22:57:401046 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
1047 CanViewSource(browser_));
1048 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION,
1049 CanEmailPageLocation(browser_));
1050 if (browser_->is_devtools())
1051 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false);
1052
Alan Cutter81ac726682018-09-25 00:18:361053 bool can_create_bookmark_app = CanCreateBookmarkApp(browser_);
1054 command_updater_.UpdateCommandEnabled(IDC_INSTALL_PWA,
1055 can_create_bookmark_app);
1056 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUT,
1057 can_create_bookmark_app);
Alan Cutter403cebb2018-05-17 05:22:451058 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW,
Alan Cutter81ac726682018-09-25 00:18:361059 can_create_bookmark_app);
[email protected]5d98294912012-06-27 22:57:401060
[email protected]9b7ab882012-09-10 23:46:361061 command_updater_.UpdateCommandEnabled(
1062 IDC_TOGGLE_REQUEST_TABLET_SITE,
1063 CanRequestTabletSite(current_web_contents));
1064
[email protected]5d98294912012-06-27 22:57:401065 UpdateCommandsForContentRestrictionState();
1066 UpdateCommandsForBookmarkEditing();
[email protected]3cac87232012-11-20 01:48:271067 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:411068 UpdateCommandsForMediaRouter();
[email protected]d93dbd12014-08-04 23:42:531069 // Update the zoom commands when an active tab is selected.
1070 UpdateCommandsForZoomState();
1071}
1072
1073void BrowserCommandController::UpdateCommandsForZoomState() {
1074 WebContents* contents =
1075 browser_->tab_strip_model()->GetActiveWebContents();
1076 if (!contents)
1077 return;
a.sarkar.arundaadc712015-02-26 05:39:081078 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS,
1079 CanZoomIn(contents));
1080 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL,
ccameronb7c1d6c2015-03-09 17:08:241081 CanResetZoom(contents));
a.sarkar.arundaadc712015-02-26 05:39:081082 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS,
1083 CanZoomOut(contents));
[email protected]5d98294912012-06-27 22:57:401084}
1085
1086void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
1087 int restrictions = GetContentRestrictions(browser_);
1088
1089 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011090 IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY));
[email protected]5d98294912012-06-27 22:57:401091 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011092 IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT));
[email protected]5d98294912012-06-27 22:57:401093 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011094 IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE));
[email protected]5d98294912012-06-27 22:57:401095 UpdateSaveAsState();
1096 UpdatePrintingState();
1097}
1098
1099void BrowserCommandController::UpdateCommandsForDevTools() {
Ivan Sandrk9669d0e2017-12-15 23:50:201100 if (is_locked_fullscreen_)
1101 return;
1102
Pavol Marko56df0272018-07-04 17:55:041103 bool dev_tools_enabled = DevToolsWindow::AllowDevToolsFor(
1104 profile(), browser_->tab_strip_model()->GetActiveWebContents());
[email protected]5d98294912012-06-27 22:57:401105 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS,
1106 dev_tools_enabled);
1107 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE,
1108 dev_tools_enabled);
[email protected]2056c3192013-10-21 22:40:511109 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES,
1110 dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401111 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT,
1112 dev_tools_enabled);
[email protected]d16657c2012-09-03 14:25:101113 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE,
1114 dev_tools_enabled);
spqchan2c5d541e2017-10-25 07:07:111115#if defined(OS_MACOSX)
1116 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS,
1117 dev_tools_enabled);
1118#endif
[email protected]5d98294912012-06-27 22:57:401119}
1120
1121void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
Ivan Sandrk9669d0e2017-12-15 23:50:201122 if (is_locked_fullscreen_)
1123 return;
1124
[email protected]5d98294912012-06-27 22:57:401125 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE,
1126 CanBookmarkCurrentPage(browser_));
1127 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
1128 CanBookmarkAllTabs(browser_));
thestig5149d272014-10-30 07:25:291129#if defined(OS_WIN)
1130 command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN, true);
1131#endif
[email protected]5d98294912012-06-27 22:57:401132}
1133
1134void BrowserCommandController::UpdateCommandsForBookmarkBar() {
Ivan Sandrk9669d0e2017-12-15 23:50:201135 if (is_locked_fullscreen_)
1136 return;
1137
tfarina3bddbe112014-08-28 05:29:321138 command_updater_.UpdateCommandEnabled(
1139 IDC_SHOW_BOOKMARK_BAR,
1140 browser_defaults::bookmarks_enabled && !profile()->IsGuestSession() &&
mlerman7831f57d2015-05-25 11:40:151141 !profile()->IsSystemProfile() &&
tfarina3bddbe112014-08-28 05:29:321142 !profile()->GetPrefs()->IsManagedPreference(
1143 bookmarks::prefs::kShowBookmarkBar) &&
1144 IsShowingMainUI());
[email protected]5d98294912012-06-27 22:57:401145}
1146
[email protected]9ec3ea5b2012-12-03 18:14:301147void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
Ivan Sandrk9669d0e2017-12-15 23:50:201148 if (is_locked_fullscreen_)
1149 return;
1150
[email protected]9ec3ea5b2012-12-03 18:14:301151 UpdateSaveAsState();
[email protected]05454532013-01-22 21:09:081152 UpdateOpenFileState(&command_updater_);
[email protected]9ec3ea5b2012-12-03 18:14:301153}
1154
[email protected]32dfede2013-08-25 15:48:251155void BrowserCommandController::UpdateCommandsForFullscreenMode() {
Ivan Sandrk9669d0e2017-12-15 23:50:201156 if (is_locked_fullscreen_)
1157 return;
1158
zijiehe3c7af992017-02-12 20:59:401159 const bool is_fullscreen = window() && window()->IsFullscreen();
1160 const bool show_main_ui = IsShowingMainUI();
manukf1a116392018-10-25 16:28:241161 const bool show_location_bar = IsShowingLocationBar();
1162
zijiehe3c7af992017-02-12 20:59:401163 const bool main_not_fullscreen = show_main_ui && !is_fullscreen;
[email protected]5d98294912012-06-27 22:57:401164
1165 // Navigation commands
1166 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1167
1168 // Window management commands
1169 command_updater_.UpdateCommandEnabled(
1170 IDC_SHOW_AS_TAB,
zijiehe3c7af992017-02-12 20:59:401171 !browser_->is_type_tabbed() && !is_fullscreen);
[email protected]5d98294912012-06-27 22:57:401172
1173 // Focus various bits of UI
1174 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
manukf1a116392018-10-25 16:28:241175 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_location_bar);
[email protected]5d98294912012-06-27 22:57:401176 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
1177 command_updater_.UpdateCommandEnabled(
1178 IDC_FOCUS_MENU_BAR, main_not_fullscreen);
1179 command_updater_.UpdateCommandEnabled(
1180 IDC_FOCUS_NEXT_PANE, main_not_fullscreen);
1181 command_updater_.UpdateCommandEnabled(
1182 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen);
1183 command_updater_.UpdateCommandEnabled(
1184 IDC_FOCUS_BOOKMARKS, main_not_fullscreen);
[email protected]822ca8c62013-04-19 00:49:151185 command_updater_.UpdateCommandEnabled(
David Tsengc0b1b642018-01-24 07:12:271186 IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY, main_not_fullscreen);
[email protected]5d98294912012-06-27 22:57:401187
1188 // Show various bits of UI
1189 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431190#if defined(GOOGLE_CHROME_BUILD)
[email protected]5d98294912012-06-27 22:57:401191 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431192#endif
Mihai Sardarescu2ec5205682018-09-26 09:20:051193 UpdateShowSyncState(show_main_ui);
[email protected]5d98294912012-06-27 22:57:401194
[email protected]5d98294912012-06-27 22:57:401195 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
1196 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
1197 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
1198 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
primianod3a81ab2016-01-25 22:21:151199
1200 if (base::debug::IsProfilingSupported())
1201 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
[email protected]5d98294912012-06-27 22:57:401202
[email protected]aeafc3852014-04-29 16:51:291203#if !defined(OS_MACOSX)
zijiehe3c7af992017-02-12 20:59:401204 // Disable toggling into fullscreen mode if disallowed by pref.
1205 const bool fullscreen_enabled = is_fullscreen ||
1206 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed);
1207#else
1208 const bool fullscreen_enabled = true;
[email protected]00a1cc5b2012-11-07 13:44:511209#endif
1210
1211 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled);
spqchanb8ffc7d2015-11-17 01:17:211212 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR,
1213 fullscreen_enabled);
[email protected]5d98294912012-06-27 22:57:401214
1215 UpdateCommandsForBookmarkBar();
zijiehedb473d552017-02-24 01:13:411216 UpdateCommandsForIncognitoAvailability();
Alan Cutter167dfe82018-04-11 09:06:001217 UpdateCommandsForHostedAppAvailability();
1218}
1219
1220void BrowserCommandController::UpdateCommandsForHostedAppAvailability() {
1221 bool has_toolbar =
1222 browser_->is_type_tabbed() ||
1223 extensions::HostedAppBrowserController::IsForExperimentalHostedAppBrowser(
1224 browser_);
1225 if (window() && window()->ShouldHideUIForFullscreen())
1226 has_toolbar = false;
1227 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, has_toolbar);
1228 command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE, has_toolbar);
1229 command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE, has_toolbar);
1230 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, has_toolbar);
[email protected]5d98294912012-06-27 22:57:401231}
1232
Ivan Sandrk9669d0e2017-12-15 23:50:201233#if defined(OS_CHROMEOS)
1234namespace {
1235
1236#if DCHECK_IS_ON()
1237// Makes sure that all commands that are not whitelisted are disabled. DCHECKs
1238// otherwise. Compiled only in debug mode.
1239void NonWhitelistedCommandsAreDisabled(CommandUpdaterImpl* command_updater) {
1240 constexpr int kWhitelistedIds[] = {
1241 IDC_CUT, IDC_COPY, IDC_PASTE,
1242 IDC_FIND, IDC_FIND_NEXT, IDC_FIND_PREVIOUS,
1243 IDC_ZOOM_PLUS, IDC_ZOOM_NORMAL, IDC_ZOOM_MINUS,
1244 };
1245
1246 // Go through all the command ids, skip the whitelisted ones.
1247 for (int id : command_updater->GetAllIds()) {
Haeun Kim3f6123502018-08-26 18:03:041248 if (base::ContainsValue(kWhitelistedIds, id)) {
Ivan Sandrk9669d0e2017-12-15 23:50:201249 continue;
1250 }
1251 DCHECK(!command_updater->IsCommandEnabled(id));
1252 }
1253}
1254#endif
1255
1256} // namespace
1257
1258void BrowserCommandController::UpdateCommandsForLockedFullscreenMode() {
Ivan Sandrk9669d0e2017-12-15 23:50:201259 bool is_locked_fullscreen = ash::IsWindowTrustedPinned(browser_->window());
1260 // Sanity check to make sure this function is called only on state change.
1261 DCHECK_NE(is_locked_fullscreen, is_locked_fullscreen_);
1262 if (is_locked_fullscreen == is_locked_fullscreen_)
1263 return;
1264 is_locked_fullscreen_ = is_locked_fullscreen;
1265
1266 if (is_locked_fullscreen_) {
1267 command_updater_.DisableAllCommands();
1268 // Update the state of whitelisted commands:
1269 // IDC_CUT/IDC_COPY/IDC_PASTE,
1270 UpdateCommandsForContentRestrictionState();
1271 // IDC_FIND/IDC_FIND_NEXT/IDC_FIND_PREVIOUS,
1272 UpdateCommandsForFind();
1273 // IDC_ZOOM_PLUS/IDC_ZOOM_NORMAL/IDC_ZOOM_MINUS.
1274 UpdateCommandsForZoomState();
1275 // All other commands will be disabled (there is an early return in their
1276 // corresponding UpdateCommandsFor* functions).
1277#if DCHECK_IS_ON()
1278 NonWhitelistedCommandsAreDisabled(&command_updater_);
1279#endif
1280 } else {
1281 // Do an init call to re-initialize command state after the
1282 // DisableAllCommands.
1283 InitCommandState();
1284 }
1285}
1286#endif
1287
[email protected]5d98294912012-06-27 22:57:401288void BrowserCommandController::UpdatePrintingState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201289 if (is_locked_fullscreen_)
1290 return;
1291
[email protected]d53e4032012-06-29 18:58:341292 bool print_enabled = CanPrint(browser_);
1293 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
Lei Zhang48a4a5262018-04-17 20:18:441294#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:551295 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT,
1296 CanBasicPrint(browser_));
Lei Zhang48a4a5262018-04-17 20:18:441297#endif
[email protected]5d98294912012-06-27 22:57:401298}
1299
1300void BrowserCommandController::UpdateSaveAsState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201301 if (is_locked_fullscreen_)
1302 return;
1303
[email protected]5d98294912012-06-27 22:57:401304 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_));
1305}
1306
Mihai Sardarescu2ec5205682018-09-26 09:20:051307void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) {
1308 if (is_locked_fullscreen_)
1309 return;
1310
Mihai Sardarescuf87ccc12018-09-26 10:37:451311 command_updater_.UpdateCommandEnabled(
Mihai Sardarescu290bc882018-10-12 10:48:141312 IDC_SHOW_SIGNIN, show_main_ui && pref_signin_allowed_.GetValue());
Mihai Sardarescu2ec5205682018-09-26 09:20:051313}
1314
[email protected]05454532013-01-22 21:09:081315// static
1316void BrowserCommandController::UpdateOpenFileState(
1317 CommandUpdater* command_updater) {
[email protected]5d98294912012-06-27 22:57:401318 bool enabled = true;
1319 PrefService* local_state = g_browser_process->local_state();
1320 if (local_state)
1321 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs);
1322
[email protected]05454532013-01-22 21:09:081323 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled);
[email protected]5d98294912012-06-27 22:57:401324}
1325
1326void BrowserCommandController::UpdateReloadStopState(bool is_loading,
1327 bool force) {
Ivan Sandrk9669d0e2017-12-15 23:50:201328 if (is_locked_fullscreen_)
1329 return;
1330
[email protected]5d98294912012-06-27 22:57:401331 window()->UpdateReloadStopState(is_loading, force);
1332 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
1333}
1334
[email protected]2e9369e2014-08-15 09:12:531335void BrowserCommandController::UpdateTabRestoreCommandState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201336 if (is_locked_fullscreen_)
1337 return;
1338
blundell74001adc2015-09-18 11:04:251339 sessions::TabRestoreService* tab_restore_service =
[email protected]2e9369e2014-08-15 09:12:531340 TabRestoreServiceFactory::GetForProfile(profile());
1341 // The command is enabled if the service hasn't loaded yet to trigger loading.
1342 // The command is updated once the load completes.
1343 command_updater_.UpdateCommandEnabled(
1344 IDC_RESTORE_TAB,
1345 tab_restore_service &&
1346 (!tab_restore_service->IsLoaded() ||
1347 GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE));
1348}
1349
[email protected]3cac87232012-11-20 01:48:271350void BrowserCommandController::UpdateCommandsForFind() {
1351 TabStripModel* model = browser_->tab_strip_model();
1352 bool enabled = !model->IsTabBlocked(model->active_index()) &&
1353 !browser_->is_devtools();
1354
1355 command_updater_.UpdateCommandEnabled(IDC_FIND, enabled);
1356 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled);
1357 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled);
1358}
1359
apacible45cbfc92015-09-28 22:45:411360void BrowserCommandController::UpdateCommandsForMediaRouter() {
Ivan Sandrk9669d0e2017-12-15 23:50:201361 if (is_locked_fullscreen_)
1362 return;
1363
apacible45cbfc92015-09-28 22:45:411364 command_updater_.UpdateCommandEnabled(IDC_ROUTE_MEDIA,
1365 CanRouteMedia(browser_));
1366}
1367
[email protected]409ea2972012-11-10 19:54:431368void BrowserCommandController::AddInterstitialObservers(WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071369 interstitial_observers_.push_back(new InterstitialObserver(this, contents));
[email protected]5d98294912012-06-27 22:57:401370}
1371
1372void BrowserCommandController::RemoveInterstitialObservers(
[email protected]e89cfcb2012-11-11 14:47:241373 WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071374 for (size_t i = 0; i < interstitial_observers_.size(); i++) {
1375 if (interstitial_observers_[i]->web_contents() != contents)
1376 continue;
1377
1378 delete interstitial_observers_[i];
1379 interstitial_observers_.erase(interstitial_observers_.begin() + i);
1380 return;
1381 }
[email protected]5d98294912012-06-27 22:57:401382}
1383
1384BrowserWindow* BrowserCommandController::window() {
1385 return browser_->window();
1386}
1387
1388Profile* BrowserCommandController::profile() {
1389 return browser_->profile();
1390}
1391
[email protected]5d98294912012-06-27 22:57:401392} // namespace chrome