blob: 2f091179823a64b2241e2cdec745f7a3ee40906f [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"
21#include "chrome/browser/extensions/extension_service.h"
benwells39f23ae2014-08-27 08:01:5222#include "chrome/browser/extensions/extension_util.h"
[email protected]2e9d79f2013-08-16 05:45:5623#include "chrome/browser/lifetime/application_lifetime.h"
Pavol Markodebb0ff2018-05-07 18:35:4124#include "chrome/browser/policy/developer_tools_policy_handler.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;
645 case IDC_VIEW_INCOMPATIBILITIES:
646 ShowConflicts(browser_);
647 break;
648 case IDC_HELP_PAGE_VIA_KEYBOARD:
649 ShowHelp(browser_, HELP_SOURCE_KEYBOARD);
650 break;
651 case IDC_HELP_PAGE_VIA_MENU:
652 ShowHelp(browser_, HELP_SOURCE_MENU);
653 break;
Bret Sepulveda2d018662017-05-18 21:31:48654 case IDC_SHOW_BETA_FORUM:
655 ShowBetaForum(browser_);
656 break;
estade8c0780f2015-08-21 23:36:41657 case IDC_SHOW_SIGNIN:
gogerald71bf6c902015-12-08 00:49:37658 ShowBrowserSigninOrSettings(
659 browser_, signin_metrics::AccessPoint::ACCESS_POINT_MENU);
estade8c0780f2015-08-21 23:36:41660 break;
[email protected]6bd370b2014-05-28 14:19:47661 case IDC_DISTILL_PAGE:
662 DistillCurrentPage(browser_);
663 break;
apacible45cbfc92015-09-28 22:45:41664 case IDC_ROUTE_MEDIA:
665 RouteMedia(browser_);
666 break;
Tommy Steimelc4477982017-11-29 18:07:18667 case IDC_WINDOW_MUTE_SITE:
668 MuteSite(browser_);
ellyjones0101ba02017-05-19 15:50:26669 break;
670 case IDC_WINDOW_PIN_TAB:
671 PinTab(browser_);
672 break;
[email protected]5d98294912012-06-27 22:57:40673
Christopher Lam0dbac2b2017-11-14 07:12:10674 // Hosted App commands
675 case IDC_COPY_URL:
676 CopyURL(browser_);
677 break;
678 case IDC_OPEN_IN_CHROME:
679 OpenInChrome(browser_);
680 break;
681 case IDC_SITE_SETTINGS:
682 ShowSiteSettings(
683 browser_,
684 browser_->tab_strip_model()->GetActiveWebContents()->GetVisibleURL());
685 break;
Alan Cutter0c3132302018-02-21 05:09:02686 case IDC_HOSTED_APP_MENU_APP_INFO:
687 ShowPageInfoDialog(browser_->tab_strip_model()->GetActiveWebContents(),
Alan Cutter689f89a2018-03-08 05:09:54688 bubble_anchor_util::kAppMenuButton);
Christopher Lam86b52712017-12-04 01:58:33689 break;
Christopher Lam0dbac2b2017-11-14 07:12:10690
[email protected]5d98294912012-06-27 22:57:40691 default:
692 LOG(WARNING) << "Received Unimplemented Command: " << id;
693 break;
694 }
Ivan Sandrk9669d0e2017-12-15 23:50:20695
696 return true;
697}
698
699void BrowserCommandController::AddCommandObserver(int id,
700 CommandObserver* observer) {
701 command_updater_.AddCommandObserver(id, observer);
702}
703
704void BrowserCommandController::RemoveCommandObserver(
705 int id, CommandObserver* observer) {
706 command_updater_.RemoveCommandObserver(id, observer);
707}
708
709void BrowserCommandController::RemoveCommandObserver(
710 CommandObserver* observer) {
711 command_updater_.RemoveCommandObserver(observer);
712}
713
714bool BrowserCommandController::UpdateCommandEnabled(int id, bool state) {
715 if (is_locked_fullscreen_)
716 return false;
717
718 return command_updater_.UpdateCommandEnabled(id, state);
[email protected]5d98294912012-06-27 22:57:40719}
720
estade8c0780f2015-08-21 23:36:41721////////////////////////////////////////////////////////////////////////////////
722// BrowserCommandController, SigninPrefObserver implementation:
723
724void BrowserCommandController::OnSigninAllowedPrefChange() {
725 // For unit tests, we don't have a window.
726 if (!window())
727 return;
728 UpdateShowSyncState(IsShowingMainUI());
729}
730
[email protected]5d98294912012-06-27 22:57:40731// BrowserCommandController, TabStripModelObserver implementation:
732
pmonette9119e492016-09-20 22:14:55733void BrowserCommandController::TabInsertedAt(TabStripModel* tab_strip_model,
734 WebContents* contents,
[email protected]5d98294912012-06-27 22:57:40735 int index,
736 bool foreground) {
737 AddInterstitialObservers(contents);
738}
739
[email protected]e89cfcb2012-11-11 14:47:24740void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) {
[email protected]5d98294912012-06-27 22:57:40741 RemoveInterstitialObservers(contents);
742}
743
744void BrowserCommandController::TabReplacedAt(TabStripModel* tab_strip_model,
[email protected]b624ddc2012-11-15 18:04:13745 WebContents* old_contents,
746 WebContents* new_contents,
[email protected]5d98294912012-06-27 22:57:40747 int index) {
[email protected]b624ddc2012-11-15 18:04:13748 RemoveInterstitialObservers(old_contents);
749 AddInterstitialObservers(new_contents);
[email protected]5d98294912012-06-27 22:57:40750}
751
[email protected]3cac87232012-11-20 01:48:27752void BrowserCommandController::TabBlockedStateChanged(
753 content::WebContents* contents,
754 int index) {
755 PrintingStateChanged();
756 FullscreenStateChanged();
757 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:41758 UpdateCommandsForMediaRouter();
[email protected]3cac87232012-11-20 01:48:27759}
760
[email protected]5d98294912012-06-27 22:57:40761////////////////////////////////////////////////////////////////////////////////
762// BrowserCommandController, TabRestoreServiceObserver implementation:
763
764void BrowserCommandController::TabRestoreServiceChanged(
blundell74001adc2015-09-18 11:04:25765 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53766 UpdateTabRestoreCommandState();
[email protected]5d98294912012-06-27 22:57:40767}
768
769void BrowserCommandController::TabRestoreServiceDestroyed(
blundell74001adc2015-09-18 11:04:25770 sessions::TabRestoreService* service) {
[email protected]5d98294912012-06-27 22:57:40771 service->RemoveObserver(this);
772}
773
[email protected]2e9369e2014-08-15 09:12:53774void BrowserCommandController::TabRestoreServiceLoaded(
blundell74001adc2015-09-18 11:04:25775 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53776 UpdateTabRestoreCommandState();
777}
778
[email protected]5d98294912012-06-27 22:57:40779////////////////////////////////////////////////////////////////////////////////
[email protected]5d98294912012-06-27 22:57:40780// BrowserCommandController, private:
781
[email protected]20ca0382013-02-28 19:50:07782class BrowserCommandController::InterstitialObserver
783 : public content::WebContentsObserver {
784 public:
785 InterstitialObserver(BrowserCommandController* controller,
786 content::WebContents* web_contents)
787 : WebContentsObserver(web_contents),
788 controller_(controller) {
789 }
790
dcheng5dd5ff62014-10-21 12:42:38791 void DidAttachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07792 controller_->UpdateCommandsForTabState();
793 }
794
dcheng5dd5ff62014-10-21 12:42:38795 void DidDetachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07796 controller_->UpdateCommandsForTabState();
797 }
798
799 private:
800 BrowserCommandController* controller_;
801
802 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver);
803};
804
[email protected]6a414ff2013-02-27 08:22:54805bool BrowserCommandController::IsShowingMainUI() {
806 bool should_hide_ui = window() && window()->ShouldHideUIForFullscreen();
807 return browser_->is_type_tabbed() && !should_hide_ui;
[email protected]5d98294912012-06-27 22:57:40808}
809
810void BrowserCommandController::InitCommandState() {
811 // All browser commands whose state isn't set automagically some other way
812 // (like Back & Forward with initial page load) must have their state
813 // initialized here, otherwise they will be forever disabled.
814
Ivan Sandrk9669d0e2017-12-15 23:50:20815 if (is_locked_fullscreen_)
816 return;
817
[email protected]5d98294912012-06-27 22:57:40818 // Navigation commands
819 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true);
toyoshim7dad4b1182016-04-01 14:28:05820 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE, true);
[email protected]58e29032012-08-06 20:19:57821 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, true);
[email protected]5d98294912012-06-27 22:57:40822
823 // Window management commands
824 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true);
825 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true);
826 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true);
827 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true);
[email protected]2e9369e2014-08-15 09:12:53828 UpdateTabRestoreCommandState();
[email protected]d28d3782013-02-26 16:31:55829 command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
[email protected]5d98294912012-06-27 22:57:40830 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true);
[email protected]d12cc5e2013-10-19 18:25:06831#if defined(OS_CHROMEOS)
James Cook934abaf2017-09-19 22:21:58832 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
[email protected]d12cc5e2013-10-19 18:25:06833 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_2, true);
834 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_3, true);
835#endif
[email protected]893124a22014-04-15 00:45:28836#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15837 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
838 command_updater_.UpdateCommandEnabled(IDC_MAXIMIZE_WINDOW, true);
839 command_updater_.UpdateCommandEnabled(IDC_RESTORE_WINDOW, true);
[email protected]af97be4c62014-02-13 14:43:34840 command_updater_.UpdateCommandEnabled(IDC_USE_SYSTEM_TITLE_BAR, true);
841#endif
Alan Cutter09965802018-03-27 07:25:29842 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW, true);
[email protected]5d98294912012-06-27 22:57:40843
844 // Page-related commands
845 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true);
[email protected]4bee4432014-05-05 13:11:41846 command_updater_.UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE, true);
[email protected]5d98294912012-06-27 22:57:40847
848 // Zoom
849 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true);
850 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true);
[email protected]d93dbd12014-08-04 23:42:53851 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, false);
[email protected]5d98294912012-06-27 22:57:40852 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
853
854 // Show various bits of UI
mlerman7831f57d2015-05-25 11:40:15855 const bool guest_session = profile()->IsGuestSession() ||
856 profile()->IsSystemProfile();
857 DCHECK(!profile()->IsSystemProfile())
858 << "Ought to never have browser for the system profile.";
[email protected]338416c02014-05-13 16:47:06859 const bool normal_window = browser_->is_type_tabbed();
[email protected]05454532013-01-22 21:09:08860 UpdateOpenFileState(&command_updater_);
[email protected]5d98294912012-06-27 22:57:40861 UpdateCommandsForDevTools();
862 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager());
[email protected]338416c02014-05-13 16:47:06863 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session);
[email protected]5d98294912012-06-27 22:57:40864 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
[email protected]674b65672014-06-02 23:21:56865 command_updater_.UpdateCommandEnabled(IDC_HELP_MENU, true);
[email protected]5d98294912012-06-27 22:57:40866 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
867 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
Bret Sepulveda2d018662017-05-18 21:31:48868 command_updater_.UpdateCommandEnabled(IDC_SHOW_BETA_FORUM, true);
[email protected]338416c02014-05-13 16:47:06869 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session);
[email protected]2f1acc212012-11-13 10:43:51870 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU,
[email protected]338416c02014-05-13 16:47:06871 !guest_session &&
[email protected]2f1acc212012-11-13 10:43:51872 !profile()->IsOffTheRecord());
tsergeant341a8272017-04-18 03:54:33873 command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA,
874 !guest_session);
[email protected]39d47592014-01-10 21:42:45875#if defined(OS_CHROMEOS)
caelyn4e4e08a2015-02-04 21:27:49876 command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true);
[email protected]338416c02014-05-13 16:47:06877#else
878 // Chrome OS uses the system tray menu to handle multi-profiles.
anthonyvd7dc985da2015-03-23 16:53:19879 if (normal_window && (guest_session || !profile()->IsOffTheRecord())) {
[email protected]338416c02014-05-13 16:47:06880 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
anthonyvd7dc985da2015-03-23 16:53:19881 }
[email protected]39d47592014-01-10 21:42:45882#endif
[email protected]5d98294912012-06-27 22:57:40883
estade8c0780f2015-08-21 23:36:41884 UpdateShowSyncState(true);
885
[email protected]5d98294912012-06-27 22:57:40886 // Navigation commands
[email protected]c9f983d2014-02-05 09:00:24887 command_updater_.UpdateCommandEnabled(
888 IDC_HOME,
benwellsc431c0ae2015-01-27 22:04:06889 normal_window ||
890 (extensions::util::IsNewBookmarkAppsEnabled() && browser_->is_app()));
[email protected]5d98294912012-06-27 22:57:40891
Christopher Lam0dbac2b2017-11-14 07:12:10892 const bool is_experimental_hosted_app =
893 extensions::HostedAppBrowserController::IsForExperimentalHostedAppBrowser(
894 browser_);
895 // Hosted app browser commands.
896 command_updater_.UpdateCommandEnabled(IDC_COPY_URL,
897 is_experimental_hosted_app);
898 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_CHROME,
899 is_experimental_hosted_app);
900 command_updater_.UpdateCommandEnabled(IDC_SITE_SETTINGS,
901 is_experimental_hosted_app);
Alan Cutter0c3132302018-02-21 05:09:02902 command_updater_.UpdateCommandEnabled(IDC_HOSTED_APP_MENU_APP_INFO,
Christopher Lam86b52712017-12-04 01:58:33903 is_experimental_hosted_app);
Christopher Lam0dbac2b2017-11-14 07:12:10904
[email protected]5d98294912012-06-27 22:57:40905 // Window management commands
[email protected]5d98294912012-06-27 22:57:40906 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window);
907 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB,
908 normal_window);
909 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window);
910 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window);
911 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window);
912 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window);
913 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window);
914 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window);
915 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window);
916 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window);
917 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window);
918 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window);
919 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window);
[email protected]5d98294912012-06-27 22:57:40920
[email protected]338416c02014-05-13 16:47:06921 // These are always enabled; the menu determines their menu item visibility.
[email protected]5d98294912012-06-27 22:57:40922 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
923 command_updater_.UpdateCommandEnabled(IDC_VIEW_INCOMPATIBILITIES, true);
924
[email protected]6bd370b2014-05-28 14:19:47925 // Distill current page.
926 command_updater_.UpdateCommandEnabled(
avi556c05022014-12-22 23:31:43927 IDC_DISTILL_PAGE, base::CommandLine::ForCurrentProcess()->HasSwitch(
928 switches::kEnableDomDistiller));
[email protected]6bd370b2014-05-28 14:19:47929
Tommy Steimelc4477982017-11-29 18:07:18930 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE, normal_window);
ellyjones0101ba02017-05-19 15:50:26931 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, normal_window);
932
[email protected]338416c02014-05-13 16:47:06933 // Initialize other commands whose state changes based on various conditions.
[email protected]32dfede2013-08-25 15:48:25934 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40935 UpdateCommandsForContentRestrictionState();
[email protected]5d98294912012-06-27 22:57:40936 UpdateCommandsForBookmarkEditing();
[email protected]5d98294912012-06-27 22:57:40937 UpdateCommandsForIncognitoAvailability();
938}
939
[email protected]05454532013-01-22 21:09:08940// static
941void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
942 CommandUpdater* command_updater,
943 Profile* profile) {
mlermane01e6de2014-09-29 19:26:47944 const bool guest_session = profile->IsGuestSession();
945 // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession().
[email protected]5d98294912012-06-27 22:57:40946 IncognitoModePrefs::Availability incognito_availability =
[email protected]05454532013-01-22 21:09:08947 IncognitoModePrefs::GetAvailability(profile->GetPrefs());
948 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40949 IDC_NEW_WINDOW,
950 incognito_availability != IncognitoModePrefs::FORCED);
[email protected]05454532013-01-22 21:09:08951 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40952 IDC_NEW_INCOGNITO_WINDOW,
mlermane01e6de2014-09-29 19:26:47953 incognito_availability != IncognitoModePrefs::DISABLED && !guest_session);
[email protected]5d98294912012-06-27 22:57:40954
[email protected]57b25292014-05-01 16:31:06955 const bool forced_incognito =
956 incognito_availability == IncognitoModePrefs::FORCED ||
957 guest_session; // Guest always runs in Incognito mode.
[email protected]05454532013-01-22 21:09:08958 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40959 IDC_SHOW_BOOKMARK_MANAGER,
[email protected]57b25292014-05-01 16:31:06960 browser_defaults::bookmarks_enabled && !forced_incognito);
[email protected]03d25812014-06-22 19:41:55961 ExtensionService* extension_service =
962 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]57b25292014-05-01 16:31:06963 const bool enable_extensions =
[email protected]5d98294912012-06-27 22:57:40964 extension_service && extension_service->extensions_enabled();
[email protected]5d98294912012-06-27 22:57:40965
[email protected]57b25292014-05-01 16:31:06966 // Bookmark manager and settings page/subpages are forced to open in normal
967 // mode. For this reason we disable these commands when incognito is forced.
968 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
969 enable_extensions && !forced_incognito);
970
971 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito);
972 command_updater->UpdateCommandEnabled(IDC_OPTIONS,
973 !forced_incognito || guest_session);
estade8c0780f2015-08-21 23:36:41974 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito);
[email protected]05454532013-01-22 21:09:08975}
976
977void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
Ivan Sandrk9669d0e2017-12-15 23:50:20978 if (is_locked_fullscreen_)
979 return;
980
[email protected]05454532013-01-22 21:09:08981 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile());
982
[email protected]6a414ff2013-02-27 08:22:54983 if (!IsShowingMainUI()) {
[email protected]05454532013-01-22 21:09:08984 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false);
985 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false);
986 }
[email protected]5d98294912012-06-27 22:57:40987}
988
989void BrowserCommandController::UpdateCommandsForTabState() {
Ivan Sandrk9669d0e2017-12-15 23:50:20990 if (is_locked_fullscreen_)
991 return;
992
[email protected]617ee962013-01-29 20:49:12993 WebContents* current_web_contents =
994 browser_->tab_strip_model()->GetActiveWebContents();
[email protected]1c5119c2012-09-19 00:08:57995 if (!current_web_contents) // May be NULL during tab restore.
[email protected]5d98294912012-06-27 22:57:40996 return;
[email protected]5d98294912012-06-27 22:57:40997
998 // Navigation commands
[email protected]5d98294912012-06-27 22:57:40999 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_));
[email protected]5d98294912012-06-27 22:57:401000 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_));
1001 command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_));
toyoshim7dad4b1182016-04-01 14:28:051002 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE,
[email protected]5d98294912012-06-27 22:57:401003 CanReload(browser_));
[email protected]58e29032012-08-06 20:19:571004 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE,
1005 CanReload(browser_));
[email protected]5d98294912012-06-27 22:57:401006
1007 // Window management commands
1008 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB,
1009 !browser_->is_app() && CanDuplicateTab(browser_));
Tommy Steimelc4477982017-11-29 18:07:181010 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE,
ellyjones0101ba02017-05-19 15:50:261011 !browser_->is_app());
1012 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB,
1013 !browser_->is_app());
[email protected]5d98294912012-06-27 22:57:401014
1015 // Page-related commands
1016 window()->SetStarredState(
[email protected]1c5119c2012-09-19 00:08:571017 BookmarkTabHelper::FromWebContents(current_web_contents)->is_starred());
[email protected]5423c372012-08-22 05:50:161018 window()->ZoomChangedForActiveTab(false);
[email protected]5d98294912012-06-27 22:57:401019 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
1020 CanViewSource(browser_));
1021 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION,
1022 CanEmailPageLocation(browser_));
1023 if (browser_->is_devtools())
1024 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false);
1025
[email protected]92086542014-04-08 08:45:291026 command_updater_.UpdateCommandEnabled(IDC_CREATE_HOSTED_APP,
1027 CanCreateBookmarkApp(browser_));
[email protected]5d98294912012-06-27 22:57:401028
[email protected]9b7ab882012-09-10 23:46:361029 command_updater_.UpdateCommandEnabled(
1030 IDC_TOGGLE_REQUEST_TABLET_SITE,
1031 CanRequestTabletSite(current_web_contents));
1032
[email protected]5d98294912012-06-27 22:57:401033 UpdateCommandsForContentRestrictionState();
1034 UpdateCommandsForBookmarkEditing();
[email protected]3cac87232012-11-20 01:48:271035 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:411036 UpdateCommandsForMediaRouter();
[email protected]d93dbd12014-08-04 23:42:531037 // Update the zoom commands when an active tab is selected.
1038 UpdateCommandsForZoomState();
1039}
1040
1041void BrowserCommandController::UpdateCommandsForZoomState() {
1042 WebContents* contents =
1043 browser_->tab_strip_model()->GetActiveWebContents();
1044 if (!contents)
1045 return;
a.sarkar.arundaadc712015-02-26 05:39:081046 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS,
1047 CanZoomIn(contents));
1048 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL,
ccameronb7c1d6c2015-03-09 17:08:241049 CanResetZoom(contents));
a.sarkar.arundaadc712015-02-26 05:39:081050 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS,
1051 CanZoomOut(contents));
[email protected]5d98294912012-06-27 22:57:401052}
1053
1054void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
1055 int restrictions = GetContentRestrictions(browser_);
1056
1057 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011058 IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY));
[email protected]5d98294912012-06-27 22:57:401059 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011060 IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT));
[email protected]5d98294912012-06-27 22:57:401061 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011062 IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE));
[email protected]5d98294912012-06-27 22:57:401063 UpdateSaveAsState();
1064 UpdatePrintingState();
1065}
1066
1067void BrowserCommandController::UpdateCommandsForDevTools() {
Ivan Sandrk9669d0e2017-12-15 23:50:201068 if (is_locked_fullscreen_)
1069 return;
1070
Pavol Markodebb0ff2018-05-07 18:35:411071 using DTPH = policy::DeveloperToolsPolicyHandler;
1072 // TODO(pfeldman): Possibly implement handling for
1073 // Availability::kDisallowedForForceInstalledExtensions
1074 // (https://crbug.com/838146).
[email protected]5d98294912012-06-27 22:57:401075 bool dev_tools_enabled =
Pavol Markodebb0ff2018-05-07 18:35:411076 DTPH::GetDevToolsAvailability(profile()->GetPrefs()) !=
1077 DTPH::Availability::kDisallowed;
[email protected]5d98294912012-06-27 22:57:401078 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS,
1079 dev_tools_enabled);
1080 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE,
1081 dev_tools_enabled);
[email protected]2056c3192013-10-21 22:40:511082 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES,
1083 dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401084 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT,
1085 dev_tools_enabled);
[email protected]d16657c2012-09-03 14:25:101086 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE,
1087 dev_tools_enabled);
spqchan2c5d541e2017-10-25 07:07:111088#if defined(OS_MACOSX)
1089 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS,
1090 dev_tools_enabled);
1091#endif
[email protected]5d98294912012-06-27 22:57:401092}
1093
1094void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
Ivan Sandrk9669d0e2017-12-15 23:50:201095 if (is_locked_fullscreen_)
1096 return;
1097
[email protected]5d98294912012-06-27 22:57:401098 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE,
1099 CanBookmarkCurrentPage(browser_));
1100 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
1101 CanBookmarkAllTabs(browser_));
thestig5149d272014-10-30 07:25:291102#if defined(OS_WIN)
1103 command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN, true);
1104#endif
[email protected]5d98294912012-06-27 22:57:401105}
1106
1107void BrowserCommandController::UpdateCommandsForBookmarkBar() {
Ivan Sandrk9669d0e2017-12-15 23:50:201108 if (is_locked_fullscreen_)
1109 return;
1110
tfarina3bddbe112014-08-28 05:29:321111 command_updater_.UpdateCommandEnabled(
1112 IDC_SHOW_BOOKMARK_BAR,
1113 browser_defaults::bookmarks_enabled && !profile()->IsGuestSession() &&
mlerman7831f57d2015-05-25 11:40:151114 !profile()->IsSystemProfile() &&
tfarina3bddbe112014-08-28 05:29:321115 !profile()->GetPrefs()->IsManagedPreference(
1116 bookmarks::prefs::kShowBookmarkBar) &&
1117 IsShowingMainUI());
[email protected]5d98294912012-06-27 22:57:401118}
1119
[email protected]9ec3ea5b2012-12-03 18:14:301120void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
Ivan Sandrk9669d0e2017-12-15 23:50:201121 if (is_locked_fullscreen_)
1122 return;
1123
[email protected]9ec3ea5b2012-12-03 18:14:301124 UpdateSaveAsState();
[email protected]05454532013-01-22 21:09:081125 UpdateOpenFileState(&command_updater_);
[email protected]9ec3ea5b2012-12-03 18:14:301126}
1127
[email protected]32dfede2013-08-25 15:48:251128void BrowserCommandController::UpdateCommandsForFullscreenMode() {
Ivan Sandrk9669d0e2017-12-15 23:50:201129 if (is_locked_fullscreen_)
1130 return;
1131
zijiehe3c7af992017-02-12 20:59:401132 const bool is_fullscreen = window() && window()->IsFullscreen();
1133 const bool show_main_ui = IsShowingMainUI();
1134 const bool main_not_fullscreen = show_main_ui && !is_fullscreen;
[email protected]5d98294912012-06-27 22:57:401135
1136 // Navigation commands
1137 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1138
1139 // Window management commands
1140 command_updater_.UpdateCommandEnabled(
1141 IDC_SHOW_AS_TAB,
zijiehe3c7af992017-02-12 20:59:401142 !browser_->is_type_tabbed() && !is_fullscreen);
[email protected]5d98294912012-06-27 22:57:401143
1144 // Focus various bits of UI
1145 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
1146 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui);
1147 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
1148 command_updater_.UpdateCommandEnabled(
1149 IDC_FOCUS_MENU_BAR, main_not_fullscreen);
1150 command_updater_.UpdateCommandEnabled(
1151 IDC_FOCUS_NEXT_PANE, main_not_fullscreen);
1152 command_updater_.UpdateCommandEnabled(
1153 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen);
1154 command_updater_.UpdateCommandEnabled(
1155 IDC_FOCUS_BOOKMARKS, main_not_fullscreen);
[email protected]822ca8c62013-04-19 00:49:151156 command_updater_.UpdateCommandEnabled(
David Tsengc0b1b642018-01-24 07:12:271157 IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY, main_not_fullscreen);
[email protected]5d98294912012-06-27 22:57:401158
1159 // Show various bits of UI
1160 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431161#if defined(GOOGLE_CHROME_BUILD)
[email protected]5d98294912012-06-27 22:57:401162 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431163#endif
estade8c0780f2015-08-21 23:36:411164 UpdateShowSyncState(show_main_ui);
[email protected]5d98294912012-06-27 22:57:401165
[email protected]5d98294912012-06-27 22:57:401166 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
1167 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
1168 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
1169 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
primianod3a81ab2016-01-25 22:21:151170
1171 if (base::debug::IsProfilingSupported())
1172 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
[email protected]5d98294912012-06-27 22:57:401173
[email protected]aeafc3852014-04-29 16:51:291174#if !defined(OS_MACOSX)
zijiehe3c7af992017-02-12 20:59:401175 // Disable toggling into fullscreen mode if disallowed by pref.
1176 const bool fullscreen_enabled = is_fullscreen ||
1177 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed);
1178#else
1179 const bool fullscreen_enabled = true;
[email protected]00a1cc5b2012-11-07 13:44:511180#endif
1181
1182 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled);
spqchanb8ffc7d2015-11-17 01:17:211183 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR,
1184 fullscreen_enabled);
[email protected]5d98294912012-06-27 22:57:401185
1186 UpdateCommandsForBookmarkBar();
zijiehedb473d552017-02-24 01:13:411187 UpdateCommandsForIncognitoAvailability();
Alan Cutter167dfe82018-04-11 09:06:001188 UpdateCommandsForHostedAppAvailability();
1189}
1190
1191void BrowserCommandController::UpdateCommandsForHostedAppAvailability() {
1192 bool has_toolbar =
1193 browser_->is_type_tabbed() ||
1194 extensions::HostedAppBrowserController::IsForExperimentalHostedAppBrowser(
1195 browser_);
1196 if (window() && window()->ShouldHideUIForFullscreen())
1197 has_toolbar = false;
1198 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, has_toolbar);
1199 command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE, has_toolbar);
1200 command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE, has_toolbar);
1201 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, has_toolbar);
[email protected]5d98294912012-06-27 22:57:401202}
1203
Ivan Sandrk9669d0e2017-12-15 23:50:201204#if defined(OS_CHROMEOS)
1205namespace {
1206
1207#if DCHECK_IS_ON()
1208// Makes sure that all commands that are not whitelisted are disabled. DCHECKs
1209// otherwise. Compiled only in debug mode.
1210void NonWhitelistedCommandsAreDisabled(CommandUpdaterImpl* command_updater) {
1211 constexpr int kWhitelistedIds[] = {
1212 IDC_CUT, IDC_COPY, IDC_PASTE,
1213 IDC_FIND, IDC_FIND_NEXT, IDC_FIND_PREVIOUS,
1214 IDC_ZOOM_PLUS, IDC_ZOOM_NORMAL, IDC_ZOOM_MINUS,
1215 };
1216
1217 // Go through all the command ids, skip the whitelisted ones.
1218 for (int id : command_updater->GetAllIds()) {
1219 if (std::find(std::begin(kWhitelistedIds), std::end(kWhitelistedIds), id)
1220 != std::end(kWhitelistedIds)) {
1221 continue;
1222 }
1223 DCHECK(!command_updater->IsCommandEnabled(id));
1224 }
1225}
1226#endif
1227
1228} // namespace
1229
1230void BrowserCommandController::UpdateCommandsForLockedFullscreenMode() {
Ivan Sandrk9669d0e2017-12-15 23:50:201231 bool is_locked_fullscreen = ash::IsWindowTrustedPinned(browser_->window());
1232 // Sanity check to make sure this function is called only on state change.
1233 DCHECK_NE(is_locked_fullscreen, is_locked_fullscreen_);
1234 if (is_locked_fullscreen == is_locked_fullscreen_)
1235 return;
1236 is_locked_fullscreen_ = is_locked_fullscreen;
1237
1238 if (is_locked_fullscreen_) {
1239 command_updater_.DisableAllCommands();
1240 // Update the state of whitelisted commands:
1241 // IDC_CUT/IDC_COPY/IDC_PASTE,
1242 UpdateCommandsForContentRestrictionState();
1243 // IDC_FIND/IDC_FIND_NEXT/IDC_FIND_PREVIOUS,
1244 UpdateCommandsForFind();
1245 // IDC_ZOOM_PLUS/IDC_ZOOM_NORMAL/IDC_ZOOM_MINUS.
1246 UpdateCommandsForZoomState();
1247 // All other commands will be disabled (there is an early return in their
1248 // corresponding UpdateCommandsFor* functions).
1249#if DCHECK_IS_ON()
1250 NonWhitelistedCommandsAreDisabled(&command_updater_);
1251#endif
1252 } else {
1253 // Do an init call to re-initialize command state after the
1254 // DisableAllCommands.
1255 InitCommandState();
1256 }
1257}
1258#endif
1259
[email protected]5d98294912012-06-27 22:57:401260void BrowserCommandController::UpdatePrintingState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201261 if (is_locked_fullscreen_)
1262 return;
1263
[email protected]d53e4032012-06-29 18:58:341264 bool print_enabled = CanPrint(browser_);
1265 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
Lei Zhang48a4a5262018-04-17 20:18:441266#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:551267 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT,
1268 CanBasicPrint(browser_));
Lei Zhang48a4a5262018-04-17 20:18:441269#endif
[email protected]5d98294912012-06-27 22:57:401270}
1271
1272void BrowserCommandController::UpdateSaveAsState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201273 if (is_locked_fullscreen_)
1274 return;
1275
[email protected]5d98294912012-06-27 22:57:401276 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_));
1277}
1278
estade8c0780f2015-08-21 23:36:411279void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) {
Ivan Sandrk9669d0e2017-12-15 23:50:201280 if (is_locked_fullscreen_)
1281 return;
1282
estade8c0780f2015-08-21 23:36:411283 command_updater_.UpdateCommandEnabled(
1284 IDC_SHOW_SYNC_SETUP, show_main_ui && pref_signin_allowed_.GetValue());
1285}
1286
[email protected]05454532013-01-22 21:09:081287// static
1288void BrowserCommandController::UpdateOpenFileState(
1289 CommandUpdater* command_updater) {
[email protected]5d98294912012-06-27 22:57:401290 bool enabled = true;
1291 PrefService* local_state = g_browser_process->local_state();
1292 if (local_state)
1293 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs);
1294
[email protected]05454532013-01-22 21:09:081295 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled);
[email protected]5d98294912012-06-27 22:57:401296}
1297
1298void BrowserCommandController::UpdateReloadStopState(bool is_loading,
1299 bool force) {
Ivan Sandrk9669d0e2017-12-15 23:50:201300 if (is_locked_fullscreen_)
1301 return;
1302
[email protected]5d98294912012-06-27 22:57:401303 window()->UpdateReloadStopState(is_loading, force);
1304 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
1305}
1306
[email protected]2e9369e2014-08-15 09:12:531307void BrowserCommandController::UpdateTabRestoreCommandState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201308 if (is_locked_fullscreen_)
1309 return;
1310
blundell74001adc2015-09-18 11:04:251311 sessions::TabRestoreService* tab_restore_service =
[email protected]2e9369e2014-08-15 09:12:531312 TabRestoreServiceFactory::GetForProfile(profile());
1313 // The command is enabled if the service hasn't loaded yet to trigger loading.
1314 // The command is updated once the load completes.
1315 command_updater_.UpdateCommandEnabled(
1316 IDC_RESTORE_TAB,
1317 tab_restore_service &&
1318 (!tab_restore_service->IsLoaded() ||
1319 GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE));
1320}
1321
[email protected]3cac87232012-11-20 01:48:271322void BrowserCommandController::UpdateCommandsForFind() {
1323 TabStripModel* model = browser_->tab_strip_model();
1324 bool enabled = !model->IsTabBlocked(model->active_index()) &&
1325 !browser_->is_devtools();
1326
1327 command_updater_.UpdateCommandEnabled(IDC_FIND, enabled);
1328 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled);
1329 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled);
1330}
1331
apacible45cbfc92015-09-28 22:45:411332void BrowserCommandController::UpdateCommandsForMediaRouter() {
Ivan Sandrk9669d0e2017-12-15 23:50:201333 if (is_locked_fullscreen_)
1334 return;
1335
apacible45cbfc92015-09-28 22:45:411336 command_updater_.UpdateCommandEnabled(IDC_ROUTE_MEDIA,
1337 CanRouteMedia(browser_));
1338}
1339
[email protected]409ea2972012-11-10 19:54:431340void BrowserCommandController::AddInterstitialObservers(WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071341 interstitial_observers_.push_back(new InterstitialObserver(this, contents));
[email protected]5d98294912012-06-27 22:57:401342}
1343
1344void BrowserCommandController::RemoveInterstitialObservers(
[email protected]e89cfcb2012-11-11 14:47:241345 WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071346 for (size_t i = 0; i < interstitial_observers_.size(); i++) {
1347 if (interstitial_observers_[i]->web_contents() != contents)
1348 continue;
1349
1350 delete interstitial_observers_[i];
1351 interstitial_observers_.erase(interstitial_observers_.begin() + i);
1352 return;
1353 }
[email protected]5d98294912012-06-27 22:57:401354}
1355
1356BrowserWindow* BrowserCommandController::window() {
1357 return browser_->window();
1358}
1359
1360Profile* BrowserCommandController::profile() {
1361 return browser_->profile();
1362}
1363
[email protected]5d98294912012-06-27 22:57:401364} // namespace chrome