blob: c624c8cef54e83964f946316becedc81e79a776d [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"
brettwfb87ed22015-12-05 00:44:1512#include "base/debug/debugging_flags.h"
primianod3a81ab2016-01-25 22:21:1513#include "base/debug/profiler.h"
avi655876a2015-12-25 07:18:1514#include "base/macros.h"
avi655876a2015-12-25 07:18:1515#include "build/build_config.h"
[email protected]5d98294912012-06-27 22:57:4016#include "chrome/app/chrome_command_ids.h"
17#include "chrome/browser/browser_process.h"
[email protected]dcc8fbc2013-07-12 00:54:0918#include "chrome/browser/chrome_notification_types.h"
[email protected]5d98294912012-06-27 22:57:4019#include "chrome/browser/defaults.h"
20#include "chrome/browser/extensions/extension_service.h"
benwells39f23ae2014-08-27 08:01:5221#include "chrome/browser/extensions/extension_util.h"
[email protected]2e9d79f2013-08-16 05:45:5622#include "chrome/browser/lifetime/application_lifetime.h"
[email protected]5d98294912012-06-27 22:57:4023#include "chrome/browser/prefs/incognito_mode_prefs.h"
[email protected]5d98294912012-06-27 22:57:4024#include "chrome/browser/profiles/profile.h"
mlermane01e6de2014-09-29 19:26:4725#include "chrome/browser/profiles/profile_manager.h"
[email protected]5d98294912012-06-27 22:57:4026#include "chrome/browser/sessions/tab_restore_service_factory.h"
[email protected]0b32f9b62012-09-17 19:08:0327#include "chrome/browser/shell_integration.h"
[email protected]3d27d272013-07-31 03:15:1628#include "chrome/browser/signin/signin_promo.h"
[email protected]5d98294912012-06-27 22:57:4029#include "chrome/browser/sync/profile_sync_service_factory.h"
30#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
31#include "chrome/browser/ui/browser.h"
32#include "chrome/browser/ui/browser_commands.h"
33#include "chrome/browser/ui/browser_window.h"
34#include "chrome/browser/ui/chrome_pages.h"
[email protected]5d98294912012-06-27 22:57:4035#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]00a1cc5b2012-11-07 13:44:5136#include "chrome/browser/ui/tabs/tab_strip_model_utils.h"
[email protected]2056c3192013-10-21 22:40:5137#include "chrome/browser/ui/webui/inspect_ui.h"
[email protected]3c71576ce2013-07-23 02:00:0138#include "chrome/common/content_restriction.h"
[email protected]5d98294912012-06-27 22:57:4039#include "chrome/common/pref_names.h"
40#include "chrome/common/profiling.h"
brettwe1f0af8b2015-10-09 21:30:4641#include "components/bookmarks/common/bookmark_pref_names.h"
blundell7282b512015-11-09 07:21:1142#include "components/browser_sync/browser/profile_sync_service.h"
sdefresne0f2ef352015-07-27 19:18:0043#include "components/dom_distiller/core/dom_distiller_switches.h"
brettwb1fc1b82016-02-02 00:19:0844#include "components/prefs/pref_service.h"
blundella08c5dd2015-09-18 06:14:1645#include "components/sessions/core/tab_restore_service.h"
brettwe1f0af8b2015-10-09 21:30:4646#include "components/signin/core/common/signin_pref_names.h"
[email protected]5d98294912012-06-27 22:57:4047#include "content/public/browser/native_web_keyboard_event.h"
48#include "content/public/browser/navigation_controller.h"
49#include "content/public/browser/navigation_entry.h"
[email protected]6708dbc2012-11-04 00:17:2250#include "content/public/browser/user_metrics.h"
[email protected]5d98294912012-06-27 22:57:4051#include "content/public/browser/web_contents.h"
[email protected]20ca0382013-02-28 19:50:0752#include "content/public/browser/web_contents_observer.h"
[email protected]5d98294912012-06-27 22:57:4053#include "content/public/common/url_constants.h"
[email protected]03d25812014-06-22 19:41:5554#include "extensions/browser/extension_system.h"
[email protected]7e9acd082013-09-17 23:31:1655#include "ui/events/keycodes/keyboard_codes.h"
[email protected]5d98294912012-06-27 22:57:4056
[email protected]9c4d68332013-01-30 13:34:4157#if defined(OS_MACOSX)
58#include "chrome/browser/ui/browser_commands_mac.h"
59#endif
60
[email protected]5d98294912012-06-27 22:57:4061#if defined(OS_WIN)
[email protected]a43ed002013-02-05 19:47:5462#include "base/win/windows_version.h"
[email protected]2d0f80f2013-11-01 22:47:1863#include "content/public/browser/gpu_data_manager.h"
[email protected]5d98294912012-06-27 22:57:4064#endif
65
[email protected]4b0bcef2012-09-27 00:20:5666#if defined(USE_ASH)
[email protected]fa9412762013-09-04 23:31:3367#include "ash/accelerators/accelerator_commands.h"
[email protected]4b0bcef2012-09-27 00:20:5668#include "chrome/browser/ui/ash/ash_util.h"
69#endif
70
[email protected]d12cc5e2013-10-19 18:25:0671#if defined(OS_CHROMEOS)
[email protected]7c43e7fe2013-11-01 13:35:1772#include "ash/multi_profile_uma.h"
[email protected]fdf74bf2014-04-30 21:24:0273#include "ash/session/session_state_delegate.h"
[email protected]d12cc5e2013-10-19 18:25:0674#include "ash/shell.h"
[email protected]0c930812014-01-30 18:01:4775#include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h"
[email protected]5226f1e2013-11-09 04:12:1076#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.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)
81#include "ui/events/linux/text_edit_key_bindings_delegate_auralinux.h"
[email protected]1e2172f2014-04-01 17:32:3482#endif
83
[email protected]5d98294912012-06-27 22:57:4084using content::NavigationEntry;
85using content::NavigationController;
86using content::WebContents;
87
88namespace {
89
[email protected]32dfede2013-08-25 15:48:2590enum WindowState {
91 // Not in fullscreen mode.
92 WINDOW_STATE_NOT_FULLSCREEN,
93
94 // Fullscreen mode, occupying the whole screen.
95 WINDOW_STATE_FULLSCREEN,
[email protected]32dfede2013-08-25 15:48:2596};
97
[email protected]5d98294912012-06-27 22:57:4098// Returns |true| if entry has an internal chrome:// URL, |false| otherwise.
99bool HasInternalURL(const NavigationEntry* entry) {
100 if (!entry)
101 return false;
102
103 // Check the |virtual_url()| first. This catches regular chrome:// URLs
104 // including URLs that were rewritten (such as chrome://bookmarks).
[email protected]2d9748b22014-02-11 00:17:29105 if (entry->GetVirtualURL().SchemeIs(content::kChromeUIScheme))
[email protected]5d98294912012-06-27 22:57:40106 return true;
107
108 // If the |virtual_url()| isn't a chrome:// URL, check if it's actually
109 // view-source: of a chrome:// URL.
[email protected]dbdda5402013-05-30 22:13:48110 if (entry->GetVirtualURL().SchemeIs(content::kViewSourceScheme))
[email protected]2d9748b22014-02-11 00:17:29111 return entry->GetURL().SchemeIs(content::kChromeUIScheme);
[email protected]5d98294912012-06-27 22:57:40112
113 return false;
114}
115
[email protected]5d98294912012-06-27 22:57:40116} // namespace
117
118namespace chrome {
119
120///////////////////////////////////////////////////////////////////////////////
121// BrowserCommandController, public:
122
[email protected]338416c02014-05-13 16:47:06123BrowserCommandController::BrowserCommandController(Browser* browser)
[email protected]5d98294912012-06-27 22:57:40124 : browser_(browser),
[email protected]d4b2d232013-04-30 21:14:23125 command_updater_(this),
[email protected]5d98294912012-06-27 22:57:40126 block_command_execution_(false),
127 last_blocked_command_id_(-1),
128 last_blocked_command_disposition_(CURRENT_TAB) {
[email protected]5d98294912012-06-27 22:57:40129 browser_->tab_strip_model()->AddObserver(this);
130 PrefService* local_state = g_browser_process->local_state();
131 if (local_state) {
132 local_pref_registrar_.Init(local_state);
[email protected]9ec3ea5b2012-12-03 18:14:30133 local_pref_registrar_.Add(
134 prefs::kAllowFileSelectionDialogs,
135 base::Bind(
136 &BrowserCommandController::UpdateCommandsForFileSelectionDialogs,
137 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40138 }
139
140 profile_pref_registrar_.Init(profile()->GetPrefs());
[email protected]9ec3ea5b2012-12-03 18:14:30141 profile_pref_registrar_.Add(
142 prefs::kDevToolsDisabled,
143 base::Bind(&BrowserCommandController::UpdateCommandsForDevTools,
144 base::Unretained(this)));
145 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32146 bookmarks::prefs::kEditBookmarksEnabled,
[email protected]9ec3ea5b2012-12-03 18:14:30147 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkEditing,
148 base::Unretained(this)));
149 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32150 bookmarks::prefs::kShowBookmarkBar,
[email protected]9ec3ea5b2012-12-03 18:14:30151 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkBar,
152 base::Unretained(this)));
153 profile_pref_registrar_.Add(
154 prefs::kIncognitoModeAvailability,
155 base::Bind(
156 &BrowserCommandController::UpdateCommandsForIncognitoAvailability,
157 base::Unretained(this)));
158 profile_pref_registrar_.Add(
159 prefs::kPrintingEnabled,
160 base::Bind(&BrowserCommandController::UpdatePrintingState,
161 base::Unretained(this)));
[email protected]32dfede2013-08-25 15:48:25162#if !defined(OS_MACOSX)
163 profile_pref_registrar_.Add(
164 prefs::kFullscreenAllowed,
165 base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode,
166 base::Unretained(this)));
167#endif
estade8c0780f2015-08-21 23:36:41168 pref_signin_allowed_.Init(
169 prefs::kSigninAllowed,
170 profile()->GetOriginalProfile()->GetPrefs(),
171 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange,
172 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40173
174 InitCommandState();
175
blundell74001adc2015-09-18 11:04:25176 sessions::TabRestoreService* tab_restore_service =
[email protected]5d98294912012-06-27 22:57:40177 TabRestoreServiceFactory::GetForProfile(profile());
178 if (tab_restore_service) {
179 tab_restore_service->AddObserver(this);
180 TabRestoreServiceChanged(tab_restore_service);
181 }
[email protected]5d98294912012-06-27 22:57:40182}
183
184BrowserCommandController::~BrowserCommandController() {
[email protected]95e39472012-10-05 23:37:36185 // TabRestoreService may have been shutdown by the time we get here. Don't
186 // trigger creating it.
blundell74001adc2015-09-18 11:04:25187 sessions::TabRestoreService* tab_restore_service =
[email protected]95e39472012-10-05 23:37:36188 TabRestoreServiceFactory::GetForProfileIfExisting(profile());
[email protected]5d98294912012-06-27 22:57:40189 if (tab_restore_service)
190 tab_restore_service->RemoveObserver(this);
191 profile_pref_registrar_.RemoveAll();
192 local_pref_registrar_.RemoveAll();
193 browser_->tab_strip_model()->RemoveObserver(this);
[email protected]5d98294912012-06-27 22:57:40194}
195
196bool BrowserCommandController::IsReservedCommandOrKey(
197 int command_id,
198 const content::NativeWebKeyboardEvent& event) {
199 // In Apps mode, no keys are reserved.
200 if (browser_->is_app())
201 return false;
202
203#if defined(OS_CHROMEOS)
[email protected]397abd32013-08-21 05:44:19204 // On Chrome OS, the top row of keys are mapped to browser actions like
205 // back/forward or refresh. We don't want web pages to be able to change the
206 // behavior of these keys. Ash handles F4 and up; this leaves us needing to
207 // reserve browser back/forward and refresh here.
[email protected]5d98294912012-06-27 22:57:40208 ui::KeyboardCode key_code =
[email protected]3642e2d2012-10-29 21:31:14209 static_cast<ui::KeyboardCode>(event.windowsKeyCode);
[email protected]397abd32013-08-21 05:44:19210 if ((key_code == ui::VKEY_BROWSER_BACK && command_id == IDC_BACK) ||
211 (key_code == ui::VKEY_BROWSER_FORWARD && command_id == IDC_FORWARD) ||
212 (key_code == ui::VKEY_BROWSER_REFRESH && command_id == IDC_RELOAD)) {
[email protected]5d98294912012-06-27 22:57:40213 return true;
214 }
215#endif
216
217 if (window()->IsFullscreen() && command_id == IDC_FULLSCREEN)
218 return true;
[email protected]1e2172f2014-04-01 17:32:34219
[email protected]893124a22014-04-15 00:45:28220#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]1e2172f2014-04-01 17:32:34221 // If this key was registered by the user as a content editing hotkey, then
222 // it is not reserved.
[email protected]d5bedb6d2014-04-08 10:49:32223 ui::TextEditKeyBindingsDelegateAuraLinux* delegate =
[email protected]1e2172f2014-04-01 17:32:34224 ui::GetTextEditKeyBindingsDelegate();
[email protected]47e8e7542014-04-03 07:52:42225 if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL))
[email protected]1e2172f2014-04-01 17:32:34226 return false;
227#endif
228
[email protected]5d98294912012-06-27 22:57:40229 return command_id == IDC_CLOSE_TAB ||
230 command_id == IDC_CLOSE_WINDOW ||
231 command_id == IDC_NEW_INCOGNITO_WINDOW ||
232 command_id == IDC_NEW_TAB ||
233 command_id == IDC_NEW_WINDOW ||
234 command_id == IDC_RESTORE_TAB ||
235 command_id == IDC_SELECT_NEXT_TAB ||
236 command_id == IDC_SELECT_PREVIOUS_TAB ||
[email protected]3642e2d2012-10-29 21:31:14237 command_id == IDC_EXIT;
[email protected]5d98294912012-06-27 22:57:40238}
239
240void BrowserCommandController::SetBlockCommandExecution(bool block) {
241 block_command_execution_ = block;
242 if (block) {
243 last_blocked_command_id_ = -1;
244 last_blocked_command_disposition_ = CURRENT_TAB;
245 }
246}
247
248int BrowserCommandController::GetLastBlockedCommand(
249 WindowOpenDisposition* disposition) {
250 if (disposition)
251 *disposition = last_blocked_command_disposition_;
252 return last_blocked_command_id_;
253}
254
255void BrowserCommandController::TabStateChanged() {
256 UpdateCommandsForTabState();
257}
258
[email protected]d93dbd12014-08-04 23:42:53259void BrowserCommandController::ZoomStateChanged() {
260 UpdateCommandsForZoomState();
261}
262
[email protected]5d98294912012-06-27 22:57:40263void BrowserCommandController::ContentRestrictionsChanged() {
264 UpdateCommandsForContentRestrictionState();
265}
266
267void BrowserCommandController::FullscreenStateChanged() {
[email protected]32dfede2013-08-25 15:48:25268 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40269}
270
271void BrowserCommandController::PrintingStateChanged() {
272 UpdatePrintingState();
273}
274
275void BrowserCommandController::LoadingStateChanged(bool is_loading,
276 bool force) {
277 UpdateReloadStopState(is_loading, force);
278}
279
wittman76df71db32014-12-18 23:26:58280void BrowserCommandController::ExtensionStateChanged() {
281 // Extensions may disable the bookmark editing commands.
282 UpdateCommandsForBookmarkEditing();
283}
284
[email protected]5d98294912012-06-27 22:57:40285////////////////////////////////////////////////////////////////////////////////
[email protected]de0d0f42012-12-06 21:27:11286// BrowserCommandController, CommandUpdaterDelegate implementation:
[email protected]5d98294912012-06-27 22:57:40287
288void BrowserCommandController::ExecuteCommandWithDisposition(
[email protected]de0d0f42012-12-06 21:27:11289 int id,
290 WindowOpenDisposition disposition) {
[email protected]5d98294912012-06-27 22:57:40291 // No commands are enabled if there is not yet any selected tab.
292 // TODO(pkasting): It seems like we should not need this, because either
293 // most/all commands should not have been enabled yet anyway or the ones that
294 // are enabled should be global, or safe themselves against having no selected
295 // tab. However, Ben says he tried removing this before and got lots of
296 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
297 // window construction. This probably could use closer examination someday.
[email protected]59253a652012-11-20 00:17:26298 if (browser_->tab_strip_model()->active_index() == TabStripModel::kNoTab)
[email protected]5d98294912012-06-27 22:57:40299 return;
300
301 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command "
302 << id;
303
304 // If command execution is blocked then just record the command and return.
305 if (block_command_execution_) {
306 // We actually only allow no more than one blocked command, otherwise some
307 // commands maybe lost.
308 DCHECK_EQ(last_blocked_command_id_, -1);
309 last_blocked_command_id_ = id;
310 last_blocked_command_disposition_ = disposition;
311 return;
312 }
313
314 // The order of commands in this switch statement must match the function
315 // declaration order in browser.h!
316 switch (id) {
317 // Navigation commands
318 case IDC_BACK:
319 GoBack(browser_, disposition);
320 break;
321 case IDC_FORWARD:
322 GoForward(browser_, disposition);
323 break;
324 case IDC_RELOAD:
325 Reload(browser_, disposition);
326 break;
[email protected]58e29032012-08-06 20:19:57327 case IDC_RELOAD_CLEARING_CACHE:
328 ClearCache(browser_);
329 // FALL THROUGH
toyoshim7dad4b1182016-04-01 14:28:05330 case IDC_RELOAD_BYPASSING_CACHE:
331 ReloadBypassingCache(browser_, disposition);
[email protected]5d98294912012-06-27 22:57:40332 break;
333 case IDC_HOME:
334 Home(browser_, disposition);
335 break;
336 case IDC_OPEN_CURRENT_URL:
337 OpenCurrentURL(browser_);
338 break;
339 case IDC_STOP:
340 Stop(browser_);
341 break;
342
343 // Window management commands
344 case IDC_NEW_WINDOW:
345 NewWindow(browser_);
346 break;
347 case IDC_NEW_INCOGNITO_WINDOW:
348 NewIncognitoWindow(browser_);
349 break;
350 case IDC_CLOSE_WINDOW:
[email protected]e6e30ac2014-01-13 21:24:39351 content::RecordAction(base::UserMetricsAction("CloseWindowByKey"));
[email protected]04b9e692012-08-24 14:49:09352 CloseWindow(browser_);
[email protected]5d98294912012-06-27 22:57:40353 break;
354 case IDC_NEW_TAB:
355 NewTab(browser_);
356 break;
357 case IDC_CLOSE_TAB:
[email protected]e6e30ac2014-01-13 21:24:39358 content::RecordAction(base::UserMetricsAction("CloseTabByKey"));
[email protected]04b9e692012-08-24 14:49:09359 CloseTab(browser_);
[email protected]5d98294912012-06-27 22:57:40360 break;
361 case IDC_SELECT_NEXT_TAB:
[email protected]e6e30ac2014-01-13 21:24:39362 content::RecordAction(base::UserMetricsAction("Accel_SelectNextTab"));
[email protected]5d98294912012-06-27 22:57:40363 SelectNextTab(browser_);
364 break;
365 case IDC_SELECT_PREVIOUS_TAB:
[email protected]0db969d2013-05-30 18:26:16366 content::RecordAction(
[email protected]e6e30ac2014-01-13 21:24:39367 base::UserMetricsAction("Accel_SelectPreviousTab"));
[email protected]5d98294912012-06-27 22:57:40368 SelectPreviousTab(browser_);
369 break;
[email protected]5d98294912012-06-27 22:57:40370 case IDC_MOVE_TAB_NEXT:
371 MoveTabNext(browser_);
372 break;
373 case IDC_MOVE_TAB_PREVIOUS:
374 MoveTabPrevious(browser_);
375 break;
376 case IDC_SELECT_TAB_0:
377 case IDC_SELECT_TAB_1:
378 case IDC_SELECT_TAB_2:
379 case IDC_SELECT_TAB_3:
380 case IDC_SELECT_TAB_4:
381 case IDC_SELECT_TAB_5:
382 case IDC_SELECT_TAB_6:
383 case IDC_SELECT_TAB_7:
384 SelectNumberedTab(browser_, id - IDC_SELECT_TAB_0);
385 break;
386 case IDC_SELECT_LAST_TAB:
387 SelectLastTab(browser_);
388 break;
389 case IDC_DUPLICATE_TAB:
390 DuplicateTab(browser_);
391 break;
392 case IDC_RESTORE_TAB:
393 RestoreTab(browser_);
394 break;
[email protected]5d98294912012-06-27 22:57:40395 case IDC_SHOW_AS_TAB:
396 ConvertPopupToTabbedBrowser(browser_);
397 break;
398 case IDC_FULLSCREEN:
[email protected]9c4d68332013-01-30 13:34:41399#if defined(OS_MACOSX)
andresantosob5753852014-11-21 23:07:56400 chrome::ToggleFullscreenWithToolbarOrFallback(browser_);
[email protected]9c4d68332013-01-30 13:34:41401#else
[email protected]3f32b9b2012-07-09 16:59:28402 chrome::ToggleFullscreenMode(browser_);
[email protected]9c4d68332013-01-30 13:34:41403#endif
[email protected]5d98294912012-06-27 22:57:40404 break;
[email protected]770c6d82012-09-06 22:21:32405
[email protected]d12cc5e2013-10-19 18:25:06406#if defined(OS_CHROMEOS)
407 case IDC_VISIT_DESKTOP_OF_LRU_USER_2:
[email protected]0c930812014-01-30 18:01:47408 case IDC_VISIT_DESKTOP_OF_LRU_USER_3:
409 ExecuteVisitDesktopCommand(id, browser_->window()->GetNativeWindow());
410 break;
[email protected]d12cc5e2013-10-19 18:25:06411#endif
412
[email protected]893124a22014-04-15 00:45:28413#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]af97be4c62014-02-13 14:43:34414 case IDC_USE_SYSTEM_TITLE_BAR: {
415 PrefService* prefs = browser_->profile()->GetPrefs();
416 prefs->SetBoolean(prefs::kUseCustomChromeFrame,
417 !prefs->GetBoolean(prefs::kUseCustomChromeFrame));
418 break;
419 }
420#endif
421
[email protected]5d98294912012-06-27 22:57:40422#if defined(OS_MACOSX)
423 case IDC_PRESENTATION_MODE:
[email protected]9c4d68332013-01-30 13:34:41424 chrome::ToggleFullscreenMode(browser_);
[email protected]5d98294912012-06-27 22:57:40425 break;
spqchanb8ffc7d2015-11-17 01:17:21426 case IDC_TOGGLE_FULLSCREEN_TOOLBAR:
427 chrome::ToggleFullscreenToolbar(browser_);
428 break;
[email protected]5d98294912012-06-27 22:57:40429#endif
430 case IDC_EXIT:
431 Exit();
432 break;
433
434 // Page-related commands
435 case IDC_SAVE_PAGE:
436 SavePage(browser_);
437 break;
438 case IDC_BOOKMARK_PAGE:
deepak.m154a7f392014-12-15 04:41:43439 BookmarkCurrentPageAllowingExtensionOverrides(browser_);
[email protected]5d98294912012-06-27 22:57:40440 break;
[email protected]5d98294912012-06-27 22:57:40441 case IDC_BOOKMARK_ALL_TABS:
442 BookmarkAllTabs(browser_);
443 break;
444 case IDC_VIEW_SOURCE:
445 ViewSelectedSource(browser_);
446 break;
447 case IDC_EMAIL_PAGE_LOCATION:
448 EmailPageLocation(browser_);
449 break;
450 case IDC_PRINT:
451 Print(browser_);
452 break;
bondd052b5f82015-10-28 22:39:32453
vitalybukae29991c2014-11-05 21:15:12454#if defined(ENABLE_BASIC_PRINTING)
vitalybukaf9433e42014-09-08 10:04:55455 case IDC_BASIC_PRINT:
[email protected]e6e30ac2014-01-13 21:24:39456 content::RecordAction(base::UserMetricsAction("Accel_Advanced_Print"));
vitalybukaf9433e42014-09-08 10:04:55457 BasicPrint(browser_);
[email protected]5d98294912012-06-27 22:57:40458 break;
vitalybukae29991c2014-11-05 21:15:12459#endif // ENABLE_BASIC_PRINTING
bondd052b5f82015-10-28 22:39:32460
bondd052b5f82015-10-28 22:39:32461 case IDC_SAVE_CREDIT_CARD_FOR_PAGE:
462 SaveCreditCard(browser_);
463 break;
[email protected]e625b7602013-10-28 09:24:56464 case IDC_TRANSLATE_PAGE:
465 Translate(browser_);
466 break;
[email protected]4bee4432014-05-05 13:11:41467 case IDC_MANAGE_PASSWORDS_FOR_PAGE:
468 ManagePasswordsForPage(browser_);
469 break;
470
471 // Page encoding commands
[email protected]5d98294912012-06-27 22:57:40472 case IDC_ENCODING_AUTO_DETECT:
473 browser_->ToggleEncodingAutoDetect();
474 break;
475 case IDC_ENCODING_UTF8:
476 case IDC_ENCODING_UTF16LE:
[email protected]5d98294912012-06-27 22:57:40477 case IDC_ENCODING_WINDOWS1252:
478 case IDC_ENCODING_GBK:
479 case IDC_ENCODING_GB18030:
[email protected]5d98294912012-06-27 22:57:40480 case IDC_ENCODING_BIG5:
481 case IDC_ENCODING_KOREAN:
482 case IDC_ENCODING_SHIFTJIS:
483 case IDC_ENCODING_ISO2022JP:
484 case IDC_ENCODING_EUCJP:
485 case IDC_ENCODING_THAI:
486 case IDC_ENCODING_ISO885915:
487 case IDC_ENCODING_MACINTOSH:
488 case IDC_ENCODING_ISO88592:
489 case IDC_ENCODING_WINDOWS1250:
490 case IDC_ENCODING_ISO88595:
491 case IDC_ENCODING_WINDOWS1251:
492 case IDC_ENCODING_KOI8R:
493 case IDC_ENCODING_KOI8U:
jshin03456dca2015-03-24 20:51:34494 case IDC_ENCODING_IBM866:
[email protected]5d98294912012-06-27 22:57:40495 case IDC_ENCODING_ISO88597:
496 case IDC_ENCODING_WINDOWS1253:
497 case IDC_ENCODING_ISO88594:
498 case IDC_ENCODING_ISO885913:
499 case IDC_ENCODING_WINDOWS1257:
500 case IDC_ENCODING_ISO88593:
501 case IDC_ENCODING_ISO885910:
502 case IDC_ENCODING_ISO885914:
503 case IDC_ENCODING_ISO885916:
504 case IDC_ENCODING_WINDOWS1254:
505 case IDC_ENCODING_ISO88596:
506 case IDC_ENCODING_WINDOWS1256:
507 case IDC_ENCODING_ISO88598:
508 case IDC_ENCODING_ISO88598I:
509 case IDC_ENCODING_WINDOWS1255:
510 case IDC_ENCODING_WINDOWS1258:
511 browser_->OverrideEncoding(id);
512 break;
513
514 // Clipboard commands
515 case IDC_CUT:
[email protected]5d98294912012-06-27 22:57:40516 case IDC_COPY:
[email protected]5d98294912012-06-27 22:57:40517 case IDC_PASTE:
pkastingcd3f08bce2015-04-18 13:37:12518 CutCopyPaste(browser_, id);
[email protected]5d98294912012-06-27 22:57:40519 break;
520
521 // Find-in-page
522 case IDC_FIND:
523 Find(browser_);
524 break;
525 case IDC_FIND_NEXT:
526 FindNext(browser_);
527 break;
528 case IDC_FIND_PREVIOUS:
529 FindPrevious(browser_);
530 break;
531
532 // Zoom
533 case IDC_ZOOM_PLUS:
534 Zoom(browser_, content::PAGE_ZOOM_IN);
535 break;
536 case IDC_ZOOM_NORMAL:
537 Zoom(browser_, content::PAGE_ZOOM_RESET);
538 break;
539 case IDC_ZOOM_MINUS:
540 Zoom(browser_, content::PAGE_ZOOM_OUT);
541 break;
542
543 // Focus various bits of UI
544 case IDC_FOCUS_TOOLBAR:
[email protected]e6e30ac2014-01-13 21:24:39545 content::RecordAction(base::UserMetricsAction("Accel_Focus_Toolbar"));
[email protected]5d98294912012-06-27 22:57:40546 FocusToolbar(browser_);
547 break;
548 case IDC_FOCUS_LOCATION:
[email protected]e6e30ac2014-01-13 21:24:39549 content::RecordAction(base::UserMetricsAction("Accel_Focus_Location"));
[email protected]5d98294912012-06-27 22:57:40550 FocusLocationBar(browser_);
551 break;
552 case IDC_FOCUS_SEARCH:
[email protected]e6e30ac2014-01-13 21:24:39553 content::RecordAction(base::UserMetricsAction("Accel_Focus_Search"));
[email protected]5d98294912012-06-27 22:57:40554 FocusSearch(browser_);
555 break;
556 case IDC_FOCUS_MENU_BAR:
557 FocusAppMenu(browser_);
558 break;
559 case IDC_FOCUS_BOOKMARKS:
[email protected]9fbc1902013-12-06 01:49:45560 content::RecordAction(
[email protected]e6e30ac2014-01-13 21:24:39561 base::UserMetricsAction("Accel_Focus_Bookmarks"));
[email protected]5d98294912012-06-27 22:57:40562 FocusBookmarksToolbar(browser_);
563 break;
[email protected]822ca8c62013-04-19 00:49:15564 case IDC_FOCUS_INFOBARS:
565 FocusInfobars(browser_);
566 break;
[email protected]5d98294912012-06-27 22:57:40567 case IDC_FOCUS_NEXT_PANE:
568 FocusNextPane(browser_);
569 break;
570 case IDC_FOCUS_PREVIOUS_PANE:
571 FocusPreviousPane(browser_);
572 break;
573
574 // Show various bits of UI
575 case IDC_OPEN_FILE:
576 browser_->OpenFile();
577 break;
578 case IDC_CREATE_SHORTCUTS:
[email protected]619f86182012-07-03 21:30:18579 CreateApplicationShortcuts(browser_);
[email protected]5d98294912012-06-27 22:57:40580 break;
[email protected]488e3952013-11-18 05:29:14581 case IDC_CREATE_HOSTED_APP:
[email protected]92086542014-04-08 08:45:29582 CreateBookmarkAppFromCurrentWebContents(browser_);
[email protected]488e3952013-11-18 05:29:14583 break;
[email protected]5d98294912012-06-27 22:57:40584 case IDC_DEV_TOOLS:
[email protected]c934c382013-11-01 00:36:01585 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Show());
[email protected]5d98294912012-06-27 22:57:40586 break;
587 case IDC_DEV_TOOLS_CONSOLE:
[email protected]c934c382013-11-01 00:36:01588 ToggleDevToolsWindow(browser_, DevToolsToggleAction::ShowConsole());
[email protected]5d98294912012-06-27 22:57:40589 break;
[email protected]2056c3192013-10-21 22:40:51590 case IDC_DEV_TOOLS_DEVICES:
591 InspectUI::InspectDevices(browser_);
592 break;
[email protected]5d98294912012-06-27 22:57:40593 case IDC_DEV_TOOLS_INSPECT:
[email protected]c934c382013-11-01 00:36:01594 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Inspect());
[email protected]5d98294912012-06-27 22:57:40595 break;
[email protected]d16657c2012-09-03 14:25:10596 case IDC_DEV_TOOLS_TOGGLE:
[email protected]c934c382013-11-01 00:36:01597 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Toggle());
[email protected]d16657c2012-09-03 14:25:10598 break;
[email protected]5d98294912012-06-27 22:57:40599 case IDC_TASK_MANAGER:
[email protected]29c262de2013-06-22 15:39:38600 OpenTaskManager(browser_);
[email protected]5d98294912012-06-27 22:57:40601 break;
caelyn4e4e08a2015-02-04 21:27:49602#if defined(OS_CHROMEOS)
603 case IDC_TAKE_SCREENSHOT:
604 TakeScreenshot();
605 break;
606#endif
[email protected]236ad3022013-09-04 03:27:43607#if defined(GOOGLE_CHROME_BUILD)
[email protected]5d98294912012-06-27 22:57:40608 case IDC_FEEDBACK:
609 OpenFeedbackDialog(browser_);
610 break;
[email protected]236ad3022013-09-04 03:27:43611#endif
[email protected]5d98294912012-06-27 22:57:40612 case IDC_SHOW_BOOKMARK_BAR:
613 ToggleBookmarkBar(browser_);
614 break;
615 case IDC_PROFILING_ENABLED:
616 Profiling::Toggle();
617 break;
618
619 case IDC_SHOW_BOOKMARK_MANAGER:
620 ShowBookmarkManager(browser_);
621 break;
622 case IDC_SHOW_APP_MENU:
[email protected]e6e30ac2014-01-13 21:24:39623 content::RecordAction(base::UserMetricsAction("Accel_Show_App_Menu"));
[email protected]5d98294912012-06-27 22:57:40624 ShowAppMenu(browser_);
625 break;
626 case IDC_SHOW_AVATAR_MENU:
627 ShowAvatarMenu(browser_);
628 break;
anthonyvd7dc985da2015-03-23 16:53:19629 case IDC_SHOW_FAST_USER_SWITCHER:
630 ShowFastUserSwitcher(browser_);
631 break;
[email protected]5d98294912012-06-27 22:57:40632 case IDC_SHOW_HISTORY:
633 ShowHistory(browser_);
634 break;
635 case IDC_SHOW_DOWNLOADS:
636 ShowDownloads(browser_);
637 break;
638 case IDC_MANAGE_EXTENSIONS:
[email protected]bc9833c32013-02-28 04:05:08639 ShowExtensions(browser_, std::string());
[email protected]5d98294912012-06-27 22:57:40640 break;
641 case IDC_OPTIONS:
642 ShowSettings(browser_);
643 break;
644 case IDC_EDIT_SEARCH_ENGINES:
645 ShowSearchEngineSettings(browser_);
646 break;
647 case IDC_VIEW_PASSWORDS:
648 ShowPasswordManager(browser_);
649 break;
650 case IDC_CLEAR_BROWSING_DATA:
651 ShowClearBrowsingDataDialog(browser_);
652 break;
653 case IDC_IMPORT_SETTINGS:
654 ShowImportDialog(browser_);
655 break;
[email protected]9b7ab882012-09-10 23:46:36656 case IDC_TOGGLE_REQUEST_TABLET_SITE:
657 ToggleRequestTabletSite(browser_);
658 break;
[email protected]5d98294912012-06-27 22:57:40659 case IDC_ABOUT:
660 ShowAboutChrome(browser_);
661 break;
662 case IDC_UPGRADE_DIALOG:
663 OpenUpdateChromeDialog(browser_);
664 break;
665 case IDC_VIEW_INCOMPATIBILITIES:
666 ShowConflicts(browser_);
667 break;
668 case IDC_HELP_PAGE_VIA_KEYBOARD:
669 ShowHelp(browser_, HELP_SOURCE_KEYBOARD);
670 break;
671 case IDC_HELP_PAGE_VIA_MENU:
672 ShowHelp(browser_, HELP_SOURCE_MENU);
673 break;
estade8c0780f2015-08-21 23:36:41674 case IDC_SHOW_SIGNIN:
gogerald71bf6c902015-12-08 00:49:37675 ShowBrowserSigninOrSettings(
676 browser_, signin_metrics::AccessPoint::ACCESS_POINT_MENU);
estade8c0780f2015-08-21 23:36:41677 break;
[email protected]6bd370b2014-05-28 14:19:47678 case IDC_DISTILL_PAGE:
679 DistillCurrentPage(browser_);
680 break;
kpschoedelf8e9274e2014-10-07 18:32:41681#if defined(OS_CHROMEOS)
682 case IDC_TOUCH_HUD_PROJECTION_TOGGLE:
683 ash::accelerators::ToggleTouchHudProjection();
684 break;
685#endif
apacible45cbfc92015-09-28 22:45:41686 case IDC_ROUTE_MEDIA:
687 RouteMedia(browser_);
688 break;
[email protected]5d98294912012-06-27 22:57:40689
690 default:
691 LOG(WARNING) << "Received Unimplemented Command: " << id;
692 break;
693 }
694}
695
estade8c0780f2015-08-21 23:36:41696////////////////////////////////////////////////////////////////////////////////
697// BrowserCommandController, SigninPrefObserver implementation:
698
699void BrowserCommandController::OnSigninAllowedPrefChange() {
700 // For unit tests, we don't have a window.
701 if (!window())
702 return;
703 UpdateShowSyncState(IsShowingMainUI());
704}
705
[email protected]5d98294912012-06-27 22:57:40706// BrowserCommandController, TabStripModelObserver implementation:
707
[email protected]409ea2972012-11-10 19:54:43708void BrowserCommandController::TabInsertedAt(WebContents* contents,
[email protected]5d98294912012-06-27 22:57:40709 int index,
710 bool foreground) {
711 AddInterstitialObservers(contents);
712}
713
[email protected]e89cfcb2012-11-11 14:47:24714void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) {
[email protected]5d98294912012-06-27 22:57:40715 RemoveInterstitialObservers(contents);
716}
717
718void BrowserCommandController::TabReplacedAt(TabStripModel* tab_strip_model,
[email protected]b624ddc2012-11-15 18:04:13719 WebContents* old_contents,
720 WebContents* new_contents,
[email protected]5d98294912012-06-27 22:57:40721 int index) {
[email protected]b624ddc2012-11-15 18:04:13722 RemoveInterstitialObservers(old_contents);
723 AddInterstitialObservers(new_contents);
[email protected]5d98294912012-06-27 22:57:40724}
725
[email protected]3cac87232012-11-20 01:48:27726void BrowserCommandController::TabBlockedStateChanged(
727 content::WebContents* contents,
728 int index) {
729 PrintingStateChanged();
730 FullscreenStateChanged();
731 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:41732 UpdateCommandsForMediaRouter();
[email protected]3cac87232012-11-20 01:48:27733}
734
[email protected]5d98294912012-06-27 22:57:40735////////////////////////////////////////////////////////////////////////////////
736// BrowserCommandController, TabRestoreServiceObserver implementation:
737
738void BrowserCommandController::TabRestoreServiceChanged(
blundell74001adc2015-09-18 11:04:25739 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53740 UpdateTabRestoreCommandState();
[email protected]5d98294912012-06-27 22:57:40741}
742
743void BrowserCommandController::TabRestoreServiceDestroyed(
blundell74001adc2015-09-18 11:04:25744 sessions::TabRestoreService* service) {
[email protected]5d98294912012-06-27 22:57:40745 service->RemoveObserver(this);
746}
747
[email protected]2e9369e2014-08-15 09:12:53748void BrowserCommandController::TabRestoreServiceLoaded(
blundell74001adc2015-09-18 11:04:25749 sessions::TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53750 UpdateTabRestoreCommandState();
751}
752
[email protected]5d98294912012-06-27 22:57:40753////////////////////////////////////////////////////////////////////////////////
[email protected]5d98294912012-06-27 22:57:40754// BrowserCommandController, private:
755
[email protected]20ca0382013-02-28 19:50:07756class BrowserCommandController::InterstitialObserver
757 : public content::WebContentsObserver {
758 public:
759 InterstitialObserver(BrowserCommandController* controller,
760 content::WebContents* web_contents)
761 : WebContentsObserver(web_contents),
762 controller_(controller) {
763 }
764
dcheng5dd5ff62014-10-21 12:42:38765 void DidAttachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07766 controller_->UpdateCommandsForTabState();
767 }
768
dcheng5dd5ff62014-10-21 12:42:38769 void DidDetachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07770 controller_->UpdateCommandsForTabState();
771 }
772
773 private:
774 BrowserCommandController* controller_;
775
776 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver);
777};
778
[email protected]6a414ff2013-02-27 08:22:54779bool BrowserCommandController::IsShowingMainUI() {
780 bool should_hide_ui = window() && window()->ShouldHideUIForFullscreen();
781 return browser_->is_type_tabbed() && !should_hide_ui;
[email protected]5d98294912012-06-27 22:57:40782}
783
784void BrowserCommandController::InitCommandState() {
785 // All browser commands whose state isn't set automagically some other way
786 // (like Back & Forward with initial page load) must have their state
787 // initialized here, otherwise they will be forever disabled.
788
789 // Navigation commands
790 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true);
toyoshim7dad4b1182016-04-01 14:28:05791 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE, true);
[email protected]58e29032012-08-06 20:19:57792 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, true);
[email protected]5d98294912012-06-27 22:57:40793
794 // Window management commands
795 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true);
796 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true);
797 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true);
798 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true);
[email protected]2e9369e2014-08-15 09:12:53799 UpdateTabRestoreCommandState();
[email protected]d28d3782013-02-26 16:31:55800 command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
[email protected]5d98294912012-06-27 22:57:40801 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true);
[email protected]fa9412762013-09-04 23:31:33802#if defined(USE_ASH)
803 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
804#endif
[email protected]d12cc5e2013-10-19 18:25:06805#if defined(OS_CHROMEOS)
806 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_2, true);
807 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_3, true);
808#endif
[email protected]893124a22014-04-15 00:45:28809#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]af97be4c62014-02-13 14:43:34810 command_updater_.UpdateCommandEnabled(IDC_USE_SYSTEM_TITLE_BAR, true);
811#endif
[email protected]5d98294912012-06-27 22:57:40812
813 // Page-related commands
814 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true);
[email protected]4bee4432014-05-05 13:11:41815 command_updater_.UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE, true);
[email protected]5d98294912012-06-27 22:57:40816 command_updater_.UpdateCommandEnabled(IDC_ENCODING_AUTO_DETECT, true);
817 command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF8, true);
818 command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF16LE, true);
[email protected]5d98294912012-06-27 22:57:40819 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1252, true);
820 command_updater_.UpdateCommandEnabled(IDC_ENCODING_GBK, true);
821 command_updater_.UpdateCommandEnabled(IDC_ENCODING_GB18030, true);
[email protected]5d98294912012-06-27 22:57:40822 command_updater_.UpdateCommandEnabled(IDC_ENCODING_BIG5, true);
823 command_updater_.UpdateCommandEnabled(IDC_ENCODING_THAI, true);
824 command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOREAN, true);
825 command_updater_.UpdateCommandEnabled(IDC_ENCODING_SHIFTJIS, true);
826 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO2022JP, true);
827 command_updater_.UpdateCommandEnabled(IDC_ENCODING_EUCJP, true);
828 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885915, true);
829 command_updater_.UpdateCommandEnabled(IDC_ENCODING_MACINTOSH, true);
830 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88592, true);
831 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1250, true);
832 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88595, true);
833 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1251, true);
834 command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOI8R, true);
835 command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOI8U, true);
jshin03456dca2015-03-24 20:51:34836 command_updater_.UpdateCommandEnabled(IDC_ENCODING_IBM866, true);
[email protected]5d98294912012-06-27 22:57:40837 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88597, true);
838 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1253, true);
839 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88594, true);
840 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885913, true);
841 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1257, true);
842 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88593, true);
843 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885910, true);
844 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885914, true);
845 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885916, true);
846 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1254, true);
847 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88596, true);
848 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1256, true);
849 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88598, true);
850 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88598I, true);
851 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1255, true);
852 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1258, true);
853
854 // Zoom
855 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true);
856 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true);
[email protected]d93dbd12014-08-04 23:42:53857 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, false);
[email protected]5d98294912012-06-27 22:57:40858 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
859
860 // Show various bits of UI
mlerman7831f57d2015-05-25 11:40:15861 const bool guest_session = profile()->IsGuestSession() ||
862 profile()->IsSystemProfile();
863 DCHECK(!profile()->IsSystemProfile())
864 << "Ought to never have browser for the system profile.";
[email protected]338416c02014-05-13 16:47:06865 const bool normal_window = browser_->is_type_tabbed();
[email protected]05454532013-01-22 21:09:08866 UpdateOpenFileState(&command_updater_);
[email protected]5d98294912012-06-27 22:57:40867 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, false);
868 UpdateCommandsForDevTools();
869 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager());
[email protected]338416c02014-05-13 16:47:06870 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session);
[email protected]5d98294912012-06-27 22:57:40871 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
[email protected]674b65672014-06-02 23:21:56872 command_updater_.UpdateCommandEnabled(IDC_HELP_MENU, true);
[email protected]5d98294912012-06-27 22:57:40873 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
874 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
[email protected]338416c02014-05-13 16:47:06875 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session);
[email protected]2f1acc212012-11-13 10:43:51876 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU,
[email protected]338416c02014-05-13 16:47:06877 !guest_session &&
[email protected]2f1acc212012-11-13 10:43:51878 !profile()->IsOffTheRecord());
[email protected]338416c02014-05-13 16:47:06879 command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA, normal_window);
[email protected]39d47592014-01-10 21:42:45880#if defined(OS_CHROMEOS)
caelyn4e4e08a2015-02-04 21:27:49881 command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true);
kpschoedelf8e9274e2014-10-07 18:32:41882 command_updater_.UpdateCommandEnabled(IDC_TOUCH_HUD_PROJECTION_TOGGLE, true);
[email protected]338416c02014-05-13 16:47:06883#else
884 // Chrome OS uses the system tray menu to handle multi-profiles.
anthonyvd7dc985da2015-03-23 16:53:19885 if (normal_window && (guest_session || !profile()->IsOffTheRecord())) {
[email protected]338416c02014-05-13 16:47:06886 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
anthonyvd7dc985da2015-03-23 16:53:19887 command_updater_.UpdateCommandEnabled(IDC_SHOW_FAST_USER_SWITCHER, true);
888 }
[email protected]39d47592014-01-10 21:42:45889#endif
[email protected]5d98294912012-06-27 22:57:40890
estade8c0780f2015-08-21 23:36:41891 UpdateShowSyncState(true);
892
[email protected]5d98294912012-06-27 22:57:40893 // Navigation commands
[email protected]c9f983d2014-02-05 09:00:24894 command_updater_.UpdateCommandEnabled(
895 IDC_HOME,
benwellsc431c0ae2015-01-27 22:04:06896 normal_window ||
897 (extensions::util::IsNewBookmarkAppsEnabled() && browser_->is_app()));
[email protected]5d98294912012-06-27 22:57:40898
899 // Window management commands
[email protected]5d98294912012-06-27 22:57:40900 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window);
901 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB,
902 normal_window);
903 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window);
904 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window);
905 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window);
906 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window);
907 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window);
908 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window);
909 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window);
910 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window);
911 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window);
912 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window);
913 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window);
[email protected]5d98294912012-06-27 22:57:40914
[email protected]338416c02014-05-13 16:47:06915 // These are always enabled; the menu determines their menu item visibility.
[email protected]5d98294912012-06-27 22:57:40916 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
917 command_updater_.UpdateCommandEnabled(IDC_VIEW_INCOMPATIBILITIES, true);
918
[email protected]6bd370b2014-05-28 14:19:47919 // Distill current page.
920 command_updater_.UpdateCommandEnabled(
avi556c05022014-12-22 23:31:43921 IDC_DISTILL_PAGE, base::CommandLine::ForCurrentProcess()->HasSwitch(
922 switches::kEnableDomDistiller));
[email protected]6bd370b2014-05-28 14:19:47923
[email protected]338416c02014-05-13 16:47:06924 // Initialize other commands whose state changes based on various conditions.
[email protected]32dfede2013-08-25 15:48:25925 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40926 UpdateCommandsForContentRestrictionState();
[email protected]5d98294912012-06-27 22:57:40927 UpdateCommandsForBookmarkEditing();
[email protected]5d98294912012-06-27 22:57:40928 UpdateCommandsForIncognitoAvailability();
929}
930
[email protected]05454532013-01-22 21:09:08931// static
932void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
933 CommandUpdater* command_updater,
934 Profile* profile) {
mlermane01e6de2014-09-29 19:26:47935 const bool guest_session = profile->IsGuestSession();
936 // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession().
[email protected]5d98294912012-06-27 22:57:40937 IncognitoModePrefs::Availability incognito_availability =
[email protected]05454532013-01-22 21:09:08938 IncognitoModePrefs::GetAvailability(profile->GetPrefs());
939 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40940 IDC_NEW_WINDOW,
941 incognito_availability != IncognitoModePrefs::FORCED);
[email protected]05454532013-01-22 21:09:08942 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40943 IDC_NEW_INCOGNITO_WINDOW,
mlermane01e6de2014-09-29 19:26:47944 incognito_availability != IncognitoModePrefs::DISABLED && !guest_session);
[email protected]5d98294912012-06-27 22:57:40945
[email protected]57b25292014-05-01 16:31:06946 const bool forced_incognito =
947 incognito_availability == IncognitoModePrefs::FORCED ||
948 guest_session; // Guest always runs in Incognito mode.
[email protected]05454532013-01-22 21:09:08949 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:40950 IDC_SHOW_BOOKMARK_MANAGER,
[email protected]57b25292014-05-01 16:31:06951 browser_defaults::bookmarks_enabled && !forced_incognito);
[email protected]03d25812014-06-22 19:41:55952 ExtensionService* extension_service =
953 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]57b25292014-05-01 16:31:06954 const bool enable_extensions =
[email protected]5d98294912012-06-27 22:57:40955 extension_service && extension_service->extensions_enabled();
[email protected]5d98294912012-06-27 22:57:40956
[email protected]57b25292014-05-01 16:31:06957 // Bookmark manager and settings page/subpages are forced to open in normal
958 // mode. For this reason we disable these commands when incognito is forced.
959 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
960 enable_extensions && !forced_incognito);
961
962 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito);
963 command_updater->UpdateCommandEnabled(IDC_OPTIONS,
964 !forced_incognito || guest_session);
estade8c0780f2015-08-21 23:36:41965 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito);
[email protected]05454532013-01-22 21:09:08966}
967
968void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
969 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile());
970
[email protected]6a414ff2013-02-27 08:22:54971 if (!IsShowingMainUI()) {
[email protected]05454532013-01-22 21:09:08972 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false);
973 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false);
974 }
[email protected]5d98294912012-06-27 22:57:40975}
976
977void BrowserCommandController::UpdateCommandsForTabState() {
[email protected]617ee962013-01-29 20:49:12978 WebContents* current_web_contents =
979 browser_->tab_strip_model()->GetActiveWebContents();
[email protected]1c5119c2012-09-19 00:08:57980 if (!current_web_contents) // May be NULL during tab restore.
[email protected]5d98294912012-06-27 22:57:40981 return;
[email protected]5d98294912012-06-27 22:57:40982
983 // Navigation commands
984 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_));
985 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_));
986 command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_));
toyoshim7dad4b1182016-04-01 14:28:05987 command_updater_.UpdateCommandEnabled(IDC_RELOAD_BYPASSING_CACHE,
[email protected]5d98294912012-06-27 22:57:40988 CanReload(browser_));
[email protected]58e29032012-08-06 20:19:57989 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE,
990 CanReload(browser_));
[email protected]5d98294912012-06-27 22:57:40991
992 // Window management commands
993 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB,
994 !browser_->is_app() && CanDuplicateTab(browser_));
995
996 // Page-related commands
997 window()->SetStarredState(
[email protected]1c5119c2012-09-19 00:08:57998 BookmarkTabHelper::FromWebContents(current_web_contents)->is_starred());
[email protected]5423c372012-08-22 05:50:16999 window()->ZoomChangedForActiveTab(false);
[email protected]5d98294912012-06-27 22:57:401000 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
1001 CanViewSource(browser_));
1002 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION,
1003 CanEmailPageLocation(browser_));
1004 if (browser_->is_devtools())
1005 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false);
1006
1007 // Changing the encoding is not possible on Chrome-internal webpages.
1008 NavigationController& nc = current_web_contents->GetController();
[email protected]97174892014-06-03 09:06:121009 bool is_chrome_internal = HasInternalURL(nc.GetLastCommittedEntry()) ||
[email protected]5d98294912012-06-27 22:57:401010 current_web_contents->ShowingInterstitialPage();
1011 command_updater_.UpdateCommandEnabled(IDC_ENCODING_MENU,
1012 !is_chrome_internal && current_web_contents->IsSavable());
1013
1014 // Show various bits of UI
1015 // TODO(pinkerton): Disable app-mode in the model until we implement it
1016 // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148
1017#if !defined(OS_MACOSX)
1018 command_updater_.UpdateCommandEnabled(
1019 IDC_CREATE_SHORTCUTS,
1020 CanCreateApplicationShortcuts(browser_));
mitchelljones6d1594de2014-12-02 01:42:441021#endif
[email protected]92086542014-04-08 08:45:291022 command_updater_.UpdateCommandEnabled(IDC_CREATE_HOSTED_APP,
1023 CanCreateBookmarkApp(browser_));
[email protected]5d98294912012-06-27 22:57:401024
[email protected]9b7ab882012-09-10 23:46:361025 command_updater_.UpdateCommandEnabled(
1026 IDC_TOGGLE_REQUEST_TABLET_SITE,
1027 CanRequestTabletSite(current_web_contents));
1028
[email protected]5d98294912012-06-27 22:57:401029 UpdateCommandsForContentRestrictionState();
1030 UpdateCommandsForBookmarkEditing();
[email protected]3cac87232012-11-20 01:48:271031 UpdateCommandsForFind();
apacible45cbfc92015-09-28 22:45:411032 UpdateCommandsForMediaRouter();
[email protected]d93dbd12014-08-04 23:42:531033 // Update the zoom commands when an active tab is selected.
1034 UpdateCommandsForZoomState();
1035}
1036
1037void BrowserCommandController::UpdateCommandsForZoomState() {
1038 WebContents* contents =
1039 browser_->tab_strip_model()->GetActiveWebContents();
1040 if (!contents)
1041 return;
a.sarkar.arundaadc712015-02-26 05:39:081042 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS,
1043 CanZoomIn(contents));
1044 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL,
ccameronb7c1d6c2015-03-09 17:08:241045 CanResetZoom(contents));
a.sarkar.arundaadc712015-02-26 05:39:081046 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS,
1047 CanZoomOut(contents));
[email protected]5d98294912012-06-27 22:57:401048}
1049
1050void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
1051 int restrictions = GetContentRestrictions(browser_);
1052
1053 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011054 IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY));
[email protected]5d98294912012-06-27 22:57:401055 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011056 IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT));
[email protected]5d98294912012-06-27 22:57:401057 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011058 IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE));
[email protected]5d98294912012-06-27 22:57:401059 UpdateSaveAsState();
1060 UpdatePrintingState();
1061}
1062
1063void BrowserCommandController::UpdateCommandsForDevTools() {
1064 bool dev_tools_enabled =
1065 !profile()->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled);
1066 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS,
1067 dev_tools_enabled);
1068 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE,
1069 dev_tools_enabled);
[email protected]2056c3192013-10-21 22:40:511070 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES,
1071 dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401072 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT,
1073 dev_tools_enabled);
[email protected]d16657c2012-09-03 14:25:101074 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE,
1075 dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401076}
1077
1078void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
1079 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE,
1080 CanBookmarkCurrentPage(browser_));
1081 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
1082 CanBookmarkAllTabs(browser_));
thestig5149d272014-10-30 07:25:291083#if defined(OS_WIN)
1084 command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN, true);
1085#endif
[email protected]5d98294912012-06-27 22:57:401086}
1087
1088void BrowserCommandController::UpdateCommandsForBookmarkBar() {
tfarina3bddbe112014-08-28 05:29:321089 command_updater_.UpdateCommandEnabled(
1090 IDC_SHOW_BOOKMARK_BAR,
1091 browser_defaults::bookmarks_enabled && !profile()->IsGuestSession() &&
mlerman7831f57d2015-05-25 11:40:151092 !profile()->IsSystemProfile() &&
tfarina3bddbe112014-08-28 05:29:321093 !profile()->GetPrefs()->IsManagedPreference(
1094 bookmarks::prefs::kShowBookmarkBar) &&
1095 IsShowingMainUI());
[email protected]5d98294912012-06-27 22:57:401096}
1097
[email protected]9ec3ea5b2012-12-03 18:14:301098void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
1099 UpdateSaveAsState();
[email protected]05454532013-01-22 21:09:081100 UpdateOpenFileState(&command_updater_);
[email protected]9ec3ea5b2012-12-03 18:14:301101}
1102
[email protected]32dfede2013-08-25 15:48:251103void BrowserCommandController::UpdateCommandsForFullscreenMode() {
1104 WindowState window_state = WINDOW_STATE_NOT_FULLSCREEN;
1105 if (window() && window()->IsFullscreen()) {
1106 window_state = WINDOW_STATE_FULLSCREEN;
[email protected]32dfede2013-08-25 15:48:251107 }
[email protected]6a414ff2013-02-27 08:22:541108 bool show_main_ui = IsShowingMainUI();
[email protected]32dfede2013-08-25 15:48:251109 bool main_not_fullscreen =
1110 show_main_ui && window_state == WINDOW_STATE_NOT_FULLSCREEN;
[email protected]5d98294912012-06-27 22:57:401111
1112 // Navigation commands
1113 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1114
1115 // Window management commands
1116 command_updater_.UpdateCommandEnabled(
1117 IDC_SHOW_AS_TAB,
[email protected]32dfede2013-08-25 15:48:251118 !browser_->is_type_tabbed() &&
1119 window_state == WINDOW_STATE_NOT_FULLSCREEN);
[email protected]5d98294912012-06-27 22:57:401120
1121 // Focus various bits of UI
1122 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
1123 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui);
1124 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
1125 command_updater_.UpdateCommandEnabled(
1126 IDC_FOCUS_MENU_BAR, main_not_fullscreen);
1127 command_updater_.UpdateCommandEnabled(
1128 IDC_FOCUS_NEXT_PANE, main_not_fullscreen);
1129 command_updater_.UpdateCommandEnabled(
1130 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen);
1131 command_updater_.UpdateCommandEnabled(
1132 IDC_FOCUS_BOOKMARKS, main_not_fullscreen);
[email protected]822ca8c62013-04-19 00:49:151133 command_updater_.UpdateCommandEnabled(
1134 IDC_FOCUS_INFOBARS, main_not_fullscreen);
[email protected]5d98294912012-06-27 22:57:401135
1136 // Show various bits of UI
1137 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431138#if defined(GOOGLE_CHROME_BUILD)
[email protected]5d98294912012-06-27 22:57:401139 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431140#endif
estade8c0780f2015-08-21 23:36:411141 UpdateShowSyncState(show_main_ui);
[email protected]5d98294912012-06-27 22:57:401142
1143 // Settings page/subpages are forced to open in normal mode. We disable these
[email protected]90efc3e2014-04-22 18:39:031144 // commands for guest sessions and when incognito is forced.
[email protected]5d98294912012-06-27 22:57:401145 const bool options_enabled = show_main_ui &&
[email protected]5d98294912012-06-27 22:57:401146 IncognitoModePrefs::GetAvailability(
1147 profile()->GetPrefs()) != IncognitoModePrefs::FORCED;
[email protected]57b25292014-05-01 16:31:061148 const bool guest_session = profile()->IsGuestSession();
[email protected]5d98294912012-06-27 22:57:401149 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled);
[email protected]57b25292014-05-01 16:31:061150 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS,
1151 options_enabled && !guest_session);
[email protected]5d98294912012-06-27 22:57:401152
1153 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
1154 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
1155 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
1156 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
primianod3a81ab2016-01-25 22:21:151157
1158 if (base::debug::IsProfilingSupported())
1159 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
[email protected]5d98294912012-06-27 22:57:401160
scottmg8caddb12016-03-21 18:22:421161 bool fullscreen_enabled = true;
[email protected]aeafc3852014-04-29 16:51:291162#if !defined(OS_MACOSX)
[email protected]32dfede2013-08-25 15:48:251163 if (window_state == WINDOW_STATE_NOT_FULLSCREEN &&
1164 !profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed)) {
1165 // Disable toggling into fullscreen mode if disallowed by pref.
1166 fullscreen_enabled = false;
1167 }
[email protected]00a1cc5b2012-11-07 13:44:511168#endif
1169
1170 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled);
1171 command_updater_.UpdateCommandEnabled(IDC_PRESENTATION_MODE,
1172 fullscreen_enabled);
spqchanb8ffc7d2015-11-17 01:17:211173 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_FULLSCREEN_TOOLBAR,
1174 fullscreen_enabled);
[email protected]5d98294912012-06-27 22:57:401175
1176 UpdateCommandsForBookmarkBar();
[email protected]5d98294912012-06-27 22:57:401177}
1178
1179void BrowserCommandController::UpdatePrintingState() {
[email protected]d53e4032012-06-29 18:58:341180 bool print_enabled = CanPrint(browser_);
1181 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
vitalybukae29991c2014-11-05 21:15:121182#if defined(ENABLE_BASIC_PRINTING)
vitalybukaf9433e42014-09-08 10:04:551183 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT,
1184 CanBasicPrint(browser_));
vitalybukae29991c2014-11-05 21:15:121185#endif // ENABLE_BASIC_PRINTING
[email protected]5d98294912012-06-27 22:57:401186}
1187
1188void BrowserCommandController::UpdateSaveAsState() {
1189 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_));
1190}
1191
estade8c0780f2015-08-21 23:36:411192void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) {
1193 command_updater_.UpdateCommandEnabled(
1194 IDC_SHOW_SYNC_SETUP, show_main_ui && pref_signin_allowed_.GetValue());
1195}
1196
[email protected]05454532013-01-22 21:09:081197// static
1198void BrowserCommandController::UpdateOpenFileState(
1199 CommandUpdater* command_updater) {
[email protected]5d98294912012-06-27 22:57:401200 bool enabled = true;
1201 PrefService* local_state = g_browser_process->local_state();
1202 if (local_state)
1203 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs);
1204
[email protected]05454532013-01-22 21:09:081205 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled);
[email protected]5d98294912012-06-27 22:57:401206}
1207
1208void BrowserCommandController::UpdateReloadStopState(bool is_loading,
1209 bool force) {
1210 window()->UpdateReloadStopState(is_loading, force);
1211 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
1212}
1213
[email protected]2e9369e2014-08-15 09:12:531214void BrowserCommandController::UpdateTabRestoreCommandState() {
blundell74001adc2015-09-18 11:04:251215 sessions::TabRestoreService* tab_restore_service =
[email protected]2e9369e2014-08-15 09:12:531216 TabRestoreServiceFactory::GetForProfile(profile());
1217 // The command is enabled if the service hasn't loaded yet to trigger loading.
1218 // The command is updated once the load completes.
1219 command_updater_.UpdateCommandEnabled(
1220 IDC_RESTORE_TAB,
1221 tab_restore_service &&
1222 (!tab_restore_service->IsLoaded() ||
1223 GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE));
1224}
1225
[email protected]3cac87232012-11-20 01:48:271226void BrowserCommandController::UpdateCommandsForFind() {
1227 TabStripModel* model = browser_->tab_strip_model();
1228 bool enabled = !model->IsTabBlocked(model->active_index()) &&
1229 !browser_->is_devtools();
1230
1231 command_updater_.UpdateCommandEnabled(IDC_FIND, enabled);
1232 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled);
1233 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled);
1234}
1235
apacible45cbfc92015-09-28 22:45:411236void BrowserCommandController::UpdateCommandsForMediaRouter() {
1237 command_updater_.UpdateCommandEnabled(IDC_ROUTE_MEDIA,
1238 CanRouteMedia(browser_));
1239}
1240
[email protected]409ea2972012-11-10 19:54:431241void BrowserCommandController::AddInterstitialObservers(WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071242 interstitial_observers_.push_back(new InterstitialObserver(this, contents));
[email protected]5d98294912012-06-27 22:57:401243}
1244
1245void BrowserCommandController::RemoveInterstitialObservers(
[email protected]e89cfcb2012-11-11 14:47:241246 WebContents* contents) {
[email protected]20ca0382013-02-28 19:50:071247 for (size_t i = 0; i < interstitial_observers_.size(); i++) {
1248 if (interstitial_observers_[i]->web_contents() != contents)
1249 continue;
1250
1251 delete interstitial_observers_[i];
1252 interstitial_observers_.erase(interstitial_observers_.begin() + i);
1253 return;
1254 }
[email protected]5d98294912012-06-27 22:57:401255}
1256
1257BrowserWindow* BrowserCommandController::window() {
1258 return browser_->window();
1259}
1260
1261Profile* BrowserCommandController::profile() {
1262 return browser_->profile();
1263}
1264
[email protected]5d98294912012-06-27 22:57:401265} // namespace chrome