blob: 82b5af67fffde2ffd62f0a867eaaaf1cc13009df [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
erikchen12c65582018-05-14 17:26:04740void BrowserCommandController::TabDetachedAt(WebContents* contents,
741 int index,
742 bool was_active) {
[email protected]5d98294912012-06-27 22:57:40743 RemoveInterstitialObservers(contents);
744}
745
746void BrowserCommandController::TabReplacedAt(TabStripModel* tab_strip_model,
[email protected]b624ddc2012-11-15 18:04:13747 WebContents* old_contents,
748 WebContents* new_contents,
[email protected]5d98294912012-06-27 22:57:40749 int index) {
[email protected]b624ddc2012-11-15 18:04:13750 RemoveInterstitialObservers(old_contents);
751 AddInterstitialObservers(new_contents);
[email protected]5d98294912012-06-27 22:57:40752}
753
[email protected]3cac87232012-11-20 01:48:27754void BrowserCommandController::TabBlockedStateChanged(
755 content::WebContents* contents,
756 int index) {
757 PrintingStateChanged();
758 FullscreenStateChanged();
759 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:41760 UpdateCommandsForMediaRouter();
[email protected]3cac87232012-11-20 01:48:27761}
762
[email protected]5d98294912012-06-27 22:57:40763////////////////////////////////////////////////////////////////////////////////
764// BrowserCommandController, TabRestoreServiceObserver implementation:
765
766void BrowserCommandController::TabRestoreServiceChanged(
blundell74001adc2015-09-18 11:04:25767 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53768 UpdateTabRestoreCommandState();
[email protected]5d98294912012-06-27 22:57:40769}
770
771void BrowserCommandController::TabRestoreServiceDestroyed(
blundell74001adc2015-09-18 11:04:25772 sessions::TabRestoreService* service) {
[email protected]5d98294912012-06-27 22:57:40773 service->RemoveObserver(this);
774}
775
[email protected]2e9369e2014-08-15 09:12:53776void BrowserCommandController::TabRestoreServiceLoaded(
blundell74001adc2015-09-18 11:04:25777 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53778 UpdateTabRestoreCommandState();
779}
780
[email protected]5d98294912012-06-27 22:57:40781////////////////////////////////////////////////////////////////////////////////
[email protected]5d98294912012-06-27 22:57:40782// BrowserCommandController, private:
783
[email protected]20ca0382013-02-28 19:50:07784class BrowserCommandController::InterstitialObserver
785 : public content::WebContentsObserver {
786 public:
787 InterstitialObserver(BrowserCommandController* controller,
788 content::WebContents* web_contents)
789 : WebContentsObserver(web_contents),
790 controller_(controller) {
791 }
792
dcheng5dd5ff62014-10-21 12:42:38793 void DidAttachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07794 controller_->UpdateCommandsForTabState();
795 }
796
dcheng5dd5ff62014-10-21 12:42:38797 void DidDetachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07798 controller_->UpdateCommandsForTabState();
799 }
800
801 private:
802 BrowserCommandController* controller_;
803
804 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver);
805};
806
[email protected]6a414ff2013-02-27 08:22:54807bool BrowserCommandController::IsShowingMainUI() {
808 bool should_hide_ui = window() && window()->ShouldHideUIForFullscreen();
809 return browser_->is_type_tabbed() && !should_hide_ui;
[email protected]5d98294912012-06-27 22:57:40810}
811
812void BrowserCommandController::InitCommandState() {
813 // All browser commands whose state isn't set automagically some other way
814 // (like Back & Forward with initial page load) must have their state
815 // initialized here, otherwise they will be forever disabled.
816
Ivan Sandrk9669d0e2017-12-15 23:50:20817 if (is_locked_fullscreen_)
818 return;
819
[email protected]5d98294912012-06-27 22:57:40820 // Navigation commands
821 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true);
toyoshim7dad4b1182016-04-01 14:28:05822 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE, true);
[email protected]58e29032012-08-06 20:19:57823 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, true);
[email protected]5d98294912012-06-27 22:57:40824
825 // Window management commands
826 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true);
827 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true);
828 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true);
829 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true);
[email protected]2e9369e2014-08-15 09:12:53830 UpdateTabRestoreCommandState();
[email protected]d28d3782013-02-26 16:31:55831 command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
[email protected]5d98294912012-06-27 22:57:40832 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true);
[email protected]d12cc5e2013-10-19 18:25:06833#if defined(OS_CHROMEOS)
James Cook934abaf2017-09-19 22:21:58834 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
[email protected]d12cc5e2013-10-19 18:25:06835 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_2, true);
836 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_3, true);
837#endif
[email protected]893124a22014-04-15 00:45:28838#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15839 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
840 command_updater_.UpdateCommandEnabled(IDC_MAXIMIZE_WINDOW, true);
841 command_updater_.UpdateCommandEnabled(IDC_RESTORE_WINDOW, true);
[email protected]af97be4c62014-02-13 14:43:34842 command_updater_.UpdateCommandEnabled(IDC_USE_SYSTEM_TITLE_BAR, true);
843#endif
Alan Cutter09965802018-03-27 07:25:29844 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW, true);
[email protected]5d98294912012-06-27 22:57:40845
846 // Page-related commands
847 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true);
[email protected]4bee4432014-05-05 13:11:41848 command_updater_.UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE, true);
[email protected]5d98294912012-06-27 22:57:40849
850 // Zoom
851 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true);
852 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true);
[email protected]d93dbd12014-08-04 23:42:53853 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, false);
[email protected]5d98294912012-06-27 22:57:40854 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
855
856 // Show various bits of UI
mlerman7831f57d2015-05-25 11:40:15857 const bool guest_session = profile()->IsGuestSession() ||
858 profile()->IsSystemProfile();
859 DCHECK(!profile()->IsSystemProfile())
860 << "Ought to never have browser for the system profile.";
[email protected]338416c02014-05-13 16:47:06861 const bool normal_window = browser_->is_type_tabbed();
[email protected]05454532013-01-22 21:09:08862 UpdateOpenFileState(&command_updater_);
[email protected]5d98294912012-06-27 22:57:40863 UpdateCommandsForDevTools();
864 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager());
[email protected]338416c02014-05-13 16:47:06865 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session);
[email protected]5d98294912012-06-27 22:57:40866 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
[email protected]674b65672014-06-02 23:21:56867 command_updater_.UpdateCommandEnabled(IDC_HELP_MENU, true);
[email protected]5d98294912012-06-27 22:57:40868 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
869 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
Bret Sepulveda2d018662017-05-18 21:31:48870 command_updater_.UpdateCommandEnabled(IDC_SHOW_BETA_FORUM, true);
[email protected]338416c02014-05-13 16:47:06871 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session);
[email protected]2f1acc212012-11-13 10:43:51872 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU,
[email protected]338416c02014-05-13 16:47:06873 !guest_session &&
[email protected]2f1acc212012-11-13 10:43:51874 !profile()->IsOffTheRecord());
tsergeant341a8272017-04-18 03:54:33875 command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA,
876 !guest_session);
[email protected]39d47592014-01-10 21:42:45877#if defined(OS_CHROMEOS)
caelyn4e4e08a2015-02-04 21:27:49878 command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true);
[email protected]338416c02014-05-13 16:47:06879#else
880 // Chrome OS uses the system tray menu to handle multi-profiles.
anthonyvd7dc985da2015-03-23 16:53:19881 if (normal_window && (guest_session || !profile()->IsOffTheRecord())) {
[email protected]338416c02014-05-13 16:47:06882 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
anthonyvd7dc985da2015-03-23 16:53:19883 }
[email protected]39d47592014-01-10 21:42:45884#endif
[email protected]5d98294912012-06-27 22:57:40885
estade8c0780f2015-08-21 23:36:41886 UpdateShowSyncState(true);
887
[email protected]5d98294912012-06-27 22:57:40888 // Navigation commands
[email protected]c9f983d2014-02-05 09:00:24889 command_updater_.UpdateCommandEnabled(
890 IDC_HOME,
benwellsc431c0ae2015-01-27 22:04:06891 normal_window ||
892 (extensions::util::IsNewBookmarkAppsEnabled() && browser_->is_app()));
[email protected]5d98294912012-06-27 22:57:40893
Christopher Lam0dbac2b2017-11-14 07:12:10894 const bool is_experimental_hosted_app =
895 extensions::HostedAppBrowserController::IsForExperimentalHostedAppBrowser(
896 browser_);
897 // Hosted app browser commands.
898 command_updater_.UpdateCommandEnabled(IDC_COPY_URL,
899 is_experimental_hosted_app);
900 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_CHROME,
901 is_experimental_hosted_app);
902 command_updater_.UpdateCommandEnabled(IDC_SITE_SETTINGS,
903 is_experimental_hosted_app);
Alan Cutter0c3132302018-02-21 05:09:02904 command_updater_.UpdateCommandEnabled(IDC_HOSTED_APP_MENU_APP_INFO,
Christopher Lam86b52712017-12-04 01:58:33905 is_experimental_hosted_app);
Christopher Lam0dbac2b2017-11-14 07:12:10906
[email protected]5d98294912012-06-27 22:57:40907 // Window management commands
[email protected]5d98294912012-06-27 22:57:40908 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window);
909 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB,
910 normal_window);
911 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window);
912 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window);
913 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window);
914 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window);
915 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window);
916 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window);
917 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window);
918 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window);
919 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window);
920 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window);
921 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window);
[email protected]5d98294912012-06-27 22:57:40922
[email protected]338416c02014-05-13 16:47:06923 // These are always enabled; the menu determines their menu item visibility.
[email protected]5d98294912012-06-27 22:57:40924 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
925 command_updater_.UpdateCommandEnabled(IDC_VIEW_INCOMPATIBILITIES, true);
926
[email protected]6bd370b2014-05-28 14:19:47927 // Distill current page.
928 command_updater_.UpdateCommandEnabled(
avi556c05022014-12-22 23:31:43929 IDC_DISTILL_PAGE, base::CommandLine::ForCurrentProcess()->HasSwitch(
930 switches::kEnableDomDistiller));
[email protected]6bd370b2014-05-28 14:19:47931
Tommy Steimelc4477982017-11-29 18:07:18932 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE, normal_window);
ellyjones0101ba02017-05-19 15:50:26933 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, normal_window);
934
[email protected]338416c02014-05-13 16:47:06935 // Initialize other commands whose state changes based on various conditions.
[email protected]32dfede2013-08-25 15:48:25936 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40937 UpdateCommandsForContentRestrictionState();
[email protected]5d98294912012-06-27 22:57:40938 UpdateCommandsForBookmarkEditing();
[email protected]5d98294912012-06-27 22:57:40939 UpdateCommandsForIncognitoAvailability();
940}
941
[email protected]05454532013-01-22 21:09:08942// static
943void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
944 CommandUpdater* command_updater,
945 Profile* profile) {
mlermane01e6de2014-09-29 19:26:47946 const bool guest_session = profile->IsGuestSession();
947 // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession().
[email protected]5d98294912012-06-27 22:57:40948 IncognitoModePrefs::Availability incognito_availability =
[email protected]05454532013-01-22 21:09:08949 IncognitoModePrefs::GetAvailability(profile->GetPrefs());
950 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40951 IDC_NEW_WINDOW,
952 incognito_availability != IncognitoModePrefs::FORCED);
[email protected]05454532013-01-22 21:09:08953 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40954 IDC_NEW_INCOGNITO_WINDOW,
mlermane01e6de2014-09-29 19:26:47955 incognito_availability != IncognitoModePrefs::DISABLED && !guest_session);
[email protected]5d98294912012-06-27 22:57:40956
[email protected]57b25292014-05-01 16:31:06957 const bool forced_incognito =
958 incognito_availability == IncognitoModePrefs::FORCED ||
959 guest_session; // Guest always runs in Incognito mode.
[email protected]05454532013-01-22 21:09:08960 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40961 IDC_SHOW_BOOKMARK_MANAGER,
[email protected]57b25292014-05-01 16:31:06962 browser_defaults::bookmarks_enabled && !forced_incognito);
Devlin Cronin21dba422018-05-30 15:45:16963 extensions::ExtensionService* extension_service =
[email protected]03d25812014-06-22 19:41:55964 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]57b25292014-05-01 16:31:06965 const bool enable_extensions =
[email protected]5d98294912012-06-27 22:57:40966 extension_service && extension_service->extensions_enabled();
[email protected]5d98294912012-06-27 22:57:40967
[email protected]57b25292014-05-01 16:31:06968 // Bookmark manager and settings page/subpages are forced to open in normal
969 // mode. For this reason we disable these commands when incognito is forced.
970 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
971 enable_extensions && !forced_incognito);
972
973 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito);
974 command_updater->UpdateCommandEnabled(IDC_OPTIONS,
975 !forced_incognito || guest_session);
estade8c0780f2015-08-21 23:36:41976 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito);
[email protected]05454532013-01-22 21:09:08977}
978
979void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
Ivan Sandrk9669d0e2017-12-15 23:50:20980 if (is_locked_fullscreen_)
981 return;
982
[email protected]05454532013-01-22 21:09:08983 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile());
984
[email protected]6a414ff2013-02-27 08:22:54985 if (!IsShowingMainUI()) {
[email protected]05454532013-01-22 21:09:08986 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false);
987 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false);
988 }
[email protected]5d98294912012-06-27 22:57:40989}
990
991void BrowserCommandController::UpdateCommandsForTabState() {
Ivan Sandrk9669d0e2017-12-15 23:50:20992 if (is_locked_fullscreen_)
993 return;
994
[email protected]617ee962013-01-29 20:49:12995 WebContents* current_web_contents =
996 browser_->tab_strip_model()->GetActiveWebContents();
[email protected]1c5119c2012-09-19 00:08:57997 if (!current_web_contents) // May be NULL during tab restore.
[email protected]5d98294912012-06-27 22:57:40998 return;
[email protected]5d98294912012-06-27 22:57:40999
1000 // Navigation commands
[email protected]5d98294912012-06-27 22:57:401001 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_));
[email protected]5d98294912012-06-27 22:57:401002 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_));
1003 command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_));
toyoshim7dad4b1182016-04-01 14:28:051004 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE,
[email protected]5d98294912012-06-27 22:57:401005 CanReload(browser_));
[email protected]58e29032012-08-06 20:19:571006 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE,
1007 CanReload(browser_));
[email protected]5d98294912012-06-27 22:57:401008
1009 // Window management commands
1010 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB,
1011 !browser_->is_app() && CanDuplicateTab(browser_));
Tommy Steimelc4477982017-11-29 18:07:181012 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE,
ellyjones0101ba02017-05-19 15:50:261013 !browser_->is_app());
1014 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB,
1015 !browser_->is_app());
[email protected]5d98294912012-06-27 22:57:401016
1017 // Page-related commands
1018 window()->SetStarredState(
[email protected]1c5119c2012-09-19 00:08:571019 BookmarkTabHelper::FromWebContents(current_web_contents)->is_starred());
[email protected]5423c372012-08-22 05:50:161020 window()->ZoomChangedForActiveTab(false);
[email protected]5d98294912012-06-27 22:57:401021 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
1022 CanViewSource(browser_));
1023 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION,
1024 CanEmailPageLocation(browser_));
1025 if (browser_->is_devtools())
1026 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false);
1027
[email protected]92086542014-04-08 08:45:291028 command_updater_.UpdateCommandEnabled(IDC_CREATE_HOSTED_APP,
1029 CanCreateBookmarkApp(browser_));
Alan Cutter403cebb2018-05-17 05:22:451030 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW,
1031 CanCreateBookmarkApp(browser_));
[email protected]5d98294912012-06-27 22:57:401032
[email protected]9b7ab882012-09-10 23:46:361033 command_updater_.UpdateCommandEnabled(
1034 IDC_TOGGLE_REQUEST_TABLET_SITE,
1035 CanRequestTabletSite(current_web_contents));
1036
[email protected]5d98294912012-06-27 22:57:401037 UpdateCommandsForContentRestrictionState();
1038 UpdateCommandsForBookmarkEditing();
[email protected]3cac87232012-11-20 01:48:271039 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:411040 UpdateCommandsForMediaRouter();
[email protected]d93dbd12014-08-04 23:42:531041 // Update the zoom commands when an active tab is selected.
1042 UpdateCommandsForZoomState();
1043}
1044
1045void BrowserCommandController::UpdateCommandsForZoomState() {
1046 WebContents* contents =
1047 browser_->tab_strip_model()->GetActiveWebContents();
1048 if (!contents)
1049 return;
a.sarkar.arundaadc712015-02-26 05:39:081050 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS,
1051 CanZoomIn(contents));
1052 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL,
ccameronb7c1d6c2015-03-09 17:08:241053 CanResetZoom(contents));
a.sarkar.arundaadc712015-02-26 05:39:081054 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS,
1055 CanZoomOut(contents));
[email protected]5d98294912012-06-27 22:57:401056}
1057
1058void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
1059 int restrictions = GetContentRestrictions(browser_);
1060
1061 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011062 IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY));
[email protected]5d98294912012-06-27 22:57:401063 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011064 IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT));
[email protected]5d98294912012-06-27 22:57:401065 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011066 IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE));
[email protected]5d98294912012-06-27 22:57:401067 UpdateSaveAsState();
1068 UpdatePrintingState();
1069}
1070
1071void BrowserCommandController::UpdateCommandsForDevTools() {
Ivan Sandrk9669d0e2017-12-15 23:50:201072 if (is_locked_fullscreen_)
1073 return;
1074
Pavol Markodebb0ff2018-05-07 18:35:411075 using DTPH = policy::DeveloperToolsPolicyHandler;
1076 // TODO(pfeldman): Possibly implement handling for
1077 // Availability::kDisallowedForForceInstalledExtensions
1078 // (https://crbug.com/838146).
[email protected]5d98294912012-06-27 22:57:401079 bool dev_tools_enabled =
Pavol Markodebb0ff2018-05-07 18:35:411080 DTPH::GetDevToolsAvailability(profile()->GetPrefs()) !=
1081 DTPH::Availability::kDisallowed;
[email protected]5d98294912012-06-27 22:57:401082 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS,
1083 dev_tools_enabled);
1084 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE,
1085 dev_tools_enabled);
[email protected]2056c3192013-10-21 22:40:511086 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES,
1087 dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401088 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT,
1089 dev_tools_enabled);
[email protected]d16657c2012-09-03 14:25:101090 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE,
1091 dev_tools_enabled);
spqchan2c5d541e2017-10-25 07:07:111092#if defined(OS_MACOSX)
1093 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS,
1094 dev_tools_enabled);
1095#endif
[email protected]5d98294912012-06-27 22:57:401096}
1097
1098void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
Ivan Sandrk9669d0e2017-12-15 23:50:201099 if (is_locked_fullscreen_)
1100 return;
1101
[email protected]5d98294912012-06-27 22:57:401102 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE,
1103 CanBookmarkCurrentPage(browser_));
1104 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
1105 CanBookmarkAllTabs(browser_));
thestig5149d272014-10-30 07:25:291106#if defined(OS_WIN)
1107 command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN, true);
1108#endif
[email protected]5d98294912012-06-27 22:57:401109}
1110
1111void BrowserCommandController::UpdateCommandsForBookmarkBar() {
Ivan Sandrk9669d0e2017-12-15 23:50:201112 if (is_locked_fullscreen_)
1113 return;
1114
tfarina3bddbe112014-08-28 05:29:321115 command_updater_.UpdateCommandEnabled(
1116 IDC_SHOW_BOOKMARK_BAR,
1117 browser_defaults::bookmarks_enabled && !profile()->IsGuestSession() &&
mlerman7831f57d2015-05-25 11:40:151118 !profile()->IsSystemProfile() &&
tfarina3bddbe112014-08-28 05:29:321119 !profile()->GetPrefs()->IsManagedPreference(
1120 bookmarks::prefs::kShowBookmarkBar) &&
1121 IsShowingMainUI());
[email protected]5d98294912012-06-27 22:57:401122}
1123
[email protected]9ec3ea5b2012-12-03 18:14:301124void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
Ivan Sandrk9669d0e2017-12-15 23:50:201125 if (is_locked_fullscreen_)
1126 return;
1127
[email protected]9ec3ea5b2012-12-03 18:14:301128 UpdateSaveAsState();
[email protected]05454532013-01-22 21:09:081129 UpdateOpenFileState(&command_updater_);
[email protected]9ec3ea5b2012-12-03 18:14:301130}
1131
[email protected]32dfede2013-08-25 15:48:251132void BrowserCommandController::UpdateCommandsForFullscreenMode() {
Ivan Sandrk9669d0e2017-12-15 23:50:201133 if (is_locked_fullscreen_)
1134 return;
1135
zijiehe3c7af992017-02-12 20:59:401136 const bool is_fullscreen = window() && window()->IsFullscreen();
1137 const bool show_main_ui = IsShowingMainUI();
1138 const bool main_not_fullscreen = show_main_ui && !is_fullscreen;
[email protected]5d98294912012-06-27 22:57:401139
1140 // Navigation commands
1141 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1142
1143 // Window management commands
1144 command_updater_.UpdateCommandEnabled(
1145 IDC_SHOW_AS_TAB,
zijiehe3c7af992017-02-12 20:59:401146 !browser_->is_type_tabbed() && !is_fullscreen);
[email protected]5d98294912012-06-27 22:57:401147
1148 // Focus various bits of UI
1149 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
1150 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui);
1151 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
1152 command_updater_.UpdateCommandEnabled(
1153 IDC_FOCUS_MENU_BAR, main_not_fullscreen);
1154 command_updater_.UpdateCommandEnabled(
1155 IDC_FOCUS_NEXT_PANE, main_not_fullscreen);
1156 command_updater_.UpdateCommandEnabled(
1157 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen);
1158 command_updater_.UpdateCommandEnabled(
1159 IDC_FOCUS_BOOKMARKS, main_not_fullscreen);
[email protected]822ca8c62013-04-19 00:49:151160 command_updater_.UpdateCommandEnabled(
David Tsengc0b1b642018-01-24 07:12:271161 IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY, main_not_fullscreen);
[email protected]5d98294912012-06-27 22:57:401162
1163 // Show various bits of UI
1164 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431165#if defined(GOOGLE_CHROME_BUILD)
[email protected]5d98294912012-06-27 22:57:401166 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431167#endif
estade8c0780f2015-08-21 23:36:411168 UpdateShowSyncState(show_main_ui);
[email protected]5d98294912012-06-27 22:57:401169
[email protected]5d98294912012-06-27 22:57:401170 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
1171 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
1172 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
1173 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
primianod3a81ab2016-01-25 22:21:151174
1175 if (base::debug::IsProfilingSupported())
1176 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
[email protected]5d98294912012-06-27 22:57:401177
[email protected]aeafc3852014-04-29 16:51:291178#if !defined(OS_MACOSX)
zijiehe3c7af992017-02-12 20:59:401179 // Disable toggling into fullscreen mode if disallowed by pref.
1180 const bool fullscreen_enabled = is_fullscreen ||
1181 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed);
1182#else
1183 const bool fullscreen_enabled = true;
[email protected]00a1cc5b2012-11-07 13:44:511184#endif
1185
1186 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled);
spqchanb8ffc7d2015-11-17 01:17:211187 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR,
1188 fullscreen_enabled);
[email protected]5d98294912012-06-27 22:57:401189
1190 UpdateCommandsForBookmarkBar();
zijiehedb473d552017-02-24 01:13:411191 UpdateCommandsForIncognitoAvailability();
Alan Cutter167dfe82018-04-11 09:06:001192 UpdateCommandsForHostedAppAvailability();
1193}
1194
1195void BrowserCommandController::UpdateCommandsForHostedAppAvailability() {
1196 bool has_toolbar =
1197 browser_->is_type_tabbed() ||
1198 extensions::HostedAppBrowserController::IsForExperimentalHostedAppBrowser(
1199 browser_);
1200 if (window() && window()->ShouldHideUIForFullscreen())
1201 has_toolbar = false;
1202 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, has_toolbar);
1203 command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE, has_toolbar);
1204 command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE, has_toolbar);
1205 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, has_toolbar);
[email protected]5d98294912012-06-27 22:57:401206}
1207
Ivan Sandrk9669d0e2017-12-15 23:50:201208#if defined(OS_CHROMEOS)
1209namespace {
1210
1211#if DCHECK_IS_ON()
1212// Makes sure that all commands that are not whitelisted are disabled. DCHECKs
1213// otherwise. Compiled only in debug mode.
1214void NonWhitelistedCommandsAreDisabled(CommandUpdaterImpl* command_updater) {
1215 constexpr int kWhitelistedIds[] = {
1216 IDC_CUT, IDC_COPY, IDC_PASTE,
1217 IDC_FIND, IDC_FIND_NEXT, IDC_FIND_PREVIOUS,
1218 IDC_ZOOM_PLUS, IDC_ZOOM_NORMAL, IDC_ZOOM_MINUS,
1219 };
1220
1221 // Go through all the command ids, skip the whitelisted ones.
1222 for (int id : command_updater->GetAllIds()) {
1223 if (std::find(std::begin(kWhitelistedIds), std::end(kWhitelistedIds), id)
1224 != std::end(kWhitelistedIds)) {
1225 continue;
1226 }
1227 DCHECK(!command_updater->IsCommandEnabled(id));
1228 }
1229}
1230#endif
1231
1232} // namespace
1233
1234void BrowserCommandController::UpdateCommandsForLockedFullscreenMode() {
Ivan Sandrk9669d0e2017-12-15 23:50:201235 bool is_locked_fullscreen = ash::IsWindowTrustedPinned(browser_->window());
1236 // Sanity check to make sure this function is called only on state change.
1237 DCHECK_NE(is_locked_fullscreen, is_locked_fullscreen_);
1238 if (is_locked_fullscreen == is_locked_fullscreen_)
1239 return;
1240 is_locked_fullscreen_ = is_locked_fullscreen;
1241
1242 if (is_locked_fullscreen_) {
1243 command_updater_.DisableAllCommands();
1244 // Update the state of whitelisted commands:
1245 // IDC_CUT/IDC_COPY/IDC_PASTE,
1246 UpdateCommandsForContentRestrictionState();
1247 // IDC_FIND/IDC_FIND_NEXT/IDC_FIND_PREVIOUS,
1248 UpdateCommandsForFind();
1249 // IDC_ZOOM_PLUS/IDC_ZOOM_NORMAL/IDC_ZOOM_MINUS.
1250 UpdateCommandsForZoomState();
1251 // All other commands will be disabled (there is an early return in their
1252 // corresponding UpdateCommandsFor* functions).
1253#if DCHECK_IS_ON()
1254 NonWhitelistedCommandsAreDisabled(&command_updater_);
1255#endif
1256 } else {
1257 // Do an init call to re-initialize command state after the
1258 // DisableAllCommands.
1259 InitCommandState();
1260 }
1261}
1262#endif
1263
[email protected]5d98294912012-06-27 22:57:401264void BrowserCommandController::UpdatePrintingState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201265 if (is_locked_fullscreen_)
1266 return;
1267
[email protected]d53e4032012-06-29 18:58:341268 bool print_enabled = CanPrint(browser_);
1269 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
Lei Zhang48a4a5262018-04-17 20:18:441270#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:551271 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT,
1272 CanBasicPrint(browser_));
Lei Zhang48a4a5262018-04-17 20:18:441273#endif
[email protected]5d98294912012-06-27 22:57:401274}
1275
1276void BrowserCommandController::UpdateSaveAsState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201277 if (is_locked_fullscreen_)
1278 return;
1279
[email protected]5d98294912012-06-27 22:57:401280 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_));
1281}
1282
estade8c0780f2015-08-21 23:36:411283void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) {
Ivan Sandrk9669d0e2017-12-15 23:50:201284 if (is_locked_fullscreen_)
1285 return;
1286
estade8c0780f2015-08-21 23:36:411287 command_updater_.UpdateCommandEnabled(
1288 IDC_SHOW_SYNC_SETUP, show_main_ui && pref_signin_allowed_.GetValue());
1289}
1290
[email protected]05454532013-01-22 21:09:081291// static
1292void BrowserCommandController::UpdateOpenFileState(
1293 CommandUpdater* command_updater) {
[email protected]5d98294912012-06-27 22:57:401294 bool enabled = true;
1295 PrefService* local_state = g_browser_process->local_state();
1296 if (local_state)
1297 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs);
1298
[email protected]05454532013-01-22 21:09:081299 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled);
[email protected]5d98294912012-06-27 22:57:401300}
1301
1302void BrowserCommandController::UpdateReloadStopState(bool is_loading,
1303 bool force) {
Ivan Sandrk9669d0e2017-12-15 23:50:201304 if (is_locked_fullscreen_)
1305 return;
1306
[email protected]5d98294912012-06-27 22:57:401307 window()->UpdateReloadStopState(is_loading, force);
1308 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
1309}
1310
[email protected]2e9369e2014-08-15 09:12:531311void BrowserCommandController::UpdateTabRestoreCommandState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201312 if (is_locked_fullscreen_)
1313 return;
1314
blundell74001adc2015-09-18 11:04:251315 sessions::TabRestoreService* tab_restore_service =
[email protected]2e9369e2014-08-15 09:12:531316 TabRestoreServiceFactory::GetForProfile(profile());
1317 // The command is enabled if the service hasn't loaded yet to trigger loading.
1318 // The command is updated once the load completes.
1319 command_updater_.UpdateCommandEnabled(
1320 IDC_RESTORE_TAB,
1321 tab_restore_service &&
1322 (!tab_restore_service->IsLoaded() ||
1323 GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE));
1324}
1325
[email protected]3cac87232012-11-20 01:48:271326void BrowserCommandController::UpdateCommandsForFind() {
1327 TabStripModel* model = browser_->tab_strip_model();
1328 bool enabled = !model->IsTabBlocked(model->active_index()) &&
1329 !browser_->is_devtools();
1330
1331 command_updater_.UpdateCommandEnabled(IDC_FIND, enabled);
1332 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled);
1333 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled);
1334}
1335
apacible45cbfc92015-09-28 22:45:411336void BrowserCommandController::UpdateCommandsForMediaRouter() {
Ivan Sandrk9669d0e2017-12-15 23:50:201337 if (is_locked_fullscreen_)
1338 return;
1339
apacible45cbfc92015-09-28 22:45:411340 command_updater_.UpdateCommandEnabled(IDC_ROUTE_MEDIA,
1341 CanRouteMedia(browser_));
1342}
1343
[email protected]409ea2972012-11-10 19:54:431344void BrowserCommandController::AddInterstitialObservers(WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071345 interstitial_observers_.push_back(new InterstitialObserver(this, contents));
[email protected]5d98294912012-06-27 22:57:401346}
1347
1348void BrowserCommandController::RemoveInterstitialObservers(
[email protected]e89cfcb2012-11-11 14:47:241349 WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071350 for (size_t i = 0; i < interstitial_observers_.size(); i++) {
1351 if (interstitial_observers_[i]->web_contents() != contents)
1352 continue;
1353
1354 delete interstitial_observers_[i];
1355 interstitial_observers_.erase(interstitial_observers_.begin() + i);
1356 return;
1357 }
[email protected]5d98294912012-06-27 22:57:401358}
1359
1360BrowserWindow* BrowserCommandController::window() {
1361 return browser_->window();
1362}
1363
1364Profile* BrowserCommandController::profile() {
1365 return browser_->profile();
1366}
1367
[email protected]5d98294912012-06-27 22:57:401368} // namespace chrome