blob: 14dc84a82bfbc1ee284849b6849f1e9e70c3ef81 [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"
[email protected]5d98294912012-06-27 22:57:4024#include "chrome/browser/prefs/incognito_mode_prefs.h"
[email protected]5d98294912012-06-27 22:57:4025#include "chrome/browser/profiles/profile.h"
mlermane01e6de2014-09-29 19:26:4726#include "chrome/browser/profiles/profile_manager.h"
[email protected]5d98294912012-06-27 22:57:4027#include "chrome/browser/sessions/tab_restore_service_factory.h"
[email protected]0b32f9b62012-09-17 19:08:0328#include "chrome/browser/shell_integration.h"
[email protected]3d27d272013-07-31 03:15:1629#include "chrome/browser/signin/signin_promo.h"
[email protected]5d98294912012-06-27 22:57:4030#include "chrome/browser/sync/profile_sync_service_factory.h"
Christopher Lam86b52712017-12-04 01:58:3331#include "chrome/browser/ui/apps/app_info_dialog.h"
[email protected]5d98294912012-06-27 22:57:4032#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
33#include "chrome/browser/ui/browser.h"
34#include "chrome/browser/ui/browser_commands.h"
35#include "chrome/browser/ui/browser_window.h"
36#include "chrome/browser/ui/chrome_pages.h"
Alan Cutter09965802018-03-27 07:25:2937#include "chrome/browser/ui/extensions/application_launch.h"
Christopher Lam0dbac2b2017-11-14 07:12:1038#include "chrome/browser/ui/extensions/hosted_app_browser_controller.h"
Alan Cutter0c3132302018-02-21 05:09:0239#include "chrome/browser/ui/page_info/page_info_dialog.h"
[email protected]5d98294912012-06-27 22:57:4040#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]2056c3192013-10-21 22:40:5141#include "chrome/browser/ui/webui/inspect_ui.h"
[email protected]3c71576ce2013-07-23 02:00:0142#include "chrome/common/content_restriction.h"
[email protected]5d98294912012-06-27 22:57:4043#include "chrome/common/pref_names.h"
44#include "chrome/common/profiling.h"
brettwe1f0af8b2015-10-09 21:30:4645#include "components/bookmarks/common/bookmark_pref_names.h"
maxbogue26f40222016-09-16 20:22:1846#include "components/browser_sync/profile_sync_service.h"
sdefresne0f2ef352015-07-27 19:18:0047#include "components/dom_distiller/core/dom_distiller_switches.h"
Scott Violet9ae82892018-03-01 18:38:1248#include "components/feature_engagement/buildflags.h"
brettwb1fc1b82016-02-02 00:19:0849#include "components/prefs/pref_service.h"
blundella08c5dd2015-09-18 06:14:1650#include "components/sessions/core/tab_restore_service.h"
David Rogera6c88122017-10-25 13:02:4651#include "components/signin/core/browser/signin_pref_names.h"
[email protected]5d98294912012-06-27 22:57:4052#include "content/public/browser/native_web_keyboard_event.h"
53#include "content/public/browser/navigation_controller.h"
54#include "content/public/browser/navigation_entry.h"
Lukasz Anforowicze1b954d92017-10-30 21:28:0655#include "content/public/browser/render_frame_host.h"
[email protected]5d98294912012-06-27 22:57:4056#include "content/public/browser/web_contents.h"
[email protected]20ca0382013-02-28 19:50:0757#include "content/public/browser/web_contents_observer.h"
bend32292b2016-10-07 00:21:5858#include "content/public/common/service_manager_connection.h"
[email protected]5d98294912012-06-27 22:57:4059#include "content/public/common/url_constants.h"
[email protected]03d25812014-06-22 19:41:5560#include "extensions/browser/extension_system.h"
Scott Violet318a55f2018-03-30 19:08:1961#include "printing/buildflags/buildflags.h"
[email protected]7e9acd082013-09-17 23:31:1662#include "ui/events/keycodes/keyboard_codes.h"
[email protected]5d98294912012-06-27 22:57:4063
[email protected]9c4d68332013-01-30 13:34:4164#if defined(OS_MACOSX)
65#include "chrome/browser/ui/browser_commands_mac.h"
66#endif
67
[email protected]5d98294912012-06-27 22:57:4068#if defined(OS_WIN)
[email protected]a43ed002013-02-05 19:47:5469#include "base/win/windows_version.h"
[email protected]2d0f80f2013-11-01 22:47:1870#include "content/public/browser/gpu_data_manager.h"
[email protected]5d98294912012-06-27 22:57:4071#endif
72
[email protected]d12cc5e2013-10-19 18:25:0673#if defined(OS_CHROMEOS)
Ivan Sandrk9669d0e2017-12-15 23:50:2074#include "ash/public/cpp/window_pin_type.h"
[email protected]0c930812014-01-30 18:01:4775#include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h"
caelyn4e4e08a2015-02-04 21:27:4976#include "chrome/browser/ui/browser_commands_chromeos.h"
[email protected]d12cc5e2013-10-19 18:25:0677#endif
78
[email protected]d5bedb6d2014-04-08 10:49:3279#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
karandeepbe6200332016-06-21 12:26:1080#include "ui/base/ime/linux/text_edit_key_bindings_delegate_auralinux.h"
[email protected]1e2172f2014-04-01 17:32:3481#endif
82
Bettina Deaf3dac202017-09-16 20:53:2283#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:1484#include "chrome/browser/feature_engagement/bookmark/bookmark_tracker.h"
85#include "chrome/browser/feature_engagement/bookmark/bookmark_tracker_factory.h"
Catherine Chungbeb884222017-08-01 15:47:5586#include "chrome/browser/feature_engagement/new_tab/new_tab_tracker.h"
87#include "chrome/browser/feature_engagement/new_tab/new_tab_tracker_factory.h"
88#endif
89
[email protected]5d98294912012-06-27 22:57:4090using content::NavigationEntry;
91using content::NavigationController;
92using content::WebContents;
93
[email protected]5d98294912012-06-27 22:57:4094namespace chrome {
95
96///////////////////////////////////////////////////////////////////////////////
97// BrowserCommandController, public:
98
[email protected]338416c02014-05-13 16:47:0699BrowserCommandController::BrowserCommandController(Browser* browser)
[email protected]5d98294912012-06-27 22:57:40100 : browser_(browser),
Ivan Sandrk9669d0e2017-12-15 23:50:20101 command_updater_(nullptr) {
[email protected]5d98294912012-06-27 22:57:40102 browser_->tab_strip_model()->AddObserver(this);
103 PrefService* local_state = g_browser_process->local_state();
104 if (local_state) {
105 local_pref_registrar_.Init(local_state);
[email protected]9ec3ea5b2012-12-03 18:14:30106 local_pref_registrar_.Add(
107 prefs::kAllowFileSelectionDialogs,
108 base::Bind(
109 &BrowserCommandController::UpdateCommandsForFileSelectionDialogs,
110 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40111 }
112
113 profile_pref_registrar_.Init(profile()->GetPrefs());
[email protected]9ec3ea5b2012-12-03 18:14:30114 profile_pref_registrar_.Add(
115 prefs::kDevToolsDisabled,
116 base::Bind(&BrowserCommandController::UpdateCommandsForDevTools,
117 base::Unretained(this)));
118 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32119 bookmarks::prefs::kEditBookmarksEnabled,
[email protected]9ec3ea5b2012-12-03 18:14:30120 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkEditing,
121 base::Unretained(this)));
122 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32123 bookmarks::prefs::kShowBookmarkBar,
[email protected]9ec3ea5b2012-12-03 18:14:30124 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkBar,
125 base::Unretained(this)));
126 profile_pref_registrar_.Add(
127 prefs::kIncognitoModeAvailability,
128 base::Bind(
129 &BrowserCommandController::UpdateCommandsForIncognitoAvailability,
130 base::Unretained(this)));
131 profile_pref_registrar_.Add(
132 prefs::kPrintingEnabled,
133 base::Bind(&BrowserCommandController::UpdatePrintingState,
134 base::Unretained(this)));
[email protected]32dfede2013-08-25 15:48:25135#if !defined(OS_MACOSX)
136 profile_pref_registrar_.Add(
137 prefs::kFullscreenAllowed,
138 base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode,
139 base::Unretained(this)));
140#endif
estade8c0780f2015-08-21 23:36:41141 pref_signin_allowed_.Init(
142 prefs::kSigninAllowed,
143 profile()->GetOriginalProfile()->GetPrefs(),
144 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange,
145 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40146
147 InitCommandState();
148
blundell74001adc2015-09-18 11:04:25149 sessions::TabRestoreService* tab_restore_service =
[email protected]5d98294912012-06-27 22:57:40150 TabRestoreServiceFactory::GetForProfile(profile());
151 if (tab_restore_service) {
152 tab_restore_service->AddObserver(this);
153 TabRestoreServiceChanged(tab_restore_service);
154 }
[email protected]5d98294912012-06-27 22:57:40155}
156
157BrowserCommandController::~BrowserCommandController() {
[email protected]95e39472012-10-05 23:37:36158 // TabRestoreService may have been shutdown by the time we get here. Don't
159 // trigger creating it.
blundell74001adc2015-09-18 11:04:25160 sessions::TabRestoreService* tab_restore_service =
[email protected]95e39472012-10-05 23:37:36161 TabRestoreServiceFactory::GetForProfileIfExisting(profile());
[email protected]5d98294912012-06-27 22:57:40162 if (tab_restore_service)
163 tab_restore_service->RemoveObserver(this);
164 profile_pref_registrar_.RemoveAll();
165 local_pref_registrar_.RemoveAll();
166 browser_->tab_strip_model()->RemoveObserver(this);
[email protected]5d98294912012-06-27 22:57:40167}
168
169bool BrowserCommandController::IsReservedCommandOrKey(
170 int command_id,
171 const content::NativeWebKeyboardEvent& event) {
172 // In Apps mode, no keys are reserved.
173 if (browser_->is_app())
174 return false;
175
176#if defined(OS_CHROMEOS)
[email protected]397abd32013-08-21 05:44:19177 // On Chrome OS, the top row of keys are mapped to browser actions like
178 // back/forward or refresh. We don't want web pages to be able to change the
179 // behavior of these keys. Ash handles F4 and up; this leaves us needing to
180 // reserve browser back/forward and refresh here.
[email protected]5d98294912012-06-27 22:57:40181 ui::KeyboardCode key_code =
Blink Reformat1c4d759e2017-04-09 16:34:54182 static_cast<ui::KeyboardCode>(event.windows_key_code);
[email protected]397abd32013-08-21 05:44:19183 if ((key_code == ui::VKEY_BROWSER_BACK && command_id == IDC_BACK) ||
184 (key_code == ui::VKEY_BROWSER_FORWARD && command_id == IDC_FORWARD) ||
185 (key_code == ui::VKEY_BROWSER_REFRESH && command_id == IDC_RELOAD)) {
[email protected]5d98294912012-06-27 22:57:40186 return true;
187 }
188#endif
189
zijiehe68cd3dc22017-04-07 18:50:29190 if (window()->IsFullscreen()) {
191 // In fullscreen, all commands except for IDC_FULLSCREEN and IDC_EXIT should
192 // be delivered to the web page. The intent to implement and ship can be
193 // found in http://crbug.com/680809.
194 const bool is_exit_fullscreen =
195 (command_id == IDC_EXIT || command_id == IDC_FULLSCREEN);
196#if defined(OS_MACOSX)
197 // This behavior is different on Mac OS, which has a unique user-initiated
198 // full-screen mode. According to the discussion in http://crbug.com/702251,
199 // the commands should be reserved for browser-side handling if the browser
200 // window's toolbar is visible.
201 if (window()->IsToolbarShowing()) {
202 if (command_id == IDC_FULLSCREEN)
203 return true;
204 } else {
205 return is_exit_fullscreen;
206 }
207#else
208 return is_exit_fullscreen;
209#endif
210 }
[email protected]1e2172f2014-04-01 17:32:34211
[email protected]893124a22014-04-15 00:45:28212#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]1e2172f2014-04-01 17:32:34213 // If this key was registered by the user as a content editing hotkey, then
214 // it is not reserved.
[email protected]d5bedb6d2014-04-08 10:49:32215 ui::TextEditKeyBindingsDelegateAuraLinux* delegate =
[email protected]1e2172f2014-04-01 17:32:34216 ui::GetTextEditKeyBindingsDelegate();
[email protected]47e8e7542014-04-03 07:52:42217 if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL))
[email protected]1e2172f2014-04-01 17:32:34218 return false;
219#endif
220
zijiehe13207802017-02-16 08:06:10221 return command_id == IDC_CLOSE_TAB ||
222 command_id == IDC_CLOSE_WINDOW ||
223 command_id == IDC_NEW_INCOGNITO_WINDOW ||
224 command_id == IDC_NEW_TAB ||
225 command_id == IDC_NEW_WINDOW ||
226 command_id == IDC_RESTORE_TAB ||
227 command_id == IDC_SELECT_NEXT_TAB ||
228 command_id == IDC_SELECT_PREVIOUS_TAB ||
229 command_id == IDC_EXIT;
[email protected]5d98294912012-06-27 22:57:40230}
231
[email protected]5d98294912012-06-27 22:57:40232void BrowserCommandController::TabStateChanged() {
233 UpdateCommandsForTabState();
234}
235
[email protected]d93dbd12014-08-04 23:42:53236void BrowserCommandController::ZoomStateChanged() {
237 UpdateCommandsForZoomState();
238}
239
[email protected]5d98294912012-06-27 22:57:40240void BrowserCommandController::ContentRestrictionsChanged() {
241 UpdateCommandsForContentRestrictionState();
242}
243
244void BrowserCommandController::FullscreenStateChanged() {
[email protected]32dfede2013-08-25 15:48:25245 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40246}
247
Ivan Sandrk9669d0e2017-12-15 23:50:20248#if defined(OS_CHROMEOS)
249void BrowserCommandController::LockedFullscreenStateChanged() {
250 UpdateCommandsForLockedFullscreenMode();
251}
252#endif
253
[email protected]5d98294912012-06-27 22:57:40254void BrowserCommandController::PrintingStateChanged() {
255 UpdatePrintingState();
256}
257
258void BrowserCommandController::LoadingStateChanged(bool is_loading,
259 bool force) {
260 UpdateReloadStopState(is_loading, force);
261}
262
wittman76df71db32014-12-18 23:26:58263void BrowserCommandController::ExtensionStateChanged() {
264 // Extensions may disable the bookmark editing commands.
265 UpdateCommandsForBookmarkEditing();
266}
267
[email protected]5d98294912012-06-27 22:57:40268////////////////////////////////////////////////////////////////////////////////
Ivan Sandrk9669d0e2017-12-15 23:50:20269// BrowserCommandController, CommandUpdater implementation:
[email protected]5d98294912012-06-27 22:57:40270
Ivan Sandrk9669d0e2017-12-15 23:50:20271bool BrowserCommandController::SupportsCommand(int id) const {
272 return command_updater_.SupportsCommand(id);
273}
274
275bool BrowserCommandController::IsCommandEnabled(int id) const {
276 return command_updater_.IsCommandEnabled(id);
277}
278
279bool BrowserCommandController::ExecuteCommand(int id) {
280 return ExecuteCommandWithDisposition(id, WindowOpenDisposition::CURRENT_TAB);
281}
282
283bool BrowserCommandController::ExecuteCommandWithDisposition(
284 int id, WindowOpenDisposition disposition) {
285 // Doesn't go through the command_updater_ to avoid dealing with having a
286 // naming collision for ExecuteCommandWithDisposition (both
287 // CommandUpdaterDelegate and CommandUpdater declare this function so we
288 // choose to not implement CommandUpdaterDelegate inside this class and
289 // therefore command_updater_ doesn't have the delegate set).
290 if (!SupportsCommand(id) || !IsCommandEnabled(id))
291 return false;
292
[email protected]5d98294912012-06-27 22:57:40293 // No commands are enabled if there is not yet any selected tab.
294 // TODO(pkasting): It seems like we should not need this, because either
295 // most/all commands should not have been enabled yet anyway or the ones that
296 // are enabled should be global, or safe themselves against having no selected
297 // tab. However, Ben says he tried removing this before and got lots of
298 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
299 // window construction. This probably could use closer examination someday.
[email protected]59253a652012-11-20 00:17:26300 if (browser_->tab_strip_model()->active_index() == TabStripModel::kNoTab)
Ivan Sandrk9669d0e2017-12-15 23:50:20301 return true;
[email protected]5d98294912012-06-27 22:57:40302
303 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command "
304 << id;
305
[email protected]5d98294912012-06-27 22:57:40306 // The order of commands in this switch statement must match the function
307 // declaration order in browser.h!
308 switch (id) {
309 // Navigation commands
[email protected]5d98294912012-06-27 22:57:40310 case IDC_BACK:
[email protected]5d98294912012-06-27 22:57:40311 GoBack(browser_, disposition);
312 break;
[email protected]5d98294912012-06-27 22:57:40313 case IDC_FORWARD:
[email protected]5d98294912012-06-27 22:57:40314 GoForward(browser_, disposition);
315 break;
316 case IDC_RELOAD:
317 Reload(browser_, disposition);
318 break;
[email protected]58e29032012-08-06 20:19:57319 case IDC_RELOAD_CLEARING_CACHE:
320 ClearCache(browser_);
Nico Webera745ef72018-01-29 23:45:57321 FALLTHROUGH;
toyoshim7dad4b1182016-04-01 14:28:05322 case IDC_RELOAD_BYPASSING_CACHE:
323 ReloadBypassingCache(browser_, disposition);
[email protected]5d98294912012-06-27 22:57:40324 break;
325 case IDC_HOME:
326 Home(browser_, disposition);
327 break;
328 case IDC_OPEN_CURRENT_URL:
329 OpenCurrentURL(browser_);
330 break;
331 case IDC_STOP:
332 Stop(browser_);
333 break;
334
335 // Window management commands
336 case IDC_NEW_WINDOW:
337 NewWindow(browser_);
338 break;
339 case IDC_NEW_INCOGNITO_WINDOW:
340 NewIncognitoWindow(browser_);
341 break;
342 case IDC_CLOSE_WINDOW:
bratell0a7406f2017-03-28 07:46:37343 base::RecordAction(base::UserMetricsAction("CloseWindowByKey"));
[email protected]04b9e692012-08-24 14:49:09344 CloseWindow(browser_);
[email protected]5d98294912012-06-27 22:57:40345 break;
Bettina Dea0a4505922017-09-28 00:53:32346 case IDC_NEW_TAB: {
347 NewTab(browser_);
348#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Catherine Chungbeb884222017-08-01 15:47:55349 // This is not in NewTab() to avoid tracking programmatic creation of new
350 // tabs by extensions.
Bettina Dea0a4505922017-09-28 00:53:32351 auto* new_tab_tracker =
352 feature_engagement::NewTabTrackerFactory::GetInstance()
353 ->GetForProfile(profile());
354
355 new_tab_tracker->OnNewTabOpened();
356 new_tab_tracker->CloseBubble();
Catherine Chungbeb884222017-08-01 15:47:55357#endif
[email protected]5d98294912012-06-27 22:57:40358 break;
Bettina Dea0a4505922017-09-28 00:53:32359 }
[email protected]5d98294912012-06-27 22:57:40360 case IDC_CLOSE_TAB:
bratell0a7406f2017-03-28 07:46:37361 base::RecordAction(base::UserMetricsAction("CloseTabByKey"));
[email protected]04b9e692012-08-24 14:49:09362 CloseTab(browser_);
[email protected]5d98294912012-06-27 22:57:40363 break;
364 case IDC_SELECT_NEXT_TAB:
bratell0a7406f2017-03-28 07:46:37365 base::RecordAction(base::UserMetricsAction("Accel_SelectNextTab"));
[email protected]5d98294912012-06-27 22:57:40366 SelectNextTab(browser_);
367 break;
368 case IDC_SELECT_PREVIOUS_TAB:
bratell0a7406f2017-03-28 07:46:37369 base::RecordAction(base::UserMetricsAction("Accel_SelectPreviousTab"));
[email protected]5d98294912012-06-27 22:57:40370 SelectPreviousTab(browser_);
371 break;
[email protected]5d98294912012-06-27 22:57:40372 case IDC_MOVE_TAB_NEXT:
373 MoveTabNext(browser_);
374 break;
375 case IDC_MOVE_TAB_PREVIOUS:
376 MoveTabPrevious(browser_);
377 break;
378 case IDC_SELECT_TAB_0:
379 case IDC_SELECT_TAB_1:
380 case IDC_SELECT_TAB_2:
381 case IDC_SELECT_TAB_3:
382 case IDC_SELECT_TAB_4:
383 case IDC_SELECT_TAB_5:
384 case IDC_SELECT_TAB_6:
385 case IDC_SELECT_TAB_7:
bratell0a7406f2017-03-28 07:46:37386 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
[email protected]5d98294912012-06-27 22:57:40387 SelectNumberedTab(browser_, id - IDC_SELECT_TAB_0);
388 break;
389 case IDC_SELECT_LAST_TAB:
bratell0a7406f2017-03-28 07:46:37390 base::RecordAction(base::UserMetricsAction("Accel_SelectNumberedTab"));
[email protected]5d98294912012-06-27 22:57:40391 SelectLastTab(browser_);
392 break;
393 case IDC_DUPLICATE_TAB:
394 DuplicateTab(browser_);
395 break;
396 case IDC_RESTORE_TAB:
397 RestoreTab(browser_);
398 break;
[email protected]5d98294912012-06-27 22:57:40399 case IDC_SHOW_AS_TAB:
400 ConvertPopupToTabbedBrowser(browser_);
401 break;
402 case IDC_FULLSCREEN:
[email protected]3f32b9b2012-07-09 16:59:28403 chrome::ToggleFullscreenMode(browser_);
[email protected]5d98294912012-06-27 22:57:40404 break;
Alan Cutter09965802018-03-27 07:25:29405 case IDC_OPEN_IN_PWA_WINDOW:
406 base::RecordAction(base::UserMetricsAction("OpenActiveTabInPwaWindow"));
407 ReparentSecureActiveTabIntoPwaWindow(browser_);
408 break;
[email protected]770c6d82012-09-06 22:21:32409
[email protected]d12cc5e2013-10-19 18:25:06410#if defined(OS_CHROMEOS)
411 case IDC_VISIT_DESKTOP_OF_LRU_USER_2:
[email protected]0c930812014-01-30 18:01:47412 case IDC_VISIT_DESKTOP_OF_LRU_USER_3:
zijiehe4dde8072017-02-13 20:38:35413 ExecuteVisitDesktopCommand(id, window()->GetNativeWindow());
[email protected]0c930812014-01-30 18:01:47414 break;
[email protected]d12cc5e2013-10-19 18:25:06415#endif
416
[email protected]893124a22014-04-15 00:45:28417#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15418 case IDC_MINIMIZE_WINDOW:
419 browser_->window()->Minimize();
420 break;
421 case IDC_MAXIMIZE_WINDOW:
422 browser_->window()->Maximize();
423 break;
424 case IDC_RESTORE_WINDOW:
425 browser_->window()->Restore();
426 break;
[email protected]af97be4c62014-02-13 14:43:34427 case IDC_USE_SYSTEM_TITLE_BAR: {
zijiehe4dde8072017-02-13 20:38:35428 PrefService* prefs = profile()->GetPrefs();
[email protected]af97be4c62014-02-13 14:43:34429 prefs->SetBoolean(prefs::kUseCustomChromeFrame,
430 !prefs->GetBoolean(prefs::kUseCustomChromeFrame));
431 break;
432 }
433#endif
434
[email protected]5d98294912012-06-27 22:57:40435#if defined(OS_MACOSX)
spqchanb8ffc7d2015-11-17 01:17:21436 case IDC_TOGGLE_FULLSCREEN_TOOLBAR:
437 chrome::ToggleFullscreenToolbar(browser_);
438 break;
spqchan2c5d541e2017-10-25 07:07:11439 case IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS: {
440 PrefService* prefs = profile()->GetPrefs();
441 prefs->SetBoolean(prefs::kAllowJavascriptAppleEvents,
442 !prefs->GetBoolean(prefs::kAllowJavascriptAppleEvents));
443 break;
444 }
[email protected]5d98294912012-06-27 22:57:40445#endif
446 case IDC_EXIT:
447 Exit();
448 break;
449
450 // Page-related commands
451 case IDC_SAVE_PAGE:
452 SavePage(browser_);
453 break;
454 case IDC_BOOKMARK_PAGE:
Anatoly Pilikovee720922017-11-01 09:43:17455#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:14456 feature_engagement::BookmarkTrackerFactory::GetInstance()
457 ->GetForProfile(profile())
458 ->OnBookmarkAdded();
459#endif
deepak.m154a7f392014-12-15 04:41:43460 BookmarkCurrentPageAllowingExtensionOverrides(browser_);
[email protected]5d98294912012-06-27 22:57:40461 break;
[email protected]5d98294912012-06-27 22:57:40462 case IDC_BOOKMARK_ALL_TABS:
Anatoly Pilikovee720922017-11-01 09:43:17463#if BUILDFLAG(ENABLE_DESKTOP_IN_PRODUCT_HELP)
Bettina Dea48125dc2017-09-06 03:23:14464 feature_engagement::BookmarkTrackerFactory::GetInstance()
465 ->GetForProfile(profile())
466 ->OnBookmarkAdded();
467#endif
[email protected]5d98294912012-06-27 22:57:40468 BookmarkAllTabs(browser_);
469 break;
470 case IDC_VIEW_SOURCE:
Lukasz Anforowicze1b954d92017-10-30 21:28:06471 browser_->tab_strip_model()
472 ->GetActiveWebContents()
473 ->GetMainFrame()
474 ->ViewSource();
[email protected]5d98294912012-06-27 22:57:40475 break;
476 case IDC_EMAIL_PAGE_LOCATION:
477 EmailPageLocation(browser_);
478 break;
479 case IDC_PRINT:
480 Print(browser_);
481 break;
bondd052b5f82015-10-28 22:39:32482
Lei Zhang48a4a5262018-04-17 20:18:44483#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:55484 case IDC_BASIC_PRINT:
bratell0a7406f2017-03-28 07:46:37485 base::RecordAction(base::UserMetricsAction("Accel_Advanced_Print"));
vitalybukaf9433e42014-09-08 10:04:55486 BasicPrint(browser_);
[email protected]5d98294912012-06-27 22:57:40487 break;
Lei Zhang48a4a5262018-04-17 20:18:44488#endif // ENABLE_PRINTING
bondd052b5f82015-10-28 22:39:32489
bondd052b5f82015-10-28 22:39:32490 case IDC_SAVE_CREDIT_CARD_FOR_PAGE:
491 SaveCreditCard(browser_);
492 break;
[email protected]e625b7602013-10-28 09:24:56493 case IDC_TRANSLATE_PAGE:
494 Translate(browser_);
495 break;
[email protected]4bee4432014-05-05 13:11:41496 case IDC_MANAGE_PASSWORDS_FOR_PAGE:
497 ManagePasswordsForPage(browser_);
498 break;
499
[email protected]5d98294912012-06-27 22:57:40500 // Clipboard commands
501 case IDC_CUT:
[email protected]5d98294912012-06-27 22:57:40502 case IDC_COPY:
[email protected]5d98294912012-06-27 22:57:40503 case IDC_PASTE:
pkastingcd3f08bce2015-04-18 13:37:12504 CutCopyPaste(browser_, id);
[email protected]5d98294912012-06-27 22:57:40505 break;
506
507 // Find-in-page
508 case IDC_FIND:
509 Find(browser_);
510 break;
511 case IDC_FIND_NEXT:
512 FindNext(browser_);
513 break;
514 case IDC_FIND_PREVIOUS:
515 FindPrevious(browser_);
516 break;
517
518 // Zoom
519 case IDC_ZOOM_PLUS:
520 Zoom(browser_, content::PAGE_ZOOM_IN);
521 break;
522 case IDC_ZOOM_NORMAL:
523 Zoom(browser_, content::PAGE_ZOOM_RESET);
524 break;
525 case IDC_ZOOM_MINUS:
526 Zoom(browser_, content::PAGE_ZOOM_OUT);
527 break;
528
529 // Focus various bits of UI
530 case IDC_FOCUS_TOOLBAR:
bratell0a7406f2017-03-28 07:46:37531 base::RecordAction(base::UserMetricsAction("Accel_Focus_Toolbar"));
[email protected]5d98294912012-06-27 22:57:40532 FocusToolbar(browser_);
533 break;
534 case IDC_FOCUS_LOCATION:
bratell0a7406f2017-03-28 07:46:37535 base::RecordAction(base::UserMetricsAction("Accel_Focus_Location"));
[email protected]5d98294912012-06-27 22:57:40536 FocusLocationBar(browser_);
537 break;
538 case IDC_FOCUS_SEARCH:
bratell0a7406f2017-03-28 07:46:37539 base::RecordAction(base::UserMetricsAction("Accel_Focus_Search"));
[email protected]5d98294912012-06-27 22:57:40540 FocusSearch(browser_);
541 break;
542 case IDC_FOCUS_MENU_BAR:
543 FocusAppMenu(browser_);
544 break;
545 case IDC_FOCUS_BOOKMARKS:
bratell0a7406f2017-03-28 07:46:37546 base::RecordAction(base::UserMetricsAction("Accel_Focus_Bookmarks"));
[email protected]5d98294912012-06-27 22:57:40547 FocusBookmarksToolbar(browser_);
548 break;
David Tsengc0b1b642018-01-24 07:12:27549 case IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY:
550 FocusInactivePopupForAccessibility(browser_);
[email protected]822ca8c62013-04-19 00:49:15551 break;
[email protected]5d98294912012-06-27 22:57:40552 case IDC_FOCUS_NEXT_PANE:
553 FocusNextPane(browser_);
554 break;
555 case IDC_FOCUS_PREVIOUS_PANE:
556 FocusPreviousPane(browser_);
557 break;
558
559 // Show various bits of UI
560 case IDC_OPEN_FILE:
561 browser_->OpenFile();
562 break;
[email protected]488e3952013-11-18 05:29:14563 case IDC_CREATE_HOSTED_APP:
[email protected]92086542014-04-08 08:45:29564 CreateBookmarkAppFromCurrentWebContents(browser_);
[email protected]488e3952013-11-18 05:29:14565 break;
[email protected]5d98294912012-06-27 22:57:40566 case IDC_DEV_TOOLS:
[email protected]c934c382013-11-01 00:36:01567 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Show());
[email protected]5d98294912012-06-27 22:57:40568 break;
569 case IDC_DEV_TOOLS_CONSOLE:
einbinderdfa567b2016-12-16 01:15:52570 ToggleDevToolsWindow(browser_, DevToolsToggleAction::ShowConsolePanel());
[email protected]5d98294912012-06-27 22:57:40571 break;
[email protected]2056c3192013-10-21 22:40:51572 case IDC_DEV_TOOLS_DEVICES:
573 InspectUI::InspectDevices(browser_);
574 break;
[email protected]5d98294912012-06-27 22:57:40575 case IDC_DEV_TOOLS_INSPECT:
[email protected]c934c382013-11-01 00:36:01576 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Inspect());
[email protected]5d98294912012-06-27 22:57:40577 break;
[email protected]d16657c2012-09-03 14:25:10578 case IDC_DEV_TOOLS_TOGGLE:
[email protected]c934c382013-11-01 00:36:01579 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Toggle());
[email protected]d16657c2012-09-03 14:25:10580 break;
[email protected]5d98294912012-06-27 22:57:40581 case IDC_TASK_MANAGER:
[email protected]29c262de2013-06-22 15:39:38582 OpenTaskManager(browser_);
[email protected]5d98294912012-06-27 22:57:40583 break;
caelyn4e4e08a2015-02-04 21:27:49584#if defined(OS_CHROMEOS)
585 case IDC_TAKE_SCREENSHOT:
586 TakeScreenshot();
587 break;
588#endif
[email protected]236ad3022013-09-04 03:27:43589#if defined(GOOGLE_CHROME_BUILD)
[email protected]5d98294912012-06-27 22:57:40590 case IDC_FEEDBACK:
afakhryf4575bd2017-04-28 02:21:04591 OpenFeedbackDialog(browser_, kFeedbackSourceBrowserCommand);
[email protected]5d98294912012-06-27 22:57:40592 break;
[email protected]236ad3022013-09-04 03:27:43593#endif
[email protected]5d98294912012-06-27 22:57:40594 case IDC_SHOW_BOOKMARK_BAR:
595 ToggleBookmarkBar(browser_);
596 break;
597 case IDC_PROFILING_ENABLED:
598 Profiling::Toggle();
599 break;
600
601 case IDC_SHOW_BOOKMARK_MANAGER:
602 ShowBookmarkManager(browser_);
603 break;
604 case IDC_SHOW_APP_MENU:
bratell0a7406f2017-03-28 07:46:37605 base::RecordAction(base::UserMetricsAction("Accel_Show_App_Menu"));
[email protected]5d98294912012-06-27 22:57:40606 ShowAppMenu(browser_);
607 break;
608 case IDC_SHOW_AVATAR_MENU:
609 ShowAvatarMenu(browser_);
610 break;
[email protected]5d98294912012-06-27 22:57:40611 case IDC_SHOW_HISTORY:
612 ShowHistory(browser_);
613 break;
614 case IDC_SHOW_DOWNLOADS:
615 ShowDownloads(browser_);
616 break;
617 case IDC_MANAGE_EXTENSIONS:
[email protected]bc9833c32013-02-28 04:05:08618 ShowExtensions(browser_, std::string());
[email protected]5d98294912012-06-27 22:57:40619 break;
620 case IDC_OPTIONS:
621 ShowSettings(browser_);
622 break;
623 case IDC_EDIT_SEARCH_ENGINES:
624 ShowSearchEngineSettings(browser_);
625 break;
626 case IDC_VIEW_PASSWORDS:
627 ShowPasswordManager(browser_);
628 break;
629 case IDC_CLEAR_BROWSING_DATA:
630 ShowClearBrowsingDataDialog(browser_);
631 break;
632 case IDC_IMPORT_SETTINGS:
633 ShowImportDialog(browser_);
634 break;
[email protected]9b7ab882012-09-10 23:46:36635 case IDC_TOGGLE_REQUEST_TABLET_SITE:
636 ToggleRequestTabletSite(browser_);
637 break;
[email protected]5d98294912012-06-27 22:57:40638 case IDC_ABOUT:
639 ShowAboutChrome(browser_);
640 break;
641 case IDC_UPGRADE_DIALOG:
642 OpenUpdateChromeDialog(browser_);
643 break;
644 case IDC_VIEW_INCOMPATIBILITIES:
645 ShowConflicts(browser_);
646 break;
647 case IDC_HELP_PAGE_VIA_KEYBOARD:
648 ShowHelp(browser_, HELP_SOURCE_KEYBOARD);
649 break;
650 case IDC_HELP_PAGE_VIA_MENU:
651 ShowHelp(browser_, HELP_SOURCE_MENU);
652 break;
Bret Sepulveda2d018662017-05-18 21:31:48653 case IDC_SHOW_BETA_FORUM:
654 ShowBetaForum(browser_);
655 break;
estade8c0780f2015-08-21 23:36:41656 case IDC_SHOW_SIGNIN:
gogerald71bf6c902015-12-08 00:49:37657 ShowBrowserSigninOrSettings(
658 browser_, signin_metrics::AccessPoint::ACCESS_POINT_MENU);
estade8c0780f2015-08-21 23:36:41659 break;
[email protected]6bd370b2014-05-28 14:19:47660 case IDC_DISTILL_PAGE:
661 DistillCurrentPage(browser_);
662 break;
apacible45cbfc92015-09-28 22:45:41663 case IDC_ROUTE_MEDIA:
664 RouteMedia(browser_);
665 break;
Tommy Steimelc4477982017-11-29 18:07:18666 case IDC_WINDOW_MUTE_SITE:
667 MuteSite(browser_);
ellyjones0101ba02017-05-19 15:50:26668 break;
669 case IDC_WINDOW_PIN_TAB:
670 PinTab(browser_);
671 break;
[email protected]5d98294912012-06-27 22:57:40672
Christopher Lam0dbac2b2017-11-14 07:12:10673 // Hosted App commands
674 case IDC_COPY_URL:
675 CopyURL(browser_);
676 break;
677 case IDC_OPEN_IN_CHROME:
678 OpenInChrome(browser_);
679 break;
680 case IDC_SITE_SETTINGS:
681 ShowSiteSettings(
682 browser_,
683 browser_->tab_strip_model()->GetActiveWebContents()->GetVisibleURL());
684 break;
Alan Cutter0c3132302018-02-21 05:09:02685 case IDC_HOSTED_APP_MENU_APP_INFO:
686 ShowPageInfoDialog(browser_->tab_strip_model()->GetActiveWebContents(),
Alan Cutter689f89a2018-03-08 05:09:54687 bubble_anchor_util::kAppMenuButton);
Christopher Lam86b52712017-12-04 01:58:33688 break;
Christopher Lam0dbac2b2017-11-14 07:12:10689
[email protected]5d98294912012-06-27 22:57:40690 default:
691 LOG(WARNING) << "Received Unimplemented Command: " << id;
692 break;
693 }
Ivan Sandrk9669d0e2017-12-15 23:50:20694
695 return true;
696}
697
698void BrowserCommandController::AddCommandObserver(int id,
699 CommandObserver* observer) {
700 command_updater_.AddCommandObserver(id, observer);
701}
702
703void BrowserCommandController::RemoveCommandObserver(
704 int id, CommandObserver* observer) {
705 command_updater_.RemoveCommandObserver(id, observer);
706}
707
708void BrowserCommandController::RemoveCommandObserver(
709 CommandObserver* observer) {
710 command_updater_.RemoveCommandObserver(observer);
711}
712
713bool BrowserCommandController::UpdateCommandEnabled(int id, bool state) {
714 if (is_locked_fullscreen_)
715 return false;
716
717 return command_updater_.UpdateCommandEnabled(id, state);
[email protected]5d98294912012-06-27 22:57:40718}
719
estade8c0780f2015-08-21 23:36:41720////////////////////////////////////////////////////////////////////////////////
721// BrowserCommandController, SigninPrefObserver implementation:
722
723void BrowserCommandController::OnSigninAllowedPrefChange() {
724 // For unit tests, we don't have a window.
725 if (!window())
726 return;
727 UpdateShowSyncState(IsShowingMainUI());
728}
729
[email protected]5d98294912012-06-27 22:57:40730// BrowserCommandController, TabStripModelObserver implementation:
731
pmonette9119e492016-09-20 22:14:55732void BrowserCommandController::TabInsertedAt(TabStripModel* tab_strip_model,
733 WebContents* contents,
[email protected]5d98294912012-06-27 22:57:40734 int index,
735 bool foreground) {
736 AddInterstitialObservers(contents);
737}
738
[email protected]e89cfcb2012-11-11 14:47:24739void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) {
[email protected]5d98294912012-06-27 22:57:40740 RemoveInterstitialObservers(contents);
741}
742
743void BrowserCommandController::TabReplacedAt(TabStripModel* tab_strip_model,
[email protected]b624ddc2012-11-15 18:04:13744 WebContents* old_contents,
745 WebContents* new_contents,
[email protected]5d98294912012-06-27 22:57:40746 int index) {
[email protected]b624ddc2012-11-15 18:04:13747 RemoveInterstitialObservers(old_contents);
748 AddInterstitialObservers(new_contents);
[email protected]5d98294912012-06-27 22:57:40749}
750
[email protected]3cac87232012-11-20 01:48:27751void BrowserCommandController::TabBlockedStateChanged(
752 content::WebContents* contents,
753 int index) {
754 PrintingStateChanged();
755 FullscreenStateChanged();
756 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:41757 UpdateCommandsForMediaRouter();
[email protected]3cac87232012-11-20 01:48:27758}
759
[email protected]5d98294912012-06-27 22:57:40760////////////////////////////////////////////////////////////////////////////////
761// BrowserCommandController, TabRestoreServiceObserver implementation:
762
763void BrowserCommandController::TabRestoreServiceChanged(
blundell74001adc2015-09-18 11:04:25764 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53765 UpdateTabRestoreCommandState();
[email protected]5d98294912012-06-27 22:57:40766}
767
768void BrowserCommandController::TabRestoreServiceDestroyed(
blundell74001adc2015-09-18 11:04:25769 sessions::TabRestoreService* service) {
[email protected]5d98294912012-06-27 22:57:40770 service->RemoveObserver(this);
771}
772
[email protected]2e9369e2014-08-15 09:12:53773void BrowserCommandController::TabRestoreServiceLoaded(
blundell74001adc2015-09-18 11:04:25774 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53775 UpdateTabRestoreCommandState();
776}
777
[email protected]5d98294912012-06-27 22:57:40778////////////////////////////////////////////////////////////////////////////////
[email protected]5d98294912012-06-27 22:57:40779// BrowserCommandController, private:
780
[email protected]20ca0382013-02-28 19:50:07781class BrowserCommandController::InterstitialObserver
782 : public content::WebContentsObserver {
783 public:
784 InterstitialObserver(BrowserCommandController* controller,
785 content::WebContents* web_contents)
786 : WebContentsObserver(web_contents),
787 controller_(controller) {
788 }
789
dcheng5dd5ff62014-10-21 12:42:38790 void DidAttachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07791 controller_->UpdateCommandsForTabState();
792 }
793
dcheng5dd5ff62014-10-21 12:42:38794 void DidDetachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07795 controller_->UpdateCommandsForTabState();
796 }
797
798 private:
799 BrowserCommandController* controller_;
800
801 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver);
802};
803
[email protected]6a414ff2013-02-27 08:22:54804bool BrowserCommandController::IsShowingMainUI() {
805 bool should_hide_ui = window() && window()->ShouldHideUIForFullscreen();
806 return browser_->is_type_tabbed() && !should_hide_ui;
[email protected]5d98294912012-06-27 22:57:40807}
808
809void BrowserCommandController::InitCommandState() {
810 // All browser commands whose state isn't set automagically some other way
811 // (like Back & Forward with initial page load) must have their state
812 // initialized here, otherwise they will be forever disabled.
813
Ivan Sandrk9669d0e2017-12-15 23:50:20814 if (is_locked_fullscreen_)
815 return;
816
[email protected]5d98294912012-06-27 22:57:40817 // Navigation commands
818 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true);
toyoshim7dad4b1182016-04-01 14:28:05819 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE, true);
[email protected]58e29032012-08-06 20:19:57820 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, true);
[email protected]5d98294912012-06-27 22:57:40821
822 // Window management commands
823 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true);
824 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true);
825 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true);
826 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true);
[email protected]2e9369e2014-08-15 09:12:53827 UpdateTabRestoreCommandState();
[email protected]d28d3782013-02-26 16:31:55828 command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
[email protected]5d98294912012-06-27 22:57:40829 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true);
[email protected]d12cc5e2013-10-19 18:25:06830#if defined(OS_CHROMEOS)
James Cook934abaf2017-09-19 22:21:58831 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
[email protected]d12cc5e2013-10-19 18:25:06832 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_2, true);
833 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_3, true);
834#endif
[email protected]893124a22014-04-15 00:45:28835#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
Tom Andersonf15ede502017-11-10 03:17:15836 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
837 command_updater_.UpdateCommandEnabled(IDC_MAXIMIZE_WINDOW, true);
838 command_updater_.UpdateCommandEnabled(IDC_RESTORE_WINDOW, true);
[email protected]af97be4c62014-02-13 14:43:34839 command_updater_.UpdateCommandEnabled(IDC_USE_SYSTEM_TITLE_BAR, true);
840#endif
Alan Cutter09965802018-03-27 07:25:29841 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_PWA_WINDOW, true);
[email protected]5d98294912012-06-27 22:57:40842
843 // Page-related commands
844 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true);
[email protected]4bee4432014-05-05 13:11:41845 command_updater_.UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE, true);
[email protected]5d98294912012-06-27 22:57:40846
847 // Zoom
848 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true);
849 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true);
[email protected]d93dbd12014-08-04 23:42:53850 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, false);
[email protected]5d98294912012-06-27 22:57:40851 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
852
853 // Show various bits of UI
mlerman7831f57d2015-05-25 11:40:15854 const bool guest_session = profile()->IsGuestSession() ||
855 profile()->IsSystemProfile();
856 DCHECK(!profile()->IsSystemProfile())
857 << "Ought to never have browser for the system profile.";
[email protected]338416c02014-05-13 16:47:06858 const bool normal_window = browser_->is_type_tabbed();
[email protected]05454532013-01-22 21:09:08859 UpdateOpenFileState(&command_updater_);
[email protected]5d98294912012-06-27 22:57:40860 UpdateCommandsForDevTools();
861 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager());
[email protected]338416c02014-05-13 16:47:06862 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session);
[email protected]5d98294912012-06-27 22:57:40863 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
[email protected]674b65672014-06-02 23:21:56864 command_updater_.UpdateCommandEnabled(IDC_HELP_MENU, true);
[email protected]5d98294912012-06-27 22:57:40865 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
866 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
Bret Sepulveda2d018662017-05-18 21:31:48867 command_updater_.UpdateCommandEnabled(IDC_SHOW_BETA_FORUM, true);
[email protected]338416c02014-05-13 16:47:06868 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session);
[email protected]2f1acc212012-11-13 10:43:51869 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU,
[email protected]338416c02014-05-13 16:47:06870 !guest_session &&
[email protected]2f1acc212012-11-13 10:43:51871 !profile()->IsOffTheRecord());
tsergeant341a8272017-04-18 03:54:33872 command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA,
873 !guest_session);
[email protected]39d47592014-01-10 21:42:45874#if defined(OS_CHROMEOS)
caelyn4e4e08a2015-02-04 21:27:49875 command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true);
[email protected]338416c02014-05-13 16:47:06876#else
877 // Chrome OS uses the system tray menu to handle multi-profiles.
anthonyvd7dc985da2015-03-23 16:53:19878 if (normal_window && (guest_session || !profile()->IsOffTheRecord())) {
[email protected]338416c02014-05-13 16:47:06879 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
anthonyvd7dc985da2015-03-23 16:53:19880 }
[email protected]39d47592014-01-10 21:42:45881#endif
[email protected]5d98294912012-06-27 22:57:40882
estade8c0780f2015-08-21 23:36:41883 UpdateShowSyncState(true);
884
[email protected]5d98294912012-06-27 22:57:40885 // Navigation commands
[email protected]c9f983d2014-02-05 09:00:24886 command_updater_.UpdateCommandEnabled(
887 IDC_HOME,
benwellsc431c0ae2015-01-27 22:04:06888 normal_window ||
889 (extensions::util::IsNewBookmarkAppsEnabled() && browser_->is_app()));
[email protected]5d98294912012-06-27 22:57:40890
Christopher Lam0dbac2b2017-11-14 07:12:10891 const bool is_experimental_hosted_app =
892 extensions::HostedAppBrowserController::IsForExperimentalHostedAppBrowser(
893 browser_);
894 // Hosted app browser commands.
895 command_updater_.UpdateCommandEnabled(IDC_COPY_URL,
896 is_experimental_hosted_app);
897 command_updater_.UpdateCommandEnabled(IDC_OPEN_IN_CHROME,
898 is_experimental_hosted_app);
899 command_updater_.UpdateCommandEnabled(IDC_SITE_SETTINGS,
900 is_experimental_hosted_app);
Alan Cutter0c3132302018-02-21 05:09:02901 command_updater_.UpdateCommandEnabled(IDC_HOSTED_APP_MENU_APP_INFO,
Christopher Lam86b52712017-12-04 01:58:33902 is_experimental_hosted_app);
Christopher Lam0dbac2b2017-11-14 07:12:10903
[email protected]5d98294912012-06-27 22:57:40904 // Window management commands
[email protected]5d98294912012-06-27 22:57:40905 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window);
906 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB,
907 normal_window);
908 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window);
909 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window);
910 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window);
911 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window);
912 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window);
913 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window);
914 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window);
915 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window);
916 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window);
917 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window);
918 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window);
[email protected]5d98294912012-06-27 22:57:40919
[email protected]338416c02014-05-13 16:47:06920 // These are always enabled; the menu determines their menu item visibility.
[email protected]5d98294912012-06-27 22:57:40921 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
922 command_updater_.UpdateCommandEnabled(IDC_VIEW_INCOMPATIBILITIES, true);
923
[email protected]6bd370b2014-05-28 14:19:47924 // Distill current page.
925 command_updater_.UpdateCommandEnabled(
avi556c05022014-12-22 23:31:43926 IDC_DISTILL_PAGE, base::CommandLine::ForCurrentProcess()->HasSwitch(
927 switches::kEnableDomDistiller));
[email protected]6bd370b2014-05-28 14:19:47928
Tommy Steimelc4477982017-11-29 18:07:18929 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE, normal_window);
ellyjones0101ba02017-05-19 15:50:26930 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB, normal_window);
931
[email protected]338416c02014-05-13 16:47:06932 // Initialize other commands whose state changes based on various conditions.
[email protected]32dfede2013-08-25 15:48:25933 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40934 UpdateCommandsForContentRestrictionState();
[email protected]5d98294912012-06-27 22:57:40935 UpdateCommandsForBookmarkEditing();
[email protected]5d98294912012-06-27 22:57:40936 UpdateCommandsForIncognitoAvailability();
937}
938
[email protected]05454532013-01-22 21:09:08939// static
940void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
941 CommandUpdater* command_updater,
942 Profile* profile) {
mlermane01e6de2014-09-29 19:26:47943 const bool guest_session = profile->IsGuestSession();
944 // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession().
[email protected]5d98294912012-06-27 22:57:40945 IncognitoModePrefs::Availability incognito_availability =
[email protected]05454532013-01-22 21:09:08946 IncognitoModePrefs::GetAvailability(profile->GetPrefs());
947 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40948 IDC_NEW_WINDOW,
949 incognito_availability != IncognitoModePrefs::FORCED);
[email protected]05454532013-01-22 21:09:08950 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40951 IDC_NEW_INCOGNITO_WINDOW,
mlermane01e6de2014-09-29 19:26:47952 incognito_availability != IncognitoModePrefs::DISABLED && !guest_session);
[email protected]5d98294912012-06-27 22:57:40953
[email protected]57b25292014-05-01 16:31:06954 const bool forced_incognito =
955 incognito_availability == IncognitoModePrefs::FORCED ||
956 guest_session; // Guest always runs in Incognito mode.
[email protected]05454532013-01-22 21:09:08957 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40958 IDC_SHOW_BOOKMARK_MANAGER,
[email protected]57b25292014-05-01 16:31:06959 browser_defaults::bookmarks_enabled && !forced_incognito);
[email protected]03d25812014-06-22 19:41:55960 ExtensionService* extension_service =
961 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]57b25292014-05-01 16:31:06962 const bool enable_extensions =
[email protected]5d98294912012-06-27 22:57:40963 extension_service && extension_service->extensions_enabled();
[email protected]5d98294912012-06-27 22:57:40964
[email protected]57b25292014-05-01 16:31:06965 // Bookmark manager and settings page/subpages are forced to open in normal
966 // mode. For this reason we disable these commands when incognito is forced.
967 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
968 enable_extensions && !forced_incognito);
969
970 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito);
971 command_updater->UpdateCommandEnabled(IDC_OPTIONS,
972 !forced_incognito || guest_session);
estade8c0780f2015-08-21 23:36:41973 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito);
[email protected]05454532013-01-22 21:09:08974}
975
976void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
Ivan Sandrk9669d0e2017-12-15 23:50:20977 if (is_locked_fullscreen_)
978 return;
979
[email protected]05454532013-01-22 21:09:08980 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile());
981
[email protected]6a414ff2013-02-27 08:22:54982 if (!IsShowingMainUI()) {
[email protected]05454532013-01-22 21:09:08983 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false);
984 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false);
985 }
[email protected]5d98294912012-06-27 22:57:40986}
987
988void BrowserCommandController::UpdateCommandsForTabState() {
Ivan Sandrk9669d0e2017-12-15 23:50:20989 if (is_locked_fullscreen_)
990 return;
991
[email protected]617ee962013-01-29 20:49:12992 WebContents* current_web_contents =
993 browser_->tab_strip_model()->GetActiveWebContents();
[email protected]1c5119c2012-09-19 00:08:57994 if (!current_web_contents) // May be NULL during tab restore.
[email protected]5d98294912012-06-27 22:57:40995 return;
[email protected]5d98294912012-06-27 22:57:40996
997 // Navigation commands
[email protected]5d98294912012-06-27 22:57:40998 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_));
[email protected]5d98294912012-06-27 22:57:40999 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_));
1000 command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_));
toyoshim7dad4b1182016-04-01 14:28:051001 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE,
[email protected]5d98294912012-06-27 22:57:401002 CanReload(browser_));
[email protected]58e29032012-08-06 20:19:571003 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE,
1004 CanReload(browser_));
[email protected]5d98294912012-06-27 22:57:401005
1006 // Window management commands
1007 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB,
1008 !browser_->is_app() && CanDuplicateTab(browser_));
Tommy Steimelc4477982017-11-29 18:07:181009 command_updater_.UpdateCommandEnabled(IDC_WINDOW_MUTE_SITE,
ellyjones0101ba02017-05-19 15:50:261010 !browser_->is_app());
1011 command_updater_.UpdateCommandEnabled(IDC_WINDOW_PIN_TAB,
1012 !browser_->is_app());
[email protected]5d98294912012-06-27 22:57:401013
1014 // Page-related commands
1015 window()->SetStarredState(
[email protected]1c5119c2012-09-19 00:08:571016 BookmarkTabHelper::FromWebContents(current_web_contents)->is_starred());
[email protected]5423c372012-08-22 05:50:161017 window()->ZoomChangedForActiveTab(false);
[email protected]5d98294912012-06-27 22:57:401018 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
1019 CanViewSource(browser_));
1020 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION,
1021 CanEmailPageLocation(browser_));
1022 if (browser_->is_devtools())
1023 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false);
1024
[email protected]92086542014-04-08 08:45:291025 command_updater_.UpdateCommandEnabled(IDC_CREATE_HOSTED_APP,
1026 CanCreateBookmarkApp(browser_));
[email protected]5d98294912012-06-27 22:57:401027
[email protected]9b7ab882012-09-10 23:46:361028 command_updater_.UpdateCommandEnabled(
1029 IDC_TOGGLE_REQUEST_TABLET_SITE,
1030 CanRequestTabletSite(current_web_contents));
1031
[email protected]5d98294912012-06-27 22:57:401032 UpdateCommandsForContentRestrictionState();
1033 UpdateCommandsForBookmarkEditing();
[email protected]3cac87232012-11-20 01:48:271034 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:411035 UpdateCommandsForMediaRouter();
[email protected]d93dbd12014-08-04 23:42:531036 // Update the zoom commands when an active tab is selected.
1037 UpdateCommandsForZoomState();
1038}
1039
1040void BrowserCommandController::UpdateCommandsForZoomState() {
1041 WebContents* contents =
1042 browser_->tab_strip_model()->GetActiveWebContents();
1043 if (!contents)
1044 return;
a.sarkar.arundaadc712015-02-26 05:39:081045 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS,
1046 CanZoomIn(contents));
1047 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL,
ccameronb7c1d6c2015-03-09 17:08:241048 CanResetZoom(contents));
a.sarkar.arundaadc712015-02-26 05:39:081049 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS,
1050 CanZoomOut(contents));
[email protected]5d98294912012-06-27 22:57:401051}
1052
1053void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
1054 int restrictions = GetContentRestrictions(browser_);
1055
1056 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011057 IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY));
[email protected]5d98294912012-06-27 22:57:401058 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011059 IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT));
[email protected]5d98294912012-06-27 22:57:401060 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011061 IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE));
[email protected]5d98294912012-06-27 22:57:401062 UpdateSaveAsState();
1063 UpdatePrintingState();
1064}
1065
1066void BrowserCommandController::UpdateCommandsForDevTools() {
Ivan Sandrk9669d0e2017-12-15 23:50:201067 if (is_locked_fullscreen_)
1068 return;
1069
[email protected]5d98294912012-06-27 22:57:401070 bool dev_tools_enabled =
1071 !profile()->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled);
1072 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS,
1073 dev_tools_enabled);
1074 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE,
1075 dev_tools_enabled);
[email protected]2056c3192013-10-21 22:40:511076 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES,
1077 dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401078 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT,
1079 dev_tools_enabled);
[email protected]d16657c2012-09-03 14:25:101080 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE,
1081 dev_tools_enabled);
spqchan2c5d541e2017-10-25 07:07:111082#if defined(OS_MACOSX)
1083 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_JAVASCRIPT_APPLE_EVENTS,
1084 dev_tools_enabled);
1085#endif
[email protected]5d98294912012-06-27 22:57:401086}
1087
1088void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
Ivan Sandrk9669d0e2017-12-15 23:50:201089 if (is_locked_fullscreen_)
1090 return;
1091
[email protected]5d98294912012-06-27 22:57:401092 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE,
1093 CanBookmarkCurrentPage(browser_));
1094 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
1095 CanBookmarkAllTabs(browser_));
thestig5149d272014-10-30 07:25:291096#if defined(OS_WIN)
1097 command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN, true);
1098#endif
[email protected]5d98294912012-06-27 22:57:401099}
1100
1101void BrowserCommandController::UpdateCommandsForBookmarkBar() {
Ivan Sandrk9669d0e2017-12-15 23:50:201102 if (is_locked_fullscreen_)
1103 return;
1104
tfarina3bddbe112014-08-28 05:29:321105 command_updater_.UpdateCommandEnabled(
1106 IDC_SHOW_BOOKMARK_BAR,
1107 browser_defaults::bookmarks_enabled && !profile()->IsGuestSession() &&
mlerman7831f57d2015-05-25 11:40:151108 !profile()->IsSystemProfile() &&
tfarina3bddbe112014-08-28 05:29:321109 !profile()->GetPrefs()->IsManagedPreference(
1110 bookmarks::prefs::kShowBookmarkBar) &&
1111 IsShowingMainUI());
[email protected]5d98294912012-06-27 22:57:401112}
1113
[email protected]9ec3ea5b2012-12-03 18:14:301114void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
Ivan Sandrk9669d0e2017-12-15 23:50:201115 if (is_locked_fullscreen_)
1116 return;
1117
[email protected]9ec3ea5b2012-12-03 18:14:301118 UpdateSaveAsState();
[email protected]05454532013-01-22 21:09:081119 UpdateOpenFileState(&command_updater_);
[email protected]9ec3ea5b2012-12-03 18:14:301120}
1121
[email protected]32dfede2013-08-25 15:48:251122void BrowserCommandController::UpdateCommandsForFullscreenMode() {
Ivan Sandrk9669d0e2017-12-15 23:50:201123 if (is_locked_fullscreen_)
1124 return;
1125
zijiehe3c7af992017-02-12 20:59:401126 const bool is_fullscreen = window() && window()->IsFullscreen();
1127 const bool show_main_ui = IsShowingMainUI();
1128 const bool main_not_fullscreen = show_main_ui && !is_fullscreen;
[email protected]5d98294912012-06-27 22:57:401129
1130 // Navigation commands
1131 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1132
1133 // Window management commands
1134 command_updater_.UpdateCommandEnabled(
1135 IDC_SHOW_AS_TAB,
zijiehe3c7af992017-02-12 20:59:401136 !browser_->is_type_tabbed() && !is_fullscreen);
[email protected]5d98294912012-06-27 22:57:401137
1138 // Focus various bits of UI
1139 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
1140 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui);
1141 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
1142 command_updater_.UpdateCommandEnabled(
1143 IDC_FOCUS_MENU_BAR, main_not_fullscreen);
1144 command_updater_.UpdateCommandEnabled(
1145 IDC_FOCUS_NEXT_PANE, main_not_fullscreen);
1146 command_updater_.UpdateCommandEnabled(
1147 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen);
1148 command_updater_.UpdateCommandEnabled(
1149 IDC_FOCUS_BOOKMARKS, main_not_fullscreen);
[email protected]822ca8c62013-04-19 00:49:151150 command_updater_.UpdateCommandEnabled(
David Tsengc0b1b642018-01-24 07:12:271151 IDC_FOCUS_INACTIVE_POPUP_FOR_ACCESSIBILITY, main_not_fullscreen);
[email protected]5d98294912012-06-27 22:57:401152
1153 // Show various bits of UI
1154 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431155#if defined(GOOGLE_CHROME_BUILD)
[email protected]5d98294912012-06-27 22:57:401156 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431157#endif
estade8c0780f2015-08-21 23:36:411158 UpdateShowSyncState(show_main_ui);
[email protected]5d98294912012-06-27 22:57:401159
[email protected]5d98294912012-06-27 22:57:401160 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
1161 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
1162 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
1163 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
primianod3a81ab2016-01-25 22:21:151164
1165 if (base::debug::IsProfilingSupported())
1166 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
[email protected]5d98294912012-06-27 22:57:401167
[email protected]aeafc3852014-04-29 16:51:291168#if !defined(OS_MACOSX)
zijiehe3c7af992017-02-12 20:59:401169 // Disable toggling into fullscreen mode if disallowed by pref.
1170 const bool fullscreen_enabled = is_fullscreen ||
1171 profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed);
1172#else
1173 const bool fullscreen_enabled = true;
[email protected]00a1cc5b2012-11-07 13:44:511174#endif
1175
1176 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled);
spqchanb8ffc7d2015-11-17 01:17:211177 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR,
1178 fullscreen_enabled);
[email protected]5d98294912012-06-27 22:57:401179
1180 UpdateCommandsForBookmarkBar();
zijiehedb473d552017-02-24 01:13:411181 UpdateCommandsForIncognitoAvailability();
Alan Cutter167dfe82018-04-11 09:06:001182 UpdateCommandsForHostedAppAvailability();
1183}
1184
1185void BrowserCommandController::UpdateCommandsForHostedAppAvailability() {
1186 bool has_toolbar =
1187 browser_->is_type_tabbed() ||
1188 extensions::HostedAppBrowserController::IsForExperimentalHostedAppBrowser(
1189 browser_);
1190 if (window() && window()->ShouldHideUIForFullscreen())
1191 has_toolbar = false;
1192 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, has_toolbar);
1193 command_updater_.UpdateCommandEnabled(IDC_FOCUS_NEXT_PANE, has_toolbar);
1194 command_updater_.UpdateCommandEnabled(IDC_FOCUS_PREVIOUS_PANE, has_toolbar);
1195 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, has_toolbar);
[email protected]5d98294912012-06-27 22:57:401196}
1197
Ivan Sandrk9669d0e2017-12-15 23:50:201198#if defined(OS_CHROMEOS)
1199namespace {
1200
1201#if DCHECK_IS_ON()
1202// Makes sure that all commands that are not whitelisted are disabled. DCHECKs
1203// otherwise. Compiled only in debug mode.
1204void NonWhitelistedCommandsAreDisabled(CommandUpdaterImpl* command_updater) {
1205 constexpr int kWhitelistedIds[] = {
1206 IDC_CUT, IDC_COPY, IDC_PASTE,
1207 IDC_FIND, IDC_FIND_NEXT, IDC_FIND_PREVIOUS,
1208 IDC_ZOOM_PLUS, IDC_ZOOM_NORMAL, IDC_ZOOM_MINUS,
1209 };
1210
1211 // Go through all the command ids, skip the whitelisted ones.
1212 for (int id : command_updater->GetAllIds()) {
1213 if (std::find(std::begin(kWhitelistedIds), std::end(kWhitelistedIds), id)
1214 != std::end(kWhitelistedIds)) {
1215 continue;
1216 }
1217 DCHECK(!command_updater->IsCommandEnabled(id));
1218 }
1219}
1220#endif
1221
1222} // namespace
1223
1224void BrowserCommandController::UpdateCommandsForLockedFullscreenMode() {
Ivan Sandrk9669d0e2017-12-15 23:50:201225 bool is_locked_fullscreen = ash::IsWindowTrustedPinned(browser_->window());
1226 // Sanity check to make sure this function is called only on state change.
1227 DCHECK_NE(is_locked_fullscreen, is_locked_fullscreen_);
1228 if (is_locked_fullscreen == is_locked_fullscreen_)
1229 return;
1230 is_locked_fullscreen_ = is_locked_fullscreen;
1231
1232 if (is_locked_fullscreen_) {
1233 command_updater_.DisableAllCommands();
1234 // Update the state of whitelisted commands:
1235 // IDC_CUT/IDC_COPY/IDC_PASTE,
1236 UpdateCommandsForContentRestrictionState();
1237 // IDC_FIND/IDC_FIND_NEXT/IDC_FIND_PREVIOUS,
1238 UpdateCommandsForFind();
1239 // IDC_ZOOM_PLUS/IDC_ZOOM_NORMAL/IDC_ZOOM_MINUS.
1240 UpdateCommandsForZoomState();
1241 // All other commands will be disabled (there is an early return in their
1242 // corresponding UpdateCommandsFor* functions).
1243#if DCHECK_IS_ON()
1244 NonWhitelistedCommandsAreDisabled(&command_updater_);
1245#endif
1246 } else {
1247 // Do an init call to re-initialize command state after the
1248 // DisableAllCommands.
1249 InitCommandState();
1250 }
1251}
1252#endif
1253
[email protected]5d98294912012-06-27 22:57:401254void BrowserCommandController::UpdatePrintingState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201255 if (is_locked_fullscreen_)
1256 return;
1257
[email protected]d53e4032012-06-29 18:58:341258 bool print_enabled = CanPrint(browser_);
1259 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
Lei Zhang48a4a5262018-04-17 20:18:441260#if BUILDFLAG(ENABLE_PRINTING)
vitalybukaf9433e42014-09-08 10:04:551261 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT,
1262 CanBasicPrint(browser_));
Lei Zhang48a4a5262018-04-17 20:18:441263#endif
[email protected]5d98294912012-06-27 22:57:401264}
1265
1266void BrowserCommandController::UpdateSaveAsState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201267 if (is_locked_fullscreen_)
1268 return;
1269
[email protected]5d98294912012-06-27 22:57:401270 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_));
1271}
1272
estade8c0780f2015-08-21 23:36:411273void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) {
Ivan Sandrk9669d0e2017-12-15 23:50:201274 if (is_locked_fullscreen_)
1275 return;
1276
estade8c0780f2015-08-21 23:36:411277 command_updater_.UpdateCommandEnabled(
1278 IDC_SHOW_SYNC_SETUP, show_main_ui && pref_signin_allowed_.GetValue());
1279}
1280
[email protected]05454532013-01-22 21:09:081281// static
1282void BrowserCommandController::UpdateOpenFileState(
1283 CommandUpdater* command_updater) {
[email protected]5d98294912012-06-27 22:57:401284 bool enabled = true;
1285 PrefService* local_state = g_browser_process->local_state();
1286 if (local_state)
1287 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs);
1288
[email protected]05454532013-01-22 21:09:081289 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled);
[email protected]5d98294912012-06-27 22:57:401290}
1291
1292void BrowserCommandController::UpdateReloadStopState(bool is_loading,
1293 bool force) {
Ivan Sandrk9669d0e2017-12-15 23:50:201294 if (is_locked_fullscreen_)
1295 return;
1296
[email protected]5d98294912012-06-27 22:57:401297 window()->UpdateReloadStopState(is_loading, force);
1298 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
1299}
1300
[email protected]2e9369e2014-08-15 09:12:531301void BrowserCommandController::UpdateTabRestoreCommandState() {
Ivan Sandrk9669d0e2017-12-15 23:50:201302 if (is_locked_fullscreen_)
1303 return;
1304
blundell74001adc2015-09-18 11:04:251305 sessions::TabRestoreService* tab_restore_service =
[email protected]2e9369e2014-08-15 09:12:531306 TabRestoreServiceFactory::GetForProfile(profile());
1307 // The command is enabled if the service hasn't loaded yet to trigger loading.
1308 // The command is updated once the load completes.
1309 command_updater_.UpdateCommandEnabled(
1310 IDC_RESTORE_TAB,
1311 tab_restore_service &&
1312 (!tab_restore_service->IsLoaded() ||
1313 GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE));
1314}
1315
[email protected]3cac87232012-11-20 01:48:271316void BrowserCommandController::UpdateCommandsForFind() {
1317 TabStripModel* model = browser_->tab_strip_model();
1318 bool enabled = !model->IsTabBlocked(model->active_index()) &&
1319 !browser_->is_devtools();
1320
1321 command_updater_.UpdateCommandEnabled(IDC_FIND, enabled);
1322 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled);
1323 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled);
1324}
1325
apacible45cbfc92015-09-28 22:45:411326void BrowserCommandController::UpdateCommandsForMediaRouter() {
Ivan Sandrk9669d0e2017-12-15 23:50:201327 if (is_locked_fullscreen_)
1328 return;
1329
apacible45cbfc92015-09-28 22:45:411330 command_updater_.UpdateCommandEnabled(IDC_ROUTE_MEDIA,
1331 CanRouteMedia(browser_));
1332}
1333
[email protected]409ea2972012-11-10 19:54:431334void BrowserCommandController::AddInterstitialObservers(WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071335 interstitial_observers_.push_back(new InterstitialObserver(this, contents));
[email protected]5d98294912012-06-27 22:57:401336}
1337
1338void BrowserCommandController::RemoveInterstitialObservers(
[email protected]e89cfcb2012-11-11 14:47:241339 WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071340 for (size_t i = 0; i < interstitial_observers_.size(); i++) {
1341 if (interstitial_observers_[i]->web_contents() != contents)
1342 continue;
1343
1344 delete interstitial_observers_[i];
1345 interstitial_observers_.erase(interstitial_observers_.begin() + i);
1346 return;
1347 }
[email protected]5d98294912012-06-27 22:57:401348}
1349
1350BrowserWindow* BrowserCommandController::window() {
1351 return browser_->window();
1352}
1353
1354Profile* BrowserCommandController::profile() {
1355 return browser_->profile();
1356}
1357
[email protected]5d98294912012-06-27 22:57:401358} // namespace chrome