blob: 8ae3cc56bbc474dfe1f5174351bad3256e197268 [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
[email protected]488e3952013-11-18 05:29:147#include "base/command_line.h"
[email protected]3853a4c2013-02-11 17:15:578#include "base/prefs/pref_service.h"
[email protected]5d98294912012-06-27 22:57:409#include "chrome/app/chrome_command_ids.h"
10#include "chrome/browser/browser_process.h"
[email protected]dcc8fbc2013-07-12 00:54:0911#include "chrome/browser/chrome_notification_types.h"
[email protected]5d98294912012-06-27 22:57:4012#include "chrome/browser/defaults.h"
13#include "chrome/browser/extensions/extension_service.h"
benwells39f23ae2014-08-27 08:01:5214#include "chrome/browser/extensions/extension_util.h"
[email protected]2e9d79f2013-08-16 05:45:5615#include "chrome/browser/lifetime/application_lifetime.h"
[email protected]5d98294912012-06-27 22:57:4016#include "chrome/browser/prefs/incognito_mode_prefs.h"
[email protected]5d98294912012-06-27 22:57:4017#include "chrome/browser/profiles/profile.h"
mlermane01e6de2014-09-29 19:26:4718#include "chrome/browser/profiles/profile_manager.h"
[email protected]5d98294912012-06-27 22:57:4019#include "chrome/browser/sessions/tab_restore_service.h"
20#include "chrome/browser/sessions/tab_restore_service_factory.h"
[email protected]0b32f9b62012-09-17 19:08:0321#include "chrome/browser/shell_integration.h"
[email protected]3d27d272013-07-31 03:15:1622#include "chrome/browser/signin/signin_promo.h"
[email protected]5d98294912012-06-27 22:57:4023#include "chrome/browser/sync/profile_sync_service.h"
24#include "chrome/browser/sync/profile_sync_service_factory.h"
25#include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
26#include "chrome/browser/ui/browser.h"
27#include "chrome/browser/ui/browser_commands.h"
28#include "chrome/browser/ui/browser_window.h"
29#include "chrome/browser/ui/chrome_pages.h"
[email protected]5d98294912012-06-27 22:57:4030#include "chrome/browser/ui/tabs/tab_strip_model.h"
[email protected]00a1cc5b2012-11-07 13:44:5131#include "chrome/browser/ui/tabs/tab_strip_model_utils.h"
[email protected]2056c3192013-10-21 22:40:5132#include "chrome/browser/ui/webui/inspect_ui.h"
[email protected]488e3952013-11-18 05:29:1433#include "chrome/common/chrome_switches.h"
[email protected]3c71576ce2013-07-23 02:00:0134#include "chrome/common/content_restriction.h"
[email protected]5d98294912012-06-27 22:57:4035#include "chrome/common/pref_names.h"
36#include "chrome/common/profiling.h"
37#include "content/public/browser/native_web_keyboard_event.h"
38#include "content/public/browser/navigation_controller.h"
39#include "content/public/browser/navigation_entry.h"
[email protected]6708dbc2012-11-04 00:17:2240#include "content/public/browser/user_metrics.h"
[email protected]5d98294912012-06-27 22:57:4041#include "content/public/browser/web_contents.h"
[email protected]20ca0382013-02-28 19:50:0742#include "content/public/browser/web_contents_observer.h"
[email protected]5d98294912012-06-27 22:57:4043#include "content/public/common/url_constants.h"
[email protected]03d25812014-06-22 19:41:5544#include "extensions/browser/extension_system.h"
[email protected]7e9acd082013-09-17 23:31:1645#include "ui/events/keycodes/keyboard_codes.h"
[email protected]5d98294912012-06-27 22:57:4046
[email protected]9c4d68332013-01-30 13:34:4147#if defined(OS_MACOSX)
48#include "chrome/browser/ui/browser_commands_mac.h"
49#endif
50
[email protected]5d98294912012-06-27 22:57:4051#if defined(OS_WIN)
52#include "base/win/metro.h"
[email protected]a43ed002013-02-05 19:47:5453#include "base/win/windows_version.h"
[email protected]471e1e82013-08-14 09:53:5254#include "chrome/browser/ui/apps/apps_metro_handler_win.h"
[email protected]2d0f80f2013-11-01 22:47:1855#include "content/public/browser/gpu_data_manager.h"
[email protected]5d98294912012-06-27 22:57:4056#endif
57
[email protected]4b0bcef2012-09-27 00:20:5658#if defined(USE_ASH)
[email protected]fa9412762013-09-04 23:31:3359#include "ash/accelerators/accelerator_commands.h"
[email protected]4b0bcef2012-09-27 00:20:5660#include "chrome/browser/ui/ash/ash_util.h"
61#endif
62
[email protected]d12cc5e2013-10-19 18:25:0663#if defined(OS_CHROMEOS)
[email protected]7c43e7fe2013-11-01 13:35:1764#include "ash/multi_profile_uma.h"
[email protected]fdf74bf2014-04-30 21:24:0265#include "ash/session/session_state_delegate.h"
[email protected]d12cc5e2013-10-19 18:25:0666#include "ash/shell.h"
[email protected]0c930812014-01-30 18:01:4767#include "chrome/browser/ui/ash/multi_user/multi_user_context_menu.h"
[email protected]5226f1e2013-11-09 04:12:1068#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
[email protected]39d47592014-01-10 21:42:4569#include "chrome/browser/ui/browser_commands_chromeos.h"
[email protected]d12cc5e2013-10-19 18:25:0670#endif
71
[email protected]d5bedb6d2014-04-08 10:49:3272#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
73#include "ui/events/linux/text_edit_key_bindings_delegate_auralinux.h"
[email protected]1e2172f2014-04-01 17:32:3474#endif
75
[email protected]5d98294912012-06-27 22:57:4076using content::NavigationEntry;
77using content::NavigationController;
78using content::WebContents;
79
80namespace {
81
[email protected]32dfede2013-08-25 15:48:2582enum WindowState {
83 // Not in fullscreen mode.
84 WINDOW_STATE_NOT_FULLSCREEN,
85
86 // Fullscreen mode, occupying the whole screen.
87 WINDOW_STATE_FULLSCREEN,
88
89 // Fullscreen mode for metro snap, occupying the full height and 20% of
90 // the screen width.
91 WINDOW_STATE_METRO_SNAP,
92};
93
[email protected]5d98294912012-06-27 22:57:4094// Returns |true| if entry has an internal chrome:// URL, |false| otherwise.
95bool HasInternalURL(const NavigationEntry* entry) {
96 if (!entry)
97 return false;
98
99 // Check the |virtual_url()| first. This catches regular chrome:// URLs
100 // including URLs that were rewritten (such as chrome://bookmarks).
[email protected]2d9748b22014-02-11 00:17:29101 if (entry->GetVirtualURL().SchemeIs(content::kChromeUIScheme))
[email protected]5d98294912012-06-27 22:57:40102 return true;
103
104 // If the |virtual_url()| isn't a chrome:// URL, check if it's actually
105 // view-source: of a chrome:// URL.
[email protected]dbdda5402013-05-30 22:13:48106 if (entry->GetVirtualURL().SchemeIs(content::kViewSourceScheme))
[email protected]2d9748b22014-02-11 00:17:29107 return entry->GetURL().SchemeIs(content::kChromeUIScheme);
[email protected]5d98294912012-06-27 22:57:40108
109 return false;
110}
111
[email protected]0b32f9b62012-09-17 19:08:03112#if defined(OS_WIN)
113// Windows 8 specific helper class to manage DefaultBrowserWorker. It does the
114// following asynchronous actions in order:
115// 1- Check that chrome is the default browser
116// 2- If we are the default, restart chrome in metro and exit
117// 3- If not the default browser show the 'select default browser' system dialog
118// 4- When dialog dismisses check again who got made the default
119// 5- If we are the default then restart chrome in metro and exit
120// 6- If we are not the default exit.
121//
122// Note: this class deletes itself.
[email protected]24ced7dc02013-04-04 08:32:39123class SwitchToMetroUIHandler
[email protected]0b32f9b62012-09-17 19:08:03124 : public ShellIntegration::DefaultWebClientObserver {
125 public:
[email protected]24ced7dc02013-04-04 08:32:39126 SwitchToMetroUIHandler()
[email protected]d4b2d232013-04-30 21:14:23127 : default_browser_worker_(
128 new ShellIntegration::DefaultBrowserWorker(this)),
[email protected]0b32f9b62012-09-17 19:08:03129 first_check_(true) {
130 default_browser_worker_->StartCheckIsDefault();
131 }
132
[email protected]24ced7dc02013-04-04 08:32:39133 virtual ~SwitchToMetroUIHandler() {
[email protected]0b32f9b62012-09-17 19:08:03134 default_browser_worker_->ObserverDestroyed();
135 }
136
137 private:
138 virtual void SetDefaultWebClientUIState(
mostynb205d6252014-10-04 00:49:22139 ShellIntegration::DefaultWebClientUIState state) override {
[email protected]0b32f9b62012-09-17 19:08:03140 switch (state) {
141 case ShellIntegration::STATE_PROCESSING:
142 return;
143 case ShellIntegration::STATE_UNKNOWN :
144 break;
145 case ShellIntegration::STATE_IS_DEFAULT:
[email protected]d51373d2013-10-31 15:22:00146 chrome::AttemptRestartToMetroMode();
[email protected]0b32f9b62012-09-17 19:08:03147 break;
148 case ShellIntegration::STATE_NOT_DEFAULT:
149 if (first_check_) {
150 default_browser_worker_->StartSetAsDefault();
151 return;
152 }
153 break;
154 default:
155 NOTREACHED();
156 }
157 delete this;
158 }
159
mostynb205d6252014-10-04 00:49:22160 virtual void OnSetAsDefaultConcluded(bool success) override {
[email protected]0b32f9b62012-09-17 19:08:03161 if (!success) {
162 delete this;
163 return;
164 }
165 first_check_ = false;
166 default_browser_worker_->StartCheckIsDefault();
167 }
168
mostynb205d6252014-10-04 00:49:22169 virtual bool IsInteractiveSetDefaultPermitted() override {
[email protected]0b32f9b62012-09-17 19:08:03170 return true;
171 }
172
173 scoped_refptr<ShellIntegration::DefaultBrowserWorker> default_browser_worker_;
174 bool first_check_;
175
[email protected]24ced7dc02013-04-04 08:32:39176 DISALLOW_COPY_AND_ASSIGN(SwitchToMetroUIHandler);
[email protected]0b32f9b62012-09-17 19:08:03177};
178#endif // defined(OS_WIN)
179
[email protected]5d98294912012-06-27 22:57:40180} // namespace
181
182namespace chrome {
183
184///////////////////////////////////////////////////////////////////////////////
185// BrowserCommandController, public:
186
[email protected]338416c02014-05-13 16:47:06187BrowserCommandController::BrowserCommandController(Browser* browser)
[email protected]5d98294912012-06-27 22:57:40188 : browser_(browser),
[email protected]d4b2d232013-04-30 21:14:23189 command_updater_(this),
[email protected]5d98294912012-06-27 22:57:40190 block_command_execution_(false),
191 last_blocked_command_id_(-1),
192 last_blocked_command_disposition_(CURRENT_TAB) {
[email protected]5d98294912012-06-27 22:57:40193 browser_->tab_strip_model()->AddObserver(this);
194 PrefService* local_state = g_browser_process->local_state();
195 if (local_state) {
196 local_pref_registrar_.Init(local_state);
[email protected]9ec3ea5b2012-12-03 18:14:30197 local_pref_registrar_.Add(
198 prefs::kAllowFileSelectionDialogs,
199 base::Bind(
200 &BrowserCommandController::UpdateCommandsForFileSelectionDialogs,
201 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40202 }
203
204 profile_pref_registrar_.Init(profile()->GetPrefs());
[email protected]9ec3ea5b2012-12-03 18:14:30205 profile_pref_registrar_.Add(
206 prefs::kDevToolsDisabled,
207 base::Bind(&BrowserCommandController::UpdateCommandsForDevTools,
208 base::Unretained(this)));
209 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32210 bookmarks::prefs::kEditBookmarksEnabled,
[email protected]9ec3ea5b2012-12-03 18:14:30211 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkEditing,
212 base::Unretained(this)));
213 profile_pref_registrar_.Add(
tfarina3bddbe112014-08-28 05:29:32214 bookmarks::prefs::kShowBookmarkBar,
[email protected]9ec3ea5b2012-12-03 18:14:30215 base::Bind(&BrowserCommandController::UpdateCommandsForBookmarkBar,
216 base::Unretained(this)));
217 profile_pref_registrar_.Add(
218 prefs::kIncognitoModeAvailability,
219 base::Bind(
220 &BrowserCommandController::UpdateCommandsForIncognitoAvailability,
221 base::Unretained(this)));
222 profile_pref_registrar_.Add(
223 prefs::kPrintingEnabled,
224 base::Bind(&BrowserCommandController::UpdatePrintingState,
225 base::Unretained(this)));
[email protected]32dfede2013-08-25 15:48:25226#if !defined(OS_MACOSX)
227 profile_pref_registrar_.Add(
228 prefs::kFullscreenAllowed,
229 base::Bind(&BrowserCommandController::UpdateCommandsForFullscreenMode,
230 base::Unretained(this)));
231#endif
[email protected]074311a2013-02-28 23:14:09232 pref_signin_allowed_.Init(
233 prefs::kSigninAllowed,
234 profile()->GetOriginalProfile()->GetPrefs(),
235 base::Bind(&BrowserCommandController::OnSigninAllowedPrefChange,
236 base::Unretained(this)));
[email protected]5d98294912012-06-27 22:57:40237
238 InitCommandState();
239
240 TabRestoreService* tab_restore_service =
241 TabRestoreServiceFactory::GetForProfile(profile());
242 if (tab_restore_service) {
243 tab_restore_service->AddObserver(this);
244 TabRestoreServiceChanged(tab_restore_service);
245 }
[email protected]5d98294912012-06-27 22:57:40246}
247
248BrowserCommandController::~BrowserCommandController() {
[email protected]95e39472012-10-05 23:37:36249 // TabRestoreService may have been shutdown by the time we get here. Don't
250 // trigger creating it.
[email protected]5d98294912012-06-27 22:57:40251 TabRestoreService* tab_restore_service =
[email protected]95e39472012-10-05 23:37:36252 TabRestoreServiceFactory::GetForProfileIfExisting(profile());
[email protected]5d98294912012-06-27 22:57:40253 if (tab_restore_service)
254 tab_restore_service->RemoveObserver(this);
255 profile_pref_registrar_.RemoveAll();
256 local_pref_registrar_.RemoveAll();
257 browser_->tab_strip_model()->RemoveObserver(this);
[email protected]5d98294912012-06-27 22:57:40258}
259
260bool BrowserCommandController::IsReservedCommandOrKey(
261 int command_id,
262 const content::NativeWebKeyboardEvent& event) {
263 // In Apps mode, no keys are reserved.
264 if (browser_->is_app())
265 return false;
266
267#if defined(OS_CHROMEOS)
[email protected]397abd32013-08-21 05:44:19268 // On Chrome OS, the top row of keys are mapped to browser actions like
269 // back/forward or refresh. We don't want web pages to be able to change the
270 // behavior of these keys. Ash handles F4 and up; this leaves us needing to
271 // reserve browser back/forward and refresh here.
[email protected]5d98294912012-06-27 22:57:40272 ui::KeyboardCode key_code =
[email protected]3642e2d2012-10-29 21:31:14273 static_cast<ui::KeyboardCode>(event.windowsKeyCode);
[email protected]397abd32013-08-21 05:44:19274 if ((key_code == ui::VKEY_BROWSER_BACK && command_id == IDC_BACK) ||
275 (key_code == ui::VKEY_BROWSER_FORWARD && command_id == IDC_FORWARD) ||
276 (key_code == ui::VKEY_BROWSER_REFRESH && command_id == IDC_RELOAD)) {
[email protected]5d98294912012-06-27 22:57:40277 return true;
278 }
279#endif
280
281 if (window()->IsFullscreen() && command_id == IDC_FULLSCREEN)
282 return true;
[email protected]1e2172f2014-04-01 17:32:34283
[email protected]893124a22014-04-15 00:45:28284#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]1e2172f2014-04-01 17:32:34285 // If this key was registered by the user as a content editing hotkey, then
286 // it is not reserved.
[email protected]d5bedb6d2014-04-08 10:49:32287 ui::TextEditKeyBindingsDelegateAuraLinux* delegate =
[email protected]1e2172f2014-04-01 17:32:34288 ui::GetTextEditKeyBindingsDelegate();
[email protected]47e8e7542014-04-03 07:52:42289 if (delegate && event.os_event && delegate->MatchEvent(*event.os_event, NULL))
[email protected]1e2172f2014-04-01 17:32:34290 return false;
291#endif
292
[email protected]5d98294912012-06-27 22:57:40293 return command_id == IDC_CLOSE_TAB ||
294 command_id == IDC_CLOSE_WINDOW ||
295 command_id == IDC_NEW_INCOGNITO_WINDOW ||
296 command_id == IDC_NEW_TAB ||
297 command_id == IDC_NEW_WINDOW ||
298 command_id == IDC_RESTORE_TAB ||
299 command_id == IDC_SELECT_NEXT_TAB ||
300 command_id == IDC_SELECT_PREVIOUS_TAB ||
[email protected]3642e2d2012-10-29 21:31:14301 command_id == IDC_EXIT;
[email protected]5d98294912012-06-27 22:57:40302}
303
304void BrowserCommandController::SetBlockCommandExecution(bool block) {
305 block_command_execution_ = block;
306 if (block) {
307 last_blocked_command_id_ = -1;
308 last_blocked_command_disposition_ = CURRENT_TAB;
309 }
310}
311
312int BrowserCommandController::GetLastBlockedCommand(
313 WindowOpenDisposition* disposition) {
314 if (disposition)
315 *disposition = last_blocked_command_disposition_;
316 return last_blocked_command_id_;
317}
318
319void BrowserCommandController::TabStateChanged() {
320 UpdateCommandsForTabState();
321}
322
[email protected]d93dbd12014-08-04 23:42:53323void BrowserCommandController::ZoomStateChanged() {
324 UpdateCommandsForZoomState();
325}
326
[email protected]5d98294912012-06-27 22:57:40327void BrowserCommandController::ContentRestrictionsChanged() {
328 UpdateCommandsForContentRestrictionState();
329}
330
331void BrowserCommandController::FullscreenStateChanged() {
[email protected]32dfede2013-08-25 15:48:25332 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:40333}
334
335void BrowserCommandController::PrintingStateChanged() {
336 UpdatePrintingState();
337}
338
339void BrowserCommandController::LoadingStateChanged(bool is_loading,
340 bool force) {
341 UpdateReloadStopState(is_loading, force);
342}
343
[email protected]5d98294912012-06-27 22:57:40344////////////////////////////////////////////////////////////////////////////////
[email protected]de0d0f42012-12-06 21:27:11345// BrowserCommandController, CommandUpdaterDelegate implementation:
[email protected]5d98294912012-06-27 22:57:40346
347void BrowserCommandController::ExecuteCommandWithDisposition(
[email protected]de0d0f42012-12-06 21:27:11348 int id,
349 WindowOpenDisposition disposition) {
[email protected]5d98294912012-06-27 22:57:40350 // No commands are enabled if there is not yet any selected tab.
351 // TODO(pkasting): It seems like we should not need this, because either
352 // most/all commands should not have been enabled yet anyway or the ones that
353 // are enabled should be global, or safe themselves against having no selected
354 // tab. However, Ben says he tried removing this before and got lots of
355 // crashes, e.g. from Windows sending WM_COMMANDs at random times during
356 // window construction. This probably could use closer examination someday.
[email protected]59253a652012-11-20 00:17:26357 if (browser_->tab_strip_model()->active_index() == TabStripModel::kNoTab)
[email protected]5d98294912012-06-27 22:57:40358 return;
359
360 DCHECK(command_updater_.IsCommandEnabled(id)) << "Invalid/disabled command "
361 << id;
362
363 // If command execution is blocked then just record the command and return.
364 if (block_command_execution_) {
365 // We actually only allow no more than one blocked command, otherwise some
366 // commands maybe lost.
367 DCHECK_EQ(last_blocked_command_id_, -1);
368 last_blocked_command_id_ = id;
369 last_blocked_command_disposition_ = disposition;
370 return;
371 }
372
373 // The order of commands in this switch statement must match the function
374 // declaration order in browser.h!
375 switch (id) {
376 // Navigation commands
377 case IDC_BACK:
378 GoBack(browser_, disposition);
379 break;
380 case IDC_FORWARD:
381 GoForward(browser_, disposition);
382 break;
383 case IDC_RELOAD:
384 Reload(browser_, disposition);
385 break;
[email protected]58e29032012-08-06 20:19:57386 case IDC_RELOAD_CLEARING_CACHE:
387 ClearCache(browser_);
388 // FALL THROUGH
[email protected]5d98294912012-06-27 22:57:40389 case IDC_RELOAD_IGNORING_CACHE:
390 ReloadIgnoringCache(browser_, disposition);
391 break;
392 case IDC_HOME:
393 Home(browser_, disposition);
394 break;
395 case IDC_OPEN_CURRENT_URL:
396 OpenCurrentURL(browser_);
397 break;
398 case IDC_STOP:
399 Stop(browser_);
400 break;
401
402 // Window management commands
403 case IDC_NEW_WINDOW:
404 NewWindow(browser_);
405 break;
406 case IDC_NEW_INCOGNITO_WINDOW:
407 NewIncognitoWindow(browser_);
408 break;
409 case IDC_CLOSE_WINDOW:
[email protected]e6e30ac2014-01-13 21:24:39410 content::RecordAction(base::UserMetricsAction("CloseWindowByKey"));
[email protected]04b9e692012-08-24 14:49:09411 CloseWindow(browser_);
[email protected]5d98294912012-06-27 22:57:40412 break;
413 case IDC_NEW_TAB:
414 NewTab(browser_);
415 break;
416 case IDC_CLOSE_TAB:
[email protected]e6e30ac2014-01-13 21:24:39417 content::RecordAction(base::UserMetricsAction("CloseTabByKey"));
[email protected]04b9e692012-08-24 14:49:09418 CloseTab(browser_);
[email protected]5d98294912012-06-27 22:57:40419 break;
420 case IDC_SELECT_NEXT_TAB:
[email protected]e6e30ac2014-01-13 21:24:39421 content::RecordAction(base::UserMetricsAction("Accel_SelectNextTab"));
[email protected]5d98294912012-06-27 22:57:40422 SelectNextTab(browser_);
423 break;
424 case IDC_SELECT_PREVIOUS_TAB:
[email protected]0db969d2013-05-30 18:26:16425 content::RecordAction(
[email protected]e6e30ac2014-01-13 21:24:39426 base::UserMetricsAction("Accel_SelectPreviousTab"));
[email protected]5d98294912012-06-27 22:57:40427 SelectPreviousTab(browser_);
428 break;
[email protected]5d98294912012-06-27 22:57:40429 case IDC_MOVE_TAB_NEXT:
430 MoveTabNext(browser_);
431 break;
432 case IDC_MOVE_TAB_PREVIOUS:
433 MoveTabPrevious(browser_);
434 break;
435 case IDC_SELECT_TAB_0:
436 case IDC_SELECT_TAB_1:
437 case IDC_SELECT_TAB_2:
438 case IDC_SELECT_TAB_3:
439 case IDC_SELECT_TAB_4:
440 case IDC_SELECT_TAB_5:
441 case IDC_SELECT_TAB_6:
442 case IDC_SELECT_TAB_7:
443 SelectNumberedTab(browser_, id - IDC_SELECT_TAB_0);
444 break;
445 case IDC_SELECT_LAST_TAB:
446 SelectLastTab(browser_);
447 break;
448 case IDC_DUPLICATE_TAB:
449 DuplicateTab(browser_);
450 break;
451 case IDC_RESTORE_TAB:
452 RestoreTab(browser_);
453 break;
[email protected]5d98294912012-06-27 22:57:40454 case IDC_SHOW_AS_TAB:
455 ConvertPopupToTabbedBrowser(browser_);
456 break;
457 case IDC_FULLSCREEN:
[email protected]9c4d68332013-01-30 13:34:41458#if defined(OS_MACOSX)
[email protected]d74d1e12013-02-11 23:01:49459 chrome::ToggleFullscreenWithChromeOrFallback(browser_);
[email protected]9c4d68332013-01-30 13:34:41460#else
[email protected]3f32b9b2012-07-09 16:59:28461 chrome::ToggleFullscreenMode(browser_);
[email protected]9c4d68332013-01-30 13:34:41462#endif
[email protected]5d98294912012-06-27 22:57:40463 break;
[email protected]770c6d82012-09-06 22:21:32464
[email protected]d12cc5e2013-10-19 18:25:06465#if defined(OS_CHROMEOS)
466 case IDC_VISIT_DESKTOP_OF_LRU_USER_2:
[email protected]0c930812014-01-30 18:01:47467 case IDC_VISIT_DESKTOP_OF_LRU_USER_3:
468 ExecuteVisitDesktopCommand(id, browser_->window()->GetNativeWindow());
469 break;
[email protected]d12cc5e2013-10-19 18:25:06470#endif
471
[email protected]893124a22014-04-15 00:45:28472#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]af97be4c62014-02-13 14:43:34473 case IDC_USE_SYSTEM_TITLE_BAR: {
474 PrefService* prefs = browser_->profile()->GetPrefs();
475 prefs->SetBoolean(prefs::kUseCustomChromeFrame,
476 !prefs->GetBoolean(prefs::kUseCustomChromeFrame));
477 break;
478 }
479#endif
480
[email protected]5d98294912012-06-27 22:57:40481#if defined(OS_WIN)
[email protected]770c6d82012-09-06 22:21:32482 // Windows 8 specific commands.
[email protected]5d98294912012-06-27 22:57:40483 case IDC_METRO_SNAP_ENABLE:
484 browser_->SetMetroSnapMode(true);
485 break;
486 case IDC_METRO_SNAP_DISABLE:
487 browser_->SetMetroSnapMode(false);
488 break;
ananta196db192014-08-28 21:37:55489 case IDC_WIN_DESKTOP_RESTART:
490 if (!VerifyASHSwitchForApps(window()->GetNativeWindow(), id))
[email protected]396de6872013-11-08 08:50:37491 break;
492
[email protected]d51373d2013-10-31 15:22:00493 chrome::AttemptRestartToDesktopMode();
ananta196db192014-08-28 21:37:55494 if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
495 content::RecordAction(base::UserMetricsAction("Win8DesktopRestart"));
496 } else {
497 content::RecordAction(base::UserMetricsAction("Win7DesktopRestart"));
498 }
[email protected]770c6d82012-09-06 22:21:32499 break;
[email protected]0b32f9b62012-09-17 19:08:03500 case IDC_WIN8_METRO_RESTART:
ananta196db192014-08-28 21:37:55501 case IDC_WIN_CHROMEOS_RESTART:
502 if (!VerifyASHSwitchForApps(window()->GetNativeWindow(), id))
[email protected]24ced7dc02013-04-04 08:32:39503 break;
ananta196db192014-08-28 21:37:55504 if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
505 // SwitchToMetroUIHandler deletes itself.
506 new SwitchToMetroUIHandler;
507 content::RecordAction(base::UserMetricsAction("Win8MetroRestart"));
508 } else {
509 content::RecordAction(base::UserMetricsAction("Win7ASHRestart"));
510 chrome::AttemptRestartToMetroMode();
511 }
[email protected]0b32f9b62012-09-17 19:08:03512 break;
thestig5149d272014-10-30 07:25:29513 case IDC_PIN_TO_START_SCREEN:
514 TogglePagePinnedToStartScreen(browser_);
515 break;
[email protected]5d98294912012-06-27 22:57:40516#endif
[email protected]770c6d82012-09-06 22:21:32517
[email protected]5d98294912012-06-27 22:57:40518#if defined(OS_MACOSX)
519 case IDC_PRESENTATION_MODE:
[email protected]9c4d68332013-01-30 13:34:41520 chrome::ToggleFullscreenMode(browser_);
[email protected]5d98294912012-06-27 22:57:40521 break;
522#endif
523 case IDC_EXIT:
524 Exit();
525 break;
526
527 // Page-related commands
528 case IDC_SAVE_PAGE:
529 SavePage(browser_);
530 break;
531 case IDC_BOOKMARK_PAGE:
532 BookmarkCurrentPage(browser_);
533 break;
[email protected]5d98294912012-06-27 22:57:40534 case IDC_BOOKMARK_ALL_TABS:
535 BookmarkAllTabs(browser_);
536 break;
537 case IDC_VIEW_SOURCE:
538 ViewSelectedSource(browser_);
539 break;
540 case IDC_EMAIL_PAGE_LOCATION:
541 EmailPageLocation(browser_);
542 break;
543 case IDC_PRINT:
544 Print(browser_);
545 break;
vitalybukaf9433e42014-09-08 10:04:55546#if !defined(DISABLE_BASIC_PRINTING)
547 case IDC_BASIC_PRINT:
[email protected]e6e30ac2014-01-13 21:24:39548 content::RecordAction(base::UserMetricsAction("Accel_Advanced_Print"));
vitalybukaf9433e42014-09-08 10:04:55549 BasicPrint(browser_);
[email protected]5d98294912012-06-27 22:57:40550 break;
vitalybukaf9433e42014-09-08 10:04:55551#endif // !DISABLE_BASIC_PRINTING
[email protected]e625b7602013-10-28 09:24:56552 case IDC_TRANSLATE_PAGE:
553 Translate(browser_);
554 break;
[email protected]4bee4432014-05-05 13:11:41555 case IDC_MANAGE_PASSWORDS_FOR_PAGE:
556 ManagePasswordsForPage(browser_);
557 break;
558
559 // Page encoding commands
[email protected]5d98294912012-06-27 22:57:40560 case IDC_ENCODING_AUTO_DETECT:
561 browser_->ToggleEncodingAutoDetect();
562 break;
563 case IDC_ENCODING_UTF8:
564 case IDC_ENCODING_UTF16LE:
[email protected]5d98294912012-06-27 22:57:40565 case IDC_ENCODING_WINDOWS1252:
566 case IDC_ENCODING_GBK:
567 case IDC_ENCODING_GB18030:
568 case IDC_ENCODING_BIG5HKSCS:
569 case IDC_ENCODING_BIG5:
570 case IDC_ENCODING_KOREAN:
571 case IDC_ENCODING_SHIFTJIS:
572 case IDC_ENCODING_ISO2022JP:
573 case IDC_ENCODING_EUCJP:
574 case IDC_ENCODING_THAI:
575 case IDC_ENCODING_ISO885915:
576 case IDC_ENCODING_MACINTOSH:
577 case IDC_ENCODING_ISO88592:
578 case IDC_ENCODING_WINDOWS1250:
579 case IDC_ENCODING_ISO88595:
580 case IDC_ENCODING_WINDOWS1251:
581 case IDC_ENCODING_KOI8R:
582 case IDC_ENCODING_KOI8U:
583 case IDC_ENCODING_ISO88597:
584 case IDC_ENCODING_WINDOWS1253:
585 case IDC_ENCODING_ISO88594:
586 case IDC_ENCODING_ISO885913:
587 case IDC_ENCODING_WINDOWS1257:
588 case IDC_ENCODING_ISO88593:
589 case IDC_ENCODING_ISO885910:
590 case IDC_ENCODING_ISO885914:
591 case IDC_ENCODING_ISO885916:
592 case IDC_ENCODING_WINDOWS1254:
593 case IDC_ENCODING_ISO88596:
594 case IDC_ENCODING_WINDOWS1256:
595 case IDC_ENCODING_ISO88598:
596 case IDC_ENCODING_ISO88598I:
597 case IDC_ENCODING_WINDOWS1255:
598 case IDC_ENCODING_WINDOWS1258:
599 browser_->OverrideEncoding(id);
600 break;
601
602 // Clipboard commands
603 case IDC_CUT:
604 Cut(browser_);
605 break;
606 case IDC_COPY:
607 Copy(browser_);
608 break;
609 case IDC_PASTE:
610 Paste(browser_);
611 break;
612
613 // Find-in-page
614 case IDC_FIND:
615 Find(browser_);
616 break;
617 case IDC_FIND_NEXT:
618 FindNext(browser_);
619 break;
620 case IDC_FIND_PREVIOUS:
621 FindPrevious(browser_);
622 break;
623
624 // Zoom
625 case IDC_ZOOM_PLUS:
626 Zoom(browser_, content::PAGE_ZOOM_IN);
627 break;
628 case IDC_ZOOM_NORMAL:
629 Zoom(browser_, content::PAGE_ZOOM_RESET);
630 break;
631 case IDC_ZOOM_MINUS:
632 Zoom(browser_, content::PAGE_ZOOM_OUT);
633 break;
634
635 // Focus various bits of UI
636 case IDC_FOCUS_TOOLBAR:
[email protected]e6e30ac2014-01-13 21:24:39637 content::RecordAction(base::UserMetricsAction("Accel_Focus_Toolbar"));
[email protected]5d98294912012-06-27 22:57:40638 FocusToolbar(browser_);
639 break;
640 case IDC_FOCUS_LOCATION:
[email protected]e6e30ac2014-01-13 21:24:39641 content::RecordAction(base::UserMetricsAction("Accel_Focus_Location"));
[email protected]5d98294912012-06-27 22:57:40642 FocusLocationBar(browser_);
643 break;
644 case IDC_FOCUS_SEARCH:
[email protected]e6e30ac2014-01-13 21:24:39645 content::RecordAction(base::UserMetricsAction("Accel_Focus_Search"));
[email protected]5d98294912012-06-27 22:57:40646 FocusSearch(browser_);
647 break;
648 case IDC_FOCUS_MENU_BAR:
649 FocusAppMenu(browser_);
650 break;
651 case IDC_FOCUS_BOOKMARKS:
[email protected]9fbc1902013-12-06 01:49:45652 content::RecordAction(
[email protected]e6e30ac2014-01-13 21:24:39653 base::UserMetricsAction("Accel_Focus_Bookmarks"));
[email protected]5d98294912012-06-27 22:57:40654 FocusBookmarksToolbar(browser_);
655 break;
[email protected]822ca8c62013-04-19 00:49:15656 case IDC_FOCUS_INFOBARS:
657 FocusInfobars(browser_);
658 break;
[email protected]5d98294912012-06-27 22:57:40659 case IDC_FOCUS_NEXT_PANE:
660 FocusNextPane(browser_);
661 break;
662 case IDC_FOCUS_PREVIOUS_PANE:
663 FocusPreviousPane(browser_);
664 break;
665
666 // Show various bits of UI
667 case IDC_OPEN_FILE:
668 browser_->OpenFile();
669 break;
670 case IDC_CREATE_SHORTCUTS:
[email protected]619f86182012-07-03 21:30:18671 CreateApplicationShortcuts(browser_);
[email protected]5d98294912012-06-27 22:57:40672 break;
[email protected]488e3952013-11-18 05:29:14673 case IDC_CREATE_HOSTED_APP:
[email protected]92086542014-04-08 08:45:29674 CreateBookmarkAppFromCurrentWebContents(browser_);
[email protected]488e3952013-11-18 05:29:14675 break;
[email protected]5d98294912012-06-27 22:57:40676 case IDC_DEV_TOOLS:
[email protected]c934c382013-11-01 00:36:01677 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Show());
[email protected]5d98294912012-06-27 22:57:40678 break;
679 case IDC_DEV_TOOLS_CONSOLE:
[email protected]c934c382013-11-01 00:36:01680 ToggleDevToolsWindow(browser_, DevToolsToggleAction::ShowConsole());
[email protected]5d98294912012-06-27 22:57:40681 break;
[email protected]2056c3192013-10-21 22:40:51682 case IDC_DEV_TOOLS_DEVICES:
683 InspectUI::InspectDevices(browser_);
684 break;
[email protected]5d98294912012-06-27 22:57:40685 case IDC_DEV_TOOLS_INSPECT:
[email protected]c934c382013-11-01 00:36:01686 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Inspect());
[email protected]5d98294912012-06-27 22:57:40687 break;
[email protected]d16657c2012-09-03 14:25:10688 case IDC_DEV_TOOLS_TOGGLE:
[email protected]c934c382013-11-01 00:36:01689 ToggleDevToolsWindow(browser_, DevToolsToggleAction::Toggle());
[email protected]d16657c2012-09-03 14:25:10690 break;
[email protected]5d98294912012-06-27 22:57:40691 case IDC_TASK_MANAGER:
[email protected]29c262de2013-06-22 15:39:38692 OpenTaskManager(browser_);
[email protected]5d98294912012-06-27 22:57:40693 break;
[email protected]39d47592014-01-10 21:42:45694#if defined(OS_CHROMEOS)
695 case IDC_TAKE_SCREENSHOT:
696 TakeScreenshot();
697 break;
698#endif
[email protected]236ad3022013-09-04 03:27:43699#if defined(GOOGLE_CHROME_BUILD)
[email protected]5d98294912012-06-27 22:57:40700 case IDC_FEEDBACK:
701 OpenFeedbackDialog(browser_);
702 break;
[email protected]236ad3022013-09-04 03:27:43703#endif
[email protected]5d98294912012-06-27 22:57:40704 case IDC_SHOW_BOOKMARK_BAR:
705 ToggleBookmarkBar(browser_);
706 break;
707 case IDC_PROFILING_ENABLED:
708 Profiling::Toggle();
709 break;
710
711 case IDC_SHOW_BOOKMARK_MANAGER:
712 ShowBookmarkManager(browser_);
713 break;
714 case IDC_SHOW_APP_MENU:
[email protected]e6e30ac2014-01-13 21:24:39715 content::RecordAction(base::UserMetricsAction("Accel_Show_App_Menu"));
[email protected]5d98294912012-06-27 22:57:40716 ShowAppMenu(browser_);
717 break;
718 case IDC_SHOW_AVATAR_MENU:
719 ShowAvatarMenu(browser_);
720 break;
721 case IDC_SHOW_HISTORY:
722 ShowHistory(browser_);
723 break;
724 case IDC_SHOW_DOWNLOADS:
725 ShowDownloads(browser_);
726 break;
727 case IDC_MANAGE_EXTENSIONS:
[email protected]bc9833c32013-02-28 04:05:08728 ShowExtensions(browser_, std::string());
[email protected]5d98294912012-06-27 22:57:40729 break;
730 case IDC_OPTIONS:
731 ShowSettings(browser_);
732 break;
733 case IDC_EDIT_SEARCH_ENGINES:
734 ShowSearchEngineSettings(browser_);
735 break;
736 case IDC_VIEW_PASSWORDS:
737 ShowPasswordManager(browser_);
738 break;
739 case IDC_CLEAR_BROWSING_DATA:
740 ShowClearBrowsingDataDialog(browser_);
741 break;
742 case IDC_IMPORT_SETTINGS:
743 ShowImportDialog(browser_);
744 break;
[email protected]9b7ab882012-09-10 23:46:36745 case IDC_TOGGLE_REQUEST_TABLET_SITE:
746 ToggleRequestTabletSite(browser_);
747 break;
[email protected]5d98294912012-06-27 22:57:40748 case IDC_ABOUT:
749 ShowAboutChrome(browser_);
750 break;
751 case IDC_UPGRADE_DIALOG:
752 OpenUpdateChromeDialog(browser_);
753 break;
754 case IDC_VIEW_INCOMPATIBILITIES:
755 ShowConflicts(browser_);
756 break;
757 case IDC_HELP_PAGE_VIA_KEYBOARD:
758 ShowHelp(browser_, HELP_SOURCE_KEYBOARD);
759 break;
760 case IDC_HELP_PAGE_VIA_MENU:
761 ShowHelp(browser_, HELP_SOURCE_MENU);
762 break;
[email protected]08fafe42013-02-03 08:10:49763 case IDC_SHOW_SIGNIN:
[email protected]3d27d272013-07-31 03:15:16764 ShowBrowserSignin(browser_, signin::SOURCE_MENU);
[email protected]5d98294912012-06-27 22:57:40765 break;
766 case IDC_TOGGLE_SPEECH_INPUT:
767 ToggleSpeechInput(browser_);
768 break;
[email protected]6bd370b2014-05-28 14:19:47769 case IDC_DISTILL_PAGE:
770 DistillCurrentPage(browser_);
771 break;
kpschoedelf8e9274e2014-10-07 18:32:41772#if defined(OS_CHROMEOS)
773 case IDC_TOUCH_HUD_PROJECTION_TOGGLE:
774 ash::accelerators::ToggleTouchHudProjection();
775 break;
776#endif
[email protected]5d98294912012-06-27 22:57:40777
778 default:
779 LOG(WARNING) << "Received Unimplemented Command: " << id;
780 break;
781 }
782}
783
784////////////////////////////////////////////////////////////////////////////////
[email protected]074311a2013-02-28 23:14:09785// BrowserCommandController, SigninPrefObserver implementation:
786
787void BrowserCommandController::OnSigninAllowedPrefChange() {
788 // For unit tests, we don't have a window.
789 if (!window())
790 return;
791 UpdateShowSyncState(IsShowingMainUI());
792}
793
[email protected]5d98294912012-06-27 22:57:40794// BrowserCommandController, TabStripModelObserver implementation:
795
[email protected]409ea2972012-11-10 19:54:43796void BrowserCommandController::TabInsertedAt(WebContents* contents,
[email protected]5d98294912012-06-27 22:57:40797 int index,
798 bool foreground) {
799 AddInterstitialObservers(contents);
800}
801
[email protected]e89cfcb2012-11-11 14:47:24802void BrowserCommandController::TabDetachedAt(WebContents* contents, int index) {
[email protected]5d98294912012-06-27 22:57:40803 RemoveInterstitialObservers(contents);
804}
805
806void BrowserCommandController::TabReplacedAt(TabStripModel* tab_strip_model,
[email protected]b624ddc2012-11-15 18:04:13807 WebContents* old_contents,
808 WebContents* new_contents,
[email protected]5d98294912012-06-27 22:57:40809 int index) {
[email protected]b624ddc2012-11-15 18:04:13810 RemoveInterstitialObservers(old_contents);
811 AddInterstitialObservers(new_contents);
[email protected]5d98294912012-06-27 22:57:40812}
813
[email protected]3cac87232012-11-20 01:48:27814void BrowserCommandController::TabBlockedStateChanged(
815 content::WebContents* contents,
816 int index) {
817 PrintingStateChanged();
818 FullscreenStateChanged();
819 UpdateCommandsForFind();
820}
821
[email protected]5d98294912012-06-27 22:57:40822////////////////////////////////////////////////////////////////////////////////
823// BrowserCommandController, TabRestoreServiceObserver implementation:
824
825void BrowserCommandController::TabRestoreServiceChanged(
826 TabRestoreService* service) {
[email protected]2e9369e2014-08-15 09:12:53827 UpdateTabRestoreCommandState();
[email protected]5d98294912012-06-27 22:57:40828}
829
830void BrowserCommandController::TabRestoreServiceDestroyed(
831 TabRestoreService* service) {
832 service->RemoveObserver(this);
833}
834
[email protected]2e9369e2014-08-15 09:12:53835void BrowserCommandController::TabRestoreServiceLoaded(
836 TabRestoreService* service) {
837 UpdateTabRestoreCommandState();
838}
839
[email protected]5d98294912012-06-27 22:57:40840////////////////////////////////////////////////////////////////////////////////
[email protected]5d98294912012-06-27 22:57:40841// BrowserCommandController, private:
842
[email protected]20ca0382013-02-28 19:50:07843class BrowserCommandController::InterstitialObserver
844 : public content::WebContentsObserver {
845 public:
846 InterstitialObserver(BrowserCommandController* controller,
847 content::WebContents* web_contents)
848 : WebContentsObserver(web_contents),
849 controller_(controller) {
850 }
851
dcheng5dd5ff62014-10-21 12:42:38852 void DidAttachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07853 controller_->UpdateCommandsForTabState();
854 }
855
dcheng5dd5ff62014-10-21 12:42:38856 void DidDetachInterstitialPage() override {
[email protected]20ca0382013-02-28 19:50:07857 controller_->UpdateCommandsForTabState();
858 }
859
860 private:
861 BrowserCommandController* controller_;
862
863 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver);
864};
865
[email protected]6a414ff2013-02-27 08:22:54866bool BrowserCommandController::IsShowingMainUI() {
867 bool should_hide_ui = window() && window()->ShouldHideUIForFullscreen();
868 return browser_->is_type_tabbed() && !should_hide_ui;
[email protected]5d98294912012-06-27 22:57:40869}
870
871void BrowserCommandController::InitCommandState() {
872 // All browser commands whose state isn't set automagically some other way
873 // (like Back & Forward with initial page load) must have their state
874 // initialized here, otherwise they will be forever disabled.
875
876 // Navigation commands
877 command_updater_.UpdateCommandEnabled(IDC_RELOAD, true);
878 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE, true);
[email protected]58e29032012-08-06 20:19:57879 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE, true);
[email protected]5d98294912012-06-27 22:57:40880
881 // Window management commands
882 command_updater_.UpdateCommandEnabled(IDC_CLOSE_WINDOW, true);
883 command_updater_.UpdateCommandEnabled(IDC_NEW_TAB, true);
884 command_updater_.UpdateCommandEnabled(IDC_CLOSE_TAB, true);
885 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB, true);
[email protected]2e9369e2014-08-15 09:12:53886 UpdateTabRestoreCommandState();
[email protected]6ed406c2013-03-12 17:57:11887#if defined(OS_WIN) && defined(USE_ASH)
888 if (browser_->host_desktop_type() != chrome::HOST_DESKTOP_TYPE_ASH)
889 command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
890#else
[email protected]d28d3782013-02-26 16:31:55891 command_updater_.UpdateCommandEnabled(IDC_EXIT, true);
[email protected]6ed406c2013-03-12 17:57:11892#endif
[email protected]5d98294912012-06-27 22:57:40893 command_updater_.UpdateCommandEnabled(IDC_DEBUG_FRAME_TOGGLE, true);
[email protected]fa9412762013-09-04 23:31:33894#if defined(USE_ASH)
895 command_updater_.UpdateCommandEnabled(IDC_MINIMIZE_WINDOW, true);
896#endif
[email protected]d12cc5e2013-10-19 18:25:06897#if defined(OS_CHROMEOS)
898 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_2, true);
899 command_updater_.UpdateCommandEnabled(IDC_VISIT_DESKTOP_OF_LRU_USER_3, true);
900#endif
[email protected]893124a22014-04-15 00:45:28901#if defined(OS_LINUX) && !defined(OS_CHROMEOS)
[email protected]af97be4c62014-02-13 14:43:34902 command_updater_.UpdateCommandEnabled(IDC_USE_SYSTEM_TITLE_BAR, true);
903#endif
[email protected]5d98294912012-06-27 22:57:40904
905 // Page-related commands
906 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION, true);
[email protected]4bee4432014-05-05 13:11:41907 command_updater_.UpdateCommandEnabled(IDC_MANAGE_PASSWORDS_FOR_PAGE, true);
[email protected]5d98294912012-06-27 22:57:40908 command_updater_.UpdateCommandEnabled(IDC_ENCODING_AUTO_DETECT, true);
909 command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF8, true);
910 command_updater_.UpdateCommandEnabled(IDC_ENCODING_UTF16LE, true);
[email protected]5d98294912012-06-27 22:57:40911 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1252, true);
912 command_updater_.UpdateCommandEnabled(IDC_ENCODING_GBK, true);
913 command_updater_.UpdateCommandEnabled(IDC_ENCODING_GB18030, true);
914 command_updater_.UpdateCommandEnabled(IDC_ENCODING_BIG5HKSCS, true);
915 command_updater_.UpdateCommandEnabled(IDC_ENCODING_BIG5, true);
916 command_updater_.UpdateCommandEnabled(IDC_ENCODING_THAI, true);
917 command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOREAN, true);
918 command_updater_.UpdateCommandEnabled(IDC_ENCODING_SHIFTJIS, true);
919 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO2022JP, true);
920 command_updater_.UpdateCommandEnabled(IDC_ENCODING_EUCJP, true);
921 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885915, true);
922 command_updater_.UpdateCommandEnabled(IDC_ENCODING_MACINTOSH, true);
923 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88592, true);
924 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1250, true);
925 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88595, true);
926 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1251, true);
927 command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOI8R, true);
928 command_updater_.UpdateCommandEnabled(IDC_ENCODING_KOI8U, true);
929 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88597, true);
930 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1253, true);
931 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88594, true);
932 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885913, true);
933 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1257, true);
934 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88593, true);
935 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885910, true);
936 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885914, true);
937 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO885916, true);
938 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1254, true);
939 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88596, true);
940 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1256, true);
941 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88598, true);
942 command_updater_.UpdateCommandEnabled(IDC_ENCODING_ISO88598I, true);
943 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1255, true);
944 command_updater_.UpdateCommandEnabled(IDC_ENCODING_WINDOWS1258, true);
945
946 // Zoom
947 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MENU, true);
948 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, true);
[email protected]d93dbd12014-08-04 23:42:53949 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, false);
[email protected]5d98294912012-06-27 22:57:40950 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, true);
951
952 // Show various bits of UI
[email protected]338416c02014-05-13 16:47:06953 const bool guest_session = profile()->IsGuestSession();
954 const bool normal_window = browser_->is_type_tabbed();
[email protected]05454532013-01-22 21:09:08955 UpdateOpenFileState(&command_updater_);
[email protected]5d98294912012-06-27 22:57:40956 command_updater_.UpdateCommandEnabled(IDC_CREATE_SHORTCUTS, false);
957 UpdateCommandsForDevTools();
958 command_updater_.UpdateCommandEnabled(IDC_TASK_MANAGER, CanOpenTaskManager());
[email protected]338416c02014-05-13 16:47:06959 command_updater_.UpdateCommandEnabled(IDC_SHOW_HISTORY, !guest_session);
[email protected]5d98294912012-06-27 22:57:40960 command_updater_.UpdateCommandEnabled(IDC_SHOW_DOWNLOADS, true);
[email protected]674b65672014-06-02 23:21:56961 command_updater_.UpdateCommandEnabled(IDC_HELP_MENU, true);
[email protected]5d98294912012-06-27 22:57:40962 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_KEYBOARD, true);
963 command_updater_.UpdateCommandEnabled(IDC_HELP_PAGE_VIA_MENU, true);
[email protected]338416c02014-05-13 16:47:06964 command_updater_.UpdateCommandEnabled(IDC_BOOKMARKS_MENU, !guest_session);
[email protected]2f1acc212012-11-13 10:43:51965 command_updater_.UpdateCommandEnabled(IDC_RECENT_TABS_MENU,
[email protected]338416c02014-05-13 16:47:06966 !guest_session &&
[email protected]2f1acc212012-11-13 10:43:51967 !profile()->IsOffTheRecord());
[email protected]338416c02014-05-13 16:47:06968 command_updater_.UpdateCommandEnabled(IDC_CLEAR_BROWSING_DATA, normal_window);
[email protected]39d47592014-01-10 21:42:45969#if defined(OS_CHROMEOS)
970 command_updater_.UpdateCommandEnabled(IDC_TAKE_SCREENSHOT, true);
kpschoedelf8e9274e2014-10-07 18:32:41971 command_updater_.UpdateCommandEnabled(IDC_TOUCH_HUD_PROJECTION_TOGGLE, true);
[email protected]338416c02014-05-13 16:47:06972#else
973 // Chrome OS uses the system tray menu to handle multi-profiles.
974 if (normal_window && (guest_session || !profile()->IsOffTheRecord()))
975 command_updater_.UpdateCommandEnabled(IDC_SHOW_AVATAR_MENU, true);
[email protected]39d47592014-01-10 21:42:45976#endif
[email protected]5d98294912012-06-27 22:57:40977
[email protected]074311a2013-02-28 23:14:09978 UpdateShowSyncState(true);
[email protected]5d98294912012-06-27 22:57:40979
[email protected]5d98294912012-06-27 22:57:40980 // Navigation commands
[email protected]c9f983d2014-02-05 09:00:24981 command_updater_.UpdateCommandEnabled(
982 IDC_HOME,
benwells39f23ae2014-08-27 08:01:52983 normal_window || (extensions::util::IsStreamlinedHostedAppsEnabled() &&
[email protected]c9f983d2014-02-05 09:00:24984 browser_->is_app()));
[email protected]5d98294912012-06-27 22:57:40985
986 // Window management commands
[email protected]5d98294912012-06-27 22:57:40987 command_updater_.UpdateCommandEnabled(IDC_SELECT_NEXT_TAB, normal_window);
988 command_updater_.UpdateCommandEnabled(IDC_SELECT_PREVIOUS_TAB,
989 normal_window);
990 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_NEXT, normal_window);
991 command_updater_.UpdateCommandEnabled(IDC_MOVE_TAB_PREVIOUS, normal_window);
992 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_0, normal_window);
993 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_1, normal_window);
994 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_2, normal_window);
995 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_3, normal_window);
996 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_4, normal_window);
997 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_5, normal_window);
998 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_6, normal_window);
999 command_updater_.UpdateCommandEnabled(IDC_SELECT_TAB_7, normal_window);
1000 command_updater_.UpdateCommandEnabled(IDC_SELECT_LAST_TAB, normal_window);
1001#if defined(OS_WIN)
[email protected]338416c02014-05-13 16:47:061002 bool metro = browser_->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH;
1003 command_updater_.UpdateCommandEnabled(IDC_METRO_SNAP_ENABLE, metro);
1004 command_updater_.UpdateCommandEnabled(IDC_METRO_SNAP_DISABLE, metro);
ananta196db192014-08-28 21:37:551005 int restart_mode = metro ? IDC_WIN_DESKTOP_RESTART :
1006 (base::win::GetVersion() >= base::win::VERSION_WIN8 ?
1007 IDC_WIN8_METRO_RESTART : IDC_WIN_CHROMEOS_RESTART);
[email protected]770c6d82012-09-06 22:21:321008 command_updater_.UpdateCommandEnabled(restart_mode, normal_window);
[email protected]5d98294912012-06-27 22:57:401009#endif
[email protected]5d98294912012-06-27 22:57:401010
[email protected]338416c02014-05-13 16:47:061011 // These are always enabled; the menu determines their menu item visibility.
[email protected]5d98294912012-06-27 22:57:401012 command_updater_.UpdateCommandEnabled(IDC_UPGRADE_DIALOG, true);
1013 command_updater_.UpdateCommandEnabled(IDC_VIEW_INCOMPATIBILITIES, true);
1014
[email protected]5d98294912012-06-27 22:57:401015 // Toggle speech input
1016 command_updater_.UpdateCommandEnabled(IDC_TOGGLE_SPEECH_INPUT, true);
1017
[email protected]6bd370b2014-05-28 14:19:471018 // Distill current page.
1019 command_updater_.UpdateCommandEnabled(
1020 IDC_DISTILL_PAGE,
1021 CommandLine::ForCurrentProcess()->HasSwitch(
1022 switches::kEnableDomDistiller));
1023
[email protected]338416c02014-05-13 16:47:061024 // Initialize other commands whose state changes based on various conditions.
[email protected]32dfede2013-08-25 15:48:251025 UpdateCommandsForFullscreenMode();
[email protected]5d98294912012-06-27 22:57:401026 UpdateCommandsForContentRestrictionState();
[email protected]5d98294912012-06-27 22:57:401027 UpdateCommandsForBookmarkEditing();
[email protected]5d98294912012-06-27 22:57:401028 UpdateCommandsForIncognitoAvailability();
1029}
1030
[email protected]05454532013-01-22 21:09:081031// static
1032void BrowserCommandController::UpdateSharedCommandsForIncognitoAvailability(
1033 CommandUpdater* command_updater,
1034 Profile* profile) {
mlermane01e6de2014-09-29 19:26:471035 const bool guest_session = profile->IsGuestSession();
1036 // TODO(mlerman): Make GetAvailability account for profile->IsGuestSession().
[email protected]5d98294912012-06-27 22:57:401037 IncognitoModePrefs::Availability incognito_availability =
[email protected]05454532013-01-22 21:09:081038 IncognitoModePrefs::GetAvailability(profile->GetPrefs());
1039 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:401040 IDC_NEW_WINDOW,
1041 incognito_availability != IncognitoModePrefs::FORCED);
[email protected]05454532013-01-22 21:09:081042 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:401043 IDC_NEW_INCOGNITO_WINDOW,
mlermane01e6de2014-09-29 19:26:471044 incognito_availability != IncognitoModePrefs::DISABLED && !guest_session);
[email protected]5d98294912012-06-27 22:57:401045
[email protected]57b25292014-05-01 16:31:061046 const bool forced_incognito =
1047 incognito_availability == IncognitoModePrefs::FORCED ||
1048 guest_session; // Guest always runs in Incognito mode.
[email protected]05454532013-01-22 21:09:081049 command_updater->UpdateCommandEnabled(
[email protected]5d98294912012-06-27 22:57:401050 IDC_SHOW_BOOKMARK_MANAGER,
[email protected]57b25292014-05-01 16:31:061051 browser_defaults::bookmarks_enabled && !forced_incognito);
[email protected]03d25812014-06-22 19:41:551052 ExtensionService* extension_service =
1053 extensions::ExtensionSystem::Get(profile)->extension_service();
[email protected]57b25292014-05-01 16:31:061054 const bool enable_extensions =
[email protected]5d98294912012-06-27 22:57:401055 extension_service && extension_service->extensions_enabled();
[email protected]5d98294912012-06-27 22:57:401056
[email protected]57b25292014-05-01 16:31:061057 // Bookmark manager and settings page/subpages are forced to open in normal
1058 // mode. For this reason we disable these commands when incognito is forced.
1059 command_updater->UpdateCommandEnabled(IDC_MANAGE_EXTENSIONS,
1060 enable_extensions && !forced_incognito);
1061
1062 command_updater->UpdateCommandEnabled(IDC_IMPORT_SETTINGS, !forced_incognito);
1063 command_updater->UpdateCommandEnabled(IDC_OPTIONS,
1064 !forced_incognito || guest_session);
1065 command_updater->UpdateCommandEnabled(IDC_SHOW_SIGNIN, !forced_incognito);
[email protected]05454532013-01-22 21:09:081066}
1067
1068void BrowserCommandController::UpdateCommandsForIncognitoAvailability() {
1069 UpdateSharedCommandsForIncognitoAvailability(&command_updater_, profile());
1070
[email protected]6a414ff2013-02-27 08:22:541071 if (!IsShowingMainUI()) {
[email protected]05454532013-01-22 21:09:081072 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS, false);
1073 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, false);
1074 }
[email protected]5d98294912012-06-27 22:57:401075}
1076
1077void BrowserCommandController::UpdateCommandsForTabState() {
[email protected]617ee962013-01-29 20:49:121078 WebContents* current_web_contents =
1079 browser_->tab_strip_model()->GetActiveWebContents();
[email protected]1c5119c2012-09-19 00:08:571080 if (!current_web_contents) // May be NULL during tab restore.
[email protected]5d98294912012-06-27 22:57:401081 return;
[email protected]5d98294912012-06-27 22:57:401082
1083 // Navigation commands
1084 command_updater_.UpdateCommandEnabled(IDC_BACK, CanGoBack(browser_));
1085 command_updater_.UpdateCommandEnabled(IDC_FORWARD, CanGoForward(browser_));
1086 command_updater_.UpdateCommandEnabled(IDC_RELOAD, CanReload(browser_));
1087 command_updater_.UpdateCommandEnabled(IDC_RELOAD_IGNORING_CACHE,
1088 CanReload(browser_));
[email protected]58e29032012-08-06 20:19:571089 command_updater_.UpdateCommandEnabled(IDC_RELOAD_CLEARING_CACHE,
1090 CanReload(browser_));
[email protected]5d98294912012-06-27 22:57:401091
1092 // Window management commands
1093 command_updater_.UpdateCommandEnabled(IDC_DUPLICATE_TAB,
1094 !browser_->is_app() && CanDuplicateTab(browser_));
1095
1096 // Page-related commands
1097 window()->SetStarredState(
[email protected]1c5119c2012-09-19 00:08:571098 BookmarkTabHelper::FromWebContents(current_web_contents)->is_starred());
[email protected]5423c372012-08-22 05:50:161099 window()->ZoomChangedForActiveTab(false);
[email protected]5d98294912012-06-27 22:57:401100 command_updater_.UpdateCommandEnabled(IDC_VIEW_SOURCE,
1101 CanViewSource(browser_));
1102 command_updater_.UpdateCommandEnabled(IDC_EMAIL_PAGE_LOCATION,
1103 CanEmailPageLocation(browser_));
1104 if (browser_->is_devtools())
1105 command_updater_.UpdateCommandEnabled(IDC_OPEN_FILE, false);
1106
1107 // Changing the encoding is not possible on Chrome-internal webpages.
1108 NavigationController& nc = current_web_contents->GetController();
[email protected]97174892014-06-03 09:06:121109 bool is_chrome_internal = HasInternalURL(nc.GetLastCommittedEntry()) ||
[email protected]5d98294912012-06-27 22:57:401110 current_web_contents->ShowingInterstitialPage();
1111 command_updater_.UpdateCommandEnabled(IDC_ENCODING_MENU,
1112 !is_chrome_internal && current_web_contents->IsSavable());
1113
1114 // Show various bits of UI
1115 // TODO(pinkerton): Disable app-mode in the model until we implement it
1116 // on the Mac. Be sure to remove both ifdefs. http://crbug.com/13148
1117#if !defined(OS_MACOSX)
1118 command_updater_.UpdateCommandEnabled(
1119 IDC_CREATE_SHORTCUTS,
1120 CanCreateApplicationShortcuts(browser_));
[email protected]92086542014-04-08 08:45:291121 command_updater_.UpdateCommandEnabled(IDC_CREATE_HOSTED_APP,
1122 CanCreateBookmarkApp(browser_));
[email protected]5d98294912012-06-27 22:57:401123#endif
1124
[email protected]9b7ab882012-09-10 23:46:361125 command_updater_.UpdateCommandEnabled(
1126 IDC_TOGGLE_REQUEST_TABLET_SITE,
1127 CanRequestTabletSite(current_web_contents));
1128
[email protected]5d98294912012-06-27 22:57:401129 UpdateCommandsForContentRestrictionState();
1130 UpdateCommandsForBookmarkEditing();
[email protected]3cac87232012-11-20 01:48:271131 UpdateCommandsForFind();
[email protected]d93dbd12014-08-04 23:42:531132 // Update the zoom commands when an active tab is selected.
1133 UpdateCommandsForZoomState();
1134}
1135
1136void BrowserCommandController::UpdateCommandsForZoomState() {
1137 WebContents* contents =
1138 browser_->tab_strip_model()->GetActiveWebContents();
1139 if (!contents)
1140 return;
1141 command_updater_.UpdateCommandEnabled(IDC_ZOOM_PLUS, CanZoomIn(contents));
1142 command_updater_.UpdateCommandEnabled(IDC_ZOOM_NORMAL, ActualSize(contents));
1143 command_updater_.UpdateCommandEnabled(IDC_ZOOM_MINUS, CanZoomOut(contents));
[email protected]5d98294912012-06-27 22:57:401144}
1145
1146void BrowserCommandController::UpdateCommandsForContentRestrictionState() {
1147 int restrictions = GetContentRestrictions(browser_);
1148
1149 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011150 IDC_COPY, !(restrictions & CONTENT_RESTRICTION_COPY));
[email protected]5d98294912012-06-27 22:57:401151 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011152 IDC_CUT, !(restrictions & CONTENT_RESTRICTION_CUT));
[email protected]5d98294912012-06-27 22:57:401153 command_updater_.UpdateCommandEnabled(
[email protected]3c71576ce2013-07-23 02:00:011154 IDC_PASTE, !(restrictions & CONTENT_RESTRICTION_PASTE));
[email protected]5d98294912012-06-27 22:57:401155 UpdateSaveAsState();
1156 UpdatePrintingState();
1157}
1158
1159void BrowserCommandController::UpdateCommandsForDevTools() {
1160 bool dev_tools_enabled =
1161 !profile()->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled);
1162 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS,
1163 dev_tools_enabled);
1164 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_CONSOLE,
1165 dev_tools_enabled);
[email protected]2056c3192013-10-21 22:40:511166 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_DEVICES,
1167 dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401168 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_INSPECT,
1169 dev_tools_enabled);
[email protected]d16657c2012-09-03 14:25:101170 command_updater_.UpdateCommandEnabled(IDC_DEV_TOOLS_TOGGLE,
1171 dev_tools_enabled);
[email protected]5d98294912012-06-27 22:57:401172}
1173
1174void BrowserCommandController::UpdateCommandsForBookmarkEditing() {
1175 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_PAGE,
1176 CanBookmarkCurrentPage(browser_));
1177 command_updater_.UpdateCommandEnabled(IDC_BOOKMARK_ALL_TABS,
1178 CanBookmarkAllTabs(browser_));
thestig5149d272014-10-30 07:25:291179#if defined(OS_WIN)
1180 command_updater_.UpdateCommandEnabled(IDC_PIN_TO_START_SCREEN, true);
1181#endif
[email protected]5d98294912012-06-27 22:57:401182}
1183
1184void BrowserCommandController::UpdateCommandsForBookmarkBar() {
tfarina3bddbe112014-08-28 05:29:321185 command_updater_.UpdateCommandEnabled(
1186 IDC_SHOW_BOOKMARK_BAR,
1187 browser_defaults::bookmarks_enabled && !profile()->IsGuestSession() &&
1188 !profile()->GetPrefs()->IsManagedPreference(
1189 bookmarks::prefs::kShowBookmarkBar) &&
1190 IsShowingMainUI());
[email protected]5d98294912012-06-27 22:57:401191}
1192
[email protected]9ec3ea5b2012-12-03 18:14:301193void BrowserCommandController::UpdateCommandsForFileSelectionDialogs() {
1194 UpdateSaveAsState();
[email protected]05454532013-01-22 21:09:081195 UpdateOpenFileState(&command_updater_);
[email protected]9ec3ea5b2012-12-03 18:14:301196}
1197
[email protected]32dfede2013-08-25 15:48:251198void BrowserCommandController::UpdateCommandsForFullscreenMode() {
1199 WindowState window_state = WINDOW_STATE_NOT_FULLSCREEN;
1200 if (window() && window()->IsFullscreen()) {
1201 window_state = WINDOW_STATE_FULLSCREEN;
1202#if defined(OS_WIN)
1203 if (window()->IsInMetroSnapMode())
1204 window_state = WINDOW_STATE_METRO_SNAP;
1205#endif
1206 }
[email protected]6a414ff2013-02-27 08:22:541207 bool show_main_ui = IsShowingMainUI();
[email protected]32dfede2013-08-25 15:48:251208 bool main_not_fullscreen =
1209 show_main_ui && window_state == WINDOW_STATE_NOT_FULLSCREEN;
[email protected]5d98294912012-06-27 22:57:401210
1211 // Navigation commands
1212 command_updater_.UpdateCommandEnabled(IDC_OPEN_CURRENT_URL, show_main_ui);
1213
1214 // Window management commands
1215 command_updater_.UpdateCommandEnabled(
1216 IDC_SHOW_AS_TAB,
[email protected]32dfede2013-08-25 15:48:251217 !browser_->is_type_tabbed() &&
1218 window_state == WINDOW_STATE_NOT_FULLSCREEN);
[email protected]5d98294912012-06-27 22:57:401219
1220 // Focus various bits of UI
1221 command_updater_.UpdateCommandEnabled(IDC_FOCUS_TOOLBAR, show_main_ui);
1222 command_updater_.UpdateCommandEnabled(IDC_FOCUS_LOCATION, show_main_ui);
1223 command_updater_.UpdateCommandEnabled(IDC_FOCUS_SEARCH, show_main_ui);
1224 command_updater_.UpdateCommandEnabled(
1225 IDC_FOCUS_MENU_BAR, main_not_fullscreen);
1226 command_updater_.UpdateCommandEnabled(
1227 IDC_FOCUS_NEXT_PANE, main_not_fullscreen);
1228 command_updater_.UpdateCommandEnabled(
1229 IDC_FOCUS_PREVIOUS_PANE, main_not_fullscreen);
1230 command_updater_.UpdateCommandEnabled(
1231 IDC_FOCUS_BOOKMARKS, main_not_fullscreen);
[email protected]822ca8c62013-04-19 00:49:151232 command_updater_.UpdateCommandEnabled(
1233 IDC_FOCUS_INFOBARS, main_not_fullscreen);
[email protected]5d98294912012-06-27 22:57:401234
1235 // Show various bits of UI
1236 command_updater_.UpdateCommandEnabled(IDC_DEVELOPER_MENU, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431237#if defined(GOOGLE_CHROME_BUILD)
[email protected]5d98294912012-06-27 22:57:401238 command_updater_.UpdateCommandEnabled(IDC_FEEDBACK, show_main_ui);
[email protected]236ad3022013-09-04 03:27:431239#endif
[email protected]074311a2013-02-28 23:14:091240 UpdateShowSyncState(show_main_ui);
[email protected]5d98294912012-06-27 22:57:401241
1242 // Settings page/subpages are forced to open in normal mode. We disable these
[email protected]90efc3e2014-04-22 18:39:031243 // commands for guest sessions and when incognito is forced.
[email protected]5d98294912012-06-27 22:57:401244 const bool options_enabled = show_main_ui &&
[email protected]5d98294912012-06-27 22:57:401245 IncognitoModePrefs::GetAvailability(
1246 profile()->GetPrefs()) != IncognitoModePrefs::FORCED;
[email protected]57b25292014-05-01 16:31:061247 const bool guest_session = profile()->IsGuestSession();
[email protected]5d98294912012-06-27 22:57:401248 command_updater_.UpdateCommandEnabled(IDC_OPTIONS, options_enabled);
[email protected]57b25292014-05-01 16:31:061249 command_updater_.UpdateCommandEnabled(IDC_IMPORT_SETTINGS,
1250 options_enabled && !guest_session);
[email protected]5d98294912012-06-27 22:57:401251
1252 command_updater_.UpdateCommandEnabled(IDC_EDIT_SEARCH_ENGINES, show_main_ui);
1253 command_updater_.UpdateCommandEnabled(IDC_VIEW_PASSWORDS, show_main_ui);
1254 command_updater_.UpdateCommandEnabled(IDC_ABOUT, show_main_ui);
1255 command_updater_.UpdateCommandEnabled(IDC_SHOW_APP_MENU, show_main_ui);
1256#if defined (ENABLE_PROFILING) && !defined(NO_TCMALLOC)
1257 command_updater_.UpdateCommandEnabled(IDC_PROFILING_ENABLED, show_main_ui);
1258#endif
1259
[email protected]7efaed362013-04-04 09:33:321260 // Disable explicit fullscreen toggling when in metro snap mode.
[email protected]32dfede2013-08-25 15:48:251261 bool fullscreen_enabled = window_state != WINDOW_STATE_METRO_SNAP;
[email protected]aeafc3852014-04-29 16:51:291262#if !defined(OS_MACOSX)
[email protected]32dfede2013-08-25 15:48:251263 if (window_state == WINDOW_STATE_NOT_FULLSCREEN &&
1264 !profile()->GetPrefs()->GetBoolean(prefs::kFullscreenAllowed)) {
1265 // Disable toggling into fullscreen mode if disallowed by pref.
1266 fullscreen_enabled = false;
1267 }
[email protected]00a1cc5b2012-11-07 13:44:511268#endif
1269
1270 command_updater_.UpdateCommandEnabled(IDC_FULLSCREEN, fullscreen_enabled);
1271 command_updater_.UpdateCommandEnabled(IDC_PRESENTATION_MODE,
1272 fullscreen_enabled);
[email protected]5d98294912012-06-27 22:57:401273
1274 UpdateCommandsForBookmarkBar();
[email protected]5d98294912012-06-27 22:57:401275}
1276
1277void BrowserCommandController::UpdatePrintingState() {
[email protected]d53e4032012-06-29 18:58:341278 bool print_enabled = CanPrint(browser_);
1279 command_updater_.UpdateCommandEnabled(IDC_PRINT, print_enabled);
vitalybukaf9433e42014-09-08 10:04:551280#if !defined(DISABLE_BASIC_PRINTING)
1281 command_updater_.UpdateCommandEnabled(IDC_BASIC_PRINT,
1282 CanBasicPrint(browser_));
vitalybuka73b79802014-09-08 17:17:121283#endif // !DISABLE_BASIC_PRINTING
[email protected]5d98294912012-06-27 22:57:401284}
1285
1286void BrowserCommandController::UpdateSaveAsState() {
1287 command_updater_.UpdateCommandEnabled(IDC_SAVE_PAGE, CanSavePage(browser_));
1288}
1289
[email protected]074311a2013-02-28 23:14:091290void BrowserCommandController::UpdateShowSyncState(bool show_main_ui) {
1291 command_updater_.UpdateCommandEnabled(
1292 IDC_SHOW_SYNC_SETUP, show_main_ui && pref_signin_allowed_.GetValue());
1293}
1294
[email protected]05454532013-01-22 21:09:081295// static
1296void BrowserCommandController::UpdateOpenFileState(
1297 CommandUpdater* command_updater) {
[email protected]5d98294912012-06-27 22:57:401298 bool enabled = true;
1299 PrefService* local_state = g_browser_process->local_state();
1300 if (local_state)
1301 enabled = local_state->GetBoolean(prefs::kAllowFileSelectionDialogs);
1302
[email protected]05454532013-01-22 21:09:081303 command_updater->UpdateCommandEnabled(IDC_OPEN_FILE, enabled);
[email protected]5d98294912012-06-27 22:57:401304}
1305
1306void BrowserCommandController::UpdateReloadStopState(bool is_loading,
1307 bool force) {
1308 window()->UpdateReloadStopState(is_loading, force);
1309 command_updater_.UpdateCommandEnabled(IDC_STOP, is_loading);
1310}
1311
[email protected]2e9369e2014-08-15 09:12:531312void BrowserCommandController::UpdateTabRestoreCommandState() {
1313 TabRestoreService* tab_restore_service =
1314 TabRestoreServiceFactory::GetForProfile(profile());
1315 // The command is enabled if the service hasn't loaded yet to trigger loading.
1316 // The command is updated once the load completes.
1317 command_updater_.UpdateCommandEnabled(
1318 IDC_RESTORE_TAB,
1319 tab_restore_service &&
1320 (!tab_restore_service->IsLoaded() ||
1321 GetRestoreTabType(browser_) != TabStripModelDelegate::RESTORE_NONE));
1322}
1323
[email protected]3cac87232012-11-20 01:48:271324void BrowserCommandController::UpdateCommandsForFind() {
1325 TabStripModel* model = browser_->tab_strip_model();
1326 bool enabled = !model->IsTabBlocked(model->active_index()) &&
1327 !browser_->is_devtools();
1328
1329 command_updater_.UpdateCommandEnabled(IDC_FIND, enabled);
1330 command_updater_.UpdateCommandEnabled(IDC_FIND_NEXT, enabled);
1331 command_updater_.UpdateCommandEnabled(IDC_FIND_PREVIOUS, enabled);
1332}
1333
[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