blob: c1cd97d6868bc436ddeb8eca17d063d6d18a62de [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"
avi655876a2015-12-25 07:18:1516#include "build/build_config.h"
[email protected]5d98294912012-06-27 22:57:4017#include "chrome/app/chrome_command_ids.h"
18#include "chrome/browser/browser_process.h"
[email protected]dcc8fbc2013-07-12 00:54:0919#include "chrome/browser/chrome_notification_types.h"
[email protected]5d98294912012-06-27 22:57:4020#include "chrome/browser/defaults.h"
Pavol Marko56df0272018-07-04 17:55:0421#include "chrome/browser/devtools/devtools_window.h"
[email protected]5d98294912012-06-27 22:57:4022#include "chrome/browser/extensions/extension_service.h"
benwells39f23ae2014-08-27 08:01:5223#include "chrome/browser/extensions/extension_util.h"
[email protected]2e9d79f2013-08-16 05:45:5624#include "chrome/browser/lifetime/application_lifetime.h"
[email protected]5d98294912012-06-27 22:57:4025#include "chrome/browser/prefs/incognito_mode_prefs.h"
[email protected]5d98294912012-06-27 22:57:4026#include "chrome/browser/profiles/profile.h"
mlermane01e6de2014-09-29 19:26:4727#include "chrome/browser/profiles/profile_manager.h"
[email protected]5d98294912012-06-27 22:57:4028#include "chrome/browser/sessions/tab_restore_service_factory.h"
[email protected]0b32f9b62012-09-17 19:08:0329#include "chrome/browser/shell_integration.h"
[email protected]3d27d272013-07-31 03:15:1630#include "chrome/browser/signin/signin_promo.h"
[email protected]5d98294912012-06-27 22:57:4031#include "chrome/browser/sync/profile_sync_service_factory.h"
Christopher Lam86b52712017-12-04 01:58:3332#include "chrome/browser/ui/apps/app_info_dialog.h"
[email protected]5d98294912012-06-27 22:57:4033#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
34#include "chrome/browser/ui/browser.h"
35#include "chrome/browser/ui/browser_commands.h"
36#include "chrome/browser/ui/browser_window.h"
37#include "chrome/browser/ui/chrome_pages.h"
Alan Cutter09965802018-03-27 07:25:2938#include "chrome/browser/ui/extensions/application_launch.h"
Christopher Lam0dbac2b2017-11-14 07:12:1039#include "chrome/browser/ui/extensions/hosted_app_browser_controller.h"
Alan Cutter0c3132302018-02-21 05:09:0240#include "chrome/browser/ui/page_info/page_info_dialog.h"
[email protected]5d98294912012-06-27 22:57:4041#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]2056c3192013-10-21 22:40:5142#include "chrome/browser/ui/webui/inspect_ui.h"
[email protected]3c71576ce2013-07-23 02:00:0143#include "chrome/common/content_restriction.h"
[email protected]5d98294912012-06-27 22:57:4044#include "chrome/common/pref_names.h"
45#include "chrome/common/profiling.h"
brettwe1f0af8b2015-10-09 21:30:4646#include "components/bookmarks/common/bookmark_pref_names.h"
maxbogue26f40222016-09-16 20:22:1847#include "components/browser_sync/profile_sync_service.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
[email protected]5d98294912012-06-27 22:57:4091using content::NavigationEntry;
92using content::NavigationController;
93using content::WebContents;
94
[email protected]5d98294912012-06-27 22:57:4095namespace chrome {
96
97///////////////////////////////////////////////////////////////////////////////
98// BrowserCommandController, public:
99
[email protected]338416c02014-05-13 16:47:06100BrowserCommandController::BrowserCommandController(Browser* browser)
[email protected]5d98294912012-06-27 22:57:40101 : browser_(browser),
Ivan Sandrk9669d0e2017-12-15 23:50:20102 command_updater_(nullptr) {
[email protected]5d98294912012-06-27 22:57:40103 browser_->tab_strip_model()->AddObserver(this);
104 PrefService* local_state = g_browser_process->local_state();
105 if (local_state) {
106 local_pref_registrar_.Init(local_state);
[email protected]9ec3ea5b2012-12-03 18:14:30107 local_pref_registrar_.Add(
108 prefs::kAllowFileSelectionDialogs,
109 base::Bind(
110 &BrowserCommandController::UpdateCommandsForFileSelectionDialogs,
111 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40112 }
113
114 profile_pref_registrar_.Init(profile()->GetPrefs());
[email protected]9ec3ea5b2012-12-03 18:14:30115 profile_pref_registrar_.Add(
Pavol Markodebb0ff2018-05-07 18:35:41116 prefs::kDevToolsAvailability,
[email protected]9ec3ea5b2012-12-03 18:14:30117 base::Bind(&BrowserCommandController::UpdateCommandsForDevTools,
118 base::Unretained(this)));
119 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32120 bookmarks::prefs::kEditBookmarksEnabled,
[email protected]9ec3ea5b2012-12-03 18:14:30121 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkEditing,
122 base::Unretained(this)));
123 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32124 bookmarks::prefs::kShowBookmarkBar,
[email protected]9ec3ea5b2012-12-03 18:14:30125 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkBar,
126 base::Unretained(this)));
127 profile_pref_registrar_.Add(
128 prefs::kIncognitoModeAvailability,
129 base::Bind(
130 &BrowserCommandController::UpdateCommandsForIncognitoAvailability,
131 base::Unretained(this)));
132 profile_pref_registrar_.Add(
133 prefs::kPrintingEnabled,
134 base::Bind(&BrowserCommandController::UpdatePrintingState,
135 base::Unretained(this)));
[email protected]32dfede2013-08-25 15:48:25136#if !defined(OS_MACOSX)
137 profile_pref_registrar_.Add(
138 prefs::kFullscreenAllowed,
139 base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode,
140 base::Unretained(this)));
141#endif
estade8c0780f2015-08-21 23:36:41142 pref_signin_allowed_.Init(
143 prefs::kSigninAllowed,
144 profile()->GetOriginalProfile()->GetPrefs(),
145 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange,
146 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40147
148 InitCommandState();
149
blundell74001adc2015-09-18 11:04:25150 sessions::TabRestoreService* tab_restore_service =
[email protected]5d98294912012-06-27 22:57:40151 TabRestoreServiceFactory::GetForProfile(profile());
152 if (tab_restore_service) {
153 tab_restore_service->AddObserver(this);
154 TabRestoreServiceChanged(tab_restore_service);
155 }
[email protected]5d98294912012-06-27 22:57:40156}
157
158BrowserCommandController::~BrowserCommandController() {
[email protected]95e39472012-10-05 23:37:36159 // TabRestoreService may have been shutdown by the time we get here. Don't
160 // trigger creating it.
blundell74001adc2015-09-18 11:04:25161 sessions::TabRestoreService* tab_restore_service =
[email protected]95e39472012-10-05 23:37:36162 TabRestoreServiceFactory::GetForProfileIfExisting(profile());
[email protected]5d98294912012-06-27 22:57:40163 if (tab_restore_service)
164 tab_restore_service->RemoveObserver(this);
165 profile_pref_registrar_.RemoveAll();
166 local_pref_registrar_.RemoveAll();
167 browser_->tab_strip_model()->RemoveObserver(this);
[email protected]5d98294912012-06-27 22:57:40168}
169
170bool BrowserCommandController::IsReservedCommandOrKey(
171 int command_id,
172 const content::NativeWebKeyboardEvent& event) {
173 // In Apps mode, no keys are reserved.
174 if (browser_->is_app())
175 return false;
176
177#if defined(OS_CHROMEOS)
[email protected]397abd32013-08-21 05:44:19178 // On Chrome OS, the top row of keys are mapped to browser actions like
179 // back/forward or refresh. We don't want web pages to be able to change the
180 // behavior of these keys. Ash handles F4 and up; this leaves us needing to
181 // reserve browser back/forward and refresh here.
[email protected]5d98294912012-06-27 22:57:40182 ui::KeyboardCode key_code =
Blink Reformat1c4d759e2017-04-09 16:34:54183 static_cast<ui::KeyboardCode>(event.windows_key_code);
[email protected]397abd32013-08-21 05:44:19184 if ((key_code == ui::VKEY_BROWSER_BACK && command_id == IDC_BACK) ||
185 (key_code == ui::VKEY_BROWSER_FORWARD && command_id == IDC_FORWARD) ||
186 (key_code == ui::VKEY_BROWSER_REFRESH && command_id == IDC_RELOAD)) {
[email protected]5d98294912012-06-27 22:57:40187 return true;
188 }
189#endif
190
zijiehe68cd3dc22017-04-07 18:50:29191 if (window()->IsFullscreen()) {
192 // In fullscreen, all commands except for IDC_FULLSCREEN and IDC_EXIT should
193 // be delivered to the web page. The intent to implement and ship can be
194 // found in http://crbug.com/680809.
195 const bool is_exit_fullscreen =
196 (command_id == IDC_EXIT || command_id == IDC_FULLSCREEN);
197#if defined(OS_MACOSX)
198 // This behavior is different on Mac OS, which has a unique user-initiated
199 // full-screen mode. According to the discussion in http://crbug.com/702251,
200 // the commands should be reserved for browser-side handling if the browser
201 // window's toolbar is visible.
202 if (window()->IsToolbarShowing()) {
203 if (command_id == IDC_FULLSCREEN)
204 return true;
205 } else {
206 return is_exit_fullscreen;
207 }
208#else
209 return is_exit_fullscreen;
210#endif
211 }
[email protected]1e2172f2014-04-01 17:32:34212
[email protected]893124a22014-04-15 00:45:28213#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]1e2172f2014-04-01 17:32:34214 // If this key was registered by the user as a content editing hotkey, then
215 // it is not reserved.
[email protected]d5bedb6d2014-04-08 10:49:32216 ui::TextEditKeyBindingsDelegateAuraLinux* delegate =
[email protected]1e2172f2014-04-01 17:32:34217 ui::GetTextEditKeyBindingsDelegate();
[email protected]47e8e7542014-04-03 07:52:42218 if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL))
[email protected]1e2172f2014-04-01 17:32:34219 return false;
220#endif
221
zijiehe13207802017-02-16 08:06:10222 return command_id == IDC_CLOSE_TAB ||
223 command_id == IDC_CLOSE_WINDOW ||
224 command_id == IDC_NEW_INCOGNITO_WINDOW ||
225 command_id == IDC_NEW_TAB ||
226 command_id == IDC_NEW_WINDOW ||
227 command_id == IDC_RESTORE_TAB ||
228 command_id == IDC_SELECT_NEXT_TAB ||
229 command_id == IDC_SELECT_PREVIOUS_TAB ||
230 command_id == IDC_EXIT;
[email protected]5d98294912012-06-27 22:57:40231}
232
[email protected]5d98294912012-06-27 22:57:40233void BrowserCommandController::TabStateChanged() {
234 UpdateCommandsForTabState();
235}
236
[email protected]d93dbd12014-08-04 23:42:53237void BrowserCommandController::ZoomStateChanged() {
238 UpdateCommandsForZoomState();
239}
240
[email protected]5d98294912012-06-27 22:57:40241void BrowserCommandController::ContentRestrictionsChanged() {
242 UpdateCommandsForContentRestrictionState();
243}
244
245void BrowserCommandController::FullscreenStateChanged() {
[email protected]32dfede2013-08-25 15:48:25246 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40247}
248
Ivan Sandrk9669d0e2017-12-15 23:50:20249#if defined(OS_CHROMEOS)
250void BrowserCommandController::LockedFullscreenStateChanged() {
251 UpdateCommandsForLockedFullscreenMode();
252}
253#endif
254
[email protected]5d98294912012-06-27 22:57:40255void BrowserCommandController::PrintingStateChanged() {
256 UpdatePrintingState();
257}
258
259void BrowserCommandController::LoadingStateChanged(bool is_loading,
260 bool force) {
261 UpdateReloadStopState(is_loading, force);
262}
263
wittman76df71db32014-12-18 23:26:58264void BrowserCommandController::ExtensionStateChanged() {
265 // Extensions may disable the bookmark editing commands.
266 UpdateCommandsForBookmarkEditing();
267}
268
[email protected]5d98294912012-06-27 22:57:40269////////////////////////////////////////////////////////////////////////////////
Ivan Sandrk9669d0e2017-12-15 23:50:20270// BrowserCommandController, CommandUpdater implementation:
[email protected]5d98294912012-06-27 22:57:40271
Ivan Sandrk9669d0e2017-12-15 23:50:20272bool BrowserCommandController::SupportsCommand(int id) const {
273 return command_updater_.SupportsCommand(id);
274}
275
276bool BrowserCommandController::IsCommandEnabled(int id) const {
277 return command_updater_.IsCommandEnabled(id);
278}
279
280bool BrowserCommandController::ExecuteCommand(int id) {
281 return ExecuteCommandWithDisposition(id, WindowOpenDisposition::CURRENT_TAB);
282}
283
284bool BrowserCommandController::ExecuteCommandWithDisposition(
285 int id, WindowOpenDisposition disposition) {
286 // Doesn't go through the command_updater_ to avoid dealing with having a
287 // naming collision for ExecuteCommandWithDisposition (both
288 // CommandUpdaterDelegate and CommandUpdater declare this function so we
289 // choose to not implement CommandUpdaterDelegate inside this class and
290 // therefore command_updater_ doesn't have the delegate set).
291 if (!SupportsCommand(id) || !IsCommandEnabled(id))
292 return false;
293
[email protected]5d98294912012-06-27 22:57:40294 // No commands are enabled if there is not yet any selected tab.
295 // TODO(pkasting): It seems like we should not need this, because either
296 // most/all commands should not have been enabled yet anyway or the ones that
297 // are enabled should be global, or safe themselves against having no selected
298 // tab. However, Ben says he tried removing this before and got lots of
299 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
300 // window construction. This probably could use closer examination someday.
[email protected]59253a652012-11-20 00:17:26301 if (browser_->tab_strip_model()->active_index() == TabStripModel::kNoTab)
Ivan Sandrk9669d0e2017-12-15 23:50:20302 return true;
[email protected]5d98294912012-06-27 22:57:40303
304 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command "
305 << id;
306
[email protected]5d98294912012-06-27 22:57:40307 // The order of commands in this switch statement must match the function
308 // declaration order in browser.h!
309 switch (id) {
310 // Navigation commands
[email protected]5d98294912012-06-27 22:57:40311 case IDC_BACK:
[email protected]5d98294912012-06-27 22:57:40312 GoBack(browser_, disposition);
313 break;
[email protected]5d98294912012-06-27 22:57:40314 case IDC_FORWARD:
[email protected]5d98294912012-06-27 22:57:40315 GoForward(browser_, disposition);
316 break;
317 case IDC_RELOAD:
318 Reload(browser_, disposition);
319 break;
[email protected]58e29032012-08-06 20:19:57320 case IDC_RELOAD_CLEARING_CACHE:
321 ClearCache(browser_);
Nico Webera745ef72018-01-29 23:45:57322 FALLTHROUGH;
toyoshim7dad4b1182016-04-01 14:28:05323 case IDC_RELOAD_BYPASSING_CACHE:
324 ReloadBypassingCache(browser_, disposition);
[email protected]5d98294912012-06-27 22:57:40325 break;
326 case IDC_HOME:
327 Home(browser_, disposition);
328 break;
329 case IDC_OPEN_CURRENT_URL:
330 OpenCurrentURL(browser_);
331 break;
332 case IDC_STOP:
333 Stop(browser_);
334 break;
335
336 // Window management commands
337 case IDC_NEW_WINDOW:
338 NewWindow(browser_);
339 break;
340 case IDC_NEW_INCOGNITO_WINDOW:
341 NewIncognitoWindow(browser_);
342 break;
343 case IDC_CLOSE_WINDOW:
bratell0a7406f2017-03-28 07:46:37344 base::RecordAction(base::UserMetricsAction("CloseWindowByKey"));
[email protected]04b9e692012-08-24 14:49:09345 CloseWindow(browser_);
[email protected]5d98294912012-06-27 22:57:40346 break;
Bettina Dea0a4505922017-09-28 00:53:32347 case IDC_NEW_TAB: {
348 NewTab(browser_);
349#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Catherine Chungbeb884222017-08-01 15:47:55350 // This is not in NewTab() to avoid tracking programmatic creation of new
351 // tabs by extensions.
Bettina Dea0a4505922017-09-28 00:53:32352 auto* new_tab_tracker =
353 feature_engagement::NewTabTrackerFactory::GetInstance()
354 ->GetForProfile(profile());
355
356 new_tab_tracker->OnNewTabOpened();
357 new_tab_tracker->CloseBubble();
Catherine Chungbeb884222017-08-01 15:47:55358#endif
[email protected]5d98294912012-06-27 22:57:40359 break;
Bettina Dea0a4505922017-09-28 00:53:32360 }
[email protected]5d98294912012-06-27 22:57:40361 case IDC_CLOSE_TAB:
bratell0a7406f2017-03-28 07:46:37362 base::RecordAction(base::UserMetricsAction("CloseTabByKey"));
[email protected]04b9e692012-08-24 14:49:09363 CloseTab(browser_);
[email protected]5d98294912012-06-27 22:57:40364 break;
365 case IDC_SELECT_NEXT_TAB:
bratell0a7406f2017-03-28 07:46:37366 base::RecordAction(base::UserMetricsAction("Accel_SelectNextTab"));
[email protected]5d98294912012-06-27 22:57:40367 SelectNextTab(browser_);
368 break;
369 case IDC_SELECT_PREVIOUS_TAB:
bratell0a7406f2017-03-28 07:46:37370 base::RecordAction(base::UserMetricsAction("Accel_SelectPreviousTab"));
[email protected]5d98294912012-06-27 22:57:40371 SelectPreviousTab(browser_);
372 break;
[email protected]5d98294912012-06-27 22:57:40373 case IDC_MOVE_TAB_NEXT:
374 MoveTabNext(browser_);
375 break;
376 case IDC_MOVE_TAB_PREVIOUS:
377 MoveTabPrevious(browser_);
378 break;
379 case IDC_SELECT_TAB_0:
380 case IDC_SELECT_TAB_1:
381 case IDC_SELECT_TAB_2:
382 case IDC_SELECT_TAB_3:
383 case IDC_SELECT_TAB_4:
384 case IDC_SELECT_TAB_5:
385 case IDC_SELECT_TAB_6:
386 case IDC_SELECT_TAB_7:
bratell0a7406f2017-03-28 07:46:37387 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
[email protected]5d98294912012-06-27 22:57:40388 SelectNumberedTab(browser_, id - IDC_SELECT_TAB_0);
389 break;
390 case IDC_SELECT_LAST_TAB:
bratell0a7406f2017-03-28 07:46:37391 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
[email protected]5d98294912012-06-27 22:57:40392 SelectLastTab(browser_);
393 break;
394 case IDC_DUPLICATE_TAB:
395 DuplicateTab(browser_);
396 break;
397 case IDC_RESTORE_TAB:
398 RestoreTab(browser_);
399 break;
[email protected]5d98294912012-06-27 22:57:40400 case IDC_SHOW_AS_TAB:
401 ConvertPopupToTabbedBrowser(browser_);
402 break;
403 case IDC_FULLSCREEN:
[email protected]3f32b9b2012-07-09 16:59:28404 chrome::ToggleFullscreenMode(browser_);
[email protected]5d98294912012-06-27 22:57:40405 break;
Alan Cutter09965802018-03-27 07:25:29406 case IDC_OPEN_IN_PWA_WINDOW:
407 base::RecordAction(base::UserMetricsAction("OpenActiveTabInPwaWindow"));
408 ReparentSecureActiveTabIntoPwaWindow(browser_);
409 break;
[email protected]770c6d82012-09-06 22:21:32410
[email protected]d12cc5e2013-10-19 18:25:06411#if defined(OS_CHROMEOS)
412 case IDC_VISIT_DESKTOP_OF_LRU_USER_2:
[email protected]0c930812014-01-30 18:01:47413 case IDC_VISIT_DESKTOP_OF_LRU_USER_3:
zijiehe4dde8072017-02-13 20:38:35414 ExecuteVisitDesktopCommand(id, window()->GetNativeWindow());
[email protected]0c930812014-01-30 18:01:47415 break;
[email protected]d12cc5e2013-10-19 18:25:06416#endif
417
[email protected]893124a22014-04-15 00:45:28418#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15419 case IDC_MINIMIZE_WINDOW:
420 browser_->window()->Minimize();
421 break;
422 case IDC_MAXIMIZE_WINDOW:
423 browser_->window()->Maximize();
424 break;
425 case IDC_RESTORE_WINDOW:
426 browser_->window()->Restore();
427 break;
[email protected]af97be4c62014-02-13 14:43:34428 case IDC_USE_SYSTEM_TITLE_BAR: {
zijiehe4dde8072017-02-13 20:38:35429 PrefService* prefs = profile()->GetPrefs();
[email protected]af97be4c62014-02-13 14:43:34430 prefs->SetBoolean(prefs::kUseCustomChromeFrame,
431 !prefs->GetBoolean(prefs::kUseCustomChromeFrame));
432 break;
433 }
434#endif
435
[email protected]5d98294912012-06-27 22:57:40436#if defined(OS_MACOSX)
spqchanb8ffc7d2015-11-17 01:17:21437 case IDC_TOGGLE_FULLSCREEN_TOOLBAR:
438 chrome::ToggleFullscreenToolbar(browser_);
439 break;
spqchan2c5d541e2017-10-25 07:07:11440 case IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS: {
441 PrefService* prefs = profile()->GetPrefs();
442 prefs->SetBoolean(prefs::kAllowJavascriptAppleEvents,
443 !prefs->GetBoolean(prefs::kAllowJavascriptAppleEvents));
444 break;
445 }
[email protected]5d98294912012-06-27 22:57:40446#endif
447 case IDC_EXIT:
448 Exit();
449 break;
450
451 // Page-related commands
452 case IDC_SAVE_PAGE:
453 SavePage(browser_);
454 break;
455 case IDC_BOOKMARK_PAGE:
Anatoly Pilikovee720922017-11-01 09:43:17456#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:14457 feature_engagement::BookmarkTrackerFactory::GetInstance()
458 ->GetForProfile(profile())
459 ->OnBookmarkAdded();
460#endif
deepak.m154a7f392014-12-15 04:41:43461 BookmarkCurrentPageAllowingExtensionOverrides(browser_);
[email protected]5d98294912012-06-27 22:57:40462 break;
[email protected]5d98294912012-06-27 22:57:40463 case IDC_BOOKMARK_ALL_TABS:
Anatoly Pilikovee720922017-11-01 09:43:17464#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:14465 feature_engagement::BookmarkTrackerFactory::GetInstance()
466 ->GetForProfile(profile())
467 ->OnBookmarkAdded();
468#endif
[email protected]5d98294912012-06-27 22:57:40469 BookmarkAllTabs(browser_);
470 break;
471 case IDC_VIEW_SOURCE:
Lukasz Anforowicze1b954d92017-10-30 21:28:06472 browser_->tab_strip_model()
473 ->GetActiveWebContents()
474 ->GetMainFrame()
475 ->ViewSource();
[email protected]5d98294912012-06-27 22:57:40476 break;
477 case IDC_EMAIL_PAGE_LOCATION:
478 EmailPageLocation(browser_);
479 break;
480 case IDC_PRINT:
481 Print(browser_);
482 break;
bondd052b5f82015-10-28 22:39:32483
Lei Zhang48a4a5262018-04-17 20:18:44484#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:55485 case IDC_BASIC_PRINT:
bratell0a7406f2017-03-28 07:46:37486 base::RecordAction(base::UserMetricsAction("Accel_Advanced_Print"));
vitalybukaf9433e42014-09-08 10:04:55487 BasicPrint(browser_);
[email protected]5d98294912012-06-27 22:57:40488 break;
Lei Zhang48a4a5262018-04-17 20:18:44489#endif // ENABLE_PRINTING
bondd052b5f82015-10-28 22:39:32490
bondd052b5f82015-10-28 22:39:32491 case IDC_SAVE_CREDIT_CARD_FOR_PAGE:
492 SaveCreditCard(browser_);
493 break;
[email protected]e625b7602013-10-28 09:24:56494 case IDC_TRANSLATE_PAGE:
495 Translate(browser_);
496 break;
[email protected]4bee4432014-05-05 13:11:41497 case IDC_MANAGE_PASSWORDS_FOR_PAGE:
498 ManagePasswordsForPage(browser_);
499 break;
500
[email protected]5d98294912012-06-27 22:57:40501 // Clipboard commands
502 case IDC_CUT:
[email protected]5d98294912012-06-27 22:57:40503 case IDC_COPY:
[email protected]5d98294912012-06-27 22:57:40504 case IDC_PASTE:
pkastingcd3f08bce2015-04-18 13:37:12505 CutCopyPaste(browser_, id);
[email protected]5d98294912012-06-27 22:57:40506 break;
507
508 // Find-in-page
509 case IDC_FIND:
510 Find(browser_);
511 break;
512 case IDC_FIND_NEXT:
513 FindNext(browser_);
514 break;
515 case IDC_FIND_PREVIOUS:
516 FindPrevious(browser_);
517 break;
518
519 // Zoom
520 case IDC_ZOOM_PLUS:
521 Zoom(browser_, content::PAGE_ZOOM_IN);
522 break;
523 case IDC_ZOOM_NORMAL:
524 Zoom(browser_, content::PAGE_ZOOM_RESET);
525 break;
526 case IDC_ZOOM_MINUS:
527 Zoom(browser_, content::PAGE_ZOOM_OUT);
528 break;
529
530 // Focus various bits of UI
531 case IDC_FOCUS_TOOLBAR:
bratell0a7406f2017-03-28 07:46:37532 base::RecordAction(base::UserMetricsAction("Accel_Focus_Toolbar"));
[email protected]5d98294912012-06-27 22:57:40533 FocusToolbar(browser_);
534 break;
535 case IDC_FOCUS_LOCATION:
bratell0a7406f2017-03-28 07:46:37536 base::RecordAction(base::UserMetricsAction("Accel_Focus_Location"));
[email protected]5d98294912012-06-27 22:57:40537 FocusLocationBar(browser_);
538 break;
539 case IDC_FOCUS_SEARCH:
bratell0a7406f2017-03-28 07:46:37540 base::RecordAction(base::UserMetricsAction("Accel_Focus_Search"));
[email protected]5d98294912012-06-27 22:57:40541 FocusSearch(browser_);
542 break;
543 case IDC_FOCUS_MENU_BAR:
544 FocusAppMenu(browser_);
545 break;
546 case IDC_FOCUS_BOOKMARKS:
bratell0a7406f2017-03-28 07:46:37547 base::RecordAction(base::UserMetricsAction("Accel_Focus_Bookmarks"));
[email protected]5d98294912012-06-27 22:57:40548 FocusBookmarksToolbar(browser_);
549 break;
David Tsengc0b1b642018-01-24 07:12:27550 case IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY:
551 FocusInactivePopupForAccessibility(browser_);
[email protected]822ca8c62013-04-19 00:49:15552 break;
[email protected]5d98294912012-06-27 22:57:40553 case IDC_FOCUS_NEXT_PANE:
554 FocusNextPane(browser_);
555 break;
556 case IDC_FOCUS_PREVIOUS_PANE:
557 FocusPreviousPane(browser_);
558 break;
559
560 // Show various bits of UI
561 case IDC_OPEN_FILE:
562 browser_->OpenFile();
563 break;
[email protected]488e3952013-11-18 05:29:14564 case IDC_CREATE_HOSTED_APP:
[email protected]92086542014-04-08 08:45:29565 CreateBookmarkAppFromCurrentWebContents(browser_);
[email protected]488e3952013-11-18 05:29:14566 break;
[email protected]5d98294912012-06-27 22:57:40567 case IDC_DEV_TOOLS:
[email protected]c934c382013-11-01 00:36:01568 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Show());
[email protected]5d98294912012-06-27 22:57:40569 break;
570 case IDC_DEV_TOOLS_CONSOLE:
einbinderdfa567b2016-12-16 01:15:52571 ToggleDevToolsWindow(browser_, DevToolsToggleAction::ShowConsolePanel());
[email protected]5d98294912012-06-27 22:57:40572 break;
[email protected]2056c3192013-10-21 22:40:51573 case IDC_DEV_TOOLS_DEVICES:
574 InspectUI::InspectDevices(browser_);
575 break;
[email protected]5d98294912012-06-27 22:57:40576 case IDC_DEV_TOOLS_INSPECT:
[email protected]c934c382013-11-01 00:36:01577 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Inspect());
[email protected]5d98294912012-06-27 22:57:40578 break;
[email protected]d16657c2012-09-03 14:25:10579 case IDC_DEV_TOOLS_TOGGLE:
[email protected]c934c382013-11-01 00:36:01580 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Toggle());
[email protected]d16657c2012-09-03 14:25:10581 break;
[email protected]5d98294912012-06-27 22:57:40582 case IDC_TASK_MANAGER:
[email protected]29c262de2013-06-22 15:39:38583 OpenTaskManager(browser_);
[email protected]5d98294912012-06-27 22:57:40584 break;
caelyn4e4e08a2015-02-04 21:27:49585#if defined(OS_CHROMEOS)
586 case IDC_TAKE_SCREENSHOT:
587 TakeScreenshot();
588 break;
589#endif
[email protected]236ad3022013-09-04 03:27:43590#if defined(GOOGLE_CHROME_BUILD)
[email protected]5d98294912012-06-27 22:57:40591 case IDC_FEEDBACK:
afakhryf4575bd2017-04-28 02:21:04592 OpenFeedbackDialog(browser_, kFeedbackSourceBrowserCommand);
[email protected]5d98294912012-06-27 22:57:40593 break;
[email protected]236ad3022013-09-04 03:27:43594#endif
[email protected]5d98294912012-06-27 22:57:40595 case IDC_SHOW_BOOKMARK_BAR:
596 ToggleBookmarkBar(browser_);
597 break;
598 case IDC_PROFILING_ENABLED:
599 Profiling::Toggle();
600 break;
601
602 case IDC_SHOW_BOOKMARK_MANAGER:
603 ShowBookmarkManager(browser_);
604 break;
605 case IDC_SHOW_APP_MENU:
bratell0a7406f2017-03-28 07:46:37606 base::RecordAction(base::UserMetricsAction("Accel_Show_App_Menu"));
[email protected]5d98294912012-06-27 22:57:40607 ShowAppMenu(browser_);
608 break;
609 case IDC_SHOW_AVATAR_MENU:
610 ShowAvatarMenu(browser_);
611 break;
[email protected]5d98294912012-06-27 22:57:40612 case IDC_SHOW_HISTORY:
613 ShowHistory(browser_);
614 break;
615 case IDC_SHOW_DOWNLOADS:
616 ShowDownloads(browser_);
617 break;
618 case IDC_MANAGE_EXTENSIONS:
[email protected]bc9833c32013-02-28 04:05:08619 ShowExtensions(browser_, std::string());
[email protected]5d98294912012-06-27 22:57:40620 break;
621 case IDC_OPTIONS:
622 ShowSettings(browser_);
623 break;
624 case IDC_EDIT_SEARCH_ENGINES:
625 ShowSearchEngineSettings(browser_);
626 break;
627 case IDC_VIEW_PASSWORDS:
628 ShowPasswordManager(browser_);
629 break;
630 case IDC_CLEAR_BROWSING_DATA:
631 ShowClearBrowsingDataDialog(browser_);
632 break;
633 case IDC_IMPORT_SETTINGS:
634 ShowImportDialog(browser_);
635 break;
[email protected]9b7ab882012-09-10 23:46:36636 case IDC_TOGGLE_REQUEST_TABLET_SITE:
637 ToggleRequestTabletSite(browser_);
638 break;
[email protected]5d98294912012-06-27 22:57:40639 case IDC_ABOUT:
640 ShowAboutChrome(browser_);
641 break;
642 case IDC_UPGRADE_DIALOG:
643 OpenUpdateChromeDialog(browser_);
644 break;
[email protected]5d98294912012-06-27 22:57:40645 case IDC_HELP_PAGE_VIA_KEYBOARD:
646 ShowHelp(browser_, HELP_SOURCE_KEYBOARD);
647 break;
648 case IDC_HELP_PAGE_VIA_MENU:
649 ShowHelp(browser_, HELP_SOURCE_MENU);
650 break;
Bret Sepulveda2d018662017-05-18 21:31:48651 case IDC_SHOW_BETA_FORUM:
652 ShowBetaForum(browser_);
653 break;
estade8c0780f2015-08-21 23:36:41654 case IDC_SHOW_SIGNIN:
gogerald71bf6c902015-12-08 00:49:37655 ShowBrowserSigninOrSettings(
656 browser_, signin_metrics::AccessPoint::ACCESS_POINT_MENU);
estade8c0780f2015-08-21 23:36:41657 break;
[email protected]6bd370b2014-05-28 14:19:47658 case IDC_DISTILL_PAGE:
659 DistillCurrentPage(browser_);
660 break;
apacible45cbfc92015-09-28 22:45:41661 case IDC_ROUTE_MEDIA:
662 RouteMedia(browser_);
663 break;
Tommy Steimelc4477982017-11-29 18:07:18664 case IDC_WINDOW_MUTE_SITE:
665 MuteSite(browser_);
ellyjones0101ba02017-05-19 15:50:26666 break;
667 case IDC_WINDOW_PIN_TAB:
668 PinTab(browser_);
669 break;
[email protected]5d98294912012-06-27 22:57:40670
Christopher Lam0dbac2b2017-11-14 07:12:10671 // Hosted App commands
672 case IDC_COPY_URL:
673 CopyURL(browser_);
674 break;
675 case IDC_OPEN_IN_CHROME:
676 OpenInChrome(browser_);
677 break;
678 case IDC_SITE_SETTINGS:
679 ShowSiteSettings(
680 browser_,
681 browser_->tab_strip_model()->GetActiveWebContents()->GetVisibleURL());
682 break;
Alan Cutter0c3132302018-02-21 05:09:02683 case IDC_HOSTED_APP_MENU_APP_INFO:
684 ShowPageInfoDialog(browser_->tab_strip_model()->GetActiveWebContents(),
Alan Cutter689f89a2018-03-08 05:09:54685 bubble_anchor_util::kAppMenuButton);
Christopher Lam86b52712017-12-04 01:58:33686 break;
Tom Andersonbddfeda52018-06-14 22:25:06687#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(OS_CHROMEOS))
688 case IDC_TOGGLE_CONFIRM_TO_QUIT_OPTION:
689 ToggleConfirmToQuitOption(browser_);
690 break;
691#endif
Christopher Lam0dbac2b2017-11-14 07:12:10692
[email protected]5d98294912012-06-27 22:57:40693 default:
694 LOG(WARNING) << "Received Unimplemented Command: " << id;
695 break;
696 }
Ivan Sandrk9669d0e2017-12-15 23:50:20697
698 return true;
699}
700
701void BrowserCommandController::AddCommandObserver(int id,
702 CommandObserver* observer) {
703 command_updater_.AddCommandObserver(id, observer);
704}
705
706void BrowserCommandController::RemoveCommandObserver(
707 int id, CommandObserver* observer) {
708 command_updater_.RemoveCommandObserver(id, observer);
709}
710
711void BrowserCommandController::RemoveCommandObserver(
712 CommandObserver* observer) {
713 command_updater_.RemoveCommandObserver(observer);
714}
715
716bool BrowserCommandController::UpdateCommandEnabled(int id, bool state) {
717 if (is_locked_fullscreen_)
718 return false;
719
720 return command_updater_.UpdateCommandEnabled(id, state);
[email protected]5d98294912012-06-27 22:57:40721}
722
estade8c0780f2015-08-21 23:36:41723////////////////////////////////////////////////////////////////////////////////
724// BrowserCommandController, SigninPrefObserver implementation:
725
726void BrowserCommandController::OnSigninAllowedPrefChange() {
727 // For unit tests, we don't have a window.
728 if (!window())
729 return;
730 UpdateShowSyncState(IsShowingMainUI());
731}
732
[email protected]5d98294912012-06-27 22:57:40733// BrowserCommandController, TabStripModelObserver implementation:
734
pmonette9119e492016-09-20 22:14:55735void BrowserCommandController::TabInsertedAt(TabStripModel* tab_strip_model,
736 WebContents* contents,
[email protected]5d98294912012-06-27 22:57:40737 int index,
738 bool foreground) {
739 AddInterstitialObservers(contents);
740}
741
erikchen12c65582018-05-14 17:26:04742void BrowserCommandController::TabDetachedAt(WebContents* contents,
743 int index,
744 bool was_active) {
[email protected]5d98294912012-06-27 22:57:40745 RemoveInterstitialObservers(contents);
746}
747
748void BrowserCommandController::TabReplacedAt(TabStripModel* tab_strip_model,
[email protected]b624ddc2012-11-15 18:04:13749 WebContents* old_contents,
750 WebContents* new_contents,
[email protected]5d98294912012-06-27 22:57:40751 int index) {
[email protected]b624ddc2012-11-15 18:04:13752 RemoveInterstitialObservers(old_contents);
753 AddInterstitialObservers(new_contents);
[email protected]5d98294912012-06-27 22:57:40754}
755
[email protected]3cac87232012-11-20 01:48:27756void BrowserCommandController::TabBlockedStateChanged(
757 content::WebContents* contents,
758 int index) {
759 PrintingStateChanged();
760 FullscreenStateChanged();
761 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:41762 UpdateCommandsForMediaRouter();
[email protected]3cac87232012-11-20 01:48:27763}
764
[email protected]5d98294912012-06-27 22:57:40765////////////////////////////////////////////////////////////////////////////////
766// BrowserCommandController, TabRestoreServiceObserver implementation:
767
768void BrowserCommandController::TabRestoreServiceChanged(
blundell74001adc2015-09-18 11:04:25769 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53770 UpdateTabRestoreCommandState();
[email protected]5d98294912012-06-27 22:57:40771}
772
773void BrowserCommandController::TabRestoreServiceDestroyed(
blundell74001adc2015-09-18 11:04:25774 sessions::TabRestoreService* service) {
[email protected]5d98294912012-06-27 22:57:40775 service->RemoveObserver(this);
776}
777
[email protected]2e9369e2014-08-15 09:12:53778void BrowserCommandController::TabRestoreServiceLoaded(
blundell74001adc2015-09-18 11:04:25779 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53780 UpdateTabRestoreCommandState();
781}
782
[email protected]5d98294912012-06-27 22:57:40783////////////////////////////////////////////////////////////////////////////////
[email protected]5d98294912012-06-27 22:57:40784// BrowserCommandController, private:
785
[email protected]20ca0382013-02-28 19:50:07786class BrowserCommandController::InterstitialObserver
787 : public content::WebContentsObserver {
788 public:
789 InterstitialObserver(BrowserCommandController* controller,
790 content::WebContents* web_contents)
791 : WebContentsObserver(web_contents),
792 controller_(controller) {
793 }
794
dcheng5dd5ff62014-10-21 12:42:38795 void DidAttachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07796 controller_->UpdateCommandsForTabState();
797 }
798
dcheng5dd5ff62014-10-21 12:42:38799 void DidDetachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07800 controller_->UpdateCommandsForTabState();
801 }
802
803 private:
804 BrowserCommandController* controller_;
805
806 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver);
807};
808
[email protected]6a414ff2013-02-27 08:22:54809bool BrowserCommandController::IsShowingMainUI() {
810 bool should_hide_ui = window() && window()->ShouldHideUIForFullscreen();
811 return browser_->is_type_tabbed() && !should_hide_ui;
[email protected]5d98294912012-06-27 22:57:40812}
813
814void BrowserCommandController::InitCommandState() {
815 // All browser commands whose state isn't set automagically some other way
816 // (like Back & Forward with initial page load) must have their state
817 // initialized here, otherwise they will be forever disabled.
818
Ivan Sandrk9669d0e2017-12-15 23:50:20819 if (is_locked_fullscreen_)
820 return;
821
[email protected]5d98294912012-06-27 22:57:40822 // Navigation commands
823 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true);
toyoshim7dad4b1182016-04-01 14:28:05824 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE, true);
[email protected]58e29032012-08-06 20:19:57825 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, true);
[email protected]5d98294912012-06-27 22:57:40826
827 // Window management commands
828 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true);
829 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true);
830 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true);
831 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true);
[email protected]2e9369e2014-08-15 09:12:53832 UpdateTabRestoreCommandState();
[email protected]d28d3782013-02-26 16:31:55833 command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
[email protected]5d98294912012-06-27 22:57:40834 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true);
[email protected]d12cc5e2013-10-19 18:25:06835#if defined(OS_CHROMEOS)
James Cook934abaf2017-09-19 22:21:58836 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
[email protected]d12cc5e2013-10-19 18:25:06837 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_2, true);
838 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_3, true);
839#endif
[email protected]893124a22014-04-15 00:45:28840#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15841 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
842 command_updater_.UpdateCommandEnabled(IDC_MAXIMIZE_WINDOW, true);
843 command_updater_.UpdateCommandEnabled(IDC_RESTORE_WINDOW, true);
[email protected]af97be4c62014-02-13 14:43:34844 command_updater_.UpdateCommandEnabled(IDC_USE_SYSTEM_TITLE_BAR, true);
845#endif
Alan Cutter09965802018-03-27 07:25:29846 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW, true);
[email protected]5d98294912012-06-27 22:57:40847
848 // Page-related commands
849 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true);
[email protected]4bee4432014-05-05 13:11:41850 command_updater_.UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE, true);
[email protected]5d98294912012-06-27 22:57:40851
852 // Zoom
853 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true);
854 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true);
[email protected]d93dbd12014-08-04 23:42:53855 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, false);
[email protected]5d98294912012-06-27 22:57:40856 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
857
858 // Show various bits of UI
mlerman7831f57d2015-05-25 11:40:15859 const bool guest_session = profile()->IsGuestSession() ||
860 profile()->IsSystemProfile();
861 DCHECK(!profile()->IsSystemProfile())
862 << "Ought to never have browser for the system profile.";
[email protected]338416c02014-05-13 16:47:06863 const bool normal_window = browser_->is_type_tabbed();
[email protected]05454532013-01-22 21:09:08864 UpdateOpenFileState(&command_updater_);
[email protected]5d98294912012-06-27 22:57:40865 UpdateCommandsForDevTools();
866 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager());
[email protected]338416c02014-05-13 16:47:06867 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session);
[email protected]5d98294912012-06-27 22:57:40868 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
[email protected]674b65672014-06-02 23:21:56869 command_updater_.UpdateCommandEnabled(IDC_HELP_MENU, true);
[email protected]5d98294912012-06-27 22:57:40870 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
871 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
Bret Sepulveda2d018662017-05-18 21:31:48872 command_updater_.UpdateCommandEnabled(IDC_SHOW_BETA_FORUM, true);
[email protected]338416c02014-05-13 16:47:06873 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session);
[email protected]2f1acc212012-11-13 10:43:51874 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU,
[email protected]338416c02014-05-13 16:47:06875 !guest_session &&
[email protected]2f1acc212012-11-13 10:43:51876 !profile()->IsOffTheRecord());
tsergeant341a8272017-04-18 03:54:33877 command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA,
878 !guest_session);
Tom Andersonbddfeda52018-06-14 22:25:06879 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_CONFIRM_TO_QUIT_OPTION,
880 true);
[email protected]39d47592014-01-10 21:42:45881#if defined(OS_CHROMEOS)
caelyn4e4e08a2015-02-04 21:27:49882 command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true);
[email protected]338416c02014-05-13 16:47:06883#else
884 // Chrome OS uses the system tray menu to handle multi-profiles.
anthonyvd7dc985da2015-03-23 16:53:19885 if (normal_window && (guest_session || !profile()->IsOffTheRecord())) {
[email protected]338416c02014-05-13 16:47:06886 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
anthonyvd7dc985da2015-03-23 16:53:19887 }
[email protected]39d47592014-01-10 21:42:45888#endif
[email protected]5d98294912012-06-27 22:57:40889
estade8c0780f2015-08-21 23:36:41890 UpdateShowSyncState(true);
891
[email protected]5d98294912012-06-27 22:57:40892 // Navigation commands
[email protected]c9f983d2014-02-05 09:00:24893 command_updater_.UpdateCommandEnabled(
894 IDC_HOME,
benwellsc431c0ae2015-01-27 22:04:06895 normal_window ||
896 (extensions::util::IsNewBookmarkAppsEnabled() && browser_->is_app()));
[email protected]5d98294912012-06-27 22:57:40897
Christopher Lam0dbac2b2017-11-14 07:12:10898 const bool is_experimental_hosted_app =
899 extensions::HostedAppBrowserController::IsForExperimentalHostedAppBrowser(
900 browser_);
901 // Hosted app browser commands.
902 command_updater_.UpdateCommandEnabled(IDC_COPY_URL,
903 is_experimental_hosted_app);
904 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_CHROME,
905 is_experimental_hosted_app);
906 command_updater_.UpdateCommandEnabled(IDC_SITE_SETTINGS,
907 is_experimental_hosted_app);
Alan Cutter0c3132302018-02-21 05:09:02908 command_updater_.UpdateCommandEnabled(IDC_HOSTED_APP_MENU_APP_INFO,
Christopher Lam86b52712017-12-04 01:58:33909 is_experimental_hosted_app);
Christopher Lam0dbac2b2017-11-14 07:12:10910
[email protected]5d98294912012-06-27 22:57:40911 // Window management commands
[email protected]5d98294912012-06-27 22:57:40912 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window);
913 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB,
914 normal_window);
915 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window);
916 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window);
917 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window);
918 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window);
919 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window);
920 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window);
921 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window);
922 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window);
923 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window);
924 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window);
925 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window);
[email protected]5d98294912012-06-27 22:57:40926
[email protected]338416c02014-05-13 16:47:06927 // These are always enabled; the menu determines their menu item visibility.
[email protected]5d98294912012-06-27 22:57:40928 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
[email protected]5d98294912012-06-27 22:57:40929
[email protected]6bd370b2014-05-28 14:19:47930 // Distill current page.
931 command_updater_.UpdateCommandEnabled(
avi556c05022014-12-22 23:31:43932 IDC_DISTILL_PAGE, base::CommandLine::ForCurrentProcess()->HasSwitch(
933 switches::kEnableDomDistiller));
[email protected]6bd370b2014-05-28 14:19:47934
Tommy Steimelc4477982017-11-29 18:07:18935 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE, normal_window);
ellyjones0101ba02017-05-19 15:50:26936 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, normal_window);
937
[email protected]338416c02014-05-13 16:47:06938 // Initialize other commands whose state changes based on various conditions.
[email protected]32dfede2013-08-25 15:48:25939 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40940 UpdateCommandsForContentRestrictionState();
[email protected]5d98294912012-06-27 22:57:40941 UpdateCommandsForBookmarkEditing();
[email protected]5d98294912012-06-27 22:57:40942 UpdateCommandsForIncognitoAvailability();
943}
944
[email protected]05454532013-01-22 21:09:08945// static
946void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
947 CommandUpdater* command_updater,
948 Profile* profile) {
mlermane01e6de2014-09-29 19:26:47949 const bool guest_session = profile->IsGuestSession();
950 // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession().
[email protected]5d98294912012-06-27 22:57:40951 IncognitoModePrefs::Availability incognito_availability =
[email protected]05454532013-01-22 21:09:08952 IncognitoModePrefs::GetAvailability(profile->GetPrefs());
953 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40954 IDC_NEW_WINDOW,
955 incognito_availability != IncognitoModePrefs::FORCED);
[email protected]05454532013-01-22 21:09:08956 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40957 IDC_NEW_INCOGNITO_WINDOW,
mlermane01e6de2014-09-29 19:26:47958 incognito_availability != IncognitoModePrefs::DISABLED && !guest_session);
[email protected]5d98294912012-06-27 22:57:40959
[email protected]57b25292014-05-01 16:31:06960 const bool forced_incognito =
961 incognito_availability == IncognitoModePrefs::FORCED ||
962 guest_session; // Guest always runs in Incognito mode.
[email protected]05454532013-01-22 21:09:08963 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40964 IDC_SHOW_BOOKMARK_MANAGER,
[email protected]57b25292014-05-01 16:31:06965 browser_defaults::bookmarks_enabled && !forced_incognito);
Devlin Cronin21dba422018-05-30 15:45:16966 extensions::ExtensionService* extension_service =
[email protected]03d25812014-06-22 19:41:55967 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]57b25292014-05-01 16:31:06968 const bool enable_extensions =
[email protected]5d98294912012-06-27 22:57:40969 extension_service && extension_service->extensions_enabled();
[email protected]5d98294912012-06-27 22:57:40970
[email protected]57b25292014-05-01 16:31:06971 // Bookmark manager and settings page/subpages are forced to open in normal
972 // mode. For this reason we disable these commands when incognito is forced.
973 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
974 enable_extensions && !forced_incognito);
975
976 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito);
977 command_updater->UpdateCommandEnabled(IDC_OPTIONS,
978 !forced_incognito || guest_session);
estade8c0780f2015-08-21 23:36:41979 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito);
[email protected]05454532013-01-22 21:09:08980}
981
982void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
Ivan Sandrk9669d0e2017-12-15 23:50:20983 if (is_locked_fullscreen_)
984 return;
985
[email protected]05454532013-01-22 21:09:08986 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile());
987
[email protected]6a414ff2013-02-27 08:22:54988 if (!IsShowingMainUI()) {
[email protected]05454532013-01-22 21:09:08989 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false);
990 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false);
991 }
[email protected]5d98294912012-06-27 22:57:40992}
993
994void BrowserCommandController::UpdateCommandsForTabState() {
Ivan Sandrk9669d0e2017-12-15 23:50:20995 if (is_locked_fullscreen_)
996 return;
997
[email protected]617ee962013-01-29 20:49:12998 WebContents* current_web_contents =
999 browser_->tab_strip_model()->GetActiveWebContents();
[email protected]1c5119c2012-09-19 00:08:571000 if (!current_web_contents) // May be NULL during tab restore.
[email protected]5d98294912012-06-27 22:57:401001 return;
[email protected]5d98294912012-06-27 22:57:401002
1003 // Navigation commands
[email protected]5d98294912012-06-27 22:57:401004 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_));
[email protected]5d98294912012-06-27 22:57:401005 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_));
1006 command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_));
toyoshim7dad4b1182016-04-01 14:28:051007 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE,
[email protected]5d98294912012-06-27 22:57:401008 CanReload(browser_));
[email protected]58e29032012-08-06 20:19:571009 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE,
1010 CanReload(browser_));
[email protected]5d98294912012-06-27 22:57:401011
1012 // Window management commands
1013 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB,
1014 !browser_->is_app() && CanDuplicateTab(browser_));
Tommy Steimelc4477982017-11-29 18:07:181015 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE,
ellyjones0101ba02017-05-19 15:50:261016 !browser_->is_app());
1017 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB,
1018 !browser_->is_app());
[email protected]5d98294912012-06-27 22:57:401019
1020 // Page-related commands
1021 window()->SetStarredState(
[email protected]1c5119c2012-09-19 00:08:571022 BookmarkTabHelper::FromWebContents(current_web_contents)->is_starred());
[email protected]5423c372012-08-22 05:50:161023 window()->ZoomChangedForActiveTab(false);
[email protected]5d98294912012-06-27 22:57:401024 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
1025 CanViewSource(browser_));
1026 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION,
1027 CanEmailPageLocation(browser_));
1028 if (browser_->is_devtools())
1029 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false);
1030
[email protected]92086542014-04-08 08:45:291031 command_updater_.UpdateCommandEnabled(IDC_CREATE_HOSTED_APP,
1032 CanCreateBookmarkApp(browser_));
Alan Cutter403cebb2018-05-17 05:22:451033 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW,
1034 CanCreateBookmarkApp(browser_));
[email protected]5d98294912012-06-27 22:57:401035
[email protected]9b7ab882012-09-10 23:46:361036 command_updater_.UpdateCommandEnabled(
1037 IDC_TOGGLE_REQUEST_TABLET_SITE,
1038 CanRequestTabletSite(current_web_contents));
1039
[email protected]5d98294912012-06-27 22:57:401040 UpdateCommandsForContentRestrictionState();
1041 UpdateCommandsForBookmarkEditing();
[email protected]3cac87232012-11-20 01:48:271042 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:411043 UpdateCommandsForMediaRouter();
[email protected]d93dbd12014-08-04 23:42:531044 // Update the zoom commands when an active tab is selected.
1045 UpdateCommandsForZoomState();
1046}
1047
1048void BrowserCommandController::UpdateCommandsForZoomState() {
1049 WebContents* contents =
1050 browser_->tab_strip_model()->GetActiveWebContents();
1051 if (!contents)
1052 return;
a.sarkar.arundaadc712015-02-26 05:39:081053 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS,
1054 CanZoomIn(contents));
1055 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL,
ccameronb7c1d6c2015-03-09 17:08:241056 CanResetZoom(contents));
a.sarkar.arundaadc712015-02-26 05:39:081057 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS,
1058 CanZoomOut(contents));
[email protected]5d98294912012-06-27 22:57:401059}
1060
1061void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
1062 int restrictions = GetContentRestrictions(browser_);
1063
1064 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011065 IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY));
[email protected]5d98294912012-06-27 22:57:401066 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011067 IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT));
[email protected]5d98294912012-06-27 22:57:401068 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011069 IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE));
[email protected]5d98294912012-06-27 22:57:401070 UpdateSaveAsState();
1071 UpdatePrintingState();
1072}
1073
1074void BrowserCommandController::UpdateCommandsForDevTools() {
Ivan Sandrk9669d0e2017-12-15 23:50:201075 if (is_locked_fullscreen_)
1076 return;
1077
Pavol Marko56df0272018-07-04 17:55:041078 bool dev_tools_enabled = DevToolsWindow::AllowDevToolsFor(
1079 profile(), browser_->tab_strip_model()->GetActiveWebContents());
[email protected]5d98294912012-06-27 22:57:401080 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS,
1081 dev_tools_enabled);
1082 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE,
1083 dev_tools_enabled);
[email protected]2056c3192013-10-21 22:40:511084 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES,
1085 dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401086 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT,
1087 dev_tools_enabled);
[email protected]d16657c2012-09-03 14:25:101088 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE,
1089 dev_tools_enabled);
spqchan2c5d541e2017-10-25 07:07:111090#if defined(OS_MACOSX)
1091 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS,
1092 dev_tools_enabled);
1093#endif
[email protected]5d98294912012-06-27 22:57:401094}
1095
1096void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
Ivan Sandrk9669d0e2017-12-15 23:50:201097 if (is_locked_fullscreen_)
1098 return;
1099
[email protected]5d98294912012-06-27 22:57:401100 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE,
1101 CanBookmarkCurrentPage(browser_));
1102 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
1103 CanBookmarkAllTabs(browser_));
thestig5149d272014-10-30 07:25:291104#if defined(OS_WIN)
1105 command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN, true);
1106#endif
[email protected]5d98294912012-06-27 22:57:401107}
1108
1109void BrowserCommandController::UpdateCommandsForBookmarkBar() {
Ivan Sandrk9669d0e2017-12-15 23:50:201110 if (is_locked_fullscreen_)
1111 return;
1112
tfarina3bddbe112014-08-28 05:29:321113 command_updater_.UpdateCommandEnabled(
1114 IDC_SHOW_BOOKMARK_BAR,
1115 browser_defaults::bookmarks_enabled && !profile()->IsGuestSession() &&
mlerman7831f57d2015-05-25 11:40:151116 !profile()->IsSystemProfile() &&
tfarina3bddbe112014-08-28 05:29:321117 !profile()->GetPrefs()->IsManagedPreference(
1118 bookmarks::prefs::kShowBookmarkBar) &&
1119 IsShowingMainUI());
[email protected]5d98294912012-06-27 22:57:401120}
1121
[email protected]9ec3ea5b2012-12-03 18:14:301122void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
Ivan Sandrk9669d0e2017-12-15 23:50:201123 if (is_locked_fullscreen_)
1124 return;
1125
[email protected]9ec3ea5b2012-12-03 18:14:301126 UpdateSaveAsState();
[email protected]05454532013-01-22 21:09:081127 UpdateOpenFileState(&command_updater_);
[email protected]9ec3ea5b2012-12-03 18:14:301128}
1129
[email protected]32dfede2013-08-25 15:48:251130void BrowserCommandController::UpdateCommandsForFullscreenMode() {
Ivan Sandrk9669d0e2017-12-15 23:50:201131 if (is_locked_fullscreen_)
1132 return;
1133
zijiehe3c7af992017-02-12 20:59:401134 const bool is_fullscreen = window() && window()->IsFullscreen();
1135 const bool show_main_ui = IsShowingMainUI();
1136 const bool main_not_fullscreen = show_main_ui && !is_fullscreen;
[email protected]5d98294912012-06-27 22:57:401137
1138 // Navigation commands
1139 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1140
1141 // Window management commands
1142 command_updater_.UpdateCommandEnabled(
1143 IDC_SHOW_AS_TAB,
zijiehe3c7af992017-02-12 20:59:401144 !browser_->is_type_tabbed() && !is_fullscreen);
[email protected]5d98294912012-06-27 22:57:401145
1146 // Focus various bits of UI
1147 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
1148 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui);
1149 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
1150 command_updater_.UpdateCommandEnabled(
1151 IDC_FOCUS_MENU_BAR, main_not_fullscreen);
1152 command_updater_.UpdateCommandEnabled(
1153 IDC_FOCUS_NEXT_PANE, main_not_fullscreen);
1154 command_updater_.UpdateCommandEnabled(
1155 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen);
1156 command_updater_.UpdateCommandEnabled(
1157 IDC_FOCUS_BOOKMARKS, main_not_fullscreen);
[email protected]822ca8c62013-04-19 00:49:151158 command_updater_.UpdateCommandEnabled(
David Tsengc0b1b642018-01-24 07:12:271159 IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY, main_not_fullscreen);
[email protected]5d98294912012-06-27 22:57:401160
1161 // Show various bits of UI
1162 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431163#if defined(GOOGLE_CHROME_BUILD)
[email protected]5d98294912012-06-27 22:57:401164 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431165#endif
estade8c0780f2015-08-21 23:36:411166 UpdateShowSyncState(show_main_ui);
[email protected]5d98294912012-06-27 22:57:401167
[email protected]5d98294912012-06-27 22:57:401168 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
1169 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
1170 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
1171 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
primianod3a81ab2016-01-25 22:21:151172
1173 if (base::debug::IsProfilingSupported())
1174 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
[email protected]5d98294912012-06-27 22:57:401175
[email protected]aeafc3852014-04-29 16:51:291176#if !defined(OS_MACOSX)
zijiehe3c7af992017-02-12 20:59:401177 // Disable toggling into fullscreen mode if disallowed by pref.
1178 const bool fullscreen_enabled = is_fullscreen ||
1179 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed);
1180#else
1181 const bool fullscreen_enabled = true;
[email protected]00a1cc5b2012-11-07 13:44:511182#endif
1183
1184 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled);
spqchanb8ffc7d2015-11-17 01:17:211185 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR,
1186 fullscreen_enabled);
[email protected]5d98294912012-06-27 22:57:401187
1188 UpdateCommandsForBookmarkBar();
zijiehedb473d552017-02-24 01:13:411189 UpdateCommandsForIncognitoAvailability();
Alan Cutter167dfe82018-04-11 09:06:001190 UpdateCommandsForHostedAppAvailability();
1191}
1192
1193void BrowserCommandController::UpdateCommandsForHostedAppAvailability() {
1194 bool has_toolbar =
1195 browser_->is_type_tabbed() ||
1196 extensions::HostedAppBrowserController::IsForExperimentalHostedAppBrowser(
1197 browser_);
1198 if (window() && window()->ShouldHideUIForFullscreen())
1199 has_toolbar = false;
1200 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, has_toolbar);
1201 command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE, has_toolbar);
1202 command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE, has_toolbar);
1203 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, has_toolbar);
[email protected]5d98294912012-06-27 22:57:401204}
1205
Ivan Sandrk9669d0e2017-12-15 23:50:201206#if defined(OS_CHROMEOS)
1207namespace {
1208
1209#if DCHECK_IS_ON()
1210// Makes sure that all commands that are not whitelisted are disabled. DCHECKs
1211// otherwise. Compiled only in debug mode.
1212void NonWhitelistedCommandsAreDisabled(CommandUpdaterImpl* command_updater) {
1213 constexpr int kWhitelistedIds[] = {
1214 IDC_CUT, IDC_COPY, IDC_PASTE,
1215 IDC_FIND, IDC_FIND_NEXT, IDC_FIND_PREVIOUS,
1216 IDC_ZOOM_PLUS, IDC_ZOOM_NORMAL, IDC_ZOOM_MINUS,
1217 };
1218
1219 // Go through all the command ids, skip the whitelisted ones.
1220 for (int id : command_updater->GetAllIds()) {
1221 if (std::find(std::begin(kWhitelistedIds), std::end(kWhitelistedIds), id)
1222 != std::end(kWhitelistedIds)) {
1223 continue;
1224 }
1225 DCHECK(!command_updater->IsCommandEnabled(id));
1226 }
1227}
1228#endif
1229
1230} // namespace
1231
1232void BrowserCommandController::UpdateCommandsForLockedFullscreenMode() {
Ivan Sandrk9669d0e2017-12-15 23:50:201233 bool is_locked_fullscreen = ash::IsWindowTrustedPinned(browser_->window());
1234 // Sanity check to make sure this function is called only on state change.
1235 DCHECK_NE(is_locked_fullscreen, is_locked_fullscreen_);
1236 if (is_locked_fullscreen == is_locked_fullscreen_)
1237 return;
1238 is_locked_fullscreen_ = is_locked_fullscreen;
1239
1240 if (is_locked_fullscreen_) {
1241 command_updater_.DisableAllCommands();
1242 // Update the state of whitelisted commands:
1243 // IDC_CUT/IDC_COPY/IDC_PASTE,
1244 UpdateCommandsForContentRestrictionState();
1245 // IDC_FIND/IDC_FIND_NEXT/IDC_FIND_PREVIOUS,
1246 UpdateCommandsForFind();
1247 // IDC_ZOOM_PLUS/IDC_ZOOM_NORMAL/IDC_ZOOM_MINUS.
1248 UpdateCommandsForZoomState();
1249 // All other commands will be disabled (there is an early return in their
1250 // corresponding UpdateCommandsFor* functions).
1251#if DCHECK_IS_ON()
1252 NonWhitelistedCommandsAreDisabled(&command_updater_);
1253#endif
1254 } else {
1255 // Do an init call to re-initialize command state after the
1256 // DisableAllCommands.
1257 InitCommandState();
1258 }
1259}
1260#endif
1261
[email protected]5d98294912012-06-27 22:57:401262void BrowserCommandController::UpdatePrintingState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201263 if (is_locked_fullscreen_)
1264 return;
1265
[email protected]d53e4032012-06-29 18:58:341266 bool print_enabled = CanPrint(browser_);
1267 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
Lei Zhang48a4a5262018-04-17 20:18:441268#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:551269 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT,
1270 CanBasicPrint(browser_));
Lei Zhang48a4a5262018-04-17 20:18:441271#endif
[email protected]5d98294912012-06-27 22:57:401272}
1273
1274void BrowserCommandController::UpdateSaveAsState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201275 if (is_locked_fullscreen_)
1276 return;
1277
[email protected]5d98294912012-06-27 22:57:401278 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_));
1279}
1280
estade8c0780f2015-08-21 23:36:411281void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) {
Ivan Sandrk9669d0e2017-12-15 23:50:201282 if (is_locked_fullscreen_)
1283 return;
1284
estade8c0780f2015-08-21 23:36:411285 command_updater_.UpdateCommandEnabled(
1286 IDC_SHOW_SYNC_SETUP, show_main_ui && pref_signin_allowed_.GetValue());
1287}
1288
[email protected]05454532013-01-22 21:09:081289// static
1290void BrowserCommandController::UpdateOpenFileState(
1291 CommandUpdater* command_updater) {
[email protected]5d98294912012-06-27 22:57:401292 bool enabled = true;
1293 PrefService* local_state = g_browser_process->local_state();
1294 if (local_state)
1295 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs);
1296
[email protected]05454532013-01-22 21:09:081297 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled);
[email protected]5d98294912012-06-27 22:57:401298}
1299
1300void BrowserCommandController::UpdateReloadStopState(bool is_loading,
1301 bool force) {
Ivan Sandrk9669d0e2017-12-15 23:50:201302 if (is_locked_fullscreen_)
1303 return;
1304
[email protected]5d98294912012-06-27 22:57:401305 window()->UpdateReloadStopState(is_loading, force);
1306 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
1307}
1308
[email protected]2e9369e2014-08-15 09:12:531309void BrowserCommandController::UpdateTabRestoreCommandState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201310 if (is_locked_fullscreen_)
1311 return;
1312
blundell74001adc2015-09-18 11:04:251313 sessions::TabRestoreService* tab_restore_service =
[email protected]2e9369e2014-08-15 09:12:531314 TabRestoreServiceFactory::GetForProfile(profile());
1315 // The command is enabled if the service hasn't loaded yet to trigger loading.
1316 // The command is updated once the load completes.
1317 command_updater_.UpdateCommandEnabled(
1318 IDC_RESTORE_TAB,
1319 tab_restore_service &&
1320 (!tab_restore_service->IsLoaded() ||
1321 GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE));
1322}
1323
[email protected]3cac87232012-11-20 01:48:271324void BrowserCommandController::UpdateCommandsForFind() {
1325 TabStripModel* model = browser_->tab_strip_model();
1326 bool enabled = !model->IsTabBlocked(model->active_index()) &&
1327 !browser_->is_devtools();
1328
1329 command_updater_.UpdateCommandEnabled(IDC_FIND, enabled);
1330 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled);
1331 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled);
1332}
1333
apacible45cbfc92015-09-28 22:45:411334void BrowserCommandController::UpdateCommandsForMediaRouter() {
Ivan Sandrk9669d0e2017-12-15 23:50:201335 if (is_locked_fullscreen_)
1336 return;
1337
apacible45cbfc92015-09-28 22:45:411338 command_updater_.UpdateCommandEnabled(IDC_ROUTE_MEDIA,
1339 CanRouteMedia(browser_));
1340}
1341
[email protected]409ea2972012-11-10 19:54:431342void BrowserCommandController::AddInterstitialObservers(WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071343 interstitial_observers_.push_back(new InterstitialObserver(this, contents));
[email protected]5d98294912012-06-27 22:57:401344}
1345
1346void BrowserCommandController::RemoveInterstitialObservers(
[email protected]e89cfcb2012-11-11 14:47:241347 WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071348 for (size_t i = 0; i < interstitial_observers_.size(); i++) {
1349 if (interstitial_observers_[i]->web_contents() != contents)
1350 continue;
1351
1352 delete interstitial_observers_[i];
1353 interstitial_observers_.erase(interstitial_observers_.begin() + i);
1354 return;
1355 }
[email protected]5d98294912012-06-27 22:57:401356}
1357
1358BrowserWindow* BrowserCommandController::window() {
1359 return browser_->window();
1360}
1361
1362Profile* BrowserCommandController::profile() {
1363 return browser_->profile();
1364}
1365
[email protected]5d98294912012-06-27 22:57:401366} // namespace chrome